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),WarpSelectreaches 55% of theoretical memory bandwidth (16% atk = 1000), beatingfgknnby 1.62x atk = 100and 2.01x atk = 1000, and running over 10x faster thanthrust::sort_by_key. - 8.5x faster than prior GPU billion-scale ANN: On
SIFT1B(1 billion vectors,m = 8bytes/vector on one GPU), Faiss reachesR@10 = 0.376in 17.7 microseconds per query versus Wieschollek et al.’sR@10 = 0.35in 150 microseconds. - 1,500x faster than single-thread CPU on
DEEP1B: Across 1 billion 80-d OPQ vectors (m = 20bytes,20 GBacross 4 Titan X GPUs withS = 2, R = 2), Faiss hitsR@1 = 0.4517in 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 a10-NN graph on 95 millionYFCC100Mimages (>0.8 accuracy) in 35 minutes and a 1 billion-vectorDEEP1Bgraph in 6 to under 12 hours, compared to 108.7 hours across 128 CPU servers for a smaller36.5MNN-Descentrun.
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 needsO(l)auxiliary buffers and multiple global-memory passes (TBiSruns out of scratch memory pastl = 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.
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.
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 GEMMEven 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.
1 billion SIFT vectors at 8 bytes/vector on 1 Titan X
Single-GPU IVFADCAt identical 8-byte compression on 1 billion vectors, GPU IVFADC + WarpSelect beats prior GPU ANN by nearly an order of magnitude.
- Why prior GPU ANN lagged
- Wieschollek et al. suffered slower list scanning and selection bottlenecks, taking 150 us per query at R@10 = 0.35.
- Faiss mechanism
- Compact 8-byte PQ codes (m=8) stay resident in single-GPU RAM with shared-memory lookup tables and two-pass WarpSelect.
- Measured evidence
- Section 6.4: R@10 = 0.376 in 17.7 us per query (8.5x faster than Wieschollek's 150 us at higher recall); on SIFT1M hits R@1=0.80 vs 0.51 in 0.02 ms.
- Production impact
- Turns single-GPU compressed scanning into tens-of-microseconds-per-vector throughput for large batched lookups.
1 billion CNN descriptors (20 GB index across 4 Titan X GPUs)
Multi-GPU S=2, R=2Combining 2 shards with 2 replicas fits a 20 GB OPQ+IVFADC index across 4 GPUs while matching CPU recall at 1,500x higher speed.
- Why single GPU or CPU stalls
- A 20 GB index overflows one 12 GB Titan X, while single-thread CPU search takes 20 ms per vector to reach R@1 = 0.45.
- Faiss mechanism
- OPQ reduces d=96 to d=80 with m=20 PQ bytes and |C1|=2^18 centroids, sharded S=2 ways and replicated R=2 ways across 4 GPUs.
- Measured evidence
- Section 6.4: reaches R@1 = 0.4517 in 0.0133 ms (13.3 us) per query across n_q = 10,000 queries.
- Production impact
- Sharding scales capacity across device VRAM while replication scales query throughput nearly linearly for large batches.
95M YFCC100M in 35 min & 1B DEEP1B in 6-12 hours
All-pairs graph buildAll-pairs approximate search over IVFADC replaces 100-server CPU NN-Descent clusters with a single 4-GPU workstation.
- Why CPU NN-Descent breaks
- NN-Descent demands huge graph memory overhead (>80 GB on Deep1B) plus random access across 384 GB of raw vectors; 36.5M took 128 CPUs 108.7 hours.
- Faiss mechanism
- Index all vectors with IVFADC (|C1|=2^16 for YFCC100M, 2^18 for DEEP1B), then query the entire dataset back against itself.
- Measured evidence
- Section 6.5: 95M YFCC100M (>0.8 accuracy, S=1, R=4) finishes in 35 minutes; 1B DEEP1B finishes in 6 hr (low quality) to under 12 hr (high quality).
- Production impact
- Enables billion-scale dataset deduplication, clustering, and image-graph traversal on one multi-GPU machine.
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 (
1M128-d): fusingWarpSelectintocuBLASGEMM hits 85% of peak, beats unfused write-back by 25%+, and beatsthrust::sort_by_keyby over 10x. - SIFT1B (
1Bvectors,8bytes/vector): single-GPU Faiss hitsR@10 = 0.376in 17.7 microseconds per query, 8.5x faster than prior GPU state of the art. - DEEP1B (
1Bvectors,20 GB): shardingS = 2and replicatingR = 2across 4 Titan X GPUs reachesR@1 = 0.4517in 0.0133 ms per query vs. 20 ms on 1 CPU thread. - k-NN Graph builds: querying IVFADC against itself builds a
95MYFCC100M graph in 35 minutes and a1BDEEP1B graph in under 12 hours on 4 GPUs vs. 108.7 hours on 128 CPUs for36.5MNN-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.


