mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #3108] [CLOSED] [Engine] perf(hip): optimize exact QSA block scoring and top-k selection on gfx12 #4458
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#4458
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/3108
Author: @bsorensen110
Created: 10/18/2026
Status: ❌ Closed
Base:
main← Head:perf/rdna4-d7-qsa-select📝 Commits (2)
c195690perf(hip): optimize exact QSA block scoring and top-k selection on gfx12f5412a8test(hip): independently verify exact QSA score and rows parity📊 Changes
4 files changed (+481 additions, -141 deletions)
View changed files
📝
CMakeLists.txt(+15 -0)📝
src/kernels/cuda/qsa_select.cu(+235 -139)📝
src/kernels/qsa_rows_bench.cpp(+54 -1)📝
src/kernels/qsa_scores_parity.cpp(+177 -1)📄 Description
Problem and result
This PR optimizes the exact QSA block-scoring and radix top-k selection kernels in
src/kernels/cuda/qsa_select.cuon RDNA4 (gfx1200/gfx1201) and wave32 HIP targets with 100% bitwise parity:__shfl_xor_syncreductions withv_permlanex16_b32/v_mov_b32_dppto keep reductions on VALU pipe, replaces device-scope__syncthreads()in LDS-only selection/scoring loops with workgroup-scopedsel_sync_lds()(waits on bothloadcnt(0)anddscnt(0)to avoid L2 cache-invalidation while safe when divergent paths skip VMEM blocks).PERspecializations & parallelized scans: Addsblock_topk_reg_kernel<2,9,17>for small block counts, lowers HIP prefill crossoverkRegMinBlocksfrom 7,168 to 4,096, replaces single-thread 256-iteration radix-bin search and 32-warp prefix loops with parallel 8-warp/1-warp prefix scans inblock_topk_kernel/block_topk_wide_kernel.br(64/128/256/512) with__launch_bounds__(256,2)and lowers default gfx12 activation threshold toactive_blocks >= 512(ctx >= 2,048).Related discussion
none
Approach
On wave32 HIP targets,
__shfl_xor_synclowers tods_bpermute_b32on LDS/DS pipe, causing overhead. Usingv_permlanex16_b32(MASK=16) andv_mov_b32_dpp(row_xmask:1|2|4|8, 0x160|MASK) keeps reductions on VALU pipe while summing exact same lane pairs in exact same tree order. Device-scope__syncthreads()inside loops causes unnecessary L2 cache-invalidation; workgroup-scopedsel_sync_lds()waits on bothloadcnt(0)anddscnt(0)to avoid L2 cache-invalidation overhead while safe when divergents_cbranch_execzpaths skip a VMEM basic block. SmallerPERspecializations reduce VGPR/SGPR pressure and spills for small block counts. Parallelized scans replace inefficient serial loops with warp-level prefix sums, improving occupancy. Dynamic grid granularity (br) and lower activation threshold improve utilization of wavefronts at moderate context sizes.Validation
Passed:
qsa_scores_parity: revisione88ee39d, GPU AMD Radeon AI PRO R9700 (gfx1201), observed PASS (zero bitwise differences, includes independent pre-PR baseline scorer)qsa_topk_active_parity: revisione88ee39d, GPU AMD Radeon AI PRO R9700 (gfx1201), observed PASS (selected IDs bitwise identical)qsa_rows_bench --rows: revisione88ee39d, GPU AMD Radeon AI PRO R9700 (gfx1201), observed PASS (runs without error, validates nq=5–8 and partial tails via internal checks)arch_defaults_test: revisione88ee39d, GPU AMD Radeon AI PRO R9700 (gfx1201), observed PASSFailed:
Not run:
Limits
br) and activation threshold are tuned for gfx1201; may require adjustment for other GPUs.PERspecializations (PER = 2,9,17) are limited to block counts within their respective reach; larger blocks still use existing kernels.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.