Skip to content

Support two-slot partial-wait WGMMA pipelines in counted K-loops #934

Closed

Description

@uurl

Summary

Extend the existing register-resident BF16 WGMMA counted K-loop lowering to support a conservative two-slot partial-wait pipeline.

CUDA Oxide currently supports the two required shapes independently:

  • a canonical counted K-loop with one 32-value f32 accumulator carried through one convergent inline-PTX scope;
  • a straight-line partial-wait pipeline with two independent 32-value accumulator slots and wait_group<1>.

The missing composition is a counted K-loop that carries two independent accumulator slots, advances two descriptor pairs affinely, commits both groups independently, and keeps at most one group pending through wait_group<1>.

Supported shape

Recognize a canonical counted loop equivalent to:

preheader:
    fence
    goto header(i0, desc_a0, desc_b0, desc_a1, desc_b1)

header(i, desc_a0, desc_b0, desc_a1, desc_b1):
    if done:
        goto exit
    else:
        goto latch

latch:
    mma(acc0, desc_a0, desc_b0)
    commit_group
    wait_group<1>

    mma(acc1, desc_a1, desc_b1)
    commit_group
    wait_group<1>

    i       = i + 1
    desc_a0 = desc_a0 + desc_a0_step
    desc_b0 = desc_b0 + desc_b0_step
    desc_a1 = desc_a1 + desc_a1_step
    desc_b1 = desc_b1 + desc_b1_step

    goto header(...)

exit:
    wait_group<0>

The two accumulator pointers must refer to distinct canonical [[f32; 8]; 4] accumulator objects.

Proposed lowering

Introduce an internal value-form carrier with:

64 x f32 accumulator inputs
4 x u64 descriptor bases
4 x u64 descriptor steps
1 x u64 trip count

->

64 x f32 accumulator results

The entire asynchronous lifetime remains inside one convergent inline-PTX operation.

The generated PTX should contain:

  • one wgmma.fence.sync.aligned;
  • two static wgmma.mma_async instructions in the counted loop;
  • two wgmma.commit_group.sync.aligned instructions;
  • two wgmma.wait_group.sync.aligned 1 instructions;
  • four affine descriptor recurrences;
  • one final wgmma.wait_group.sync.aligned 0.

Acceptance criteria

  • recognize the canonical two-slot counted-loop shape from pointer-form MIR;
  • keep both 32-value accumulator slots register-resident across the loop;
  • lower the fused region to one convergent inline-PTX scope;
  • emit 64 tied f32 accumulator values and nine u64 control operands;
  • preserve the existing single-accumulator counted-loop lowering;
  • preserve the existing straight-line partial-wait pipeline lowering;
  • compile successfully through LLVM NVPTX;
  • be accepted by ptxas -arch=sm_90a;
  • produce no stack frame or spills;
  • introduce no .local, ld.local, or st.local accumulator traffic.

Non-goals

This issue does not add:

  • arbitrary wait_group<N> depths;
  • more than two accumulator slots;
  • dynamic wait depths;
  • multiple MMAs per committed group;
  • arbitrary loop CFGs;
  • nested loops;
  • dynamic trip counts;
  • F16 or TF32 variants;
  • public API changes.

Generalizing the counted-loop pipeline beyond the exact two-slot wait_group<1> shape should be handled separately.

Activity

  1. added
    enhancement
    codegen
    cuda-feature
    on Aug 17, 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

    codegencuda-featureenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions