Repository navigation
Count the CTAs instead of asking, and flash_forward's 1 is real for the other reason (#78) - #84
Merged
Merged
Conversation
…he other reason (#78) `cuOccupancyMaxActiveBlocksPerMultiprocessor` returns 1 for any kernel containing a `tcgen05.alloc` (#77). #51 then measured `gemm` losing 2.07x to a one-CTA-per-SM grid cap, which is impossible if 1 were the ceiling, so the query had been shown once not to predict residency and flash_forward's 1 stopped being established. Rather than infer residency from where a throughput curve flattens, count it. `%smid` names the SM a CTA is running on and `%globaltimer` is a device-wide nanosecond clock, so each census CTA records where it ran and timestamps both ends of its TMEM allocation; the host sweeps those intervals per SM for the most ever open at once. Two intervals are kept, and the pair is the point: a CTA parked inside a blocking `tcgen05.alloc` is resident and making no progress, which no grid-cap sweep can distinguish from absence. Residency is `min(512 / columns, shared per SM / plan)`, exactly, at all fourteen rungs. So: - flash_forward's 1 CTA/SM is REAL, and tcgen05 is not the cause. Its 256 columns admit 2; its 147536 B shared plan admits 1 with no allocator in the kernel at all. Shared memory is the only thing capping it — the resource #70 tried to rule out and could not, because the query it asked was pinned by the allocator in all four of its readings. - gemm's envelope counts 3, reproducing #83's clock-bisected 3 on an instrument with nothing in common with a throughput curve. - alloc_cluster is charged identically to alloc_block at equal columns, so the pair does not split the SM's tensor memory. #78's leading hypothesis for why the two kernels differ is refuted; what differs is their shared plans. - The query reacts to the instruction, not to a held resource: a kernel that allocates 512 columns and releases them before doing anything runs 25 CTAs an SM while the query still answers 1. `cuOccupancyMaxActiveClusters` does describe a `#[cluster_launch]` kernel, and matches the census on the cluster control. The docs saying it could not predate anyone calling it.
Two doc sites said the occupancy question was unanswerable for a `#[cluster_launch]` kernel. Both are accurate about the function they name and misleading about the situation, one commit after the census showed `cuOccupancyMaxActiveClusters` does describe such a kernel and agrees with a counted census on the cluster control. - `main.rs`'s `entry` field: `None` now marks a query nobody wired into that table rather than a residency nothing can reach. - `gemm.rs`'s `CTAS_PER_SM`: #83's clock-bisected 3 stays as the measured figure and so does the route to it. Added that #78's census counts 3 at the same envelope from `%smid` and `%globaltimer` — two methods sharing nothing agreeing on one integer — and that it names the resource the bisection could not: 128 columns admit 4, the 73792 B shared plan admits 3, so shared memory caps this kernel and tcgen05 does not. No constant re-tuned, no kernel touched.
This was referenced Jul 28, 2026
Closed
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 #78.
The answer, in one line
flash_forward's 1 CTA/SM is REAL — andtcgen05is not what causes it. Itsshared plan is. Which means #74's advice was right for this kernel by accident, and
#70's conclusion that shared memory was not the lever is backwards: it is the only
lever that kernel has.
Counting, rather than asking or inferring
#78 asks for residency "by TIMING rather than by asking the query", and suggests #51's
grid-cap sweep. There is a better instrument on this hardware, and it is what landed.
%smidnames the SM a CTA is running on and%globaltimeris a device-wide nanosecondclock, so a CTA can write down where it ran and when.
device-tests' newtmem residency censuslaunches 4736 one-warp CTAs, each of which records its%smid, timestamps entry, allocates, timestamps, spins on the clock for 100 µs, andtimestamps again. The host sweeps those intervals per SM and takes the most ever open
at once.
That is strictly stronger than a grid-cap sweep, for a reason no sweep can fix. Two
intervals are counted:
[entered, left][allocated, left]A CTA parked inside a blocking
tcgen05.allocis resident and making no progress. Athroughput curve reads that as absence; the census reads it as the
residentcolumnsitting one above
holding. It also needs no calibration run, no assumption that thework is latency-bound, and no argument about where a curve "flattens".
The measurement
B200, 4736 one-warp CTAs over 148 SMs, 100 µs each, 233472 B shared memory per SM.
budgetismin(512 / columns, shared per SM / plan).allocallocallocallocallocalloc512 then freealloc_clusternonealloc_clusteralloc_clusteralloc+ half that planflash_forward's envelopegemm's envelope (cg2)holdingequalsbudgetat all fourteen rungs. Exact, not a trend — which is whyit is asserted as an equality rather than reported.
What that settles
1.
flash_forward(#78's actual question). Its 256 columns admit 2. Its 147536 Bshared plan admits 1 — measured on the rung with no allocator in the kernel at
all. Together: 1. So the headline number #74 reported is correct and every reason
given for it was wrong. #70 queried that plan at 147536, 73792, 32800 and 0 bytes, got
1 block/SM at each, and ruled shared memory out; all four answers were the allocator
pinning the query.
2.
gemm— an independent confirmation of #83. #83 bisected its grid cap on a clockand got 3 CTAs/SM. The census at the same envelope counts 3. Two instruments
with nothing in common agreeing on one integer, and the census adds the mechanism: 128
columns allow 4, 73792 B of shared allows 3, the smaller binds. Shared memory caps
that kernel and tensor memory does not.
3.
alloc_clustervsalloc_block— #78's leading hypothesis, refuted. Identical atequal column counts: 4 and 4 at 128, 1 and 1 at 512. A
cta_group::2allocation is notsplit across the pair; each rank pays its full count against its own SM. What actually
differs between the two kernels is their shared plans, 73792 B against 147536 B.
4. What the query is doing. It reacts to the instruction being present, not to a
resource held: the allocate-and-release rung takes all 512 columns, gives them straight
back before the counted interval, runs 25 CTAs an SM, and is still answered 1. Both
queries are otherwise accurate — 32 predicted / 32 counted for the plain control, 8 / 8
for the cluster control — which is exactly what made the 1 easy to believe.
5.
cuOccupancyMaxActiveClustersexists. It takes the cluster shape the block queryhas no argument for.
main.rs'sclusterplaceholder and #51's "cannot currently beanswered" predate anyone calling it. It is in the
drivercolumn above.A correction to #74/#77 that I am also the author of
Mid-PR I had written that flash was at 2 and its 1 was "the query, not the hardware".
That was true of tensor memory alone and false of the kernel, and only adding the
shared-memory rungs caught it. Both the code and the prose now carry the joint model.
The general claim that survives: shrinking a TMEM allocation to the next legal power
of two doubles the CTAs tensor memory holds — a real lever where #74 and #77 said
there was none — but it is worth nothing while shared memory is the tighter resource,
which for both kernels here it is.
The probe is a guard
The case fails if
holding != budgetat any rung (above is impossible, below means thedriver changed its reservation model and the docs are stale), if the control collapses
to 1, if the allocate-and-release rung falls to 1, or if any spin ended on its iteration
guard rather than on the clock — a short hold overlaps less and would read exactly like
low residency, so that check is what stops a hoisted
%globaltimerfrom being reportedas a finding. The table prints on both paths.
tmem occupancy ladderis kept and still asserted; its docs now say it measures thequery's behaviour, and its verdict string no longer draws a hardware conclusion from it.
Not done here, deliberately
flash_forwardis untouched. It has no launcher and no CPU reference, so shrinking itsring cannot be checked for correctness, let alone timed. Filed as #85 with the numbers.
Its module doc still carries #77's "shrinking the allocation buys nothing", which is now
wrong — correcting it needs
examples/src/, which #29 owned for this window.Verification
modal run modal_app.py::build— green, realsm_100acodegen of both kernel cratesincluding the nine new census kernels.
modal run modal_app.py::device_tests— 31/31 on a B200, table above. Reproducedidentically across five runs.
modal run modal_app.py::examples— green;gemmexact,softmax1.97e-3,layernorm3.87e-3.modal run modal_app.py::regcount— census kernels at 16–20 registers, 0 spills, 0frame, so nothing in them can be a register ceiling.
cargo fmt,cargo clippy --all-targets -- -D warnings,cargo test(76 + gaps).e913940; the one conflict wasexamples/README.md's §7, where The cap was the whole story: gemm adopts pipeline::run at a dead heat (#51) #83 hadrewritten the section — resolved in favour of The cap was the whole story: gemm adopts pipeline::run at a dead heat (#51) #83's text with the census's mechanism
added under it.
Measured vs inferred. Every number in every table is measured. Inferred: that the
mechanism is a hardware allocator dividing 512 columns rather than a driver reservation
— the behaviour is indistinguishable from that at every rung, and the allocate-and-
release rung rules out a static admission-time reservation, but no driver internal was
inspected. Also inferred and flagged as such in the README: that 116736 B is where
flash's plan would start admitting 2. The census brackets that threshold between 73768 B
(counts 2) and 147536 B (counts 1) and does not locate it.