Skip to content

A row statistic reaches global memory, and the row axis says which lane writes it (#130) - #170

Merged
feitreim merged 1 commit into
mainfrom
feat/issue-130-row-vec-memory
Aug 3, 2026
Merged

feitreim merged 1 commit into
mainfrom
feat/issue-130-row-vec-memory

Conversation

@feitreim

@feitreim feitreim commented Aug 3, 2026

Copy link
Copy Markdown
Owner

Closes the global half of #130 item 2 — the half that a real kernel walked
into. RegVec had no bridge to memory at all; a per-row statistic could leave
the warp only by being folded to a scalar through sync::block_reduce.

What lands

  • global::store_row_vec / global::load_row_vec — one element per row of an
    [M, _] band, all in one column of a row-major buffer. The addresses are
    store_rows' addresses restricted to a single column, so the two agree by
    construction; there is no run to widen, since consecutive slots are 8 rows
    apart.
  • RowLayout::owns_row(lane) -> bool — required, no default, lane % 4 == 0
    for BaseLdtm.

Why owns_row rather than letting the replicas write

row_of is not injective across a warp: a row's f32 lives in every lane
holding any of that row's columns. Four threads storing the same value to the
same address is idempotent and still not a single writer, and it is four times
the store traffic. This is the row axis' version of what
ColLayout::CONTIGUOUS_VALUES is on the column axis — a claim about the map
that only the map can make — so it goes in the trait rather than being derived
at the call site or assumed by the mover.

The load direction has the opposite rule and no predicate: a RegVec is
defined as one copy per lane holding the row, so the reads that look redundant
are what makes the vector well-formed. They are the same address across a quad
and coalesce.

Where the pressure came from

feitreim/oxide-train#68, the unified flash-attention forward. Its epilogue writes
fp32 logsumexp[B*T, H] — one f32 per query row, in the head's own column of a
[rows, heads] buffer, at stride H. That is exactly store_row_vec(dest, row, head, lane, lse); without it the kernel open-codes if lane % 4 == 0 { ... }
over BaseLdtm::row, which is the gap restated in a kernel. The oxide-train
branch pins kittens to this branch's rev and moves back to ferro main when
this merges.

Gates

  • tests/gaps.rs names the pair as a_row_statistic_reaches_global_memory,
    beside global_movers_carry_an_element.
  • the_owning_lanes_cover_a_bands_rows_exactly_once — the owning lanes name
    each of the band's M rows exactly once, at M = 16, 32, 128. This is the row
    axis' a_bands_threads_cover_its_rectangle_exactly_once.
  • a_row_statistic_round_trips_through_one_column — F32's accesses are plain
    pointer reads and writes, so the movers themselves run on the host: store into
    one column of a three-head buffer, assert every other element is untouched,
    read back into all four replicas.
  • GAPS.md 2.2 and 1.4 updated; 2.2's "cannot leave the warp" paragraph now
    reads only for the shared-memory half, which is what is still open on RegVec cannot reach memory, SharedVec cannot be sliced, and neither can be folded in place #130.
  • scripts/fmt --check, cargo clippy --all-targets -- -D warnings,
    cargo test all clean locally.

No device case: the map is pure arithmetic over row_of, and both host tests
above check it directly. If tier 3 should carry one anyway, say so and I will
add it to device-tests.

What is still open on #130

Item 1 (SharedVec::slice), the shared-memory half of item 2
(ldst::load_row_vec/store_row_vec), and item 3 (maps and folds in shared
memory). None of them were on the path of the kernel that prompted this.

…ne writes it

`global::store_row_vec` / `load_row_vec`: one element per row of a band, all in
one column of a row-major buffer. Attention's log-sum-exp is a column of
`[rows, heads]` and is the shape that motivated it — the statistic every
flash-attention epilogue computes and, until now, the one thing it could not
hand back.

`RowLayout::owns_row` is the part that could not be derived. `row_of` is not
injective across a warp: a row's `f32` lives in every lane that holds any of
that row's columns, so a store without an owner is four threads writing the same
value to the same address. It is the row axis' answer to what
`ColLayout::CONTIGUOUS_VALUES` is on the column axis — a claim only the map can
make — and `the_owning_lanes_cover_a_bands_rows_exactly_once` checks it as
stated. The load has no such rule and every replica issues, which is what makes
the vector well-formed on the way in.

`F32`'s accesses are plain pointer reads and writes, so the movers themselves
run on the host: `a_row_statistic_round_trips_through_one_column` stores into
one column of a three-head buffer, checks every other element is untouched, and
reads it back into all four replicas.

GAPS.md 2.2 and 1.4 move from "`RegVec` has no bridge to memory at all" to the
shared half only; `tests/gaps.rs` names the pair.

Refs #130.
@feitreim
feitreim merged commit 37ea9e7 into main Aug 3, 2026
3 checks passed
feitreim added a commit to feitreim/oxide-train that referenced this pull request Aug 3, 2026
The three generations of issue #35 — `flash_forward_tcgen05`,
`flash_forward_pipelined`, `flash_forward_persistent` — collapse into
`flash_forward`. What made them three was a 64-query tile against an `M128`
accumulator: every MMA filled 64 real rows and 64 phantom ones, half the tensor
core thrown away, and phases 2 and 3 bought it back with structure — a
dedicated TMA warp and MMA warp, then two softmax warpgroups ping-ponging
adjacent query tiles over one ring.

A CTA now owns 128 query rows. The MMA is whole, the softmax warpgroup is
naturally the accumulator's own four warps, and the overlap that took three
warp roles is one double-buffered score segment: the leader issues `S(i+1)`
before the warpgroup runs the softmax of tile `i`, so the tensor core is
running `S(i+1)` and `O(i-1)` throughout it. 128 threads where the persistent
kernel had 192, and no phantom-read pad in any plan in the module any more.

The rest is the library's, which is the other half of #68. `SharedPlan` carves
the plan instead of a column of `smem.add(n * TILE_BYTES)`. `pipeline::run` is
the persistent work-item loop. `make_causal_at` takes the two block origins, so
the hand-written per-value diagonal branch — a hundred lines of `if col <= row`
across two passes — is one call, and it is right for both diagonal tiles rather
than only the first. `online_rescale` is the flash rescale. `block_reduce` is
the correction vote three kernels open-coded as a votes array plus a barrier
phase. `tcgen05.ld.x8` drains a band 64 columns at a time where the old drain
took 16. `store_row_vec` writes the LSE, which is what ferro #130 was about.

FA4's conditional correction survives unchanged in substance: the output
segment accumulates under a fixed per-row reference until some row's tile max
climbs past `CORRECTION_THRESHOLD`, and only then is it drained and restarted.

The backward kernels are untouched (#69) and now share the forward's
`PairedPanel`/`PairedPTile`/`STmem`/`AccTmem` rather than parallel definitions.

The bench's FLOP count changes from *issued* MMA work to algorithmic: issued
was twice algorithmic only because of the phantom half, and the two have
converged. Compare the milliseconds against the recorded figures, not the
TFLOP/s.

`kittens` is pinned to feitreim/ferro-kittens#170's tested rev for
`global::store_row_vec`; the pin moves back to ferro main when that merges.
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.

1 participant