Repository navigation
A row statistic reaches global memory, and the row axis says which lane writes it (#130) - #170
Merged
Merged
Conversation
…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.
This was referenced Aug 3, 2026
Closed
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes the global half of #130 item 2 — the half that a real kernel walked
into.
RegVechad no bridge to memory at all; a per-row statistic could leavethe 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 arestore_rows' addresses restricted to a single column, so the two agree byconstruction; there is no run to widen, since consecutive slots are 8 rows
apart.
RowLayout::owns_row(lane) -> bool— required, no default,lane % 4 == 0for
BaseLdtm.Why
owns_rowrather than letting the replicas writerow_ofis not injective across a warp: a row'sf32lives in every laneholding 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_VALUESis on the column axis — a claim about the mapthat 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
RegVecisdefined 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 strideH. That is exactlystore_row_vec(dest, row, head, lane, lse); without it the kernel open-codesif lane % 4 == 0 { ... }over
BaseLdtm::row, which is the gap restated in a kernel. The oxide-trainbranch pins
kittensto this branch's rev and moves back to ferromainwhenthis merges.
Gates
tests/gaps.rsnames the pair asa_row_statistic_reaches_global_memory,beside
global_movers_carry_an_element.the_owning_lanes_cover_a_bands_rows_exactly_once— the owning lanes nameeach of the band's
Mrows exactly once, at M = 16, 32, 128. This is the rowaxis'
a_bands_threads_cover_its_rectangle_exactly_once.a_row_statistic_round_trips_through_one_column—F32's accesses are plainpointer 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.md2.2 and 1.4 updated; 2.2's "cannot leave the warp" paragraph nowreads 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 testall clean locally.No device case: the map is pure arithmetic over
row_of, and both host testsabove 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 sharedmemory). None of them were on the path of the kernel that prompted this.