Skip to content

An accumulator releases from one lane a warp, and the 512 arrivals it replaces measured as nothing - #218

Merged
feitreim merged 2 commits into
mainfrom
acc-lane-guard
Aug 6, 2026
Merged

feitreim merged 2 commits into
mainfrom
acc-lane-guard

Conversation

@feitreim

@feitreim feitreim commented Aug 6, 2026

Copy link
Copy Markdown
Owner

Closes out the review flag #197 left as "the most concrete follow-up here".

release_accumulator had every lane of every epilogue warp arrive on empty,
for a fact that is one per warp: a warp is done with the accumulator when its
last tcgen05.wait::ld has retired, and that instruction retires the warp's
loads and not the lane's. #197's split doubled the epilogue's warps and doubled
the count with them — 256 arrivals a slot to 512, against oxide-train's 8 — on
the barrier between an accumulator's drain and the next item's MMA.

It is worth nothing, measured. It ships guarded anyway, because one arrival
a warp is what the code means and 512 was an accident of where the guard was
not.

The arrival-count arithmetic

The guard is a lane test; the count empty is armed with is the same statement
read from the other end, so both move together or the kernel deadlocks.

entry before after
[256, 256], [512, 256] — RANKS · epilogue_warps(2) 2 · 8 · 32 = 512 2 · 8 = 16
[256, 128] — RANKS · epilogue_warps(1) 2 · 4 · 32 = 256 2 · 4 = 8

Nothing else arrives on empty at either entry:

  • The [512, 256] epilogue's two halves are two slots of the same ring
    signalled by the same call, which is why Large::epilogue stops spelling the
    arrival itself and calls release_accumulator(half) — SemaphoreRing<2>::sem
    takes the index mod 2, so sem(sequence) at the one-accumulator entries and
    sem(half) at the two-accumulator one are the same call. One lane guard now
    covers both entries and both slots.
  • The epilogue and the MMA warp break their item loops on the same
    has_work == 0, read from the same shared cell by all 32 lanes, so a warp
    leaves as a warp and a launch's last item leaves no half-signalled slot.
  • The [512, 256] early release inside multiply_at is a wait, not an
    arrival.

What makes the guard legal is [Common::drain]'s closing warp::sync_mask:
past it, no lane of the warp still has the accumulator in flight, and nothing
else in the drain reads tensor memory.

The A/B, which is same-container

bench sol-ablate grows a table 7 — both arms at the shipped geometry and the
shipped drain, differing in one const, run round-robin against the no drain
control at their own 320 threads. Two whole passes, because what is being looked
for is a barrier's micro-cost.

4096³ [256, 256] 8192³ [512, 256]
launch, all lanes 0.0980, 0.0969 ms 0.5385, 0.5387 ms
launch, one lane a warp 0.0979, 0.0980 ms 0.5384, 0.5387 ms
ratio 1.001, 0.989 1.000, 1.000
drain, all lanes → one lane 3.46 → 3.42, 3.16 → 3.43 µs 3.13 → 3.11, 3.19 → 3.19 µs

At [512, 256] the two arms agree to four figures in both passes. At
[256, 256] the two passes disagree in sign, and by less than that shape's own
pass-to-pass spread on a fixed arm — the all-lanes row alone moves 0.0980 to
0.0969, 1.1%, which is larger than the 1.1% the second pass reads as a
difference. So this is a measured null, not a small win.

The reading is that 512 arrivals cost nothing because nothing serializes them:
an mbarrier.arrive is one atomic increment against a shared-memory word, the
32 lanes of a warp issue theirs in one instruction, and the MMA warp's
empty.wait is a parity spin that the last arrival ends whichever lane it came
from. The count was never the term.

(One footnote on that run: its arrivals column printed 256 and 8, the
one-warpgroup counts, because the helper feeding it divided thread counts
instead of naming the warpgroups — threads is affine in the warpgroups, not
linear. Display only, and fixed in this PR. The kernels derive their own count
at compile time from their own GROUPS, and a wrong one deadlocks rather than
mismeasures — both arms ran and both are on check.)

Cross-container, which says less

bench --case gemm-sol, main and this branch, cuBLASLt FP16 taken in each
container:

shape entry main this branch cuBLASLt, main → branch ratio main ratio branch
4096³ [256, 256] 0.0970 ms 0.0963 0.0843 → 0.0836 (−0.83%) 0.869 0.868
8192³ [512, 256] 0.5382 ms 0.5396 0.5133 → 0.5120 (−0.25%) 0.954 0.949
16384³ [512, 256] 4.1100 ms 4.1142 4.0681 → 4.0649 (−0.08%) 0.990 0.988

Read the same-container table and not this one. The denominator moved
0.08–0.83% between the two containers, in the same direction and by more than
either arm's own difference at every shape — where #197's pair held to 0.04% at
the two large shapes, this one did not. Every row here is inside that drift, and
all three rows of the shipped kernel are checked exact against the CPU reference
before they are timed.

bench sol-ablate could not run at all before this

Worth flagging separately, because it is a live regression on main rather than
something this change touched. #197 pinned the thirty-three ablation probes to
ONE_WARPGROUP so the ladder would keep comparing against what it always did,
and took the shipped kernels to 320 threads. But Arm::Whole launches the
shipped kernel
, and its thread count went to the pinned ONE_WARPGROUP with
the probes — so table 1's first row asked for 192 threads from a kernel whose
launch contract requires 320, which validate_static rejects rather than runs:

FAIL  gemm_sol_m256: block (192, 1, 1) does not match required block (320, 1, 1)

Table 1 died there and every table after it was lost. Verified on ac79127
before touching anything. whole gets pinned probes of its own —
gemm_sol_m256_whole, gemm_sol_m512_whole, at ONE_WARPGROUP and 192
threads — which is what #197 intended for the other thirty-three, and keeps
tables 1/2/4/5 from silently comparing a 320-thread whole against 192-thread
companions. Arm::Wg2 is the shipped kernel's own row and always was.

Registers

scripts/modal-run regcount, gate green, zero stack and zero spill on every
gemm_sol rung
including both new arms:

kernel                               threads  wants  regs  ceiling  headroom  allows
examples/gemm_sol_m256                   320      1    82      168        86       2
examples/gemm_sol_m256_n128              192      1    80      255       175       4
examples/gemm_sol_m512                   320      1    95      168        73       2
experiments/gemm_sol_m256                320      1    82      168        86       2
experiments/gemm_sol_m256_n128           192      1    80      255       175       4
experiments/gemm_sol_m512                320      1    95      168        73       2

gemm_sol_m512 moves 83 → 95 and gemm_sol_m256 does not move at all (82
before and after, main measured with the same tooling). The two table-7 arms,
compiled in one crate in one build, say the guard is what did it rather than the
Large::epilogue dedupe: gemm_sol_m512_wg2 84 against
gemm_sol_m512_wg2_lane 95, both at zero spill and zero stack. Residency is
fixed by the shared plan either way — the step at 320 threads is 168 registers
and 95 leaves 73 of headroom — and the arm that carries the +11 is the one that
times identically to four figures at 8192³, twice.

Gates

  • scripts/modal-run build — clippy clean on all four manifests, sm_100a
    codegen for device-tests, examples and experiments, ptxas clean.
  • scripts/modal-run regcount — occupancy gate green, table above; no .local
    on any shipped entry or either new arm.
  • bench --case gemm-sol — all three entries checked exact against the CPU
    reference before timing, all green.
  • bench --case sol-ablate — every table, both passes; the two new arms are on
    check (Arm::EXACT_DRAINS) because they compute the same C.
  • scripts/fmt --check clean.

… replaces measured as nothing

`release_accumulator` had every lane of every epilogue warp arrive on `empty`,
for a fact that is one per warp: a warp is done with the accumulator when its
last `tcgen05.wait::ld` has retired, and that instruction retires the warp's
loads and not the lane's. #197's split doubled the epilogue's warps and doubled
the count with them -- 256 arrivals a slot to 512, against oxide-train's 8 --
on the barrier between an accumulator's drain and the next item's MMA. It was
the most concrete follow-up that PR's review left, and it is worth nothing.

The guard is a lane test and the count `empty` is armed with is the same
statement read from the other end, so both move together:

  [256, 256] and [512, 256]   RANKS * epilogue_warps(2) * 32 = 512  ->  16
  [256, 128]                  RANKS * epilogue_warps(1) * 32 = 256  ->   8

Nothing else arrives on `empty` at either entry. The `[512, 256]` epilogue's
two halves are two slots of the same ring signalled by the same call -- which
is why `Large::epilogue` stops spelling the arrival itself and calls
`release_accumulator(half)`, so one lane guard covers both entries and both
slots. The epilogue and the MMA warp break their item loops on the same
`has_work == 0`, so a launch's last item leaves no half-signalled slot behind.
What makes the guard legal is the drain's closing `warp::sync_mask`: past it,
no lane of the warp still has the accumulator in flight.

`bench sol-ablate` table 7 is the A/B, both arms in one container, round-robin,
two passes, against the `no drain` control at the same 320 threads:

  4096^3 [256, 256]   all lanes 0.0980, 0.0969 ms   one lane 0.0979, 0.0980
                      ratio 1.001, 0.989   drain 3.46 -> 3.42, 3.16 -> 3.43 us
  8192^3 [512, 256]   all lanes 0.5385, 0.5387 ms   one lane 0.5384, 0.5387
                      ratio 1.000, 1.000   drain 3.13 -> 3.11, 3.19 -> 3.19 us

At [512, 256] the arms agree to four figures in both passes. At [256, 256] the
passes disagree in sign by less than that shape's own spread on a fixed arm --
the all-lanes row alone moves 1.1% between them. It is a null: an arrival is
one atomic increment on a shared word, a warp issues its 32 in one instruction,
and the waiter is a parity spin that does not care how many ended it. It ships
guarded anyway, because one a warp is what the code means.

`bench sol-ablate` also could not run at all before this. #197 pinned the
ablation probes to ONE_WARPGROUP and took the shipped kernels to 320 threads,
but `Arm::Whole` launches the shipped kernel and kept asking for 192 -- which
the launch contract rejects rather than runs, so table 1 died on
`block (192, 1, 1) does not match required block (320, 1, 1)` and every table
after it was lost. `whole` gets pinned probes of its own at the geometry every
ladder here is held at, which is what #197 intended for the other thirty-three.

regcount: the gate is green and every `gemm_sol` rung reads zero stack and zero
spill. `gemm_sol_m512` moves 83 -> 95 registers and `gemm_sol_m256` does not
move at all, and the two arms in one crate say the guard is what did it --
`gemm_sol_m512_wg2` 84 against `gemm_sol_m512_wg2_lane` 95. Residency is fixed
by the shared plan either way; the step at 320 threads is 168 and 95 leaves 73.
@feitreim
feitreim merged commit 3ae07a8 into main Aug 6, 2026
feitreim added a commit that referenced this pull request Aug 7, 2026
…is a gate (#225) (#229)

* The jump tables were #219's after all, and the census that missed it is a gate (#225)

Three readings of `regcount`'s jump-table census, each from a build that
`_freshen` (#228) forced and whose four crates are seen to recompile in the
container log, same image and same pinned nightly:

    3ae07a8   #218, before the access ladder        0 of 309
    bda3329   after #219, before #227              55 of 318   (9 shipped)
    09beda9   main, after #227                      0 of 319

#219 introduced every `brx` in this tree and #227 removed every one of them,
which is the consumer's bisect exactly. #227 reported the opposite -- 51 already
present at 3ae07a8, identical counts across its own fix -- from a comparison
taken across the warm cache volume #228 later found serving stale builds. Both
numbers are superseded. 3ae07a8 has no `AccessWidth` to match on at all, so
zero is the only count that tree can produce.

Half of #225's "necessary but not sufficient" survives and half does not. No GPU
entry point mounts the cache volume (#226), so #227's B200 runs at then-main
really were runs of the 55-table tree and those modules really did load.
`shared_drain_quad` is the half that goes: it was added on the fix branch, after
the fix had put both drains back on a three-case dispatch, so it has never
carried a table and it is inside main's 0 of 319. Its doc said it demonstrated a
JIT taking four of them; it demonstrated nothing of the kind, and now says so.

So the census arms on the condition it set for itself. A kernel in the shipped
set -- `examples/` plus `GATED_KERNELS` -- carrying a `brx` fails the run;
probes are printed and do not, the way the local-memory depot's are. The table
stays as the diagnostic.

Watched in both directions: green at this branch (0 of 319) and red at bda3329's
sources under the same armed `modal_app.py`, naming the nine shipped kernels.

* The access ladder's note carries the in-tree numbers, not only the consumer's
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant