Repository navigation
The occupancy step is 168, not 170, and regcount now fails the run on it (#95) - #100
Merged
Merged
Conversation
`modal_app.py::regcount` now derives, per gated kernel, the most registers a thread may use and still hold the CTAs per SM the kernel's own grid is sized for, and raises when `ptxas` went over. The ceiling comes from the launch and the register file, never from a constant: `#[launch_contract(block = ...)]` and `const CTAS_PER_SM` are read out of the kernel's own source, and the arithmetic is transcribed from `cudaOccMaxBlocksPerSMRegsLimit` and checked against the toolkit's `cuda_occupancy.h` on every run. At 128 threads the step is 168, not the 170 a naive `file / threads / CTAs` gives: registers are allocated per warp in units of 256 across four sub-partitions. `gemm_cg2` is at 167, so its headroom is one register. `regcount` also ran in no workflow at all, so nothing between `gemm_cg2` and a silent third of its occupancy was automatic. It is a tier-2 job now.
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 #95.
The answer, in one line
The gate is in
regcountand it fails the run on the step. The step is 168,not 170 — so
gemm_cg2has one register of headroom, not three — andregcountwas running in no workflow at all, so the gate had nowhere tofire from until this PR put it on tier 2.
1. The gate
modal_app.py::regcountgrew a fourth table, and it is the only thing in thisrepo that fails a run on a register count:
Nothing in that row is a constant in
modal_app.py.threadsis the exactblock shape out of
#[launch_contract(block = (128, 1, 1))]— the same literalthe host launch is validated against — and
wantsisconst CTAS_PER_SM: u32 = 3, the residencygemm_cg2's own grid is sized from, bisected on a clock by#83 and counted with
%smidby #84. Both are read out ofexamples/src/gemm.rsat run time, so if
THREADSor the residency target moves, the gate moves withit. If either declaration goes missing the gate raises rather than quietly
watching nothing. A kernel joins
GATED_KERNELSby declaring both;gemm_cg2is the only kernel in the repo that does today.
It gates on the step, not on a count. 167 → 165 passes. 167 → 169 fails,
because 169 is the register that costs a CTA.
And the comment says what the number does not mean. Crossing the step is not
a claim that the kernel got slower per thread — this repo has five occasions
where the register column ordered time backwards (#47, #63, #67, #76, #94), and
#94 spent 40 → 167 registers on this very kernel for +13.7%. Occupancy is the
one consequence of a count that does not depend on a theory of what the
registers are for, and for
gemm_cg2it is not even abstract: the grid isliterally
SMS * CTAS_PER_SM / RANKSclusters, so a residency it no longer hasis a persistent grid that oversubscribes.
2. The step is 168, and #95's table is wrong by two
#95 gives ≤170 → 3 CTAs. The real arithmetic is coarser, and in two ways at
once — this is #95's own "if the step arithmetic is more complicated than the
table, that is a finding":
whole.
Both read off
cuda_occupancy.hforcomputeMajor == 10(
cudaOccRegAllocationGranularity→ 256,cudaOccSubPartitionsPerMultiprocessor→ 4). So 169 registers a thread is 5408 a warp, which rounds to 5632, of
which a 16384-register sub-partition holds two warps and not three — 8 warps
an SM, 2 CTAs of 128 threads. 168 is 5376 exactly, which fits three.
At 128 threads on sm_100a:
gemm_cg2is at 167. One register of headroom, not three.I did not want to ship a transcription on my own reading of a header, so the
gate checks it.
_check_occupancy_modelwrites a ~25-line C++ file thatincludes the toolkit's
cuda_occupancy.h, fills in only the arch and theregister file, calls NVIDIA's own
cudaOccMaxBlocksPerSMRegsLimitat everyregister count
ptxascan emit, and raises on any disagreement. It needs nodriver and no GPU, which is the whole reason it can live in a CPU-only gate:
The one hardware number that stays hardcoded is the 64 K register file, named
and sourced.
ptxasis the only NVIDIA tool in the container that might havebeen asked instead, and it does not know.
Two smaller things the header says that the naive model does not:
ptxas' own255 binds before the header's
maxRegsPerThreadof 256 for compute major ≥ 7,and from Hopper onward block barriers are an occupancy term too
(
cudaOccMaxBlocksPerSMBlockBarrierLimit;ctaLimitBlocks * 2available at10.0). The gate does not model barriers —
ptxas -vreports them and they arenowhere near binding here — but it is a real fifth term and worth knowing exists.
3.
regcountwas in no workflowThis is the part of #95's premise that did not hold, and it mattered more than
the arithmetic.
regcountis referenced inREADME.md,GAPS.mdandexamples/README.mdand appears in no file under.github/. Tier 2 ran::buildand nothing else. So the only thing standing betweengemm_cg2and asilent third of its occupancy was somebody remembering to run an entry point by
hand and read a column of a fifty-row table.
cuda.ymlnow has a second job that runsmodal run modal_app.py::regcount. Aseparate job rather than a step in
build, because it goes red for a differentreason — a register count, not a compile — and that belongs on the check list
rather than inside a log; and because it is independent work that can run beside
build. The cost is honest and stated inCI.md: it builds both kernel cratesin its own container, so tier 2 costs roughly twice what it did. Still
CPU-minutes.
4. The positive control, and its actual red output
Per #67 and #76: a check nobody has seen fail is not a check.
groupnorm_tileinexamples/src/layernorm.rsis a real kernel at a real 236registers and 128 threads — the one that file's header deliberately leaves
holding the whole band. Temporarily giving it
#[launch_contract(domain = 1, block = (128, 1, 1))], giving the fileconst CTAS_PER_SM: u32 = 3;, and addingit to
GATED_KERNELS— three edits, all reverted, none of them in this diff —modal run modal_app.py::regcountexits 1:gemm_cg2stays green in the same table, which is the half of a control that iseasy to leave out.
What this control does not do is inflate
gemm_cg2itself, and the reason isitself a finding — §6. I could not make that kernel exceed 168 by adding live
state, and I did not touch
examples/src/gemm.rsto fake it.5. Is the 40 → 167 jump load-bearing? Measured, CPU-only
-maxrregcounton the same PTX — no rebuild, so nothing else varies — sayswhat a smaller budget costs this kernel:
Three things fall out of that table.
167 is not what the kernel needs — it is what
ptxaschose. The identicalPTX compiles at 144 registers with zero spill and an unchanged 528-byte
frame. So at least 23 of the 167 are allocator headroom, not live state. The
first real cost is at 136 (44 bytes each way), and getting back to 40 — the
pre-#94 number — costs 2376 bytes of spill stores. The old 40 was never this
kernel compiled cheaper; it was a different amount of work.
167 is not a ceiling either. Given a 255 budget
ptxastakes 234 on thesame PTX. Both directions are available and it picks 167.
The band is not what moved. #94's own table has the frame at 528 bytes on
both sides of the change, and a
[32, 128]fp32 band is 512 bytes. The bandlived in local memory before #94 and still does. Whatever the 127 registers are,
they are not the accumulator.
So: the jump bought 13.7% and I have no reason to doubt that. The number 167
is not load-bearing — there is a 23-register gap between what
ptxasallocatedand what it needs to compile this kernel without spilling, and that gap is free
headroom for #15, #87 and #88 if they want it.
I did not establish the mechanism of 40 → 167. #94's agent's guess (the
memory clobber) was measured and wrong, and I have not replaced it with a
measured one. What I can say is that the store loop's shape moves the number
by about 20 (§7) and the allocator's target sets the rest, and neither of those
is "what the extra live state is". I would rather leave that open than add a
sixth wrong theory to the five this repo has already collected.
6.
ptxaspins this kernel at 168, and that resets what the gate is forI tried three times to push
gemm_cg2over its step fromsrc/global.rs, whichI was cleared to change. This is what happened:
gemm_cg2global_copy_probe_128_moversld.global.v2, memory clobber both ends)Eight registers of live state that
ptxascannot fold, sink or rematerialisemoved it one register. Thirty-two moved the frame by 256 bytes and left
the count at 168.
And look where everything lands:
gemm_cg2167,flash_forward168,global_copy_probe_128_movers168,global_copy_probe_128_open_coded168. Fourunrelated kernels within one register of each other, and 168 is exactly the
largest count that keeps twelve warps on an SM.
ptxas' default allocationtarget sits on this kernel's occupancy step.
That is worth stating plainly, because it changes what #95's risk actually is.
"#15 or #87 adds live state and the count drifts past 170" is not the failure
mode —
ptxaswill spill before it does that, and #87's bigger pair tile willshow up as spill bytes and a growing frame, not as a count over the step. What
will fire this gate is
THREADSorCTAS_PER_SMmoving (#87 is a plausiblesource of both), a
#[launch_bounds]or-maxrregcountbeing introduced, or atoolkit upgrade moving
ptxas' default. Those are all real, all silent today,and the gate is now the thing that notices. That paragraph is in the gate's own
comment, not only here.
It also means the gate is close to vacuous only for this one geometry, not in
general: at 256 threads a kernel wanting 2 CTAs/SM has a ceiling of 128, well
under
ptxas' target, and the gate bites immediately.7. Reclaimable headroom, for whoever takes #15 / #87 / #88
Two levers, both measured, neither shipped here, each with the reason.
(a) 23 registers, free, no source change.
-maxrregcount=144compiles thiskernel with zero spill and an unchanged frame. The cleaner spelling is
cuda-oxide's
#[launch_bounds], which emits.maxntid/.minnctapersmand makesthe residency target a compiler input rather than a CI check — in
examples/src/gemm.rs, which I am not touching:Caveat, and the reason this is a sketch and not a diff:
.minnctapersmmakesptxasspill rather than exceed, so it converts an occupancy loss intolocal-memory traffic, and #47 priced exactly that trade at 2.6× on
softmax. Itneeds a clock.
regcountshows the static half for free.(b) ~20 registers from the store loop's shape. Transposing
store_rows_in_runs' nest — value outer, slot inner, the same stores to the sameaddresses in a different order — moves
gemm_cg2167 → 148 andglobal_copy_probe_128_movers168 → 146. Two kernels, same direction, samemagnitude:
src/global.rswas cleared for me to change, and I deliberately did not. Everyinstruction touches the same 32 lane addresses either way, so per-store sector
utilisation — the whole of #94's win — is unchanged; what changes is the order
the stores are issued, and therefore row locality across successive
instructions. The epilogue is 20–22% of the 8192³ launch by #94's own fit. That
is a timing claim, this issue booked no B200, and shipping an untimed reordering
of the hot epilogue is exactly the move this repo keeps writing issues about. It
belongs to whoever next runs
--case gemm-depth.Scope
examples/src/gemm.rsandsrc/pipeline.rsare untouched, as is all ofsrc/,device-tests/and the rest ofexamples/. #97 is unaffected.modal_app.py: the occupancy model, the ceiling, the source-parsed launchgeometry, the
cuda_occupancy.hcross-check and the gate. ~250 lines, most ofit comment.
.github/workflows/cuda.yml: aregcountjob on tier 2.CI.md,README.md: what the gate is, what it costs, and what 168 is.Verification
modal run modal_app.py::regcount— exit 0 on this tree; table in §1, modelcross-check green at all 255 counts, ladder and timed-twins tables unchanged
from
main(identical at all 20 rungs).modal run modal_app.py::regcounton the control tree — exit 1, output in§4, reverted.
modal run modal_app.py::build— exit 0, every step including the realsm_100acodegen of both kernel crates and thecublasfeature.-maxrregcountprobe behind §5 and §6 (temporary, not in this diff).Measured vs inferred. Measured: every register, spill and frame figure; the
step table, against NVIDIA's own model, compiled and run; the three inflation
attempts; the transpose. Inferred, and flagged as such in §6: that the 167/168
clustering across four kernels is
ptxas' default occupancy target rather thanfour coincidences. Not established, and stated as such in §5: what the 127
registers #94 added actually hold.