Skip to main content
QUICK REVIEW

[论文解读] Flash-KMeans: Fast and Memory-Efficient Exact K-Means

Shuo Yang, Haocheng Xi|arXiv (Cornell University)|Mar 10, 2026
Graph Theory and AlgorithmsComputer Science被引用 0
一句话总结

Flash-KMeans 提供面向 IO 的、精确的 K-Means 实现,适用于现代 GPU,通过消除距离矩阵材料化并降低原子写入冲突,在端到端实现上实现对基线的大规模加速,并在无精度损失的情况下实现离线外部存储的可扩展性。

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.

研究动机与目标

  • 推动 K-Means 从离线分析转向 AI 系统中的在线原语的转变。
  • 识别标准 GPU K-Means 实现中的内核级瓶颈(IO 绑定的分配和原子更新争用)。
  • 提出一种面向 IO 的、保持严格等价性的重新设计,以提升在现代 GPU 上的端到端性能。
  • 通过离线外部执行和动态形状优化证明可部署性。
  • 为在 AI 流水线中对聚类原语进行面向硬件的加速提供设计原则。)
  • methodR包含:

提出的方法

  • 引入 FlashAssign,将距离计算与在线 argmin 融合,避免显式的 N×K 距离矩阵材料化。
  • 引入排序-逆变更新,将原子散射转化为分段级局部化规约,通过对分配进行排序并使用逆映射。
  • 应用分块流_overlap 以隐藏 PCIe 传输,并使用缓存感知编译启发式以降低首跑时间。
  • 在保持与标准 Lloyd’s K-Means 等价性的前提下,围绕硬件瓶颈重构数据流。
  • 在 NVIDIA H200 GPU 上进行评估,并与 cuML、FAISS、fast_pytorch_kmeans 进行端到端和内核级指标的对比。

实验结果

研究问题

  • RQ1K-Means 能否在不改变其数学形式的前提下高效地在 GPU 上在线执行?
  • RQ2标准 GPU K-Means 实现中的主要硬件瓶颈是什么,如何缓解?
  • RQ3面向 IO 的内核设计和算法-系统协同设计是否能在在线 AI 流水线中带来显著的端到端加速和可部署性?
  • RQ4所提出的方法在极端数据规模和动态工作负载(离线、动态形状)下的扩展性如何?

主要发现

  • FlashAssign 消除了 N×K 距离材料化,在分配内核实现中实现高达 21.2× 的加速。
  • Sort-Inverse_Update 降低原子争用,在质心更新内核实现中实现高达 6.3× 的加速。
  • 端到端的加速,最高达到对基线的 17.9×,以及对 FAISS 超 200×、对 cuML 的 33×。
  • 在离线外部场景下,点数高达十亿时,Flash-KMeans 实现高达 10.5× 的端到端加速。
  • 缓存感知编译启发式在优化性能方面达到最优水平的 0.3% 内,并将调优开销降低多达 175×。
  • 该方法支持无缝的离线外部执行和动态形状部署,准确性几乎不受影响。

阅读本论文

在 Nubint 阅读器中打开原文,边读边就任意段落提问。

在 Nubint 中阅读本论文

本解读由 AI 根据论文原文生成,引用前请核对原文。