interplane.Get Omega
Read in your language

CUDApp

CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.

Brought by drakestapleton

branch main Branches Tags History

CUDApp / om / attn-any / README.md

124 lines · 6952 bytes Raw Blame History Rendered
1# Seeded Omega any-shape attention
2
3IMPLEMENTED: `emit.om` and `kernel.om` select all instructions, tails, loops,
4masking and online softmax; `plan.om` admits shapes and selects GQA offsets and
5launch geometry. The C API is an allocation/copy/session-launch shell. This is a
6new entry, not a replacement of the tuned attention generators. No existing
7attn/pattn/attn256/pattn256 generator is changed.
8
9The original attention branch stacks on CodegenA's generic replay prerequisite
10`22ebf8f` (`feat/omega-codegen-a`, CUDApp #275). The DNN follow-on includes
11the separately authorized replay admission repair `a8c6a22`: the opcode bound
12uses `BW_IR_LAST`, with a compiled reverting mutant and boundary regression.
13Compiler: omega-mv `e5b32567`, omc SHA-256
14`2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f`.
15Generated C uses the pinned `om/units.sh` bridge frontend and stays generated.
16This does not adopt an outside production implementation. The existing host IR
17replay/register allocator and session remain migration-pending dependencies.
18
19## Contract
20
21Contiguous Q `[q_heads][seq_q][head_dim]`, K/V
22`[kv_heads][seq_kv][head_dim]`; output `[q_heads][seq_q][head_dim]` in f32.
23Inputs are f32, bf16 or IEEE binary16. Native half widening uses the seeded
24sm_121 IR conversion; head dimension is any integer 1..256, not just multiples
25of 32. Sequence lengths are independently any integer 1..65535; Q and KV head
26counts are positive, Q heads at most 65535, KV heads divide Q heads, and each
27Q/KV tensor has at most 1073741824 elements. GQA groups are contiguous.
28Causal mode is top-left aligned (`key <= query`), not bottom-right aligned.
29No batch dimension or strides are implied. Scale may be any finite f32,
30including zero or negative. Input values and intermediate dots must be finite;
31there is no input-value scan. The admission limits describe geometry, not a
32universal numerical error bound.
33
34One 32-lane warp owns a query row. Each lane holds up to eight Q components
35and output numerators. Component tails predicate memory operations, never
36remove lanes from the shuffle. The KV loop visits each admitted visible key,
37reduces dot products across all lanes, updates f32 running maximum/sum and
38output numerators, then normalizes once. No attention score matrix is stored.
39Both query tails and key tails are exact loop bounds rather than padded rows.
40
41## Numerical reference and tolerance
42
43`tests/gpu_attn_any_ref.h` materializes naive scores in double, computes a
44double maximum/exp/sum, then a weighted V sum. It shares no production
45admission, recurrence, grouping or instruction helpers. The test fixtures use
46exactly representable dyadics: |Q|, |K|, |V| <= 1/8, head_dim <= 256,
47seq_kv <= 513, and |scale| <= 1/4. Simulator EX2/RCP use the host floating
48oracle; their passing does not qualify the chip's approximations.
49
50For binary16 fixtures the independent reference decodes integer fields directly
51to double, without using the production conversion instruction:
52`WolframLanguageEvaluator: {FullSimplify[e-15-10],1-15-10,N[2^-24],N[2^-10]}`
53returned `{e-25,-24,5.960464477539063*^-8,0.0009765625}`.
54Normal values use `ldexp(1024+fraction,exponent-25)`; subnormals use
55`ldexp(fraction,-24)`. Storage decoding introduces no approximate half arithmetic.
56
57WolframLanguageEvaluator query:
58
59```wolfram
60FullSimplify[(s Exp[m-t] o + Exp[x-t] v)/(s Exp[m-t]+Exp[x-t]) -
61 (Exp[m] s o + Exp[x] v)/(Exp[m] s+Exp[x]),
62 Assumptions -> Element[{s,m,t,x,o,v},Reals] && s>0]
63```
64
65Result: `0`. This verifies rescaling the prior sum/numerator to the new maximum
66preserves the softmax-weighted value in exact arithmetic.
67
68The absolute comparison tolerance is `2^-10 = 0.0009765625`. It is a
69conservative **modeled test envelope**, not a proven universal error bound.
70Using f32 unit roundoff `u=2^-24`, gamma(n)=n*u/(1-n*u), a provisional
71transcendental allowance `2^-20` and safety factor 16:
72
73```wolfram
74N[16 ((256 2^-24)/(1-256 2^-24)+
75 (513 2^-24)/(1-513 2^-24)+2^-20)]
76N[2^-10]
77N[256 (1/8)^2 (1/4)]
78```
79
80Wolfram results: `0.0007486530236091783`, `0.0009765625`, and `1.`
81respectively. The last is the fixture's maximum absolute score envelope.
82The chosen tolerance rounds up the modeled accumulation/transcendental
83allowance. Actual errors are checked element by element against the independent
84reference; NaNs fail. No empirical error or speed is inferred from these models.
85
86## Host acceptance
87
88```sh
89export OMEGA_OMC=$HOME/work/cudastack/omega-mv/seed/out/omc
90export OMEGA_BRIDGE=$HOME/work/cudastack/omega-bridge
91bwrap --dev-bind / / --dev /dev --proc /proc -- taskset -c 10-14 nice -n 10 sh om/units.sh
92bwrap --dev-bind / / --dev /dev --proc /proc -- taskset -c 10-14 nice -n 10 make -j3 test-gpu-attn-any test-gpu-attn-any-mutants
93```
94
95The mixed-factor sweep covers sequence lengths 1, 2, 7, 64, 65, 513 independently
96for Q/KV, head dimensions 64, 80, 96, 128, 256, GQA groups 1, 4, 8,
97both causal modes and all three dtypes. It is a documented mixed-factor sweep, not
98an exhaustive Cartesian product. Additional cases cover dimensions 1,3,31,33,255,
99eight additional f16 head dimensions, negative and zero scale, rectangular wrong-mask control, distinct KV-head grouping and a
100513-by-513 case. Allocation ranges guard all global memory accesses.
101Refusal controls cover dimension 257, non-dividing/zero heads, zero KV length,
102over-limit sequences/tensors, invalid causal flags, nonfinite scale and invalid dtype 3.
103The execution API is also checked to refuse an invalid shape before opening a session.
104Source mutants change mask, GQA mapping, normalization, component tails,
105dimension admission and native half widening in isolated copies. All six must generate successfully
106and then fail behavior checks; a compile error does not count as a kill.
107
108Both baseline and mutant links interpose session open/lock/unlock/free.
109Simulation and quick modes abort on any such call. A seventh compiled
110test-source mutant calls `session_open` directly and must die with SIGABRT,
111not merely return a device error. The separate `--shell-contract` mode uses
112an isolated fake session and forces allocation failure: NULL must stop before
113allocation, while a non-NULL open must reach it. That regression checks the
114C shell's pointer-success contract without opening hardware; it is not chip
115execution. Only the explicit `--chip` mode forwards interposed session calls.
116Every host, simulator, mutation or differential command must run inside the
117device-free namespace above. Interposition is an additional defense, not a
118replacement for hiding all device nodes.
119
120Chip execution and qualification: **NOT_RUN**. See [CHIP.md](CHIP.md). A passing
121host reference/simulator is EXERCISED only. ROADMAP's status remains PARTIAL.
122The native half encoder seam is documented in `../dnn-layers/README.md`.
123The compiler pin and seeded language are unchanged. The new experimental API
124and lane-local commands are documented here and in `docs/runtime/API.md`.