Skip to content

A per-column operand in global memory reaches registers without a tile's worth of them (#172) - #173

Merged
feitreim merged 3 commits into
mainfrom
feat/issue-172-load-cols
Aug 3, 2026
Merged

feitreim merged 3 commits into
mainfrom
feat/issue-172-load-cols

Conversation

@feitreim

@feitreim feitreim commented Aug 3, 2026 •

Copy link
Copy Markdown
Owner

Closes #172.

ldst::load_vec reads a ColVec out of a SharedVec; global::load_rows reads a RegTile out of global memory. There was no third call, so a per-column operand that lives in global memory — a norm's weight, a bias — had no way into the registers that multiply by it.

The consumer is the RMSNorm port in feitreim/oxide-train#70. Its weight is [dim] fp32 with dim a runtime number, so it cannot be a SharedVec<E, N> for load_vec to read, and staging a chunk of it per iteration would cost two barriers per chunk in a kernel that otherwise has none. The only spelling available was a stride-zero cursor feeding load_rows, which broadcasts the vector into a full RegTile and holds every value once per row the thread owns — L::SLOTS * L::VALUES registers for L::VALUES distinct numbers.

What changed

global::load_cols, the same walk load_rows does over one row:

pub unsafe fn load_cols<E: Element, const N: usize, L: ColLayout<N>>(
    src: GlobalRows<E>, row: u32, column: u32, lane: u32,
) -> ColVec<N, L>

pairs_are_one_access loses its M and its FragmentLayout bound in the process: the claim it tests is about columns alone, and sharing it is what keeps the vector mover from restating the pairing decision (CONTIGUOUS_VALUES + runs_aligned) a second time and drifting from it.

No store_cols. A kernel that produces a per-column result produces it from col_reduce across a grid and wants an atomic, not a plain store — so it has no consumer, and the rule is to ship what a kernel needs.

Measured

RMSNorm forward and backward, 24576 x 3072 fp32 on a B200, tile port against the shipped block-per-row kernel, sweeping the chunk width (modal run modal_app.py::main --kernel ops --sweep ... in oxide-train):

chunk rows/warp before (load_rows at stride 0) after (load_cols)
32 32 0.831x / 0.778x 0.832x / 0.780x
64 32 0.151x / 0.098x 0.165x / 0.108x
64 16 0.257x / 0.169x 0.280x / 0.187x
192 16 0.111x / 0.064x 0.116x / 0.070x

Two things worth saying plainly, since both are the sort of claim this file exists to keep honest.

Its motivating consumer did not ship, and that is yours to weigh. The RMSNorm port stayed flat — see the numbers below — so load_cols lands with a device case and no kernel in any repo calling it. I am not going to dress that up: what justifies it is that #172's gap was filed off a real kernel's real need, GAPS.md §1.4 and §3.1 named the hole before this PR existed, and the API is the missing third call in a set of three rather than a new idea. If you would rather it wait for a consumer, close it and #172 stays filed with the measurements attached.

It does not rescue the port. The RMSNorm family stays flat in oxide-train — the shipped kernel is at 4.17 TB/s forward and 5.64 TB/s backward and the best tile shape reaches 0.83x/0.91x of it, for a reason load_cols cannot touch: a warp-per-band kernel has 24576 threads where the block-per-row one has 6.3M, and it cannot hold enough loads in flight. The numbers, and the four other families #70 covers, are on oxide-train#70; the one that did win — SwiGLU, from the measure-first tier — is oxide-train#73 and uses none of this.

The cliff past 32 columns is not the parameter tile. Removing it moved chunk 64 from 0.151x to 0.165x and no further, so what collapses there is something else — a .local depot in the register-file arithmetic, which is exactly what regcount's census (#167) was built to see. That is not this PR's, and it is worth its own issue; what this PR claims is the register count, not the cliff.

What load_cols does buy is the spelling: the kernel now says mul_col(load_cols(...)) where it said mul(load_rows(stride_0, ...)), and the operand is VALUES registers instead of SLOTS * VALUES.

Gates

  • Tier 1 local: scripts/fmt --check, clippy --all-targets -- -D warnings, cargo test (75 doctests), RUSTDOCFLAGS=-D warnings cargo doc --no-deps — all clean.
  • Tier 3: scripts/modal-run device_tests on a B200, 43 of 43 cases passed, including the new one:
pass  global rows map     [32, 128] at (16, 40) of a 64x192 matrix, all at BaseLdtm's coordinates
pass  global column map   [128] columns at (16, 40) of a 64x192 matrix, all at BaseLdtm's columns

global column map is a separate case from global rows map rather than a line added to it: a mover that silently read the tile's rows would pass there and cannot pass here. Its column origin (40) is neither a 16-column block boundary nor the row's start, and both it and the pitch are even, so it takes the paired ld.global.v2 arm — the scalar arm is load_rows' own and covered by the case beside it.

GAPS.md 2.2 gains the entry; 1.4 and 3.1 lose the half of their hole this closes and keep the RegVec half, which is still #130's. tests/gaps.rs names it in global_movers_carry_an_element, beside the tile movers it shares a cursor and a pairing test with.

…e's worth of them (#172)

`ldst::load_vec` reads a `ColVec` out of a `SharedVec` and `global::load_rows`
reads a `RegTile` out of global memory; there was no third call, so a parameter
vector whose length is a runtime number — oxide-train's RMSNorm weight, which
cannot be a `SharedVec<E, N>` for that reason — could only reach the registers
that multiply by it through a stride-zero cursor feeding `load_rows`. That
spells `L::VALUES` distinct numbers as `L::SLOTS * L::VALUES` registers, and on
a B200 it is a cliff rather than a rounding error: the RMSNorm port measures
0.83x of the shipped kernel at a 32-column chunk and 0.15x at 64, where the
chunk width is the only knob that buys memory-level parallelism.

`load_cols` is that third call — the same addresses `load_rows` walks, on one
row, into a `ColVec`. The pairing decision is shared rather than restated, which
is why `pairs_are_one_access` loses its `M` and its `FragmentLayout` bound: the
claim it tests is about columns alone, and the vector mover spends it too.

No `store_cols`. A kernel that produces a per-column result produces it from
`col_reduce` across a grid and wants an atomic, not a plain store.

GAPS 2.2 gains the entry, 1.4 and 3.1 lose the half of their hole this closes,
`tests/gaps.rs` names it beside the tile movers, and `global column map` is its
device case — a separate one from `global rows map` because a mover that
silently read the tile's rows would pass there and cannot pass here.
@feitreim feitreim added the gpu-ci Run the B200 device-test tier on this PR (costs GPU minutes) label Aug 3, 2026
@feitreim
feitreim merged commit bf1dac0 into main Aug 3, 2026
4 checks passed
feitreim added a commit that referenced this pull request Aug 3, 2026
…ts per-column statistic (#179)

An attention backward pass is the first kernel to score `K·Qᵀ` rather than
`Q·Kᵀ`, and both halves of what a band needs turned out to exist on one
diagonal only.

`RegTile::make_causal_t_at` is `make_causal_at`'s twin: the block-origin form
of the transposed causal mask, row origin first as in the other. The argument
for the `_at` spelling is stronger here than where it already existed — a CTA
owning a block of keys streams the queries at and after them, so
`key_base - query_base` is negative on every visit but the first, and the `u32`
subtraction a call site would otherwise write wraps to a huge positive number
and masks nothing.

`global::load_col_vec` is `load_row_vec`'s: the same addresses — one element
per band position, down a single global column — delivered as the `ColVec` a
`sub_col_assign` takes instead of the `RegVec` a `sub_row_assign` does. Which
axis a saved statistic broadcasts along is a property of the band, not of the
statistic: the query-parallel backward reads the log-sum-exp per row, and the
key-parallel one needs the same numbers per column.

It is deliberately not `load_cols` (#173), which reads a run *along* one row
and pairs consecutive values into one access. Two movers returning `ColVec`
off the same argument list is a hazard, so the device case is a separate one:
`global column statistic` beside `global column map`, over the same matrix and
origin, where a mover that took the other walk delivers an element that names
itself and the failure prints which walk actually ran.

Gates: `scripts/fmt --check`, `clippy --all-targets -D warnings`, `cargo test`
(110 unit + 80 doctests, including two new host tests — the transposed mask
against the band's global origin, and `load_col_vec` against `load_row_vec`'s
own addresses), `RUSTDOCFLAGS=-D warnings cargo doc`. GAPS.md 2.2 and 3.4 gain
the entries; `tests/gaps.rs` names both.
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.

A per-column operand in global memory has no way into registers: load_cols, the global twin of ldst::load_vec

1 participant