Skip to content

Reduction TMA stores (cp.reduce.async.bulk.tensor): upstream to cuda-oxide rather than ptx_asm! locally #42

Open

Description

@feitreim

Split out of #9, which landed the plain TMA store path and deliberately scoped
reduction stores out until we knew which way to go. We know now.

ThunderKittens has store_add_async / store_min_async / store_max_async —
the ops that make split-K and multi-CTA reduction epilogues cheap, since each
CTA can accumulate into global memory without a separate reduction pass.

The evidence points to upstreaming, not a local intrinsic

ldst::stmatrix_m8n8_x2 is precedent for writing a ptx_asm! intrinsic here
rather than waiting on upstream. But the two cases are not alike, and the
difference is the whole argument:

  • stmatrix was one broken declaration. cuda-oxide emits the intrinsic and
    it fails to resolve, so a three-line ptx_asm! routes around a single defect.
    Note the load direction needed no workaround at all — wmma::ldmatrix_x2
    lowers cleanly (Shared to register load: the missing half of ldst #21).
  • cp.reduce.async.bulk.tensor is absent in every rank and every op, and
    prefetch with it — while the plain cp_async_bulk_tensor_{1..5}d_s2g family
    is complete at all five ranks and lowers with no workaround.

That is a gap in cuda-oxide's generated intrinsic catalog, not a defect
specific to one instruction. Reimplementing a ~15-function family by hand here
means maintaining a parallel copy of something the generator should emit, and
carrying it indefinitely against a pinned rev.

Suggested route

  1. Check whether the omission is deliberate (some cp.reduce forms have arch or
    alignment constraints) or simply not covered by the generator's input.
  2. If the latter, upstream it — it likely lands as generator input rather than
    hand-written code, so it would arrive with the whole family at once.
  3. Only fall back to a local ptx_asm! if upstreaming is refused or too slow,
    and if so scope it to the ops a kernel actually needs (add first) rather
    than the full cross-product.

Not urgent

Nothing in the backlog is blocked on it. No example needs it: the GEMM's
epilogue is a plain store, and neither normalization reduces across CTAs. It
becomes load-bearing the moment anyone writes a split-K GEMM or a multi-CTA
attention backward, so it is worth having the answer before then rather than
during.

Related: #9 (the plain store path, landed), #15 (lcsf, whose pipelined
epilogue is the other consumer).

Activity

  1. added
    blocked-upstream
    on Jul 27, 2026
  2. feitreim commented on Jul 29, 2026

    @feitreim
    OwnerAuthor

    From the 2026-07-29 library audit, on the "and prefetch is absent for the same reason" half of GAPS.md §2.3 — it is not the same reason, and prefetch is much cheaper than this issue.

    Checked against a checkout of the pinned revision whose HEAD I confirmed equals b099f64c1a32869b74be99f4f88242fb68655b51 before reading it (the #106 rule):

    in intrinsics/imported.json generated into cuda-device
    cp.reduce.async.bulk.tensor (this issue) no — zero occurrences no
    cp.async.bulk.prefetch.L2 yes — int_nvvm_cp_async_bulk_prefetch_L2, with both the plain and .L2::cache_hint forms no
    cp.async.bulk.tensor.prefetch (im2col and tiled) yes — int_nvvm_cp_async_bulk_tensor_prefetch_* no

    So the two asks are different jobs. This issue needs a new LLVM intrinsic record and a lowering, which is why it argues for an upstream contribution over a local ptx_asm!. Prefetch needs neither: the record and the lowering are already in the repo at our pin, and what is missing is only the generated Rust wrapper. That is a generation-list change upstream, or — since it is a plain instruction with no barrier and no transaction accounting — a five-line ptx_asm! locally with none of this issue's argument against it.

    Not proposing anything be done here; recording it so the next reader of §2.3 does not inherit "blocked upstream" for both. GAPS.md's pinned-rev table is corrected in the same PR.

  3. feitreim commented on Jul 29, 2026

    @feitreim
    OwnerAuthor

    Correction found during the 20a5616 upgrade audit: the cp.async.bulk.tensor.reduce.* records are present in intrinsics/imported.json at both the former b099f64 pin and the new pin. They remain absent from crates/cuda-device/src/generated/tma.rs and from the generated public ABI.

    So this is narrower than the issue body says: it appears to be admission/generation-list work, not a need to add imported LLVM records and lowering from scratch. GAPS.md has been corrected accordingly. The preferred upstream route remains the same.

  4. feitreim commented on Aug 4, 2026

    @feitreim
    OwnerAuthor

    Route 3 taken: oxide-train#80's accumulate epilogue is the kernel that asked, so the scoped fallback (add, rank 2, tile mode only) is up as #187, gated by a new device-tests case (tma reduce-add store, seed + 2·value bit-exact on a B200).

    The decision-tree step 1 answer, confirmed at the 20a5616 pin: neither intrinsics/overlay.toml nor intrinsics/abi-v1.toml mentions the reduce family at all — the plain s2g family's catalog ids are in abi-v1.toml, the reduce records never made the admission list. A generation-list gap, not policy. Step 2 stays the end state: filed upstream as NVIDIA/cuda-rust#660; when it lands, cp_reduce_async_bulk_tensor_2d_s2g_add's ptx_asm! body shrinks to a call and this issue can close on the swap.

  5. added a commit that references this issue on Aug 4, 2026
  6. feitreim commented on Aug 10, 2026

    @feitreim
    OwnerAuthor

    Upstream landed: NVIDIA/cuda-rust#660 closed as completed 2026-08-10, fixed by NVIDIA/cuda-rust#770 (merged 2026-08-10, merge commit 73d0df3c9dccc566c4bf7857a4e37536b49edb30, stacked on #721 / 9eaaa20).

    What upstream shipped — more than the minimum ask:

    • All 64 cp.reduce.async.bulk.tensor variants admitted, not just the .add tile forms: add/and/dec/inc/max/min/or/xor × tile 1D–5D × im2col 3D–5D. ABI entries i0923–i0986.
    • Generated cuda-device APIs plus dialect ops and MIR lowering, through typed NVVM intrinsics on the LLVM backend and inline PTX on the libNVVM backend. Target-gated PTX 8.0 / SM90+.
    • One spelling note for when we swap: the Rust/LLVM im2col forms map to the PTX im2col_no_offs spelling.

    One caveat carried from upstream's evidence: all 64 variants were validated compile/assemble/link on both backends, but hardware runtime execution upstream remains unexecuted. Our tma reduce-add store device-tests case (seed + 2·value bit-exact on a B200, added with #187) is therefore still the runtime gate for the swap — keep it.

    Remaining to close this issue, per the 2026-08-04 comment ("close on the swap"):

    1. Bump the cuda-oxide pin past 73d0df3 — the current 20a5616 pin predates both stacked PRs. Note oxide-train#66 tracks the swap-back bump to 20a5616; that target is now superseded by this one.
    2. Shrink cp_reduce_async_bulk_tensor_2d_s2g_add's ptx_asm! body (Reduction TMA store, scoped to add at rank 2 (#42 route 3): the fallback the accumulate epilogue asked for #187) to a call into the generated wrapper, with the existing device test unchanged as the gate.

    Dropping the blocked-upstream label: nothing upstream is in the way anymore, what remains is our pin bump and the swap.

  7. removed
    blocked-upstream
    on Aug 10, 2026
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