Skip to content

[AMDGPU] Lower unsupported 16x16x128 FP8 and 32x16x128 F4 WMMAs on gfx1250-strict - #246606

Closed
yuyzhang512 wants to merge 3 commits into
llvm:mainfrom
yuyzhang512:amdgpu-strict-split-wmma-32x16x128-f4
Closed

yuyzhang512 wants to merge 3 commits into
llvm:mainfrom
yuyzhang512:amdgpu-strict-split-wmma-32x16x128-f4

Conversation

@yuyzhang512

@yuyzhang512 yuyzhang512 commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

gfx1250-strict does not support wmma.f32.16x16x128.{fp8,bf8}.{fp8,bf8} or
wmma.{,scale.,scale16.}f32.32x16x128.f4.

  • Promote the 16x16x128 FP8/BF8 WMMAs to scaled
    wmma.scale.f32.16x16x128.f8f6f4 with scale values set to 1.
  • Split each 32x16x128 F4 WMMA into two scaled
    wmma.{scale,scale16}.f32.16x16x128.f8f6f4 with FP4 operands, one for each
    16-row half of A and C/D. The 32x16 WMMA ignores the scale selects, so B
    scales always use ROW0. The unscaled variant gets scale values set to 1.

…fx1250-strict

gfx1250-strict does not support `wmma.{,scale.,scale16.}f32.32x16x128.f4`.
Split it into two scaled `wmma.{scale,scale16}.f32.16x16x128.f8f6f4` with
FP4 operands, one for each 16-row half of A and C/D. The 32x16 WMMA
ignores the scale selects, so B scales always use ROW0. The unscaled
variant gets scale values set to 1.
@llvmorg-github-actions

Copy link
Copy Markdown

@llvm/pr-subscribers-backend-amdgpu

Author: Yuyang Zhang (yuyzhang512)

Changes

gfx1250-strict does not support wmma.{,scale.,scale16.}f32.32x16x128.f4. Split it into two scaled wmma.scale,scale16}.f32.16x16x128.f8f6f4 with FP4 operands, one for each 16-row half of A and C/D. The 32x16 WMMA ignores the scale selects, so B scales always use ROW0. The unscaled variant gets scale values set to 1.


Full diff: https://github.com/llvm/llvm-project/pull/246606.diff

2 Files Affected:

  • (modified) llvm/lib/Target/AMDGPU/AMDGPULowerIntrinsics.cpp (+75)
  • (added) llvm/test/CodeGen/AMDGPU/llvm.amdgcn.wmma.32x16x128.f4.gfx1250-strict.ll (+178)
diff --git a/llvm/lib/Target/AMDGPU/AMDGPULowerIntrinsics.cpp b/llvm/lib/Target/AMDGPU/AMDGPULowerIntrinsics.cpp
index 6bd29173ecff3d..6426d9fb400746 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULowerIntrinsics.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULowerIntrinsics.cpp
@@ -46,6 +46,7 @@ class AMDGPULowerIntrinsicsImpl {
   bool visitMonitorSleep(IntrinsicInst &I);
   bool visitCvtScale(IntrinsicInst &I);
   bool visitUnscaledWMMA(IntrinsicInst &I);
+  bool visitF4WMMA(IntrinsicInst &I);
   bool visitMcastLoad(IntrinsicInst &I);
 };
 
@@ -117,6 +118,11 @@ bool AMDGPULowerIntrinsicsImpl::run() {
       forEachCall(
           F, [&](IntrinsicInst *II) { Changed |= visitUnscaledWMMA(*II); });
       break;
+    case Intrinsic::amdgcn_wmma_f32_32x16x128_f4:
+    case Intrinsic::amdgcn_wmma_scale_f32_32x16x128_f4:
+    case Intrinsic::amdgcn_wmma_scale16_f32_32x16x128_f4:
+      forEachCall(F, [&](IntrinsicInst *II) { Changed |= visitF4WMMA(*II); });
+      break;
     case Intrinsic::amdgcn_cluster_load_b32:
     case Intrinsic::amdgcn_cluster_load_b64:
     case Intrinsic::amdgcn_cluster_load_b128:
@@ -357,6 +363,75 @@ bool AMDGPULowerIntrinsicsImpl::visitUnscaledWMMA(IntrinsicInst &I) {
   return true;
 }
 
+bool AMDGPULowerIntrinsicsImpl::visitF4WMMA(IntrinsicInst &I) {
+  const GCNSubtarget &ST = TM.getSubtarget<GCNSubtarget>(*I.getFunction());
+  if (!ST.hasGFX1250_STRICT())
+    return false;
+
+  Intrinsic::ID ID = I.getIntrinsicID();
+  Intrinsic::ID NewID =
+      ID == Intrinsic::amdgcn_wmma_scale16_f32_32x16x128_f4
+          ? Intrinsic::amdgcn_wmma_scale16_f32_16x16x128_f8f6f4
+          : Intrinsic::amdgcn_wmma_scale_f32_16x16x128_f8f6f4;
+
+  IRBuilder<> B(&I);
+  Value *A = I.getArgOperand(0);
+  Value *BMat = I.getArgOperand(1);
+  Value *CMod = I.getArgOperand(2);
+  Value *C = I.getArgOperand(3);
+
+  Value *AScaleFmt, *AScale, *BScaleFmt, *BScale;
+  if (ID == Intrinsic::amdgcn_wmma_f32_32x16x128_f4) {
+    AScaleFmt = BScaleFmt = B.getInt32(AMDGPU::WMMA::MATRIX_SCALE_FMT_E8);
+    AScale = BScale = B.getInt32(0);
+  } else {
+    AScaleFmt = I.getArgOperand(5);
+    AScale = I.getArgOperand(6);
+    BScaleFmt = I.getArgOperand(8);
+    BScale = I.getArgOperand(9);
+  }
+
+  auto *ATy = cast<FixedVectorType>(A->getType());
+  auto *CTy = cast<FixedVectorType>(C->getType());
+  unsigned AHalf = ATy->getNumElements() / 2;
+  unsigned CHalf = CTy->getNumElements() / 2;
+  Type *HalfTy = FixedVectorType::get(CTy->getElementType(), CHalf);
+  Value *FP4 = B.getInt32(AMDGPU::WMMA::MATRIX_FMT_FP4);
+
+  Value *Res[2];
+  for (unsigned Half = 0; Half < 2; ++Half) {
+    Value *AH =
+        B.CreateShuffleVector(A, createSequentialMask(Half * AHalf, AHalf, 0));
+    Value *CH =
+        B.CreateShuffleVector(C, createSequentialMask(Half * CHalf, CHalf, 0));
+    Value *Args[] = {FP4,
+                     AH,
+                     FP4,
+                     BMat,
+                     CMod,
+                     CH,
+                     B.getInt32(AMDGPU::WMMA::MATRIX_SCALE_ROW0 + Half),
+                     AScaleFmt,
+                     AScale,
+                     B.getInt32(AMDGPU::WMMA::MATRIX_SCALE_ROW0),
+                     BScaleFmt,
+                     BScale,
+                     B.getFalse(),
+                     B.getFalse()};
+    CallInst *NewI = B.CreateIntrinsicWithoutFolding(HalfTy, NewID, Args);
+    NewI->copyMetadata(I);
+    Res[Half] = NewI;
+  }
+
+  Value *D = B.CreateShuffleVector(Res[0], Res[1],
+                                   createSequentialMask(0, 2 * CHalf, 0));
+  D->takeName(&I);
+  I.replaceAllUsesWith(D);
+  I.eraseFromParent();
+
+  return true;
+}
+
 // A multicast load whose workgroup mask names all 16 workgroups of a cluster
 // may never return to some of them. Clamp the mask to 0x7fff: workgroups 0-14
 // still multicast to each other, and workgroup 15 does an ordinary load (mask
diff --git a/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.wmma.32x16x128.f4.gfx1250-strict.ll b/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.wmma.32x16x128.f4.gfx1250-strict.ll
new file mode 100644
index 00000000000000..2198df8ddbb79a
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.wmma.32x16x128.f4.gfx1250-strict.ll
@@ -0,0 +1,178 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
+; RUN: llc -mtriple=amdgpu12.50 < %s | FileCheck %s --check-prefixes=GFX1250
+; RUN: llc -mtriple=amdgpu12.50s < %s | FileCheck %s --check-prefixes=GFX1250S
+
+define amdgpu_ps void @test_wmma_f32_32x16x128_f4(<16 x i32> %A, <8 x i32> %B, <16 x float> %C, ptr addrspace(1) %out) {
+; GFX1250-LABEL: test_wmma_f32_32x16x128_f4:
+; GFX1250:       ; %bb.0: ; %bb
+; GFX1250-NEXT:    s_setreg_imm32_b32 hwreg(HW_REG_WAVE_MODE, 25, 1), 1 ; msbs: dst=0 src0=0 src1=0 src2=0
+; GFX1250-NEXT:    s_mov_b64 s[64:65], 0
+; GFX1250-NEXT:    v_nop
+; GFX1250-NEXT:    global_prefetch_b8 v0, s[64:65] scope:SCOPE_SE
+; GFX1250-NEXT:    v_wmma_f32_32x16x128_f4 v[24:39], v[0:15], v[16:23], v[24:39]
+; GFX1250-NEXT:    s_clause 0x3
+; GFX1250-NEXT:    global_store_b128 v[40:41], v[36:39], off offset:48
+; GFX1250-NEXT:    global_store_b128 v[40:41], v[32:35], off offset:32
+; GFX1250-NEXT:    global_store_b128 v[40:41], v[28:31], off offset:16
+; GFX1250-NEXT:    global_store_b128 v[40:41], v[24:27], off
+; GFX1250-NEXT:    s_endpgm
+;
+; GFX1250S-LABEL: test_wmma_f32_32x16x128_f4:
+; GFX1250S:       ; %bb.0: ; %bb
+; GFX1250S-NEXT:    s_setreg_imm32_b32 hwreg(HW_REG_WAVE_MODE, 25, 1), 1 ; msbs: dst=0 src0=0 src1=0 src2=0
+; GFX1250S-NEXT:    s_mov_b64 s[64:65], 0
+; GFX1250S-NEXT:    v_nop
+; GFX1250S-NEXT:    global_prefetch_b8 v0, s[64:65] scope:SCOPE_SE
+; GFX1250S-NEXT:    v_wmma_scale_f32_16x16x128_f8f6f4 v[32:39], v[8:15], v[16:23], v[32:39], 0, 0 matrix_a_fmt:MATRIX_FMT_FP4 matrix_b_fmt:MATRIX_FMT_FP4 matrix_a_scale:MATRIX_SCALE_ROW1
+; GFX1250S-NEXT:    v_wmma_scale_f32_16x16x128_f8f6f4 v[24:31], v[0:7], v[16:23], v[24:31], 0, 0 matrix_a_fmt:MATRIX_FMT_FP4 matrix_b_fmt:MATRIX_FMT_FP4
+; GFX1250S-NEXT:    s_clause 0x3
+; GFX1250S-NEXT:    global_store_b128 v[40:41], v[36:39], off offset:48
+; GFX1250S-NEXT:    global_store_b128 v[40:41], v[32:35], off offset:32
+; GFX1250S-NEXT:    global_store_b128 v[40:41], v[28:31], off offset:16
+; GFX1250S-NEXT:    global_store_b128 v[40:41], v[24:27], off
+; GFX1250S-NEXT:    s_endpgm
+bb:
+  %res = call <16 x float> @llvm.amdgcn.wmma.f32.32x16x128.f4.v16i32.v8i32.v16f32(<16 x i32> %A, <8 x i32> %B, i16 0, <16 x float> %C)
+  store <16 x float> %res, ptr addrspace(1) %out
+  ret void
+}
+
+define amdgpu_ps void @test_wmma_f32_32x16x128_f4_negC(<16 x i32> %A, <8 x i32> %B, <16 x float> %C, ptr addrspace(1) %out) {
+; GFX1250-LABEL: test_wmma_f32_32x16x128_f4_negC:
+; GFX1250:       ; %bb.0: ; %bb
+; GFX1250-NEXT:    s_setreg_imm32_b32 hwreg(HW_REG_WAVE_MODE, 25, 1), 1 ; msbs: dst=0 src0=0 src1=0 src2=0
+; GFX1250-NEXT:    s_mov_b64 s[64:65], 0
+; GFX1250-NEXT:    v_nop
+; GFX1250-NEXT:    global_prefetch_b8 v0, s[64:65] scope:SCOPE_SE
+; GFX1250-NEXT:    v_wmma_f32_32x16x128_f4 v[24:39], v[0:15], v[16:23], v[24:39] neg_lo:[0,0,1]
+; GFX1250-NEXT:    s_clause 0x3
+; GFX1250-NEXT:    global_store_b128 v[40:41], v[36:39], off offset:48
+; GFX1250-NEXT:    global_store_b128 v[40:41], v[32:35], off offset:32
+; GFX1250-NEXT:    global_store_b128 v[40:41], v[28:31], off offset:16
+; GFX1250-NEXT:    global_store_b128 v[40:41], v[24:27], off
+; GFX1250-NEXT:    s_endpgm
+;
+; GFX1250S-LABEL: test_wmma_f32_32x16x128_f4_negC:
+; GFX1250S:       ; %bb.0: ; %bb
+; GFX1250S-NEXT:    s_setreg_imm32_b32 hwreg(HW_REG_WAVE_MODE, 25, 1), 1 ; msbs: dst=0 src0=0 src1=0 src2=0
+; GFX1250S-NEXT:    s_mov_b64 s[64:65], 0
+; GFX1250S-NEXT:    v_nop
+; GFX1250S-NEXT:    global_prefetch_b8 v0, s[64:65] scope:SCOPE_SE
+; GFX1250S-NEXT:    v_wmma_scale_f32_16x16x128_f8f6f4 v[32:39], v[8:15], v[16:23], v[32:39], 0, 0 matrix_a_fmt:MATRIX_FMT_FP4 matrix_b_fmt:MATRIX_FMT_FP4 matrix_a_scale:MATRIX_SCALE_ROW1 neg_lo:[0,0,1]
+; GFX1250S-NEXT:    v_wmma_scale_f32_16x16x128_f8f6f4 v[24:31], v[0:7], v[16:23], v[24:31], 0, 0 matrix_a_fmt:MATRIX_FMT_FP4 matrix_b_fmt:MATRIX_FMT_FP4 neg_lo:[0,0,1]
+; GFX1250S-NEXT:    s_clause 0x3
+; GFX1250S-NEXT:    global_store_b128 v[40:41], v[36:39], off offset:48
+; GFX1250S-NEXT:    global_store_b128 v[40:41], v[32:35], off offset:32
+; GFX1250S-NEXT:    global_store_b128 v[40:41], v[28:31], off offset:16
+; GFX1250S-NEXT:    global_store_b128 v[40:41], v[24:27], off
+; GFX1250S-NEXT:    s_endpgm
+bb:
+  %res = call <16 x float> @llvm.amdgcn.wmma.f32.32x16x128.f4.v16i32.v8i32.v16f32(<16 x i32> %A, <8 x i32> %B, i16 1, <16 x float> %C)
+  store <16 x float> %res, ptr addrspace(1) %out
+  ret void
+}
+
+define amdgpu_ps void @test_wmma_scale_f32_32x16x128_f4(<16 x i32> %A, <8 x i32> %B, <16 x float> %C, i32 %scale_src0, i32 %scale_src1, ptr addrspace(1) %out) {
+; GFX1250-LABEL: test_wmma_scale_f32_32x16x128_f4:
+; GFX1250:       ; %bb.0: ; %bb
+; GFX1250-NEXT:    s_setreg_imm32_b32 hwreg(HW_REG_WAVE_MODE, 25, 1), 1 ; msbs: dst=0 src0=0 src1=0 src2=0
+; GFX1250-NEXT:    s_mov_b64 s[64:65], 0
+; GFX1250-NEXT:    v_nop
+; GFX1250-NEXT:    global_prefetch_b8 v0, s[64:65] scope:SCOPE_SE
+; GFX1250-NEXT:    v_wmma_scale_f32_32x16x128_f4 v[24:39], v[0:15], v[16:23], v[24:39], v40, v41 matrix_b_scale:MATRIX_SCALE_ROW1
+; GFX1250-NEXT:    s_clause 0x3
+; GFX1250-NEXT:    global_store_b128 v[42:43], v[36:39], off offset:48
+; GFX1250-NEXT:    global_store_b128 v[42:43], v[32:35], off offset:32
+; GFX1250-NEXT:    global_store_b128 v[42:43], v[28:31], off offset:16
+; GFX1250-NEXT:    global_store_b128 v[42:43], v[24:27], off
+; GFX1250-NEXT:    s_endpgm
+;
+; GFX1250S-LABEL: test_wmma_scale_f32_32x16x128_f4:
+; GFX1250S:       ; %bb.0: ; %bb
+; GFX1250S-NEXT:    s_setreg_imm32_b32 hwreg(HW_REG_WAVE_MODE, 25, 1), 1 ; msbs: dst=0 src0=0 src1=0 src2=0
+; GFX1250S-NEXT:    s_mov_b64 s[64:65], 0
+; GFX1250S-NEXT:    v_nop
+; GFX1250S-NEXT:    global_prefetch_b8 v0, s[64:65] scope:SCOPE_SE
+; GFX1250S-NEXT:    v_wmma_scale_f32_16x16x128_f8f6f4 v[32:39], v[8:15], v[16:23], v[32:39], v40, v41 matrix_a_fmt:MATRIX_FMT_FP4 matrix_b_fmt:MATRIX_FMT_FP4 matrix_a_scale:MATRIX_SCALE_ROW1
+; GFX1250S-NEXT:    v_wmma_scale_f32_16x16x128_f8f6f4 v[24:31], v[0:7], v[16:23], v[24:31], v40, v41 matrix_a_fmt:MATRIX_FMT_FP4 matrix_b_fmt:MATRIX_FMT_FP4
+; GFX1250S-NEXT:    s_clause 0x3
+; GFX1250S-NEXT:    global_store_b128 v[42:43], v[36:39], off offset:48
+; GFX1250S-NEXT:    global_store_b128 v[42:43], v[32:35], off offset:32
+; GFX1250S-NEXT:    global_store_b128 v[42:43], v[28:31], off offset:16
+; GFX1250S-NEXT:    global_store_b128 v[42:43], v[24:27], off
+; GFX1250S-NEXT:    s_endpgm
+bb:
+  %res = call <16 x float> @llvm.amdgcn.wmma.scale.f32.32x16x128.f4.v16f32.v16i32.v8i32(<16 x i32> %A, <8 x i32> %B, i16 0, <16 x float> %C, i32 0, i32 0, i32 %scale_src0, i32 1, i32 0, i32 %scale_src1, i1 false, i1 false)
+  store <16 x float> %res, ptr addrspace(1) %out
+  ret void
+}
+
+define amdgpu_ps void @test_wmma_scale_f32_32x16x128_f4_e4m3(<16 x i32> %A, <8 x i32> %B, <16 x float> %C, i32 %scale_src0, i32 %scale_src1, ptr addrspace(1) %out) {
+; GFX1250-LABEL: test_wmma_scale_f32_32x16x128_f4_e4m3:
+; GFX1250:       ; %bb.0: ; %bb
+; GFX1250-NEXT:    s_setreg_imm32_b32 hwreg(HW_REG_WAVE_MODE, 25, 1), 1 ; msbs: dst=0 src0=0 src1=0 src2=0
+; GFX1250-NEXT:    s_mov_b64 s[64:65], 0
+; GFX1250-NEXT:    v_nop
+; GFX1250-NEXT:    global_prefetch_b8 v0, s[64:65] scope:SCOPE_SE
+; GFX1250-NEXT:    v_wmma_scale_f32_32x16x128_f4 v[24:39], v[0:15], v[16:23], v[24:39], v40, v41 matrix_a_scale_fmt:MATRIX_SCALE_FMT_E4M3 matrix_b_scale_fmt:MATRIX_SCALE_FMT_E4M3 matrix_a_reuse matrix_b_reuse
+; GFX1250-NEXT:    s_clause 0x3
+; GFX1250-NEXT:    global_store_b128 v[42:43], v[36:39], off offset:48
+; GFX1250-NEXT:    global_store_b128 v[42:43], v[32:35], off offset:32
+; GFX1250-NEXT:    global_store_b128 v[42:43], v[28:31], off offset:16
+; GFX1250-NEXT:    global_store_b128 v[42:43], v[24:27], off
+; GFX1250-NEXT:    s_endpgm
+;
+; GFX1250S-LABEL: test_wmma_scale_f32_32x16x128_f4_e4m3:
+; GFX1250S:       ; %bb.0: ; %bb
+; GFX1250S-NEXT:    s_setreg_imm32_b32 hwreg(HW_REG_WAVE_MODE, 25, 1), 1 ; msbs: dst=0 src0=0 src1=0 src2=0
+; GFX1250S-NEXT:    s_mov_b64 s[64:65], 0
+; GFX1250S-NEXT:    v_nop
+; GFX1250S-NEXT:    global_prefetch_b8 v0, s[64:65] scope:SCOPE_SE
+; GFX1250S-NEXT:    v_wmma_scale_f32_16x16x128_f8f6f4 v[32:39], v[8:15], v[16:23], v[32:39], v40, v41 matrix_a_fmt:MATRIX_FMT_FP4 matrix_b_fmt:MATRIX_FMT_FP4 matrix_a_scale:MATRIX_SCALE_ROW1 matrix_a_scale_fmt:MATRIX_SCALE_FMT_E4M3 matrix_b_scale_fmt:MATRIX_SCALE_FMT_E4M3
+; GFX1250S-NEXT:    v_wmma_scale_f32_16x16x128_f8f6f4 v[24:31], v[0:7], v[16:23], v[24:31], v40, v41 matrix_a_fmt:MATRIX_FMT_FP4 matrix_b_fmt:MATRIX_FMT_FP4 matrix_a_scale_fmt:MATRIX_SCALE_FMT_E4M3 matrix_b_scale_fmt:MATRIX_SCALE_FMT_E4M3
+; GFX1250S-NEXT:    s_clause 0x3
+; GFX1250S-NEXT:    global_store_b128 v[42:43], v[36:39], off offset:48
+; GFX1250S-NEXT:    global_store_b128 v[42:43], v[32:35], off offset:32
+; GFX1250S-NEXT:    global_store_b128 v[42:43], v[28:31], off offset:16
+; GFX1250S-NEXT:    global_store_b128 v[42:43], v[24:27], off
+; GFX1250S-NEXT:    s_endpgm
+bb:
+  %res = call <16 x float> @llvm.amdgcn.wmma.scale.f32.32x16x128.f4.v16f32.v16i32.v8i32(<16 x i32> %A, <8 x i32> %B, i16 0, <16 x float> %C, i32 0, i32 2, i32 %scale_src0, i32 0, i32 2, i32 %scale_src1, i1 true, i1 true)
+  store <16 x float> %res, ptr addrspace(1) %out
+  ret void
+}
+
+define amdgpu_ps void @test_wmma_scale16_f32_32x16x128_f4(<16 x i32> %A, <8 x i32> %B, <16 x float> %C, i64 %scale_src0, i64 %scale_src1, ptr addrspace(1) %out) {
+; GFX1250-LABEL: test_wmma_scale16_f32_32x16x128_f4:
+; GFX1250:       ; %bb.0: ; %bb
+; GFX1250-NEXT:    s_setreg_imm32_b32 hwreg(HW_REG_WAVE_MODE, 25, 1), 1 ; msbs: dst=0 src0=0 src1=0 src2=0
+; GFX1250-NEXT:    s_mov_b64 s[64:65], 0
+; GFX1250-NEXT:    v_nop
+; GFX1250-NEXT:    global_prefetch_b8 v0, s[64:65] scope:SCOPE_SE
+; GFX1250-NEXT:    v_wmma_scale16_f32_32x16x128_f4 v[24:39], v[0:15], v[16:23], v[24:39], v[40:41], v[42:43] matrix_b_scale:MATRIX_SCALE_ROW1
+; GFX1250-NEXT:    s_clause 0x3
+; GFX1250-NEXT:    global_store_b128 v[44:45], v[36:39], off offset:48
+; GFX1250-NEXT:    global_store_b128 v[44:45], v[32:35], off offset:32
+; GFX1250-NEXT:    global_store_b128 v[44:45], v[28:31], off offset:16
+; GFX1250-NEXT:    global_store_b128 v[44:45], v[24:27], off
+; GFX1250-NEXT:    s_endpgm
+;
+; GFX1250S-LABEL: test_wmma_scale16_f32_32x16x128_f4:
+; GFX1250S:       ; %bb.0: ; %bb
+; GFX1250S-NEXT:    s_setreg_imm32_b32 hwreg(HW_REG_WAVE_MODE, 25, 1), 1 ; msbs: dst=0 src0=0 src1=0 src2=0
+; GFX1250S-NEXT:    s_mov_b64 s[64:65], 0
+; GFX1250S-NEXT:    v_nop
+; GFX1250S-NEXT:    global_prefetch_b8 v0, s[64:65] scope:SCOPE_SE
+; GFX1250S-NEXT:    v_wmma_scale16_f32_16x16x128_f8f6f4 v[32:39], v[8:15], v[16:23], v[32:39], v[40:41], v[42:43] matrix_a_fmt:MATRIX_FMT_FP4 matrix_b_fmt:MATRIX_FMT_FP4 matrix_a_scale:MATRIX_SCALE_ROW1
+; GFX1250S-NEXT:    v_wmma_scale16_f32_16x16x128_f8f6f4 v[24:31], v[0:7], v[16:23], v[24:31], v[40:41], v[42:43] matrix_a_fmt:MATRIX_FMT_FP4 matrix_b_fmt:MATRIX_FMT_FP4
+; GFX1250S-NEXT:    s_clause 0x3
+; GFX1250S-NEXT:    global_store_b128 v[44:45], v[36:39], off offset:48
+; GFX1250S-NEXT:    global_store_b128 v[44:45], v[32:35], off offset:32
+; GFX1250S-NEXT:    global_store_b128 v[44:45], v[28:31], off offset:16
+; GFX1250S-NEXT:    global_store_b128 v[44:45], v[24:27], off
+; GFX1250S-NEXT:    s_endpgm
+bb:
+  %res = call <16 x float> @llvm.amdgcn.wmma.scale16.f32.32x16x128.f4.v16f32.v16i32.v8i32(<16 x i32> %A, <8 x i32> %B, i16 0, <16 x float> %C, i32 0, i32 0, i64 %scale_src0, i32 1, i32 0, i64 %scale_src1, i1 false, i1 false)
+  store <16 x float> %res, ptr addrspace(1) %out
+  ret void
+}

@shiltian shiltian left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the target doesn't support the instruction, the intrinsic should not be supported. Use a feature guard on the intrinsic instead such that they can't be used by users.

…gfx1250-strict

gfx1250-strict does not support `wmma.f32.16x16x128.{fp8,bf8}.{fp8,bf8}`.
Promote it to scaled WMMA with scale values set to 1.
@yuyzhang512 yuyzhang512 changed the title [AMDGPU] Split 32x16x128 F4 WMMA into two 16x16x128 F8F6F4 WMMAs on gfx1250-strict [AMDGPU] Lower unsupported 16x16x128 FP8 and 32x16x128 F4 WMMAs on gfx1250-strict Nov 30, 2026
@yuyzhang512

yuyzhang512 commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor Author

If the target doesn't support the instruction, the intrinsic should not be supported. Use a feature guard on the intrinsic instead such that they can't be used by users.

Thanks for the review. Without a workaround in the compiler, kernel writers like FlyDSL and Gluon have to keep a separate strict version of every kernel that uses these, which is a lot of extra work. aiter#8527 ran into exactly this with the FlyDSL fp4 MoE kernels and ended up falling back to fp8 activations.

The rewrite doesn't change semantics. It's the same thing #230253 already does for wmma_f32_16x16x128_f8f6f4 on strict. I also checked the f4 split against the native 32x16 instruction on the functional model and got bit-exact results.

So I think it's fine to expand them here for convenience. What do you think?

@shiltian

shiltian commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

No. WMMA intrinsics are very specific. The backend should not do the heavy lifting of lowering them to different instructions depending on whether the HW supports them or not. This is a no-go approach.

CC @scchan @rampitec

@yuyzhang512

Copy link
Copy Markdown
Contributor Author

No. WMMA intrinsics are very specific. The backend should not do the heavy lifting of lowering them to different instructions depending on whether the HW supports them or not. This is a no-go approach.

CC @scchan @rampitec

Thanks for explaining. I'll close this PR.

zufayu pushed a commit to ROCm/aiter that referenced this pull request Dec 3, 2026
…250-strict (#9058)

gfx1250-strict (MI450 A0 errata) has no wmma-f4-insts. The fp4-activation
grouped TDM GEMM emits v_wmma_scale_f32_32x16x128_f4, which LLVM drops on that
target after printing "requires target feature 'wmma-f4-insts'", leaving a
kernel without the matmul (NaN output, #8527).

When the FlyDSL target is gfx1250-strict, emit each 32x16x128 f4 WMMA as two
v_wmma_scale_f32_16x16x128_f8f6f4 with FP4 operands, one per 16-row half of
the weight operand and the accumulator, following the lowering proposed in
llvm/llvm-project#246606. The weight scale VGPR is shared, with ROW0/ROW1
selecting each half. The activation scale select stays wm % 2; forcing ROW0
as the LLVM lowering does reads the wrong lanes for odd wm (rel_l2 6.4e-2 vs
2.7e-3 with per-token-varying scales on A0).

This replaces the NotImplementedError guard from #8670. The plain gfx1250
target is unchanged (same 32x16x128 f4 instructions, bit-identical results).

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants