Repository navigation
C is bf16, the accumulator is not, and the baseline moved with it (#108) - #109
Merged
Merged
Conversation
feitreim
added a commit
that referenced
this pull request
Jul 29, 2026
Tier 1 checks the library, device-tests and examples. A root `cargo fmt` reaches only the first -- the other two are separate workspaces -- so a change can be clean locally and red in CI on whitespace alone. That has happened three times (#97, #104, #109), each costing a review round trip on a gate that runs in twenty seconds.
feitreim
added a commit
that referenced
this pull request
Jul 29, 2026
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
added a commit
that referenced
this pull request
Jul 29, 2026
…#109's 8.3 us closes to 8.07 (#117) (#117) * The LDTM half at .x8 and stmatrix at .x4, ablated against #116's staged epilogue (#117) * Measure it: .x8 is +23.6/+8.6/+3.6%, .x4 alone is nothing, and #109's 8.3 us of LDTM closes to 8.07 * const assert uses is_multiple_of, which clippy requires and WIDTH_OK already used
feitreim
added a commit
that referenced
this pull request
Jul 29, 2026
…ce (#119) (#120) `gemm`'s default epilogue becomes `staged84` and `gemm_ws`'s becomes `staged8`. #116, #117 and #118 each ended by saying the rung was worth shipping and that shipping it belonged in its own change; this is that change and it is the whole of it. No rung added, none deleted, nothing retuned — every entry point still launches and is still on the correctness gate. The two differ on purpose. `.x8` costs +52 and +50 registers identically; what differs is what `.x4` hands back — 14 on `gemm_cg2` (94 -> 80) and 2 on `gemm_ws` (94 -> 92) — and that recovery IS the composition gain. There the pair is +5.1% at 16384^3 against `.x8` alone's +3.6%; here `staged8` and `staged84` land inside 1.1% and trade places between sessions, so the tie goes to the rung with less surface. Confirmed in one container with cuBLASLt re-measured in it (#109's lesson): `gemm` 0.1432 -> 0.1044, 0.7584 -> 0.6684 and 5.5157 -> 5.0132 ms, which is +37.2% / +13.5% / +10.0% and 0.583 -> 0.801, 0.827 -> 0.939 and 0.871 -> 0.958 of the library. `gemm_ws` +19.6% / +8.7% / +6.3% and 0.599 -> 0.717, 0.790 -> 0.858, 0.812 -> 0.863. Both reproduce their published ratios; the 16384^3 rows moved because the denominator did. The constants that describe the shipped launch moved with it: `main.rs` reports 114 816 B and 147 584 B, and `CTAS_PER_SM` does not move on either kernel because the tensor-memory term of `min(512 / columns, shared per SM / plan)` binds at both envelopes. `regcount`'s occupancy gate gained `gemm_cg2_staged_x8x4` and reads 166 / 42 / 80 against a ceiling of 255. Deliberately unmoved: the ablation cube, `bench --case epilogue` and `bench --case staged` stay built at `lcf`, and `ws_bench` table 1 now NAMES `lcf` on both sides rather than taking `gemm`'s default, so its one variable is still where the overlap comes from.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
gemm_cg2writes bf16Coff an unchanged fp32 accumulator, andcublaslt.rs's output layout moves toCUDA_R_16BFin the same commit.Both columns, measured together, with an fp32 control run back to back
Four B200 containers in one session. The control is
a68c390itself —the commit before this one, fp32 on both sides — through the same
bench --case gemm. cuBLASLt's heuristic returned a byte-identical algorithmat every size in both runs, so nothing here is a different kernel.
One pair of containers is not enough to read those rows. The branch was
measured three times at 8192³ — 0.7344 / 0.7456 / 0.7440 — against the control's
single 0.7489, so the gain is +0.4% to +2.0%, about +1.1% on the mean,
against a 1.5% cross-container spread. At 16384³ the three bf16 measurements
straddle the control (5.2326 / 5.5193 / 5.4765 vs 5.4025).
So: bf16
Cis throughput-neutral, and both pre-registered predictions hold.−1% to +1.5% was predicted and ~+1% measured; 0 to −3 ratio points were predicted
and the ratio is 0.812–0.825 against 0.823, flat to two points down. The library
gains at least as much from the cheaper output as we do — which is exactly why
moving only our side would have manufactured a win: against the published fp32
ratios this would have read as +3.6% and +4.9%.
Which prior rows survive: almost none. Every
ours/theirsratio in §7 —#92's 0.573–0.694, #102's 0.742/0.793, #87's 0.826/0.886, #107's 0.824–0.881 —
is a pair of fp32-output measurements, as is every absolute millisecond. What
survives is everything that is a property of the tile: counted residency,
registers,
GROUP, the shared plan, wave efficiency,wave_reuse. §7 says sowhere the numbers are.
The small-size rows moved a lot and none of it is readable — #92 measured
cuBLASLt's own run-to-run variance below 2048³ at 33–77%, and every delta down
there is inside the variance already documented for its own side. Our ratio at
256³ goes 0.336 → 0.463, and that is the baseline getting worse.
Accuracy: the tolerance did not move, because there is still none
The comparison is still
==, at every element, for both sides. The roundingwent into the reference:
check_crounds the exact fp32 dot product with thesame round-to-nearest-even
cvt.rn.bf16x2.f32uses and compares 16-bit words.That is available because the sum is still exact — every partial stays under
2²⁴ — so rounding a known integer once is deterministic.
Worst relative error against the exact fp32 reference: 3.86e-3 (2⁻⁸, as
predicted), reported by
check_crather than asserted, printed on every checkedsize. Widening the observed value and comparing within a tolerance would have
been strictly weaker: a tolerance admitting correct rounding admits everything
under it. What the check is now blind to is stated in
check_c— errors underabout half an ulp of bf16; no failure mode this gate exists for is in that range.
Registers, spill, residency
gemm_cg2is 166 registers, 0 spill, 528 B frame — the gate reads 166against a ceiling of 255. Prediction 3 said 168 and unchanged; the count moved
in both directions (
lcsfis 172), which is the seventh time the registercolumn has failed to say what it was expected to here. Nothing follows it.
Residency is 2 CTAs an SM, counted not assumed — #87's census counted 2 at
exactly this envelope and this change moves neither term of
min(512/columns, shared per SM/plan). No new census rung was run, deliberately.stmatrix: reachable, no plumbing left, and worth at most ~6%Reachable — the estimate #94 rejected it on is now zero.
ldst::store_tile,SharedTile::tma_store_2dandTensorMapElement for Bf16already exist; allthree of #94's missing pieces were the same fact, which was that
Cwas fp32.Priced, not assumed. Two new probes:
2xruns the epilogue twice per item,2sruns the LDTM once and the stores twice, both aimed at the cluster's hometile.
2x − lcfis one epilogue,2s − lcfis one store loop,2x − 2sis theLDTM — no fit, and nothing deleted for a dead-code pass to have a say in.
Prediction 6 (5–12 µs) is refuted by about 2×, and how it is wrong is the
useful part. 21.4 µs sits above the whole item boundary as #104 fits it
(8.6–18.3 µs), and the epilogue is only part of that boundary — which can only
be true if the epilogue is partly overlapped in the real kernel and not at all
in the probe. So
2x − lcfis the epilogue's serial cost and the fit'sintercept is its exposed residue. The pre-registration argued the bias ran
the other way.
stmatrixkeeps the LDTM and halves the stores, so its ceiling is half thestores column: ~6.2% at 8192³ and ~5.1% at 16384³ — and
gemm_cg2_2scosts255 registers (0 spill, residency unchanged), so part of that 13.11 µs may be
pressure rather than stores, making it an upper bound on an upper bound. Against
it: 18344 B a CTA is free at unchanged residency, a bf16
[128,64]strip is16384 B and fits — four single-buffered TMA round trips an item, against
eight for fp32 — with no room to double-buffer.
Verdict: a build-and-measure question rather than a plumbing one, and the
largest lever currently identified. Two things argue it delivers less than the
ceiling:
lcsf(moves when the epilogue runs) is +1.0%/+1.7%, andhot(moves where its bytes land) is +0.5%/−0.0%. Neither is a store-count
experiment, so neither refutes the 6% — but the epilogue's placement and its
bytes are both worth nothing, and only its issue count is left.
What ran
::buildand::regcount(CPU) green;::examplesexact at both sizes, allfive rungs, both schedulers,
lcsf, three traversal widths;bench --case gemmon the branch and on
a68c390;bench --case epiloguetwice. Every appconfirmed
stopped.Library change is
GlobalRows<E>plusElement::write_pair/read_pair— thegeneralization
global.rs's own module doc predicted.flash_forwardanddevice-testsstill write fp32 through the same movers, so the losing sidestays reachable and on the gate; an fp32
gemmentry point is not kept, and §7says why.
Closes #108.