Skip to content

[AMDGPU] Promote wmma_f32_16x16x128_f8f6f4 to scaled version on gfx1250-strict - #230253

Merged
rampitec merged 1 commit into
mainfrom
users/rampitec/promote-wmma-scale
Oct 9, 2026
Merged

rampitec merged 1 commit into
mainfrom
users/rampitec/promote-wmma-scale

Conversation

@rampitec

@rampitec rampitec commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Added scale factor is 0 which does not change the result. "0" is a special value that maps to the exponent "1.0" when passed as a constant.

@rampitec

rampitec commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by sgh.

…50-strict

Added scale factor is 0 which does not change the result.
@rampitec
rampitec force-pushed the users/rampitec/promote-wmma-scale branch from e12d04f to 965d5cb Compare October 8, 2026 19:32
@rampitec
rampitec requested review from arsenm and scchan October 8, 2026 19:33
@rampitec
rampitec marked this pull request as ready for review October 8, 2026 19:33
@llvmorg-github-actions

Copy link
Copy Markdown

@llvm/pr-subscribers-backend-amdgpu

Author: Stanislav Mekhanoshin (rampitec)

Changes

Added scale factor is 0 which does not change the result.


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

2 Files Affected:

  • (modified) llvm/lib/Target/AMDGPU/AMDGPULowerIntrinsics.cpp (+37)
  • (added) llvm/test/CodeGen/AMDGPU/llvm.amdgcn.wmma.f8f6f4.gfx1250.ll (+35)
diff --git a/llvm/lib/Target/AMDGPU/AMDGPULowerIntrinsics.cpp b/llvm/lib/Target/AMDGPU/AMDGPULowerIntrinsics.cpp
index af87810692990..e8c42bd05753d 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULowerIntrinsics.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULowerIntrinsics.cpp
@@ -42,6 +42,7 @@ class AMDGPULowerIntrinsicsImpl {
   bool visitPtrSBufferLoad(IntrinsicInst &I);
   bool visitMonitorSleep(IntrinsicInst &I);
   bool visitCvtScale(IntrinsicInst &I);
+  bool visitUnscaledWMMA(IntrinsicInst &I);
 };
 
 class AMDGPULowerIntrinsicsLegacy : public ModulePass {
@@ -105,6 +106,10 @@ bool AMDGPULowerIntrinsicsImpl::run() {
     case Intrinsic::amdgcn_cvt_scale_pk16_f32_bf6:
       forEachCall(F, [&](IntrinsicInst *II) { Changed |= visitCvtScale(*II); });
       break;
+    case Intrinsic::amdgcn_wmma_f32_16x16x128_f8f6f4:
+      forEachCall(
+          F, [&](IntrinsicInst *II) { Changed |= visitUnscaledWMMA(*II); });
+      break;
     }
   }
 
@@ -302,6 +307,38 @@ bool AMDGPULowerIntrinsicsImpl::visitCvtScale(IntrinsicInst &I) {
   return false;
 }
 
+bool AMDGPULowerIntrinsicsImpl::visitUnscaledWMMA(IntrinsicInst &I) {
+  assert(I.getIntrinsicID() == Intrinsic::amdgcn_wmma_f32_16x16x128_f8f6f4);
+
+  const GCNSubtarget &ST = TM.getSubtarget<GCNSubtarget>(*I.getFunction());
+  if (!ST.hasGFX1250_STRICT())
+    return false;
+
+  IRBuilder<> B(&I);
+
+  // Convert unscaled WMMA into a scaled version with scale factors 0.
+  SmallVector<Value *, 14> Args(I.args());
+  Args.push_back(B.getInt32(0)); // matrix_a_scale
+  Args.push_back(
+      B.getInt32(AMDGPU::WMMA::MATRIX_SCALE_FMT_E8)); // matrix_a_scale_fmt
+  Args.push_back(B.getInt32(0)); // matrix a scale exponential
+  Args.push_back(B.getInt32(0)); // matrix_b_scale
+  Args.push_back(
+      B.getInt32(AMDGPU::WMMA::MATRIX_SCALE_FMT_E8)); // matrix_b_scale_fmt
+  Args.push_back(B.getInt32(0)); // matrix b scale exponential
+  Args.push_back(B.getInt1(0));  // matrix_a_reuse
+  Args.push_back(B.getInt1(0));  // matrix_b_reuse
+
+  CallInst *NewI = B.CreateIntrinsicWithoutFolding(
+      I.getType(), Intrinsic::amdgcn_wmma_scale_f32_16x16x128_f8f6f4, Args);
+  I.replaceAllUsesWith(NewI);
+  NewI->copyMetadata(I);
+  NewI->takeName(&I);
+  I.eraseFromParent();
+
+  return true;
+}
+
 PreservedAnalyses AMDGPULowerIntrinsicsPass::run(Module &M,
                                                  ModuleAnalysisManager &MAM) {
   AMDGPULowerIntrinsicsImpl Impl(M, TM);
diff --git a/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.wmma.f8f6f4.gfx1250.ll b/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.wmma.f8f6f4.gfx1250.ll
new file mode 100644
index 0000000000000..5b9373dfb55d7
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.wmma.f8f6f4.gfx1250.ll
@@ -0,0 +1,35 @@
+; 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_16x16x128_f8f6f4(<16 x i32> %A, <16 x i32> %B, <8 x float> %C, ptr addrspace(1) %out) {
+; GFX1250-LABEL: test_wmma_f32_16x16x128_f8f6f4:
+; 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_16x16x128_f8f6f4 v[32:39], v[0:15], v[16:31], v[32:39] matrix_a_fmt:MATRIX_FMT_BF8 matrix_b_fmt:MATRIX_FMT_FP6
+; GFX1250-NEXT:    s_clause 0x1
+; GFX1250-NEXT:    global_store_b128 v[40:41], v[36:39], off offset:16
+; GFX1250-NEXT:    global_store_b128 v[40:41], v[32:35], off
+; GFX1250-NEXT:    s_endpgm
+;
+; GFX1250S-LABEL: test_wmma_f32_16x16x128_f8f6f4:
+; 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[0:15], v[16:31], v[32:39], 0, 0 matrix_a_fmt:MATRIX_FMT_BF8 matrix_b_fmt:MATRIX_FMT_FP6
+; GFX1250S-NEXT:    s_clause 0x1
+; GFX1250S-NEXT:    global_store_b128 v[40:41], v[36:39], off offset:16
+; GFX1250S-NEXT:    global_store_b128 v[40:41], v[32:35], off
+; GFX1250S-NEXT:    s_endpgm
+bb:
+  %res = call <8 x float> @llvm.amdgcn.wmma.f32.16x16x128.f8f6f4.v8f32.v16i32.v16i32(i32 1, <16 x i32> %A, i32 2, <16 x i32> %B, i16 0, <8 x float> %C)
+  store <8 x float> %res, ptr addrspace(1) %out
+  ret void
+}
+
+declare <8 x float> @llvm.amdgcn.wmma.f32.16x16x128.f8f6f4.v8f32.v16i32.v16i32(i32, <16 x i32>, i32, <16 x i32>, i16, <8 x float>)

@krzysz00 krzysz00 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.

Approved with documentation request

Args.push_back(B.getInt32(0)); // matrix_a_scale
Args.push_back(
B.getInt32(AMDGPU::WMMA::MATRIX_SCALE_FMT_E8)); // matrix_a_scale_fmt
Args.push_back(B.getInt32(0)); // matrix a scale exponential

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.

I'd like to flag - and this is a note for the PR description too or a comment, because of how this has bit people before - "0" mere is a special value that maps to the exponent "1.0" ... and only when passed as a constant.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated PR description.

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.

Though this is now reminding me that the scale conversion intrinsics really should've been duplicated - one for vgpr inputs, one for constant/sgpr inputs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

AFAIR we have disabled constant inputs?

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.

Yeah, we did, but I figure there's an argument for exposing them - that's not this PR, though

@rampitec rampitec Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Surely not this, but back then I made a question: is a uniform value useful on practice? And I've got no answer.

@rampitec
rampitec merged commit c0a1a2c into main Oct 9, 2026
17 of 18 checks passed
@rampitec
rampitec deleted the users/rampitec/promote-wmma-scale branch October 9, 2026 05:35
ram-NK pushed a commit to ram-NK/llvm-project that referenced this pull request Oct 14, 2026
…50-strict (llvm#230253)

Added scale factor is 0 which does not change the result. "0" is a
special value that maps to the exponent "1.0" when passed as a constant.
MazenEwiss pushed a commit to MazenEwiss/llvm-project that referenced this pull request Oct 14, 2026
…50-strict (llvm#230253)

Added scale factor is 0 which does not change the result. "0" is a
special value that maps to the exponent "1.0" when passed as a constant.
afagaj added a commit to ROCm/rocm-libraries that referenced this pull request Nov 26, 2026
… WMMA fallback

The gfx1250-strict fallback called __builtin_amdgcn_wmma_f32_16x16x128_f8f6f4.
On gfx1250-strict LLVM rewrites that to the scaled instruction with a scale
of 0 (llvm/llvm-project#230253), which means 1.0 only as an inline constant.
At -O0 the 0 is placed in a VGPR, where E8M0 0 is 2^-127, so the WMMA
returned C instead of A*B + C.

Call __builtin_amdgcn_wmma_scale_f32_16x16x128_f8f6f4 directly with an E8M0
scale of 1.0 (0x7F7F7F7F) for A and B. This is correct at every optimization
level and also passes the matrix reuse hints through on gfx1250-strict.

Tests:
- test_amdgcn_mma_layout_gfx1250_f8_o0 (CK Tile) and
  test_wmma_op_f8_16x16x128_o0 (CK) run the existing FP8/BF8 16x16x128
  runtime checks again at -O0.

Also name both instructions in the instruction_name strings of the eight
CK Tile ops, and describe the strict path accurately in comments and in
CHANGELOG.md.

JIRA ID : ROCM-35020

Co-Authored-By: Claude Opus 5.5 <[email protected]>
afagaj added a commit to ROCm/rocm-libraries that referenced this pull request Dec 2, 2026
)

## Motivation

The CK build fails for `gfx1250-strict` with current compilers:

```
ck_tile/core/arch/mma/wmma/wmma_gfx12.hpp:1027:17: error: '__builtin_amdgcn_wmma_f32_16x16x128_fp8_fp8'
needs target feature wmma-16x16x128fp8-insts,wavefrontsize32
```

gfx1250-strict (A0) has no
`V_WMMA_F{16,32}_16X16X128_{FP8,BF8}_{FP8,BF8}`. LLVM now gates those 8
builtins on `wmma-16x16x128fp8-insts`, which only gfx1250 has:
llvm/llvm-project#228564, re-landed as llvm/llvm-project#229044
(LCOMPILER-2899). CK and CK Tile guard the 20 call sites with
`__gfx125__`, which also covers gfx1250-strict. Older compilers accepted
the builtins on strict and emitted instructions that A0 does not
support.

JIRA ID : ROCM-35020

## Technical Details

All 20 call sites now go through one helper per library:

| Library | Helper | Call sites |
|---|---|---|
| CK Tile | `wmma_{f32,f16}_16x16x128_f8` in
`ck_tile/core/arch/mma/wmma/wmma_gfx1250_f8_16x16x128.hpp` (new) |
`wmma_gfx12.hpp` (8), `warp_gemm_attribute_wmma_impl_8bit_traits.hpp`
(4) |
| CK | `wmma_{f32,f16}_16x16x128_f8_gfx125` in `ck/utility/amd_wmma.hpp`
| `amd_wmma.hpp` (8) |

- **gfx1250, gfx1251:** unchanged. The helpers emit the native builtins,
and the warp GEMM traits keep their `reuse_a` / `reuse_b` flags. gfx1250
ISA is identical before and after.
- **gfx1250-strict, f32 output:**
`__builtin_amdgcn_wmma_scale_f32_16x16x128_f8f6f4` with the FP8 (0) /
BF8 (1) format flags and an explicit E8M0 scale of 1.0 (`0x7F7F7F7F`)
for A and B, plus the reuse hints. It reads A and B in the same register
layout as the native instructions.
- Why not the unscaled `__builtin_amdgcn_wmma_f32_16x16x128_f8f6f4`: on
gfx1250-strict LLVM rewrites it to the scaled instruction with a scale
of 0 (llvm/llvm-project#230253). 0 means 1.0 only as an inline constant.
At -O0 it is placed in a VGPR, where E8M0 0 is 2^-127, and the result is
C instead of A*B + C. An explicit 1.0 is correct at every optimization
level.
- **gfx1250-strict, f16 output:** F8F6F4 has no f16-output form, so the
helper converts C to f32, runs the f32 path, and rounds once to f16.
Cost per f16 WMMA on strict: 8 `v_cvt_f32_f16` and 4 `v_cvt_pk_f16_f32`,
and C takes 8 VGPRs instead of 4.
- The op types (`amdgcn_mma` specializations, `WmmaTraits`) do not
change, so host and device passes still select the same MmaOp (see the
comment at the top of the GFX1250 section in `wmma_gfx12.hpp`). The
`instruction_name` strings of the eight CK Tile ops now name both
instructions.

**Tests** (CK and CK Tile tested separately; they do not depend on each
other):

| Test | Library | What |
|---|---|---|
| `test_ck_tile_wmma_f8_16x16x128_gfx125` | CK Tile | compile-only, 12
call sites, every gfx125 target the compiler supports, whatever
`GPU_TARGETS` is |
| `test_ck_wmma_f8_16x16x128_gfx125` | CK | compile-only, 8 call sites,
same |
| `test_wmma_op_f8_16x16x128_o0` | CK | the existing runtime check
against a CPU reference (`test_wmma_op`, 16x16x128 cases), built at -O0
|

CK CI's daily gfx1250-strict build only builds the MIOpen and hipTensor
instance libraries, not tests.

## Test Plan

1. Device-compile all 20 wrappers for gfx1250 and gfx1250-strict with
ROCm LLVM `d196b6e0be62` (TheRock Multi-Arch CI run
[45807908974](https://github.com/ROCm/TheRock/actions/runs/45807908974)),
with `develop` and with this PR, at -O0 and -O3.
2. CK CMake build with `-DGPU_TARGETS=gfx1250-strict` and the same
compiler: all three new tests plus `test_amdgcn_mma_layout_gfx1250`,
`test_tile_gemm_quant_pipelines_gfx1250` and `test_wmma_op`.
3. Runtime on the rocJITsu gfx1250 emulator (B0 model). The emulator
cannot run gfx1250-strict code objects, so the strict path was forced on
in a scratch copy of each helper and built for gfx1250:
- the strict path vs the native instruction, at -O0 and -O3, all 4 A/B
type pairs, on narrow-exponent data (every f32 sum exact) and on
full-range finite data; and, for comparison, the unscaled F8F6F4 builtin
as LLVM lowers it on strict (scale 0);
- `test_wmma_op_f8_16x16x128_o0` with the strict path forced on, using
the explicit 1.0 scale and using a scale of 0, to show that the -O0 test
detects a wrong scale.

## Test Result

1. With `develop`, gfx1250-strict fails with 20 errors (one per call
site) and gfx1250 passes. With this PR, both pass at -O0 and -O3.
gfx1250-strict emits only `v_wmma_scale_f32_16x16x128_f8f6f4`, always
with the 1.0 scale.
2. All targets build. Against the `develop` headers, the compile-only CK
Tile test fails with 12 errors and the CK test with 8.
3. Emulator:

   | Strict path, vs native | Narrow-exponent data | Full-range data |
   |---|---|---|
| explicit scale 1.0 (this PR), -O0 and -O3 | f32 and f16 bit-identical
| f16 bit-identical; f32 differs in 157-193 of 256 elements per pair,
max relative difference 4.8e-5 |
| unscaled builtin (LLVM promotes it with scale 0), -O3 | bit-identical
| same as explicit scale 1.0 |
| unscaled builtin (LLVM promotes it with scale 0), -O0 | all 256
outputs wrong, every output equals C | not measured |

The full-range f32 difference is far below FP8/BF8 input precision. The
emulator models B0, so this does not prove A0 behaviour.

`test_wmma_op_f8_16x16x128_o0` with the strict path forced on: 8/8 pass
with the explicit 1.0 scale; 8/8 fail with a scale of 0.

4. A0 hardware (gfx1250-strict): one scaled F8F6F4 WMMA with the scale 0
or 1.0, as a literal and as a runtime value, at -O0 and -O3. A scale of
0 gives C whenever it is in a register (literal at -O0, runtime value at
both levels); 1.0 is correct in every case. Reproducer and output in the
review thread.

Not covered: CK itself on A0 hardware, and the full CK test suite on
gfx1250-strict.

Separately, the LLVM rewrite in llvm/llvm-project#230253 should not
depend on the scale staying an inline constant; that is a compiler
issue, to be reported to LLVM separately.

## Submission Checklist

- [x] Look over the contributing guidelines at
https://github.com/ROCm/TheRock/blob/main/GOVERNANCE.md#pull-requests.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
assistant-librarian Bot pushed a commit to ROCm/composable_kernel that referenced this pull request Dec 2, 2026
fix(ck,ck_tile): build FP8/BF8 16x16x128 WMMA for
 gfx1250-strict (#16834)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

## Motivation

The CK build fails for `gfx1250-strict` with current compilers:

```
ck_tile/core/arch/mma/wmma/wmma_gfx12.hpp:1027:17: error: '__builtin_amdgcn_wmma_f32_16x16x128_fp8_fp8'
needs target feature wmma-16x16x128fp8-insts,wavefrontsize32
```

gfx1250-strict (A0) has no
`V_WMMA_F{16,32}_16X16X128_{FP8,BF8}_{FP8,BF8}`. LLVM now gates those 8
builtins on `wmma-16x16x128fp8-insts`, which only gfx1250 has:
llvm/llvm-project#228564, re-landed as llvm/llvm-project#229044
(LCOMPILER-2899). CK and CK Tile guard the 20 call sites with
`__gfx125__`, which also covers gfx1250-strict. Older compilers accepted
the builtins on strict and emitted instructions that A0 does not
support.

JIRA ID : ROCM-35020

## Technical Details

All 20 call sites now go through one helper per library:

| Library | Helper | Call sites |
|---|---|---|
| CK Tile | `wmma_{f32,f16}_16x16x128_f8` in
`ck_tile/core/arch/mma/wmma/wmma_gfx1250_f8_16x16x128.hpp` (new) |
`wmma_gfx12.hpp` (8), `warp_gemm_attribute_wmma_impl_8bit_traits.hpp`
(4) |
| CK | `wmma_{f32,f16}_16x16x128_f8_gfx125` in `ck/utility/amd_wmma.hpp`
| `amd_wmma.hpp` (8) |

- **gfx1250, gfx1251:** unchanged. The helpers emit the native builtins,
and the warp GEMM traits keep their `reuse_a` / `reuse_b` flags. gfx1250
ISA is identical before and after.
- **gfx1250-strict, f32 output:**
`__builtin_amdgcn_wmma_scale_f32_16x16x128_f8f6f4` with the FP8 (0) /
BF8 (1) format flags and an explicit E8M0 scale of 1.0 (`0x7F7F7F7F`)
for A and B, plus the reuse hints. It reads A and B in the same register
layout as the native instructions.
- Why not the unscaled `__builtin_amdgcn_wmma_f32_16x16x128_f8f6f4`: on
gfx1250-strict LLVM rewrites it to the scaled instruction with a scale
of 0 (llvm/llvm-project#230253). 0 means 1.0 only as an inline constant.
At -O0 it is placed in a VGPR, where E8M0 0 is 2^-127, and the result is
C instead of A*B + C. An explicit 1.0 is correct at every optimization
level.
- **gfx1250-strict, f16 output:** F8F6F4 has no f16-output form, so the
helper converts C to f32, runs the f32 path, and rounds once to f16.
Cost per f16 WMMA on strict: 8 `v_cvt_f32_f16` and 4 `v_cvt_pk_f16_f32`,
and C takes 8 VGPRs instead of 4.
- The op types (`amdgcn_mma` specializations, `WmmaTraits`) do not
change, so host and device passes still select the same MmaOp (see the
comment at the top of the GFX1250 section in `wmma_gfx12.hpp`). The
`instruction_name` strings of the eight CK Tile ops now name both
instructions.

**Tests** (CK and CK Tile tested separately; they do not depend on each
other):

| Test | Library | What |
|---|---|---|
| `test_ck_tile_wmma_f8_16x16x128_gfx125` | CK Tile | compile-only, 12
call sites, every gfx125 target the compiler supports, whatever
`GPU_TARGETS` is |
| `test_ck_wmma_f8_16x16x128_gfx125` | CK | compile-only, 8 call sites,
same |
| `test_wmma_op_f8_16x16x128_o0` | CK | the existing runtime check
against a CPU reference (`test_wmma_op`, 16x16x128 cases), built at -O0
|

CK CI's daily gfx1250-strict build only builds the MIOpen and hipTensor
instance libraries, not tests.

## Test Plan

1. Device-compile all 20 wrappers for gfx1250 and gfx1250-strict with
ROCm LLVM `d196b6e0be62` (TheRock Multi-Arch CI run
[45807908974](https://github.com/ROCm/TheRock/actions/runs/45807908974)),
with `develop` and with this PR, at -O0 and -O3.
2. CK CMake build with `-DGPU_TARGETS=gfx1250-strict` and the same
compiler: all three new tests plus `test_amdgcn_mma_layout_gfx1250`,
`test_tile_gemm_quant_pipelines_gfx1250` and `test_wmma_op`.
3. Runtime on the rocJITsu gfx1250 emulator (B0 model). The emulator
cannot run gfx1250-strict code objects, so the strict path was forced on
in a scratch copy of each helper and built for gfx1250:
- the strict path vs the native instruction, at -O0 and -O3, all 4 A/B
type pairs, on narrow-exponent data (every f32 sum exact) and on
full-range finite data; and, for comparison, the unscaled F8F6F4 builtin
as LLVM lowers it on strict (scale 0);
- `test_wmma_op_f8_16x16x128_o0` with the strict path forced on, using
the explicit 1.0 scale and using a scale of 0, to show that the -O0 test
detects a wrong scale.

## Test Result

1. With `develop`, gfx1250-strict fails with 20 errors (one per call
site) and gfx1250 passes. With this PR, both pass at -O0 and -O3.
gfx1250-strict emits only `v_wmma_scale_f32_16x16x128_f8f6f4`, always
with the 1.0 scale.
2. All targets build. Against the `develop` headers, the compile-only CK
Tile test fails with 12 errors and the CK test with 8.
3. Emulator:

   | Strict path, vs native | Narrow-exponent data | Full-range data |
   |---|---|---|
| explicit scale 1.0 (this PR), -O0 and -O3 | f32 and f16 bit-identical
| f16 bit-identical; f32 differs in 157-193 of 256 elements per pair,
max relative difference 4.8e-5 |
| unscaled builtin (LLVM promotes it with scale 0), -O3 | bit-identical
| same as explicit scale 1.0 |
| unscaled builtin (LLVM promotes it with scale 0), -O0 | all 256
outputs wrong, every output equals C | not measured |

The full-range f32 difference is far below FP8/BF8 input precision. The
emulator models B0, so this does not prove A0 behaviour.

`test_wmma_op_f8_16x16x128_o0` with the strict path forced on: 8/8 pass
with the explicit 1.0 scale; 8/8 fail with a scale of 0.

4. A0 hardware (gfx1250-strict): one scaled F8F6F4 WMMA with the scale 0
or 1.0, as a literal and as a runtime value, at -O0 and -O3. A scale of
0 gives C whenever it is in a register (literal at -O0, runtime value at
both levels); 1.0 is correct in every case. Reproducer and output in the
review thread.

Not covered: CK itself on A0 hardware, and the full CK test suite on
gfx1250-strict.

Separately, the LLVM rewrite in llvm/llvm-project#230253 should not
depend on the scale staying an inline constant; that is a compiler
issue, to be reported to LLVM separately.

## Submission Checklist

- [x] Look over the contributing guidelines at
https://github.com/ROCm/TheRock/blob/main/GOVERNANCE.md#pull-requests.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
JiaLuo-CAN pushed a commit to ROCm/rocm-libraries that referenced this pull request Dec 2, 2026
)

## Motivation

The CK build fails for `gfx1250-strict` with current compilers:

```
ck_tile/core/arch/mma/wmma/wmma_gfx12.hpp:1027:17: error: '__builtin_amdgcn_wmma_f32_16x16x128_fp8_fp8'
needs target feature wmma-16x16x128fp8-insts,wavefrontsize32
```

gfx1250-strict (A0) has no
`V_WMMA_F{16,32}_16X16X128_{FP8,BF8}_{FP8,BF8}`. LLVM now gates those 8
builtins on `wmma-16x16x128fp8-insts`, which only gfx1250 has:
llvm/llvm-project#228564, re-landed as llvm/llvm-project#229044
(LCOMPILER-2899). CK and CK Tile guard the 20 call sites with
`__gfx125__`, which also covers gfx1250-strict. Older compilers accepted
the builtins on strict and emitted instructions that A0 does not
support.

JIRA ID : ROCM-35020

## Technical Details

All 20 call sites now go through one helper per library:

| Library | Helper | Call sites |
|---|---|---|
| CK Tile | `wmma_{f32,f16}_16x16x128_f8` in
`ck_tile/core/arch/mma/wmma/wmma_gfx1250_f8_16x16x128.hpp` (new) |
`wmma_gfx12.hpp` (8), `warp_gemm_attribute_wmma_impl_8bit_traits.hpp`
(4) |
| CK | `wmma_{f32,f16}_16x16x128_f8_gfx125` in `ck/utility/amd_wmma.hpp`
| `amd_wmma.hpp` (8) |

- **gfx1250, gfx1251:** unchanged. The helpers emit the native builtins,
and the warp GEMM traits keep their `reuse_a` / `reuse_b` flags. gfx1250
ISA is identical before and after.
- **gfx1250-strict, f32 output:**
`__builtin_amdgcn_wmma_scale_f32_16x16x128_f8f6f4` with the FP8 (0) /
BF8 (1) format flags and an explicit E8M0 scale of 1.0 (`0x7F7F7F7F`)
for A and B, plus the reuse hints. It reads A and B in the same register
layout as the native instructions.
- Why not the unscaled `__builtin_amdgcn_wmma_f32_16x16x128_f8f6f4`: on
gfx1250-strict LLVM rewrites it to the scaled instruction with a scale
of 0 (llvm/llvm-project#230253). 0 means 1.0 only as an inline constant.
At -O0 it is placed in a VGPR, where E8M0 0 is 2^-127, and the result is
C instead of A*B + C. An explicit 1.0 is correct at every optimization
level.
- **gfx1250-strict, f16 output:** F8F6F4 has no f16-output form, so the
helper converts C to f32, runs the f32 path, and rounds once to f16.
Cost per f16 WMMA on strict: 8 `v_cvt_f32_f16` and 4 `v_cvt_pk_f16_f32`,
and C takes 8 VGPRs instead of 4.
- The op types (`amdgcn_mma` specializations, `WmmaTraits`) do not
change, so host and device passes still select the same MmaOp (see the
comment at the top of the GFX1250 section in `wmma_gfx12.hpp`). The
`instruction_name` strings of the eight CK Tile ops now name both
instructions.

**Tests** (CK and CK Tile tested separately; they do not depend on each
other):

| Test | Library | What |
|---|---|---|
| `test_ck_tile_wmma_f8_16x16x128_gfx125` | CK Tile | compile-only, 12
call sites, every gfx125 target the compiler supports, whatever
`GPU_TARGETS` is |
| `test_ck_wmma_f8_16x16x128_gfx125` | CK | compile-only, 8 call sites,
same |
| `test_wmma_op_f8_16x16x128_o0` | CK | the existing runtime check
against a CPU reference (`test_wmma_op`, 16x16x128 cases), built at -O0
|

CK CI's daily gfx1250-strict build only builds the MIOpen and hipTensor
instance libraries, not tests.

## Test Plan

1. Device-compile all 20 wrappers for gfx1250 and gfx1250-strict with
ROCm LLVM `d196b6e0be62` (TheRock Multi-Arch CI run
[45807908974](https://github.com/ROCm/TheRock/actions/runs/45807908974)),
with `develop` and with this PR, at -O0 and -O3.
2. CK CMake build with `-DGPU_TARGETS=gfx1250-strict` and the same
compiler: all three new tests plus `test_amdgcn_mma_layout_gfx1250`,
`test_tile_gemm_quant_pipelines_gfx1250` and `test_wmma_op`.
3. Runtime on the rocJITsu gfx1250 emulator (B0 model). The emulator
cannot run gfx1250-strict code objects, so the strict path was forced on
in a scratch copy of each helper and built for gfx1250:
- the strict path vs the native instruction, at -O0 and -O3, all 4 A/B
type pairs, on narrow-exponent data (every f32 sum exact) and on
full-range finite data; and, for comparison, the unscaled F8F6F4 builtin
as LLVM lowers it on strict (scale 0);
- `test_wmma_op_f8_16x16x128_o0` with the strict path forced on, using
the explicit 1.0 scale and using a scale of 0, to show that the -O0 test
detects a wrong scale.

## Test Result

1. With `develop`, gfx1250-strict fails with 20 errors (one per call
site) and gfx1250 passes. With this PR, both pass at -O0 and -O3.
gfx1250-strict emits only `v_wmma_scale_f32_16x16x128_f8f6f4`, always
with the 1.0 scale.
2. All targets build. Against the `develop` headers, the compile-only CK
Tile test fails with 12 errors and the CK test with 8.
3. Emulator:

   | Strict path, vs native | Narrow-exponent data | Full-range data |
   |---|---|---|
| explicit scale 1.0 (this PR), -O0 and -O3 | f32 and f16 bit-identical
| f16 bit-identical; f32 differs in 157-193 of 256 elements per pair,
max relative difference 4.8e-5 |
| unscaled builtin (LLVM promotes it with scale 0), -O3 | bit-identical
| same as explicit scale 1.0 |
| unscaled builtin (LLVM promotes it with scale 0), -O0 | all 256
outputs wrong, every output equals C | not measured |

The full-range f32 difference is far below FP8/BF8 input precision. The
emulator models B0, so this does not prove A0 behaviour.

`test_wmma_op_f8_16x16x128_o0` with the strict path forced on: 8/8 pass
with the explicit 1.0 scale; 8/8 fail with a scale of 0.

4. A0 hardware (gfx1250-strict): one scaled F8F6F4 WMMA with the scale 0
or 1.0, as a literal and as a runtime value, at -O0 and -O3. A scale of
0 gives C whenever it is in a register (literal at -O0, runtime value at
both levels); 1.0 is correct in every case. Reproducer and output in the
review thread.

Not covered: CK itself on A0 hardware, and the full CK test suite on
gfx1250-strict.

Separately, the LLVM rewrite in llvm/llvm-project#230253 should not
depend on the scale staying an inline constant; that is a compiler
issue, to be reported to LLVM separately.

## Submission Checklist

- [x] Look over the contributing guidelines at
https://github.com/ROCm/TheRock/blob/main/GOVERNANCE.md#pull-requests.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

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.

3 participants