mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #3013] [CLOSED] perf(hip): tune RDNA4 QSA prompt WMMA path (STRATA_HIP_WMMA stays opt-in) #4399
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#4399
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/3013
Author: @bsorensen110
Created: 10/18/2026
Status: ❌ Closed
Base:
main← Head:perf/rdna4-p4-qsa-prompt-attn📝 Commits (2)
35080caperf(hip): tune RDNA4 QSA prompt WMMA pathf9b1114perf(hip): tune RDNA4 QSA prompt WMMA path, keep STRATA_HIP_WMMA opt-in📊 Changes
3 files changed (+126 additions, -39 deletions)
View changed files
📝
src/core/arch_defaults.cpp(+2 -0)📝
src/core/arch_defaults_test.cpp(+14 -1)📝
src/kernels/cuda/qsa_prompt_attn.cu(+110 -38)📄 Description
Summary
Optimizes the HIP
int8-KV QSA prompt-attention matrix-core kernel (prompt_attn_wmma_kernel<SPLIT>insrc/kernels/cuda/qsa_prompt_attn.cu).STRATA_HIP_WMMA=1remains opt-in on every architecture (gfx12andgfx11included). While this PR's changes insideprompt_attn_wmma_kernel<SPLIT>are 100% bitwise identical tomain'sprompt_attn_wmma_kernel<SPLIT>(NEWHASH2c5cab7eb6601f66/deb4f727fbac41af/2d10cd9d6d1fd5b5), the matrix-core path itself differs in its last bits from the default FP32 fallback (qsa_decode_attn_batch) due toFP16 hi + losplitting and reduction order. KeepingSTRATA_HIP_WMMAout ofarch_defaults.cpppreserves the exact-only policy ofarch_default_env("gfx1201")and avoids process-wide enablement ongfx11stages in mixed-GPU runs.pa_sync_lds):__syncthreads()barriers insideprompt_attn_wmma_kernel(which synchronize only LDSS) withs_wait_dscnt 0x0; s_barrier_signal -1; s_barrier_wait -1ongfx12ands_waitcnt lgkmcnt(0); s_barrierongfx11(generic__syncthreads()elsewhere), avoiding thes_wait_loadcnt_dscnt 0x0global-load drain andglobal_inv scope:SCOPE_SEL0 vector-cache invalidation emitted by generic__syncthreads()ongfx12.fetchK-before-V + deferred FP16 scale conversion + post-q·KV staging):k_scaleandv_scalein rawuint16_tregisters (Chunk::ksc_u16[2],Chunk::vsc_u16) duringfetch()and converts them viau16_scale()(with an emptyasm volatile("" : "+v"(u))barrier on AMDGPU) only at their point of use after theq·KWMMAs, preventing LLVM from hoistingv_cvt_f32_f16into the conditional global-load blocks and forcing an earlys_wait_loadcnt 0x0.Kglobal loads before theVglobal loads infetch(), and moves LDSVstaging (S.v/S.vs) insidechunk()to after theq·KWMMAs, soVglobal loads stay in flight while the matrix cores computeq·K.Vgather + in-register DPP byte transpose (dpp_tr4) + VALU wave butterfly reductions (pa_xor_u32/pa_xor_f32):ds_load_i8reads per wave per chunk in thep·Vloop (S.v[warp][cb + i][d]) with 16 aligned 32-bitds_load_b32reads (*reinterpret_cast<const uint32_t*>(&S.v[warp][cb + 4 * q4 + qs4][j * 16 + qm4])) followed by an in-register 4×4 byte transpose across the 4 lanes of a hardware DPP quad (dpp_tr4:__builtin_amdgcn_mov_dppquad_perm0xb1/0x4e+__builtin_amdgcn_perm).__shfl_xor_syncin theq-max, row-max, row-sum,row_x16, andV-scale reductions with VALU lane permutations (pa_xor_u32/pa_xor_f32:mov_dppquad_perm0xb1/0x4efor masks1/2,permlane16for4/8,permlanex16for16), avoidingds_bpermute_b32traffic through the LDS pipe and cuttinggfx1201register pressure from191to168VGPRs (SPLIT=true) and160to147VGPRs (SPLIT=false) with0spills (SmemWremains21,648 B).The change
Three files changed vs
main(477ac13c) atf9b11142:src/kernels/cuda/qsa_prompt_attn.cu(+110/−38):pa_sync_lds(),dpp_tr4(),pa_xor_u32(), andpa_xor_f32()inside#if defined(__HIPCC__).prompt_attn_wmma_kernel<SPLIT>: rawuint16_tscales (Chunk::vsc_u16,Chunk::ksc_u16[2]) +u16_scale(), K-before-V global loads infetch(), V slice staged intoS.v/S.vsafter theq·KWMMAs inchunk(),pa_sync_lds()barriers,pa_xor_f32()butterfly reductions, and aligned 32-bitS.vloads +dpp_tr4()inp·V.SmemWlayout is unchanged (uint8_t v[4][WCH][WVS]withWVS = 80,21,648 Btotal).src/core/arch_defaults.cpp(+2/−0):STRATA_HIP_WMMAis intentionally excluded from thegfx12default table.src/core/arch_defaults_test.cpp(+14/−1):STRATA_HIP_WMMAis absent fromarch_default_envongfx1200/gfx1201, clears all sevengfx12env vars (STRATA_GFX12_DEFAULTS,STRATA_HIP_WMMA,STRATA_GDN_HEAD,STRATA_GDN_PP,STRATA_GDN_CONVL2,STRATA_GDN_NOY,STRATA_CVEC_FUSE) before assertingapply_arch_defaults("gfx1201").size() == 5, and verifies thatSTRATA_HIP_WMMAstays unset by default while an explicitSTRATA_HIP_WMMA=1is preserved.Evidence
All runtime measurements below were taken on commit
f9b11142vsmain(477ac13c) on an uncontended AMD Radeon AI PRO R9700 (gfx1201, 32 GB,strata.servicestopped).1. ELF Resource Usage (
llvm-readobj --notes)main→ this PR)main→ this PR)gfx1201/gfx1200prompt_attn_wmma_kernel<true>191→168(-23)32→3221,6480gfx1201/gfx1200prompt_attn_wmma_kernel<false>160→147(-13)32→3221,6480gfx1100/gfx1151prompt_attn_wmma_kernel<true>243→235(-8)32→3421,6480gfx1100/gfx1151prompt_attn_wmma_kernel<false>197→177(-20)32→3421,64802. Kernel Microbenchmark & Parity:
hip_prompt_attn_wmma(main@477ac13cvs this PR @f9b11142)1 warmup pair + 5 interleaved pairs of separately built
hip_prompt_attn_wmmabinaries (mainvsf9b11142). On HIP,hip_prompt_attn_wmmasetsSTRATA_HIP_WMMA=1inmain()and timesprompt_attn_wmma_kernel<true>against the FP32 fallback (qsa_decode_attn_batch) and an FP64 host reference.Output FNV-1a checksums (
NEWHASH) ofprompt_attn_wmma_kernel<true>are 100% bitwise identical betweenmainandf9b11142across all three shapes (FAILURES: 0):int8KV)mainWMMA (477ac13c, 5 trials / median)f9b11142, 5 trials / median)mainWMMANEWHASH(main== this PR)ctx 32768, 2048 q5.605, 5.586, 5.582, 5.608, 5.603 ms(5.603 ms)4.653, 4.666, 4.674, 4.668, 4.659 ms(4.666 ms)-16.7%(1.20×)8.28×(38.61 ms)2c5cab7eb6601f66(exact)ctx 1500, 1500 q1.755, 1.754, 1.729, 1.753, 1.652 ms(1.753 ms)1.462, 1.470, 1.461, 1.456, 1.459 ms(1.461 ms)-16.7%(1.20×)8.66×(12.65 ms)deb4f727fbac41af(exact)ctx 2100, 256 q0.742, 0.748, 0.742, 0.743, 0.738 ms(0.742 ms)0.589, 0.590, 0.595, 0.606, 0.590 ms(0.590 ms)-20.5%(1.26×)8.89×(5.25 ms)2d10cd9d6d1fd5b5(exact)Parity against FP64 and the FP32 kernel (
FAILURES: 0on all three shapes):ctx 32768, 2048 q2.64e-062.13e-066.32e-06(1.7e-06of scale3.62)ctx 1500, 1500 q3.57e-061.78e-065.25e-06(1.4e-06of scale3.57)ctx 2100, 256 q3.13e-062.03e-064.05e-06(1.1e-06of scale3.61)3. End-to-End 397B
--servePrefill A/B (Swift-Qwen3.8-Flash-Next-IQ3_S, 60 Layers / 12 QSA Layers,T = 4096)Measured via
strata --serve --kv int8 --prefill 4096 --prompt-cache 0withSTRATA_PREFILL_TIMING=1,STRATA_HIPBLASLT_TUNING,STRATA_DENSE_MMQ=1,STRATA_PF_FUSED=1,STRATA_HC_Q8=1(1warmup +3rotated-token trials per arm on idlegfx1201):qsa attnGPU Phase (12 QSA layers, trials / median)DONEPrefill Read Wall (trials / median)main(477ac13c),STRATA_HIP_WMMA=0(default FP32)706, 707, 710 ms(707 ms)1922, 1925, 1930 ms(1925 ms)1987.0, 1990.4, 1995.6 ms(1990.4 ms)2,057.9 tok/smain(477ac13c),STRATA_HIP_WMMA=1(baseline WMMA)105, 105, 106 ms(105 ms)1367, 1420, 1371 ms(1371 ms)1410.7, 1463.0, 1414.2 ms(1414.2 ms)2,896.4 tok/sf9b11142),STRATA_HIP_WMMA=1(P4 WMMA)87, 87, 87 ms(87 ms,-18 ms/-17.1%vsmainWMMA;8.13×vs FP32)1353, 1355, 1356 ms(1355 ms,-16 msvsmainWMMA)1395.9, 1397.6, 1398.4 ms(1397.6 ms,-16.6 msvsmainWMMA)2,930.8 tok/s(+1.2%vsmainWMMA;+42.4%vs FP32)4. Multi-Architecture Compilation & Policy Checks
arch_defaults_test:arch_defaults_test: OK(gfx12 (RDNA4): 5 exact speed switches on by default: GDN_HEAD GDN_PP GDN_CONVL2 GDN_NOY CVEC_FUSE;STRATA_HIP_WMMAunset by default, preserved when explicitly set).hipcc/ Clang 22.0.0): Compiledsrc/kernels/cuda/qsa_prompt_attn.cucleanly across--offload-arch=gfx1100,gfx1101,gfx1102,gfx1103,gfx1151,gfx1200,gfx1201with0register spills.nvcc13.4): Compiledsrc/kernels/cuda/qsa_prompt_attn.cucleanly across-gencode arch=compute_75,code=sm_75(Turing),-gencode arch=compute_89,code=sm_89(Ada),-gencode arch=compute_100,code=sm_100(Blackwell), and-gencode arch=compute_120,code=sm_120(Blackwell).What this does NOT fix
STRATA_HIP_WMMA=0): While this PR is bit-for-bit identical tomain'sSTRATA_HIP_WMMA=1implementation (2c5cab7eb6601f66/deb4f727fbac41af/2d10cd9d6d1fd5b5), the matrix-core path splits FP32qandpintoFP16 hi + lopairs (2.64e-06 .. 3.57e-06vs FP64, compared to1.78e-06 .. 2.13e-06for the FP32 fallback). For that reasonSTRATA_HIP_WMMA=1remains opt-in on every architecture.gfx11compiles cleanly (235VGPRs forSPLIT=true,177VGPRs forSPLIT=false,0spills), but no RDNA3 hardware runtime measurement was taken on this host.--kv k8v4prompt attention:prompt_attn_wmma_kernelapplies to--kv int8(pools.k_q4 == nullptr && pools.v_q4 == nullptr).Test plan
arch_defaults_testpasses (OK,gfx12table = 5 exact switches,STRATA_HIP_WMMAopt-in)hip_prompt_attn_wmmapasses all 3 shapes (FAILURES: 0) with identicalNEWHASHchecksums tomainongfx1201hip_prompt_attn_wmmaA/B againstmain(-16.7%,-16.7%,-20.5%)--serve --kv int84K prefill A/B (qsa attn105 → 87 ms,-17.1%; total prefill1,414.2 → 1,397.6 ms)gfx1100,gfx1101,gfx1102,gfx1103,gfx1151,gfx1200,gfx1201)sm_75,sm_89,sm_100,sm_120)Reproduction
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.