[Rock] Add i4 (iu4 16x16x32) WMMA GEMM support for gfx12#2417
Open
rhway666 wants to merge 2 commits into
Open
Conversation
rocMLIR already scaffolds the i4 WMMA type id (I4_To_I32_TyId) and i4->i32
accumulation in getRetType, but never wires it to an instruction. This adds the
missing gfx12 path so an i4 GEMM lowers to wmma_i32_16x16x32_iu4, mirroring the
i8 16x16x16 path. iu4 uses K=32 and inputVectorLen 16 (vs i8's K=16/8) because a
4-bit element packs at twice the K depth of i8.
- WmmaInsnGroup: add the gfx12 {I4,32} -> wmma_i32_16x16x32_iu4 map entry and
select K=32 for i4.
- rocmlir-gen: accept "-t i4" and default its output type to i32.
- RockOps.td: allow I<4> in GemmInputTypes.
- RockDialect: verifyGemmTypes accepts i4 only on gfx12 (RDNA4); gfx11 rejects.
- ParamLookupTable: map i4 to "i4" in the tuning lookup key.
- QuickTuningPerfconfigs: add a hand-placed gfx1201 i4 quick-tuning config
(the autotuner cannot yet tune i4; see the inline note and PR description).
- README: list i4 in the -t/--dtype examples.
- test/Dialect/Rock/wmma_gemm_i4.mlir: lowering check + gfx11 negative check.
Assisted-by: Claude (Anthropic)
Contributor
There was a problem hiding this comment.
Pull request overview
This PR wires up native i4 (iu4) integer WMMA GEMM codegen on gfx12/RDNA4, enabling i4×i4→i32 GEMM to lower through rock to the wmma_i32_16x16x32_iu4 instruction, and adds the supporting frontend, verification, tuning-key, perfconfig, and test updates.
Changes:
- Add gfx12 WMMA instruction selection/mapping for iu4 16x16x32 (K=32) and gate i4 GEMM types to RDNA4.
- Extend
rocmlir-gendtype handling to accept-t i4and default i4 output to i32. - Add tuning-key + quick-tuning entry for
gfx1201_gemm_i4and a Lit test covering gfx12 lowering and gfx11 rejection.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
README.md |
Documents -t i4 in rocmlir-gen dtype examples. |
mlir/tools/rocmlir-gen/rocmlir-gen.cpp |
Adds CLI parsing for i4 and defaults i4 output dtype to i32. |
mlir/test/Dialect/Rock/wmma_gemm_i4.mlir |
New Lit test for gfx1201 lowering to WMMA iu4 and gfx1100 rejection. |
mlir/lib/Dialect/Rock/Tuning/ParamLookupTable.cpp |
Adds i4 (bitwidth==4) dtype string normalization for tuning keys. |
mlir/lib/Dialect/Rock/IR/WmmaInsnGroup.cpp |
Adds gfx12 iu4 WMMA op mapping and selects K=32 for i4. |
mlir/lib/Dialect/Rock/IR/RockDialect.cpp |
Verifier allows i4 on RDNA4 WMMA GEMM. |
mlir/include/mlir/Dialect/Rock/Tuning/QuickTuningPerfconfigs.inc |
Adds gfx1201_gemm_i4 quick-tuning perfconfig entry. |
mlir/include/mlir/Dialect/Rock/IR/RockOps.td |
Allows I<4> in GemmInputTypes (affects GEMM and rock.conv forward). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…gnostic - verifyConvOp rejects i4 (i4 WMMA is GEMM-only) instead of fatal-erroring in tuning-parameter selection, since rock.conv shares GemmInputTypes. - verifyGemmTypes emits an RDNA4-specific error message that includes int4. - test/Dialect/Rock/conv_i4_unsupported.mlir: conv i4 rejection check. Addresses Copilot review on ROCm#2417. Assisted-by: Claude (Anthropic)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds native i4 (iu4) integer GEMM codegen for gfx12/RDNA4: an i4×i4→i32 GEMM
now lowers through the
rockdialect towmma_i32_16x16x32_iu4(mirrors theexisting i8
wmma_i32_16x16x16_iu8path). Distinct from prior i4 work (#1584 isi4×f16 mixed-precision; #1682 is i4 vector loads) — this is the native
iu4×iu4 integer WMMA path.
Tracking issue for i4 follow-ups (autotuner, verifier, conv/other-arch,
signedness, full tuning short-list): #2418
Assisted-by: Claude (Anthropic)
Motivation
The i4 WMMA type id (
I4_To_I32_TyId) andgetRetType(i4→i32) already existupstream, but i4 was never wired to an instruction. This connects it: the
instruction map, the frontend (
-t i4), the type gates (gfx12-only), thetuning-key string, and a tuning config. iu4 uses K=32 and inputVectorLen=16
(vs i8's 16/8) because a 4-bit element packs at twice the K depth of an 8-bit
element. Gated to gfx12 (gfx11 rejects i4).
Technical Details
Files (8):
Dialect/Rock/IR/WmmaInsnGroup.cpp— gfx12 insn map{I4_To_I32_TyId, 32} → wmma_i32_16x16x32_iu4;selectchooses K=32 for i4.tools/rocmlir-gen/rocmlir-gen.cpp— accept-t i4; default i4 output to i32.IR/RockOps.td— allowI<4>inGemmInputTypes.IR/RockDialect.cpp—verifyGemmTypesaccepts i4 only on gfx12 (RDNA4).Tuning/ParamLookupTable.cpp— map i4 to"i4"in the tuning key.Tuning/QuickTuningPerfconfigs.inc— a gfx1201 i4 tuning config.README.md— list i4 in the-t/--dtypeexamples.test/Dialect/Rock/wmma_gemm_i4.mlir— lowering check + gfx11 negative check.Notes for reviewers:
signedness selector (tracked as a shared integer-WMMA follow-up in the issue).
selectpicks K=32 for i4 via a ternary since i4 is the onlyK≠16 type on gfx12 today; mirrors the gfx1250 per-type-K style and can be
refactored to if/else-if if more K variants are added on gfx12.
QuickTuningPerfconfigs.incis generatedby
quickTuningGen.py --updatefrom sweep TSVs. The i4 entry is required,not a perf nicety: the quick-tuning lookup
report_fatal_errors on a miss(
Tuning parameters not found for key gfx1201_gemm_i4) and falls back only bysame op+dtype across architectures — so i4 has no i8 fallback and no other arch
carries
gemm_i4. Without it, i4 GEMM does not lower. The autotuner(
rocmlir-tuning-driver) cannot yet tune i4 (its applicability pipeline rejectsall i4 configs), so the entry is placed by hand and a future
--updatewould drop it (flagged inline). The single config is correctness-verified and
was chosen as the most robust single config across the i8
tier1-gemmshapes(offline rocprofv3 sweep on gfx1201); those numbers are provisional and not
CI-verified. A full per-shape short-list will be produced data-driven via
quickTuningGen.py --update(not hand-edited) once i4 is wired into theautotuner — tracked in the issue.
Known limitation (out of scope, follow-up): the
--verifier cpu/gpurandom-data auto-compare paths still need i4 narrow-type handling — (1)
rock.transform's affine index-map must be rewritten for the packed (i8) layout;(2) the workgroup-LDS
memref<…xi4, #gpu.workgroup>alloc +vector.storeofvector<Nxi4>must be packed consistently. This does not affect the generatedkernel (validated below); it's a separate narrow-type follow-up.
Test Plan
mlir/test/Dialect/Rock/wmma_gemm_i4.mlir, CI-runnable):rocmlir-gen … -t i4 -wmma=on --arch gfx1201 | rocmlir-driver …lowers toamdgpu.wmma 16x16x32 … vector<16xi4>androcdl.wmma.i32.16x16x32.iu4 … (vector<2xi32>, vector<2xi32>, vector<8xi32>) -> vector<8xi32>; a gfx1100 i4 GEMM is rejected.i4 kernel compiles to a gfx1201 binary and executes.
Test Result
C[m][n] = Σ_k 1·1 = K— verified output == Kfor K ∈ {32, 128, 256} on gfx1201.
(bit-exact).
clang-formatclean (git clang-format --diffis empty).Submission Checklist