Skip to content

An MN-major B is one instruction wide, and mma_ab stops banding it (#194) - #195

Merged
feitreim merged 1 commit into
mainfrom
mma-ab-wide-band
Aug 5, 2026
Merged

feitreim merged 1 commit into
mainfrom
mma-ab-wide-band

Conversation

@feitreim

@feitreim feitreim commented Aug 5, 2026

Copy link
Copy Markdown
Owner

Closes #194.

The change

mma_ab walks its MN-major B through SharedTile::mn_walk, one instruction per K chunk covering the whole [M, N], instead of one N = 64 instruction per stacked B subtile into tmem + 64 * subtile.

let b = b.mn_walk();
let instruction = descriptor::<E>(shape, false, b.transposed());
while chunk < K / K_CHUNK {
    E::mma(tmem, a.operand_descriptor(k_major_offset(chunk, A::SUBTILE_BYTES)),
           b.chunk_descriptor(chunk), instruction, accumulate || chunk > 0);
    chunk += 1;
}

That is mma_atb's B handling exactly — the two walks differ only in their A — and it makes shape the operands' logical product at every entry point in the module. mma_ab's doc loses the two paragraphs explaining why its N was the band's, mm_ab loses the clause that referred to them, and the mistake #175 documents stops being representable: M128_N128 for a [K, 128] B is now the right answer rather than the one that overlaps the bands.

New bound: one leading offset reaches one stacked subtile, so B is at most two of them wide. A const assert, not a wrong D.

TmemTile::fragment issues both of its loads before waiting on either. tcgen05.wait::ld retires prior loads, plural — the basis of tile_x8_batched — so waiting after each meant the .x1 path never had more than one load in flight and paid full TMEM latency per four values. Batching costs nothing in liveness, since both arrivals are the call's return value either way, and it halves the waits of every .x1 band including TmemTile::tile.

Why

Two reasons, and the second is the one that motivated it.

One shape rule fewer. GAPS.md §3.3 already recorded that the MN-major operand has two right descriptor spellings and that the new walks use the leading-offset one; docs/library/mma.md already recorded that this is what lets mma_atb cover a 128-wide MN in one instruction. mma_ab was the last caller of the banding spelling.

1.50× the tensor-core rate on that product. oxide-train#94's cadence probe — one warp, one CTA, chained walks into a resident accumulator, 256 rounds a variant, on a B200:

walk instrs issue/instr retire/instr ticks per M128_N64_K16-equivalent
mma_abt M128_N64 K=128 2048 55.7 55.7 55.7
mma_abt M128_N128 K=128 2048 63.9 64.1 32.0
mma_abt M128_N256 K=128 2048 127.8 128.1 32.0
mma_ab two N=64 bands, [128,64] × [64,128] 2048 48.0 48.2 48.2
the same product in one N=128 band 1024 63.9 64.1 32.1

issue/instr equals retire/instr in every row: the issuing thread is back-pressured against a full MMA pipe, so these are the tensor core's retirement rates and not front-end tolls. A quarter-width MMA costs the tensor core what a half-width one costs, and N = 256 buys nothing over N = 128.

Why it is the same sum

Same operands, same products, same K order — the wide form issues chunk 0..K/16 into one accumulator where the banded form issued chunk 0..K/16 into band 0 and then into band 1. Any given output element accumulates over K in the identical order; elements are independent. Bit-identical, and stated as such rather than measured to a tolerance.

The descriptors say it too, and there is a host test for it now: the_wide_ab_walk_keeps_the_banded_walks_chunk_addresses requires mn_walk's chunk address at every K chunk to equal operand_descriptor(k_rows_offset(chunk)) — the banded walk's own address arithmetic. The second 64 columns move out of a second instruction's base address and into the first's leading offset, which the existing an_mn_major_walk_reaches_the_second_subtile_by_leading_offset already pins.

k_rows_offset is now #[cfg(test)]: it is no longer how any walk reaches a chunk, only the independent statement of the geometry the tests hold mn_walk to.

Callers updated

  • device-tests' walk_ab → MmaShape::M128_N128. This is the gate: the mma A·Bᵀ … mma transpose control cases run all four operand orders over one pair of logical matrices staged four ways and require the same product from each, so a wide walk that reads its second subtile wrong fails there rather than in a tolerance.
  • examples/' flash_forward output_shape → M128_N128, and the comment that explained the band rule now explains that there isn't one.
  • mma_ab's doctest.

Downstream, oxide-train has four mma_ab call sites — the forward's O = P·V, backward-q's dQ += dS·K, backward-kv's dV += Pᵀ·dY and dK += dSᵀ·Q — all [K, 128] against a 128-column accumulator, and all move to M128_N128 in the pin bump.

Gates

  • scripts/fmt --check clean across all four manifests.
  • cargo test — 112 lib + 82 doctests, green, including the new descriptor-equivalence test.
  • cargo clippy --all-targets --all-features clean.
  • cargo check on device-tests/, examples/ and experiments/.
  • Device tests want a gpu-ci run: the mma transpose-control family for mma_ab's product and ldtm x8 map for the .x1 path the fragment batching touches.

@feitreim feitreim added the gpu-ci Run the B200 device-test tier on this PR (costs GPU minutes) label Aug 5, 2026
@feitreim
feitreim merged commit f64a27b into main Aug 5, 2026
4 checks passed
@feitreim
feitreim deleted the mma-ab-wide-band branch August 5, 2026 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gpu-ci Run the B200 device-test tier on this PR (costs GPU minutes)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mma_ab bands its MN-major B 64 wide, which is one shape rule too many and 1.50x off the tensor core's rate

1 participant