Repository navigation
A shared tile out to global memory, by plain vectorized stores (#15) - #113
Merged
Merged
Conversation
The epilogue's shared->global half without the TMA engine, which is what NVIDIA's own `gemm_sol_final` does at cuda-oxide b099f64: `stmatrix` into a staging tile, then read it back and issue wide contiguous global stores. `store_shared_rows` copies a `[R, C]` `SharedTile` to a rectangle of a row-major buffer at a runtime leading dimension. The 16-byte swizzle chunk is the unit both sides agree on -- SWIZZLE_128B permutes chunks within a 128-byte row and never the bytes inside one, and 16 bytes is also the widest store PTX has -- so the global side is walked contiguously and the tile's own cursor is asked where each chunk went. The width ladder reuses `GlobalRows::runs_aligned`, descending 16, 8, 4 bytes to the element. Cooperative, not collective: `THREADS` threads split the chunks by a flat index, with no barrier, no fence and no wait inside. There is deliberately no `fence.proxy.async.shared::cta` -- both ends are generic-proxy, so a `bar.sync` between the `stmatrix` writes and these reads is the whole obligation, and it belongs to the caller. Device case `shared drain` / `shared drain wide`: four warps fill a staging tile with position identities, drain it to a rectangle inset in a 80x208 bf16 matrix seeded with poison, and the host checks every element including the margins that had to stay poison. Four column origins run the four rungs of the ladder off one kernel.
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.
The epilogue's shared→global half without the TMA engine — the route
NVIDIA's own
gemm_sol_finaltakes at cuda-oxideb099f64(
crates/rustc-codegen-cuda/examples/gemm_sol_final/src/kernels.rs, hashconfirmed against the checkout, not assumed from the directory name):
stmatrixinto a staging tile, read it back, and issue wide contiguous globalstores. #109 measured our register-side epilogue as issue-bound; this is the
primitive the kernel that answers that will be built on.
kittens::global::store_shared_rowscopies a[R, C]SharedTileto arectangle of a row-major buffer at a runtime leading dimension.
The swizzle: option (a), and why
The global side is walked contiguously and the tile's own cursor is asked
where each chunk went (
SwizzledChunks::at). Three reasons, in order of howmuch they decided it:
permutes 16-byte chunks and never the bytes inside one, and 16 bytes is also
the widest store PTX has (
st.global.v4.b32). So the chunk is simultaneouslythe largest run contiguous in both address spaces and the largest one an
instruction could have carried anyway. The swizzle cannot cost the global
side anything, because there was nothing above 16 bytes to lose.
within one 128-byte row, and a 128-byte row is exactly the 32 banks once
over — eight lanes reading the eight chunks of a row touch every bank exactly
once, permuted or not.
SharedVec's docs already file anunswizzled tile under Swizzle modes: 32B, 64B, and unswizzled #14 and name its precondition (
ATOM_BYTEShas to stopmeaning "TMA box width" first). It would also move the disorder onto the
stmatrixthat fills the tile, where a power-of-two row pitch is theconflict the swizzle exists to prevent.
(1) and (2) are arguments about addresses. Neither is measured, and the doc
block says so in those words.
Access width
Reuses
GlobalRows::runs_alignedrather than inventing a second test.access_widthdescends 16, 8, 4 bytes to the element and takes the first thecursor admits, so an odd
ldcgets narrower stores instead of amisaligned-address fault. It is a pure public function so a host test reads
the ladder off directly instead of inferring it from which branch ran. The
2-byte rung is guarded on
E::BYTES == 2— a cursor aligned for a 4-byteelement is aligned for a 4-byte access at every column, so at fp32 that arm is
const-dead and not emitted.
Scope: cooperative, not collective
THREADSthreads split the chunks by a flat index; no barrier, no fence, nowait inside.
(lane, 32)is warp scope,(threadIdx.x, 128)is the fourepilogue warps — the reference's arrangement, and the one that puts a warp's 32
accesses on consecutive chunks of a row. Split by chunk and not by row because a
row split needs
Rto divide by the warps and the warp's rows by 32.There is deliberately no
fence.proxy.async.shared::cta, and the doc blocksays why at length, because its absence is exactly the thing a reader assumes is
a bug: both ends are generic-proxy, so a
bar.syncbetween thestmatrixwrites and these reads is the whole obligation, and it belongs to the caller,
who is the only one who knows whether the writes were another warp's.
Device test
shared drain/shared drain wide: four warps fill a[64, C]staging tilewith position identities through
store_tile, onesync_threads, then drain toa rectangle at row 8 of an 80×208 bf16 matrix seeded end to end with poison.
The host checks every element of the matrix — including the margins above,
below, left and right that had to stay poison. The pitch is wider than either
tile and not a multiple of one, so a wrong stride is a wrong answer.
columnis a kernel argument, so the fourDRAIN_COLUMNS[64, 68, 66, 65]run the four rungs of the ladder off one kernel.
38 of 38 device cases pass on a B200 (
scripts/modal-run device_tests);tier 2
buildis green on both kernel crates.What this does not establish
and coalescing arguments above are about addresses only.
2-byte stores passes all four columns. Only
access_width's host tests saywhich width a cursor gets, and they say it against a synthetic base address —
the device rungs follow from the driver's ≥256-byte allocation alignment,
which is stated but not asserted.
[64, 64]and[64, 128]bf16 at 128 threads, onedestination origin, one pitch. No fp32
SharedTileis exercised anywhere (thecrate has none), so the
E::BYTES == 4path is host-tested only.check_store_ring,a case is built so a violation is a wrong value rather than a plausible one;
it is not built to force one.