Skip to content

The store stage cost a reordering to try, and it hides nothing (#15) - #107

Merged
feitreim merged 2 commits into
mainfrom
lcsf-deferred-drain
Jul 29, 2026
Merged

feitreim merged 2 commits into
mainfrom
lcsf-deferred-drain

Conversation

@feitreim

Copy link
Copy Markdown
Owner

Closes #15 for the GEMM, with a measured rejection rather than a build.

The two premises this was queued behind, both wrong

The occupancy step does not exist. The brief re-derived 233472/2 − 98392 = 18344 B a CTA free, which is right. What it misses is that since #87 CTAS_PER_SM is 2 because 256 accumulator columns are half of tensor memory — min(512/columns, shared_per_sm/plan) is min(2, 2). So shared staging up to 18344 B is invisible, not pre-paid, and above it the plan falls to one CTA an SM (#98's 25–44% cliff).

16384 B is not "a band". A [32, 128] fp32 band is one warp's share of one drain step; a CTA's per-item output is 128×256 fp32 = 131072 B. The largest staging that fits is a [128, 32] strip — eight single-buffered fill→fence→TMA-store→wait-read round trips an item, since double buffering wants 32768 B.

None of which matters, because the store stage needs no buffer

pipeline::run re-arms mbarriers and touches no tensor memory, so an undrained accumulator survives the item boundary intact. Deferring the drain one item is a reordering of phases inside Job::work. src/pipeline.rs is unmodified — lcf's scaffold already admits an lcsf job. No fp32 TensorMapElement, no fp32 swizzle, no stmatrix, no proxy fence, no occupancy step. #94 scoped 250–400 lines; the thing that had to be built to find out was not on the path to finding out.

It does need a synchronisation the boundary does not supply, which is a finding on its own: the cta_group::2 MMA is issued by the leader and writes both ranks' halves, so a bar.sync would let the leader overwrite tensor memory the peer is still draining. The pre-MMA rendezvous is cluster_sync, moved inside the item.

Measured — prediction stated first, and refuted

Predicted +4% to +11% at 8192³/16384³, nothing at 1024³. Two B200 sessions, min ms over 30 launches, static, GROUP = 8, every exact row checked element-by-element before timing:

shape items/cl lcf ms lcsf ms vs lcf session 2
1024³ 1.0 0.0288 0.0304 −5.4% −2.2%
2048³ 1.0 0.0366 0.0372 −1.6% −2.8%
4096³ 1.7 0.1447 0.1490 −2.9% −1.4%
8192³ 6.9 0.7506 0.7521 −0.2% −0.0%
16384³ 27.7 5.3869 5.4421 −1.0% +1.2%

−5.4% to +1.2%, never reliably positive. f ≈ 0, against the 0.65 #98 set as the bar. On the 16384³ sign flip the control moved 2.0% while the treatment held to 0.2% — the documented cross-run spread, not a result. The 1024³ pre-registered falsifier loses most, exactly as predicted, so the cost model is right and the benefit is absent.

The one question the cheap form leaves open, closed

The deferred drain hides {LDTM + stores} behind one pipeline fill; #15's TMEM→shared→TMA route gets the same window for its LDTM and additionally decouples the global write. Epilogue::HotStore holds the epilogue's instructions fixed and deletes its HBM traffic (38 MB rewritten in L2 vs 268 MB / 1 GB streamed):

shape lcf ms hot ms write-bound part
4096³ 0.1437 0.1437 0.0%
8192³ 0.7517 0.7502 0.2%
16384³ 5.4972 5.4293 1.2%

Deleting a gigabyte of streaming writes is worth nothing. The epilogue is issue-bound, not bandwidth-bound, so the expensive route's only remaining advantage over the cheap one is ≤1.2%. It computes a wrong C on purpose, is excluded from the correctness gate, and says so in its own launch label — the one deliberate exception to rule 1, stated rather than hidden.

Why, structurally: the accumulator is single-buffered in TMEM, so the drain must finish before the item's first MMA and the window cannot exceed STAGES of loads (a second accumulator is 512 columns = one CTA an SM). Meanwhile #98 measured a lone CTA flat at ~585–640 TFLOP/s against 900–1299 for three — the neighbouring CTA's K loop is already covering these issue slots. lcsf proposes to spend a resource inter-CTA overlap has already spent.

Costs, checked not asserted

  • Registers: gemm_cg2_lcsf at 168 / 0 spill store / 0 spill load / 528 B frame, byte-identical to gemm_cg2 and all four sweep rungs. The pre-registered prediction, and direct evidence nothing is held across the boundary. Gate reads 168 against 255.
  • Residency: 2 CTAs an SM, counted. Sweep the GEMM's pair tile and pipeline depth: [256,256] at three stages should dominate on paper #87's census counted 2 at exactly this envelope (256 columns, 98392 B, wait 0.9 µs). No byte of the plan and no accumulator column moved, so the count carries by identity. No new census rung was run, deliberately — it would have spent a B200 reproducing a number.
  • cuBLASLt: lcf control at 0.828 / 0.881 (s1) and 0.824 / 0.855 (s2), reproducing Sweep the GEMM's pair tile and pipeline depth: [256,256] at three stages should dominate on paper #87's published 0.826 / 0.886. lcsf at 0.826 / 0.872 and 0.824 / 0.866. Nothing here moves the shipped kernel.
  • Exactness: lcsf on the ::examples gate at both shapes and all three traversal widths, including 4096x4096x256 where every cluster carries a pending accumulator across boundaries and one past the loop — the way this fails silently.

What ships

gemm still ships lcf. Lcsf, HotStore, the Epilogue axis and bench --case epilogue stay, and Lcsf stays on the correctness gate — the constraint that decided this is a property of this tile, and #87 moved STAGES and BLOCK_N once already. A tile with a longer fill, or a kernel whose epilogue is genuinely latency-exposed, should re-run this rather than inherit its answer.

What this does not claim: lcsf is a bad trade for a GEMM whose accumulator is single-buffered in TMEM and whose epilogue is issue-bound. #15's original motivation — a training kernel with a producer-consumer epilogue — is a different kernel and nothing here prices it. What is established is the method: a store stage costs one reordering to try, so measure before anyone scopes a tensor map.

examples/README.md §7 has both tables and the forward pointers from the three earlier sections that promised this. lcsc, interpreter and common/templates.cuh are untouched, so #15 stays open for those unless you want it split.

feitreim added 2 commits July 28, 2026 20:11
`lcsf` was queued behind an occupancy step that no longer exists and a
staging buffer it never needed. Both premises are wrong, and removing
them makes the experiment cheap enough that the answer is a measurement
rather than an estimate.

The occupancy step: since #87, `CTAS_PER_SM` is 2 because 256 accumulator
columns are half of tensor memory, not because 98392 B is half the shared
budget. `min(512/columns, shared/plan)` is `min(2, 2)`, so shared memory
up to 18344 B a CTA is invisible rather than pre-paid. And 16384 B is an
eighth of a CTA's per-item output, not "a band" — the largest staging
that fits is a [128, 32] strip, eight single-buffered TMA round trips an
item.

The staging buffer: none is needed. `pipeline::run` re-arms mbarriers and
touches no tensor memory, so an undrained accumulator survives the item
boundary intact. Deferring the drain one item is a reordering of phases
inside `Job::work`, and `src/pipeline.rs` is unmodified — `lcf`'s
scaffold already admits an `lcsf` job. No fp32 `TensorMapElement`, no
fp32 swizzle, no `stmatrix`, no proxy fence, no occupancy step.

It does need a synchronisation the boundary does not supply: the
`cta_group::2` MMA is issued by the leader and writes both ranks' halves,
so the pre-MMA rendezvous has to be `cluster_sync` inside the item.

Measured over two B200 sessions, five sizes, static schedule, GROUP = 8,
every exact row checked element-by-element before it was timed:
-5.4% to +1.2%, never reliably positive. 8192³ is -0.2%/-0.0% and 16384³
is -1.0%/+1.2%, and on the second the control moved 2.0% while the
treatment held to 0.2%. The pre-registered prediction was +4% to +11%
and it is refuted; the 1024³ falsifier behaved as predicted and loses
most, so the cost model is right and the benefit is absent. f ~ 0,
against the 0.65 #98 set as the bar.

`Epilogue::HotStore` closes the one question the cheap form leaves open,
which is the only thing #15's TMEM -> shared -> TMA route buys over it:
holding the epilogue's instructions fixed while deleting its HBM traffic
is worth 0-1.2%. The epilogue is issue-bound, not bandwidth-bound. It
computes a wrong `C` on purpose, is excluded from the correctness gate,
and says so in its own launch label.

168 registers, 0 spill store, 0 spill load, 528 B stack frame on
`gemm_cg2_lcsf` — byte-identical to `gemm_cg2` and to all four sweep
rungs, which is the pre-registered prediction and the evidence that
nothing is held across the boundary. Residency is 2 CTAs an SM, counted
by #87's census at this exact envelope; no byte of the plan moved, so no
new rung was run.

`gemm` still ships `lcf`. The losing attempt stays runnable, on the
correctness gate at both shapes and all three traversal widths, because
the constraint that decided it is a property of this tile: the overlap
window is one pipeline fill and #87 moved `STAGES` once already.
`cargo fmt --all` at the root does not reach `examples/` — it is a separate
crate rather than a workspace member, which is why tier 1 formats all three
by hand and why this only showed up there.
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.

lcsf and the rest of the prototype layer

1 participant