Repository navigation
Ask the hardware for the schedule, and find out the ragged wave was never the cost (#88) - #97
Merged
Merged
Conversation
feitreim
force-pushed
the
clc-work-stealing
branch
from
July 28, 2026 21:12
607a590 to
e410f5f
Compare
This was referenced Jul 28, 2026
feitreim
added a commit
that referenced
this pull request
Jul 28, 2026
…a stale checkout (#106) PR #97 reported cuda_device::clc's module usage example as having is_canceled inverted against its own function doc. The defect was real at v0.2.1 and upstream fixed it in 61f4a563 on 2026-06-29, a month before the b099f64c this repo pins -- which now ships a 13-line clc.rs with no usage example at all. The claim came from a stale sibling checkout under ~/.cargo/git/checkouts: of six revisions cargo has left there, only 4514af2 (v0.2.1, 2026-06-10) still carries it. The file cited as settling the question, crates/mir-lower/.../clc.rs, exists at no upstream revision. No code changes -- != 0 was and is correct, established by the probe rather than by the doc. This corrects the two places that assert the upstream defect in the present tense, and names the mechanism: a ~/.cargo checkout is not a citation without git log -1 on that directory.
feitreim
added a commit
that referenced
this pull request
Jul 29, 2026
Tier 1 checks the library, device-tests and examples. A root `cargo fmt` reaches only the first -- the other two are separate workspaces -- so a change can be clean locally and red in CI on whitespace alone. That has happened three times (#97, #104, #109), each costing a review round trip on a gate that runs in twenty seconds.
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 #88.
pipeline::run_stealingputs the GEMM on Blackwell's hardware work-stealing —launch one cluster per output tile, and a cluster that finishes cancels one the
scheduler has not launched yet. It sits behind the same
Job, soTileisbyte-identical under both schedulers.
It does not pay for itself, and the reason is more interesting than the
feature. Two findings about
cuda_device::clcare worth more than thescheduler; they are near the bottom and I would read them first.
The number, against the prediction stated before it was built
Min ms over 30 timed launches, B200. Both schedulers run one shared plan —
the static path carries the 24 unused bytes of the work queue too — so this
compares schedules and not residencies. Without that control, CLC changing
occupancy would masquerade as CLC changing scheduling.
predictedis1 - tiles/(waves × 222)and is not fitted to anything. #88 named23% / 8% / ~0 and that is what the column says.
The predicted gain does not arrive. Where the model says 23% the measurement
says 1.3%; where it says 7.7% it says 1.1%.
The wave-efficiency arithmetic is not wrong, and it is worth being precise
about what it does say. At 4096³ the ragged last wave really is 23% of the grid
idling — 512 tiles over three waves of 222 leaves 154 clusters with nothing to
do. It is simply not 23% of the time, because the clusters that idle are not
the ones on the critical path: the launch ends when the last busy cluster
finishes its tile, and an idle neighbour does not make that cluster faster. The
model is right about a term, and the term is small. #90 and #94 already
measured the one that is not — the item boundary, at 18–30 µs per output tile
and 20–36% of the launch — and a dynamic schedule removes no item boundary at
all. It only changes which cluster pays them.
16384³'s ~0 is the one thing the model gets right, and it gets it right for the
wrong reason. I am not claiming the +2.4% there: it is the least reproducible row
in this repo's tables by #90's and #94's own statements, and 1–2.4% sits at the
edge of what a 0.6% session spread can resolve.
The prefetch was a regression, and #88 predicted the opposite
#88 says "a steal on the critical path would be a regression" and asks which was
measured. Both were, as two entry points differing in one thing.
The critical-path steal was faster at all four sizes. At 16384³ it is the
6.7643 in the table above, against the prefetched form's 7.3399 — 8.5%, far
outside the 0.6% these numbers repeat to.
The prefetched form has been deleted.
run_stealinghas no const parameterand the GEMM has one CLC entry point; the finding survives in
pipeline.rs'smodule doc and
examples/README.md§7, which is where it belongs.So
gemm_cg2_clcis the serial form — the one that issues itstry_cancelafter the item it will replace. The name no longer distinguishes it from a
prefetched sibling because that sibling was built, measured and deleted, not
because it was never written. If you are reading this file wondering whether the
prefetched schedule was ever tried: it was, it is the 7.3399 ms above, and it
lost. The plausible
mechanism: prefetching makes every cluster claim its next tile before finishing
its current one, so the order tiles are handed out in stops tracking the order
clusters actually become free — the ragged tail this mechanism exists to fix,
reintroduced by the optimization meant to hide its latency. One measurement,
stated as a hypothesis. What would test it is recording per-cluster item counts
and comparing their spread.
Should the static
runstay?Yes, and not as redundancy — the two buy different things. The static stride
is the fastest known schedule for this kernel and has a year of measurements
behind it. CLC's case is portability: the grid becomes the problem's own tile
count, and
SMSandCTAS_PER_SMleave the path entirely. #84 showedCTAS_PER_SMis measured and underivable, so a persistent grid picked from it isright for a B200 and cannot be known to be right for anything else.
Since CLC is not faster, adopting it has to be argued on portability alone — and
the evidence that would settle it is a second device shape, which is exactly what
this repo cannot currently run. Saying so beats asserting it either way. So
gemm::benchandcheckstill default to the static schedule, deliberately:this PR's
::benchrow stays comparable to every earlier one.The mechanism, checked directly rather than through a GEMM
device-testsgainsclc work stealing, which asks the instruction thethree questions the scheduler assumes of it. Over a 4096-cluster grid:
one that did, each once. That is the property a dropped or doubled tile breaks.
.multicast::cluster::allcompletes the transaction in every CTA of therequesting cluster and not only the issuer.
run_stealinghas each rank waiton its own copy, which is only sound because of this.
cluster and
item = ctaid_x / cluster_sizeis the right map.Each rank waits on a deadline rather than on the barrier, so the failure the
case exists to catch reports itself instead of hanging. That was not
hypothetical: the first version of this probe reported 3758 of 8192 CTAs as
stalled, and the bug was in the probe — a cancelled cluster is never launched, so
its row keeps the zeros the buffer was allocated with, which is byte-for-byte
what a stalled rank writes. A
launchedsentinel written at entry separatesthem. The probe is built on the raw
cuda_device::clcintrinsics, not onClcQueue, so a failure cannot be ambiguous between the instruction and mywrapper.
Two findings about
cuda_device::clc1. The module's usage example has
is_canceledexactly backwardscrates/cuda-device/src/clc.rs, module doc:Eighty lines below, the function's own doc says the opposite:
crates/mir-lower/src/convert/intrinsics/clc.rssettles it:The return is 1 exactly when the
is_canceledpredicate is true, and thatpredicate is true when the request succeeded. The function doc is right and
the module example is wrong.
This PR uses
!= 0as work-available. The evidence that this is the rightway round is not that I read the assembly — it is that
::examplespasses andthe probe reports 1874 cancellations carrying coordinates. Inverted, a successful
steal reads as "no work left", the cancelled cluster is never launched, and its
tile is computed by nobody: a wrong
C, silently, at every size large enough tosteal. Anyone following the module example gets that, and the failure looks like
a scheduling bug rather than a doc bug.
2. CLC is inline PTX — an LLVM backend gap upstream has already absorbed
crates/mir-lower/src/convert/intrinsics/clc.rs:Against #42's frame, which is the right one to read this through:
stmatrixcase is one broken declaration — a localptx_asm!routesaround a single defect.
cp.reduce.async.bulk.tensorcase is a whole family absent from thegenerated catalog, which is what argues for upstreaming.
CLC is a third thing, and the least demanding. The family is not absent — all
six functions are present and all six lower. The defect is one level below
cuda-oxide, in LLVM's NVPTX backend, and upstream has already routed around it in
its own lowering. So the consequence here is nothing owed and no
ptx_asm!inthis repo:
pipeline.rscalls the ordinarycuda_device::clcfunctions andnever spells a
clusterlaunchcontrolinstruction. Recorded so the next readerwho notices inline assembly in the lowering does not mistake it for a hazard we
carry, or file #42's argument against it.
Both are candidates to report upstream. Nothing has been filed by me.
Design notes
The item boundary count is unchanged. #90 priced that boundary at a fifth to
a third of the launch, so this needed auditing rather than assuming:
runtakestwo per item (after
init, afterwork);run_stealingalso takes exactly two(after
init, afterharvest). The stealing path adds one extracluster_syncfor the whole kernel — arming the response barrier before any rankcan complete transactions on it — not one per item. Against the ten items a
cluster walks at 8192³, that is one boundary against twenty.
What orders a read of the response against the next request. Every thread
reads the response, so the buffer is read by many threads and overwritten by one.
The harvest is therefore placed before the item boundary that already exists:
that boundary both retires the item and says no thread is still reading the
response the next request will land on. It costs no extra barrier.
On the last item — where the steal fails and there is no next request — the
ordering constraint simply has no partner to violate. The trailing boundary still
runs, every rank leaves the loop together (the multicast guarantees they agree),
and
disarminvalidates the barrier with nothing outstanding. Nothing canoverwrite a buffer anyone is still reading because nothing writes again at all.
run_stealingrequiresJob::RANKSto equal the launch's cluster size,which
rundoes not. It is documented in# Safetyrather than worked around:the response is multicast to the cluster and read by every thread of it, so the
boundary separating those reads from the next request has to cover the same set.
A
RANKS == 1job under a multi-CTA cluster launch would take abar.syncthereand race.
Verification
modal run modal_app.py::examples— every scheduler exact at both sizes,including 4096x4096x256 at 512 clusters under CLC, where 512 clusters
against ~222 residency means stealing genuinely happens.
modal run modal_app.py::device_tests— 32/32, including the new probe.modal run modal_app.py::clc_bench— the table above.modal run modal_app.py::bench— the static control against Two fp32 a store where the layout pairs them, and the boundary intercept says so (#91) #94 onmain:4096³ 0.1528 vs 0.1534, 8192³ 0.8991 vs 0.8987, 16384³ 6.8301 vs 6.8098. All
inside the 0.6% spread Two fp32 a store where the layout pairs them, and the boundary intercept says so (#91) #94 documents,
blocksstill 444. The +24 B of sharedplan cost nothing and residency is unchanged, so the A/B is valid.
modal run modal_app.py::build— green, realsm_100acodegen of both GEMMentry points and the probe.
cargo clippy --all-targets -- -D warnings,cargo test(78 + 1), andcargo fmtacross all three manifests — the root one does not reachdevice-tests, which is what madedevice-surfacered on the first push.::buildand::device_testswere re-run after the prefetch was deleted.::clc_benchand::benchwere not, and did not need to be: in thePREFETCH = falsemonomorphization the two prefetch blocks were already dead andthe live one was
charge/issueafter the tcgen05 fence, which is exactly thesurviving sequence. A
const boolbranch is resolved at monomorphization, so thetimed path's codegen is unchanged; everything else the trim touched is host-side
or a symbol rename.
Rebased onto
500927c. My owncpu=/timeout edit is dropped in favour of#93 — the only Modal change here is the
clc_benchentry point. The one edit tobench.rs, which #86/#90 owns, is makingTimings::minpub; it is stillprivate on
main, so it is not a duplicate, and it is the whole of my change tothat file after the rebase onto #96.
What I did not do
softmaxandlayernormare untouched — neither is persistent and neither has anitem to steal.
flash_forwardis the kernel that would most want this and stillhas no launcher (#85), so a scheduler cannot be checked for correctness on it,
let alone timed.