mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #3024] [CLOSED] perf(hip): optimize EXPDEC routed-expert kernels and enable by default on gfx12 #4407
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#4407
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/3024
Author: @bsorensen110
Created: 10/18/2026
Status: ❌ Closed
Base:
main← Head:perf/rdna4-d2-routed-experts📝 Commits (2)
6b88d48perf(hip): optimize EXPDEC routed-expert kernels and enable by default on gfx120d414dafix(hip): resolve EXPDEC gfx12 defaults per device and return effective down setting📊 Changes
4 files changed (+116 additions, -53 deletions)
View changed files
📝
CMakeLists.txt(+5 -7)📝
include/strata/hip_compat/cuda_runtime.h(+2 -0)📝
src/kernels/cuda/iq_kernels.cu(+90 -41)📝
src/kernels/iq_multi_parity.cpp(+19 -5)📄 Description
Summary
Optimize the grouped native routed-expert decode kernels (
src/kernels/cuda/iq_kernels.cu) for RDNA4 (gfx1200/gfx1201), enableEXPDEC(expdec_gu_kernelandexpdec_down_kernelonQ2_0) by default ongfx12, and enableexpdec_benchon HIP builds.Changes
Fix HIP
__launch_bounds__(256, MINB)wave-occupancy mapping onexpdec_gu_kernel(src/kernels/cuda/iq_kernels.cu):__launch_bounds__(256, MINB)specifiesMINBblocks per SM (4blocks =\le 64registers). On HIP (amd_hip_runtime.h), the second argument of__launch_bounds__(max_threads, min_blocks)maps directly toamdgpu_waves_per_eu(min_blocks)(waves per SIMD, not blocks per WGP). Since a 256-thread CTA has 8 waves = 2 waves/SIMD on RDNA3/RDNA4,MINB = 4requested only 4 waves/SIMD (allowing up to 256 VGPRs), soexpdec_gu_kernel<16..18, 1, 4>compiled to222–223 VGPRsongfx1201(capping occupancy at 6 waves/SIMD = 3 CTAs/WGP instead of 8 waves/SIMD = 4 CTAs/WGP).__launch_bounds__argument toMINB * 2on HIP (8waves/SIMD forMINB = 4), droppinggfx1201register usage to171–187 VGPRs(0spills,\le 192VGPRs = 4 CTAs/WGP acrossIQ2_XXS,IQ2_XS,IQ3_XXS, andIQ3_S).Vectorize
ed_stage_entryinexpdec_gu_kernelandexpdec_down_kernel:ed_stage_entry<XB, HALVES>looped overw = tid; w < XB * 9; w += 256, executing 3 integer divisions by 9 (w / 9), 3 intra-warp divergentif (j == 0)branches, and 3 scattered 4-byteds_store_b32stores per thread per staged entry.XB <= 80 <= 128(ED_XB = 80,ED_HB = 20), map the 256 threads directly as 128 thread-pairs(k = tid >> 1, h = tid & 1)where each active pair loads one 16-byte half-block (int4) and writes a single 16-byteds_store_b128tos_u, whiletid < XBwritess_ds[c * XB + tid]with zero loops, zero/ 9divisions, and zero intra-warp branch divergence.LDS-only barriers (
iq_sync_lds()) and elided first-pass pre-staging barriers:iq_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) instage_iq_grid,native_down_multi_kernel,expdec_gu_kernel, andexpdec_down_kernel, avoidingglobal_inv scope:SCOPE_SEL0 vector-cache invalidations and global load-queue drains (s_wait_loadcnt_dscnt 0x0).for (int e = e0; e < e1; ...)withif (g > (int) blockIdx.y || e > e0) iq_sync_lds();so the first pass (g == blockIdx.y && e == e0, which covers allT <= 4decode groups whengridDim.y == cap_groups) skips a redundant barrier.Enable
EXPDEC(STRATA_EXPDEC=1,STRATA_EXPDEC_DOWN=1) by default ongfx12and enableexpdec_benchon HIP:expdec_on()andexpdec_down_on()to1ongfx1200/gfx1201(expdec_default_gfx12()) whenSTRATA_EXPDEC/STRATA_EXPDEC_DOWNare unset (STRATA_EXPDEC=0orSTRATA_EXPDEC_DOWN=0turns them off; non-gfx12architectures remain unchanged).expdec_notestderr logging on explicitSTRATA_EXPDEC=1.expdec_benchtarget on HIP builds inCMakeLists.txtand mapcudaDevAttrMemoryClockRate/cudaDevAttrGlobalMemoryBusWidthininclude/strata/hip_compat/cuda_runtime.h.iq_multi_parity(check_grouped) to verify bitwise equality of bothmulti(EXPDEC=0) andexpdec(EXPDEC=1, EXPDEC_DOWN=1, EXPDEC_D20=1) against the reference per-entry kernels across all format pairs.Validation & Benchmarks (
gfx1201, AMD Radeon AI PRO R9700)1. Bitwise Parity & Multi-Arch Compilation
./build-copilot-hip/iq_multi_parity:0 failuresacross all 18iq_mmvqchecks, 24native_expert_groupedchecks (testing bothmultiandexpdecagainstold), and 3q8_1 finitechecks../build-copilot-hip/expdec_bench 150 0 20 18/20,21/20,22/20,18/42,21/42,22/42 def,dec,dec:w1 real:identical(0 choice comparisons differ) across all 6 format pairs andT = 1..4.gfx1100,gfx1151,gfx1200,gfx1201) and NVIDIA CUDA (sm_75,sm_89,sm_100).2. Cold Routed-Expert Microbenchmark (
./build-copilot-hip/expdec_bench 150 0 20 ..., 150 reps\times5 rounds over 121–186 MB cold expert pools)gu/down)Tdef(all / gu / down, us)gfx12DefaultEXPDEC(all / gu / down, us)18/20(IQ3_XXS / IQ4_NL, 14 layers)158.7 / 34.6 / 18.954.7 / 31.0 / 18.9-6.8%(1.073x)gu:-10.4%18/20(IQ3_XXS / IQ4_NL, 14 layers)2103.0 / 62.0 / 35.594.1 / 53.4 / 35.6-8.6%(1.095x)gu:-13.9%18/20(IQ3_XXS / IQ4_NL, 14 layers)3107.6 / 65.0 / 37.298.7 / 56.3 / 37.1-8.3%(1.090x)gu:-13.4%18/20(IQ3_XXS / IQ4_NL, 14 layers)4111.6 / 68.0 / 38.6102.8 / 59.4 / 38.3-7.9%(1.086x)gu:-12.6%21/20(IQ3_S / IQ4_NL, 9 layers)162.6 / 37.8 / 18.958.8 / 35.5 / 19.5-6.1%(1.065x)gu:-6.1%21/20(IQ3_S / IQ4_NL, 9 layers)2108.8 / 68.5 / 35.7101.2 / 60.6 / 35.8-7.0%(1.075x)gu:-11.5%21/20(IQ3_S / IQ4_NL, 9 layers)3112.7 / 71.0 / 37.2103.5 / 61.6 / 37.5-8.2%(1.089x)gu:-13.2%21/20(IQ3_S / IQ4_NL, 9 layers)4116.0 / 72.9 / 38.8107.6 / 64.8 / 39.0-7.2%(1.078x)gu:-11.1%22/20(IQ2_S / IQ4_NL, 15 layers)2101.5 / 59.4 / 35.796.4 / 54.7 / 36.2-5.0%(1.053x)gu:-7.9%22/20(IQ2_S / IQ4_NL, 15 layers)4111.5 / 67.4 / 38.8106.7 / 63.0 / 39.0-4.3%(1.045x)gu:-6.5%18/42(IQ3_XXS / Q2_0, 3 layers)297.7 / 62.9 / 31.379.3 / 54.0 / 22.7-18.8%(1.232x)gu:-14.1%,down:-27.5%18/42(IQ3_XXS / Q2_0, 3 layers)4107.9 / 68.7 / 35.388.9 / 60.1 / 26.3-17.6%(1.214x)gu:-12.5%,down:-25.5%21/42(IQ3_S / Q2_0, 1 layer)2104.0 / 68.2 / 32.186.5 / 60.7 / 23.2-16.8%(1.202x)gu:-11.0%,down:-27.7%21/42(IQ3_S / Q2_0, 1 layer)4112.2 / 72.5 / 36.393.8 / 64.9 / 26.6-16.4%(1.196x)gu:-10.5%,down:-26.7%22/42(IQ2_S / Q2_0, 5 layers)296.9 / 60.8 / 31.981.6 / 54.9 / 22.8-15.8%(1.188x)gu:-9.7%,down:-28.5%22/42(IQ2_S / Q2_0, 5 layers)4108.6 / 68.6 / 35.792.7 / 64.5 / 26.4-14.6%(1.172x)gu:-6.0%,down:-26.1%3. End-to-End 397B
--serveDecode A/B (Swift-Qwen3.8-Flash-Next-IQ3_S,--spec 4 --kv k8v4, 256 tokens, 5 matched deterministic prompts)STRATA_EXPDEC=0(legacynative_gu_multi_kernel+native_down_multi_kernel):256tokens each, identical draft acceptance on all 5 prompts):2766.0 ms(92.60 tok/s),2696.0 ms(95.00 tok/s),2731.0 ms(93.80 tok/s),1989.0 ms(128.70 tok/s),2118.0 ms(120.90 tok/s)1,280generated tokens):12,300.0 ms(104.07 tok/s)gfx12Default (STRATA_EXPDEC=1 STRATA_EXPDEC_DOWN=1):256tokens each, winning5/5prompts by-21.0to-25.0 ms):2741.0 ms(93.40 tok/s),2671.0 ms(95.90 tok/s),2706.0 ms(94.60 tok/s),1965.0 ms(130.20 tok/s),2097.0 ms(122.10 tok/s)1,280generated tokens):12,180.0 ms(105.09 tok/s,-120.0 ms/+0.98%)--adapt-async 15-trial median (256tokens):103.40 -> 106.20 tok/s(2475.0 -> 2412.0 ms,+2.71%/-63.0 ms).🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.