Skip to content

tcgen05.st is validated as LDTM's inverse and not as an MMA's input, so an in-place accumulator rescale has no ground to stand on #177

Closed

Description

@feitreim

tcgen05.st is validated as LDTM's inverse and not as an MMA's input, so an in-place accumulator rescale has no ground to stand on

What is covered and what is not

TmemTile::store_fragment / store_fragment_tile / store_tile / store_wait
are real and device-tests exercises them well — sttm round trip (.x1),
ldtm x8 map (.x8) and sttm restage together establish that STTM is the
exact inverse of the drain, at the right columns, against values the store path
never computed.

Every one of those reads the segment back with another LDTM. Nothing reads
it back with an MMA. That is the whole use STTM has in a real kernel:

src/tmem.rs:507-516 — "Ordering the write against whatever reads it — an
MMA taking the segment as accumulator, a later fragment, or dealloc_block
— is the caller's. […] Whether a tcgen05_fence_before_thread_sync /
tcgen05_fence_after_thread_sync pair is additionally required around such a
hand-off is open. This crate uses neither on any path, and that is not a
guarantee that they are unnecessary."

So the surface exists, its inverse property is proven, and the one ordering
question a kernel actually has to answer is written down as unanswered. A kernel
cannot adopt it: getting the fence wrong is not a fault, it is an accumulator
that is silently stale for some warps some of the time.

The kernel that wants it, and why it stopped

feitreim/oxide-train#68 (the unified flash-attention forward). Its output
accumulator is RegTile<32, 128> — 128 registers per thread, resident for the
whole key stream
— and it exists for exactly one reason: FA4's conditional
correction has to rescale the O = P·V segment, and with no way to write TMEM
that meant draining it to registers first. That was true when the scheme was
designed and is not true now.

What it costs, measured on a B200:

  • 1136 B of LLVM local depot in the kernel, which is out_acc whole: both
    writers (online_rescale, merge_output_tile) take it by &mut, so it is
    address-taken and never scalarizes.
  • 244 registers/thread against the 236 of the kernel it replaces.
  • The correction path that justifies all of it fires on 0.00% of key-tile
    visits
    at every gated shape, including 49152 eligible visits at the profile
    shape.

With STTM the rescale is a read-modify-write of the segment in 8-value
fragments, the accumulator stops being loop-resident, and the 128 registers
become the epilogue's transient. That is the single largest structural saving
left in that kernel.

It was not taken, and the reason is this issue: the path would be exercised
by no gate in that repo (0.00%), so a fence bug would ship unobserved, and the
library's own doc says the fence question is open.

What would close it

A device-tests case in the shape a kernel uses, not the shape a round trip
uses:

  1. MMA a segment (mm_abt, so the values are the hardware's).
  2. Drain a band, scale it in registers, store_tile it back to the same
    columns, store_wait.
  3. Issue a second MMA accumulating into that same segment (mma_* with
    accumulate = true).
  4. Drain and check against the host's scale * A·Bᵀ + A'·B'ᵀ.

Run it in both fence configurations — with and without a
tcgen05_fence_before_thread_sync / after_thread_sync pair around the
hand-off — and with the store and the MMA issued by different warps as well
as the same one, since a kernel's MMA issuer is usually not the warp that owns
the lanes. Whichever configuration is required, store_fragment's safety
contract then says so instead of saying the question is open.

Worth pairing with a negative control: a version that omits store_wait, to
confirm the case can actually see the bug it is written to exclude.

Estimate

One device-tests case in the existing fragment_probe mould plus its host
check, ~120 lines, and a doc edit turning the open paragraph into a rule. The
value is not the lines; it is that a shipped kernel is currently carrying 128
registers and 1136 B of frame because this question has no answer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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