mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #3223] [Engine] perf(prefill): port wmma_gemm and gdn_chunked WMMA kernels to RDNA4 gfx12 #4507
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#4507
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/3223
Author: @bsorensen110
Created: 10/19/2026
Status: 🔄 Open
Base:
main← Head:new/pr3010📝 Commits (2)
c18451cperf(prefill): port wmma_gemm and gdn_chunked WMMA kernels to RDNA4 gfx12 (P3)6b90b1ftest(hip): reject non-finite deltas and use bf16_from_f32 in prefill_wmma_gemm_parity📊 Changes
5 files changed (+434 additions, -129 deletions)
View changed files
📝
cmake/hip_backend.cmake(+3 -3)📝
src/prefill/kernels.cu(+86 -42)📝
src/prefill/wmma_gemm.cu(+170 -81)📝
tests/hip/gdn_chunked.cpp(+2 -1)📝
tests/hip/prefill_wmma_gemm_parity.cpp(+173 -2)📄 Description
Problem and result
Supersedes #3010 (closed during the
0.2.0-betatracker reset), rebased onto0.2.0-beta(e88ee39d).Previously, the custom HIP WMMA prefill projection kernels in
src/prefill/wmma_gemm.cu(STRATA_PF_HCDOWN=1,STRATA_PF_GEMM=1,STRATA_HCD_EXACT=1) and the chunked GDN recurrence WMMA kernels insrc/prefill/kernels.cu(STRATA_GDN_CHUNKED=1) were compiled and gated exclusively for RDNA3 (gfx1100/gfx1101/gfx1102/gfx1103/gfx1150/gfx1151), declining on RDNA4 (gfx1200/gfx1201) because RDNA4 uses a new wave32 WMMA intrinsic (__builtin_amdgcn_wmma_f32_16x16x16_f16_w32_gfx12/bf16_w32_gfx12) with an 8-elementA/Bregister fragment per lane instead of RDNA3's duplicated 16-element fragment, and a different output row mapping (m = 8 * hi + iwherehi = (lane >> 4) & 1andi = 0..7).This PR ports both
src/prefill/wmma_gemm.cuandsrc/prefill/kernels.cu(gdn_wy_kernel<true>andgdn_state_chunked_kernel<true>) togfx1200/gfx1201with LDS-only barriers (s_wait_dscnt 0x0; s_barrier_signal -1; s_barrier_wait -1), achievingmax_abs = 0(0.000000e+00) across all 3,529hip_prefill_wmma_gemm_paritycases,0failures across all 45hip_gdn_chunkedparity/guard checks,2.22x-2.80xGDN recurrence speedup, and-80.7 ms(-5.0%,T=4096) /-42.8 ms(-4.4%,T=2048) end-to-end 397B prefill wall reduction ongfx1201.Related discussion
Supersedes #3010. All affected switches (
STRATA_GDN_CHUNKED,STRATA_PF_HCDOWN,STRATA_PF_GEMM,STRATA_HCD_EXACT) remain opt-in.Approach
STRATA_WMMA_GFX12(__gfx1200__/__gfx1201__) alongsideSTRATA_WMMA_GFX11insrc/prefill/wmma_gemm.cuandSTRATA_GDN_WMMA_GFX12insrc/prefill/kernels.cu, abstracting fragment types (8 x b16vs16 x b16), loaders, WMMA intrinsics, output row mapping (wmma_row_off), and LDS-only barriers (wmma_lds_barrier/gw_lds_barrier).gfx1200;gfx1201compilation ofsrc/prefill/wmma_gemm.cuincmake/hip_backend.cmakeand extendtests/hip/prefill_wmma_gemm_parity.cppandtests/hip/gdn_chunked.cpptogfx12(including!std::isfinite(delta)checks).Validation
Passed:
cmake --build build-copilot-hip --target strata hip_prefill_wmma_gemm_parity hip_gdn_chunked arch_defaults_test -j16: revision6b90b1f1on0.2.0-beta(e88ee39d), AMD Radeon AI PRO R9700 (gfx1201, 32 GB, Linux7.2.9-2-cachyos-server, ROCm10.2.0a20260914), clean build & link../build-copilot-hip/arch_defaults_test: revision6b90b1f1(0.2.0-beta),arch_defaults_test: OK../build-copilot-hip/hip_prefill_wmma_gemm_parity: revision6b90b1f1(0.2.0-beta),gfx1201,PASS: 3529 cases, max_abs=0, 26 declined shapes../build-copilot-hip/hip_gdn_chunked: revision6b90b1f1(0.2.0-beta),gfx1201, all 45 parity & guard checks pass (FAILURES: 0,wmma=1).Failed:
Not run:
gfx1100/gfx1151hardware (verified by multi-arch compilation--offload-arch=gfx1100,gfx1151,gfx1200,gfx1201; nogfx11GPU in this host).Limits
STRATA_GDN_CHUNKED=1,STRATA_PF_HCDOWN=1,STRATA_PF_GEMM=1,STRATA_HCD_EXACT=1) are unset.STRATA_HCD_EXACT=1insrc/prefill/gemm_hip.cpponly dispatches when the loaded tuning table selectsgfx1151solution IDs1176or1177.Summary
Ports Strata's prefill FP16/BF16 WMMA kernels in
src/prefill/wmma_gemm.cuand the WY-chunked Gated DeltaNet (GDN) prefill recurrence insrc/prefill/kernels.cu(gdn_chunked) from RDNA3-only (gfx11) to RDNA4 (gfx1200/gfx1201):STRATA_WMMA_GFX11=1forgfx12builds (cmake/hip_backend.cmake:105):cmake/hip_backend.cmakematched onlygfx11, so ongfx1200;gfx1201buildssrc/prefill/wmma_gemm.cucompiled toreturn false;stubs forstrata_wmma_gemm_f16,strata_wmma_gemm_bf16,strata_pf_gemm_f16/strata_pf_gemm_f16_ld,strata_pf_hcdown_bf16, andstrata_pf_hcdown_exact_bf16.src/prefill/wmma_gemm.cuto RDNA4 (gfx1200/gfx1201) Wave32 16×16×16 WMMA (P3a):strata_wmma_gfx11_device()to acceptgfx_arch_is_gfx12_wmma().WmmaTraits<_Float16 / __bf16>,gemm_wmma_16x16_1w,gemm_wmma_64x64_4w,pfg::kernel,pfg::kernel_bk64(STRATA_PF_GEMM=1),pfg::kernel_hcdown(STRATA_PF_HCDOWN=1), andpfg::kernel_hcd_exact(STRATA_HCD_EXACT=1) to use RDNA4 8-element half-wave fragments (k = 8 * hi + 0..7),__builtin_amdgcn_wmma_f32_16x16x16_{f16,bf16}_w32_gfx12, contiguous half-wave accumulator row mapping (row = 8 * hi + i), and LDS-only barriers (s_wait_dscnt 0x0; s_barrier_signal -1; s_barrier_wait -1ongfx12,s_waitcnt lgkmcnt(0); s_barrierongfx11).gdn_wmma_prep_kernel,gdn_wmma_scan_kernel,gdn_rec_wmmainsrc/prefill/kernels.cu:1513–1875,STRATA_GDN_CHUNKED=1) to RDNA4 (gfx1200/gfx1201):gfx12, the Wave32 WMMA accumulator layout(row = 8 * hi + v, col = lane & 15)is already identical to the B-operand fragment layout(k = 8 * hi + v, n = lane & 15). Converting an accumulator tilegw_f8into a B-operand fragment (gw_acc_to_b) requires zero cross-lane permutes (4× permlanex16+8× v_perm_b32ongfx11become a direct 8-element FP32→FP16 cast ongfx12), keepinggdn_wmma_scan_kernelat239 VGPRswith0spills ongfx1201.tests/hip/prefill_wmma_gemm_parity.cpp:strata::kernels::bf16_from_f32(value)inencode(value, true)instead ofhip_bfloat16(value).data(which in a host-only.cpptranslation unit without__HIPCC__performs C++20 parenthesized aggregate initialization(uint16_t)valueand truncated fractional BF16 inputs to zero), and rejects non-finitedeltavalues (!std::isfinite(delta) || delta > 0.0).Root cause
cmake/hip_backend.cmake:105&src/prefill/wmma_gemm.cu:if(CMAKE_HIP_ARCHITECTURES MATCHES "gfx11")excludedgfx12, leavingSTRATA_WMMA_GFX11undefined on RDNA4 builds sosrc/prefill/wmma_gemm.cucompiled only the#elsestub section (return false;).src/prefill/wmma_gemm.cu, device passes checked#if defined(__gfx1100__) ...and used RDNA3 16-element replicated fragments (ext_vector_type(16)) and interleaved accumulator row indexing (2 * i + hi), whereas RDNA4 (gfx1200/gfx1201) Wave32 16×16×16 WMMA instructions (__builtin_amdgcn_wmma_f32_16x16x16_{f16,bf16}_w32_gfx12) split the 16-element K-dimension across the two half-waves (8elements per lane:hi = 0holdsk = 0..7,hi = 1holdsk = 8..15) and map accumulator elementsc[0..7]to contiguous half-wave rows8 * hi + i.src/prefill/kernels.cu:1513–1875(gdn_chunked):STRATA_GDN_WMMAandgdn_rec_wmma()checked onlygfx11targets (gfx_arch_is_gfx11_wmma), soSTRATA_GDN_CHUNKED=1always returnedfalseongfx1200/gfx1201and fell back to the token-serialgdn_rec_fused_kernel.The change
cmake/hip_backend.cmake:gfx11|gfx12when definingSTRATA_WMMA_GFX11=1.src/prefill/wmma_gemm.cu:STRATA_WMMA_DEV_GFX11,STRATA_WMMA_DEV_GFX12,WMMA_ROW(i, hi),WMMA_K_OFF(hi),wmma_sync_lds(), andpfg::pfg_sync_lds().gfx1200/gfx1201instrata_wmma_gfx11_device(),WmmaTraits<_Float16>,WmmaTraits<__bf16>,gemm_wmma_16x16_1w,gemm_wmma_64x64_4w,pfg::kernel,pfg::kernel_bk64,pfg::kernel_hcdown, andpfg::kernel_hcd_exact.src/prefill/kernels.cu:STRATA_GDN_WMMA_GFX11,STRATA_GDN_WMMA_GFX12, andGW_ROW(v, hi)forgdn_wmma_prep_kernelandgdn_wmma_scan_kernel, implement zero-permutegw_acc_to_bands_wait_dscnt 0x0barriers ongfx12, and allowgfx_arch_is_gfx12_wmma()ingdn_rec_wmma().tests/hip/gdn_chunked.cpp&tests/hip/prefill_wmma_gemm_parity.cpp:gfx_arch_is_gfx12_wmma()in both test harnesses, fixencode(value, true)inprefill_wmma_gemm_parity.cppto usestrata::kernels::bf16_from_f32(value), and add exact binary-fraction parity tests (with!std::isfinite(delta)guards) forstrata_pf_gemm_f16_ld,strata_pf_hcdown_bf16, andstrata_pf_hcdown_exact_bf16.Evidence
1. ELF Resource Usage on
gfx1201(llvm-readobj --notes)All 11 device kernels across
wmma_gemm.cu.oandkernels.cu.ocompile ongfx1201with 0 register spills (vgpr_spill_count = 0,private_segment_fixed_size = 0):Waves)wmma_gemm.cu.ogemm_wmma_16x16_1w<_Float16 / bfloat16_t>1w)wmma_gemm.cu.ogemm_wmma_64x64_4w<_Float16 / bfloat16_t>4w)wmma_gemm.cu.opfg::kernel<128, 32>8w)wmma_gemm.cu.opfg::kernel<256, 64>8w)wmma_gemm.cu.opfg::kernel_bk648w)wmma_gemm.cu.opfg::kernel_hcdown8w)wmma_gemm.cu.opfg::kernel_hcd_exact6w)kernels.cu.ogdn_wmma_prep_kernel4w)kernels.cu.ogdn_wmma_scan_kernel8w)2. Parity & Standalone Kernel Benchmarks on
gfx1201hip_prefill_wmma_gemm_parity:origin/main477ac13c): skipped with exit code77ongfx1201(WMMA GEMM parity SKIPPED: gfx1201 has no WMMA matrix cores).max_abs = 0acrossstrata_wmma_gemm_f16(1,760cases),strata_wmma_gemm_bf16(1,760cases with non-zerobf16_from_f32inputs),strata_pf_gemm_f16_ld(5cases coveringkernel<128, 32>,kernel<256, 64>, andkernel_bk64),strata_pf_hcdown_bf16(2cases), andstrata_pf_hcdown_exact_bf16(2cases).hip_gdn_chunked(1 GDN layer:HK = 16, HV = 48, S = 128, 7-repeat median):origin/main477ac13c): reportedwmma=0ongfx1201(gdn_rec_wmmadeclined everyT).wmma=1,FAILURES: 0across all 45 test cases (T = 0..16385, CPU reference, chunk continuation, weak-decay, beta-zero, and guard checks).T)gdn_rec_fused(--bench-default)gdn_rec_wmma(--bench)640.0814 ms0.0342 ms2.38x(-57.9%)3.91 ms1.64 ms-2.26 ms2560.2306 ms0.0790 ms2.92x(-65.8%)11.07 ms3.79 ms-7.28 ms20481.8829 ms0.5159 ms3.65x(-72.6%)90.38 ms24.76 ms-65.62 ms1638412.4872 ms4.0308 ms3.10x(-67.7%)599.38 ms193.48 ms-405.91 ms3276824.6364 ms7.6724 ms3.21x(-68.9%)1,182.55 ms368.28 ms-814.27 ms3. End-to-End 397B Prefill A/B (
Swift-Qwen3.8-Flash-Next-IQ3_S, 60 Layers, Same Binary Selector Comparison)Measured via
strata --serve --prompt-cache 0 --short-read 0withSTRATA_PREFILL_TIMING=1(1warmup +3timed trials per prompt length on uncontendedgfx1201):T)gdn recurrenceGPUhc readGPUDONEPrefill Wall (trials / median)204858 ms(6.0%)80 ms(8.4%)956, 956, 957(956 ms)983.8, 986.3, 985.8(985.8 ms)2,077.5 tok/sSTRATA_GDN_CHUNKED=1204818 ms(2.0%)80 ms(8.7%)921, 935, 923(923 ms)948.8, 965.4, 950.0(950.0 ms)2,155.8 tok/s-35.8 ms(+3.8%)STRATA_GDN_CHUNKED=1 STRATA_PF_HCDOWN=1204819 ms(2.0%)73 ms(7.9%)955, 917, 917(917 ms)983.0, 947.0, 944.3(947.0 ms)2,162.6 tok/s-38.8 ms(+4.1%)+ STRATA_PF_GEMM=1204819 ms(2.0%)72 ms(7.9%)917, 917, 917(917 ms)944.0, 947.8, 944.8(944.8 ms)2,167.7 tok/s-41.0 ms(+4.3%)4096121 ms(7.5%)149 ms(9.2%)1605, 1610, 1611(1610 ms)1647.5, 1652.1, 1653.4(1652.1 ms)2,479.3 tok/sSTRATA_PF_HCDOWN=1(P3a isolated,--vram-reserve-mib 1024)4096121 ms(7.5%)129 ms(8.0%)1602, 1606, 1607(1606 ms)1645, 1649, 1649(1649.0 ms)2,484.3 tok/shc read-19 ms(-12.8%)STRATA_GDN_CHUNKED=1409639 ms(2.6%)149 ms(9.7%)1536, 1539, 1540(1539 ms)1578.7, 1582.7, 1582.5(1582.5 ms)2,588.3 tok/s-69.6 ms(+4.4%)STRATA_GDN_CHUNKED=1 STRATA_PF_HCDOWN=1 STRATA_PF_GEMM=1409639 ms(2.6%)129 ms(8.4%)1531, 1534, 1534(1534 ms)1573.5, 1577.3, 1576.7(1576.7 ms)2,597.8 tok/s-75.4 ms(+4.8%)(Candidate evaluated and excluded — P3b in-kernel
Wd_q8dequant insidepfg::kernel_hcdown: UnderSTRATA_HC_Q8=1, dequantizingWd(320 × 10240BF16 =6.55 MB) once per half-layer viahc_bf16_view+kernel_hcdowntakes129 msacross 120 half-layers atT = 4096(-19 msvs148 mshipBLASLt), because the6.55 MBBF16 buffer stays resident in the R9700's 64 MB Infinity Cache across all 32 M-tiles. DequantizingWd_q8on the fly insidekernel_hcdownrepeats the 34-byte-stridedQ8_0address calculation and 8× FP32→BF16 RNE rounding across every M-tile and measured140 msatT = 4096(+11 msslower than P3a's129 ms), so P3b was excluded.)What this does NOT fix
STRATA_GDN_CHUNKED=1,STRATA_PF_HCDOWN=1,STRATA_PF_GEMM=1, andSTRATA_HCD_EXACT=1remain behind their existing opt-in environment variables because their accumulation order / FP16 state rounding differs from default hipBLASLt and FP32 serial GDN recurrence.STRATA_HCD_EXACT=1hipBLASLt solution IDs (1176/1177insrc/prefill/gemm_hip.cpp:623):kernel_hcd_exactis ported togfx12and verified viastrata_pf_hcdown_exact_bf16, butgemm_hip.cpponly dispatchesSTRATA_HCD_EXACT=1when the loaded tuning table selectsgfx1151solution IDs1176or1177.gfx1100/gfx1151: Multi-arch device compilation was verified acrossgfx1100,gfx1151,gfx1200,gfx1201; runtime execution and benchmarks were performed ongfx1201, whilegfx11hardware runtime remains unrun on this host.Test plan
hip_prefill_wmma_gemm_paritypasses3,529cases (max_abs = 0) and26declined-shape checks ongfx1201hip_gdn_chunkedpasses all45parity and guard checks (FAILURES: 0,wmma=1) ongfx1201--offload-arch=gfx1100,gfx1151,gfx1200,gfx1201) onsrc/prefill/wmma_gemm.cuandsrc/prefill/kernels.cuT = 2048andT = 4096ongfx1201Reproduction
Environment: AMD Radeon AI PRO R9700 (
gfx1201, 32 GB), Linux7.2.9-2-cachyos-server, ROCm10.2.0a20260914, basev0.1.45(477ac13c).🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.