omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / docs / gpu-reconvergence-308.md
| 1 | # GPU structured warp reconvergence (omega #308) |
| 2 | |
| 3 | Branch feat/gpu-reconvergence-308, code at 0a1812f, receipts in evidence/gpu-reconv-308/. |
| 4 | Evidence classes used below: PROVEN BY TEST (a test in this repo passes, command and receipt |
| 5 | named), MEASURED (read off the real chip or the real nvcc), DERIVED FROM REFERENCE (taken from |
| 6 | Mesa NAK source, not checked by me on the chip), INFERRED (reasoned from documentation, not |
| 7 | checked), UNKNOWN. |
| 8 | |
| 9 | ## 1. The failure mode |
| 10 | |
| 11 | On the GB10 (sm_121) a warp is 32 lanes. When lanes take different paths (a lane-dependent |
| 12 | branch or loop exit) and the code then runs a warp-wide step (SHFL, or a shared-memory exchange |
| 13 | guarded by BAR.SYNC), the lanes must first be brought back together. Without an explicit |
| 14 | reconvergence point the chip may run the later step with only some lanes active and reads the |
| 15 | inactive lanes' registers, which are undefined. |
| 16 | |
| 17 | Two places in AIEN hit this and were worked around by removing the divergence: |
| 18 | - The original divergent prime sieve (omega 888a011, lane-dependent mark loop) gave wrong |
| 19 | results; the production C5 sieve avoids it with a warp-uniform loop. |
| 20 | - Attention with a `j >= ctx` branch gave wrong results in the SHFL reduction after it |
| 21 | (2026-10-04); production attention is branch-free. |
| 22 | |
| 23 | nvcc brackets such code with BSSY (arm a barrier register, name the join point) and BSYNC (wait |
| 24 | for every armed lane, continue as one warp). Omega's Blackwell code generator had neither. #308 |
| 25 | adds them, plus a host simulator that rejects code which misuses them. |
| 26 | Chip observation (MEASURED, T1b): the diamond probe with its BSYNC dropped runs on the chip |
| 27 | without error and returns 466 of 1000 words wrong. |
| 28 | |
| 29 | ## 2. Encodings (BSSY / BSYNC, sm_121) |
| 30 | |
| 31 | | Item | Value | Class | |
| 32 | |---|---|---| |
| 33 | | BSSY.RECONVERGENT | w0 = 0x945 \| pred<<12 \| bar<<16; w1 = (delta_insns - 1) * 16; w2 = 0x03800200; control 0x000fe200 (stall 1, yield) | MEASURED (nvcc 13.0.88 -arch=sm_121, evidence/gpu-reconv-308/oracle/) | |
| 34 | | BSYNC.RECONVERGENT | w0 = 0x941 \| pred<<12 \| bar<<16; w1 = 0; w2 = 0x03800200; control 0x000fea00 (stall 5, yield) | MEASURED (same oracle) | |
| 35 | | Opcodes 0x945 / 0x941, barrier id in bits 16..19 | Mesa NAK sm70_encode.rs OpBSSy / OpBSync | DERIVED FROM REFERENCE | |
| 36 | | RECONVERGENT bit (bit 73) | set by nvcc, omitted by NAK | MEASURED (nvcc) / DERIVED (NAK). The compiler emits nvcc's form. | |
| 37 | | Branch target of BSSY | the instruction after the BSYNC; loop exits and breaks jump to the BSYNC itself (where nvcc sends them) | MEASURED (oracle k_break, k_loop, k_nested) | |
| 38 | |
| 39 | Golden fixtures for both words and refusals -101..-105 pass in `build/gpu_reconv_test` |
| 40 | (PROVEN BY TEST, 220 checks, T1a). nvdisasm decodes every emitted listing with zero |
| 41 | undecodable words (PROVEN BY TEST, same run). |
| 42 | |
| 43 | ## 3. Region API and fail-closed rules |
| 44 | |
| 45 | Bookkeeping in src/omega_bw_reconv.h (`bw_regions_*`), wrapped by region_begin / region_exit / |
| 46 | region_join in src/omega_gpu_elementwise_api.c and src/omega_gpu_attention_api.c. |
| 47 | |
| 48 | - begin allocates barrier register Bn with n = nesting depth, then emits BSSY. 16 barrier |
| 49 | registers (B0..B15) are encodable; a 17th nested region is refused and the build fails. |
| 50 | Whether the chip really provides 16 is not documented to me; I ran 16 deep on the chip |
| 51 | (rc_depth16, MEASURED, T1a) and no deeper. |
| 52 | - exit records a forward branch that leaves the region; join patches it to the BSYNC and patches |
| 53 | the BSSY target to the instruction after the BSYNC. |
| 54 | - Refused at codegen: SHFL, BAR.SYNC or EXIT inside an open region; an unclosed region; a BSYNC |
| 55 | with no BSSY; on the launch path, SHFL or BAR.SYNC after a predicated EXIT (lanes already gone). |
| 56 | (PROVEN BY TEST: RC_REFUSE_* probes and RC_DEPTH16 in `build/gpu_reconv_test`.) |
| 57 | - This is why R6 (lanes exit early, then BAR.SYNC/SHFL on the rest) is refused at codegen rather |
| 58 | than proven correct on the chip. |
| 59 | |
| 60 | ## 4. Host warp simulator (tests/bw_warp_sim.h) |
| 61 | |
| 62 | A warp is a set of fragments (pc, lane mask). A predicated branch whose lanes disagree splits the |
| 63 | fragment. Fragments run one at a time in a chosen order; tests run both lowest-pc-first and |
| 64 | highest-pc-first. Fragments merge only at a BSYNC. |
| 65 | |
| 66 | Errors (first wins, each names the pc): SHFL_SPLIT, SHFL_EXITED, BSYNC_UNARMED, BSSY_REARM, |
| 67 | JOIN_MISMATCH, NONMEMBER, STUCK, NEVER_JOINED, plus range and resource errors. |
| 68 | |
| 69 | BAR.SYNC reached by a split warp is allowed and counted (`bar_split_arrivals`). Basis: the CUDA |
| 70 | programming guide says the CTA barrier counts arriving threads since Volta. Class: INFERRED for |
| 71 | sm_121, not verified by me as a rule. Supporting observation (MEASURED earlier, prime-race |
| 72 | receipts): the production C5 staged sieve has 128 split arrivals at 1e6 in the simulator and is |
| 73 | chip-correct. Fragments stay split after the barrier (a barrier is not a reconvergence point), so a |
| 74 | later SHFL without a BSYNC still fails with SHFL_SPLIT. |
| 75 | |
| 76 | Limits: EX2 and RCP are exact in the simulator, approximate on the chip. LDCU64 is not modelled. |
| 77 | Warp issue counts are a model, not chip time (UNKNOWN how well they track the chip). |
| 78 | |
| 79 | ## 5. Hazard / scheduling metadata |
| 80 | |
| 81 | From NAK sm120: BSSY, BSYNC and BClear are Decoupled (variable latency, tracked by the |
| 82 | scoreboard). DERIVED FROM REFERENCE. Omega does not enforce this: `schedule_fixed_pairs` ignores |
| 83 | control ops, and the control words above (stall 1 / stall 5, both yield) are copied from nvcc. |
| 84 | Chip correctness of the shapes the compiler emits is MEASURED (T1, T2, T4); a different placement is not covered. |
| 85 | |
| 86 | ## 6. Evidence table |
| 87 | |
| 88 | | # | Claim | Class | Command / receipt | |
| 89 | |---|---|---|---| |
| 90 | | 1 | BSSY/BSYNC words match nvcc; refusals -101..-105 | PROVEN BY TEST + MEASURED | `build/gpu_reconv_test` PASS 220; oracle/cf.{cu,sass} | |
| 91 | | 2 | Region API bounds and refusals (16 ok, 17 refused, SHFL/BAR/EXIT in region, unclosed) | PROVEN BY TEST | gpu_reconv_test PASS 220 | |
| 92 | | 3 | Simulator catches dropped BSYNC, corrupted target, exit past join, early exit then SHFL, split SHFL | PROVEN BY TEST | gpu_reconv_test; `gpu_attention_test --sim --divergent` PASS 124 | |
| 93 | | 4 | R3 diamond, R4 loop break, R5 nested, R6 exit+BAR+SHFL, 16-deep nest: 19 sizes each (incl. partial warps), bit-exact vs CPU oracle on the chip | PROVEN BY TEST (chip) | T1a/GPU-RECONV-0a1812f/receipt.json: OMEGA_GPU_RECONV_PASS, 220 checks, 95 chip cases, 0 failed. Repeat T1b PASS 220 | |
| 94 | | 5 | Chip catches math mutants; dropped BSYNC gives wrong words | MEASURED | T1 receipts: mutants diamond 755, loopbreak 377, nested 110 violations, exit_bar CODEGEN_FAIL; dropped BSYNC 466/1000 words wrong (T1b) | |
| 95 | | 6 | R2 attention j>=ctx branch inside a region, SHFL after the join, bit-correct incl. partial warps | PROVEN BY TEST (chip) | T2-attention: production run PASS 122, sweep PASS 73; `--divergent` run PASS 122, sweep PASS 73; timing PASS 2 | |
| 96 | | 7 | Existing gates unchanged | PROVEN BY TEST (chip) | T3: elementwise 31 checks PASS; cut4b (elementwise, attention, matmul 18 + timing 4, session probe 0/30 first-call failures) PASS; prime-race run_gb10_chip.sh VERDICT PASS (585 audit runs, 1172 passes, mutant caught) in T3b | |
| 97 | | 8 | R1 original divergent sieve (888a011 mark loop in a region) and nested variant bit-identical to oracle | PROVEN BY TEST (chip) | T4: PR_GB10_MARK=divergent and divergent2, 585 runs each (every DESIGN limit plus 1e7), 0 mismatches | |
| 98 | | 9 | BAR.SYNC on a split warp is legal on sm_121 | INFERRED | see section 4 | |
| 99 | | 10 | 16 barrier registers exist on the chip beyond depth 16 / refusal of 17 matches hardware | UNKNOWN | only depth 16 tested | |
| 100 | | 11 | R6 correctness after early exit | not proven: refused at codegen | section 3 | |
| 101 | | 12 | Simulator issue counts predict chip time | UNKNOWN | model only | |
| 102 | |
| 103 | ## 7. Performance (R1, honest) |
| 104 | |
| 105 | Setup: `PR_GB10_CTA_BUDGET=64`, limit 1e6, 5 s per run, same session, three marks interleaved, |
| 106 | 8 rounds (T4/perf*.json, perf64.log, perf64-repeat.log). Unit: passes per second. MEASURED. |
| 107 | |
| 108 | | mark | per-round passes/s | note | |
| 109 | |---|---|---| |
| 110 | | uniform (C5, production) | 7618 7530 5213 6354 6914 7485 7936 6960 | noisy, 5213..7936 | |
| 111 | | divergent (888a011 loop in a region) | 9155 9147 9134 9127 9158 9107 9113 9162 | 9107..9162 | |
| 112 | | divergent2 (plus prime loop, nested) | 9092 9247 9119 9263 9004 9081 9126 9183 | 9004..9263 | |
| 113 | |
| 114 | The brief's C5 baseline was 9139 passes/s. In this session the C5 uniform build measured lower |
| 115 | and much noisier than that figure, so the table does not support a claim that divergent beats C5. |
| 116 | What it does show: the regioned divergent kernels lose no throughput against the 9139 baseline and |
| 117 | sit flat near 9140. A flat figure that matches the old baseline to within 0.2 percent suggests a |
| 118 | fixed per-pass cost (launch, host base-prime sieve, marker wait) dominates at this size |
| 119 | (INFERRED, not investigated; out of scope). Why the uniform run is noisier is UNKNOWN. |
| 120 | Kernel size: 88 instructions for all three; registers 29 (uniform) vs 26 (divergent). |
| 121 | The warp-simulator model predicts divergent warp issues 2.53M (util .656) and divergent2 2.01M |
| 122 | (util .830) against C5 global 2.89M (util .774) at 1e6 (model only, not chip time). |
| 123 | Correctness was the objective; this section is reported for completeness. |
| 124 | |
| 125 | ## 7a. Invariant for new GPU code (Drake, 2026-10-05) |
| 126 | |
| 127 | Any new lane-divergent code emitted for the Blackwell backend must either |
| 128 | |
| 129 | 1. wrap the divergent stretch in `region_begin` -> `region_exit` -> `region_join` and pass the host warp simulator (`build/gpu_reconv_test` plus the suite that exercises the kernel), or |
| 130 | 2. show in the kernel comment why every branch is provably warp-uniform (all 32 lanes take the same path), as the C5 sieve mark loop does. |
| 131 | |
| 132 | A SHFL or BAR.SYNC that depends on a lane-divergent branch without an enclosing region is a defect, not a style choice: on the chip the dropped-BSYNC mutant returned 466 of 1000 words wrong with no error (evidence/gpu-reconv-308/T1b-*). The emitter refuses the cases it can see (section 3); the simulator catches the rest. Reviewers should ask for one of the two proofs on every PR that adds a predicated branch. |
| 133 | |
| 134 | ## 8. What was not changed |
| 135 | |
| 136 | Production C5 sieve, branch-free attention, test thresholds, omega main. Divergent kernels are |
| 137 | opt-in (`PR_GB10_MARK`, `--divergent`). |
| 138 | |
| 139 | ## 9. Limitations |
| 140 | |
| 141 | - Only the shapes in the probes are chip-verified. BSSY/BSYNC placement other than "BSSY before |
| 142 | the divergence, every exit to the BSYNC, SHFL/BAR after the join" is not covered. |
| 143 | - R6 is refused, not proven. Barrier registers beyond 16 deep untested (and refused at 17). |
| 144 | - Control-op latency metadata is documented, not enforced. |
| 145 | - Chip runs were taken on one machine (GB10, driver and kernel in each receipt's device.txt). |
| 146 | |
| 147 | ## 10. Reproduce |
| 148 | |
| 149 | make build/gpu_reconv_test PHYSICS_DIR=../physics-reconv-lock |
| 150 | sh tools/run_gpu_reconv_chip.sh [OUT] [-- --observe-dropped-join] |
| 151 | build/gpu_attention_test [--divergent] [--sweep] --out receipt.json |
| 152 | PR_GB10_MARK=divergent bench/prime_race/build/gb10_native --limit 1000000 --audit-passes 5 |
| 153 | |
| 154 | Chip runs need a quiet window and the GPU lock (/tmp/aien-gb10.lock). |