Repository navigation
The cap was the whole story: gemm adopts pipeline::run at a dead heat (#51) - #83
Merged
Merged
Conversation
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
force-pushed
the
gemm-adopts-pipeline-run
branch
from
July 28, 2026 17:48
61d6f77 to
91f5c8e
Compare
This was referenced Jul 28, 2026
Closed
Merged
feitreim
added a commit
that referenced
this pull request
Jul 28, 2026
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.
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 29, 2026
… says scope four ways (#133) * Audit the library whole: three doc claims were wrong, and the surface says scope four ways `src/` is 10 156 lines and nobody had read it whole since it grew. This is that read, against Finn's three areas: API coherence, missing coverage, docs vs reality. No API changes -- findings are issues, and the only edits here are documentation corrections, where a stale doc is the finding and the fix. Corrected in `src/`: - `reg.rs`'s module header said "the measurement does not favour" the SFU `exp2`, on a register count. Timed on `softmax`, it is 2.7x the other way (#76/#81). The "ex2.approx serializes" claim had no probe and is removed, not restated. The default does not move: that is #81's call and `flash_forward` has no reference to check one against. - `tmem.rs`'s occupancy table said `gemm` allocates 128 columns and is capped by shared memory at 3 CTAs. Since #104 it asks for `BLOCK_N = 256` and tensor memory is the resource that binds it. - `ldst.rs`'s store contracts required "all 32 lanes of the warp owning TMEM rows row..row+16". Nothing in `ldst` touches tensor memory; the clause was `tmem.rs`'s, where it is correct, and the load side never had it. - Two dangling `#56` citations in `reg.rs`, predating this repo's issue #56 by a day and unresolvable against it. `GAPS.md` gains a section 7 -- the coherence of the surface itself, which no comparison against ThunderKittens finds -- and loses two entries that had gone stale inside a day: 2.2 said `GlobalRows` was fp32-only after #108 gave it an element, and 4 said the pipeline scaffold had no caller after `gemm` had been running on it since #83. Both are now named in `tests/gaps.rs`, along with the `.x8` drain, the `.x4` store, the store ring's `Scope`, the cluster charge and the operand-order square. Nine issues filed (#124-#132) and two comments on #14 and #42. * reg.rs: state the correction, let #81 carry its history * GAPS 7.4: the drain loop is shared, the preambles are not
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.
Follow-up to #80, which landed the scaffold and concluded the GEMM should not
adopt it. That conclusion was wrong, and #80 said exactly which measurement
would decide it.
#80's own words:
The spend limit lifted. I ran the point. It draws level, so
gemm.rsadopts thescaffold and
pipeline::runhas its first caller.The number
Min ms over 30 timed launches, B200, 148 SMs. Cap is in clusters; a cluster is 2
CTAs. Rows marked
=have fewer tiles than the cap, so the grid is identicalto the launch-per-tile grid and each cluster runs one item — a free control.
Two launch-per-tile runs, because the cross-run spread is a few percent and the
conclusion has to survive it; run 4 was taken adjacent to the cap-222 run for
exactly that reason.
=0.0223=0.0234=0.0231=0.0225=0.0251=0.0258=0.0268=0.0284=0.0292=0.0478=0.0492TFLOP/s at 8192³: 1081 / 1077 launch per tile, 523 at cap 74, 906 at cap
148, 1076 at cap 222.
It is a dead heat, not a win. 0.13% at 8192³ against the adjacent baseline;
4096³'s 2.3% is exactly the offset that run's own
=control rows carry. I amnot dressing parity up as a speedup —
lcffolds the epilogue into the item, sothe boundary hands back at the drain what persistence saves on launches, and a
dead heat is the ceiling for this shape. #15's
lcsfis what would let theepilogue and the next tile's first K loads cross.
What adopting it buys is that the scaffold has a caller and therefore a
regression test.
pipeline::runwas exercised by nothing at all before —including in #80, which is a poor place for a load-bearing scaffold to sit.
Why this is worth landing even at parity, stated plainly
gemm.rsusespipeline::runandruns exact.
SMS = 148constant. That is a tuning input, not a correctnessone —
runwalks every item whatever the grid is, so a device with adifferent SM count computes the same
Coff a wave that is not quite a wave.The repo already carries cited B200 constants (
B200_BF16_DENSE_TFLOPS) andtargets sm_100a exclusively.
If you would rather not carry the constant for parity, the honest alternative is
to revert this and leave the scaffold uncalled; I think the regression test is
worth more, but the numbers above are the whole basis for that and they are a
tie.
The residency, which is #78's step one
Picking the cap needs to know how many CTAs of this kernel an SM holds, and the
repo cannot ask:
cuOccupancyMaxActiveBlocksPerMultiprocessortakes a blockshape and no cluster, which is why
main.rsprintsclusterin the GEMM'soccupancy row. So it came off the clock by bisection, and the answer is 3 CTAs
per SM — what 228 KiB / 72 KiB of shared memory admits.
CTA/SM here: if the device could only hold 148 CTAs, a 148-CTA grid and a
4096-CTA grid would be the same schedule and could not differ.
The GEMM is not pinned at 1 CTA/SM like
flash_forward, by a factor ofthree. The method may be worth as much as the number: for a
#[cluster_launch]kernel, a timing sweep over a persistent grid's cap is aresidency probe, and right now it is the only one available. Recorded for #78; I
have not gone further into it.
Verification, on this tree, against current
mainmodal run modal_app.py::examples—pass gemm 512x256x256 exact (4 tiles over 4 clusters), 4096x4096x256 exact (512 tiles over 222 clusters). Thesecond size is there because the first is 4 tiles over a grid holding 222 and
never enters the loop twice, so it would pass identically against the
non-persistent kernel — a check that cannot fail against the code you replaced
is not a check.
pass softmaxandpass layernormbeside it, unchanged.modal run modal_app.py::build— exit 0, all seven steps, includingRUSTDOCFLAGS=-D warnings cargo doc --features hostand a realcargo oxide build --arch sm_100aof both crates.modal run modal_app.py::bench— four sweeps, above.bench.rschecks everysize against the CPU reference before timing it, so all six sizes up to 8192³
are exactness runs too.
cargo fmt --check(both crates),cargo clippy --all-targets -D warnings,cargo test(74 + 1).Rebased on
d213161;#79's softmax work inexamples/README.mdis untouched— this changes §7 and one sentence above it, and nothing else in that file.
One note on the timings and #82
Rebased onto #82 (#29's charge rework), which lands in this kernel's producer
loop:
tma_load_2d_arriving_atnow hands back its own charge and the leaderscales it with
across_ranks(RANKS). The merge keeps that — the persistentTile::workcarries #29's form, not the hand-written total.Every timing above was taken before #82, on both sides of the comparison.
The launch-per-tile baselines and the three capped runs were all built from the
same pre-#82 tree, so the comparison is internally valid and the dead heat
stands. What is not re-measured is the absolute figures against post-#82 code; I
would not expect a charge that is computed rather than written down to move
them, but that is a prediction and it is stated as one rather than checked.
::buildand::examplesare re-run post-rebase, so correctness is notresting on the same assumption.