Skip to content

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

Closed

Description

@feitreim

Found by the #127 work (PR #135), which declined to act on it — correctly, since it is a safety contract and loosening one on reasoning alone is the dangerous direction.

src/ldst.rs:210-213, load_fragment's safety contract:

chunks must belong to a tile at least row + 16 rows tall whose bytes are already visible to the generic proxy (a TMA load needs its barrier waited on, a stmatrix needs fence.proxy.async.shared::cta), and column + 16 must fit the tile.

Why it looks wrong

fence.proxy.async.shared::cta orders generic-proxy writes so the async proxy (TMA, tcgen05 MMA) can see them. That is the fence store_fragment's and tma_store's contracts owe, and it is correct there — those are generic-write then async-read.

But stmatrix and ldmatrix are both generic-proxy accesses: warp-level shared-memory store and load executed by threads. Generic-to-generic needs no proxy fence at all. What it needs, when the writing and reading threads differ, is a barrier. The TMA half of the same sentence is right (async write, generic read, ordered by the load's own mbarrier) — it is the stmatrix half that does not follow the rule the rest of the crate states.

src/shared.rs's publish_to_async_proxy doc, added in #135, states that rule explicitly and lists the two cases where the fence is not owed, one of which is exactly a generic-write/generic-read pair.

What would settle it

Not reasoning — this needs a B200. Both the redundant-fence reading and the missing-barrier reading produce working code most of the time, which is what makes a wrong contract here expensive later rather than now.

  • Whether any caller pairs store_fragment/stmatrix with load_fragment/ldmatrix on the same tile today, and across warps or within one.
  • Whether the sentence meant bar.sync and named the wrong instruction, or meant a case that does not arise.

If it is redundant, the fix is to say barrier and cite the rule; if the real hazard is a missing barrier, the contract is understating the obligation, which is the direction worth finding out about.

Not urgent, and why it is filed anyway

load_fragment is the .x2 load side, which #131 notes is the half that never got .x4. The contract being wrong costs nothing until someone builds on it — which is precisely when a wrong safety contract is most expensive. Related: #131, #129.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions