Repository navigation
cuda : dispatch batched top-k to the argsort path instead of per-row DeviceTopK - #28129
Closed
abdel-darwish-27 wants to merge 1 commit into
Closed
abdel-darwish-27 wants to merge 1 commit into
abdel-darwish-27 wants to merge 1 commit into
Conversation
…DeviceTopK With CCCL >= 3.2 available, ggml_cuda_op_top_k runs cub::DeviceTopK::MaxPairs in a serial per-row loop. Decode-shaped calls (nrows == 1) are fine, but prompt processing hands this op hundreds of rows at once: profiling one 141K-token prefill of a qwen4exp model showed 903,702 DeviceTopK invocations (512-row ubatches x 12 QSA layers), each launching 3-4 kernels. Keep DeviceTopK for nrows <= 4 and dispatch larger batches to the existing row-parallel argsort+copy path until DeviceSegmentedTopK exists (NVIDIA/cccl#6391).
|
Hi @abdel-darwish-27, thanks for your contribution! Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:
Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below. |
This was referenced Sep 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
With CCCL >= 3.2 (
GGML_CUDA_CUB_3DOT2=ON),ggml_cuda_op_top_krunscub::DeviceTopK::MaxPairsin a serial per-row loop. Decode-shaped calls (nrows == 1) are fine, but prompt processing hands this op hundreds of rows at once: profiling one 141K-token prefill of a qwen4exp model (512-row ubatches x 12 QSA layers) showed 903,702 DeviceTopK invocations, each launching 3-4 kernels. DeepSeek V3.2 / V4 indexer top-k hits the same path.Change
Keep
DeviceTopKfornrows <= 4and dispatch larger batches to the existing row-parallel argsort+copy path, untilDeviceSegmentedTopKexists (NVIDIA/cccl#6391 — the existing TODO in this file). The argsort fallback previously only compiled when CCCL < 3.2; it is now reachable in both configurations, sonext_power_of_2moves out of the#elif.Results
End-to-end prompt processing, Qwen3.8-Flash-Next UD-IQ4_XS on 2x RTX A6000 (sm_86), CUDA 12.1 + CCCL 3.2, master
e4b9af00vs master + this change (cold full prefills; multiple reps; contention-free samples only, foreign GPU activity sampled at 1 Hz):At the shapes covered by
test-backend-ops perf(nrows <= 16) the two paths are within noise of each other (e.g.ne=[32768,16],k=16: 257.8 vs 259.9 us/run), so the dispatch changes nothing measurable for small batches; the win comes from prompt-processing-scale row counts (hundreds of rows per op), where the serial launch overhead dominates.test-backend-ops -o TOP_Kpasses (the suite covers nrows 1-16, which exercises both dispatch branches). Also verified the CCCL < 3.2 configuration still compiles (stock CUDA 12.1).