Skip to content

The shared to register load side is stuck at ldmatrix.x2 while the store side got .x4 #131

Closed

Description

@feitreim

Found by the 2026-07-29 library audit (GAPS.md §2.1a). A narrow, measurable
follow-up to two changes that already paid.

src/ldst.rs moves fragments between shared memory and registers in both
directions. The store side has a .x4 form (store_fragment_x4,
store_tile_x4, #116) — one stmatrix.m8n8.x4 per [16, 16] block instead of
two .x2s a slot apart — and it is what gemm's shipped epilogue uses
(SHIPPED_EPILOGUE is StagedWideX4). The load side is still .x2 only:
load_fragment loops Fragment::SLOTS times over ldmatrix_x2
(src/ldst.rs:207-229).

cuda_device::wmma ships ldmatrix_x1, ldmatrix_x2 and ldmatrix_x4, plain
and trans, at the pinned revision b099f64c1a32869b74be99f4f88242fb68655b51
— checked against a checkout whose HEAD I confirmed equals the pin
(crates/cuda-device/src/wmma.rs). So this is a transcription, not an upstream
ask.

Why it is worth measuring rather than assuming

The addressing needs no new derivation. stmatrix_x4_addresses_are_the_x2_addresses_restacked
in src/ldst.rs's tests is the identity the store side used: .x4 takes 32
addresses from all lanes where .x2 takes 16 from the first half, so lane l
supplies what lane l % 16 supplied for slot l / 16. ldmatrix.x4 has the
same lane→address relation, so the same test extends.

What is not free is liveness, and that is the reason to measure rather than
switch: TmemTile::fragments_x8 (#117) bought +23.6/+8.6/+3.6% by removing
waits, and its own doc says the cost is that four blocks are live at once
where the .x1 path lets the compiler fuse one fragment through to its
consumer. ldmatrix has no wait to remove — it is a plain shared read — so the
gain here is issue slots only and the liveness cost is the same shape. It may
well be a wash. That is worth knowing rather than guessing, because right now
the crate has an asymmetry nobody chose.

Scope

Estimate

~60 lines in src/ldst.rs, ~40 for the device case. The measurement is the
work, not the code.

Related: #116 (the store side's .x4), #117 (the TMEM drain's .x8, and the
liveness argument), #81 (why a register count is not the answer).

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:memory

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions