GPUs deliver 5 to 10x the arithmetic throughput and memory bandwidth of CPUs, yet early GPU vector search stalled on the step that looks trivial on a CPU: picking the k smallest distances. In 2017, Jeff Johnson, Matthijs Douze, and Hervé Jégou at Facebook AI Research solved that bottleneck with WarpSelect, a single-pass k-selection kernel living entirely in the GPU register file, and paired it with IVFADC (inverted-file product quantization) to build Faiss.

Keeping top-k state in registers while compressing vectors into compact device-resident codes turned cluster-scale jobs into single-workstation GPU runs. Its GEMM distance kernels and compressed scanners still power billion-scale search, k-means clustering, and training-data deduplication.

  • 55% of peak GPU memory bandwidth for k-selection: On a Titan X (k = 100, 128,000-element arrays), WarpSelect reaches 55% of theoretical memory bandwidth (16% at k = 1000), beating fgknn by 1.62x at k = 100 and 2.01x at k = 1000, and running over 10x faster than thrust::sort_by_key.
  • 8.5x faster than prior GPU billion-scale ANN: On SIFT1B (1 billion vectors, m = 8 bytes/vector on one GPU), Faiss reaches R@10 = 0.376 in 17.7 microseconds per query versus Wieschollek et al.’s R@10 = 0.35 in 150 microseconds.
  • 1,500x faster than single-thread CPU on DEEP1B: Across 1 billion 80-d OPQ vectors (m = 20 bytes, 20 GB across 4 Titan X GPUs with S = 2, R = 2), Faiss hits R@1 = 0.4517 in 0.0133 ms per vector versus 20 ms (R@1 = 0.45) on one CPU thread.
  • Billion-scale k-NN graphs on four GPUs: Faiss builds a 10-NN graph on 95 million YFCC100M images (>0.8 accuracy) in 35 minutes and a 1 billion-vector DEEP1B graph in 6 to under 12 hours, compared to 108.7 hours across 128 CPU servers for a smaller 36.5M NN-Descent run.
The Faiss GPU pipeline: from coarse routing to in-register top-k
1. Coarse routing (q1)
Pick the tau closest centroids out of |C1| inverted lists.
cuBLAS GEMM + fused distance
Batched matrix multiply computes -2 <x_j, c_i>, then a fused kernel adds norms and selects tau lists per query.
2. List scanning (q2)
Scan b-byte PQ codes across the tau selected lists.
Shared-memory lookup tables (T1..Tb)
Precompute b x 256 sub-vector distances in 48 KiB shared memory so each candidate costs b fast table adds instead of d multiply-adds.
3. WarpSelect top-k
Two-pass reduction per query across GPU registers.
Register-only filter + odd-size merge
32 warp lanes filter inputs in private thread queues, triggering warp-shuffle bitonic merges only when warp-ballot sees a candidate beat W[k-1].

Pipeline from Johnson, Douze, and Jégou (2017), Sections 2, 4, and 5.

Why CPU heaps and naive GPU selection stall

A GPU reverses the CPU memory hierarchy. On a Pascal P100, the register file holds 14 MB (versus tens of kilobytes on a CPU), per-block shared memory caps at 48 KiB, and global DRAM holds 4 to 32 GB, with aggregate bandwidth scaling roughly 250 : 6.25 : 1 from registers to shared to global memory.

For small k (under 1000), a CPU max-heap fits in L1 cache. Naive GPU ports break across three bottlenecks (Sections 3 and 4):

  • GPU heaps and priority queues: Data-dependent tree paths cause severe warp divergence and scattered memory traffic, while parallel priority queues add stream barriers and CPU sync latency.
  • Multi-pass quickselect, radix select, and TBiS: Partitioning needs O(l) auxiliary buffers and multiple global-memory passes (TBiS runs out of scratch memory past l = 48,000), and fails whenever distances are computed on the fly.
  • Shared-memory queues (fgknn): Buffering in 48 KiB shared memory limits SM occupancy and adds inter-warp synchronization.
Why standard top-k designs underperform on GPU
GPU max-heap

Data-dependent tree paths cause severe warp divergence and scattered memory traffic across lanes.

Quickselect / TBiS

Requires multiple global-memory passes and large O(l) scratch space (TBiS stalls past l = 48,000).

WarpSelect (Faiss)

Single-pass, register-resident filter plus odd-size bitonic merge via warp shuffles; fusable into GEMM.

Comparison from Johnson, Douze, and Jégou (2017), Sections 3.3 and 4.

WarpSelect and kernel fusion inside the register file

To scan distance arrays in one pass near memory-bandwidth limits, WarpSelect assigns one 32-lane warp per query and keeps all state inside registers, communicating across lanes via warp shuffles with zero shared memory.

Each lane j holds a small thread queue ([T_i^j], descending, length t = 2, 3, 4, 8 for k up to 32, 128, 256, 1024), while the warp shares a sorted warp queue ([W_i], length k rounded to a multiple of 32, up to k = 1024) stored in a lane-stride register array so register indices are fixed at assembly time. Reading 32 coalesced floats per step, each lane rejects any incoming a >= T_0^j immediately; only O(k log(l/32)) inputs insert into thread queues. Whenever warp-ballot(T_0^j < W_{k-1}) detects a thread-queue spillover beating W_{k-1} (roughly O(k log(l)/t) times), the warp runs sort-odd and merge-odd (Algorithm 1, eliding power-of-2 dummy padding so t stays at 8 instead of 32 for k = 1024).

Because WarpSelect uses no shared memory or cross-warp barriers, Faiss fuses it into exact L2 search: ||x_j - y_i||^2 = ||x_j||^2 + ||y_i||^2 - 2 <x_j, y_i>. cuBLAS GEMM writes tiled -2 X Y^T across two CUDA streams (O(2 l t_q) buffer), and a fused epilogue adds ||y_i||^2 directly into WarpSelect (||x_j||^2 is constant per query row). Cutting out the extra pass over D' saves at least 25% runtime on SIFT1M (1.28 Tflop in under 1 second), reaching 85% of peak. The same fused 1-NN kernel runs k-means on MNIST8m (8.1M 784-d digits) more than 2x faster than BIDMach (140 s vs. 320 s for 256 centroids; 316 s vs. 735 s for 4096 centroids) and clusters 100M 128-d vectors (85k centroids) on 4 GPUs in 52 minutes with zero preprocessing.

IVFADC on GPU: fitting a billion vectors in memory

Raw 128-d vectors at billion scale (512 GB) overflow GPU RAM, so Faiss uses IVFADC: a coarse k-means quantizer q1(y) (|C1| ~ sqrt(l)) routes queries to the tau closest inverted lists, while a residual product quantizer q2(y - q1(y)) splits residuals into b sub-vectors quantized to 256 centroids (1 byte each). The authors skipped binary codes (higher non-exhaustive overhead), the Inverted Multi-Index (branchy multi-sequence queues), and LOPQ/Polysemous codes (too much per-vector branching for GPUs).

Inside each list I_L, precomputed sub-quantizer distance tables T_1 ... T_b (256 floats each) turn vector distance into b table lookups and additions (256 * d multiply-adds plus n * b table adds, or fewer via Equation 11’s residual decomposition). Because list scanning performs trillions of random lookups (n_q * tau * max|I_i| * b), T_1 ... T_b must stay in 48 KiB shared memory, capping b at 48 (fp32) or 96 (fp16).

Two layout choices complete the system: storing b-byte codes separately from 4- or 8-byte vector IDs (so IDs can even sit on CPU RAM), and using a two-pass WarpSelect rather than fusing selection into list scanning (shared-memory gathers dominate runtime, so fusion gains at most 15% while hurting small-batch parallelism). Across multiple GPUs, replication (R) splits query batches (n_q / R) nearly linearly, while sharding (S) splits vectors (l / S) when an index exceeds one GPU’s memory.

Four billion-scale workloads in practice

Because exact search, compressed retrieval, and all-pairs graph builds hit different bottlenecks, compare the four empirical regimes from Section 6 below.

Four GPU workloads evaluated in the Faiss paper

Select a workload (or use Left and Right arrow keys) to compare the bottleneck, Faiss's mechanism, and measured numbers against prior baselines.

Exact 10-NN search on SIFT1M (1M x 128-d, 10k queries)

Fused GEMM

Even on brute-force L2 search, reading and selecting the 10-billion-entry distance matrix dominates naive pipelines unless k-selection fuses into GEMM.

Why naive selection breaks
Sorting rows with thrust::sort_by_key runs over 10x slower; writing the full D' matrix to DRAM and re-reading it adds 25%+ overhead.
Faiss mechanism
cuBLAS GEMM computes tiled -2 X Y^T across two streams while a fused epilogue adds ||y_i||^2 and feeds WarpSelect in registers.
Measured evidence
Section 6.3: achieves 85% of theoretical peak (GEMM + tiled D' limit) on 1 Titan X, running 1.28 Tflop of distance math in under 1 second.
Production impact
Makes exact GPU brute force viable up to millions of vectors and drives 2x faster k-means training for coarse quantizers.

Source: Johnson, Douze, and Jégou (2017), Sections 6.2 through 6.5.

If you prefer the short version without clicking through each tab:

  • Exact SIFT1M (1M 128-d): fusing WarpSelect into cuBLAS GEMM hits 85% of peak, beats unfused write-back by 25%+, and beats thrust::sort_by_key by over 10x.
  • SIFT1B (1B vectors, 8 bytes/vector): single-GPU Faiss hits R@10 = 0.376 in 17.7 microseconds per query, 8.5x faster than prior GPU state of the art.
  • DEEP1B (1B vectors, 20 GB): sharding S = 2 and replicating R = 2 across 4 Titan X GPUs reaches R@1 = 0.4517 in 0.0133 ms per query vs. 20 ms on 1 CPU thread.
  • k-NN Graph builds: querying IVFADC against itself builds a 95M YFCC100M graph in 35 minutes and a 1B DEEP1B graph in under 12 hours on 4 GPUs vs. 108.7 hours on 128 CPUs for 36.5M NN-Descent.

Caveats and modern context

Three constraints still govern when GPU Faiss wins and when it loses.

First, WarpSelect caps k <= 1024 and shared memory caps b. Compile-time register indexing restricts k to at most 1024 (with bandwidth dropping from 55% at k = 100 to 16% at k = 1000), while 48 KiB shared-memory lookup tables cap sub-quantizers at b <= 48 (fp32) or b <= 96 (fp16), though newer GPUs ease that ceiling.

Second, GPU throughput relies on large query batches (n_q). Benchmarks test n_q = 10,000 queries to saturate SMs; under single-query (n_q = 1) online traffic, kernel launch overhead makes GPU IVFADC slower per request than CPU HNSW, and scaling from 4 Titan Xs to 8 M40s on DEEP1B gave sublinear speedups (~1.6x to ~1.7x).

Third, 8- to 20-byte PQ codes need reranking for high precision. R@10 = 0.376 or R@1 = 0.4517 works for coarse retrieval or graph building, not 0.99 top-10 recall without rescoring full vectors from host RAM or SSD, a split later seen in DiskANN and ColBERTv2.

For builders today, route low-batch, high-recall (0.95+) queries to CPU/SSD graphs like HNSW or DiskANN, and reach for GPU Faiss on batched search, k-means, or all-pairs similarity jobs like SEDD, using the same register-tiling and kernel-fusion playbook behind FlashAttention-2.