Repository navigation
The 1 CTA/SM is tcgen05 itself, and a smaller TMEM allocation buys nothing (#74) - #77
Merged
Merged
Conversation
…thing (#74) #70 inferred TMEM from the single fact that flash_forward is the only queryable entry using tcgen05, and said plainly that it was a guess. This builds the control it was missing: a nine-register kernel whose whole content is one tcgen05.alloc, against the byte-identical kernel with the allocator deleted. TMEM is confirmed and the obvious remedy is refuted in the same table. A CTA that touches the allocator is charged the SM's entire tensor memory — 32 columns costs exactly what 512 costs — so shrinking flash_forward's allocation is not the lever. Neither is the column count a constant ptxas recorded: the 192 rung takes it as a kernel argument. Nor is a cluster shape involved; required_cluster_dimensions is None on every rung. Also fixes two latent blockers found in flash_forward's allocator on the way: it asked for 192 columns, which is not a power of two and therefore not a legal tcgen05.alloc, and it never deallocated at all.
This was referenced Jul 28, 2026
feitreim
added a commit
that referenced
this pull request
Jul 28, 2026
…wer (#51) (#80) * A work item belongs to a cluster, not to a CTA (#51) `pipeline::run`'s map was `blockIdx.x` strided by `gridDim.x`, which hands the two CTAs of a cluster different items — exactly wrong for a cooperative MMA, whose pair has to be on one output tile. It is now `%clusterid` strided by `%nclusterid`. That is a strict generalization rather than a second scheduler: a launch that declares no cluster runs clusters of one CTA, where `%clusterid` *is* `%ctaid` and `%nclusterid` *is* `%nctaid`, so a block-scope job gets back the exact loop it had. `Job::RANKS` (default 1) says whether the job's barriers are shared across the pair, and so whether the per-item boundary has to be `barrier.cluster` rather than `bar.sync`. The barrier *count* is unchanged — the loop has the two it always had — and at `RANKS == 1` the branch folds away at compile time. The rank half of #51 needed no API. `cluster::block_rank()` reads `%cluster_ctarank` with no storage, no collective and no barrier in it, which is precisely what #6 found `Scope` could not supply for the block-reduction half. The two halves separate; wrapping a special register in a trait would add a name without adding a fact. `sync.rs` records that `ClusterSemaphore::arrive` is still called by nothing, and that #51 turned out not to want it: an item boundary is a rendezvous, and building one out of mbarriers hand-rolls `barrier.cluster` at a barrier and a spin per rank. * gemm: the persistent adoption, recorded so the measurement has a subject (#51) The GEMM as a `Tile: Job` driven by `pipeline::run`: one output tile per work item, one item per cluster, `RANKS = 2`, TMEM allocated once outside the loop because `alloc_cluster` is a whole-cluster collective whose address never changes. `check` gains a second size — 4096x4096x256, 512 tiles — because the existing 512x256x256 is four tiles over a grid that holds far more, so it never enters the loop twice and would pass identically against the kernel this replaces. A check that cannot fail against the code you replaced is not a check. Verified on a B200: `pass gemm 512x256x256 exact, 4096x4096x256 exact`, and `::bench` checks all six sweep sizes against the CPU reference before timing them, up to 8192³. The scaffold is correct. It is also slower, which is why the next commit takes it back out. This one exists so that `git show` has the kernel the numbers in `examples/README.md` §7 were taken on, rather than a description of it. * gemm keeps its launch-per-tile grid, and README §7 says what that cost (#51) Reverts the previous commit's adoption. #51 says in terms that a persistent GEMM slower than the current one is a finding and not a success, and it is slower: 2.07× at 8192³ with a one-wave cap, ~13% with a two-wave one after normalizing by that run's own control rows. The control rows are what make this a finding rather than a shrug. At sizes with fewer tiles than the cap the grid is byte-identical and each cluster runs one item, and there the persistent kernel is within noise of the one it replaced. `lcf` at one item per cluster *is* the launch-per-tile kernel, so the only thing a persistent grid changes here is how many clusters exist — and choosing that number is a residency question that `cuOccupancyMaxActiveBlocksPerMultiprocessor` cannot answer for a `#[cluster_launch]` kernel. The value the throughput curve points at, 222 clusters, is unmeasured: the Modal workspace hit its spend limit. Shipping a cap on an extrapolation is the mistake §7 is a record of, so the scaffold lands alone. Bears on #78: capping at one CTA per SM costs 2.07×, which cannot happen if the device could only hold that many CTAs. Extrapolating #77's 1 CTA/SM to this kernel is false by at least a factor of two.
This was referenced Jul 28, 2026
feitreim
added a commit
that referenced
this pull request
Jul 28, 2026
The GEMM as a `Tile: Job` driven by `pipeline::run`: one output tile per work item, one item per cluster, `RANKS = 2`, TMEM allocated once outside the loop because `alloc_cluster` is a whole-cluster collective whose address never changes. This is the scaffold's first caller, which is most of what it buys — `pipeline::run` was exercised by nothing before and is now on the `::examples` gate. `check` gains a second size, 4096x4096x256 at 512 tiles, because the existing 512x256x256 is four tiles over a grid that holds 222 and so never enters the loop twice. It would pass identically against the kernel this replaces, and a check that cannot fail against the code you replaced is not a check. It is a dead heat and not a win: 1.0217 ms at 8192³ against the launch-per-tile grid's 1.0204, 1076 TFLOP/s against 1077. Reported that way in README §7 rather than dressed up, since `lcf` folds the epilogue into the item and hands back at the boundary what persistence saves on launches. #15's `lcsf` is what would let those cross. The route to that dead heat is the part worth keeping. The grid's cap is the only thing this port changes, and two guesses at it were wrong by a lot — 2.07× slower at one CTA/SM and 1.19× at two, before three drew level. Picking it needs a residency `cuOccupancyMaxActiveBlocksPerMultiprocessor` will not give for a `#[cluster_launch]` kernel, so `CTAS_PER_SM` is a bisection on a clock rather than a derivation, and it says three — refuting the extrapolation of #77's 1 CTA/SM to this kernel by a factor of three, which is #78's step one.
feitreim
added a commit
that referenced
this pull request
Jul 28, 2026
The GEMM as a `Tile: Job` driven by `pipeline::run`: one output tile per work item, one item per cluster, `RANKS = 2`, TMEM allocated once outside the loop because `alloc_cluster` is a whole-cluster collective whose address never changes. This is the scaffold's first caller, which is most of what it buys — `pipeline::run` was exercised by nothing before and is now on the `::examples` gate. `check` gains a second size, 4096x4096x256 at 512 tiles, because the existing 512x256x256 is four tiles over a grid that holds 222 and so never enters the loop twice. It would pass identically against the kernel this replaces, and a check that cannot fail against the code you replaced is not a check. It is a dead heat and not a win: 1.0217 ms at 8192³ against the launch-per-tile grid's 1.0204, 1076 TFLOP/s against 1077. Reported that way in README §7 rather than dressed up, since `lcf` folds the epilogue into the item and hands back at the boundary what persistence saves on launches. #15's `lcsf` is what would let those cross. The route to that dead heat is the part worth keeping. The grid's cap is the only thing this port changes, and two guesses at it were wrong by a lot — 2.07× slower at one CTA/SM and 1.19× at two, before three drew level. Picking it needs a residency `cuOccupancyMaxActiveBlocksPerMultiprocessor` will not give for a `#[cluster_launch]` kernel, so `CTAS_PER_SM` is a bisection on a clock rather than a derivation, and it says three — refuting the extrapolation of #77's 1 CTA/SM to this kernel by a factor of three, which is #78's step one.
feitreim
added a commit
that referenced
this pull request
Jul 28, 2026
…he other reason (#78) (#84) * Count the CTAs instead of asking, and flash_forward's 1 is real for the 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. * Say which query cannot answer a cluster launch, and which one can (#78) 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
feitreim
added a commit
that referenced
this pull request
Jul 28, 2026
…eventh (#98) (#101) #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
added a commit
that referenced
this pull request
Jul 29, 2026
…and the epilogue was never gemm_ws's problem (#118) (#119) `.x8` LDTM and `stmatrix.x4` on `gemm_ws`, plus the two `no drain` controls the ladder is subtracted from, and the result is a lever that pays and a hypothesis that dies. The levers. Against #116's `staged`, `.x8` is +15.7% / +6.2% / +3.0% at 4096/8192/16384 cubed and `.x4` is +1.2% / +0.0% / +0.1% — the same clean null it was on `gemm_cg2`. They do not compose here: `staged8` and `staged84` are within 1.1% and trade places between sessions, and the register column said so in advance, `.x4` recovering 2 registers (94 -> 92) where on `gemm_cg2` it recovered 14 (94 -> 80) and that recovery *was* the composition gain. Best rung is +19.4% / +9.5% / +5.2% over the shipped register epilogue, 0.615 -> 0.726, 0.782 -> 0.856, 0.810 -> 0.852 of cuBLASLt. Zero spill in every rung; 94 is the largest count in the file against a reachable 255. #117's mechanism predicted the shortfall and got it. `.x8` removes a latency the drain never overlaps; this kernel already overlaps it, so `.x8` is worth 67%, 72% and 83% of what it was worth on `gemm_cg2`. By `whole - no drain` the same epilogue is exposed at 8.62 us a tile here against #114's 20.43, and its LDTM half at 3.20 against #117's 8.07 — 40-47%, which is what warp specialization and the accumulator ping-pong buy, stated as a number for the first time. "Twice the LDTM (16 against 8)" is true of the PTX and false of the work. Every census column doubles, not just LDTM, because `gemm_ws` emits its epilogue at two call sites (`Ws::work` and `Ws::finish`) where the fused job has one. The bands are `RegTile<32, 64>` in both files. The floor is the finding. `gemm_ws_no_drain` — the shipped kernel with the epilogue deleted, the probe that put `gemm_cg2` at 1850 TF/s against the library's 1808 — reaches 0.829 / 0.923 / 0.888 of cuBLASLt, and at 8192 and 16384 cubed it is *slower than `gemm`'s complete `staged84` launch*. Best against best is -9.7% / -9.4% / -6.9%; deleting the epilogue outright recovers 12.7 / 7.2 / 3.9 of those points. So no, `gemm_ws` does not beat `gemm`, and it could not have: #112's 7.3% closes to 6.9% after both kernels spent everything #116 and #117 found. The deficit is the multiply and the operand stream at one CTA an SM. #112 blamed the peer CTA and #114 refuted it; `gemm_ws.rs` blamed the missing peer CTA and this refutes that, by deleting the epilogue and losing anyway. The stale paragraph is corrected in place rather than removed. Residency counted, not queried (#77): two new census rungs at this kernel's own 131 176 B and 147 584 B read 1 resident, 1 holding at both, closing the gap the `cg2 512` rung left at a 32 B plan (1 holding, 2 resident, 100.9 us parked in a blocking alloc; 0.9 us here). No default moved. `staged8` is the rung to ship on `gemm_ws` — `.x4` is a null here alone and in composition — and that is a change worth making on its own.
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 #74.
TMEM is CONFIRMED. The fix everyone reached for is REFUTED in the same table.
#74 named the TMEM hypothesis and said it was untested — "an unexcluded-alternatives
argument from a sample of one". The control it asked for is the most valuable thing
here, so it is what landed:
device-tests'tmem occupancy ladder, anine-register kernel whose entire content is one
tcgen05.alloc, against thebyte-identical kernel with the allocator deleted. Same 32-byte shared plan, same
block sync, same store; the only thing that varies between rungs is the allocator's
operand.
Measured on a B200 (
modal run modal_app.py::device_tests, 30/30 pass),blocks/SM at 0 dynamic shared:
allocallocallocallocallocallocThe control sits at the hardware's own warp ceiling — 2048 threads an SM, so
32/32/16/8 — because at 10 registers and 32 bytes nothing else is binding. Add one
tcgen05.allocand it is 1, at every block width and at every legal columncount. A CTA that touches the allocator is charged the SM's whole tensor memory,
and the allocator's smallest unit costs exactly what all 512 columns cost.
That reproduces
flash_forward's flat 1 in a kernel with 9 registers, no sharedmemory and no MMA — so the 1 is not a defect in that kernel. It is what a tcgen05
kernel costs on Blackwell.
The three experiments #74 named
1. Vary
flash_forward's TMEM allocation and re-query. Done on the real kernel,not only on the proxy: cut from 192 columns to 32 — a 6× reduction — and re-queried
through
modal run modal_app.py::examples. Still 1 block/SM. Reverted after themeasurement.
2. A control in
device-tests. Above. It also pins at 1, so the ceiling belongsto
tcgen05rather than to anythingflash_forwarddoes.3. Is the driver reporting a cluster constraint? No.
required_cluster_dimensionsis
Noneon every rung, and the rungs issue no MMA at all — so tcgen05 implies nocta_group::2shape and the query is not answering about a launch geometry thekernel never declares.
And one the issue did not ask for, which separates two mechanisms a flat ladder
alone cannot: the 192 rung takes its column count as a kernel argument, so there
is no constant for the driver to have read. It is pricing the allocator, not a number
ptxasrecorded.What the lever actually is
None of shared memory (#70 measured it), registers (123/thread, 0 spills, would admit
4 blocks), TMEM columns (above) or cluster shape. What is left is warps per CTA.
At 1 block/SM the CTA's own width is the SM's occupancy, and
flash_forwardis 128threads — 4 warps, against its own
max_threads_per_blockof 512 and the control's32. Those 4 warps are
QUERIES / 32, one per 32 accumulator rows, so widening the CTAis a different decomposition rather than a constant to raise: warps dedicated to
the TMA and to the MMA issue. That is a design to price, and pricing it needs the
launcher and CPU reference
flash_forwardstill does not have — reported here ratherthan attempted, per the issue's "a well-specified follow-up with data is a good
outcome".
Two latent blockers found in flash's allocator on the way
Both in
flash_forward.rs, both discovered by looking hard at the one line #74'sfirst experiment varies, and both of which would stop the kernel dead the first time
anyone launches it.
It asked for 192 columns, which is not a legal
tcgen05.alloc. The operand mustbe a power of two in
[32, 512]— cuda-oxide spells the set out as "32, 64, 128,256, 512" on
TmemGuard.KEYS + HEADis 192. Nothing caught it because the columncount is an argument to an instruction, so no type and no
constassertion was everin a position to see it; there is one now. Rounded up to 256, which costs nothing
— that is this PR's own finding, and it is what makes the fix free rather than a
trade.
It never deallocated at all. A kernel that exits holding tcgen05 columns is a
CUDA_ERROR_TENSOR_MEMORY_LEAKand the next CTA on the SM is the one that pays.device-tests'repeated launchcase is the standing guard for exactly this class,and a kernel with no launcher never reaches a guard that works by launching twice.
Neither is verified at runtime, and cannot be:
flash_forwardhas no launcher. Realsm_100acodegen is the check available and it is green. Thedeallocfollowssttm_roundtrip's andrelaunch_probe's pattern exactly —sync_threadsthendealloc_block— both of which pass on a B200 in this same run.The probe is a guard, not a report
A measurement nothing re-runs decays into a claim, so the check fails if the shape
changes: if any allocating rung stops answering 1 (the "shrinking the allocation buys
nothing" advice would be stale), or if the control drops to 1 (in which case the SM
is not admitting more than one CTA of anything and the ladder cannot attribute the 1
to tcgen05 at all). The table prints on both paths — a rung that moved is exactly when
the numbers are worth reading, and an error that swallowed them would send the next
person back to the B200 to get them again.
On #70's measurement trap. The >48 KiB opt-in is a persistent mutation of the
loaded function, so a naive sweep admits once at the largest size and every later
query answers about that ceiling. Nothing here crosses 48 KiB and every query is at
zero dynamic shared — and the rungs are separate functions besides, which makes the
trap impossible rather than merely avoided.
Verification
modal run modal_app.py::build— green. clippy on all three crates, hosttests,
cargo doc -D warnings, and realcargo oxide build --arch sm_100acodegenof both kernel crates including the seven new ladder kernels.
modal run modal_app.py::device_tests— green, 30/30 on a B200. Table above.All six ISA-legal rungs are launched and their allocations balance;
repeated launchstill passes behind them.modal run modal_app.py::examples— green.gemm512x256x256 exact,softmax1.97e-3,
layernorm3.87e-3,flash_forwardstill 1 block/SM at 147536 B.modal run modal_app.py::regcount—flash_forwardat 123 registers, 0 spills,1824 B stack, 0 static shared. The
deallocand the 256-column constant cost oneregister against the 124 in the issue.
cargo fmt,cargo clippy --all-targets -- -D warnings,cargo testlocally.Measured vs inferred. Everything in the tables is measured. Inferred: that the
mechanism is the driver modelling tensor memory as a whole-SM per-CTA reservation —
the ladder shows the behaviour is indistinguishable from that at every column count
the ISA defines and with no constant to read, but no driver internal was inspected.
That warps per CTA is the remaining lever is deduction from the exhausted
alternatives, not a timing — flash has no launcher, so it cannot yet be priced as a
time, which is the same limit #74 records.