Skip to main content
QUICK REVIEW

[Paper Review] TPU-KNN: K Nearest Neighbor Search at Peak FLOP/s

Felix Chern, Blake A. Hechtman|arXiv (Cornell University)|Jun 28, 2022
Algorithms and Data CompressionComputer Science5 citations
TL;DR

This paper presents TPU-KNN, a K-nearest neighbor search algorithm that achieves peak FLOP/s performance on Google's TPU by leveraging a refined roofline model to optimize for memory and instruction-level bottlenecks. The method delivers state-of-the-art speed-recall trade-offs without requiring complex index structures or hyperparameter tuning, outperforming GPU-based baselines at similar recall levels on standard benchmarks like Sift1M and Glove1.2M.

ABSTRACT

This paper presents a novel nearest neighbor search algorithm achieving TPU (Google Tensor Processing Unit) peak performance, outperforming state-of-the-art GPU algorithms with similar level of recall. The design of the proposed algorithm is motivated by an accurate accelerator performance model that takes into account both the memory and instruction bottlenecks. Our algorithm comes with an analytical guarantee of recall in expectation and does not require maintaining sophisticated index data structure or tuning, making it suitable for applications with frequent updates. Our work is available in the open-source package of Jax and Tensorflow on TPU.

Motivation & Objective

  • To design a K-NN algorithm that achieves peak performance on TPU hardware by modeling both memory and instruction-level bottlenecks.
  • To develop a method with analytical recall guarantees in expectation, avoiding reliance on complex index structures or hyperparameter tuning.
  • To demonstrate that TPU-based K-NN can outperform state-of-the-art GPU-based algorithms under similar recall conditions.
  • To extend the roofline performance model to account for instruction throughput differences, enabling accurate algorithmic performance prediction on accelerators.
  • To provide a production-ready, open-source implementation in JAX and TensorFlow for TPU deployment.

Proposed method

  • The authors extend the roofline model to account for varying instruction throughput, enabling accurate prediction of accelerator performance bottlenecks.
  • They design a K-NN algorithm that maximizes FLOP/s utilization by minimizing data movement and balancing compute and memory bandwidth.
  • The algorithm performs brute-force distance computation on all data points, ensuring recall is based on order statistics rather than compression artifacts.
  • It leverages TPU-specific optimizations such as efficient vectorization, batch processing, and memory access patterns derived from the performance model.
  • The method uses a coefficient-wise instruction model to identify and mitigate bandwidth bottlenecks from low-throughput operations.
  • The implementation is open-sourced in JAX and TensorFlow, exposing a new operation 'approx_max_k' for efficient top-K selection on TPU.

Experimental results

Research questions

  • RQ1Can a K-NN algorithm be designed to achieve peak FLOP/s utilization on TPU by modeling both memory and instruction-level bottlenecks?
  • RQ2Does a roofline-based performance model extended to include instruction throughput differences enable accurate prediction of accelerator performance for K-NN workloads?
  • RQ3Can a simple, brute-force K-NN approach outperform complex compressed-domain search methods like IVF-Flat and IVF-PQ on TPU at comparable recall levels?
  • RQ4Is it possible to achieve high recall with analytical guarantees while avoiding complex index structures or hyperparameter tuning?
  • RQ5How does the performance of a TPU-optimized K-NN algorithm compare to state-of-the-art GPU-based K-NN methods under similar recall conditions?

Key findings

  • TPU-KNN achieves state-of-the-art speed-recall trade-offs on Sift1M and Glove1.2M benchmarks, outperforming GPU-based IVF-Flat, IVF-PQ, and flat search methods at similar recall levels.
  • The TPU implementation closely matches performance predictions from the extended roofline model, validating the accuracy of the performance modeling framework.
  • The algorithm achieves peak FLOP/s utilization on TPU by minimizing data movement and efficiently balancing compute and memory bandwidth.
  • The method maintains consistent recall across datasets because it relies on order statistics rather than compression-dependent heuristics, making it robust to data distribution shifts.
  • The open-source release in JAX and TensorFlow enables production deployment and integration with existing ML pipelines on TPU hardware.
  • The algorithm is immune to the curse of dimensionality since it computes all pairwise distances without dimensionality reduction or compression.

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.