Repository navigation
The load side has an ldmatrix.x4 too, and measured it is a wash where the store side's was not - #206
Merged
Merged
Conversation
…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
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
This was referenced Aug 6, 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.
Closes #131.
The store side got
.x4in #116 and the load side stayed at twoldmatrix_x2a 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_x4andload_tile_x4, ~60 lines. No new addressing:ldmatrix.m8n8.x4takes its 32 addresses exactly asstmatrix.m8n8.x4does,so
stmatrix_x4_addresses_are_the_x2_addresses_restackedis nowx4_addresses_are_the_x2_addresses_restackedand is the derivation for bothwide forms.
cuda_device::wmma::ldmatrix_x4lowers cleanly forsm_100a— theptx_asm!workaround is still the store side's alone.Two
device-testscases in theldtm x8 mapmould —ldmatrix x4 mapandldmatrix x4 map wide— reusingcheck_ldmatrix, so the two spellings are heldto 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 aconstparameter.examples/emits only the shipped value;experiments/src/softmax_x4.rsemitsthe 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.
.x2ms.x4ms.x2GB/s.x4GB/s.x4/.x2The last three columns are the four paired ratios of
.x4ms to.x2ms, soabove 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
.x4is 1.1% slower there.Registers,
scripts/modal-run regcount:softmax_rows(.x2, both crates)softmax_rows_x4ldmatrix_map,ldmatrix_x4_map, both_wide+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
.x2keeps shipping..x4lands as the measured alternative with the numbersin its own doc,
docs/library/ldst.mdcarries the table and the argument, anddocs/kernels/softmax.mdandGAPS.md§2.1a say the same thing where a readerof 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
.x4removed a wait, this one had none to remove.Gates (GitHub Actions is out; all run by hand)
scripts/fmt --checkcargo testcargo doc --no-depswith thecfg_attrcommented outGlobalLayouthost-gated danglesscripts/modal-run buildscripts/modal-run regcountscripts/modal-run device_testsscripts/modal-run examplessoftmax_x4at the shipped kernel's own 1.97e-3 worst errorBranched off
6cd342a(#205), so thesttm into mmacase is the fixed one.Notes for review
examples/src/softmax.rs's host half changed shape:runtakes the launch asa parameter so both entries reach the same CPU reference and the same clock.
The three
load_tilecall sites are oneband::<X4>helper; nothing else inthe 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'smiddle/extremesbecamepub(crate)ratherthan being copied into the new module.