Large scale K-means clustering using GPUs

Mi Li, Eibe Frank, Bernhard PfahringerData Min. Knowl. Discov 2023 · DOI

Abstract

K-means clustering is a fundamental unsupervised learning algorithm, yet its application to massive datasets is often hindered by GPU memory constraints and computational redundancy. This paper presents Asynchronous Selective Batched K-means (ASB K-means), a novel GPU-accelerated approach that utilizes Hamerly’s triangle inequality and asynchronous data transfers to overcome the "VRAM barrier." By processing data in batches and pruning redundant calculations on the CPU, ASB K-means enables the clustering of datasets significantly larger than the available GPU memory. Experimental results demonstrate speedups of up to 15x over standard implementations and superior performance compared to NVIDIA’s RAPIDS library.

Introduction

K-means clustering remains a workhorse in data science for partitioning datasets into $k$ clusters. However, as dataset sizes grow into the hundreds of gigabytes, traditional GPU-based implementations face two critical bottlenecks. First, the "Memory Wall" restricts processing to datasets that fit entirely within the GPU's Video RAM (VRAM). Second, standard Lloyd’s algorithm involves significant redundant work, recalculating distances for points that have already converged to a stable cluster.

To address these challenges, we introduce Asynchronous Selective Batched K-means (ASB K-means). This algorithm is designed to be an "exact" K-means implementation that handles massive datasets on modest hardware by optimizing both computational efficiency and data movement.

Methodology

The ASB K-means algorithm is built upon three core technical pillars:

1. Hamerly’s Triangle Inequality

The algorithm employs geometric pruning to avoid unnecessary distance calculations. By maintaining an upper bound (distance to the assigned center) and a lower bound (distance to the second-closest center) for each point, the system can determine if a point's cluster assignment could possibly change. If the upper bound remains smaller than the lower bound, the point is skipped, drastically reducing the GPU's workload in later iterations.

2. Batched Processing

To bypass VRAM limitations, ASB K-means processes data in discrete chunks or batches. This architectural choice ensures that the algorithm's memory footprint is limited to the size of a single batch plus the cluster centers, allowing it to scale to datasets limited only by system RAM or disk space.

3. Asynchronous Execution

Data transfer over the PCIe bus is often a performance bottleneck. ASB K-means utilizes CUDA’s asynchronous APIs to overlap data movement with computation. While the GPU processes one batch, the CPU filters the next batch and updates statistics for the previous one. This pipelining effectively "hides" the latency of data transfers.

Experimental Evaluation

The performance of ASB K-means was evaluated across three diverse data types:

  • Synthetic Datasets: Uniform distributions up to 5 million instances to test worst-case scenarios without natural clusters.
  • Image Patches: A 61GB dataset comprising 60 million grayscale image patches from Google image collections.
  • Twitter GloVe: High-dimensional word vectors (up to 200 dimensions) representing 1.2 million vocabularies.

Key Results

ASB K-means demonstrated significant performance gains over existing solutions:

  • Performance: The algorithm achieved up to a 15x speedup compared to standard GPU-based Lloyd’s implementations.
  • Competitive Benchmarking: ASB K-means consistently outperformed the K-means implementation in NVIDIA’s RAPIDS (cuML) library, typically by a factor of 1.5x to 2x.
  • Scalability: The algorithm successfully clustered a 61GB image dataset on a single 12GB GPU in approximately 2 hours—a task that would cause standard implementations to fail or require days of CPU-based processing.
  • Cluster Scaling: The pruning mechanism allows the algorithm to scale efficiently with the number of clusters ($k$). In some tests, a 30x increase in $k$ resulted in only a 1.4x increase in runtime.

Discussion and Future Work

The success of ASB K-means highlights the importance of using the CPU as a logical filter to complement the GPU's arithmetic power. By identifying stable points on the CPU, the algorithm minimizes the bandwidth required for PCIe transfers.

Future optimizations could further enhance performance. Moving the centroid update step to the GPU for high-$k$ scenarios and implementing "tiled loading" into the GPU's shared memory are promising avenues for reducing global memory access and increasing throughput.

Summary updated

BibTeX
@article{li2023large,
  author = {Mi Li and Eibe Frank and Bernhard Pfahringer},
  title = {{Large scale K-means clustering using GPUs}},
  journal = {Data Min. Knowl. Discov.},
  year = {2023},
  doi = {10.1007/s10618-022-00869-6},
}
Figure