Repository navigation
Price the occupancy step on a dead allocation, and #94's third is a seventh (#98) - #101
Merged
Merged
Conversation
…eventh (#98) #94 §6 rejected a shared staging buffer for the GEMM epilogue because it costs an occupancy step, and "cutting concurrency by a third to recover a fifth is a losing trade." The arithmetic was right and the premise under it was never measured: a third of the *residency* is not a third of the *throughput*. Measured by growing `gemm_cg2`'s declared shared plan with bytes no code reads or writes — 8192 to cross 3 -> 2, 49152 to cross 2 -> 1 — with `CTAS_PER_SM` moved to match. Work, traversal, instruction mix and register count identical either side; the only variable is residency. The dead allocation is an experiment and does not land. One CTA an SM is worth **14-16%**, not 33%. The cost is convex: the third CTA is worth a seventh, the second 25-44%, and at 1 CTA/SM throughput is flat at ~590 TFLOP/s across 4096^3 to 16384^3 — so over half of what this kernel achieves is overlap between CTAs. Three rungs added to `tmem residency census` at the exact envelopes, because a run where residency did not move measures nothing and the occupancy query is pinned at 1 by `tcgen05.alloc` (#77). They count 3 / 2 / 1, and the census's own verdict asserts it. #15's straight route is back on the table but not green: it breaks even only if `lcsf` hides ~70% of the item boundary.
This was referenced Jul 28, 2026
The [256,256] tile costs 18% at 1024 cubed and n % 256, and nothing picks between the two tiles
#105
Closed
feitreim
added a commit
that referenced
this pull request
Aug 6, 2026
…st picks from the shape (#105) (#209) #104 promoted the pair tile to `[256, 256] @ STAGES = 3` and stated its two costs rather than burying them: `n % 256 == 0` where 128 used to do, and 18% at 1024 cubed. Both rungs stayed launchable, so the material for a fix was already in the file. What did not exist was anything choosing between them, or any measurement to choose by — the sweep had both tiles at 8192 cubed and 16384 cubed and the crossover is somewhere below 2048 cubed, which nothing had timed. `bench --case crossover` is that measurement. Four rungs across eight shapes: the pre-#104 kernel as the denominator, `[256, 128] @ s4` to price the occupancy step at a fixed tile, `[256, 256]` fused to price the tile at a fixed epilogue, and `[256, 256]` on `staged84` because that is what actually launches. Its own case rather than a fifth table on `tile`, which costs most of an hour where this costs a minute — a measurement the next tile change has to re-take should be cheap to re-take. It was run three times, and the reason is in the answer: those rows are 12-23 microsecond launches and #98's 2.9% of drift between containers is 10-12% down there. What reproduces is the sign. 512 and 1024 cubed lose on every run, 2048 cubed and above win on every run, and 1536 cubed straddles zero — so the crossover is bracketed at 36 < T <= 64 output tiles of the wide rung. Which mechanism it is, since the issue asks rather than assumes: **the tile's parallelism, and the occupancy step is not reachable at all down there.** The same-tile arm reads -2.0%, +11.1% and +0.0% at 1024 cubed across the three runs — not a small effect measured imprecisely, no effect — and the `reached` column says why before the clock does: at 32 clusters on 148 SMs no SM is asked to hold a second CTA, so a rung admitted for 3 and a rung admitted for 2 run the identical schedule. #101's 14-16% is a price on a resource the small end is not spending. The loss tracks the SM column instead: at 1024 cubed the wide tile puts 32 SMs to work where the narrow one puts 64, and loses 8.4-11.9%. `gemm::plan_for` is the chooser, host-side beside the grid arithmetic. It thresholds on the wide rung's tile count and not on `n`, because tile count against SM count is the quantity the mechanism is about — a threshold on `n` would send 16384x512 to the narrow rung and that shape has a full grid. It picks an epilogue with the tile because it has to: `staged84` is built on the wide rung only. `bench_with` does not consult it, so every A/B's control arm still reads the rung it names. No rung is deleted. The acceptance holds by construction below the threshold — the fallback is `gemm_256x128_s3`, the pre-#104 entry point itself and not a reconstruction of it — and by measurement above it. `n = 1152` is a kernel rather than an error, `4096x4224x4096` runs at 1271.7 TFLOP/s, and `GEMM_SIZES`' `256x128x256` row is back. `check` grows the one shape class that was on no gate at all: every check size in this file divides both tiles, so the chooser's fallback route had never been computed by anything. It takes its plan from `plan_for`, so it tests the rule and not only the rung it happens to pick.
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.
Closes #98.
#94 §6 rejected a shared staging buffer for the epilogue because it costs an
occupancy step, and "cutting concurrency by a third to recover a term now worth
20–22% is a losing trade." The arithmetic is right. The premise under it —
that a third of the residency is a third of the throughput — had never
been measured. This measures it.
Method
The declared shared plan of
gemm_cg2grows by bytes that no code reads orwrites: 8192 to cross 3 → 2 CTAs/SM, 49152 to cross 2 → 1, with
CTAS_PER_SMmoved to match so the persistent grid asks for the residency the device will
give it. The diff on the kernel is four integer literals and no code at all —
work, traversal, instruction mix and register count identical either side. A
real staging buffer moves the epilogue and the residency at once, which is
exactly why #94 could not separate cost from benefit; the dead tail has all of
the cost and none of the benefit.
Nothing here can be optimized away, which is the main way this experiment could
have failed silently. The bytes are not an array
ptxascould delete — dynamicshared memory is a launch parameter, so only the driver could decline to
charge for it, and the census shows it charges.
The dead allocation does not land, and
examples/src/gemm.rsis untouchedin this PR (#89 owns it).
The step happened, counted not queried
cuOccupancyMaxActiveBlocksPerMultiprocessorreads 1 at all three envelopes —it is pinned by the presence of
tcgen05.alloc(#77), so it cannot answer this.Three rungs added to
tmem residency census, at the exact envelopes:residentequalsholdingat each, and the census's ownverdictassertsholders equal the resource budget — the case passing is the assertion. This is
also the first count of the plan
gemm_cg2actually declares: the 24 bytes theCLC queue added sit on the same side of the step as 73792, previously assumed.
The number
Min ms over 30 timed launches, three B200 containers in one session, every row
checked against the CPU reference before timing:
cuBLASLt runs untouched in each container and was not identical across them
(2.9% spread at 8192³), so it is used to divide out session drift:
One CTA an SM is worth 14–16%, not 33%. The cost is convex — a cliff, not a
linear cost, which #98 wanted because the two predict differently for #87.
Two controls say the static grid is not doing the work:
clc, whose grid is thetile count with no cap at all, agrees (−17.0% at 8192³ against static's −16.1%);
and resizing
MAX_CLUSTERSmoved wave efficiency the favourable way(92.3% → 98.8% at 8192³), so if anything this understates the cost. This
supersedes §7's cap sweep for this question — that shrank the grid and left
capacity alone, so it could not tell "two per SM" from "a grid that happens to
place two on most SMs."
A structural by-product: at 1 CTA/SM throughput is flat at ~585–640 TFLOP/s
from 4096³ to 16384³, where the 3-CTA curve climbs 900 → 1299. Over half of
what this kernel achieves is one CTA's stall covered by another's work.
Verdict on #15
Not the rejection, and not a green light. #94 was wrong about the price — it is
a seventh, not a third — which is enough to put
lcsf's straight route back onthe table, where the arithmetic as written had removed it. It is not enough to
build on: against a 20–22% item boundary, the trade breaks even only if
lcsfhides ~70% of that boundary (f ≈ 0.65–0.76). Hide all of it and 8192³ reaches
~1330 TFLOP/s and 0.74 of cuBLASLt; hide half and it is a 4% loss. So the
question that decides #15 is now how much of the boundary
lcsfhides — worthprototyping before the plumbing gets built.
Prediction, stated before the run (recorded in the README): 10–16% for the
first step and a 35–45% cliff for the second. Both about right; the first
overshot on raw times at 16384³ and the second was well under its band at 4096³.
Checks
modal run modal_app.py::buildgreen on this tree — clippy, host tests, docs,and a real
cargo oxide build --arch sm_100aof both kernel crates.