Skip to content

CUDA: support ncols > 1024 in bitonic argsort/top-k The original bito… - #26493

Open
Geramy wants to merge 1 commit into
ggml-org:masterfrom
Geramy:Geramy/hip-top-k-large-ncols
Open

CUDA: support ncols > 1024 in bitonic argsort/top-k The original bito…#26493
Geramy wants to merge 1 commit into
ggml-org:masterfrom
Geramy:Geramy/hip-top-k-large-ncols

Conversation

@Geramy

@Geramy Geramy commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Overview

This PR changes the argsort / top-k max cols to the maximum of the gpu available LDS by changing the kernel to use the maximum amount of X elements per thread. This was brought on due to the following issue:
#26399 (comment)

This mainly targets HIP devices due to there being no ggml_cuda_op_top_k implementation on hip.

Additional information

Please note drift is not yet calculated in the below table.

┌──────┬───────────┬──────────┬────────┐
│ n_kv │ TG before │ TG after │   %    │
├──────┼───────────┼──────────┼────────┤
│ 1004 │ 15.64     │ 15.13    │ −3.3%  │
├──────┼───────────┼──────────┼────────┤
│ 2004 │ 16.48     │ 16.29    │ −1.2%  │
├──────┼───────────┼──────────┼────────┤
│ 3004 │ 16.41     │ 16.24    │ −1.0%  │
├──────┼───────────┼──────────┼────────┤
│ 4004 │ 16.36     │ 16.18    │ −1.1%  │
├──────┼───────────┼──────────┼────────┤
│ 4504 │ 15.24     │ 16.05    │ +5.3%  │
├──────┼───────────┼──────────┼────────┤
│ 5004 │ 15.20     │ 16.08    │ +5.8%  │
├──────┼───────────┼──────────┼────────┤
│ 5504 │ 14.28     │ 16.02    │ +12.2% │
└──────┴───────────┴──────────┴────────┘

Requirements

  1. 2* AMD GPU
  2. VRAM > 83GB
  3. Deepseek-V4-Flash

…nic sort used when CUB is unavailable IE HIP, and some versions of older CUDA capped ncols to 1024 threads/blocks due to hardware LDS size limit and instead sent the request the the CPU. I have updated the kernel to now do multiple elements per thread ncols_pad/nthreads.
@Geramy
Geramy requested a review from a team as a code owner August 3, 2026 05:43
@github-actions github-actions Bot added ggml changes relating to the ggml tensor library for machine learning CUDA Related to the CUDA backend labels Aug 3, 2026
@Geramy

Geramy commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

@pwilkin

@Geramy

Geramy commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

This would close issue #26399 (comment)

@IMbackK IMbackK self-assigned this Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CUDA Related to the CUDA backend ggml changes relating to the ggml tensor library for machine learning

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants