Repository navigation
An ldmatrix reads what stmatrix wrote under a barrier, measured: the proxy fence load_fragment demanded orders nothing between them - #207
Merged
Conversation
…x` 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
…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
…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
… 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
force-pushed
the
docs/stmatrix-ldmatrix-fence
branch
from
August 6, 2026 20:39
869de4d to
55671d6
Compare
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.
load_fragmentasked forfence.proxy.async.shared::ctabefore anldmatrixread a tilestmatrixhad written. Both are generic-proxy accesses, so that fence orders nothing between them, and what such a pair owes across threads is a barrier the contract never named. Redundant demand or understated obligation — very different mistakes, and #136 is explicit that reasoning does not settle which, because both readings produce working code most of the time.Settled on a B200, with the #198 pattern: a self-attributing case, a fence matrix, a control that proves the case can see what it excludes, and the contract rewritten to what was measured.
Whether any caller was exposed
No. Every
load_fragmentandload_tilein the repo reads a TMA-staged tile —device-tests'ldmatrix_probeandband_roundtrip,examples/softmax.rs,examples/layernorm.rs— and everystmatrixwrite is read back by plainld.shared(store_shared_rows,dump_rows), by the TMA store engine, or by an MMA. The two directions had never met on one tile, which is exactly why neither reading of the sentence had ever run.band_roundtripcomposes both movers but load-then-store over disjoint rows.The survey did turn up one exposure in the other direction, which the contract had right all along:
examples/src/flash_forward.rswritesPwithstore_tileand hands it tomm_ab— a generic write an async reader takes — with only async_threadsbetween. That is the case the fence is for. Fixed here, one line, with the comment saying which hand-off it serves.The case
device-tests'stmatrix into ldmatrix. Warp 0 fills a[64, 64]tile twice — from a stale generation of position identities, published with a fence and a barrier so every warp is known to hold it, then from the fresh one — and a reader warp reads all sixteen blocks back withldmatrix.The two generations are the same addresses carrying identities 37 columns apart: odd, so the rotation is a bijection on the tile's columns; and not a multiple of 16, so no misaddressed
ldmatrixblock can produce that displacement. A value therefore names the generation that reached it, and "the ordering was missing" and "the address was wrong" are different answers rather than both being wrong.The matrix
4096 values a row.
scripts/modal-run device_tests, 57 of 57 cases passed (rebased onto #206, whose twoldmatrix x4cases are in that count).bar.synconlybar.synconlyThe fence is redundant and the barrier is the whole of it. Within one warp the two instructions are that warp's own program order and nothing is owed between them. Across warps
bar.syncalone is clean over 4096 values — and the row carrying the fence without a barrier read the previous generation of the tile. That last row is the direct half of the answer: the fence the contract demanded was in the kernel, in the position the contract named, and the read still went stale. Not an inference from which proxy the instructions use; the fence failing to order the pair, measured.Every wrong value in both firing rows was the stale generation rather than another position's identity, which is what says the failure was an ordering and not an address.
The control, and the trap it was designed around
#198's honest negative was a dropped-wait control that observed nothing, so it was evidence about neither the wait nor the case. This control cannot do that: it reads before the store with a barrier making that the order that happens, so it is an ordering rather than a race, and its dump is required to be stale everywhere. It was. Both race rows happened to fire as well, so the case observes the hazard three ways — but it never needed them to.
The race counts are the only numbers here that do not reproduce. An earlier run had
nothing between themat 128 andthe proxy fence onlyclean. Same verdict — a race that resolves in order is not an ordering either way, nothing gated rests on either row — and the doc says so rather than quietly reporting the better run.What the contract now says
load_fragmentsplits the obligation by writer instead of naming one instruction for both:stmatrixwrites through the generic proxy — the one this load reads — so no proxy fence is owed. What is owed is a barrier, and only when the writing warp is not this one:bar.syncfor a tile the block shares,bar.warp.syncfor one a warp owns.store_fragmentstates the same rule from the other side, since that is where a caller looks. #206'sload_fragment_x4andload_tile_x4landed with the old framing's bare "visible to the generic proxy" bullet; all three inheriting contracts now name the route instead of the state — the TMA load's mbarrier, or a barrier if anstmatrixin 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; the case runs.x2, which is what ships. The measured paragraph and the citation live onload_fragment;docs/library/ldst.mdhas the table, what the fence-only row does say, and what is not established (another CTA of a cluster, a warpgroup boundary at 256 threads, silicon that is not a B200).GAPS.md2.1a carries the summary.Gates
GitHub Actions is in an outage; run by hand.
scripts/fmtcargo testcfg_attrcommented, per CI.md)GlobalLayoutonesscripts/modal-run buildscripts/modal-run regcountflash_forward168 regs, 0 spillsscripts/modal-run examplespass flash_forward 2x256x128 rows attended, worst relative error 1.66e-3scripts/modal-run device_testscargo clippy(library,--features host; device-tests withCUDA_TOOLKIT_PATH)write_literalwarnings the table code shares withtmem_rescale.rsandtmem_warpgroup.rson mainRebases
Rebased twice: onto 6cd342a (#205) and then onto 2703360 (#206). #206's conflicts were
src/ldst.rs(auto-merged),GAPS.mdanddocs/library/ldst.md— keep-both in each, taking main's rewritten.x4width paragraph over the stale one my branch carried.One note on the baseline
The first
device_testsrun off this branch came back 54 of 55 withsttm into mmared. I ranorigin/mainat 5d37049 to attribute it: 53 of 54, same case, same failure — #204's untested typed-API adaptation, since fixed on main as 6cd342a (#205). This branch is rebased onto that and the case is green. Worth recording that the failure was self-attributing: every wrong value was a clean power-of-RESCALEmultiple of its own cell, which is what pointed at an addressing bug in a case built to ask a fence question. The pattern pays for itself outside the question it was built for.Closes #136