Skip to content

Support deferred accumulator lowering for BF16 WGMMA m64n64k16 #597

Closed

Description

@uurl

Problem

The public WGMMA API exposes:

wgmma_mma_m64n64k16_f32_bf16(
    acc: &mut [[f32; 8]; 4],
    desc_a: u64,
    desc_b: u64,
)

However, this operation cannot be lowered safely as an isolated pointer-based MMA call.

Each thread owns 32 f32 accumulator elements. Those values must remain in registers across the asynchronous WGMMA sequence:

wgmma.fence
one or more wgmma.mma_async instructions
wgmma.commit_group
wgmma.wait_group 0

Loading and storing the accumulator around each individual MMA call would violate the WGMMA lifetime contract because the updated values are not available until the corresponding wait completes.

The current fail-closed behavior therefore rejects BF16 WGMMA MMA calls instead of generating incorrect PTX.

Proposed solution

Add a deferred-accumulator lowering path for:

wgmma.mma_async.sync.aligned.m64n64k16.f32.bf16.bf16

The compiler should:

  1. Import BF16 WGMMA MMA calls as pointer-form dialect operations.

  2. Recognize a complete statically linear sequence consisting of:

    • one wgmma_fence;
    • one or more BF16 MMA calls using the same accumulator;
    • exactly one wgmma_commit_group;
    • one wgmma_wait_group::<0>.
  3. Replace the sequence with a deferred WGMMA group operation.

  4. Lower the group into one convergent inline-PTX scope that:

    • loads all 32 accumulator values;
    • emits the fence;
    • emits all MMA instructions;
    • commits the group;
    • waits for group zero;
    • stores the accumulator only after the wait.

Initial scope

The initial implementation should support only:

m64n64k16.f32.bf16.bf16

The sequence must satisfy all of the following:

  • all operations form one straight-line control-flow chain;
  • every MMA uses the same accumulator;
  • the accumulator is a mutable generic MIR pointer;
  • both descriptors are unsigned u64 values;
  • exactly one commit operation is present;
  • the sequence ends with wait_group<0>;
  • no unsupported operation appears between the fence and wait.

The implementation should reject:

  • F16 and TF32 MMA variants;
  • partial waits;
  • multiple accumulator objects;
  • multiple commits;
  • MMA instructions after the commit;
  • nested fences;
  • branches and control-flow joins;
  • loops;
  • incomplete fence/MMA/commit/wait sequences;
  • malformed operation shapes or descriptor types.

Acceptance criteria

  • A valid BF16 sequence is fused before final MIR-to-LLVM lowering.
  • The generated group lowers to one convergent inline-PTX scope.
  • All accumulator loads occur before the WGMMA instructions.
  • All accumulator stores occur after wgmma.wait_group.sync.aligned 0.
  • Multiple MMA instructions using the same accumulator are supported within one group.
  • Unsupported or malformed sequences fail with structured compiler errors rather than panics.
  • F16 and TF32 entry points remain fail-closed.
  • Pointer-form and deferred-group verifiers enforce exact operand, result, pointer and descriptor contracts.
  • A compile-only sm_90a example exercises the supported BF16 path.
  • Dialect, lowering, codegen and WGMMA smoketests pass.

Hardware note

Functional execution requires a Hopper sm_90a GPU and valid shared-memory descriptors.

A compile-only example may use zero descriptors to validate compiler lowering and PTX generation, but that kernel must not be launched.

Activity

  1. added
    enhancement
    cuda-feature
    IR-lowering
    on Jul 31, 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

    IR-loweringcuda-featureenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions