Repository navigation
RDNA3 WMMA kernels for the gfx1100 prefill (opt-in, runtime-gated on gfx11; rebased on 0.1.30) - #313
StevenChenSE wants to merge 1 commit into
Conversation
b2ae657 to
246fa77
Compare
|
Thanks! Two fixes needed: (1) |
…gfx11, rebased on 0.1.31 Reworked per review on the 0.1.30 attempt (Niko1221#260) and the 0.1.31 follow-up: * opt-in: nothing runs unless asked. STRATA_WMMA_GEMM=1 enables the dense GEMMs, STRATA_PA_WMMA=1 the WMMA attention; both switches are value-parsed so STRATA_WMMA_GEMM=0 disables (a bare presence check used to turn it ON for any value, including 0). Unset: the hipBLAS path, bit-identical to today's default. * runtime gate on gfx11 only: both paths query gcnArchName and return false without a gfx11 prefix. The build supplies STRATA_WMMA_GFX11 only for gfx11 arch configs. * per-arch device guards: in a gfx1100;gfx1201 mixed build the file compiles per arch, so the RDNA3 v_wmma builtins are now guarded with __gfx1100__/__gfx1101__/__gfx1102__ on the device passes - a gfx1201 pass never compiles them (the mixed build still links, and the kernel body guards to an identity it never runs). * fp16 rounds toward zero vs hipBLAS RZ: unobservable with the switches off; bounded at 4 ULP by the parity test (every delta <= 1 ULP toward zero; bf16 exact). * CMakeLists BOM and comment encoding preserved (byte-level patches; BOM re-verified). * mma16816: our fragment-preserving HIP scalar emulation retained (the dispatch runs the attention kernel on HIP), fused with upstream 0.1.31's Turing sm_75 k8 path and sm_80 k16 - the trap-only HIP fallback would have crashed the non-WMMA HIP path. Measured one RX 7900 XTX, 6-core host, PCIe 4.0 x16, engine 0.1.31, the documented configured flags, 2 interleaved reps: 4K WMMA 1083.7/1308.4 pp vs calibrated-table 852.2/1176.6 vs fallback 658.6/552.8; 1K and 32K switch sweeps in docs/AMD_HIP.md. tests/hip/prefill_wmma_gemm_parity.cpp passes (22/22) on this base.
246fa77 to
1e42cf3
Compare
|
Rebased onto current main (0.1.31) and addressed both review points:
Also: on re-testing after the rebase the switch check exposed that carrying upstream 0.1.31's trap-only mma16816 HIP path crashes our non-WMMA attention on HIP (prompt_attn_kernel hits __trap()). The PR keeps its fragment-preserving HIP scalar emulation and grafts upstream's Turing sm_75 (m16n8k8) and sm_80 (m16n8k16) CUDA paths alongside it. Parity: 22/22 on the WMMA test, fast-intrinsics exhaustive PASS. |
…ate the launcher Mirror of the wmma-optin PR fixes (re: upstream review): * STRATA_WMMA_GEMM / STRATA_WMMA_BF16 are value-parsed: =0 disables, =1 enables (a bare presence test turned WMMA on for any value, including 0). * per-arch device guards on the RDNA3 v_wmma builtins (__gfx1100__/__gfx1101__/__gfx1102__) so a gfx1100;gfx1201 mixed build never compiles gfx11 WMMA builtins into the gfx1201 device pass; the kernels stay linkable for both arches (identity fallback never launched, per the gcnArchName runtime gate). Verified on gfx1100: WMMA parity 22/22, fast-intrinsics parity PASS, no attention trap, and the switch A/B holds (GEMM=0 pp 440.6 vs GEMM=1 pp 538.1 at 1K/4K). tools/run-tuned.sh: default --spec 4 (re-measured 60.2 vs 54.5 for spec 2 at 32K after the intrinsics/residency tuning), and the launcher now sets STRATA_WMMA_GEMM=1 + STRATA_PA_WMMA=1 by default (WMMA=0/PA=0 to disable, values parsed).
|
Thanks! Not in 0.1.39. We no longer have an AMD card to test on, and the PR also changes the default HIP prompt attention (the scalar emulation in place of the upstream path), which must stay byte-identical with the switches off. Could you rebase on 0.1.39 and keep the default HIP path untouched? Please also post one run with the switches off showing identical output to 0.1.39 on gfx1100. |
|
Measured gfx1100 data for this direction (RX 7900 XTX, engine 0.1.39, nightly ROCm 10.2 SDK + gfx1100 hipBLASLt-100500 table, production-mirrored config) — and a current-main-based implementation is now up as #786. The FP32 fallback this PR targets is the single largest prefill phase on gfx1100: 25.6% of prefill GPU time at 128K, 26.9% at 32K. Porting the same
Two things we learned that may be useful for this PR's approach if it's ever rebased:
@StevenChenSE — the |
… GEMM part, on gfx1151 too From PR #313 (1e42cf3): src/prefill/wmma_gemm.cu/.h, the Gemm::f16/bf16 hooks before hipBLASLt, the build macro STRATA_WMMA_GFX11 and its parity test; not its prompt attention (STRATA_HIP_WMMA covers it). Fix: the intrinsics guard named only gfx1100/1101/1102 while the runtime gate takes any gfx11, so on gfx1150/gfx1151 mma() compiled to "return c" (silently wrong); it now names gfx1150/gfx1151 too. hip_prefill_wmma_gemm_parity on gfx1151: 3520 cases pass (f16 max_abs 2.4e-7, bf16 0). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0154bwiad8gY7wRehCXy27pN
|
Fixed in 0.1.40: the GEMM half of this PR is in, through our Strix Halo (gfx1151) branch. It is the RDNA3 / RDNA3.5 WMMA FP16 and BF16 dense GEMMs (opt-in STRATA_WMMA_GEMM=1), compiled into AMD builds only. We fixed two review points: an unlisted gfx11 part (gfx1103, gfx1152) now takes the hipBLASLt path, and the device check is cached per device. The attention half is not taken, because our own gfx11 prompt attention covers it (STRATA_HIP_WMMA=1). Thanks to StevenChenSE for the kernels. Closing. |
… GEMM part, on gfx1151 too From PR #313 (1e42cf3): src/prefill/wmma_gemm.cu/.h, the Gemm::f16/bf16 hooks before hipBLASLt, the build macro STRATA_WMMA_GFX11 and its parity test; not its prompt attention (STRATA_HIP_WMMA covers it). Fix: the intrinsics guard named only gfx1100/1101/1102 while the runtime gate takes any gfx11, so on gfx1150/gfx1151 mma() compiled to "return c" (silently wrong); it now names gfx1150/gfx1151 too. hip_prefill_wmma_gemm_parity on gfx1151: 3520 cases pass (f16 max_abs 2.4e-7, bf16 0).
…=1), its GEMM part, on gfx1151 too From PR Niko1221#313 (1e42cf3): src/prefill/wmma_gemm.cu/.h, the Gemm::f16/bf16 hooks before hipBLASLt, the build macro STRATA_WMMA_GFX11 and its parity test; not its prompt attention (STRATA_HIP_WMMA covers it). Fix: the intrinsics guard named only gfx1100/1101/1102 while the runtime gate takes any gfx11, so on gfx1150/gfx1151 mma() compiled to "return c" (silently wrong); it now names gfx1150/gfx1151 too. hip_prefill_wmma_gemm_parity on gfx1151: 3520 cases pass (f16 max_abs 2.4e-7, bf16 0).
…=1), its GEMM part, on gfx1151 too From PR Niko1221#313 (1e42cf3): src/prefill/wmma_gemm.cu/.h, the Gemm::f16/bf16 hooks before hipBLASLt, the build macro STRATA_WMMA_GFX11 and its parity test; not its prompt attention (STRATA_HIP_WMMA covers it). Fix: the intrinsics guard named only gfx1100/1101/1102 while the runtime gate takes any gfx11, so on gfx1150/gfx1151 mma() compiled to "return c" (silently wrong); it now names gfx1150/gfx1151 too. hip_prefill_wmma_gemm_parity on gfx1151: 3520 cases pass (f16 max_abs 2.4e-7, bf16 0).
…prompt) STRATA_PF_GEMM takes the S23 fused prompt GEMM first, and Niko1221#313's WMMA path covers the shapes that one declines - so BOTH are needed. Measured on gfx1151 with Qwen3.8-Flash-Next ROCmFP4-FAST-v2-ple16, three runs each, wall clock: prompt @4096 910.21 -> 979.96 tok/s (+7.7%) prompt @8192 943.61 -> 1029.21 tok/s (+9.1%) prompt @32768 1007.51 -> 1064.14 tok/s (+5.6%) decode unchanged decoded tokens identical over 128 steps It is try-then-fall-through: when strata_wmma_gemm_f16() declines a shape the call continues to hipBLASLt exactly as before, so the switch cannot make an unsupported shape fail. An earlier pass rejected this switch as "contradictory" - that measurement used --max-new 16, where warm-up variance swamps a 6% effect. Five runs a side on the GPU timeline separate cleanly (7955..8039 against 7482..7708 ms).
Second attempt of #260, rebased on current main (engine 0.1.30) — reworked per the review. Single commit, 10 files.
Addressing the review
STRATA_WMMA_GEMM=1)STRATA_WMMA_GEMM=1enables the dense WMMA GEMMs (fp16 + bf16),STRATA_PA_WMMA=1the WMMA prompt attention;STRATA_WMMA_BF16=0still excludes just bf16. With the switches unset, WMMA does not run at all — the default hipBLASLt-table-to-fallback path is unchanged and output is bit-identical to today's build. When opted in, WMMA dispatches ahead of the table; measurement below shows that arrangement is also the faster one on this card.hipGetDeviceProperties().gcnArchNameand return false without agfx11prefix, so a gfx1201, a mixed-arch build, or any other device never executes WMMA code regardless of what was compiled. Additionally theSTRATA_WMMA_GFX11compile definition is now set only for gfx11CMAKE_HIP_ARCHITECTURESconfigurations.docs/AMD_HIP.mdandtests/hip/prefill_wmma_gemm_parity.cpp.efbbbf), andcmake/hip_backend.cmake(no BOM upstream) likewise untouched in encoding.What the PR contains
src/prefill/wmma_gemm.{cu,h}— dense GEMM over the RDNA3 WMMA fragment layout (16x16x16, wave32 "doubled" inputs), fp16 + bf16, dispatched fromGemm::f16/Gemm::bf16.src/kernels/cuda/qsa_prompt_attn.cu— the prompt attention on WMMA instead of the ordered FP32 fallback.tests/hip/prefill_wmma_gemm_parity.cpp— ctest-registered parity vs a double-precision host reference, 440 shapes × 4 beta/ldy configurations × 2 dtypes (partial tiles, padding, guards, declined shapes); passes on this base (freshly rebuilt from this branch's sources).strata_prefill, the arch-gated compile definition, the ctest registration, and theCUDART_INF_Fmapping hip_compat needs.docs/AMD_HIP.md.With/without numbers
One RX 7900 XTX, 6-core host, PCIe 4.0 x16, engine 0.1.30, the documented measured configuration (
--prefill 8192 --spec 4 --kv int8 --kv-resident 32768 --adapt-every 0 --pcie-frac 0,STRATA_PREFILL_MMQ=1), two interleaved repetitions per cell.Against the strongest BLAS available here. The shipped tables (100100/100200) don't match this ROCm's hipBLASLt 1.4.1 (100401), so I calibrated a table for this runtime with the repository's own
tools/hip/tune_hipblasltand compared against it (4K, ranking consistent in both pairs):GEMM=1 PA=1)WMMA leads the calibrated table by 10–27 % on prefill in both pairs, and the plain fallback by 55–90 %; decode is a wash at this sample size.
Switch sweep (the "off" arm here is the version-mismatched hipblasGemmEx fallback):
WMMA_GEMM=1GEMM=1 PA=1GEMM=1 PA=1Prefill: +31 % at the 1K median, +88 % at 32K vs the fallback; decode unchanged within this host's variance. Host and configuration named because they matter: expert offload over PCIe and a 6-core CPU are part of the setup.
Integration notes (without these the kernels compile but never run)
STRATA_USE_HIP— a privateSTRATA_BACKEND_HIPsilently compiled the dispatch out;__gfx1100__(it defines__HIP_DEVICE_COMPILE__), so the build suppliesSTRATA_WMMA_GFX11;hip_compatneedsCUDART_INF_F(CUDA'smath_constants.hspelling) mapped toHIP_INF_F.Not claimed