Repository navigation
Global to and from registers, with no descriptor in the way (#11) - #59
Merged
Merged
Conversation
`global::GlobalRows` is a base address and a leading dimension — the whole of what a thread needs to address a row-major buffer itself — and `load_rows`/`store_rows` move an `[M, N]` register tile through it at the coordinates the fragment layout already knows. This is ThunderKittens' `global_to_register.cuh`: the path for an fp32 epilogue, which had to round-trip through a bf16 shared tile to reach global memory, and for a small operand not worth a host-built descriptor. It lives in `global.rs` rather than `ldst.rs` because `ldst` is one address derivation over `ldmatrix`/`stmatrix` and this shares none of it — and because `flash_forward` imports `ldst::store_tile` in the same file that wants this one. It is fp32 rather than generic over `Element`, which is bf16-only until #2, and it is the only mover in the crate generic over `FragmentLayout`: every other one has a lane map fixed in hardware, and a plain `st.global` fixes nothing. gemm's epilogue was the twelve lines of open-coded `RegTile::coordinate` arithmetic this library exists to delete; it is now one call, and the file has no `GAP` block left. flash's error list goes from two to one (#31). Measured, both directions, against the loop they replace (`regcount`'s new `global_copy_probe_*`): 48 registers against 56 at 32 columns, 44 against 168 at 128, no spill anywhere. Cheaper rather than free, and #22 found the same direction — the movers form the row address once per slot where a call site multiplies out per value. Checked: `global rows map` (device) reads a band out of a pitched fp32 matrix at an off-block origin and dumps by thread coordinate, the host applying the ownership map — the only case here whose source never touches the TMA engine. The store direction is `gemm`, whose 512x256 output is compared elementwise for equality, and it still passes. Four host tests for the address map itself.
feitreim
force-pushed
the
global-register-movers
branch
from
July 28, 2026 02:26
e115add to
afcf606
Compare
feitreim
added a commit
that referenced
this pull request
Jul 28, 2026
…hide (#61) The seed's row term is `37 * row` taken mod 128, so it repeats every 128 rows — one CTA band. A kernel that loaded one band and stored to another produced bit-identical expected values and the check passed it. No choice of row multiplier fixes that, and the reason is structural: the seed is an affine map of the column axis, those form a group of order 2^13 under composition, and its exponent is exactly 128. Every row-affine seed therefore repeats inside a band. `37 -> 39` changes nothing; a stride that follows the row, `(11 + 2*row)`, still repeats every 128 rows and costs the row axis its rotation-only errors as well. What the 2-group cannot supply is an odd period, so the band supplies one: `row / ROWS % 63` picks the column stride. Two rows agree only if they agree mod 128 and mod 63 bands, so a row displacement is invisible exactly when it is a multiple of 8064 rows — and 63 divides no power of two, which is what every band offset and every size here is. Positive control on a B200, load row pinned to band 0 while the store row still follows blockIdx.x: the new seed reports 32,256 of 65,536 cells wrong, the old one 0. Also unbreaks `modal run modal_app.py::build`, which has been failing on main since #59 on a redundant explicit doc link in `global.rs`.
This was referenced Jul 28, 2026
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.
kittens::global::GlobalRowsis a base address and a leading dimension — thewhole of what a thread needs to address a row-major buffer itself — and
load_rows/store_rowsmove an[M, N]register tile through it at thecoordinates the fragment layout already knows. ThunderKittens'
global_to_register.cuh, for the fp32 epilogue that had to round-trip througha bf16 shared tile to reach global memory, and for the small operand not worth
a host-built descriptor.
Three decisions, not transcription
global.rs, notldst.rs.ldstis one address derivation(
fragment_address) shared byldmatrixandstmatrix; this shares none ofit, and its question — how a global buffer is described — is
global.rs's.It also cannot be called
store_tile:flash_forwardimportsldst::store_tilein the very file that wants this one.Element. The parameter belongs there and cannotgo there yet —
ElementisBf16-only until Element carries MMA kind and conversion, ready for sub-bf16 types #2, soGlobalRows<E>wouldhave exactly one instantiation and it would be the wrong one. A
RegTileis fp32 and this path exists to move it without rounding. Element carries MMA kind and conversion, ready for sub-bf16 types #2 makes it a
bound and two
E::read/E::writecalls.FragmentLayout.ldmatrix,stmatrixandLDTM each fix a lane map in hardware; a plain
st.globalfixes nothing, sothese two take any
L.No bounds checking, deliberately: predicating every value would be paid by the
epilogues that do divide. TK's ragged-tail loads still want it, and that plus
the vector shapes is what GAPS §2.2 now says is left.
Examples
gemm's epilogue was the twelve lines of open-codedRegTile::coordinatearithmetic this library exists to delete. It is one call now and the file has
no
GAPblock left.flash_forward's import resolves, taking its errorlist from two to one (
RegTile::add_assign, #31) — confirmed by::gaps,not by reading the file.
Registers, both widths
regcount's newglobal_copy_probe_*price both movers against the loop theyreplace, at equal work:
RegTile::coordinateper valueload_rows+store_rowsCheaper rather than free, which is #22's direction again: the movers form the
row address once per slot where a call site multiplies out per value, so a
[32, 128]band costs 4 multiplies by the leading dimension instead of 128.No spill at either width, and every pre-existing kernel in the table is
unchanged.
Checks run
::buildsm_100adevice builds of both kernel crates, all three crates clean::gapsadd_assign(#31); layernorm unchanged::regcountglobal rows map::examples(B200)gemm 512x256x256 exact,softmaxunchangedcargo fmt --checkdevice-tests/,examples/The new device case covers the load only: it reads a
[32, 128]band outof a 64x192 fp32 matrix at
(16, 40)— off the buffer's corner, off a16-column block boundary, at a pitch that is not the band's width — and dumps
by
(lane, slot, value)with the host applying the ownership map. It is theonly case in the harness whose source reaches registers with no descriptor
between them. The store direction gets no case, because
gemm's epiloguealready is one:
store_rowsat a runtimeldcwider than the band, non-zerocolumn origin, four warps, and all 512x256 outputs compared for equality.
Four host tests for the address map itself, including the one property the
store rests on — a warp's threads name every element of the destination
rectangle exactly once.
Closes #11