High Performance Approximate Sort Algorithm Using GPUs

Jun Xiao, Hao Chen, Jianhua SunAdvances 2015

Abstract

Sorting is a fundamental problem in computer science, and the strict sorting usually means a strict order with ascending or descending. However, some applications in reality don't require the strict ascending or descending order and the approximate ascending or descending order just meets the requirement.

Introduction

Sorting is a cornerstone of computer science, but "strict sorting"—where every single element is in perfect ascending or descending order—comes with a high computational cost. Many real-world applications, such as search engine indexing or intermediate data processing steps, do not actually require 100% precision. In these cases, an "approximate sort" (where data is generally in the right place but might have small local clusters of disorder) is perfectly acceptable. This paper introduces a GPU-accelerated algorithm designed to leverage the massively parallel architecture of modern Graphics Processing Units (GPUs) to perform this approximate sort significantly faster than traditional strict sorting methods.

Methodology

The algorithm is built using NVIDIA’s CUDA architecture, specifically targeting the high-throughput capabilities of manycore GPUs. The process follows three main steps:

  1. Interval Mapping: The algorithm divides the range of input data (from minimum to maximum value) into a user-defined number of "intervals" ($NUM\_INTERVAL$). Each data element is mapped to an interval in parallel. The atomicInc function is used to manage "offsets" within these intervals, ensuring thread safety during data placement.
  2. Prefix Sum: Once the count of elements in each interval is known, the algorithm performs an exclusive prefix sum (using the CUDPP library). This determines the starting memory address for each interval in the final output array.
  3. Scatter: Finally, the algorithm combines the offsets from Step 1 and the starting addresses from Step 2 to "scatter" the data into its approximately sorted position.
Overview of the approximate sort algorithm steps, showing the mapping from input to an approximately-sorted array.

The resulting dataset is sorted between intervals (all items in interval $i$ are smaller than all items in interval $i+1$) but remains unsorted within each interval.

Experimental Results

The algorithm was evaluated using synthetic datasets (Uniform and Gaussian distributions) at scales of 1 million (1M), 2 million (2M), and 4 million (4M) elements.

Execution times comparison between ApporSort, MergeSort, and RadixSort across different data sizes.

Key results include:

  • Significant Speedup: The approximate sort (ApporSort) is consistently at least twice as fast as Radix sort, the fastest strict GPU sorting algorithm for large datasets.
  • Distribution Agnostic: Performance remained consistent across both Uniform and Gaussian distributions, unlike some algorithms that struggle with clustered data.
  • Scalability: As data volume doubled, the execution time of ApporSort increased much more slowly than that of Merge sort or Radix sort.

Discussion

The core insight of this work is the "Good Enough" philosophy: by relaxing the constraint of perfect order, the algorithm bypasses expensive operations like recursive comparisons or bit-level shuffling. Furthermore, the approach leverages hardware evolution; newer GPU architectures (like Kepler) have significantly improved atomic throughput, making the atomicInc-heavy approach viable.

There is a performance "sweet spot" for the number of intervals. Too few intervals lead to high thread contention on atomic counters, while too many intervals increase the overhead of the prefix sum step. However, empirical tests show that performance remains remarkably stable across a wide range of interval counts (from 10,000 to 90,000).

Conclusion

While the algorithm is "imprecise" by design, it offers a substantial performance boost for applications where local disorder is tolerable. Future work will focus on integrating this algorithm into real-world large-scale systems and developing formal metrics for the "degree of disorder" to help users tune the interval count for specific precision requirements.

Summary updated

BibTeX
@inproceedings{xiao2015high,
  author = {Jun Xiao and Hao Chen and Jianhua Sun},
  title = {{High Performance Approximate Sort Algorithm Using GPUs}},
  booktitle = {Advances},
  year = {2015},
  doi = {10.2991/csic-15.2015.28},
}
Figure