TL;DR
RadiK is a new GPU-parallel algorithm that breaks the scalability limits of traditional top-k selection. By moving away from memory-constrained merge-based methods to an optimized radix-based approach, it supports massive $k$ values (up to 100k+) with up to 4.8× speedup over existing state-of-the-art implementations.
What Problem Does This Paper Address?
Top-k selection—finding the $k$ largest or smallest elements in a dataset—is a bottleneck in two of today's hottest fields: Large Language Models (LLMs) and vector databases. During LLM inference, the model must sample from a vocabulary of over 100,000 tokens. In vector databases, K-Nearest Neighbor (KNN) searches often require retrieving thousands of results.
The challenge is that current high-performance GPU algorithms (like those in the Faiss library) are "merge-based." They rely on keeping the entire set of $k$ candidates in the GPU's fast but tiny on-chip memory (registers or shared memory). This effectively caps $k$ at around 1,024 or 2,048. When $k$ exceeds this, systems usually fall back to a "Sort & Choose" method, which is computationally wasteful because it sorts the entire dataset just to find a few elements.
Methods
The authors introduce RadiK, which is built on Radix Select rather than merging. Instead of sorting, Radix Select identifies the $k$-th element (the pivot) bit-by-bit, narrowing down the search space in each iteration. Because it only needs to maintain a constant-sized histogram of "bins," it can handle any $k \le n$.
To make this efficient on modern GPUs, the authors implemented several novel optimizations:
- Hierarchical Atomics: To avoid "atomic contention" where thousands of threads fight to update a single global counter, RadiK uses a hierarchy. Threads update local histograms in shared memory first, then merge those into global memory.
- Flush-Efficient Write Buffer: Writing filtered elements back to global memory is often fragmented and slow. RadiK uses a shared memory buffer to aggregate these elements, performing "burst" writes only when the buffer is half-full to maximize memory bandwidth.
- Task Rescheduling: In batch queries, the workload shrinks as iterations progress. RadiK "stacks" iterations from different tasks vertically to keep the GPU's Streaming Multiprocessors (SMs) fully utilized even when individual tasks become small.
- Adaptive Scaling: Radix-based methods are notoriously vulnerable to "adversarial" data (e.g., numbers that are very close together). RadiK introduces a lightweight "scaling" trick: it randomly subtracts a value from the input to "scatter" the data across different radix bins, preventing performance degradation.
Datasets
The authors evaluated RadiK using synthetic datasets designed to mimic real-world distributions:
- Uniform Distributions: Standard random data.
- Zipfian Distributions: To simulate skewed data common in natural language and web traffic.
- Adversarial Distributions: Specifically crafted "peaked" distributions (e.g., values in a very narrow range like [128.6, 128.7]) to test the robustness of the radix approach.
- Real-world Contexts: The paper references the requirements of GPT-4 (100k vocabulary) and KNN operations in vector databases.
Key Insights and Ideas
- The Scalability Wall is Architectural: The "aha" moment is realizing that merge-based methods aren't just slower at high $k$; they are physically limited by the GPU's hardware registers. Radix Select bypasses this by trading memory space for iterative bit-checks.
- Bandwidth is King: Most of the speedup doesn't come from fewer calculations, but from better "memory plumbing." By using hierarchical atomics and write buffers, RadiK gets closer to the theoretical maximum bandwidth of the GPU.
- Robustness via Randomization: The vulnerability of Radix Select to skewed data was a known "deal-breaker." The authors' solution—randomly shifting the data—is elegantly simple and adds almost zero overhead while providing a 2.7× speedup on difficult data.
Key Results
- Non-Batch Queries: RadiK achieved up to 2.5× speedup over Bitonic Select (the previous leader for small $k$).
- Batch Queries: In scenarios common in LLM serving, it achieved up to 4.8× speedup over the priority queue methods used in Faiss.
- Extreme Scalability: While previous methods crashed or slowed down significantly past $k=2048$, RadiK remained stable even as $k$ approached the median of the entire dataset.
- Robustness: The adaptive scaling technique improved performance on adversarial "peaked" distributions by 2.7×.
Limitations and Future Work
While RadiK is highly optimized for NVIDIA GPUs using CUDA, the authors note that performance is sensitive to hyper-parameters like "digit width" (how many bits are checked per iteration). These currently need to be tuned based on the specific GPU architecture.
Future work could involve automatically tuning these parameters at runtime or extending the framework to support even more complex selection criteria beyond simple "top-k" (such as weighted sampling). Additionally, while the paper focuses on FP32 data, the authors suggest that 16-bit types (FP16/BF16) would likely see even greater benefits due to fewer required radix iterations.
Summary updated