[PR #3108] [CLOSED] [Engine] perf(hip): optimize exact QSA block scoring and top-k selection on gfx12 #4458

Closed
opened 2026-11-07 15:36:11 +07:00 by bsakaguchi · 0 comments
Owner

📋 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)

  • c195690 perf(hip): optimize exact QSA block scoring and top-k selection on gfx12
  • f5412a8 test(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.cu on RDNA4 (gfx1200/gfx1201) and wave32 HIP targets with 100% bitwise parity:

  1. Wave32 VALU DPP reductions & workgroup-scoped barriers: Replaces __shfl_xor_sync reductions with v_permlanex16_b32/v_mov_b32_dpp to keep reductions on VALU pipe, replaces device-scope __syncthreads() in LDS-only selection/scoring loops with workgroup-scoped sel_sync_lds() (waits on both loadcnt(0) and dscnt(0) to avoid L2 cache-invalidation while safe when divergent paths skip VMEM blocks).
  2. Smaller-PER specializations & parallelized scans: Adds block_topk_reg_kernel<2,9,17> for small block counts, lowers HIP prefill crossover kRegMinBlocks from 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 in block_topk_kernel/block_topk_wide_kernel.
  3. Prompt exact block-scorer grid granularity & threshold: Passes dynamic br (64/128/256/512) with __launch_bounds__(256,2) and lowers default gfx12 activation threshold to active_blocks >= 512 (ctx >= 2,048).

Related discussion
none

Approach
On wave32 HIP targets, __shfl_xor_sync lowers to ds_bpermute_b32 on LDS/DS pipe, causing overhead. Using v_permlanex16_b32 (MASK=16) and v_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-scoped sel_sync_lds() waits on both loadcnt(0) and dscnt(0) to avoid L2 cache-invalidation overhead while safe when divergent s_cbranch_execz paths skip a VMEM basic block. Smaller PER specializations 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: revision e88ee39d, GPU AMD Radeon AI PRO R9700 (gfx1201), observed PASS (zero bitwise differences, includes independent pre-PR baseline scorer)
  • qsa_topk_active_parity: revision e88ee39d, GPU AMD Radeon AI PRO R9700 (gfx1201), observed PASS (selected IDs bitwise identical)
  • qsa_rows_bench --rows: revision e88ee39d, 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: revision e88ee39d, GPU AMD Radeon AI PRO R9700 (gfx1201), observed PASS

Failed:

  • none observed

Not run:

  • CUDA builds (no CUDA toolchain available)
  • SYCL builds (no SYCL toolchain available)
  • Metal builds (no Metal support)

Limits

  • The optimizations target wave32 HIP targets; non-wave32 HIP targets retain existing behavior.
  • The grid granularity heuristic (br) and activation threshold are tuned for gfx1201; may require adjustment for other GPUs.
  • The smaller-PER specializations (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.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/3108 **Author:** [@bsorensen110](https://github.com/bsorensen110) **Created:** 10/18/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `perf/rdna4-d7-qsa-select` --- ### 📝 Commits (2) - [`c195690`](https://github.com/Niko1221/Strata/commit/c1956908f0171a4df65b42206b1d9f6aad3129d7) perf(hip): optimize exact QSA block scoring and top-k selection on gfx12 - [`f5412a8`](https://github.com/Niko1221/Strata/commit/f5412a80be579fd00930d54134d7b53e7ab45f62) test(hip): independently verify exact QSA score and rows parity ### 📊 Changes **4 files changed** (+481 additions, -141 deletions) <details> <summary>View changed files</summary> 📝 `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) </details> ### 📄 Description **Problem and result** This PR optimizes the exact QSA block-scoring and radix top-k selection kernels in `src/kernels/cuda/qsa_select.cu` on RDNA4 (`gfx1200`/`gfx1201`) and wave32 HIP targets with 100% bitwise parity: 1. **Wave32 VALU DPP reductions & workgroup-scoped barriers**: Replaces `__shfl_xor_sync` reductions with `v_permlanex16_b32`/`v_mov_b32_dpp` to keep reductions on VALU pipe, replaces device-scope `__syncthreads()` in LDS-only selection/scoring loops with workgroup-scoped `sel_sync_lds()` (waits on both `loadcnt(0)` and `dscnt(0)` to avoid L2 cache-invalidation while safe when divergent paths skip VMEM blocks). 2. **Smaller-`PER` specializations & parallelized scans**: Adds `block_topk_reg_kernel<2,9,17>` for small block counts, lowers HIP prefill crossover `kRegMinBlocks` from 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 in `block_topk_kernel`/`block_topk_wide_kernel`. 3. **Prompt exact block-scorer grid granularity & threshold**: Passes dynamic `br` (64/128/256/512) with `__launch_bounds__(256,2)` and lowers default gfx12 activation threshold to `active_blocks >= 512` (ctx >= 2,048). **Related discussion** none **Approach** On wave32 HIP targets, `__shfl_xor_sync` lowers to `ds_bpermute_b32` on LDS/DS pipe, causing overhead. Using `v_permlanex16_b32` (MASK=16) and `v_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-scoped `sel_sync_lds()` waits on both `loadcnt(0)` and `dscnt(0)` to avoid L2 cache-invalidation overhead while safe when divergent `s_cbranch_execz` paths skip a VMEM basic block. Smaller `PER` specializations 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`: revision e88ee39d, GPU AMD Radeon AI PRO R9700 (gfx1201), observed PASS (zero bitwise differences, includes independent pre-PR baseline scorer) - `qsa_topk_active_parity`: revision e88ee39d, GPU AMD Radeon AI PRO R9700 (gfx1201), observed PASS (selected IDs bitwise identical) - `qsa_rows_bench --rows`: revision e88ee39d, 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`: revision e88ee39d, GPU AMD Radeon AI PRO R9700 (gfx1201), observed PASS **Failed:** - none observed **Not run:** - CUDA builds (no CUDA toolchain available) - SYCL builds (no SYCL toolchain available) - Metal builds (no Metal support) **Limits** - The optimizations target wave32 HIP targets; non-wave32 HIP targets retain existing behavior. - The grid granularity heuristic (`br`) and activation threshold are tuned for gfx1201; may require adjustment for other GPUs. - The smaller-`PER` specializations (`PER = 2,9,17`) are limited to block counts within their respective reach; larger blocks still use existing kernels. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 15:36:11 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#4458
No description provided.