Repository navigation
Description
Found by the 2026-07-29 library audit (GAPS.md §1.4, §2.2, §3.1). The vector
shapes are the least finished corner of the crate, and the holes are specific.
1. RegVec has no bridge to memory at all
ColVec — a per-column statistic — can be read from and written to shared
memory (ldst::load_vec, ldst::store_vec, #13/#53). RegVec — a per-row
statistic, and the one every attention and normalization kernel actually
computes — has neither, and no global path either. grep -n RegVec src/ldst.rs src/global.rs src/shared.rs returns nothing.
The asymmetry is not arbitrary and the fix is not symmetric: under BaseLdtm a
ColVec's entries depend only on lane % 4, so eight lanes issue one address
and shared memory broadcasts. A RegVec's slots are spread across lane / 4,
so staging one is a scatter of M / 8 elements per lane with the row index
coming from RowLayout::row_of — real work, not the same function transposed.
What it costs today: a per-row statistic that has to leave the warp goes through
sync::block_reduce (which folds it to a scalar) or is recomputed. There is no
way to write one out, and no way to read a per-row bias in.
2. SharedVec has no slice
ldst::load_vec takes a whole SharedVec<E, N>, so a chunked walk over a
parameter vector has to launder a pointer:
// examples/src/layernorm.rs:290-292
let g: Columns = load_vec(ParameterChunk::from_raw(gamma.at(column as usize)), lane);
let b: Columns = load_vec(ParameterChunk::from_raw(beta.at(column as usize)), lane);ParameterChunk (layernorm.rs:177) is a type alias that exists only for this,
and at() → from_raw() is two unsafe calls to express "the next CHUNK
elements". A SharedVec::slice::<CHUNK>(start) is a base-address addition — the
type's own doc already says "a vector is flat and unswizzled, so a slice of it
is a base address and nothing else".
3. Neither vector nor tile can be mapped or folded in shared memory
Unchanged from #13, restated here because it is the same corner: nothing in
shared.rs maps or reduces in place, so data comes back to registers before
anything is done to it. #13 closed on the type and nothing tracks the ops.
GAPS.md §3.1 and §3.2 both name it and neither has an issue — this is that
issue for the vector half.
Scope, in the order the evidence supports
SharedVec::slice::<LEN>(start)— ~15 lines, one existing caller, removes an
unsafefrom a call site.ldst::load_row_vec/store_row_vecforRegVec— ~60 lines. Needs a
device case: the lane→row scatter is the whole correctness question, exactly
ascol_of's lane groups were for the reductions.- Shared-memory maps and folds — larger, and worth its own scoping. The
argument for it is that a statistic staged for another warp is currently a
round trip through registers on both sides.
Estimate
1 and 2 together are ~80 lines plus one device-tests case. 3 is open-ended and
should not be bundled.
Related: #13 (closed on the type, left the ops), #14 (the swizzle question a
shared-tile op surface would have to answer for staging tiles).
Activity
feitreim commentedon Jul 29, 2026
Upgrade note (
20a5616): several new upstream pieces are relevant to the safe chunk/vector side of this issue:exact_divsupport enablesslice::as_chunks;DeviceBuffer::cast_chunksprovides length-adjusting host-side reinterpretation;They do not replace
SharedVec::sliceor the BaseLdtm row-vector scatter, but they can remove raw chunking/reinterpretation around global buffers and provide one upstream source for access-width legality. Include them when scoping part 1 rather than solving only the shared pointer addition.feitreim commentedon Aug 3, 2026
Item 2's global half is #170, taken because a kernel walked into it rather than because the audit listed it.
feitreim/oxide-train#68 rewrites the flash-attention forward as one kernel on the current surface. 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 aRegVecreaching global memory and nothing else; open-coded it isif lane % 4 == 0 { ... }overBaseLdtm::row, which is this issue restated inside a kernel.What the implementation sharpened, and what the issue text does not say: the scatter is not the hard part. The lane→row spread is four lines. The part that needed a decision is that
row_ofis not injective across a warp — a row'sf32lives in every lane that holds any of that row's columns — so a store has no single writer unless the layout says which lane owns a row. #170 addsRowLayout::owns_row, required and with no default, as the row axis' counterpart toColLayout::CONTIGUOUS_VALUES: a claim about the map that only the map can make. The load direction has the opposite rule and needs no predicate, since the replicas are what make the vector well-formed.So the estimate in "Scope" holds for the code and understates the surface: it is ~90 lines plus one trait method, and the trait method is the whole correctness question — not the device case the issue expected. The map is pure arithmetic over
row_of, so it is checked host-side (the_owning_lanes_cover_a_bands_rows_exactly_once, and a full round trip throughF32's plain pointer accesses).Items 1 and 3, and the shared-memory half of item 2, are untouched — none of them were on that kernel's path.
A row statistic reaches global memory, and the row axis says which la…
A row statistic reaches shared memory by scatter, and a vector slices…
A row statistic reaches shared memory by scatter, and a vector slices…