Skip to content

hip: the dense int8 prefill GEMM runs on the 8-bit WMMA - #240

Merged
Vasyl-Trefilov merged 4 commits into
RustingStudio:mainfrom
hun:hip/int8-gemm
Dec 6, 2026
Merged

Vasyl-Trefilov merged 4 commits into
RustingStudio:mainfrom
hun:hip/int8-gemm

Conversation

@hun

@hun hun commented Dec 6, 2026

Copy link
Copy Markdown

The dense int8 prefill GEMM now runs on the 8-bit WMMA (v_wmma_i32_16x16x16_iu8), which issues in ~3 cycles per 16x16x16 tile against the f16 form's 16. On an RX 9070 XT (gfx1201) it beats the f16 GEMM for every int8 type, and it is the first int8 prefill path HIP has had: int8_gemm returned false before, and #228 set mmq false to match.

Measured

leo-ab, one binary, STRATA_MMQ= forces the f16 GEMM for the other arm, 2 rounds ABBA, all cells ok, noise under 1%. Prefill tok/s:

model depth int8 WMMA f16
Bonsai 2 9B Q2_0 pp 512 3295 2589
Bonsai 2 9B Q2_0 pp 4096 3196 2338
Qwen4-35B-A3B Q4_K_XL pp 4096 1959 1839
Qwen4-35B-A3B Q4_K_XL pp 16384 1873 1767

Decode is unchanged (it runs the int8 GEMV-N, not this GEMM). MTP at k=1 (+27.9% decode) and DFlash2 are unchanged too; routing the MTP/DFlash verify step through this GEMM (STRATA_VERIFY_GEMM) is a wash against gemvn.

gemmi_q4_k is 135 VGPR / 10 waves, against 176 / 8 for the f16 gemm_q4_k.

How it works

  • compat.h: strata_ld_wmma_i8 / strata_wmma_i8, the gfx12 and gfx11 builtins. The fragment map is undocumented by AMD (ROCm issue #6025); it was confirmed on the card against a standalone harness and cross-checked with radiance's libr4d/r4d_fp8_wmma.h.
  • kernels.cu: a GEMMI_WMMA body in gemmi_q reusing the loop's existing int8 staging. A scale32 type chains its two 16-column WMMA steps in int32 (exact: 32 * 127^2 < 2^22) and folds once per 32-column weight scale; the chained fold is what made the difference between winning by 9% and by 27% on Q2_0.
  • hip/mod.rs: int8_gemm/mmq are gated on wmma_gemm() (a gfx11/gfx12 arch with STRATA_HIP_WMMA), so other targets keep the f16 GEMM. Tile lists take gemmis_* as on CUDA.
  • mmq now returns int8_gemm. It has to: the tests build their reference math from it, and hip: mmq is false, as this backend has no int8 GEMM #228's blanket false would have described a GEMM the launcher runs as int8. On a target without the WMMA both are false, which is hip: mmq is false, as this backend has no int8 GEMM #228's state.

Checks

tests/kernels on gfx1201: 38 passed, 2 failed, and both (moe_mailbox_round_trip, tensor_scale_applies_to_all_gpu_ops) fail identically on 37291b8. hiprtc_compiles_the_kernels passes for gfx1201 and gfx1100. A new int8_gemm_dense_matches_reference covers Q4_K/Q6_K/Q8_0/Q2_0 at 640 and 2560 columns on both tile shapes, to 1e-4.

docs/HIP.md has the numbers and the STRATA_MMQ switch.

Hannes Klas added 4 commits December 6, 2026 06:27
Qwen4-35B-A3B Q4_K_XL prefill +3.5% at pp4096 and Bonsai 2 9B Q2_0
+16.3% at pp4096 against the f16 GEMM, decode unchanged (leo A/B,
noise under 1%). The dp4a body this branch started with measured
slower than f16 on both and is gone.

The int8 path is gated on wmma_gemm(), so only gfx11/gfx12 compile it.
A scale32 type's two 16-column WMMA steps chain in int32 (exact,
32 * 127^2 < 2^22) and fold once, halving the per-slot fold, its cvt
and its LDS reads. Bonsai 2 9B Q2_0 prefill +21.3% at pp512 and
+26.7% at pp4096 over f16, Qwen4-35B-A3B +4.7% at pp4096 (leo A/B,
same binary, STRATA_MMQ= for f16). gemmi_q4_k 209 VGPR / 7 waves ->
135 / 10.
Main's RustingStudio#228 made mmq false while int8_gemm returns true on gfx11/12,
so the tests built an f16 reference for a GEMM the launcher ran as
int8. Tile lists also fell back to f16, which a test compared against
int8 math (Q8_0 read 3.6e-3 off). gemmis_* now serves them as on CUDA:
Q8_0 reads 8.2e-7.
Bonsai 2 9B Q2_0 3295 / 3196 tok/s at pp 512 / 4096 against 2589 /
2338 on the f16 GEMM; Qwen4-35B-A3B 1959 / 1873 at pp 4096 / 16384
against 1839 / 1767. STRATA_HIP_WMMA=0 and STRATA_MMQ are listed.
@aletheore

aletheore Bot commented Dec 6, 2026

Copy link
Copy Markdown

Aletheore Flash Lite review

Merge confidence Review effort Merge risk
5 / 5 3 / 5 Low
Area Files Lines
src/cuda 2 +139 −22
src/hip 2 +106 −17
docs 1 +17 −1
tests 1 +39 −0

No issues held up under independent verification (10 grounded, 0 confirmed by a second model).

Review details

Reviewed 6 file(s); skipped 0. Dismissed 0; outside PR diff 0. Grounding: 10 of 10 proposed finding(s).

@aletheore

aletheore Bot commented Dec 6, 2026

Copy link
Copy Markdown

🔍 Aletheore evidence diff

graph LR
    n0["src/cuda/mod.rs"]
    n1["src/hip/mod.rs"]
    n2["backend.rs"]
    n3["host_share.rs"]
    n4["chat.rs"]
    n5["device.rs"]
    n6["lib.rs"]
    n7["main.rs"]
    n8["src/vulkan/mod.rs"]
    n9["preflight.rs"]
    n10["tests/common/mod.rs"]
    n11["gpu_model.rs"]
    n12["inkling2_attn_kv.rs"]
    n13["kv_q8.rs"]
    n14["kv_turbo.rs"]
    n15["llama_numerics.rs"]
    n16["vulkan_split_kv.rs"]
    n0 --> n2
    n0 --> n3
    n0 --> n4
    n0 --> n5
    n0 --> n6
    n0 --> n7
    n0 --> n8
    n0 --> n9
    n0 --> n10
    n0 --> n11
    n0 --> n12
    n0 --> n13
    n0 --> n14
    n0 --> n15
    n0 --> n16
    n1 --> n2
    n1 --> n6
    n1 --> n10
    classDef changed fill:#d9772c,color:#fff,stroke:#b85f1c;
    classDef changedFinding fill:#c0392b,color:#fff,stroke:#922b21;
    classDef dependent fill:#f2f0ec,color:#18140f,stroke:#d6d0c5;
    class n0 changed
    class n1 changed
    class n2 dependent
    class n3 dependent
    class n4 dependent
    class n5 dependent
    class n6 dependent
    class n7 dependent
    class n8 dependent
    class n9 dependent
    class n10 dependent
    class n11 dependent
    class n12 dependent
    class n13 dependent
    class n14 dependent
    class n15 dependent
    class n16 dependent
Loading

What changed
Deterministic, computed from this commit's real scan and import graph - posted on every run, whether or not Flash Review found anything.

  • docs/HIP.md · modified · +17/-1
  • src/cuda/kernels.cu · modified · +135/-15
  • src/cuda/mod.rs · modified · +4/-7 · -1 function · 15 other dependents
  • src/hip/compat.h · modified · +39/-0 · +3 functions
  • src/hip/mod.rs · modified · +67/-17 · +2 functions · 3 other dependents
  • tests/kernels.rs · modified · +39/-0 · +1 function

Aggregate deltas

  • Modules: +0
  • Dependency graph edges: +0
  • Commits: 4

@Vasyl-Trefilov
Vasyl-Trefilov merged commit fd0a22c into RustingStudio:main Dec 6, 2026
6 checks passed
@Vasyl-Trefilov

Copy link
Copy Markdown
Member

Hi, ty, nice work on the 8-bit WMMA path. I merged it on top of main and the HIP stack, the only conflicts were the kernel name counts and the new q8 field next to the hipBLAS fields, easy to fix.
One small thing I fixed on my side: the new comment in kernels.cu has the text "#define MMA_FMA 1" in it, and the CUDA test cubin_cache_key_changes_with_mma_fma checks that an RTX 20 card's source has no "#define MMA_FMA", so it failed. I changed the comment to say "a global MMA_FMA define". After that the CUDA tests pass, including your new int8_gemm_dense_matches_reference, so the CUDA int8 path is the same as before.
I can not run RDNA3 here, so I trust your numbers for the card. It goes in after the hipBLAS stack.

@hun

hun commented Dec 6, 2026 via email

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants