[PR #3164] [CLOSED] [Engine] hip: STRATA_SELECT_GRID=2 - the selection scorer's CTA order swaps for L2 (bitwise identical) #4487

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

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/3164
Author: @vlupilin
Created: 10/19/2026
Status: ❌ Closed

Base: main ← Head: pr-grid-swap


📝 Commits (1)

  • 5b2de23 hip: STRATA_SELECT_GRID=2 - the selection scorer's CTA order swaps for L2 (bitwise identical)

📊 Changes

1 file changed (+26 additions, -4 deletions)

View changed files

📝 src/kernels/cuda/qsa_select.cu (+26 -4)

📄 Description

Problem and result

The WMMA scorer CTA order puts all key tiles of query-tile 0 first: each of 16 query-tiles re-reads the pooled key array from DRAM because L2 (8 MiB) cannot hold it. With STRATA_SELECT_GRID=2 the grid dimensions swap so CTAs sharing a key tile run together and L2 holds it for all of them. Output is bitwise identical (only the scheduling order of independent CTAs moves).

Approach

Template parameter bool XQ mapping blockIdx to query/block tiles; opt-in env STRATA_SELECT_GRID=0|1|2 with adaptive threshold STRATA_SELECT_GRID_MIN (default 8192 blocks). Default 0 = unchanged. One file: src/kernels/cuda/qsa_select.cu (+26/-4).

Validation

Passed:

Kernel benchmark (both arms same session, 5 reps, v0.2.0-beta @ 4caf857c, gfx1151 Radeon 8060S Strix Halo, ROCm 10.1, Linux 7.0.0-38-generic):

LD_LIBRARY_PATH=/opt/rocm/lib STRATA_SELECT_WMMA=1 STRATA_SELECT_GRID=0 ./build-rocm101/qsa_select_bench 32768 256 5 32768
LD_LIBRARY_PATH=/opt/rocm/lib STRATA_SELECT_WMMA=1 STRATA_SELECT_GRID=2 STRATA_SELECT_GRID_MIN=0 ./build-rocm101/qsa_select_bench 32768 256 5 32768
# (repeated for 131072, 262144, 524288)
context old order swapped speedup
32768 0.818 ms 0.756 ms 1.08x
131072 2.468 ms 2.368 ms 1.04x
262144 8.429 ms 7.831 ms 1.08x
524288 13.316 ms 10.669 ms 1.25x

Engine (interleaved 2 rounds, grid measured alone):

# baseline: STRATA_SELECT_GRID=0, test: STRATA_SELECT_GRID=2
# bench.py --lens 131072,262144,524288 --prod-params --salt 150
depth mainline +grid delta
131072 946.8 946.8 0.0%
262144 1002.8 1014.1 +1.1%
524288 928.1 944.1 +1.7%

Bitwise identical ids: verified 256/256 at all depths (qsa_select_bench gate).

Failed: none.

Not run: CUDA (kernel is HIP-only); gfx12 (maintainer R9700 can verify); shallow-context regression check below 8192 blocks (the adaptive threshold prevents the swap there).

Limits

HIP only; requires STRATA_SELECT_WMMA=1; the engine effect is depth-dependent (bigger at 512K+ where the selection cost is highest).


🔄 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/3164 **Author:** [@vlupilin](https://github.com/vlupilin) **Created:** 10/19/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr-grid-swap` --- ### 📝 Commits (1) - [`5b2de23`](https://github.com/Niko1221/Strata/commit/5b2de23403cbf9d65973c496aaa7db9d64b2b15d) hip: STRATA_SELECT_GRID=2 - the selection scorer's CTA order swaps for L2 (bitwise identical) ### 📊 Changes **1 file changed** (+26 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `src/kernels/cuda/qsa_select.cu` (+26 -4) </details> ### 📄 Description ## Problem and result The WMMA scorer CTA order puts all key tiles of query-tile 0 first: each of 16 query-tiles re-reads the pooled key array from DRAM because L2 (8 MiB) cannot hold it. With `STRATA_SELECT_GRID=2` the grid dimensions swap so CTAs sharing a key tile run together and L2 holds it for all of them. Output is bitwise identical (only the scheduling order of independent CTAs moves). ## Approach Template parameter `bool XQ` mapping blockIdx to query/block tiles; opt-in env `STRATA_SELECT_GRID=0|1|2` with adaptive threshold `STRATA_SELECT_GRID_MIN` (default 8192 blocks). Default 0 = unchanged. One file: `src/kernels/cuda/qsa_select.cu` (+26/-4). ## Validation **Passed:** Kernel benchmark (both arms same session, 5 reps, v0.2.0-beta @ 4caf857c, gfx1151 Radeon 8060S Strix Halo, ROCm 10.1, Linux 7.0.0-38-generic): ``` LD_LIBRARY_PATH=/opt/rocm/lib STRATA_SELECT_WMMA=1 STRATA_SELECT_GRID=0 ./build-rocm101/qsa_select_bench 32768 256 5 32768 LD_LIBRARY_PATH=/opt/rocm/lib STRATA_SELECT_WMMA=1 STRATA_SELECT_GRID=2 STRATA_SELECT_GRID_MIN=0 ./build-rocm101/qsa_select_bench 32768 256 5 32768 # (repeated for 131072, 262144, 524288) ``` | context | old order | swapped | speedup | |---|---:|---:|---:| | 32768 | 0.818 ms | 0.756 ms | 1.08x | | 131072 | 2.468 ms | 2.368 ms | 1.04x | | 262144 | 8.429 ms | 7.831 ms | 1.08x | | 524288 | 13.316 ms | 10.669 ms | 1.25x | Engine (interleaved 2 rounds, grid measured alone): ``` # baseline: STRATA_SELECT_GRID=0, test: STRATA_SELECT_GRID=2 # bench.py --lens 131072,262144,524288 --prod-params --salt 150 ``` | depth | mainline | +grid | delta | |---|---:|---:|---:| | 131072 | 946.8 | 946.8 | 0.0% | | 262144 | 1002.8 | 1014.1 | +1.1% | | 524288 | 928.1 | 944.1 | +1.7% | Bitwise identical ids: verified 256/256 at all depths (qsa_select_bench gate). **Failed:** none. **Not run:** CUDA (kernel is HIP-only); gfx12 (maintainer R9700 can verify); shallow-context regression check below 8192 blocks (the adaptive threshold prevents the swap there). ## Limits HIP only; requires `STRATA_SELECT_WMMA=1`; the engine effect is depth-dependent (bigger at 512K+ where the selection cost is highest). --- <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:23 +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#4487
No description provided.