mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #603] [CLOSED] qsa_select: a 1,024-thread top-k past the register kernel's reach (CUDA) - a 243K-token prompt +26% on an RTX 3060 #2718
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#2718
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/603
Author: @asp345
Created: 10/3/2026
Status: ❌ Closed
Base:
main← Head:qsa-topk-long-context📝 Commits (1)
6ba9698qsa_select: the top-k past the register kernel's reach on 1,024 threads with a histogram per warp (CUDA) - 9-12x at 262K-524K cells, a 243K-token prompt +26% on an RTX 3060📊 Changes
4 files changed (+278 additions, -5 deletions)
View changed files
📝
CMakeLists.txt(+7 -0)📝
include/strata/kernels/qsa_select.hpp(+2 -1)📝
src/kernels/cuda/qsa_select.cu(+130 -4)➕
src/kernels/qsa_topk_parity.cpp(+139 -0)📄 Description
What
On CUDA the register kernel (
block_topk_reg_kernel) holds 33,792 blocks (~135K cells). Past that,qsa_block_topktakes the original kernel (block_topk_kernel): 256 threads, each reading its own stretch of the scores on all six passes, and one shared histogram updated with atomics. The dispatch follows the capacity (--max-context), so with--max-context 262144:This adds one kernel for that range,
block_topk_wide_kernel: the register kernel's layout (1,024 threads, a histogram per warp, warp scans) with the keys read from memory instead of registers.treads blockst,t + 1024, ...: a histogram has no order, so a warp reads 32 neighbours at a time.wholdsperrows of 32 consecutive blocks, and the cells are written in the order (warp, row, lane). The per-warp counts give each warp its first output position and the tied cells before it; a row without a selected block is skipped.STRATA_TOPK_OLD=1keeps the original kernel, as before.qsa_topk_parity(new, next to the other kernel parity tests) compares the dispatched top-k withqsa_block_topk_ref.Relation to #575
#575 covers the same range with a split: the register kernel on two halves of the blocks, then a merge kernel. I built #575 (
cb29a2a) and this branch on the same base (99f3dbd, 0.1.38) and measured both on the same RTX 3060; the numbers are in the tables below.--max-context: the 8K, 16K and 32K prompts spend more time in the selection than stock does.I have no RTX 3090, so I cannot say how the two compare on #575's test card.
Measured
Setup: RTX 3060 12 GB (sm_86) on PCIe x16, Ryzen 5 5600X, 48 GB DDR4-2933, Debian 13, CUDA 13.4, base
99f3dbd(0.1.38). Qwen3.8-Flash-Next IQ3_XXS on that one card,--resident-experts --max-context 262144 --kv int8 --kv-resident 32768 --prefill auto --spec 4.Kernel (
qsa_topk_parity CONTEXT 256 50 CAPACITY: 256 queries with their block count, capacity 262,144 cells, the last two rows 524,288; ms per call). "Register" is #512's dispatch forced on this card withSTRATA_TOPK_ACTIVE_ANY=1; it stops at 33,792 blocks, and its column is from a separate run of the same tool.Between ~20K and ~110K cells the register kernel is faster than this one by up to 0.15 ms per call; I left #512's restriction to sm_75 as it is.
A decode window's call (4 queries, no block count, capacity 262,144): 0.031 -> 0.029 ms at 2,100 cells, 0.031 -> 0.028 at 8,192, 0.054 -> 0.034 at 32,768, 0.176 -> 0.083 at 131,072, 0.309 -> 0.127 at 262,144. #575 leaves these calls on the original kernel.
Prompts (
tools/needle_bench.py --depths 50, a fresh engine per run,STRATA_PREFILL_TIMING=1in every run; "original" is this branch withSTRATA_TOPK_OLD=1). Several values in a cell are separate runs. Where a prompt reused a 16,384- or 32,768-token checkpoint of the previous prompt in the same engine, the tokens read are in brackets; the reuse is the same in every arm.Prompt speed, tok/s:
The 243K prompt takes 260 s instead of 327 s.
The selection phase of the prompt path (
qsa selectin the timing line: the block scores and the top-k), ms:The 7,884-token prompt is the first of each engine and its tok/s varies from run to run in every arm (600 to 925 overall), so it is in the selection table only. With #512's dispatch forced on this card (
STRATA_TOPK_ACTIVE_ANY=1, one run) the selection takes 96, 286, 810 and 8,842 ms at 7,884, 16,471, 31,970 and 122,755 tokens, and the 122,755-token prompt reads at 998.2 tok/s.Other setups (the same model and flags,
STRATA_TOPK_OLD=1against the default, tok/s of the prompt):--mmap-expertsDecode (the x16 card, one long prompt, then 512 tokens generated three times, greedy, tok/s):
Repeated requests of one prompt do not always produce the same text, also within one arm, so only requests with identical text compare like for like. At 243K the first two requests produced identical text in both arms: 15.3 -> 14.9 s and 14.3 -> 14.0 s for the 512 tokens. At 122K no request pair has identical text, and the arms differ by less than the requests of one arm do.
Test
qsa_topk_parity --selfteston both cards: 9 context / capacity pairs (9K; both sides of the register kernel's reach at 135,160 and 135,176 cells; 2,100, 9K and 32K under a 262K capacity; 262K; 300K under 524K; 524K), each called as a decode window calls it (8 queries, no block count) and as the prompt path does (64 queries with their block count), each with continuous scores, 64 score levels and equal scores. All 18 cases: identical ids. It also passes withSTRATA_TOPK_ACTIVE_ANY=1, where a counted call past 33,792 blocks takes the new kernel.qsa_topk_active_parity(#512's test) passes on both cards; with this change its call without a bound takes the new kernel at the 262,144 capacity.decode_cluster_parityskips on these cards (below sm_90).Not run: a HIP build (the kernel and its dispatch branch are inside
#if !defined(__HIPCC__)), and a card other than the RTX 3060.🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.