Skip to content

Price the occupancy step on a dead allocation, and #94's third is a seventh (#98) - #101

Merged
feitreim merged 1 commit into
mainfrom
price-the-occupancy-step
Jul 28, 2026
Merged

feitreim merged 1 commit into
mainfrom
price-the-occupancy-step

Conversation

@feitreim

Copy link
Copy Markdown
Owner

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_cg2 grows by bytes that no code reads or
writes: 8192 to cross 3 → 2 CTAs/SM, 49152 to cross 2 → 1, with CTAS_PER_SM
moved 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 ptxas could delete — dynamic
shared 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.rs is untouched
in this PR (#89 owns it).

The step happened, counted not queried

cuOccupancyMaxActiveBlocksPerMultiprocessor reads 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:

plan counted holders resident driver's query
73792 B (#84's rung) 3 3 1
73816 B — the plan today 3 3 1
82008 B — +8192 dead 2 2 1
122968 B — +49152 dead 1 1 1

resident equals holding at each, and the census's own verdict asserts
holders equal the resource budget — the case passing is the assertion. This is
also the first count of the plan gemm_cg2 actually declares: the 24 bytes the
CLC 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:

shape 3 CTAs/SM 2 CTAs/SM 1 CTA/SM TFLOP/s 3 → 2 → 1
4096³ 0.1527 0.1727 0.2347 899.8 → 795.8 → 585.5
8192³ 0.8965 1.0668 1.8694 1226.5 → 1030.6 → 588.2
16384³ 6.7735 8.2907 13.7760 1298.6 → 1061.0 → 638.5

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:

shape ours/cuBLASLt, 3 → 2 → 1 3 → 2 2 → 1
4096³ 0.595 → 0.505 → 0.378 −15.1% −25.1%
8192³ 0.685 → 0.592 → 0.332 −13.6% −43.9%
16384³ 0.703 → 0.590 → 0.343 −16.1% −41.9%

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 the
tile count with no cap at all, agrees (−17.0% at 8192³ against static's −16.1%);
and resizing MAX_CLUSTERS moved 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 on
the 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 lcsf
hides ~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 lcsf hides — worth
prototyping 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::build green on this tree — clippy, host tests, docs,
and a real cargo oxide build --arch sm_100a of both kernel crates.

…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.
@feitreim
feitreim merged commit 99e5698 into main Jul 28, 2026
3 checks passed
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.
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.

One CTA per SM is worth an unmeasured amount, and #15 is blocked behind the number

1 participant