Skip to main content
QUICK REVIEW

[Paper Review] Flash-KMeans: Fast and Memory-Efficient Exact K-Means

Shuo Yang, Haocheng Xi|arXiv (Cornell University)|Mar 10, 2026
Graph Theory and AlgorithmsComputer Science0 citations
TL;DR

Flash-KMeans provides an IO-aware, exact K-Means implementation for modern GPUs by eliminating distance matrix materialization and reducing atomic write contention, achieving large end-to-end speedups over baselines and enabling out-of-core scalability without accuracy loss.

ABSTRACT

$k$-means has historically been positioned primarily as an offline processing primitive, typically used for dataset organization or embedding preprocessing rather than as a first-class component in online systems. In this work, we revisit this classical algorithm under the lens of modern AI system design and enable $k$-means as an online primitive. We point out that existing GPU implementations of $k$-means remain fundamentally bottlenecked by low-level system constraints rather than theoretical algorithmic complexity. Specifically, the assignment stage suffers from a severe IO bottleneck due to the massive explicit materialization of the $N imes K$ distance matrix in High Bandwidth Memory (HBM). Simultaneously, the centroid update stage is heavily penalized by hardware-level atomic write contention caused by irregular, scatter-style token aggregations. To bridge this performance gap, we propose flash-kmeans, an IO-aware and contention-free $k$-means implementation for modern GPU workloads. Flash-kmeans introduces two core kernel-level innovations: (1) FlashAssign, which fuses distance computation with an online argmin to completely bypass intermediate memory materialization; (2) sort-inverse update, which explicitly constructs an inverse mapping to transform high-contention atomic scatters into high-bandwidth, segment-level localized reductions. Furthermore, we integrate algorithm-system co-designs, including chunked-stream overlap and cache-aware compile heuristics, to ensure practical deployability. Extensive evaluations on NVIDIA H200 GPUs demonstrate that flash-kmeans achieves up to 17.9$ imes$ end-to-end speedup over best baselines, while outperforming industry-standard libraries like cuML and FAISS by 33$ imes$ and over 200$ imes$, respectively.

Motivation & Objective

  • Motivate the shift of K-Means from offline analytics to online primitives in AI systems.
  • Identify the kernel-level bottlenecks in standard GPU K-Means implementations (IO-bound assignment and atomic update contention).
  • Propose an IO-aware, exactly formulation-preserving redesign to improve end-to-end performance on modern GPUs.
  • Demonstrate deployability through out-of-core execution and dynamic-shape optimization.
  • Provide design principles for hardware-aware acceleration of clustering primitives in AI pipelines.

Proposed method

  • Introduce FlashAssign to fuse distance computation with an online argmin, avoiding explicit N×K distance matrix materialization.
  • Introduce sort-inverse update to transform atomic scatters into segment-level localized reductions by sorting assignments and using an inverse mapping.
  • Apply chunked stream overlap to hide PCIe transfers and a cache-aware compile heuristic to reduce time-to-first-run.
  • Maintain mathematical equivalence to standard Lloyd’s K-Means while restructuring dataflow around hardware bottlenecks.
  • Evaluate on NVIDIA H200 GPUs with comparisons to cuML, FAISS, and fast_pytorch_kmeans across end-to-end and kernel-level metrics.

Experimental results

Research questions

  • RQ1Can K-Means be efficiently executed online on GPUs without changing its mathematical formulation?
  • RQ2What are the primary hardware bottlenecks in standard GPU K-Means implementations and how can they be mitigated?
  • RQ3Do IO-aware kernel designs and algorithm-system co-designs yield substantial end-to-end speedups and deployability in online AI pipelines?
  • RQ4How well does the proposed approach scale to extreme data sizes and dynamic workloads (out-of-core, dynamic shapes)?

Key findings

  • FlashAssign removes the N×K distance materialization, achieving up to 21.2× speedups in the assignment kernel.
  • Sort-Inverse Update reduces atomic contention and achieves up to 6.3× speedups in the centroid update kernel.
  • End-to-end speedups reach up to 17.9× over the best baselines and over 200× vs FAISS, with 33× vs cuML.
  • In out-of-core scenarios with up to one billion points, Flash-KMeans delivers up to 10.5× end-to-end speedup.
  • The cache-aware compile heuristic matches optimal performance within 0.3% while reducing tuning overhead by up to 175×.
  • The method supports seamless out-of-core execution and dynamic-shape deployments with near-zero accuracy impact.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.