Skip to content

Put a clock on the register ladder: a streamed band costs, and #47 says what it buys (#63) - #68

Merged
feitreim merged 1 commit into
mainfrom
time-the-streamed-band
Jul 28, 2026
Merged

feitreim merged 1 commit into
mainfrom
time-the-streamed-band

Conversation

@feitreim

@feitreim feitreim commented Jul 28, 2026 •

Copy link
Copy Markdown
Owner

#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 ptxas deciding the band does 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.

modal run modal_app.py::ladder_bench times it. Four shapes, not fourteen —
[32, 96], [48, 64], [64, 64] where the effect is largest, and [32, 128]
as a control where fused wins on both static counters (168/0 against 252/0).

#47 landed on main while this was being measured and found the same
phenomenon costing 2.6× on softmax — opposite sign. Both are right, and
the gap between them is the useful part; see "the two results disagree" below.
This PR is rebased on #66 and the two sections now read against each other.

What it measured

One B200, 148 SMs, 64 warps/SM. 1 warp is nanoseconds of kernel time per band
element per step for a single 32-thread block; device is picoseconds for the
same over 9472 such blocks (64 per SM, twice what any spelling holds resident).
× is against the fused row of the same shape. regs, frame and warps/SM
are read off the driver for the function that actually ran.

regs frame warps/SM 1 warp ns ×fused device ps ×fused
[32, 96] fused 128 1536 16 4.703 1.00 8.6 1.00
assign 47 1920 32 4.654 0.99 8.5 0.99
rebound 251 1536 8 4.772 1.01 10.3 1.20
all in place 32 1152 32 4.400 0.94 6.4 0.75
[48, 64] fused 128 1536 16 4.756 1.00 8.8 1.00
assign 40 1920 32 4.538 0.95 9.3 1.05
rebound 202 1536 8 4.839 1.02 10.6 1.19
all in place 32 1152 32 4.349 0.91 6.6 0.74
[64, 64] fused 162 2560 12 5.117 1.00 12.4 1.00
assign 32 2560 32 4.816 0.94 10.2 0.82
rebound 168 2560 12 5.249 1.03 10.8 0.88
all in place 32 1536 32 4.614 0.90 7.2 0.58
[32, 128] fused 168 2560 12 4.798 1.00 10.6 1.00
assign 252 2560 8 4.526 0.94 8.9 0.85
rebound 255 2624 8 4.950 1.03 11.7 1.10
all in place 32 1536 32 4.355 0.91 6.5 0.62

open_coded is omitted only because it lands within 0.1% of assign at every
shape, 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 the
ladder's cleanest "fused wins" cell. On the clock assign is 6% faster per warp
and 15% faster across the device. The one shape where the counters agreed is the
shape where they were wrong.

Nothing in ptxas -v orders the table. Not registers — assign is 47 at
[32, 96] and 252 at [32, 128], and is 0.99× and 0.85× fused respectively, the
cheaper one being the one that fails to win. Not the frame. Not occupancy
either: at [32, 128] assign runs 8 warps/SM against fused's 12 and is
faster 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 softmax and it cost 2.6×. What differs is
not the band — it is what the freed registers are able to buy:

  • softmax is shared-memory capped: 6 blocks an SM at 39 registers a thread
    and 6 at 66. Streaming buys it nothing, so the local traffic shows undiluted.
  • The ladder probe uses no shared memory at all, so registers are the only
    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] assign gets twice
the 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 ptxas stream are the
fastest 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: assign and open_coded are
indistinguishable on the clock as well as on every static counter (the strongest
form of #31's claim yet), and rebound is the slowest per warp everywhere by
1–3%, three to five times the noise floor.

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 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.
  • The work cannot be optimized away, and the last of four reasons is
    measured rather than argued. steps is a runtime argument so the trip count
    is not constant; each iteration reads a different M·N block of scores, so
    the loads are not loop-invariant; out_acc is a serial dependence that reaches
    memory. 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.
  • 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: bool
    that gives each block its own output band so a grid may run it at all.
    ::regcount prints 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 --determinism passes on 150 kernels.

Caveats stated in the text

The probe reads M·N/32 fp32 a thread per step and does about three flops on
each, 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

…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
feitreim force-pushed the time-the-streamed-band branch from 443d668 to 1740610 Compare July 28, 2026 04:03
@feitreim feitreim changed the title Put a clock on the register ladder: a streamed band is not slower (#63) Put a clock on the register ladder: a streamed band costs, and #47 says what it buys (#63) Jul 28, 2026
@feitreim
feitreim merged commit eb324e0 into main Jul 28, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Is a streamed local-memory band actually slower? ptxas cannot say, and the ladder now makes the question concrete

1 participant