Repository navigation
A work item belongs to a cluster, and the GEMM that proved it got slower (#51) - #80
Merged
Merged
Conversation
`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.
…ect (#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.
#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
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 the scaffold half of #51. The GEMM does not adopt it, and that is the finding.
pipeline::runcan schedule a cluster now. The GEMM was ported to it, ranexact on a B200, and was slower than the kernel it replaced at every size
where the persistent grid's cap binds. #51 says in terms that this is a
finding and not a success, so the port is in this PR's history (
08e5e08) andnot in the tree, and the scaffold lands on its own.
What #51's acceptance clause asks, and where this stands
pipeline::run" — deliberately NOT met in the shipped tree. It wasmet, measured, and reverted.
examples/src/gemm.rshere is byte-identical toorigin/main.regression, reported as a finding.
I am not softening this to make it mergeable: the acceptance clause as literally
written is unmet, by choice, and #51 names that as a legitimate outcome only if
argued with numbers. The numbers are below and the one number I could not get is
named as missing.
The scaffold
The map was
blockIdx.xstrided bygridDim.x, which hands the two CTAs of acluster different items — exactly wrong for a cooperative MMA. It is now
%clusteridstrided by%nclusterid.That is a strict generalization, not a second scheduler. A launch that
declares no cluster runs clusters of one CTA, where
%clusteridis%ctaidand
%nclusteridis%nctaid, so a block-scope job provably gets back theloop it had rather than a parallel code path. There is one item map, and
blockIdx.xwas it written one level too low.Job::RANKS(default 1) says whether the job's barriers are shared across thepair, and so whether the item boundary must be
barrier.clusterrather thanbar.sync. That is what per-item barrier re-initialization needs across acluster: otherwise a leader re-arms a barrier its peer is still filling, or a
peer fills one its leader has not re-armed, and both are silent — the phase
simply never completes. The barrier count is unchanged: the loop has the two
it always had, just taken at a wider scope, and at
RANKS == 1the branch foldsaway at compile time.
On #3, which #51 asked me to check before sequencing
The two halves separate, and the rank half never needed #3. #6 found that #3
as filed could not do its job because a block-scope operation needs storage a
{ WARPS, rank(), sync() }trait cannot supply. That finding does not transfer:cluster::block_rank()is a%cluster_ctarankread with no storage, nocollective and no barrier in it. It is already the primitive, the GEMM already
calls it, and wrapping a special register in a trait would add a name without
adding a fact. No rank API was added.
ClusterSemaphore::arriveis still called by nothing#50's PR flagged it as the primitive "#51's persistent cluster pipeline is what
will want it". It turned out not to. An item boundary is a rendezvous — every
rank arriving at every rank — and building one from mbarriers hand-rolls
barrier.cluster.arrive/waitat a barrier and a spin per rank.sync.rsnowrecords that, and what is left for the primitive: a directed signal from one
named rank to another while the rest of the cluster keeps going. An honest
"unused" beats a forced call site.
The measurement
Min ms over 30 timed launches, B200, 148 SMs,
modal run modal_app.py::bench,all three sweeps post-rebase. The cap is in clusters; a cluster is 2 CTAs.
Rows marked
=have fewer tiles than the cap, so the grid is byte-identicalto the launch-per-tile grid and each cluster runs exactly one item — a free
control on the scaffold itself.
=0.0223=0.0234=0.0225=0.0251=0.0268=0.0284=0.0478TFLOP/s at 8192³: 1081 launch-per-tile, 523 at cap 74, 906 at cap 148.
The controls earn two things. The scaffold costs nothing — at an identical
grid and one item per cluster every control row is within noise. And they carry
the run-to-run offset, which is not negligible: the cap-148 run's controls sit
0.4%–11.6% above baseline, ~5% on average, so its 8192³ figure is nearer 13%
slow than 19%. I am not rounding the regression off in either direction.
The reading
lcfat one item per cluster is the launch-per-tile kernel — same rings,same barriers, same prologue and epilogue, drained at the same points. So the
only thing a persistent grid changes here is how many clusters exist, and the
controls confirm nothing else moved. The regression is entirely the cap, and the
cap is a residency question.
Which the repo cannot currently answer for this kernel:
cuOccupancyMaxActiveBlocksPerMultiprocessortakes a block shape and nocluster, which is why
main.rsprintsclusterin the GEMM's occupancy row.The one measurement that is owed
Cap 222 — 3 CTAs/SM, the value 228 KiB / 72 KiB of shared memory admits and
the value the throughput curve points at — was never run. The Modal workspace
hit its spend limit mid-investigation. It is the cap most likely to close the
gap, and possibly to beat the launch-per-tile grid outright, so the conclusion
"the GEMM should not adopt this" is provisional on that one point. Shipping a
cap on an extrapolation is exactly the mistake this table is a record of, which
is why the scaffold lands alone rather than with a guessed constant.
Evidence for #78, since it was asked for explicitly
Extrapolating #77's 1 CTA/SM to the GEMM is false, by at least a factor of
two. Capping the grid at one CTA per SM makes 8192³ take 2.1036 ms against the
uncapped 1.0169. That cannot happen if the device could only ever hold that many
CTAs — the two schedules would then be the same schedule. Doubling the cap
recovers most of it (973 → 1688 tiles/ms, sublinear and still climbing), so
residency is ≥ 2 CTAs/SM and plausibly the 3 shared memory admits.
So #78's step one has a partial answer, obtained on a clock because the query
cannot see it. I have not investigated further, per instruction.
Verification — which gates, on which tree
The rebase onto
bd9e28fhappened partway through, when I found #77 andrealized my wave constant was wrong. Everything below is stated relative to it.
Post-rebase, on a B200:
modal run modal_app.py::examples—pass gemm 512x256x256 exact (4 tiles over 4 clusters), 4096x4096x256 exact (512 tiles over 74 clusters). The74in that line is the post-rebase constant, which is how you can tell whichtree it ran on. The second size exists because the first is 4 tiles over a
grid holding far more, so it never enters the loop twice and would pass
identically against the kernel being replaced — a check that cannot fail
against the code you replaced is not a check.
::benchsweeps (caps 74 and 148).bench.rschecks every size againstthe CPU reference before timing it, so all six sizes up to 8192³ are
exactness runs as well. The scaffold is correct on silicon; it is only slow.
Pre-rebase:
modal run modal_app.py::build(realcargo oxide build --arch sm_100aof both crates, pluscargo doc --features host -D warningsandclippy), and one
::examplesrun. Superseded by the post-rebase runs above.Locally, on the exact final tree:
cargo fmt,cargo clippy --all-targets -- -D warnings,cargo test(74 + 1 passed),RUSTDOCFLAGS=-D warnings cargo doc --no-deps. All green; none of them needs a toolkit.The gap, plainly:
::buildwas not re-run on the final tree, because thespend limit blocks all Modal runs including the CPU-only ones. Expect a red CI
buildfor that reason. What the final tree differs by is bounded and worthstating rather than hand-waving:
examples/is byte-identical toorigin/main, so the examples half of::buildis what main already passes;the library differs only in
pipeline.rs(a generic with no caller, whichmonomorphizes to no PTX) and doc comments in
sync.rs. The--features hostrustdoc run is the only check not reproduced locally, and every new intra-doc
link resolves under the device-only
-D warningsrun.What this leaves
runhad no caller before #51 and has none after it, but the reason changed: itused to be that the cluster kernel could not use the scaffold, and it is now
that the one that can does not want to.
pipeline.rs's module docs say sodirectly rather than leaving it to be discovered.
#15's
lcsfis what would make persistence pay for something rather thanbreak even. Under
lcfthe epilogue is inside the item, sostore_rowsand thenext tile's first K loads are separated by a boundary that drains the pipeline —
a persistent GEMM buys a saved launch and nothing else.
tma_store_wait_read(#9, landed) is the wait that would let them cross.