Skip to content

The item boundary was the epilogue, and BLOCK_K was already right - #114

Merged
feitreim merged 1 commit into
mainfrom
ablation-ladder-blockk
Jul 29, 2026
Merged

feitreim merged 1 commit into
mainfrom
ablation-ladder-blockk

Conversation

@feitreim

Copy link
Copy Markdown
Owner

Phase 1 is an ablation of the shipped kernel; phase 2 is the BLOCK_K sweep. Both are in bench, both keep their losers, and examples/README.md §7 has the tables.

Phase 1 — the boundary, ablated rather than fitted

bench --case ablation takes a phase out of the shipped kernel and measures what the launch stops costing. That is the exposed cost by subtraction, where gemm-depth's intercept only infers it and #108's 2x measures the serial cost instead. Rungs are corners of {loads} × {mma} × {drain}, so each phase is priced in more than one context — which is what tells serial and exposed apart rather than assuming either. Every rung is on the shipped geometry with M = N = 8192; only whole computes a GEMM and the rest say UNCHECKED in their own labels.

At 8192³, per output tile on the critical path:

µs
epilogue, with the multiply beside it 20.43
epilogue, without it 20.59
ratio 1.01×
#108's 2x, serial, another session 21.4

Nothing overlaps the epilogue. Both of my pre-registered predictions (4–12 µs exposed; 1.5–4× hidden) are refuted, and so is #109's reading that the epilogue is partly overlapped and the fit sees its residue.

The no drain rung has no fixed per-tile cost at all — −0.6 / −0.2 / +1.8 µs across the three point selections, against whole's 18.0 / 22.9 / 25.0. So the item boundary is the epilogue: the barrier re-arm, the two cluster boundaries and the pipeline refill are all inside the K-proportional term. #90's five-member chain names the right members and gets the weights wrong.

The framing question in the brief, answered. The asymptote-equals-cuBLASLt reading is not an artifact of point selection — there is now a rung that reaches it with no fit:

whole no drain cuBLASLt
8192³ TFLOP/s 1491 1850 1808
K = 32768 TFLOP/s 1710 1841 —
% dense bf16 peak 66% 82% 80%

The epilogue is 111% of the entire gap to cuBLASLt at 8192³. Every other term this file has ranked lives inside the part of the kernel that is already faster than the library.

stmatrix's ceiling is real. #109 asked: if the store half is mostly hidden, 6.2% is an overestimate. It is not hidden — the epilogue is exposed at 1.01× — so 6.2% stands.

Evidence each rung measures what it names (#101's standard). A PTX opcode census per entry function: no_drain keeps all four chained tcgen05.mma and loses every LDTM, store and cvt; no_mma is the mirror; dry is the only rung with a bare mbarrier.arrive and no TMA. Plus regcount on every entry point, and the ladder's own monotonicity.

Three corners do not run, and it is recorded as an observation rather than a mechanism: every rung with the epilogue on and the loads off fails to return. Two were launched and stopped by hand; their neighbours run. My first explanation was wrong (the second hang issues no MMA). It costs the sweep the operand traffic's exposed cost — its 33% is a serial number and should not be ranked against the others.

Phase 2 — BLOCK_K

It cannot be swept as a walk width. k_walk carries const { assert!(C * E::BYTES == S::ATOM_BYTES) } and Swizzle128B is the only mode in tree, so 64 is what a walk is at bf16. A wider stage is several atoms walked in turn. It also does not move arithmetic intensity. And the shared budget caps BLOCK_K × STAGES, so every extra atom is a stage given back — making this a factorization, not an axis.

rung K in flight shared B 8192³ 16384³
k64 s1 64 32 824 821.3 894.1
k128 s1 128 65 592 1135.1 1273.0
k64 s2 128 65 608 1326.4 1527.0
k64 s3 — shipped 192 98 392 1479.5 1642.7

Doubling BLOCK_K at fixed depth is worth +38% (predicted +5–20%, refuted upward) — too large for barrier issue, and the mechanism is halved exposure to load latency, not halved fixed cost. But at equal bytes and equal residency two shallow stages beat one deep one by 14–17%. So the budget belongs in stages, and BLOCK_K = 64 was already right, for a reason this file had not stated.

Checks

Two sweeps, and the first retires a decomposition this file has carried
since #86.

`bench --case ablation` takes a phase *out* of the shipped kernel and
measures what the launch stops costing — the exposed cost, by
subtraction, where `gemm-depth`'s intercept infers it and #108's `2x`
measures the serial cost instead. Rungs are corners of
{loads} x {mma} x {drain} so a phase is priced in more than one context,
which is what tells serial and exposed apart rather than assuming either.

At 8192³, per output tile: the epilogue costs 20.4 us with the multiply
beside it and 20.6 without — a ratio of 1.01, against #108's serial 21.4
by a route sharing none of this arithmetic. Nothing overlaps it. And the
`no drain` rung's own fit has no fixed per-tile cost at all, so the item
boundary is the epilogue and the barrier re-arm, the cluster boundaries
and the pipeline refill are all inside the K-proportional term.

`no drain` measures 1850 TFLOP/s at 8192³ and 1841 at K=32768 — 82% of
dense bf16 peak, flat across a 4x change in depth — against cuBLASLt's
1808 in the same container. The epilogue is 111% of the whole gap to the
library, so the asymptote-equals-cuBLASLt reading is not an artifact of
point selection: there is now a measured rung that reaches it with no
fit. And #109's 6.2% ceiling for `stmatrix` is real rather than an
overestimate, which is the question that section left open.

Both of my pre-registered predictions were refuted and are kept as
written. Three corners do not run: every rung with the epilogue on and
the loads off fails to return, the first explanation for it was wrong,
and `Ablation::at` records the observation rather than a mechanism.

BLOCK_K is pinned at 64 by `k_walk`'s one-atom assert, and does not move
arithmetic intensity, so the sweepable quantity is the factorization of
BLOCK_K x STAGES under a fixed shared budget. Two new rungs give an
equal-bytes, equal-residency control pair: doubling BLOCK_K at fixed
depth is worth +38%, but two shallow stages beat one deep one by 14-17%,
so the budget belongs in stages and 64 was already right — for a reason
this file had not stated.

gemm_cg2 is 166 registers, 0 spill, 528 B — byte-identical to #109
across both refactors. Every rung of the tile sweep and both new entry
points are exact on the gate at all three traversal widths.
@feitreim
feitreim merged commit 933f6b5 into main Jul 29, 2026
3 checks passed
feitreim added a commit that referenced this pull request Jul 29, 2026
… them (#15) (#116)

#114 left one lever: the epilogue is the whole item boundary, it is exposed
rather than hidden, and the epilogue-free kernel already beats cuBLASLt. So
`Tile::drain_staged` — TMEM -> registers -> `stmatrix` into a per-warp [32, 64]
bf16 tile -> 16-byte stores — beside `Tile::drain`, as `Epilogue::Staged`.

Both kernels compute the GEMM and both are on the correctness gate; the shipped
default is unchanged, so every number in §7 stays quotable against one kernel.

**+8.0% / +4.2% / +1.9%** at 4096³ / 8192³ / 16384³, to 0.856 and 0.893 of
cuBLASLt. On the epilogue itself, by #114's own `whole - no drain` subtraction
at a fixed envelope: **-19.0% / -19.6% / -24.4%**, with the `lcf` arm
reproducing #114's 20.43 µs a tile at 20.14.

**The arithmetic the issue was scoped from is wrong** and the corrected table
is in `Tile::drain_staged`: total memory issue is 128 instructions a thread in
*both* arms, because `store_shared_rows`' chunk copy is a `ld.shared` and a
`st.global`. The gain is entirely that global stores fall 4x and land on full
128-byte lines. The ~6.2% ceiling assumed the stores halved; 4.2% arrived.

**It costs -124 registers** (166 -> 42, no spill): a block-at-a-time
LDTM -> `stmatrix` never materializes the band `store_rows`' slot-major walk
forces live. Residency is unmoved — 114 816 B is still 2 CTAs an SM, counted by
a new census rung and controlled for by `gemm_cg2_staged_no_drain`, which
differs from `gemm_cg2_no_drain` in 16 424 untouched bytes and 0.4%.

`gemm_ws` carries the same epilogue and gains **2.5-4.1%**, which is the control
that says the win is the store's shape and not its placement: that kernel's
epilogue was already deferred and already on warps of its own.

`regcount` grows a per-entry-function PTX opcode census, so #114's dead-code
defence is a standing check rather than a paragraph.
feitreim added a commit that referenced this pull request Jul 29, 2026
…and the epilogue was never gemm_ws's problem (#118) (#119)

`.x8` LDTM and `stmatrix.x4` on `gemm_ws`, plus the two `no drain` controls the
ladder is subtracted from, and the result is a lever that pays and a hypothesis
that dies.

The levers. Against #116's `staged`, `.x8` is +15.7% / +6.2% / +3.0% at
4096/8192/16384 cubed and `.x4` is +1.2% / +0.0% / +0.1% — the same clean null
it was on `gemm_cg2`. They do not compose here: `staged8` and `staged84` are
within 1.1% and trade places between sessions, and the register column said so
in advance, `.x4` recovering 2 registers (94 -> 92) where on `gemm_cg2` it
recovered 14 (94 -> 80) and that recovery *was* the composition gain. Best rung
is +19.4% / +9.5% / +5.2% over the shipped register epilogue, 0.615 -> 0.726,
0.782 -> 0.856, 0.810 -> 0.852 of cuBLASLt. Zero spill in every rung; 94 is the
largest count in the file against a reachable 255.

#117's mechanism predicted the shortfall and got it. `.x8` removes a latency
the drain never overlaps; this kernel already overlaps it, so `.x8` is worth
67%, 72% and 83% of what it was worth on `gemm_cg2`. By `whole - no drain` the
same epilogue is exposed at 8.62 us a tile here against #114's 20.43, and its
LDTM half at 3.20 against #117's 8.07 — 40-47%, which is what warp
specialization and the accumulator ping-pong buy, stated as a number for the
first time.

"Twice the LDTM (16 against 8)" is true of the PTX and false of the work. Every
census column doubles, not just LDTM, because `gemm_ws` emits its epilogue at
two call sites (`Ws::work` and `Ws::finish`) where the fused job has one. The
bands are `RegTile<32, 64>` in both files.

The floor is the finding. `gemm_ws_no_drain` — the shipped kernel with the
epilogue deleted, the probe that put `gemm_cg2` at 1850 TF/s against the
library's 1808 — reaches 0.829 / 0.923 / 0.888 of cuBLASLt, and at 8192 and
16384 cubed it is *slower than `gemm`'s complete `staged84` launch*. Best
against best is -9.7% / -9.4% / -6.9%; deleting the epilogue outright recovers
12.7 / 7.2 / 3.9 of those points. So no, `gemm_ws` does not beat `gemm`, and it
could not have: #112's 7.3% closes to 6.9% after both kernels spent everything
#116 and #117 found. The deficit is the multiply and the operand stream at one
CTA an SM. #112 blamed the peer CTA and #114 refuted it; `gemm_ws.rs` blamed the
missing peer CTA and this refutes that, by deleting the epilogue and losing
anyway. The stale paragraph is corrected in place rather than removed.

Residency counted, not queried (#77): two new census rungs at this kernel's own
131 176 B and 147 584 B read 1 resident, 1 holding at both, closing the gap the
`cg2 512` rung left at a 32 B plan (1 holding, 2 resident, 100.9 us parked in a
blocking alloc; 0.9 us here).

No default moved. `staged8` is the rung to ship on `gemm_ws` — `.x4` is a null
here alone and in composition — and that is a change worth making on its own.
feitreim added a commit that referenced this pull request Jul 29, 2026
#121)

* The 1.02 ceiling is an 8192-cubed fact, and the residual is stmatrix's

Nothing measured. Everything re-measured. `bench residual` re-runs #114's ceiling,
the shipped rung and cuBLASLt beside each other in one container, twice, and then
opens the residual epilogue with a doubling ladder that deletes nothing.

**The framing survives at 8192^3 and only there.** `no drain / cuBLASLt` is
1.024 and 1.018 in two fresh containers, so #114's 1.02 reproduces after both of
the changes that could have invalidated it, and the epilogue is 127-136% of the
6.5% gap. At 16384^3 the same ratio is 0.993 and 0.984 -- the epilogue-free
kernel LOSES -- so 10-23% of that gap is not epilogue. At 4096^3 it is
0.955/0.988 and the rest is the wave, which is a different mechanism and is
reported as one. Below 2048^3 cuBLASLt's own MINIMUM moves 23-26% between two
calls in one session, so no ratio there is a measurement.

**What is inside the ~7.3 us/tile, at 8192^3, both sessions:**

| | us/tile | share | lever |
| --- | ---: | ---: | --- |
| `cvt` + `stmatrix` | 3.8-4.1 | 55-64% | **none identified** |
| `ld.shared` + `st.global` | 2.0-2.3 | 31-36% | a TMA store, ~+2.7% |
| LDTM after `.x8` | 0.09 / -0.04 | 0% | spent by #117 |
| unattributed | 0.8-1.5 | 9-20% | -- |

The instrument is `Tile::drain_staged_twice`, which ADDS one link of the chain
per rung rather than removing one, because an epilogue nobody observes is one
the compiler may delete. The census says every rung stepped by exactly one pass
and that the second `.x8` LDTM survived CSE despite being spelled `_pure`.

**Two negative results, each retiring a lever.** `s84 hot` deletes the
epilogue's entire HBM traffic and is worth -2.3% to +1.8%: the stores are not
bandwidth-bound, so #15's "hand the write to a TMA engine so it stops pressing
on memory" has no pressure to relieve -- what is left to buy is the issue, and
that is a smaller and different claim. And `.x8` on the REGISTER drain
(`gemm_cg2_lcf8`, new, on the correctness gate, 166 registers byte-identical to
`gemm_cg2`) is a clean null at -1.1% to +5.8%, against +23.6/+8.6/+3.6% on the
staged path -- the scattered stores were already covering the LDTM latency.

**One positive one.** That null is the arm #116's A/B never had, and it re-prices
the shared round trip at #117's LDTM width: `staged8` beats `lcf8` by
**+12.6%/+12.8%** at 8192^3 where #116 measured +4.2% at `.x1`. The hop is worth
three times what it was measured at, because recoalescing only gets paid once
the drain has stopped waiting sixteen times a band.

**And a control this file has never taken.** Table 6 takes the same
`whole - no drain` subtraction twice in one container: it reproduces to 1-5% at
8192^3, 0.4-7% at 4096^3, and **39-46% at 16384^3**. Every 16384^3 epilogue
figure above it -- #116's 16.34, #117's 5.81, #118's 2.91 -- is inside that band
and none of them carries it. It is also why `staged8` and `staged84` trading
places here does not contradict #117 so much as locate it: that +1.5-point
composition gain was a 16384^3 row.

New: `Tile::drain_staged_twice`, `Tile::drain::<WIDE>`, five entry points
(`lcf8`, `s84 hot`, `s84 2g/2m/2x`), `bench --case residual`, six tables. No
default, constant or shipped kernel moved; `lcf8` is on the correctness gate and
the four probes say UNCHECKED in their own labels. `build`, `regcount`
(occupancy gate green, 80/87/125/102 and 166) and `examples` all pass.

* and the cvt travels with the stmatrix, so the column says so
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