Skip to content

Shared to register load: ldst::load_fragment - #33

Merged
feitreim merged 4 commits into
mainfrom
issue-21-load-fragment
Jul 27, 2026
Merged

feitreim merged 4 commits into
mainfrom
issue-21-load-fragment

Conversation

@feitreim

Copy link
Copy Markdown
Owner

The ldmatrix half of ldst. ldst was store-only, so the only ways into
registers were an MMA accumulator drain or arithmetic on registers already
held — any kernel whose input is not an MMA operand could not start.

What landed

ldst::fragment_address — store_fragment's chunk/row derivation, lifted
out into a const fn both directions call. ldmatrix and stmatrix share an
address convention (16 addresses from lanes 0..15, data spread over all 32), so
the two directions are one derivation with the data flowing opposite ways and
cannot drift. Being a free function it is host-testable for the first time: four
tests pin it against BaseLdtm's own map — that the 16 addressing lanes name
exactly the slot's 8 rows in each of the .x2's two matrices, that an address
lane's row is the row its quad's data lanes own, that the second chunk holds
the columns BaseLdtm gives values {2, 3}, and that no lane (including 16..31,
whose addresses the instruction ignores but still forms) leaves the block.

ldst::load_fragment — mirrors store_fragment's signature and its
Element<Unpacked = [f32; 2]> bound, for the same reason: ldmatrix.m8n8.x2
moves two b16 matrices, and a 4-per-word element should fail to typecheck rather
than read half the bytes it asked for. [16, 16] only; composing larger shapes
is #22.

Element::unpack — the inverse of pack, implemented for Bf16.

Device case ldmatrix map, and doc updates to examples/ and GAPS.md.

Which ldmatrix path, and why

cuda_device::wmma::ldmatrix_x2 directly — no ptx_asm! needed. It builds
for sm_100a under a real cargo oxide build, and the kernel runs correctly on
a B200. The plan flagged that it might hit the same wall stmatrix did (which
drops to ptx_asm! to dodge an unresolved LLVM declaration); it does not. That
ldmatrix is filed under a wmma module is an accident of upstream module
layout — it is a plain shared-memory read with nothing to do with the wmma MMA
path this crate does not use. stmatrix_m8n8_x2's doc now records the asymmetry
so nobody re-derives it.

What the device test proves, and does not

ldmatrix map TMAs a [TILE, TILE] tile of position identities into shared,
reads every [16, 16] block of it through load_fragment, and dumps by
(block, lane, slot, value); the host applies Fragment::coordinate.

It proves ldmatrix's ownership map is BaseLdtm and load_fragment's
addressing is the one the hardware uses. The tile's contents are placed by the
TMA engine, which the existing swizzle round trip case checks independently,
and the values are identities the register path never computes — so this is not
a round trip, and a load and a store agreeing on the same wrong map would not
pass it. It shares nothing with stmatrix round trip except the
fragment_address derivation, so the two directions are pinned to silicon
separately.

It does not cover the .trans form, elements other than bf16, tiles wider
than one swizzle subtile, or composition above [16, 16].

Softmax: not promoted, and why

softmax stays aspirational, but its GAP fence for the missing load is
gone — it calls load_fragment for real now, in the block-composition loop #22
is filed to delete. What still blocks it:

examples/README.md's "Not covered by any open issue" item 1 is struck through
and says what replaced it; items 2 and 3 pick up what is left, which is shape
rather than direction. The status table and layernorm's header (which claimed
load_tile/store_tile had no issue behind them) are updated to #22/#25.
GAPS.md gains §2.1a and its cuda-oxide support table stops calling ldmatrix
Hopper-only.

Different from the plan

  • Bf16::unpack is host-testable. The plan expected it to mirror pack's
    unreachable!() host body. It does not: cuda-device exposes cvt_* in the
    narrowing direction only, because widening bf16→fp32 is a shift and needs no
    instruction. So unpack is ordinary bit math and has a real host test.
  • modal_app.py has no regcount function on main, so that check could
    not be run. store_fragment's emitted code is unchanged by construction — the
    extracted helper is a const fn returning the same two values the inline
    expressions did.

Verified

  • modal run modal_app.py::build — clippy (lib + harness), host tests (26, all
    pass), real cargo oxide build --arch sm_100a for device-tests and the
    examples crate. Clean.
  • modal run modal_app.py on a B200, once: 8 of 8 cases pass, including the
    new ldmatrix map ("4096 elements, all at BaseLdtm's coordinates").
  • cargo clippy --all-targets and cargo fmt --check clean.

Closes #21

feitreim added 4 commits July 27, 2026 17:54
bf16 -> fp32 is a shift, not an instruction: cuda-device exposes cvt_*
in the narrowing direction only, and there is nothing here for one to
do. So unlike pack, unpack is ordinary bit math and holds on the host,
which is what the test asserts.
Extracts store_fragment's chunk/row derivation into fragment_address,
which both directions now call. ldmatrix and stmatrix share an address
convention -- 16 addresses from lanes 0..15, data over all 32 -- so the
two directions are one derivation with the data flowing opposite ways,
and cannot drift. Being a free function it is also host-testable for the
first time; four tests pin it against BaseLdtm's own map.

cuda_device::wmma::ldmatrix_x2 lowers cleanly for sm_100a, so the load
needs no ptx_asm! counterpart to stmatrix_m8n8_x2's. That it is filed
under wmma is an accident of module layout.
TMA a [TILE, TILE] tile of position identities into shared, load every
[16, 16] block of it through load_fragment, dump by thread coordinate,
let the host apply Fragment::coordinate.

The tile's contents are placed by the TMA engine -- checked independently
by the swizzle round trip case -- and the values are identities the
register path never computes, so this pins ldmatrix's ownership map to
BaseLdtm against silicon rather than showing load and store are mutual
inverses. It shares nothing with the stmatrix case but fragment_address.
…ks it

softmax's invented load_tile becomes load_fragment in the block loop that
#22 is filed to delete. It is still aspirational: chunk_writer const-asserts
a one-subtile tile (#25), so a 128-wide tile has no register/shared path in
either direction, and #5/#6/#9 are untouched. Halve COLUMNS and the rest of
the kernel would run.

README item 1, "there is no shared to register path at all", is closed and
says what replaced it; items 2 and 3 pick up what is left, which is shape
rather than direction. GAPS gains 2.1a, and its cuda-oxide support table
stops calling ldmatrix Hopper-only.
@feitreim
feitreim merged commit 3a13cbf into main Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shared to register load: the missing half of ldst

1 participant