Repository navigation
SwizzledChunks spans stacked subtiles - #35
Merged
Merged
Conversation
A tile is one flat stack of 128-byte swizzled rows: stacked subtile i starts SUBTILE_BYTES = rows * 128 bytes along, and SWIZZLE_128B XORs *physical* address bits [9:7] into the chunk index, so subtile i's row r is the tile's 128-byte row i * rows + r and takes that row's phase. The cursor splits a logical chunk index into subtile and chunk and adds the two row terms; the phase follows the absolute row, so nothing is assumed about rows against the 8-row swizzle period. That deletes chunk_writer's one-subtile const-assert, which was the only reason 64 bf16 columns was the sole width with a register/shared path at all. Chunk indices already counted across the whole logical row, so ldst::fragment_address needed no change: a column past the first subtile lands in chunk 8.. and resolves itself. The single-subtile case is byte-for-byte the old formula, subtile = 0.
The three round trips become shape-generic probes, so the wide cases are the same bodies rather than copies that can drift, and the narrow ones keep running beside them: the narrow path is what the hardware has always agreed with, and the subtile term must leave it alone. New cases: - swizzle / stmatrix / ldmatrix ... wide: a 64 by 128 tile, two stacked subtiles, so every block at columns 64.. crosses the subtile stride. - swizzle phase carry: a 4 by 128 tile. Four rows is not a whole swizzle period, so its second subtile begins mid-period. That is the only shape where an absolute swizzle phase and a per-subtile one differ; at R = 64 or 128 the two readings coincide. cell_bits gives columns seven bits so a position identity can name a 128-column tile; the exponent field stays in 0x80..0xbf, still normal.
#25 gives the 128 by 128 tile a register/shared path in both directions and #5 landed the ops, so the load GAP becomes a real load_fragment loop and the store side gets its mirror. What is left is #6 -- row_max and row_sum -- and #9, the TMA store, plus #22 as a cost rather than a hole: the band loop is written twice because the movers are per-block. README: item 3 closed, with the addressing that replaced it; status table and blocked-on lists updated.
This was referenced Jul 27, 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.
SwizzledChunksnow walks stacked subtiles, so every width the library candescribe has a register ↔ shared path — not just the 64 bf16 columns of a
single swizzle atom.
The addressing
I agree with the derivation in the brief, and it falls out of a slightly
stronger statement that makes its open question disappear.
A tile is one flat stack of 128-byte rows. Subtile
istartsSUBTILE_BYTES = rows * 128bytes along (exactly whattma_load's destinationarithmetic does), and SWIZZLE_128B XORs physical address bits
[9:7]intothe 16-byte-chunk index. The base is 128-byte aligned, so the 128-byte row index
of subtile
irowris(base >> 7) + i * rows + r, giving:Written that way there is no separate "subtile term" and no separate "phase
term": a subtile is more rows, and the phase is the row's own position in the
period. The cursor carries
rows(=R) and the logical chunk count alongsidebase/phase.What the phase depends on. The brief's form —
base + subtile * SUBTILE_BYTES + row * 128 + (chunk ^ ((row + phase) & 7)) * 16— is the above with the
subtile * rowscontribution to the phase dropped. Thetwo agree exactly when
rows % 8 == 0, i.e. when a subtile is a whole number ofswizzle periods, which holds at
R = 64andR = 128and at every live callsite. So the brief's formula is right where it is used, and its worry was the
right worry. Rather than add a
const assert!(R % 8 == 0)I folded the subtileinto the row: it costs nothing (a
subtile * rowsadd replaces asubtile * SUBTILE_BYTESadd) and makes the precondition unnecessary — theodd-
Rcase is correct rather than forbidden, and the harness checks it.ldst::fragment_addressneeded no change: its chunk index iscolumn / 8,already counted across the whole logical row, so a column in the second subtile
produces chunk
8..and resolves itself. That is also whystore_fragmentandload_fragmentare untouched apart from doc comments.Narrow path
chunk / 8 == 0andchunk % 8 == chunkwhenchunk < 8, so the single-subtilecase is byte-for-byte today's expression.
regcountbefore/after,sm_100a:swizzle_roundtripstmatrix_roundtripldmatrix_mapZero spills either way, and every other kernel in the table is unchanged. The
new wide kernels sit at 32 registers, the 4-row one at 32.
What the device test proves
device-testshad one[64, 64]tile precisely because that was the only widthchunk_writeraccepted. The three round trips are now shape-generic probes runat both widths from the same body, and the narrow cases stay in the suite so a
regression there is distinguishable from a wrong subtile term.
swizzle round trip wide— TMA a[64, 128]identity tile in, read itback through the cursor in logical order. The TMA engine placed the bytes and
the cursor found them again across the subtile stride: this is the case a
wrong stride fails, and it fails loudly rather than plausibly.
ldmatrix map wide/stmatrix round trip wide— the narrow pair'sdiscipline over all 4x8 blocks: the kernel dumps by
(block, lane, slot, value)and the host appliesFragment::coordinate.Neither kernel encodes the expected answer.
swizzle phase carry— the case worth having. A[4, 128]tile: fourrows is not a whole swizzle period, so its second subtile begins at phase 4.
This is the only shape where "phase follows the absolute row" and "phase
restarts per subtile" disagree — at
R = 64or128they coincide, so thewide cases above cannot separate them. It passes, which is silicon confirming
the absolute-address reading; under the per-subtile one every row's columns
64.. would come back permuted.
Host side:
atis pure const-style math, so it is tested thoroughly — theper-subtile formula at
R = 64, the mid-period phase atR = 4, andinjectivity over
[128,128],[64,256]and[4,128]at all eight base phases.The injectivity test says in its own comment what it cannot see: any phase
permutes a row's eight chunks, so only the stride is at stake there.
Examples
softmaxno longer has aGAPfence: it loads its[128, 128]tile withload_fragmentand stores it back withstore_fragment, both through the realcursor. It stays aspirational, and precisely what is still missing is:
RegTile::row_max/row_sum. Two of the algorithm's four lines.tma_store/tma_store_commit/tma_store_wait, so the resultcan leave.
(#5 landed, so
sub_row/exp2/div_roware real calls now.) #22 is no longera blocker for it, only a cost: the
[16, 16]band loop is written twice, onceper direction, which is the best argument for
load_tile/store_tileyet.layernormdrops #25 from its list for the same reason and keeps #22.examples/README.md: item 3 of "Not covered by any open issue" is struckthrough with the addressing that replaced it, item 1's tail and item 2 are
updated, and the status table reads
#6, #9for softmax.Verified
modal run modal_app.py::build— green, and again after the rebase onto MMA walks build their own instruction descriptor #34.This is the check that matters most here: a removed
const { assert!(..) }is a post-monomorphization thing.modal run modal_app.py::regcount— the table above, against a stashedorigin/mainbuild.modal run modal_app.py(B200) — once, the run quoted above.cargo clippy --all-targets,cargo fmt --check,cargo test— clean.Surprises
rows, notSUBTILE_BYTES. Folding it into the rowindex is what turns the phase question into a non-question; carrying bytes
would have forced the
R % 8 == 0assert the brief anticipated.fragment_addresswas already width-correct. The whole restriction lived inone
const assert!, and chunk indices >= 8 had never appeared only becausethat assert made such a tile unconstructible.
which is why the
[4, 128]tile is in there. TMA is happy with a 4-row boxunder a 128B swizzle.
Closes #25