Paper commentary
Billion-scale similarity search with GPUs
GPU k-selection enables billion-scale nearest neighbour search
- Problem Similarity search over billions of vectors is slow on GPUs, because k-selection makes several passes over global memory and exposes little parallelism. Heap-based selection suffers from warp divergence.
- Method WarpSelect keeps the selection state in registers, so most incoming values are rejected by a cheap local check. Warp-wide sorting runs only when a value could enter the final result.
- Results The authors' k-selection runs at 55% of theoretical peak at k = 100, and their Sift1B graph search is 8.5 times faster than reported prior work.
Why billion-scale search strains GPUs
The paper targets nearest-neighbour search over collections of image and video embeddings, which can reach 95 million images or a billion vectors. Exhaustive search, and exact indexing for non-exhaustive search, becomes impractical at this scale because of the curse of dimensionality. The flagship task is a k-NN graph that links every vector to its k nearest neighbours.
Compression offers a way out, since searching compressed codes does not require rebuilding the vectors. The authors focus on product quantization codes, which were shown to be more effective than binary codes. Many quantization improvements are hard to implement efficiently on a GPU, so the GPU route is less explored. Prior GPU work mostly covers binary codes, small datasets or exhaustive search, and only one billion-scale quantization method was known.
Even with compression, the selection of the k smallest distances can dominate the cost. Earlier GPU selection methods need several passes over global memory, and heap-based selection exposes little parallelism. GPU heaps suffer from warp divergence and data-dependent memory movement, which is why the authors look for a different design.
Keeping the selection state in registers
The core idea is to keep the selection state in registers, so that most incoming values are rejected by a cheap local check. Each warp is dedicated to one array, and it reads its input in groups of 32 values, so the reads stay contiguous. Warp-wide sorting is needed only when a value could enter the final result.
A GPU warp has 32 lanes, and each lane can hold up to 255 32-bit registers. The authors store a long array in a lane-stride layout, so that neighbouring lanes hold consecutive elements. Register data is far faster to reach than global memory, which makes it a good place for the selection state.
Each lane keeps a thread queue of t values sorted from largest to smallest. The warp also keeps a warp queue holding the k smallest values it has seen, which can hold up to 1024 entries. A new value larger than the lane's head entry cannot be among the k smallest, so the lane drops it at once.
When a lane's head falls below the warp queue's largest entry, the warp merges the queues and restores its invariants. The merge uses odd-size networks, which treat each array as padded to a power of two and skip comparisons with the dummy elements. Odd sizes matter because a Batcher-style merge would force the thread queue total to be a power of two.
The thread queue length t grows with k: 2 up to k = 32, 3 up to 128, 4 up to 256 and 8 up to 1024. A longer thread queue means fewer merges but more insertion work per value, so t is a trade-off between the two costs.
Exact search and the IVFADC layout
Exact search computes the inner-product term with cuBLAS GEMM and adds the database norms inside a fused k-selection kernel. Fusing the two steps means the distance matrix is written once and read once, where other implementations need three or more passes. The distance matrix does not fit in GPU memory, so the queries are tiled and two tiles run on separate streams.
IVFADC first assigns each vector to an inverted list through a coarse quantizer, and the residual is encoded with a product quantizer. The product quantizer splits a vector into sub-vectors, each with 256 reproduction values, so each sub-code fits in one byte. For a query, the distance to a code becomes a sum of table lookups, so the expensive multiply-adds are paid once per query.
The authors split the residual distance into three terms, and two of them can be precomputed into lookup tables. For one query this costs 256 times d multiply-adds plus τ times b times 256 additions, instead of τ times d times 256 multiply-adds from scratch. Because this table can be large on a GPU, the decomposition is enabled only when memory allows.
The lookup tables sit in shared memory, and that memory limits how many sub-quantizers b can use.
How the register design performs against other k-selection methods
The benchmark uses random 32-bit values, batches of 10000 arrays, and array lengths from 1000 to 128000 on a single Titan X. It compares WarpSelect with fgknn and TBiS for k = 100 and k = 1000. At the largest array length, WarpSelect ran 1.62 times faster than fgknn at k = 100 and 2.01 times faster at k = 1000. So the advantage over fgknn grows with k in this benchmark.
Measured against the memory bandwidth peak, WarpSelect runs at 55% at k = 100 but only 16% at k = 1000. The authors attribute the drop to larger thread queues and bigger merge and sort networks at large k. This fits the small-k regime that similarity search usually needs, since the authors treat k below roughly 1000 as typical.
WarpSelect differs from fgknn in keeping all state in registers and using no inter-warp synchronization or buffering. It also drops the hierarchical partition, can be fused into other kernels, and uses odd-size networks for merging and sorting.
Exact search and k-means results
With 256 centroids one GPU took 140 s, compared to 320 s for BIDMach. With 4096 centroids one GPU took 316 s, compared to 735 s for BIDMach. The authors credit part of the gain to fusing k-selection into the distance computation.
With replicas on four GPUs and 4096 centroids, the speedup over one GPU is 3.16 times. The authors' exact k-means ran on 4 GPUs in 52 minutes without preprocessing. These systems differ, so this comparison is context rather than a controlled test.
On Sift1M the partial distance matrix costs 1.28 Tflop, which runs in under a second on current GPUs. The authors' fused method reaches 85% of the peak performance they estimate, assuming GEMM usage and their tiling.
Billion-scale approximate search results
On Sift1M, the authors match the time budget of Wieschollek et al. at 0.02 ms per query on a Titan X. Their R@1 is 0.80, compared to 0.51 for the prior work. Their R@100 is 0.95, compared to 0.86.
On Sift1B, with 8 bytes per vector on a single GPU, the authors report R@10 of 0.376 at 17.7 µs per query vector. The result they cite from Wieschollek et al. is R@10 of 0.35 at 150 µs per query vector. The 8.5 times speed figure is therefore a comparison with reported numbers, not with a rerun of the prior method.
For Deep1B, the authors use PQ with m = 20 after OPQ, and |C1| = 2^18 coarse centroids. Four GPUs with S = 2 and R = 2 give R@1 of 0.4517 in 0.0133 ms per vector. The original Deep1B paper reports 0.45 R@1 in 20 ms per vector on one CPU thread. The text gives d = 80 after OPQ for this run, while the setup section gives d = 120, so the exact configuration is unclear.
Doubling the replica set to eight Maxwell M40 GPUs sped up Deep1B search by about 1.6 times for m = 20 and 1.7 times for m = 40. Replication scales close to linearly, while sharding is less efficient because of fixed overhead and the extra selection round.
Building the k-NN graph
The authors build a 10-NN graph over 95 million Yfcc100M images with an IVFADC index and 2^16 coarse centroids. Accuracy above 0.8 is reached in 35 minutes, using two replicas on four GPUs. Accuracy is the share of the 10 found neighbours that are among the 10 exact nearest neighbours, measured on 10,000 sampled images.
On Deep1B, a lower-quality graph takes about 6 hours, and a higher-quality one takes about half a day. For scale, a 36.5 million 384-d construction with NN-Descent used 128 CPU servers for 108.7 hours. The authors estimate about 200 days for Deep1B with that approach, assuming cost scales with GEMM cost.
Because the graph is connected, the authors search for smooth paths between two images. A path minimises the largest edge distance along it, so each step stays a smooth transition. On Yfcc100M the path took 20 seconds of propagation over a graph with k = 15 neighbours.
Limitations
The fused single-block IVFADC kernel improved runtime by at most 15%. Because of this small gain and simpler implementation, the authors did not use that layout. Efficiency falls to 16% of peak at k = 1000, compared to 55% at k = 100.
The billion-scale comparisons use numbers that prior work reported, not reruns on the same setup. The Deep1B dimension is given as d = 80 in the search result and d = 120 in the setup. NN-Descent would need 80 GB for Deep1B graph storage alone, and random access across all vectors.
The Yfcc100M accuracy uses 10,000 sampled images, not the full collection. The Sift1M and k-means comparisons with other systems are context, since the hardware and methods differ.
Paper info
- Authors
- Jeff Johnson, Matthijs Douze, Hervé Jégou
- Venue
- arXiv · Preprint
- First published
- 2017-2-28
- Added
- 2026-11-12
- Updated
- 2017-2-28
- Version
- v1
- arXiv
- 1702.08734
- Category
- cs.CV · cs.DB · cs.DS · cs.IR
- Original paper terms
- arXiv non-exclusive 1.0
- What we show
- Paper info and commentary
AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.
Quote from the paper
Jeff Johnson, Matthijs Douze, Hervé Jégou (2017). Billion-scale similarity search with GPUs. arXiv:1702.08734v1. https://arxiv.org/abs/1702.08734v1
BibTeX
@misc{johnson2017billion,
title = {{Billion-scale similarity search with GPUs}},
author = {Jeff Johnson and Matthijs Douze and Hervé Jégou},
year = {2017},
eprint = {1702.08734},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/1702.08734v1}
}