Repository navigation
Put a clock on the register ladder: a streamed band costs, and #47 says what it buys (#63) - #68
Merged
Merged
Conversation
…ys what it buys (#63) #60's ladder found the in-place spellings 81 to 130 registers under the fused one at three shapes, on a stack frame at least as large as the form they beat — ptxas deciding the band did not fit, leaving it addressable in local memory and streaming it. `ptxas -v` reports what was allocated and never what it cost, so the ladder could pose the question and not answer it. This times it, on a B200. `modal run modal_app.py::ladder_bench` times four rungs: `[32, 96]`, `[48, 64]` and `[64, 64]`, where the effect is largest, and `[32, 128]` as a control where fused wins on both static counters. Five spellings each, at one warp and at a device-filling grid, with registers, local frame and occupancy read off the driver for the function that actually ran. On the probe, the streamed band is not slower — it is the *fastest* thing in the table. The most streamed spelling (32 registers, whole band in local memory) wins at every shape on both grids, by 6-10% per warp and 25-42% across the device. And the control comes out backwards: at `[32, 128]`, where `fused` is 168 registers with no spill against `assign`'s 252, `assign` is 6% faster per warp and 15% faster across the device. That is the opposite sign to #47, which landed on main while this was being measured and found a streamed band costing 2.6x on `softmax`. Both are right, and the gap is the result worth having: what differs is what the freed registers are able to buy. `softmax` is shared-memory capped at 6 blocks an SM at either register count, so streaming bought it nothing and the local traffic showed undiluted; the ladder probe uses no shared memory at all, so streaming bought it 2-4x the resident warps. A streamed band costs real time, and whether it is worth paying is a question about which resource is binding in that kernel — visible even inside the probe's own table, where `[48, 64]`'s `assign` gets twice the warps and is still 5% slower. So the advice is not "fewer registers" and not "more". It is: read the register count with the occupancy beside it, and ask whether this kernel gets more warps if the band leaves the register file. If shared memory caps it anyway, keep the band in registers and walk the tile in narrower chunks (#47). If registers are binding, the in-place spellings that let ptxas stream are the fastest thing measured here. What keeps the numbers honest: - Verified before timed, bench.rs' rule. Every configuration that gets a number is launched once first and compared elementwise against an f64 reference that walks BaseLdtm's map on the host, over every block of the grid. All twenty rungs matched to 1.4e-4 against a 0.02 tolerance. - The work cannot be optimized away, and the last of the four reasons is measured rather than argued: `steps` is a runtime argument, each iteration reads a different block of `scores`, `out_acc` is a serial dependence that reaches memory — and the same rung timed at 2x the steps is within 0.010 of exactly 2x the time, at every rung. - The kernel timed is the kernel priced. `ladder_timed_*` is the ladder's own probe body at the same (M, N, FORM), differing in a `const STRIDED` that gives each block its own output band so a grid may run it at all. `::regcount` prints the twins side by side and now raises if any rung disagrees; they are identical on all twenty, every counter. The ladder's fourteen-shape table reproduces its recorded numbers cell for cell, and `--determinism` passes on 150 kernels. - A stated noise floor. Five rounds of twenty launches per rung; the widest round-to-round spread anywhere is 0.8%, so a ratio inside 1 +/- 0.008 is not a difference this run can see. Two limits stay attached: the probe is one load-heavy op at one arithmetic intensity, and local-memory traffic was measured on neither side — that the band is streamed is still read off the frame and the register count. Closes #63
feitreim
force-pushed
the
time-the-streamed-band
branch
from
July 28, 2026 04:03
443d668 to
1740610
Compare
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.
#60's ladder found the in-place spellings 81 to 130 registers under the fused
one at three shapes — on a stack frame at least as large as the form they beat.
That is not in-place winning; it is
ptxasdeciding the band does not fit,leaving it addressable in local memory and streaming it.
ptxas -vreports whatwas allocated and never what it cost, so the ladder could pose the
question and not answer it.
modal run modal_app.py::ladder_benchtimes it. Four shapes, not fourteen —[32, 96],[48, 64],[64, 64]where the effect is largest, and[32, 128]as a control where
fusedwins on both static counters (168/0 against 252/0).What it measured
One B200, 148 SMs, 64 warps/SM.
1 warpis nanoseconds of kernel time per bandelement per step for a single 32-thread block;
deviceis picoseconds for thesame over 9472 such blocks (64 per SM, twice what any spelling holds resident).
×is against thefusedrow of the same shape.regs,frameandwarps/SMare read off the driver for the function that actually ran.
[32, 96]fusedassignreboundall in place[48, 64]fusedassignreboundall in place[64, 64]fusedassignreboundall in place[32, 128]fusedassignreboundall in placeopen_codedis omitted only because it lands within 0.1% ofassignat everyshape, as it lands on the byte at every static counter.
Noise floor 0.8% — the widest round-to-round spread over all twenty rungs and
both grids, most cells 0.1–0.6%. A ratio inside 1 ± 0.008 is not a difference
this run can see.
What it found
On this probe, a streamed band is not slower — it is the fastest thing in the
table. The most streamed spelling (32 registers, whole band in local memory)
wins at every shape on both grids, by 6–10% per warp and 25–42% across the
device.
And the control comes out backwards.
[32, 128]was chosen because it is theladder's cleanest "fused wins" cell. On the clock
assignis 6% faster per warpand 15% faster across the device. The one shape where the counters agreed is the
shape where they were wrong.
Nothing in
ptxas -vorders the table. Not registers —assignis 47 at[32, 96]and 252 at[32, 128], and is 0.99× and 0.85× fused respectively, thecheaper one being the one that fails to win. Not the frame. Not occupancy
either: at
[32, 128]assignruns 8 warps/SM againstfused's 12 and isfaster anyway; at
[48, 64]it runs 32 against 16 and is 5% slower.the two results disagree, and that is the finding
#47 timed the same phenomenon on
softmaxand it cost 2.6×. What differs isnot the band — it is what the freed registers are able to buy:
softmaxis shared-memory capped: 6 blocks an SM at 39 registers a threadand 6 at 66. Streaming buys it nothing, so the local traffic shows undiluted.
constraint: 8 warps an SM at 251 registers, 32 at 32. Streaming buys 2–4× the
resident warps, and that is what pays for it.
So neither "streaming is free" nor "streaming is expensive". A streamed band
costs real time, and whether it is worth paying depends on whether the registers
it frees are the constraint actually binding. The price when the payment falls
short is visible inside the probe's own table: at
[48, 64]assigngets twicethe warps and is still 5% slower.
The advice. Read the register count with the occupancy beside it and ask:
does this kernel get more warps if the band leaves the register file? If
shared memory or the launch geometry caps it anyway, keep the band in registers
and walk the tile in narrower chunks — exactly what #47 did, for 2.6×. If
registers are binding, the in-place spellings that let
ptxasstream are thefastest thing measured here, and the register table's "failure" is a win.
Spelling at fixed shape is worth 1–3%; which side of the streaming cliff the
shape sits on is worth 25–160%. Pick the shape first.
Two things do survive at all four shapes:
assignandopen_codedareindistinguishable on the clock as well as on every static counter (the strongest
form of #31's claim yet), and
reboundis the slowest per warp everywhere by1–3%, three to five times the noise floor.
What keeps the numbers honest
bench.rs' rule. Every configuration that gets anumber is launched once first and compared elementwise against an
f64reference walking
BaseLdtm's map on the host, over every block of the grid.All twenty rungs matched to 1.4e-4 against a 0.02 tolerance — the same figure
everywhere, which is what "the same arithmetic, five ways" looks like when it
is true.
measured rather than argued.
stepsis a runtime argument so the trip countis not constant; each iteration reads a different
M·Nblock ofscores, sothe loads are not loop-invariant;
out_accis a serial dependence that reachesmemory. And the same rung timed at 2× the steps is within 0.010 of exactly
2× at every rung. This is the trap regcount measures two widths because probes are hand-written, not because measuring is expensive — sweep the ladder #60 hit once, where a probe let the
compiler restructure the loop nest until every rung collapsed to 32 registers.
ladder_timed_*is the ladder's ownprobe body at the same
(M, N, FORM), differing in aconst STRIDED: boolthat gives each block its own output band so a grid may run it at all.
::regcountprints the twins side by side and raises if any rung disagrees;they are identical on all twenty, every counter. The ladder's fourteen-shape
table also reproduces its recorded numbers cell for cell, so the new const
parameter changed nothing, and
--determinismpasses on 150 kernels.Caveats stated in the text
The probe reads
M·N/32fp32 a thread per step and does about three flops oneach, so it is a load-heavy loop with a long serial dependence; at one warp a
B200 SM is issue- and latency-bound rather than short of registers, which is
visible in the per-warp column being nearly flat (4.35–5.25 ns across every
spelling and shape). A compute-dense inner loop could price a streamed band
differently. And local-memory traffic was measured on neither side — no
profiler was run, so "the band is streamed" is still read off the frame and the
register count. What was measured is time, which is the thing the register table
was being used to predict.
Cost
One deliberate GPU run, four shapes, not a sweep. Everything static was settled
CPU-side first (
::build,::regcount).Closes #63