Repository navigation
The GEMM entry points declare their block, so the driver stops deriving it (#122) - #123
Merged
Merged
Conversation
`rebuilds` builds one commit N times and reports, per round, the PTX digest, the entry emission order, per-function body digests and `ptxas -v`'s allocation. That is the whole layer bisection in one table: PTX bytes moving is codegen (rustc + the cuda-oxide backend + `llc`), bytes identical with registers moving is ptxas. Every round builds at the *same* path, because cargo's `-C metadata` disambiguator is derived from it and rides inside every mangled generic symbol — per-round directories make the PTX differ for a reason that has nothing to do with the question. No GPU: `cargo oxide` links the driver stub and ptxas is the allocator anyway. `jit` is the half that needs one. `cargo oxide` emits `<kernel>.ptx` and `load_kernel_module` hands the text to `cuModuleLoad`, so the registers a kernel actually gets are assigned by the *driver's* JIT at load time — the one compiler in the chain this tree does not pin. It prints the PTX digest, the driver version, the image ptxas' allocation and `cuFuncGetAttribute`'s side by side, so a disagreement between the last two is legible.
…driver stops deriving it `cargo oxide` emits PTX and the driver JITs it at `cuModuleLoad`. An entry point carrying no `.maxntid` tells that JIT nothing about the block it will be launched in, so it allocates against the architecture's 255 registers and then *derives* the largest block the result can be launched in. Measured on the warpgroup-split commit of #119: 640, 640 and 384 threads, from 86, 96 and 140 registers. A build that had chosen 182 would have derived 256 — below that kernel's own 320 — which is `max_active_blocks_per_multiprocessor` of 0 and `DriverError(701)` at the first launch, and is exactly what #119 saw once in three. The same 182 is fine at 192, which is why this is invisible today. `#[launch_bounds(192, 1)]` on the three shipped tcgen05 GEMMs makes the geometry an input instead of an output: `.maxntid` now reads exactly 192 rather than a number the allocation happened to imply, and one resident CTA is a constraint ptxas must satisfy. An allocation that cannot reach it spills, which the budget gate already fails on, instead of producing a kernel the driver refuses. Two ceilings move with it — bf16 132 -> 160 and the fp32 store 168 -> 172, the reduce unchanged at 146 — with zero spill and zero frame throughout, and the budgets are ratcheted to match. The direction is the point: a `.maxntid` of exactly 192 is what lets the allocator spend the register file this kernel's one CTA an SM already owns. Residency does not move, because at 192 threads even 255 registers is still one CTA. Stable across four rebuilds at 160/172/146, parity green at unchanged tolerances.
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 #119 follow-up. The diagnosis is #122; this is the fix and the two
instruments that produced it.
The short version. The build was never the nondeterministic layer.
cargo oxideemits
gemm.ptxandcuModuleLoadhands the text to the driver's JIT, so theregisters a GEMM kernel gets are assigned by whatever
libcudathe Modal host has —the one compiler in this chain the tree does not pin. What made #119's split fragile is
separate and fixable: an entry point with no
.maxntiddoes not tell that JIT whatblock it will be launched in, so the JIT allocates freely and then derives the
largest block the result can be launched in. Measured on the split commit, unpinned:
maxntidgemm_tcgen05_bf16_optimizedgemm_tcgen05_f32_optimizedgemm_tcgen05_f32_accumulateThose fit
largest multiple of 128 ≤ 65536 / registers. Run it forward and 182registers derives 256, below the split's own 320 —
max_active_blocks_per_multiprocessorof 0 and
DriverError(701), which is #119's report exactly, and the same 182 derives256 ≥ 192 and launches fine on
main, which is why this is silent today.What ships
#[launch_bounds(192, 1)]on the three shipped tcgen05 GEMMs. The geometry becomesan input rather than an output:
.maxntidreads exactly 192 instead of a number theallocation implied, and one resident CTA is a constraint ptxas must satisfy. An
allocation that cannot reach it spills — which the budget gate already fails on —
instead of producing a kernel the driver refuses.
Two harnesses in
modal_app.py, which are what settled the layer question:modal run modal_app.py::rebuilds --kernel <k> --rounds N— builds one commit N times,each round a fresh copy at the same path, reporting the PTX digest, entry emission
order, per-function body digests and
ptxas -v's allocation. GPU-free. The same pathmatters: cargo's
-C metadatadisambiguator is derived from the build directory andrides inside every mangled generic symbol, so per-round directories give 8 distinct
PTX digests out of 8 for a reason that has nothing to do with the question (and,
measured, nothing to do with the allocation either — all 8 still 86/96/140).
modal run modal_app.py::jit --kernel <k>— the half that needs a GPU. Prints the PTXdigest, the driver version, the image ptxas' allocation and
cuFuncGetAttribute'sside by side, so a disagreement between the last two is legible.
Evidence
Registers move, and that is the pin doing its job.
gemm_tcgen05_bf16_optimizedgemm_tcgen05_f32_optimizedgemm_tcgen05_f32_accumulateUpward is the point rather than a cost: a
.maxntidof exactly 192 is what lets theallocator spend the register file this kernel's one CTA an SM already owns. Residency
does not move — at 192 threads even 255 registers is one CTA — and the budgets are
ratcheted to the new numbers.
Rebuild stability, 4 rounds with the pin:
gemm.ptxone digest, one entry order,160/172/146 every round, zero spill. (Unpinned
mainis equally stable at 132/168/146over 6 rounds — see #122 — so this is a claim about the declaration, not about
curing a flap.)
maxntidis now declared rather than derived.jiton a B200, driver 580.95.05:against the unpinned 640 / 640 / 384 above.
Gates.
gpu/gemm's four parity checks green at unchanged tolerances; the budgetgate green against the ratcheted ceilings; the build-time
ptxas -vand the driver'scuFuncGetAttributeagree on all three numbers.Throughput.
train_abagainstmain, 30 steps, two rounds alternating in onecontainer:
maincandidate/baseline = 0.9993, and the rounds cross — the candidate loses round 0 and
wins round 1 — against a within-arm spread wider than the gap. Unchanged, as expected:
the pin does not move residency, only who chooses the number.
Not in this PR
gpu/ops(81 kernels),gpu/tensor-gpu(31) andgpu/flash-attn'slib.rs(12)declare no bounds either. All are measured reproducible (#122's scope table) and none
is exposed today, but the check is an accident of their register counts rather than
anything in tree. Those crates are other agents' this week; #122 carries the follow-up.