Skip to content

The load side has an ldmatrix.x4 too, and measured it is a wash where the store side's was not - #206

Merged
feitreim merged 1 commit into
mainfrom
feat/ldmatrix-x4-load
Aug 6, 2026
Merged

feitreim merged 1 commit into
mainfrom
feat/ldmatrix-x4-load

Conversation

@feitreim

@feitreim feitreim commented Aug 6, 2026

Copy link
Copy Markdown
Owner

Closes #131.

The store side got .x4 in #116 and the load side stayed at two ldmatrix_x2
a block. This adds the wide load and then answers the question the issue was
actually about
: whether it is worth using. It is not, by a little, and now
that is a decision with a number behind it rather than an asymmetry nobody
chose.

The code

ldst::load_fragment_x4 and load_tile_x4, ~60 lines. No new addressing:
ldmatrix.m8n8.x4 takes its 32 addresses exactly as stmatrix.m8n8.x4 does,
so stmatrix_x4_addresses_are_the_x2_addresses_restacked is now
x4_addresses_are_the_x2_addresses_restacked and is the derivation for both
wide forms. cuda_device::wmma::ldmatrix_x4 lowers cleanly for sm_100a — the
ptx_asm! workaround is still the store side's alone.

Two device-tests cases in the ldtm x8 map mould — ldmatrix x4 map and
ldmatrix x4 map wide — reusing check_ldmatrix, so the two spellings are held
to the same host expectation rather than to each other: a wide load whose four
registers come back rotated is a named tile position arriving in the wrong one.

The measurement

softmax's device body now takes the load width as a const parameter.
examples/ emits only the shipped value; experiments/src/softmax_x4.rs emits
the other as a second entry in the same bundle, so both arms are one binary
and every pair is adjacent in time. scripts/modal-run bench --case ldmatrix:
four whole measurements of each arm round-robin, each the min of 30 timed
launches after 5 warm-up, every one checked against the CPU reference first.

rows × 128 × 2 planes blocks .x2 ms .x4 ms .x2 GB/s .x4 GB/s .x4/.x2 lowest highest
4096 64 0.0106 0.0105 397.2 398.4 1.0124 0.9758 1.0249
32768 512 0.0166 0.0168 2020.4 1993.5 1.0176 0.9904 1.0212
524288 8192 0.1254 0.1268 4281.0 4235.6 1.0110 1.0097 1.0148

The last three columns are the four paired ratios of .x4 ms to .x2 ms, so
above 1.000 is the narrow load ahead. The first two rows straddle 1.000 and are
unordered — one of the four pairs goes each way, which is why the ms/GB/s
medians in row 1 disagree with its ratio. The bandwidth-bound row is ordered:
all four pairs sit in 1.0097–1.0148, so .x4 is 1.1% slower there.

Registers, scripts/modal-run regcount:

kernel regs spill frame
softmax_rows (.x2, both crates) 32 0 0
softmax_rows_x4 40 0 0
ldmatrix_map, ldmatrix_x4_map, both _wide 32 0 0

+8 registers a thread and no occupancy step — the 32,776 B shared plan fixes
this kernel at 6 CTAs an SM either way. The four isolated probes read identical
because a probe that dumps each block as it arrives holds nothing; the cost only
appears where a real kernel carries statistics across the walk. That is the
liveness the issue predicted, showing up exactly where a register column alone
would have missed it.

The decision

.x2 keeps shipping. .x4 lands as the measured alternative with the numbers
in its own doc, docs/library/ldst.md carries the table and the argument, and
docs/kernels/softmax.md and GAPS.md §2.1a say the same thing where a reader
of those would look. There is no issue-slot win here to go hunting for on a
kernel of this shape, and the store/load asymmetry is now a chosen one: that
.x4 removed a wait, this one had none to remove.

Gates (GitHub Actions is out; all run by hand)

gate result
scripts/fmt --check clean, four manifests
cargo test 117 + 84 doctests, green
cargo doc --no-deps with the cfg_attr commented out only the known GlobalLayout host-gated dangles
scripts/modal-run build exit 0
scripts/modal-run regcount exit 0
scripts/modal-run device_tests exit 0, 56 of 56, including both new cases
scripts/modal-run examples exit 0, softmax_x4 at the shipped kernel's own 1.97e-3 worst error

Branched off 6cd342a (#205), so the sttm into mma case is the fixed one.

Notes for review

  • examples/src/softmax.rs's host half changed shape: run takes the launch as
    a parameter so both entries reach the same CPU reference and the same clock.
    The three load_tile call sites are one band::<X4> helper; nothing else in
    the device body moved, which should keep this cheap to rebase against The epilogue that ships is open-coded in both GEMMs; epilogue.rs holds the route that lost #126's
    store-path work.
  • experiments/src/bench.rs's middle/extremes became pub(crate) rather
    than being copied into the new module.

…re the store side's was not (#131)

`store_fragment_x4` has had a `.x4` since #116 and `load_fragment` was still
two `ldmatrix_x2` a block. `load_fragment_x4` and `load_tile_x4` close that,
on the address derivation the store side already had — `ldmatrix.m8n8.x4`
takes its 32 addresses exactly as `stmatrix.m8n8.x4` does, so one restacking
test serves both — and the `ldmatrix x4 map` / `ldmatrix x4 map wide` device
cases hold the four destination registers to the same host expectation the
narrow pair answers to.

`.x2` still ships, and that is the point of the issue. #116's `.x4` and #117's
`.x8` paid by removing waits; an `ldmatrix` has none, so the gain is issue
slots and the cost is liveness. On `softmax` — three passes, every one a
`load_tile` — the wide form is unordered at 64 and 512 blocks and 1.1% slower
at 8192, on 40 registers a thread against 32 at the same 6 CTAs an SM.
@feitreim
feitreim merged commit 2703360 into main Aug 6, 2026
feitreim added a commit that referenced this pull request Aug 6, 2026
… points at the clause rather than half of it

#206 landed `load_fragment_x4`/`load_tile_x4` against the old framing, where
"visible to the generic proxy" was a bare bullet the caller had to interpret.
`load_fragment`'s clause now splits that obligation by writer, so the three
inheriting contracts name the route instead of the state: the TMA load's own
mbarrier, or a barrier if an `stmatrix` in another warp wrote the bytes.

The two widths differ in how many addresses the warp supplies and in nothing
that touches a proxy, so it is one obligation and `docs/library/ldst.md` says
so — the case runs `.x2`, which is what ships.

Refs #136, #131
feitreim added a commit that referenced this pull request Aug 6, 2026
…the proxy fence `load_fragment` demanded orders nothing between them (#207)

* A device-tests case for what orders an `stmatrix` before the `ldmatrix` that reads it

`load_fragment`'s contract asks the caller for `fence.proxy.async.shared::cta`.
Both instructions are generic-proxy accesses, and the rule
`publish_to_async_proxy` states is that such a pair owes no proxy fence at all —
across threads it owes a barrier. Nothing in tree pairs the two directions on
one tile, so neither reading has ever run.

`stmatrix into ldmatrix`: warp 0 fills a `[64, 64]` tile twice, once from a
stale generation of position identities published with everything the contract
could ask for and then from the fresh one, and a reader warp reads the whole
tile back. The two generations are the same addresses carrying identities 37
columns apart — odd and not a multiple of 16, so no misaddressed `ldmatrix`
block can produce the displacement — and a value therefore names the generation
that reached it rather than merely failing to match.

Nine rows: the control, the proxy fence and `bar.sync` each present or absent,
and the reader being the writing warp or another one. The control reads before
the fresh store with a barrier making that the order, so it is required to come
back stale everywhere — and being an ordering rather than a race it cannot
decline to fire, which is the trap #198's dropped-wait control fell into.

Refs #136

* The fence between an `stmatrix` and an `ldmatrix` is a barrier, and `load_fragment` says so

Measured on a B200, `stmatrix into ldmatrix`, 4096 values a row:

  control: the read runs first          every value stale (the two differ)
  same warp, nothing between them       every value fresh
  same warp, the proxy fence only       every value fresh
  same warp, bar.sync only              every value fresh
  same warp, both (the contract)        every value fresh
  cross warp, bar.sync only             every value fresh
  cross warp, both (the contract)       every value fresh
  cross warp, nothing between them      128 of 4096 stale  (reported)
  cross warp, the proxy fence only      every value fresh  (reported)

So `fence.proxy.async.shared::cta` is redundant here and the barrier is the whole
of it. `load_fragment`'s contract splits the obligation by writer: a TMA load is
published by its own mbarrier, an `stmatrix` by a barrier and only when the
writing warp is not the reading one. `store_fragment` states the same rule from
the other side.

The `cross warp, nothing between them` row fired on its own, so the hazard is
real and this case sees it — and every one of its 128 wrong values was the stale
*generation* rather than another position's identity, which is what says the
failure was an ordering and not an address. The `proxy fence only` row came back
clean and is not evidence: it has no barrier in it, it is the row above with one
more instruction of delay, and a race that resolved is not an ordering.

No caller in tree was exposed: every `load_fragment` and `load_tile` in the repo
reads a TMA-staged tile, and every `stmatrix` write is read back by `ld.shared`,
by the TMA store engine, or by an MMA. The two directions had never met, which is
why neither reading of the sentence had ever run.

That survey did turn up one exposure in the other direction, which the contract
had right all along: `flash_forward` writes `P` with `store_tile` and hands it to
an MMA — a generic write an async reader takes — with only a `sync_threads`
between. The proxy fence it owes is now there.

Refs #136

* The fence-only row read stale too, so the fence failing to order the pair is measured and not inferred

The second run of the same nine rows had both races fire: `cross warp, nothing
between them` at 256 of 4096 stale, and `cross warp, the proxy fence only` at
128. The second is the one that matters. The fence the contract demanded was in
the kernel, in the position the contract named, and the `ldmatrix` still read the
previous generation of the tile — which is the fence failing to order this pair,
rather than an inference from which proxy the two instructions use.

The counts themselves are the only numbers in the table that do not reproduce;
the doc says so and says why it changes nothing, since a race that resolves in
order is not an ordering either way and nothing gated rests on either row.

Refs #136

* The `.x4` load side inherits the barrier obligation, and its contract points at the clause rather than half of it

#206 landed `load_fragment_x4`/`load_tile_x4` against the old framing, where
"visible to the generic proxy" was a bare bullet the caller had to interpret.
`load_fragment`'s clause now splits that obligation by writer, so the three
inheriting contracts name the route instead of the state: the TMA load's own
mbarrier, or a barrier if an `stmatrix` in another warp wrote the bytes.

The two widths differ in how many addresses the warp supplies and in nothing
that touches a proxy, so it is one obligation and `docs/library/ldst.md` says
so — the case runs `.x2`, which is what ships.

Refs #136, #131
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.

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

1 participant