Repository navigation
A row statistic reaches shared memory by scatter, and a vector slices to a base address (#130) - #201
Conversation
|
GitHub Actions has not dispatched a run for this branch. No Every gate was therefore run by hand, and each is the command the workflow step runs: Tier 1, locally — Tier 2 — Tier 3 — The three kernel crates were also typechecked locally against the |
… to a base address (#130) `RegVec` — the per-row statistic every attention and normalization kernel computes — had no path to shared memory, so one that had to leave the warp went through `block_reduce`, which folds it to a scalar, or was recomputed. `ldst::store_row_vec` / `load_row_vec` are that path, and they are not the `ColVec` pair transposed: under `BaseLdtm` a column depends only on `lane % 4` so `store_vec` is eight lanes issuing one address, while a row depends on `lane / 4`, so this is `M / 8` elements per lane 8 rows apart, from the one lane of each quad `RowLayout::owns_row` names. The load direction is symmetric — every lane reads, replicas included, because one copy per lane holding the row is what makes a `RegVec` well-formed. `SharedVec::slice::<LEN>(start)` is the other half: a base-address addition, per the type's own doc. `LEN <= N` is a post-monomorphization assert and fires at codegen; where the window starts is a runtime cursor, because a chunked walk's start is a loop variable. `layernorm_rows` was laundering a pointer through a type alias and an `at()` -> `from_raw()` pair to say "the next CHUNK elements", and now says it once. The lane->row scatter is the whole correctness question, so it gets a `device-tests` case: every register carries the `(lane, slot)` it came out of rather than the row it is destined for, so a value derived from `row_of` and stored at `row_of` cannot agree with itself — a permutation lands registers at indices that name where they actually came from. Poison marks a row no owner claimed, and every lane dumps its read-back so the three replicas of each quad must hold what their owner wrote. Host tests cover the same claims at fp32, where the movers are plain pointer accesses. Parts 1 and 2 of #130. Part 3 — in-place shared-memory maps and folds — is the open-ended half the issue says not to bundle.
fee5613 to
c1885fe
Compare
Parts 1 and 2 of #130. Part 3 — in-place shared-memory maps and folds — is the
open-ended half the issue says not to bundle, and is not here.
ldst::store_row_vec/load_row_vecRegVec— the per-row statistic every attention and normalization kernelcomputes — had no path to shared memory at all. A statistic that had to leave
the warp went through
sync::block_reduce, which folds it to a scalar, or wasrecomputed, and a per-row bias could not be read in.
The scatter is the whole of it, and it is not the
ColVecpair transposed.Under
BaseLdtma column depends only onlane % 4, sostore_vecis eightlanes issuing one address and shared memory broadcasting. A row depends on
lane / 4, so this isM / 8elements per lane, 8 rows apart, with no run towiden — and it needs the lane mask the column direction does not: the four lanes
of a quad hold the same row, so only the one
RowLayout::owns_rownameswrites. That predicate has been on the trait since
global::store_row_vecandthis is its second caller.
The load direction is symmetric. Every lane reads, replicas included, because
one copy per lane holding the row is what makes a
RegVecwell-formed, and aquad's four identical addresses come out of one bank read.
SharedVec::slice::<LEN>(start)A base-address addition, per the type's own doc.
LEN <= Nis apost-monomorphization assert and so fires at codegen, not on a device; where the
window starts is a runtime cursor and stays the caller's, exactly as
at'sindex is — a chunked walk's start is a loop variable, and making it a const
parameter would decide the shape of every caller's loop to buy an assertion the
length already carries.
layernorm_rowsis the one caller. It was laundering a pointer through aParameterChunktype alias and anat()->from_raw()pair to say "the nextCHUNKelements"; the alias is gone and the two calls are one.The device case
shared row statistic, beside the twoColVeccases it cannot be a restatementof. The trap it avoids: a value derived from
row_ofand stored atrow_ofagrees with itself whatever the map says. So every register carries the
(lane, slot)it came out of rather than the row it is destined for, and thehost looks for that register where
row_ofclaims it is — a permutation landsregisters at indices that name where they actually came from, and reports it.
A row no owner claimed comes back poisoned rather than as a plausible neighbour,
and every lane dumps its read-back, so the three replicas of each quad must hold
what their owner wrote.
The same two claims are host tests at fp32 in
ldst.rs, where the movers areplain pointer accesses, at
M= 16, 32 and 128.Gates
cargo testscripts/fmt --checkcargo clippy --all-targets -- -D warningsscripts/modal-run buildscripts/modal-run device_testsshared row statistic 32 rows scattered from 8 owning lanes, and read back into all 32scripts/modal-run exampleslayernorm 256x128 rows normalized, worst relative error 3.87e-3scripts/modal-run regcountlayernorm_rowsmoved no register. Run againstorigin/mainand againstthis branch: 40 in
examples/, 48 inexperiments/, both times. (The 40/48crate split is pre-existing and is the composition effect, not this diff.)
Closes #130's parts 1 and 2. Left open: part 3.