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