Skip to content

The accumulator is released at the load that last read it, and the entry that cannot ping-pong says why (#221) - #223

Merged
feitreim merged 3 commits into
mainfrom
deferred-accum-221
Aug 7, 2026
Merged

feitreim merged 3 commits into
mainfrom
deferred-accum-221

Conversation

@feitreim

@feitreim feitreim commented Aug 7, 2026

Copy link
Copy Markdown
Owner

Closes #221.

Step zero: the two surveys were each half right, and the reconciliation is that the entries differ

#221 asked for the current release semantics before anything else. They are not
one thing — they are two, and the difference is structural rather than a choice
anyone made.

The [256, N] entries are already deferred, and have been.
Small::multiply (examples/src/gemm_sol.rs:646-648) waits

if common.rank == LEADER && sequence >= ACCUMULATORS as u32 {
    common.empty.wait(sequence - ACCUMULATORS as u32);
}

and SemaphoreRing::<2>::wait(i - 2) (src/sync.rs:434) is
sem((i-2) % 2).wait(((i-2) / 2) & 1) — slot i % 2 at the phase item i - 2's
release_accumulator(i - 2) ended. That is empty(i - SLOTS) exactly, oxide-train
#86's timing, written out longhand; it is literally wait_recycled(sequence).
The 512-column allocation ping-pongs and the wait skips a generation.

The [512, 256] entry is not deferred, and cannot be. Its waits are
empty.sem(0).wait((sequence - 1) & 1) (:836-838) and empty.sem(1) at the
same generation inside multiply_at (:791-793) — both the previous item's
drain. But its two slots are not a ping-pong across items at all: they are the
item's own two 256-row halves of a 512-row macro-tile, both live for the
whole K walk. A deferred release needs a third [128, 256] slot, and
alloc_cluster::<512> is already the whole of an SM's tensor memory
(src/tmem.rs:15 — "an SM has 512"). There is no third slot to have.
docs/kernels/gemm_sol.md:165 had already said this in passing ("a one-deep
accumulator interlock per half"); nobody had connected it to #197.

Which is the reconciliation #221 asked for

oxide-train's gemm_sol_final is a one-accumulator geometry — this tree's
[256, 256]. So oxide-train PR #119's null for the warpgroup split was measured
against an already-deferred release, and #197's +2.1% was measured at
[512, 256], where the drain sits between an item and its successor entire. The
same #197 table read +0.8%/+0.9% at [256, 256]. The split's win tracks the
deferral nearly 2.5 to 1.

The arithmetic agrees to a tenth of a percent. At 8192³ the [512, 256] entry
runs 7 items a cluster in 0.5396 ms, so an item is 77 µs; #197's split cut the
drain 4.72 → 3.05 µs, and 1.67 / 77 = 2.2% against the 2.1% measured. The drain
there is exposed essentially 1:1.

What ships instead: the release moves to the load that last read the accumulator

What [512, 256] cannot defer across items it can stop paying for inside one. A
warp is done with the accumulator the instant its last band's
tcgen05.wait::ld retires — nothing below that load reads tensor memory — but
the arrival sat at the end of Common::drain, past that band's stmatrix pass
and past the ld.shared/st.global pass under it. So it moved to the last
band's load, behind one warp::sync_mask (the same sync #218's lane guard already
needs). drain now takes the slot it is draining; release_accumulator has no
call site outside it.

The interaction table — the square, one binary, same residency

bench sol-ablate table 6 is now the cross of the warpgroup split and the
release timing rather than one of them. All four corners hold ALL_LANES scope so
the only things moving are the two levers; each subtracts the no drain at its
own thread count. Two passes:

8192³ [512, 256] — the entry the target shapes use

epilogue, pass 1 pass 2 launch vs one, late
one warpgroup, late 4.69 µs 4.83 µs 1.000, 1.000
one warpgroup, early 4.32 4.50 1.005, 1.004
two warpgroups, late 3.33 3.27 1.019, 1.019
two warpgroups, early 2.86 2.79 1.025, 1.025

#221's prediction that the split's win would shrink is wrong. Two warpgroups
over one is 1.019/1.019 late and 1.020/1.021 early — the levers are additive
to within a tenth of a percent in both passes, and the best corner is both, which
is the corner that ships. The reason is in the same table: the early release takes
14-15% off the drain at two warpgroups and 7-8% at one, not the whole of it.
Three quarters of an item's drain is still standing between the accumulator and
the next MMA, and only a deferred release removes that — which is the thing this
entry cannot have.

4096³ [256, 256] — the entry that is already deferred

of one wg, pass 1 pass 2
split 1.001 0.988
early release 1.003 1.002

Both levers are nulls inside that shape's own spread — a fixed arm moves 0.0949 to
0.0961 between passes, which is larger than either effect. Which is #221 being
right about the entry it was right about.

Ratios vs cuBLASLt, three shapes

bench --case gemm-sol, ours against a cuBLASLt FP16 taken in the same process,
stream and clock. Read the ratio column: the denominator held to 0.12% across the
two containers.

shape entry ours before ours after Δ ours theirs before → after ratio before ratio after
4096³ [256, 256] 0.0949 ms 0.0943 −0.63% 0.0815 → 0.0816 0.859 0.865
8192³ [512, 256] 0.5387 0.5356 −0.58% 0.5088 → 0.5090 0.944 0.950
16384³ [512, 256] 4.1135 4.1111 −0.06% 4.0602 → 4.0647 0.987 0.989

The 8192³ row is the one table 6 corroborates in a single container: +0.6% at two
warpgroups, both passes, against +0.58% here.

Registers, and the honest cost

Zero spill and zero stack throughout, and every gated kernel is inside its step —
but this is not free:

kernel                        threads  wants  regs  ceiling  headroom  allows
examples/gemm_sol_m256            320      1    92      168        76       2
examples/gemm_sol_m256_n128       192      1    93      255       162       3
examples/gemm_sol_m512            320      1   112      168        56       1

Against 82 / 80 / 83 before. The barrier between the last load and its landing
gives ptxas a reason to keep more of the band alive across it. Residency here is
fixed at one CTA an SM by the shared plan (229 632 B of 233 472) and no register
count can raise it, so wants 1 is still met — but gemm_sol_m512's allows
falls 2 → 1 and its headroom 85 → 56 registers. That is the number to watch before
the next thing is added to this epilogue, and it is called out in the docs.

Correctness

  • bench --case gemm-sol checks every shape against the CPU reference before it
    is timed, at all three entries and all three shapes.
  • examples: all three entries exact over every rung, worst |rel| 3.89e-3 (bf16).
  • The two new ablation arms join Arm::EXACT_DRAINS, so check compares their
    C against the reference at both entries.

Shape of the diff

  • examples/src/gemm_sol.rs — drain takes slot and releases at the last
    band's load; the two epilogues drop their trailing release.
  • experiments/src/gemm_sol.rs — the release dial becomes two bits
    (ALL_LANES / ONE_LANE / ALL_LANES_EARLY / ONE_LANE_EARLY), same arity at
    every instantiation, so the shipped path and every arm move together.
  • experiments/src/sol_ablate.rs — Arm::PairedEarly and Arm::Wg2Early, four
    kernels, and table 6 as a 2×2.
  • docs/kernels/gemm_sol.md — two new sections under the epilogue.

…try that cannot ping-pong says why

The deferred release #221 asks for is already at the `[256, N]` entries —
`empty.wait(sequence - ACCUMULATORS)` is `empty(i - 2)`, the release item
`i - 2` made — and cannot exist at `[512, 256]`, whose two slots are one
item's two M-halves and whose allocation is already an SM's whole 512 TMEM
columns. What is left there is the release's *timing*: a warp is done with
the accumulator at its last band's `tcgen05.wait::ld`, not at the end of the
drain, so the arrival moves there and the last band's `stmatrix` and
`st.global` passes leave the next item's critical path.
…utes

`bench sol-ablate` table 6 crosses the warpgroup split with the release's
timing, and #221's prediction that the split's win would shrink is wrong: the
split is 1.019/1.019 late and 1.020/1.021 early. The early release is 14% off
the drain at two warpgroups, not all of it, and a deferred release is what the
prediction needed.
@feitreim
feitreim merged commit 05dd95a into main Aug 7, 2026
4 checks passed
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.

Port oxide-train's deferred accumulator release: the drain leaves the critical path

1 participant