Skip to content

Value-threaded WGMMA accumulator lowering for pipelined use (wait_group<N>, multiple groups in flight) #605

Closed

Description

@nihalpasham

Title: Value-threaded WGMMA accumulator lowering for pipelined use (wait_group, multiple groups in flight)
Labels: enhancement, cuda-feature, IR-lowering, perf

Follow-up to #598, which landed the first working WGMMA MMA lowering. That lowering fuses the whole fence/MMA/commit/wait sequence into one PTX asm block and round-trips the 32 per-thread accumulator values through memory on either side:

asm {
  ld.f32  x32          acc -> regs
  wgmma.fence
  wgmma.mma_async
  wgmma.commit_group
  wgmma.wait_group 0
  st.f32  x32          regs -> acc
}

That shape is sound by construction, but it forecloses everything that makes WGMMA fast in practice:

  • only wait_group<0> (no partial waits),
  • one group in flight at a time,
  • a 32-load + 32-store memory round-trip per fused region, so a K-loop pays it every iteration.

CUTLASS and Triton instead thread the accumulator through registers as a value across separate asm statements, which enables register-resident K-loops, multiple groups in flight, and wait_group<N>. We should get there too, with two prerequisites to solve:

  1. Aggregate SSA. Rust MIR keeps the address-taken [[f32; 8]; 4] accumulator in memory; we have no machinery to promote it to 32 SSA scalars across the region. Related local-aggregate work: Small runtime-indexed local arrays spill to PTX local memory #397, Scalarize small local arrays consumed through iterator adapters #399, Promote Copy aggregate arguments borrowed only by inlined device methods #400.
  2. Spill soundness. Naive value threading across separate asm blocks is unsound at the LLVM layer: nothing stops LLVM from spilling the in-flight accumulator vregs between the mma_async asm and the wait_group asm, which the PTX ISA forbids. The design must either fuse larger regions (fence through wait including intervening descriptor arithmetic) or find a representation LLVM provably cannot spill mid-flight.

Acceptance sketch:

  • a K-loop with descriptor offset arithmetic between MMAs keeps the accumulator in registers across iterations (no per-iteration ld/st of the accumulator),
  • wait_group<N> with N > 0 lowers, allowing multiple groups in flight,
  • the existing deferred-accumulator path remains the fallback for shapes the value-threaded path cannot prove.

Activity

  1. added
    enhancement
    help wanted
    perf
    IR-lowering
    cuda-feature
    on Jul 31, 2026
  2. nihalpasham commented on Aug 2, 2026

    @nihalpasham
    CollaboratorAuthor

    Assigned to @uurl

  3. uurl commented on Aug 6, 2026

    @uurl
    Contributor

    Tentative implementation plan

    I plan to implement this issue as a sequence of six reviewable PRs.
    The boundaries are provisional and may change based on review feedback or
    findings from the loop and pipeline legality work.

    1. Backend feasibility — test(codegen): validate spill-free 32-value WGMMA carrier #679

      • Validate 32 tied f32 accumulator inputs/results through one
        convergent inline-PTX region.
      • Compile a real BF16 m64n64k16 WGMMA sequence for sm_90a.
      • Require no PTX local-memory materialization and zero ptxas spills.
    2. Value-form accumulator carrier

      • Add the internal 32-value BF16 WGMMA accumulator representation.
      • Add verifier and lowering coverage.
      • Keep the existing pointer-form operation unchanged.
    3. Linear pointer-to-value adapter

      • Load the pointer-form accumulator once into 32 SSA values.
      • Execute the value-form group.
      • Store the values after the final full wait.
      • Preserve the current deferred pointer path as fallback.
    4. Register-resident canonical K-loop

      • Recognize the canonical counted K-loop and descriptor recurrences.
      • Fuse the asynchronous lifetime into one convergent inline-PTX region.
      • Eliminate per-iteration accumulator load/store round trips.
    5. Partial waits and multiple groups in flight

      • Support statically known wait_group<N> for N > 0.
      • Enforce a final wait_group<0> before accumulator values escape.
      • Add legality checks for multiple committed groups.
    6. Selection, fallback, and hardening

      • Select the value-threaded path only for proven-safe regions.
      • Retain the existing deferred accumulator path for unsupported shapes.
      • Add end-to-end tests, negative cases, examples, and documentation.

    This is the current decomposition, not a commitment to immutable PR
    boundaries. The ordering reflects the technical dependencies: backend
    feasibility, value representation, linear adaptation, loop fusion,
    partial waits, and final integration.

  4. added
    wgmma-value-path
    on Aug 7, 2026
  5. uurl commented on Aug 7, 2026

    @uurl
    Contributor

    The PRs are ready for review @nihalpasham
    Thanks 😀

  6. added this to the cuda oxide v0.3.0 milestone on Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

IR-loweringcuda-featureenhancementhelp wantedperfwgmma-value-path

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions