Buffer k-d Trees: Processing Massive Nearest Neighbor Queries on GPUs

Fabian Gieseke, Justin Heinermann, Cosmin E. Oancea, Christian Igel

Introduction

Nearest neighbor (NN) search—finding the closest points in a reference set to a given query point—is a cornerstone of data science. For low-dimensional data, k-d trees are the gold standard because they use hierarchical space partitioning to avoid checking every single point. However, making k-d trees run efficiently on modern GPUs has historically been a massive challenge.

This paper introduces the Buffer k-d Tree, a novel data structure that reorganizes NN searches to exploit GPU parallelism. By "buffering" queries and processing them in batches at the leaf level, the authors achieve speedups of up to 130x over sequential CPU implementations and significantly outperform standard GPU brute-force methods.

The Problem: GPU Thread Divergence

k-d trees are notoriously difficult to implement efficiently on GPUs. In a standard parallel implementation, each GPU thread handles one query. Because different queries follow different paths through the tree, the threads "diverge" (known as branch divergence), and memory access becomes irregular and slow. This often makes a simple, "dumb" brute-force search on a GPU faster than a "smart" k-d tree search. The authors set out to combine the algorithmic efficiency of k-d trees with the raw throughput of modern GPUs.

The Solution: Buffer k-d Trees

The core innovation is the Buffer k-d Tree, which splits the search into distinct phases, transforming a latency-sensitive problem into a throughput-optimized one.

Architecture of the Buffer k-d Tree
  1. The Top Tree: A small, fixed-height k-d tree (e.g., height $h=8$) is maintained on the CPU or GPU. Queries are passed through this top tree to determine which "leaf" (a larger region of space) they belong to.
  2. The Buffers: Instead of immediately searching the leaf, the query's index is placed into a buffer associated with that specific leaf.
  3. Lazy Batch Processing: Once a buffer is sufficiently full, the GPU triggers a "brute-force" search for all queries in that buffer against all reference points in that specific leaf.

Why this works: By waiting until many queries are headed to the same leaf, the GPU can perform a "block-wide SIMD" (Single Instruction, Multiple Data) operation. All threads in a GPU warp access the same reference patterns simultaneously. This local brute-force approach is highly optimized by hardware caches and eliminates the irregular memory access patterns that usually kill k-d tree performance on GPUs.

Datasets and Evaluation

The authors evaluate their approach using massive astronomical datasets from the Sloan Digital Sky Survey (SDSS). These datasets are ideal because they involve hundreds of millions of objects in moderate-dimensional spaces (4 to 27 dimensions).

Specific subsets used include low-dimensional benchmarks like psf_colors ($d=4$) and psf_mag ($d=5$), moderate dimensions like psf_model_mag ($d=10$), and a high-dimensional test (all, $d=27$) to see where the "curse of dimensionality" kicks in.

Key Results

The Buffer k-d Tree yields massive performance improvements across the board.

Runtime comparison of Buffer k-d Tree against baselines
  • Massive Speedups: The Buffer k-d Tree was 2–55x faster than a brute-force GPU implementation and 5–34x faster than a multi-threaded CPU k-d tree.
  • Comparison to Sequential: Compared to a single-threaded CPU k-d tree, the GPU approach was up to 130x faster.
  • Real-world Scale: The authors processed the entire SDSS catalog—roughly 1.178 billion queries against 2 million reference points—in about 77 minutes on a single commodity GPU (GTX 770).
  • Dimensionality: The approach remained effective up to approximately 25–30 dimensions, after which the hierarchical partitioning of k-d trees loses its advantage over brute force.

Limitations and Future Work

While highly effective for batch processing, the method has limitations:

  • The Curse of Dimensionality: Like all k-d tree variants, performance degrades as the number of dimensions ($d$) increases. For $d > 30$, the tree-based pruning becomes less effective.
  • Batch Requirement: This method requires a large batch of queries to be efficient. It is not suitable for "online" applications where you need the result of a single query immediately before receiving the next one.
  • Static Trees: The current implementation focuses on static reference sets. Future work could involve adapting the structure for dynamic data where reference points are frequently added or removed.

Summary updated

BibTeX
@inproceedings{gieseke2014buffer,
  author = {Fabian Gieseke and Justin Heinermann and Cosmin E. Oancea and Christian Igel},
  title = {{Buffer k-d Trees: Processing Massive Nearest Neighbor Queries on GPUs}},
  booktitle = {International Conference on Machine Learning},
  year = {2014},
}
Figure