Skip to content

Reduction TMA store, scoped to add at rank 2 (#42 route 3): the fallback the accumulate epilogue asked for - #187

Merged
feitreim merged 1 commit into
mainfrom
42-reduction-tma-store-add
Aug 4, 2026
Merged

feitreim merged 1 commit into
mainfrom
42-reduction-tma-store-add

Conversation

@feitreim

@feitreim feitreim commented Aug 4, 2026

Copy link
Copy Markdown
Owner

Takes #42's sanctioned route 3: the moment a kernel asked for reduction stores (oxide-train#80's accumulate epilogue, remedy 1), the scoped local fallback lands — add, rank 2, tile mode, nothing else.

The #42 decision tree, resolved

  1. Deliberate omission or generator-input gap? Checked at the pin (20a5616, HEAD verified before reading): all 64 int_nvvm_cp_async_bulk_tensor_reduce_* records are in intrinsics/imported.json, zero are generated into cuda-device, and neither intrinsics/overlay.toml nor intrinsics/abi-v1.toml mentions the family at all — the plain cp_async_bulk_tensor_*_{g2s,s2g} catalog entries sit in abi-v1.toml and the reduce family simply never made the admission list. A generation-list gap, not a policy. This confirms the correction already recorded on Reduction TMA stores (cp.reduce.async.bulk.tensor): upstream to cuda-oxide rather than ptx_asm! locally #42.
  2. Upstreaming stays the preferred end state — filed as an issue on NVlabs/cuda-oxide describing the missing family (link in comments below). When the generation list admits it, the ptx_asm! body here shrinks to a call.
  3. The scoped fallback (this PR), limited to what the GEMM epilogue needs.

What lands

  • shared::cp_reduce_async_bulk_tensor_2d_s2g_add — one ptx_asm! intrinsic (cp.reduce.async.bulk.tensor.2d.global.shared::cta.add.tile.bulk_group), the stmatrix precedent's shape. The element type lives in the tensor map, so the one intrinsic covers fp32 and bf16 alike.
  • SharedTile::tma_store_add_2d — mirrors tma_store_2d (TMA store path #9's store path), same subtile walk, same bulk-group completion, so tma_store_commit and both waits govern it unchanged.
  • StoreRing::commit_add_2d — the ring discipline (lcsf and the rest of the prototype layer #15) over the reduction, one line different from commit_2d.
  • TensorMapElement for F32 — an fp32 C was previously unmappable; the reduction store is the first consumer.
  • GAPS.md §2.3 updated: the add/rank-2 cell filled, everything else still upstream.

Scope note: bf16 needs no second intrinsic (the dtype is the map's), but no bf16 caller exists — oxide-train's bf16 acc-T row is already at 0.937× cuBLASLt with a 0.3 ms/step gap, so nothing asked for it.

Gates

  • Tier 2 build (Modal, sm_100a codegen): green — the inline PTX lowers.
  • Tier 3 device_tests (Modal B200): 51 of 51 cases passed, including the new tma reduce-add store: an fp32 [16, 64] tile (two stacked 32-column subtiles, so the subtile walk is exercised) TMA'd in and reduce-stored twice onto a destination seeded with a constant, against a host-computed two-pass answer. Expected is seed + 2·value bit-exactly (every term an exact small integer): a plain store (value), a single add (seed + value) and a dropped seed (2·value) each produce a distinct wrong value, and the pitched destination's poisoned margins catch a stray box.
  • Tier 1 locally: scripts/fmt, clippy -D warnings, 81 host tests + doctests green.

The [16, 64] fp32 tile shape is deliberate: 4096 bytes, byte-for-byte one bf16 [32, 64] staging buffer, which is how the downstream accumulate epilogue reuses its existing shared plan without moving SHARED_BYTES.

Downstream consumer: oxide-train#80 remedy 1 (PR to follow) pins this branch until it reaches main.

…cumulate epilogue asked for

The pinned cuda-oxide rev carries all 64 cp.async.bulk.tensor.reduce records
in intrinsics/imported.json and admits none of them to the generated crate,
so the family is a generation-list change upstream (the preferred end state,
#42) and this is the sanctioned bridge: one ptx_asm intrinsic
(cp_reduce_async_bulk_tensor_2d_s2g_add), SharedTile::tma_store_add_2d over
it, StoreRing::commit_add_2d for ring discipline, and TensorMapElement for
F32 so an fp32 C can be mapped at all. Gated by device-tests' 'tma
reduce-add store': a seeded destination reduce-stored twice must read back
seed + 2·tile, which no overwrite can fake.
@feitreim

feitreim commented Aug 4, 2026

Copy link
Copy Markdown
Owner Author

Downstream consumer landed as feitreim/oxide-train#82, pinning this branch at 969d7f4 — measured on B200: the fp32 weight-gradient fold premium collapsed from +25–29% to +0.3…+9.8% (negative on the worst shape), the four f32 acc-T model rows moved 0.666/0.588/0.881/0.892 → ~0.89/0.78/0.95/0.94 of cuBLASLt, and the same-container full-step A/B is −17.3 ms (dW rows −10.4 ms, plus −6.5 ms from the store kernel shedding the fold's 120 regs/512 B frame to 102/0; the reduce kernel itself is 80/0). Do not delete this branch until oxide-train swaps to a main rev.

@feitreim
feitreim merged commit 9b58025 into main Aug 4, 2026
3 checks passed
@feitreim
feitreim deleted the 42-reduction-tma-store-add branch August 4, 2026 19:06
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.

1 participant