[PR #260] [CLOSED] RDNA3 WMMA kernels for the gfx1100 prefill (dense GEMMs and prompt attention) #2533

Closed
opened 2026-11-04 02:01:03 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/260
Author: @StevenChenSE
Created: 9/30/2026
Status: ❌ Closed

Base: main ← Head: pr-wmma


📝 Commits (1)

  • bd534a5 RDNA3 WMMA kernels for the gfx1100 prefill (dense GEMMs, prompt attention, parity test)

📊 Changes

10 files changed (+1216 additions, -6 deletions)

View changed files

📝 CMakeLists.txt (+12 -2)
📝 cmake/hip_backend.cmake (+6 -0)
📝 docs/AMD_HIP.md (+32 -0)
📝 include/strata/hip_compat/cuda_runtime.h (+8 -0)
➕ include/strata/hip_compat/math_constants.h (+8 -0)
📝 src/kernels/cuda/qsa_prompt_attn.cu (+381 -4)
📝 src/prefill/gemm.cu (+26 -0)
➕ src/prefill/wmma_gemm.cu (+280 -0)
➕ src/prefill/wmma_gemm.h (+22 -0)
➕ tests/hip/prefill_wmma_gemm_parity.cpp (+441 -0)

📄 Description

gfx11's matrix instructions (v_wmma_*) are unused by this backend: dense projections reach BLAS, and the prompt
attention uses the ordered FP32 fallback, which exists because the QSA matrix instructions it was written for are
CUDA-only. This adds two native paths for gfx1100.

What

  • src/prefill/wmma_gemm.{cu,h} - dense GEMM over the RDNA3 WMMA fragment layout (16x16x16, wave32 "doubled"
    inputs), templated for _Float16 and __bfloat16, dispatched from Gemm::f16 and Gemm::bf16 ahead of the
    BLAS fallback.
  • src/kernels/cuda/qsa_prompt_attn.cu - the prompt attention itself on WMMA (scores 16x32 in two waves, output
    four warps over 64 dimensions) instead of the emulated scalar path.
  • tests/hip/prefill_wmma_gemm_parity.cpp - parity against a double-precision host reference over 440 shapes x 4
    beta/ldy configurations x 2 dtypes, including partial tiles, padding columns, end guards and the declined
    shapes; registered for ctest like the neighbouring hip_* tests.

A/B switches

STRATA_WMMA_GEMM=0 (both dense GEMMs), STRATA_WMMA_BF16=0 (bf16 only), STRATA_PA_WMMA=0 (attention).

Measured

Against an unmodified build of this branch with the same flags, one RX 7900 XTX, 6-core host, PCIe 4.0 x16, using
the documented measured configuration (--prefill 8192 --spec 4 --kv int8 --kv-resident 32768 --adapt-every 0 --pcie-frac 0, STRATA_PREFILL_MMQ=1):

prefill tier before after decode tier before after
1K 444 tok/s 601 (+35 %) 1K 42.6 41.7
4K 778 1178 (+51 %) 4K 42.7 41.0
32K 778 1527 (+96 %) 32K 55.2 54.9

Decode is unchanged inside the noise. The gain is prefill and it grows with context, which is where the dense
projections and the attention dominate. Under the kernels' own switches (1K prompt, 32 generated tokens): 616.5
tok/s with both on, 597.6 with the attention off, 387.1 with the dense GEMMs off, 369.0 with both off.

Numerical note

The fp16 parity comparison allows 4 ULP: the matrix core accumulates in fp32 but rounds toward zero, while a host
reference rounds to nearest. Every delta observed on this hardware is <= 1 ULP and toward zero, and bf16 compares
exactly; STRATA_WMMA_PARITY_EXACT=1 demands bit equality instead. The fp16 and bf16 paths both leave an 8-token
seed run bit-identical, and the decode side is unaffected.

Three integration details

Without these the kernels compile but never run, so they are part of the change:

  1. this tree's HIP macro is STRATA_USE_HIP. The kernels were written against a private STRATA_BACKEND_HIP, and
    with it undefined the WMMA dispatch was silently compiled out.
  2. cmake/hip_backend.cmake supplies STRATA_WMMA_GFX11, because the host pass of a HIP compile does not
    define __gfx1100__ even though it does define __HIP_DEVICE_COMPILE__. A compiler-macro guard therefore
    built the returning-false stubs for the symbol the engine links and the WMMA path never ran.
  3. hip_compat needs CUDART_INF_F, CUDA's math_constants.h spelling, mapped to HIP_INF_F - in the
    force-included cuda_runtime.h and in a standalone header for sources that include it by name.

Not claimed

  • These were not compared against the calibrated hipBLASLt table, which needs a ROCm release matching it (the
    table's version guard rejects this one); the BLAS fallback here is hipblasGemmEx.
  • The numbers are one host and one model pack. The host is described above because it matters: expert offload over
    PCIe and a 6-core CPU are part of the configuration.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/260 **Author:** [@StevenChenSE](https://github.com/StevenChenSE) **Created:** 9/30/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr-wmma` --- ### 📝 Commits (1) - [`bd534a5`](https://github.com/Niko1221/Strata/commit/bd534a5d5c278954ba1085f367e3d2aeabe9c8ce) RDNA3 WMMA kernels for the gfx1100 prefill (dense GEMMs, prompt attention, parity test) ### 📊 Changes **10 files changed** (+1216 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+12 -2) 📝 `cmake/hip_backend.cmake` (+6 -0) 📝 `docs/AMD_HIP.md` (+32 -0) 📝 `include/strata/hip_compat/cuda_runtime.h` (+8 -0) ➕ `include/strata/hip_compat/math_constants.h` (+8 -0) 📝 `src/kernels/cuda/qsa_prompt_attn.cu` (+381 -4) 📝 `src/prefill/gemm.cu` (+26 -0) ➕ `src/prefill/wmma_gemm.cu` (+280 -0) ➕ `src/prefill/wmma_gemm.h` (+22 -0) ➕ `tests/hip/prefill_wmma_gemm_parity.cpp` (+441 -0) </details> ### 📄 Description gfx11's matrix instructions (`v_wmma_*`) are unused by this backend: dense projections reach BLAS, and the prompt attention uses the ordered FP32 fallback, which exists because the QSA matrix instructions it was written for are CUDA-only. This adds two native paths for gfx1100. ## What * `src/prefill/wmma_gemm.{cu,h}` - dense GEMM over the RDNA3 WMMA fragment layout (16x16x16, wave32 "doubled" inputs), templated for `_Float16` and `__bfloat16`, dispatched from `Gemm::f16` and `Gemm::bf16` ahead of the BLAS fallback. * `src/kernels/cuda/qsa_prompt_attn.cu` - the prompt attention itself on WMMA (scores 16x32 in two waves, output four warps over 64 dimensions) instead of the emulated scalar path. * `tests/hip/prefill_wmma_gemm_parity.cpp` - parity against a double-precision host reference over 440 shapes x 4 beta/ldy configurations x 2 dtypes, including partial tiles, padding columns, end guards and the declined shapes; registered for ctest like the neighbouring `hip_*` tests. ## A/B switches `STRATA_WMMA_GEMM=0` (both dense GEMMs), `STRATA_WMMA_BF16=0` (bf16 only), `STRATA_PA_WMMA=0` (attention). ## Measured Against an unmodified build of this branch with the same flags, one RX 7900 XTX, 6-core host, PCIe 4.0 x16, using the documented measured configuration (`--prefill 8192 --spec 4 --kv int8 --kv-resident 32768 --adapt-every 0 --pcie-frac 0`, `STRATA_PREFILL_MMQ=1`): | prefill tier | before | after | decode tier | before | after | | --- | ---: | ---: | --- | ---: | ---: | | 1K | 444 tok/s | **601** (+35 %) | 1K | 42.6 | 41.7 | | 4K | 778 | **1178** (+51 %) | 4K | 42.7 | 41.0 | | 32K | 778 | **1527** (+96 %) | 32K | 55.2 | 54.9 | Decode is unchanged inside the noise. The gain is prefill and it grows with context, which is where the dense projections and the attention dominate. Under the kernels' own switches (1K prompt, 32 generated tokens): 616.5 tok/s with both on, 597.6 with the attention off, 387.1 with the dense GEMMs off, 369.0 with both off. ## Numerical note The fp16 parity comparison allows 4 ULP: the matrix core accumulates in fp32 but rounds toward zero, while a host reference rounds to nearest. Every delta observed on this hardware is <= 1 ULP and toward zero, and bf16 compares exactly; `STRATA_WMMA_PARITY_EXACT=1` demands bit equality instead. The fp16 and bf16 paths both leave an 8-token seed run bit-identical, and the decode side is unaffected. ## Three integration details Without these the kernels compile but never run, so they are part of the change: 1. this tree's HIP macro is `STRATA_USE_HIP`. The kernels were written against a private `STRATA_BACKEND_HIP`, and with it undefined the WMMA dispatch was silently compiled out. 2. `cmake/hip_backend.cmake` supplies `STRATA_WMMA_GFX11`, because the **host** pass of a HIP compile does not define `__gfx1100__` even though it does define `__HIP_DEVICE_COMPILE__`. A compiler-macro guard therefore built the returning-false stubs for the symbol the engine links and the WMMA path never ran. 3. `hip_compat` needs `CUDART_INF_F`, CUDA's `math_constants.h` spelling, mapped to `HIP_INF_F` - in the force-included `cuda_runtime.h` and in a standalone header for sources that include it by name. ## Not claimed * These were **not** compared against the calibrated hipBLASLt table, which needs a ROCm release matching it (the table's version guard rejects this one); the BLAS fallback here is `hipblasGemmEx`. * The numbers are one host and one model pack. The host is described above because it matters: expert offload over PCIe and a 6-core CPU are part of the configuration. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-04 02:01:03 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#2533
No description provided.