mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #2997] [CLOSED] perf(hip): enable fused_gr tsum on gfx12, fix q8_inject guard, and use LDS-only barriers #4389
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#4389
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/2997
Author: @bsorensen110
Created: 10/18/2026
Status: ❌ Closed
Base:
main← Head:perf/rdna4-d1-hc-q8-decode📝 Commits (3)
7da9c35fix(kernels): fix STRATA_HC_Q8 q8_inject guard and STRATA_TSUM q32 dispatch (D1)ceff3a5fix: change qfuse poison value from 0x5a to 0xff to detect unwritten injection outputd09a7b3perf(hip): enable fused_gr tsum on gfx12, upgrade gr_up_q32_kernel, and use LDS-only barriers📊 Changes
2 files changed (+234 additions, -81 deletions)
View changed files
📝
src/kernels/cuda/fused_gr.cu(+131 -80)📝
src/kernels/gr_parity.cpp(+103 -1)📄 Description
Summary
Optimize the multi-token fused hyperconnection (HC) decode read path (
src/kernels/cuda/fused_gr.cu) across bothSTRATA_HC_Q8=1(launch_q8_t) andSTRATA_HC_Q8=0(gr_up_q32_kernel), and enable the transposed butterfly reduction (s26ts::tsum) insidefused_gr.cuby default on RDNA4 (gfx1200/gfx1201) viagr_tsum_on()without affectingSTRATA_TSUMinnative_mmvq/native_bf16.Changes
Fix
q8_injectguard in Q8 up-projection kernels (STRATA_HC_Q8=1):gr_up_q8_kernel,gr_up_q8_q32_kernel, andgr_up_q8_fast_kernel(src/kernels/cuda/fused_gr.cu), check(m.a[k].w_inject == nullptr && m.a[k].q8_inject == nullptr)instead ofm.a[k].w_inject == nullptrwhen reducing theHCinject rows inblockIdx.x == 0, so callers that passq8_injectwithw_inject == nullptrstill writeinject_out.cudaMemsetAsync(ssg, 0, ...)and intermediatecudaStreamSynchronize(st)infused_gr_quantize_q8_0.Transposed butterfly reduction (
s26ts::tsum) + parallelowner-lane preloads ingr_up_q32_kernelandgr_up_q8_q32_kernel:template <int T, bool TS = false> gr_up_q8_q32_kernelandtemplate <int MAX_T, bool EXACT_T, bool TS = false> gr_up_q32_kernel:Tsequentialwarp_sum(acc)reductions with a single transposed butterfly reductions26ts::tsum<P>(acc, lane)across power-of-twoP = pow2_ceil(T)tokens (v_permlane16_swap_b32+ DPP row butterfly on RDNA3/RDNA4).R[i],w_norm[i],bo_prev[d0 + dd], andinj_prev[c]in parallel acrossownerlanes (lane == s26ts::tsum_lane<P>(tk) && tk < T) before thelo[k]dot loop so global memory latency is hidden behind LDS dot products.#pragma unroll 2to the8-row per-warp loop.gfx1201, this lowers register usage acrossT = 1..6and keepsT = 5, 6under the96 VGPRthreshold needed for 2 CTAs/WGP (16 waves/SIMD, 512 threads/CTA):gr_up_q8_q32_kernel<T, false>(53 / 69 / 78 / 89 / 99 / 109 VGPRs)\rightarrowgr_up_q8_q32_kernel<T, true>(45 / 59 / 68 / 77 / 86 / 95 VGPRs).gr_up_q32_kernel<T, true, false>(48 / 70 / 80 / 90 / 100 / 110 VGPRs)\rightarrowgr_up_q32_kernel<T, true, true>(40 / 61 / 69 / 78 / 87 / 96 VGPRs).gr_down_q8_kernel<T>(93 / 119 / 139 / 159 / 179 / 199 / 208 VGPRs)\rightarrowgr_down_q8_fast_kernel<T, 4>(88 / 106 / 123 / 142 / 163 / 178 / 189 VGPRs, keepingT = 6, 7\le 192VGPRs for 2 CTAs/WGP).LDS-only barriers (
gr_sync_lds()):__syncthreads()insidegr_up_q32_kernel,gr_down_q8_kernel,gr_down_q8_fast_kernel, andgr_up_q8_q32_kernelwithgr_sync_lds()(s_wait_dscnt 0x0; s_barrier_signal -1; s_barrier_wait -1ongfx1200/gfx1201,s_waitcnt lgkmcnt(0); s_barrieron other HIP targets,__syncthreads()on CUDA).lo,rsS,red,g); usinggr_sync_lds()avoids emittingglobal_inv scope:SCOPE_SE(960Shader Engine L0 cache invalidations pergr_up_q8_q32_kernellaunch and324pergr_down_q8_fast_kernellaunch) and avoids stalling in-flight global loads (s_wait_loadcnt_dscnt 0x0).Default enablement on
gfx12(gr_tsum_on()):gr_tsum_on()insrc/kernels/cuda/fused_gr.cu, which checksSTRATA_GR_TSUM(0|1), thenSTRATA_TSUM(0|1), and otherwise defaults tonorm_fast_on()(ON by default ongfx1200/gfx1201, OFF on other architectures).gfx12default tofused_gr.cuavoids turning onSTRATA_TSUM=1innative_mmvq.cuandnative_bf16.cu.Validation & Benchmarks (
gfx1201, AMD Radeon AI PRO R9700)1. Correctness (
gr_parity --selftest&fused_gr_bench)src/kernels/gr_parity.cpp(fused_multi_lds_parity) to test:STRATA_QFUSE(gr_up_q32_kernel) bitwise equality acrossSTRATA_TSUM=0andSTRATA_TSUM=1forT = 1..8;STRATA_HC_Q8=1(q8_down+q8_up+q8_injectwithw_inject == nullptrandq8_inject == nullptrwithw_inject != nullptr) acrossT = 1..8, asserting bitwise-identicalR_out,rs,inject_out,mixed, andq8_mixedoutputs betweenSTRATA_TSUM=0andSTRATA_TSUM=1../build-copilot-hip/gr_parity --selftest:STRATA_BENCH_QMIXED=1 ./build-copilot-hip/fused_gr_bench 200 1 6 16:0 differingand identical output hashes acrossT = 1..6(apply = 0, 1) betweenSTRATA_GR_TSUM=0andSTRATA_GR_TSUM=1.gfx1100,gfx1151,gfx1200,gfx1201) and NVIDIA CUDA (sm_75,sm_89,sm_100,sm_120).2. Microbenchmark (
STRATA_BENCH_QMIXED=1 ./build-copilot-hip/fused_gr_bench 200 1 6 16, cold 16-set rotation)TSTRATA_GR_TSUM=0read (us)STRATA_GR_TSUM=1(gfx12default) read (us)norm / down / up, us)fast 2(STRATA_HC_Q8=1)123.423.6+0.9%2.8 / 13.8 / 15.5\rightarrow2.8 / 13.6 / 15.8fast 2(STRATA_HC_Q8=1)227.726.6-4.0%(1.041x)2.8 / 15.1 / 18.5\rightarrow2.8 / 14.2 / 18.2fast 2(STRATA_HC_Q8=1)332.630.5-6.4%(1.069x)2.8 / 18.0 / 20.3\rightarrow2.8 / 15.8 / 20.0fast 2(STRATA_HC_Q8=1)435.731.6-11.5%(1.130x)2.8 / 20.0 / 21.4\rightarrow2.8 / 16.6 / 20.8fast 2(STRATA_HC_Q8=1)539.233.8-13.8%(1.160x)2.8 / 22.3 / 22.7\rightarrow2.8 / 17.4 / 22.0fast 2(STRATA_HC_Q8=1)642.635.7-16.2%(1.193x)2.8 / 23.9 / 24.3\rightarrow3.0 / 18.6 / 23.2fast 1(STRATA_HC_Q8=0,gr_up_q32_kernel)666.264.1-3.2%(1.033x)12.5 / 38.5 / 23.6\rightarrow12.5 / 38.6 / 21.6(up:-8.5%)3. End-to-End 397B
--serveDecode A/B (Swift-Qwen3.8-Flash-Next-IQ3_S,--spec 4 --kv k8v4, 256 tokens, 2 warmups + 5 measured trials)STRATA_GR_TSUM=0(legacywarp_sum): median102.10 tok/s(2508.0 ms; trials:106.60,100.60,101.10,118.70,102.10 tok/s)STRATA_GR_TSUM=1(gfx12defaulttsum+gr_sync_lds): median103.20 tok/s(2482.0 ms,+1.08%/-26.0 ms; trials:100.40,103.00,103.20,109.10,108.40 tok/s)🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.