Skip to content

An ldmatrix reads what stmatrix wrote under a barrier, measured: the proxy fence load_fragment demanded orders nothing between them - #207

Merged
feitreim merged 4 commits into
mainfrom
docs/stmatrix-ldmatrix-fence
Aug 6, 2026
Merged

feitreim merged 4 commits into
mainfrom
docs/stmatrix-ldmatrix-fence

Conversation

@feitreim

@feitreim feitreim commented Aug 6, 2026 •

Copy link
Copy Markdown
Owner

load_fragment asked for fence.proxy.async.shared::cta before an ldmatrix read a tile stmatrix had 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_fragment and load_tile in the repo reads a TMA-staged tile — device-tests' ldmatrix_probe and band_roundtrip, examples/softmax.rs, examples/layernorm.rs — and every stmatrix write is read back by plain ld.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_roundtrip composes 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.rs writes P with store_tile and hands it to mm_ab — a generic write an async reader takes — with only a sync_threads between. 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 with ldmatrix.

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 ldmatrix block 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 two ldmatrix x4 cases are in that count).

what varies row result
control the read runs first, barrier-ordered every value stale
same warp nothing between them every value fresh
the proxy fence only every value fresh
bar.sync only every value fresh
both — what the contract demanded every value fresh
cross warp bar.sync only every value fresh
both — what the contract demanded every value fresh
nothing between them 256 stale (reported, gates nothing)
the proxy fence only 128 stale (reported, gates nothing)

The 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.sync alone 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 them at 128 and the proxy fence only clean. 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_fragment splits the obligation by writer instead of naming one instruction for both:

  • a TMA load writes through the async proxy, and what publishes it is the load's own mbarrier, waited on;
  • an stmatrix writes 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.sync for a tile the block shares, bar.warp.sync for one a warp owns.

store_fragment states the same rule from the other side, since that is where a caller looks. #206's load_fragment_x4 and load_tile_x4 landed 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 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; the case runs .x2, which is what ships. The measured paragraph and the citation live on load_fragment; docs/library/ldst.md has 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.md 2.1a carries the summary.

Gates

GitHub Actions is in an outage; run by hand.

gate result
scripts/fmt clean
cargo test 117 + 1 + 84 pass
intra-doc links (cfg_attr commented, per CI.md) no new dangles — only the known host-gated GlobalLayout ones
scripts/modal-run build exit 0
scripts/modal-run regcount exit 0 — occupancy step not crossed; flash_forward 168 regs, 0 spills
scripts/modal-run examples exit 0 — pass flash_forward 2x256x128 rows attended, worst relative error 1.66e-3
scripts/modal-run device_tests exit 0 — 57 of 57, re-run after the #206 rebase
cargo clippy (library, --features host; device-tests with CUDA_TOOLKIT_PATH) clean but for the three write_literal warnings the table code shares with tmem_rescale.rs and tmem_warpgroup.rs on main

Rebases

Rebased twice: onto 6cd342a (#205) and then onto 2703360 (#206). #206's conflicts were src/ldst.rs (auto-merged), GAPS.md and docs/library/ldst.md — keep-both in each, taking main's rewritten .x4 width paragraph over the stale one my branch carried.

One note on the baseline

The first device_tests run off this branch came back 54 of 55 with sttm into mma red. I ran origin/main at 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-RESCALE multiple 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

…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
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.

load_fragment's contract may demand the wrong fence between stmatrix and ldmatrix

1 participant