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 / evidence / api-kernel-gen-attn / 2026-11-06 / README.md

279 lines · 16978 bytes Raw Blame History Rendered
1<!-- SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -->
2# Attention API kernel generation in seeded Omega
3
4## Implementation and provenance
5
6Branch: `feat/api-kernel-gen-attn-om`, stacked on
7`origin/feat/api-kernel-gen-om` at `bac386c`. The source-only registration
8commits are `35205e50` and `4acdb918`. Shared registration is integration-owned
9commit `20b33b52`, merged before the attention C cutover. Its aggregate identity
10staging omission was repaired by parent commit `aff2669c`, applied here as
11`51e0f36b`. The integration PR is
12[CUDApp #340](https://github.com/aien-dev/CUDApp/pull/340); this lane opens no PR.
13
14The default attention generator is `omega_attention_ir`, computed by:
15
16- `om/kgen/attention_emit.om`: exact record serialization, virtual registers,
17 scheduler scoreboards, batched loads, loop intervals and reconvergence.
18- `om/kgen/attention_tuned.om`: HD64/HD128, both storage formats, GQA groups,
19 direct/split outputs, divergent-region and existing behavioral controls.
20- `om/kgen/attention_general.om`: every head dimension from 1 through 256,
21 whole-warp thread rounding, dimension tails and the general controls.
22- `om/kgen/attention_ir.om`: checked packed-spec dispatch and scratch layout.
23
24`src/omega_gpu_attention_api.c` calls the existing single
25`omega_gpu_om_ir_replay` entry. No replay entry, opcode, allocator trust path,
26physical register budget or public API is added or changed. The replay already
27solves allocation and checks closed-loop invariants; the new C path does not
28solve allocation twice. The old emitters and scheduler compile only with
29`CUDAPP_MIGRATION_PENDING_C_API_KGEN=1`, default **0**.
30
31Each instruction is exactly eight `u64` words: opcode; destination; three
32sources; uniform register; immediate plus control in the upper word; flags.
33Metadata has 512 `u64` words. Fields 0/1/2 are instruction/GPR/UGPR counts;
344 is emitter error; 5 is closed-loop count; 16..31 hold loop intervals;
3564..319 and 320..383 hold virtual register widths. Internal scoreboard/region
36scratch is private to the emitter. Fields **6 and 7 are cleared on success**:
37attention uses the pre-existing default allocator, not the extended allocator.
38
39Remaining C in this file is API validation/host-plan dispatch, allocation,
40cache ownership, artifact encoding/digest calls and device launch glue. The
41existing host launch-shape helpers remain unchanged; the assigned migration
42is the attention IR generator, not another host-view/launch-plan cutover.
43The handwritten C generator remains only as the default-OFF differential
44oracle. Generated C is checked output of the first-party bounded Omega bridge,
45not a second handwritten implementation.
46
47Compiler: seeded `omega-mv@e5b32567`, SHA-256
48`2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f`.
49Bridge: existing integration checkout `/tmp/integ/bridge-73-79e8c36` at
50`79e8c36`, the same converter used by the stacked parent. The independent
51bootstrap compiler path is `~/work/cudastack/omega-bridge/build/bootstrap/omc`.
52Host compiler and gcov: Ubuntu GCC `13.3.0-6ubuntu2~24.04.1`; bubblewrap `0.9.0`.
53These are verification/build tools, not replacement attention implementations.
54
55## Differential and shape partition
56
57`tests/api_kernel_gen_attention.c` includes the retained C generator with the
58migration flag ON. Before either allocator runs, it compares every field of
59every eight-word instruction record, both virtual register width spaces and
60all closed-loop endpoints. It then compares allocation success/refusal,
61the full solved allocator (including uniform allocation), encoded instruction
62bytes, and complete final cubin containers. Both containers use identical valid
63attention parameter/shared-memory descriptors and independently derived
64declared register counts. A perturbed-record invocation flips a serialized
65immediate; a second invocation flips the final byte of the packed Omega cubin.
66Both must return **1**. The make target requires those red results rather than
67treating a crash or generation failure as a passing negative control.
68
69The original receipts below establish IR/encoded-text equality only; they did
70not compare final cubin bytes. The acceptance extension and its separately
71preserved receipts are in [cubin-followup/README.md](cubin-followup/README.md).
72
73The partition is derived from `gen_attention`, `gen_attention_general`,
74`heads_per_cta`, `gen_threads` and the admitted `KSpec` fields:
75
76- Both BF16 and F32.
77- Every general head dimension 1..256, thus every D/4 tail and every warp
78 boundary. HD0, HD257 and `UINT32_MAX` are refused. Tuned HD64/HD128 plus
79 adjacent/representative invalid values are checked independently.
80- Tuned `log2bs` and `log2gqa` each exhaust 0..31, including all shift values
81 and the GQA-group transitions 0/1/2/3. This is broader than the public tuned
82 plan, which admits `log2bs <= 16` and `log2gqa <= 6`.
83- General block shifts 0/1/30/31 on every head dimension and every general
84 mutant value 0..5 exercise the ordinary and saturating slot masks.
85- Every split value -1..4 (direct output and all supported partial counts).
86 Split5, reserved kind bits and invalid selector values are refused.
87- Every tuned mutant 0..6, divergent value 0..2 and GQA group 1/2/4, in both
88 formats and both tuned dimensions. General mutants 1 and 5 intentionally
89 leave the generator unchanged; their host-side behavior belongs to the
90 existing API path, while generator byte equality is still checked.
91- Shift values 32/33/`UINT32_MAX`, invalid tuned dimensions including
92 63/65/127/129, and malformed packed selectors are refused before unsafe
93 shifts or dimensions can reach the retained C oracle. Inputs that the public
94 plan cannot admit are refusal tests, not C undefined-behavior experiments.
95
96`tests/attention_kgen_mutants.py` independently perturbs five Omega semantics:
97descriptor offset, query argument offset, thread special register, scalar
98argument offset and the scheduler stall-control field. Every mutant must
99regenerate, compile, link and fail the behavioral differential with rc 1.
100A missing textual site, compiler failure, crash or surviving mutant fails the
101gate; none counts as a kill.
102
103## Observed acceptance
104
105The final generator differential reports **39,423 cases**, with raw records and
106encoded bytes identical. The deliberately corrupted record returns **1** and
107is detected. All five independently regenerated/compiled Omega mutants return
108**1** with record mismatches; the mutation gate returns **0**.
109
110All commands below ran under the wrapper in the next section. Full outputs
111are the corresponding `.log` files; `rc.tsv` consolidates their observed
112results, retaining successful earlier rows when selected gates are rerun.
113
114| Command | rc | Observed final line |
115|---|---:|---|
116| `make -j3 -f Makefile -f tests/attention_kgen.mk test-api-kgen-attention` | 0 | `PASS attention red control detected perturbed IR record` |
117| `make -j3 -f Makefile -f tests/attention_kgen.mk test-api-kgen-attention-mutants` | 0 | `PASS attention seeded semantic mutants: 5 killed` |
118| `make -j3 test-gpu-attention` | 0 | `PASS: 348 checks, 0 failed` |
119| `make -j3 test-gpu-decode-attn` | 0 | `gpu_decode_attn_test: 12 checks, 0 failed: PASS` |
120| `make -j3 test-gpu-decode-attn-maxpos` | 0 | `test-gpu-decode-attn-maxpos: 7 of 7 controls killed (5 binding mutants)` |
121| `make -j3 test-gpu-decode-attn256` | 0 | `gpu_decode_attn256_test: 14 checks, 0 failed: PASS` |
122| `make -j3 test-gpu-prefill-host` | 0 | `test-gpu-prefill-host: PASS (8 prefill tests, host model + warp simulator, no device)` |
123| `sh om/units.sh --check` | 0 | `PASS portable Omega units regenerate byte for byte` |
124| `crumb compile .` | 0 | `crumb compile: 46 crumbs, 0 rewritten` (HEAD recorded in log) |
125| `crumb verify .` | 0 | `crumb verify: OK: 46 crumbs current` |
126
127The first default-path build exposed a common `rc` declaration accidentally
128inside the migration guard; it was moved outside the guard before the listed
129successful host run. The first full unit regeneration check then exposed the
130parent aggregate identity omission described above. Only the regeneration and
131crumb gates were rerun after that manifest-only repair; the generator, encoded
132output and host test sources were unchanged. These are resolved failures, not
133waived gates.
134
135| Tier / delivery state | Verdict |
136|---|---|
137| IMPLEMENTED: seeded attention emitters and default replay cutover | PASS |
138| EXERCISED: raw IR / encoding differential and negative control | PASS |
139| EXERCISED: five semantic Omega mutants | PASS |
140| EXERCISED: required host/model/simulator targets | PASS |
141| EXERCISED: regeneration and crumb gates | PASS |
142| QUALIFIED: physical chip | NOT_RUN — no authorized GPU window |
143| MERGED / DEPLOYED | NOT_RUN — integration owner retains custody |
144
145## C oracle coverage
146
147The retained C oracle fixture is compiled with `-O0 --coverage`. After the
148serial differential and mutant gates, this command ran with the same bwrap,
149affinity and nice wrapper, from this evidence directory:
150
151```sh
152gcov --json-format -b -c -f \
153 "$HOME/work/cudastack/lanes/KernGenAttnOm/build/api-kgen/attention_diff.gcno"
154```
155
156Observed rc **0**, final line `Lines executed:51.74% of 1380`. The complete
157machine-readable receipt is `attention_diff.gcov.json.gz`. That gcov receipt
158retains its original build/source paths. Gcov reports `gen_attention` **100.00%
159of 312 lines**, `gen_attention_general` **100.00% of 176 lines**, and no
160untaken branch edges inside either generator. The whole included API file is
16151.25% of 1204 lines because the direct oracle intentionally bypasses the API,
162cache, allocation and launch functions; those unchanged host interfaces are
163exercised separately by the required host targets, not claimed as covered by
164this oracle profile.
165
166Every untaken oracle helper branch is accounted for below. Line numbers refer
167to `src/omega_gpu_attention_api.c` at this cutover:
168
169| Lines | Untaken outcome and reason |
170|---|---|
171| 82 / 94 | Invalid scheduler-kind default; every source emitter passes a declared kind. |
172| 89 | Predicated EXIT; attention's tail always emits an unconditional EXIT. |
173| 90 | Unconditional scheduler BRA; source loop/region branches are predicated, and the final self-branch is appended directly. |
174| 96, 99–102, 140, 149, 215 | Append/register exhaustion; all admitted partitions fit the existing fixed emitter limits. This is not an allocation-failure injection profile. |
175| 136 | Invalid scoreboard / excess batch size; source scoreboards and batches are bounded constants. |
176| 147 | Empty-batch alternative; every source caller of the fixed-in-batch helper has opened a load batch. |
177| 171, 172, 175 | Shuffle/barrier inside an open divergent region; the structured source closes regions before those operations. |
178| 180 | Invalid forward-patch location; patch locations are obtained from the current emitted stream. |
179| 186, 189, 197, 200, 209 | Region-stack exhaustion, missing/open-region corruption and helper failures; source nesting is bounded and balanced, including the intentional divergent controls. |
180| 195 | Unconditional region exit; the attention source uses conditional region exits. |
181| 220, 224 | Loop-stack/count exhaustion and unmatched loop end; the source loop nesting and closures are fixed and balanced. |
182| 230 | A combined live-interval-extension short-circuit outcome is absent from the emitted intervals; shape partitions do not alter that allocator safety condition. |
183| 242 | Loop-local value used after its loop; all admitted generated loops satisfy the invariant. |
184| 244 | Uniform-destination opcode alternatives in the GPR redefinition check; uniform loads do not redefine the matching GPR. |
185
186In `omega_bw_reconv.h`, untaken edges at lines 42/45/50/58/60/70/73/74/78
187are the same capacity/invalid-region/invalid-record guards: valid source
188regions never exhaust the stack/exits or provide invalid join/branch sites.
189All 28 helper lines execute, but invalid-state fault injection is not claimed.
190Zero-hit functions after the generator in the included API file and in its
191view/table headers are outside this direct-emitter oracle; they are not silently
192counted as generator coverage. Differential diagnostic error branches likewise
193remain mostly cold because equality is the expected result; the explicit red
194record and semantic mutants exercise the record mismatch path.
195
196## Reproduction and safety
197
198All test, simulator, differential and mutant executions inherit private `/dev`
199from this exact outer command. No GPU, live-RM or VFIO device is exposed.
200No service, lock, GPU module or firmware state is changed.
201
202```sh
203bwrap --dev-bind / / --dev /dev --proc /proc -- \
204 taskset -c 10-14 nice -n 10 \
205 env OMEGA_OMC="$HOME/work/cudastack/omega-mv/seed/out/omc" \
206 OMEGA_BRIDGE=/tmp/integ/bridge-73-79e8c36 \
207 OMEGA_SEED="$HOME/work/cudastack/omega-bridge/build/bootstrap/omc" \
208 python3 tests/attention_kgen_gate.py
209```
210
211The runner serializes the named gates, limits make to `-j3`, writes each
212command's full output to its own `.log`, and records the return code and final
213line in `rc.tsv`. `test-gpu-attention` itself covers host, simulator, sweep,
214HD128 host/simulator, divergent HD128 simulator and general simulator modes.
215`test-gpu-decode-attn` also depends on the max-position gate; that gate is run
216explicitly once more because it is independently named in the assignment.
217`test-gpu-decode-attn256` and `test-gpu-prefill-host` are host/simulator-only.
218No full `make test` is run by this lane. Paths in the original runner's logs are
219normalized from the local home directory to `~`; commands and other output are
220unchanged. Follow-up receipts describe their own capture conventions.
221
222## Wolfram queries
223
224The source literal conversions and adjacent shape boundaries were obtained with:
225
226```text
227WolframLanguageEvaluator:
228{FromDigits[#,16]& /@ {"ff800000","3f800000","ffff0000","80000000","000fc000","358","380","388","390","398","3a0","3a4","3a8","3ac","3b0","3b4","3b8","3bc"},
229 Table[{v-1,v,v+1},{v,{1,2,4,6,31,32,64,128,256}}]}
230-> {{4286578688,1065353216,4294901760,2147483648,1032192,856,896,904,912,920,928,932,936,940,944,948,952,956},
231 {{0,1,2},{1,2,3},{3,4,5},{5,6,7},{30,31,32},{31,32,33},{63,64,65},{127,128,129},{255,256,257}}}
232
233WolframLanguageEvaluator:
234{BitOr[15,BitShiftLeft[255,8],BitShiftLeft[7,40]],BitOr[11,512,65536],BitOr[12,1024,65536],BitOr[49,512],BitOr[50,1024],BitOr[48,1280],BitOr[45,1536],BitOr[46,3072],BitOr[54,2048]}
235-> {7696581459727,66059,66572,561,1074,1328,1581,3118,2102}
236```
237
238## Chip runbook — NOT_RUN
239
240There is no GPU window for this lane. Host/model/simulator evidence is not
241hardware qualification. Do not execute this runbook until Drake grants the
242current exclusive window and the current hardware gate/runbook is followed.
243A stale receipt or a free-looking lock is not authorization.
244
245In the authorized window, record the source/compiler/bridge revisions and
246regenerate-check the committed units. Build the default-Omega library, preserve
247the physical register budget, and use the existing `gpu_attention_test` chip
248modes for HD64, HD128, GQA/split and general shapes. Run existing decode and
249prefill chip gates from the same build. Record exact commands, device and driver
250identity, output bytes against existing references, permitted negative controls
251and passive driver fault evidence. Use the current operator procedure for GPU
252custody, service suspension/restoration and chip receipt capture. Never run an
253unapproved mutant on hardware or weaken refusal/memory/clock gates to proceed.
254The integration owner decides whether those receipts qualify the change; this
255lane neither merges nor deploys it.
256
257The existing test binaries parse the following chip payloads when neither
258`--host-only` nor `--sim` is supplied. They are **NOT_RUN**, and are not
259authorization to execute. The operator must use the current approved chip
260launcher/custody procedure, explicitly authorize the battery's built-in negative
261controls, and maintain the prescribed affinity and build concurrency limits.
262The private-`/dev` host wrapper above cannot produce a chip receipt.
263
264```sh
265./build/gpu_attention_test --out chip-attn64.json
266./build/gpu_attention_test --hd 128 --out chip-attn128.json
267./build/gpu_attention_test --sweep --out chip-attn-sweep.json
268./build/gpu_attention_test --general --out chip-attn-general.json
269./build/gpu_decode_attn_test --out chip-decode-attn.json
270./build/gpu_decode_attn256_test --out chip-decode-attn256.json
271./build/gpu_prefill_attn_test --out chip-prefill-attn.json
272./build/gpu_prefill_attn256_test --out chip-prefill-attn256.json
273```
274
275Build targets are the corresponding `build/<binary>` paths, with the migration
276flag left at its default zero. Stop on a gate refusal, unavailable window,
277unexpected device state, fault or failed positive/negative control; preserve
278the receipt and follow the operator's restoration procedure. Do not convert a
279refusal, simulator result or skipped command into PASS.