Skip to content

mma_ab's shape is the band's, and the two callers that read it as the tile's (#175) - #176

Merged
feitreim merged 1 commit into
mainfrom
fix/issue-175-mma-ab-band-width
Aug 3, 2026
Merged

feitreim merged 1 commit into
mainfrom
fix/issue-175-mma-ab-band-width

Conversation

@feitreim

@feitreim feitreim commented Aug 3, 2026

Copy link
Copy Markdown
Owner

mma_ab accumulates one 64-wide band per B subtile, at
tmem + subtile * 64. So the instruction descriptor's N is the band's
width, not the [M, N] the operand tiles describe — and two places in the tree
passed the tile's:

  • src/mma.rs:183, mma_ab's own doctest
  • examples/src/flash_forward.rs:174, output_shape, used for O = P·V

With p: [128, 64] and v: [64, 128] (2 subtiles), M128_N128 issues:

band accumulator columns written should be
0 0..128 0..64
1 64..192 64..128

Band 1 overwrites half of band 0 and runs 64 columns past a [128, 128]
accumulator. In flash_forward the allocation is 256 columns and the output
tile starts at 64, so nothing faults — it just computes a wrong O.

src/tmem.rs:40 is not an instance and is left alone: that is mm_abt,
one instruction at tmem with no band loop, so its N is B's row count and
128 is right. The two walks disagreeing about what N means is the trap.

What settles which one is right

The shipped O = P·V in feitreim/oxide-train has always passed M128_N64 for
exactly these operand shapes, B200-validated against two oracles. mma_ab's
own doc already said "One 64-wide output band per B subtile" and "tmem owns
64 * B::SUBTILES fp32 columns"; only the example and the doctest disagreed.

Why it survived

examples/src/flash_forward.rs:19 says it: "Status: compiles, and is in
the default build. There is no launcher and no CPU reference, so nothing here
is measured against a known-good O."
That is #85, and this is the first
thing it has cost — feitreim/oxide-train#68 was told to start from this file's
shape, and this is the one line of it that could not be copied.

What this does not do

Add a check. shape is a runtime argument, so no const { assert!(..) } can
see it; the doc now states the rule at both mma_ab and mm_ab and the safety
contract carries a clause for it. Making the shape a const parameter, or
deriving it from the accumulator, is #128 — and this is that issue's
part 2 with a casualty, since for mma_ab under a 2-byte element and
Swizzle128B the legal N is the constant 64 and there is no other answer a
caller could give.

Gates

scripts/fmt --check, cargo clippy --all-targets -- -D warnings,
cargo test clean. The example's PTX changes (a different instruction
descriptor immediate); it is on no correctness gate, which is the point.

Closes #175.

… tile's

`mma_ab` walks one 64-wide output band per `B` subtile, offsetting the
accumulator by 64 columns each time, so the instruction descriptor's `N` is the
*band's* width and never the tile's. Its own doc said the first half of that
and its doctest contradicted it: `M128_N128` over a `[64, 128]` `B` issues band
0 across columns 0..128 and band 1 across 64..192, so band 1 overwrites half of
band 0 and the walk runs 64 columns past a `[128, 128]` accumulator. The
columns are usually still inside the allocation, so it is a wrong `D` and not a
fault.

`examples/src/flash_forward.rs` had the same line, for its `O = P·V`, from the
day it was written. Its own doc header says why nothing caught it: no launcher,
no CPU reference, nothing measured against a known-good `O` (#85). The shipped
`O = P·V` in feitreim/oxide-train has always passed `M128_N64` for exactly
these operand shapes, B200-validated against two oracles, which is what settles
which one is right.

The doc now states the rule where a caller reads it and the safety clause
carries it, since a `const` assert cannot see a runtime `shape` — making the
shape a const parameter, or deriving it from the operands, is #128.

Closes #175.
@feitreim
feitreim merged commit 89cb0aa into main Aug 3, 2026
3 checks passed
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.

mma_ab's N is always the subtile width, and the two places that say otherwise write past the accumulator

1 participant