Skip to content

[CUDA] TopK kernel based on Radix and Bitonic Hybrid Sort#1731

Closed
tianleiwu wants to merge 3 commits into
mainfrom
tlwu/topk_sampling_cuda_kernel
Closed

[CUDA] TopK kernel based on Radix and Bitonic Hybrid Sort#1731
tianleiwu wants to merge 3 commits into
mainfrom
tlwu/topk_sampling_cuda_kernel

Conversation

@tianleiwu

@tianleiwu tianleiwu commented Sep 6, 2025

Copy link
Copy Markdown
Contributor

This PR is for a new TopK kernel based on hybrid of Radix Sort and Bitonic Sort in different stages. You can see the change here.

Note that I have split the sampling code change to another PR: #1732. If you have comments related to sampling kernel, you can add comments there. That will be merged first.

The new TopK kernel has 6X ~ 10X improvement compared to selection sort for batch_size=1, k=50, vocab_size=201088.

@tianleiwu tianleiwu changed the title [CUDA] TopK and Sampling kernel Improvements [CUDA] TopK kernel based on Radix and Bitonic Hybrid Sort Sep 6, 2025
Comment thread src/cuda/cuda_topk.cu
// Helper to determine the optimal partition size for the hybrid sort algorithm
// based on vocabulary and batch size.
inline int GetHybridSortPartitionSize(int vocab_size, int batch_size) {
if (vocab_size >= 147456) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you share commentary around how these numbers were chosen ?

@tianleiwu tianleiwu marked this pull request as draft September 7, 2025 00:41
@tianleiwu tianleiwu closed this Sep 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants