Skip to content

The column map reads its operand once a column, and the shape it was filed on cannot tell (#196) - #199

Merged
feitreim merged 1 commit into
mainfrom
perf/col-map-hoist
Aug 6, 2026
Merged

feitreim merged 1 commit into
mainfrom
perf/col-map-hoist

Conversation

@feitreim

@feitreim feitreim commented Aug 6, 2026

Copy link
Copy Markdown
Owner

Closes #196.

The change

col_map / col_map_assign are documented as the column mirror of the row maps and were not written as one — the ColVec read sat in the inner loop, so the operand was read SLOTS × VALUES times where row_map_assign reads its RegVec SLOTS times. The issue's own fix: swap the nesting so the column walk is outer and hoist cols.get(value). Elementwise, independent ops over [[f32; VALUES]; SLOTS] either way, so the result is bit-identical and only the storage walk order changes. The two doc comments now say the thing the code does, and carry what the hoist measured.

reg.rs's host tests pass unchanged (112 + 1 unit/integration, 82 doctests) — as they must, since no host-visible property of these ops moved.

What it measured

The instrument is the one the issue asked for: device-tests' new axis_map_probe, a codegen probe that prices both loop orders in one build rather than two builds a week apart. The pre-#196 walk is open-coded as a third arm (col_map_inner_read) beside the library's column maps and the row axis, over the register pass oxide-train's flash_backward_kv and flash_backward_q share — subtract a saved statistic, exp2, subtract a second, multiply — at both the [32, 16] chunk the issue names and a 128-column band. Both statistics are read out of memory rather than reduced out of the tile, so no row_reduce/col_reduce asymmetry sits between the arms.

scripts/modal-run regcount, sm_100a, no ptxas spill anywhere; the last two columns are the depot census's static instruction counts:

                      regs   frame   st.local   ld.local
 16 row                 40     128         36         20
 16 col                 40     128         36         20
 16 col_inner_read      40     128         36         20
128 row                168    2048        712        456
128 col                 39    2304        840        519
128 col_inner_read     167    2304        876        600

What contradicts the issue

At [32, 16] — the shape #196 was filed on — the loop order is free. Sixteen operand reads against four in the source, and the three forms agree on every column of both tables: registers, frame, st.local, ld.local. Four slots by four values is small enough that nothing downstream can tell which loop is outer. So the ~1 000 extra ticks a visit in kernel B's ARITH column are not this, and that kernel's arithmetic is still unattributed — worth re-opening on the oxide-train side against the second store_tile, the transposed band's own addressing, or the col_reduce shuffles the pass needs and the row form does not.

At 128 columns the hoist is real: 167 → 39 registers a thread and 600 → 519 static ld.local, on an identical 2304-byte frame. The operand is 32 f32 there, and reading it SLOTS × VALUES times is exactly what the local-load column counts; the frame not moving is what says the band was homed either way and the difference is the reads. The register column alone would not settle it — #63's lesson is that fewer registers on the same frame can be a band being streamed rather than a band that got cheaper — but the local traffic falls with it, which is not what a streamed band looks like.

No clock. The [32, 128] pair is the one worth timing and ladder_bench is the harness shaped for it; the row arm is not the pair to time against at that width, since its operand is an eighth the size.

Blast radius

groupnorm_tile (examples/layernorm.rs, mul_col / add_col) is the only shipped kernel that goes through col_map, and it is unmoved: 48 registers, no frame, no spill, exactly as docs/kernels/layernorm.md records it. Every other row of regcount matches its recorded baseline — flash_forward at 168/1568, mask_probe_128_causal at 664 st.local. The occupancy-step gate passed and the depot census still reads 1 of 12 shipped kernels.

Unrelated, noticed in passing

device-tests/src/main.rs carries a stray #[inline(always)] in the middle of drain_identities' doc block (line 1240 on main), which recent rustc warns on as unused_attributes. Left alone here.

…filed on cannot tell (#196)

`col_map` / `col_map_assign` were documented as the column mirror of the row
maps and were not written as one: the `ColVec` read sat in the inner loop, so
the operand was read `SLOTS × VALUES` times where `row_map_assign` reads its
`RegVec` `SLOTS` times. Swapping the nesting is bit-identical — elementwise,
independent ops, and `RegTile`'s storage is `[[f32; VALUES]; SLOTS]` either way
— so only the order the storage is walked in changes.

`axis_map_probe` is what prices it, and it prices both loop orders in one
build: the pre-#196 walk is open-coded as a third arm beside the library's
column maps and the row axis, over the register pass oxide-train's two flash
backward kernels share. `regcount`, sm_100a, no ptxas spill anywhere:

                      regs   frame   st.local   ld.local
 16 row                 40     128         36         20
 16 col                 40     128         36         20
 16 col_inner_read      40     128         36         20
128 row                168    2048        712        456
128 col                 39    2304        840        519
128 col_inner_read     167    2304        876        600

At the `[32, 16]` chunk the issue was filed on the three forms agree on every
column of both tables: sixteen operand reads against four in the source, and
four slots by four values is small enough that nothing downstream can tell
which loop is outer. The ~1000 ticks a visit #196 measured in the transposed
backward pass are therefore not this, and that kernel's arithmetic column is
still unattributed.

At 128 columns the hoist is worth 128 registers a thread and 81 static
`ld.local` on an identical 2304-byte frame — the operand is 32 `f32` there and
the local-load column is exactly what reading it four times over costs. The
register column alone would not settle it (#63: fewer registers on the same
frame can be a streamed band), but the traffic falls with it.

`groupnorm_tile` is the one shipped kernel that goes through `col_map`, and it
is unmoved: 48 registers, no frame, no spill, as `docs/kernels/layernorm.md`
records it.
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.

col_map_assign reads its operand SLOTS × VALUES times where row_map_assign reads it SLOTS times, and a transposed attention band pays for it

1 participant