TL;DR
This paper introduces a hybrid Most-Significant-Digit (MSD) radix sort for GPUs that significantly reduces memory bandwidth bottlenecks. By combining global partitioning with on-chip "local sorts" and optimized shared-memory atomics, the authors achieve a 2.32x speedup over state-of-the-art GPU libraries (like CUB) and successfully sort datasets up to 64 GB—far exceeding typical GPU memory—using a pipelined heterogeneous approach.
What Problem Does This Paper Address?
Sorting is a foundational operation for databases, but it is notoriously difficult to scale on GPUs. While GPUs offer massive compute power, sorting algorithms are often memory bandwidth bound.
The standard approach on GPUs has been the Least-Significant-Digit (LSD) radix sort. LSD sort is popular because it is easy to parallelize, but it requires the sort to be "stable" (preserving the relative order of equal keys). This constraint forces the algorithm to perform many passes over the entire dataset in global memory—up to 39 passes for 64-bit keys in some implementations. Each pass involves reading and writing the entire dataset, creating a massive bottleneck.
Furthermore, traditional Most-Significant-Digit (MSD) sorts, which could theoretically use fewer passes, struggle on GPUs due to load imbalance (skewed data creating buckets of vastly different sizes) and the overhead of managing millions of tiny buckets.
Methods
The authors propose a Hybrid Radix Sort that shifts the strategy from LSD to MSD to minimize global memory traffic.
- MSD Partitioning with 8-bit Digits: Instead of the typical 4 or 5 bits, this algorithm processes 8 bits per pass. This reduces the total number of passes (and thus memory transfers) by a factor of at least 1.6x.
- The "Local Sort" Threshold: When a bucket becomes small enough to fit into the GPU's on-chip shared memory (the "local sort threshold" $\hat{\partial}$), the algorithm stops global partitioning. It performs the remaining sorting passes entirely on-chip. This means the data is read once from global memory and written back once, regardless of how many internal passes are needed.
- Optimized Histogramming: To handle data skew (where many keys have the same digit value), they use a "thread reduction & atomics" technique. Threads sort small runs of keys in registers before updating shared memory counters, drastically reducing contention on atomic operations.
- Pipelined Heterogeneous Sorting: To sort data larger than the GPU's VRAM, the authors developed a system that chunks the data and overlaps PCIe transfers (Host-to-Device and Device-to-Host) with the GPU sorting process. They use an "in-place replacement" strategy to maximize the size of data chunks the GPU can handle at once.
Datasets
The authors evaluated their approach using synthetic datasets designed to test various levels of data skew:
- Uniform Distributions: 32-bit and 64-bit keys.
- Skewed Distributions: Generated using bitwise AND operations and Zipfian distributions ($\theta = 0.75$) to simulate real-world database scenarios.
- Data Sizes: Ranging from small batches (MBs) up to massive 64 GB datasets for the heterogeneous tests.
Key Insights and Ideas
- Abandoning Stability: By choosing an MSD approach, the authors realized they didn't need a "stable" sort. This freedom allows them to use hardware atomics in shared memory, which are much faster than the complex prefix-sum logic required for stable LSD sorts.
- The "Aha" of Local Sorting: The most expensive part of a radix sort is the "tail"—the final passes where you are moving small amounts of data around in global memory. By moving this "tail" to on-chip shared memory, they effectively "lift" the memory bandwidth limitation.
- Skew is an Opportunity, Not Just a Threat: While skew usually slows down GPU kernels, it actually allows the MSD sort to finish earlier for many buckets, as they hit the local sort threshold sooner.
- PCIe Overlap: The heterogeneous pipeline treats the GPU as a high-speed stream processor. By the time the last chunk of data is sent to the GPU, the first chunks are already sorted and being merged back on the CPU.
Key Results
- Pure GPU Performance: The hybrid sort achieved a 2.32x improvement over CUB (the industry standard) for uniform distributions and at least 1.66x for highly skewed distributions.
- Raw Speed: It can sort 2 GB of 8-byte records (64-bit keys) in just 50 milliseconds.
- Throughput: The implementation peaks at over 1 billion 32-bit keys per second.
- Large Scale: For a 64 GB dataset (key-value pairs), the heterogeneous approach was 2.06x faster than PARADIS, a state-of-the-art multi-threaded CPU radix sort running on 16 threads.
Limitations and Future Work
- CPU Merging Bottleneck: In the heterogeneous version, as the number of data chunks ($s$) increases, the CPU eventually struggles to merge the sorted runs quickly enough to keep up with the GPU.
- Hardware Specifics: The performance is highly dependent on the availability of fast shared memory atomics, which are present in modern NVIDIA architectures (like Pascal used in the paper) but may vary across other vendors.
- Memory Overhead: Managing the metadata for millions of buckets requires about 5% additional memory compared to an LSD sort, though the authors provide an analytical model to show this is a predictable and acceptable trade-off.
Summary updated