Skip to content

A masking write under a data-dependent condition is a rolled walk, and it unrolls now (#184) - #191

Merged
feitreim merged 2 commits into
mainfrom
fix/184-mask-rolled-walk
Aug 5, 2026
Merged

feitreim merged 2 commits into
mainfrom
fix/184-mask-rolled-walk

Conversation

@feitreim

@feitreim feitreim commented Aug 5, 2026

Copy link
Copy Markdown
Owner

Closes #184.

RegTile::mask was the rolled walk #180 did not reach, and it carries #166's
pattern now — __unroll_config::<0>() plus an inline-const bound on both
levels. That is the whole of the code change; the rest of this is the
measurement that says it should ship, because the naive form of it is what #184
recorded and did not push.

Why a mask and not a map

A conditional write is a different shape from the maps beside it.
self.set(slot, value, fill) under a data-dependent keep keeps the slot array
addressable across the branch, so the rolled walk homed the whole tile to a
.local frame — and homed it on every iteration of whatever loop the mask sat
in, not only on the ones that masked anything. That is why one right_fill on
one chunk in 786 cost oxide-train's tile classifier a 400 B frame with the
stores inside the vocabulary loop. Nothing else in reg.rs has that shape: a
map writes every value unconditionally and a reduction writes none, which is why
this is the only walk in the file that unrolls and the map walks stay #166's
open remainder.

regcount (sm_100a), main 5e4d3ff -> this branch

Two entry functions move. Every other row of all three tables is identical —
194 harness kernels, 8 examples/, 83 experiments/, same registers, same
spills, same stack, same smem. Occupancy gate green, timed twins green.

kernel regs spill st/ld stack .local decl st.local ld.local
examples/flash_forward shipped 165 -> 255 0/0 -> 0/0 1824 -> 1568 1 -> 1 774 -> 690 451 -> 383
device-tests/mask_probe_128_causal probe 71 -> 255 0/0 -> 0/0 1536 -> 1536 1 -> 1 556 -> 664 284 -> 280

The two rows moving in opposite directions is the finding, not an anomaly. The
probe's load walk is open-coded on purpose — it is what a kernel writes without
the movers — so its band stays in the frame and an unrolled mask reads it out
and writes it back. flash_forward's walks around the mask are movers and
already unroll, so its band leaves the frame instead. The probe's frame does not
grow: its st.local is a static instruction count, and unrolling trades one
rolled store for 128 predicated ones at constant offsets without changing what
runs. The census comment now says which of its columns are bytes and which are
instructions, because that distinction is the whole of this table's diff.

mask_probe's doc carried #7's claim that make_causal_at and the loop it
replaces price alike. That is now true at 32 columns and false at 128, and the
doc says so and says why.

The 255, measured rather than argued

flash_forward is the constraint #184 stopped on. It is not a spill and it is
not an occupancy step:

  • ptxas reports 0 spill stores and 0 spill loads at 255.

  • The driver reports 1 block/SM before and after. This kernel's own
    147 532 B shared plan admits exactly one CTA against the SM's 227 KiB, so the
    register term — three CTAs' worth to two — has no second CTA to take away.
    device-tests' occupancy ladder makes the same point from the other side.

  • It gets faster. scripts/modal-run examples on a B200, checked before
    timed, five warm-ups and the minimum of thirty launches:

    before after
    1024 queries x 2 heads 0.2135 ms 0.1828 ms 1.168x
    2048 queries x 4 heads 0.3966 ms 0.3347 ms 1.185x

+90 registers, -15% wall clock: the register column ordering time backwards for
the sixth time here (#47, #63, #67, #76, #94), because the frame it replaced was
written and read in the innermost loop. docs/kernels/flash_forward.md carries
the table and the caveat — a kernel with room to spare in shared memory, where
the third CTA is real, would read this differently.

The downstream witness

A scratch clone of oxide-train at feat/issue-70-tile-probes, gpu/ops pinned
to this branch's 445f88e, nothing else touched.
fused_classifier_forward_tile_bf16 is a warp-per-band softmax over a
RegTile<16, 64> whose only use of mask is one right_fill:

frame st.local ld.local regs
at its own pin __local_depot13[400] 150 104 48
pinned here __local_depot13[272] 66 36 64

128 B, exactly one ClassChunk (RegTile<16, 64> is 2 slots x 16 values of
fp32). The mask's tile came out of the frame and nothing else did; the 272 B
that remain are the row_max / sub_row / exp / row_sum walks around it,
which are #166's map-walk remainder and not this issue. So the depot does not go
to zero, and the reason it does not is attributable to the byte.

On a clock, same container, shipped block-per-row kernel as the control:

tile ratio to shipped
at its own pin 3.3831 ms 732.7 GB/s 0.438x
pinned here 2.4914 ms 995.0 GB/s 0.594x

1.358x, and past the 0.563x #184 measured for deleting the right_fill
entirely — the walk was costing more than the mask it computed. Every other
family in that bench is unmoved within 1.5% (rms_norm forward/backward, four
swiglu rungs), which is the control that says this is the mask and not the
container.

This is a witness, not a perf claim. That kernel loses either way, it is out
of the training path, and oxide-train#78 leaves it flat. No training step gets
faster from this.

What is deliberately not done

Both alternatives to the unroll were built and measured, and both are worse:

  • The select form — self.set(slot, value, if keep {old} else {fill}), so
    there is no branch to keep the array addressable. Without the markers the walk
    stays rolled and the frame stays: flash_forward 165 -> 167 registers, 1824 B
    either way, depot 774/455. With the markers it produces a byte-identical
    regcount table to the branch form. The extra get buys nothing, so the
    branch stays.
  • BaseLdtm::column's [0, 1, 8, 9][value % 4], which RegTile::mask is a rolled walk #180 did not reach: a 400 B frame and 27% of a kernel, from one right_fill #184's PTX shows
    being re-stored to .local and read back by a runtime index every iteration.
    It is equal to 8 * (value / 2) + value % 2 — no array, pure arithmetic, and
    the existing host tests pass on it unchanged. It is also a tree-wide codegen
    perturbation: half the ladder and probe rows move, in both directions
    (ladder_probe_32x192_all_in_place 251 -> 32, ladder_probe_32x256_fused
    picks up 456 more spill stores, several rungs lose their 144-272 B frames
    outright), and four of regcount's twenty timed rungs come off their ladder
    twins
    , which fails the run. It is a real finding and it wants its own issue
    and its own before/after; it is not this change, and RegTile::mask is a rolled walk #180 did not reach: a 400 B frame and 27% of a kernel, from one right_fill #184 does not need it —
    once the mask unrolls, value is a constant and that table folds.

Gates

  • scripts/fmt --check, cargo test (111 + 81 doctests) clean.
  • scripts/modal-run regcount from this branch: green end to end, tables above.
  • scripts/modal-run device_tests on a B200: 51 of 51.
  • scripts/modal-run examples on a B200: every check passes, flash_forward
    2x256x128 rows attended, worst relative error 1.66e-3 — the same figure as
    before the change.

@feitreim feitreim added the gpu-ci Run the B200 device-test tier on this PR (costs GPU minutes) label Aug 5, 2026
@feitreim

feitreim commented Aug 5, 2026

Copy link
Copy Markdown
Owner Author

The BaseLdtm::column half of "what is deliberately not done" is now #192, with its own before/after table — 14 frames removed, 14 spill regressions, four timed twins off the ladder. It is not needed here: once mask unrolls, value is a constant and the array folds.

@feitreim
feitreim merged commit 92fc5f3 into main Aug 5, 2026
4 checks passed
@feitreim
feitreim deleted the fix/184-mask-rolled-walk branch August 5, 2026 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gpu-ci Run the B200 device-test tier on this PR (costs GPU minutes)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RegTile::mask is a rolled walk #180 did not reach: a 400 B frame and 27% of a kernel, from one right_fill

1 participant