faiss 0.6.3 → 0.6.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/ext/faiss/extconf.rb +1 -1
- data/lib/faiss/version.rb +1 -1
- data/vendor/faiss/faiss/AutoTune.cpp +175 -0
- data/vendor/faiss/faiss/Clustering.cpp +150 -60
- data/vendor/faiss/faiss/Clustering.h +37 -0
- data/vendor/faiss/faiss/IVFlib.cpp +99 -0
- data/vendor/faiss/faiss/IVFlib.h +15 -0
- data/vendor/faiss/faiss/Index.cpp +44 -0
- data/vendor/faiss/faiss/Index.h +18 -13
- data/vendor/faiss/faiss/IndexBinary.cpp +8 -0
- data/vendor/faiss/faiss/IndexBinary.h +8 -0
- data/vendor/faiss/faiss/IndexBinaryFromFloat.cpp +23 -2
- data/vendor/faiss/faiss/IndexBinaryHNSW.cpp +94 -144
- data/vendor/faiss/faiss/IndexBinaryHNSW.h +18 -5
- data/vendor/faiss/faiss/IndexBinaryIVF.cpp +40 -14
- data/vendor/faiss/faiss/IndexBinaryIVF.h +8 -1
- data/vendor/faiss/faiss/IndexFastScan.cpp +33 -17
- data/vendor/faiss/faiss/IndexFastScan.h +6 -3
- data/vendor/faiss/faiss/IndexFlat.cpp +64 -4
- data/vendor/faiss/faiss/IndexFlat.h +33 -2
- data/vendor/faiss/faiss/IndexFlatCodes.cpp +6 -1
- data/vendor/faiss/faiss/IndexHNSW.cpp +755 -99
- data/vendor/faiss/faiss/IndexHNSW.h +69 -7
- data/vendor/faiss/faiss/IndexIDMap.cpp +43 -6
- data/vendor/faiss/faiss/IndexIDMap.h +7 -0
- data/vendor/faiss/faiss/IndexIVF.cpp +297 -32
- data/vendor/faiss/faiss/IndexIVF.h +53 -1
- data/vendor/faiss/faiss/IndexIVFFastScan.cpp +46 -14
- data/vendor/faiss/faiss/IndexIVFFastScan.h +4 -2
- data/vendor/faiss/faiss/IndexIVFFlat.cpp +33 -0
- data/vendor/faiss/faiss/IndexIVFFlat.h +16 -0
- data/vendor/faiss/faiss/IndexIVFPQ.cpp +9 -1
- data/vendor/faiss/faiss/IndexIVFPQ.h +11 -0
- data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +1 -0
- data/vendor/faiss/faiss/IndexIVFRaBitQ.cpp +3 -20
- data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.cpp +50 -14
- data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.h +5 -2
- data/vendor/faiss/faiss/IndexIVFSQFastScan.cpp +855 -0
- data/vendor/faiss/faiss/IndexIVFSQFastScan.h +145 -0
- data/vendor/faiss/faiss/IndexNNDescent.cpp +0 -3
- data/vendor/faiss/faiss/IndexPiPNN.cpp +201 -0
- data/vendor/faiss/faiss/IndexPiPNN.h +83 -0
- data/vendor/faiss/faiss/IndexRaBitQFastScan.cpp +6 -3
- data/vendor/faiss/faiss/IndexRaBitQFastScan.h +10 -4
- data/vendor/faiss/faiss/IndexReplicas.cpp +20 -0
- data/vendor/faiss/faiss/IndexReplicas.h +9 -0
- data/vendor/faiss/faiss/IndexSQFastScan.cpp +648 -0
- data/vendor/faiss/faiss/IndexSQFastScan.h +129 -0
- data/vendor/faiss/faiss/IndexShards.cpp +13 -3
- data/vendor/faiss/faiss/IndexShards.h +5 -0
- data/vendor/faiss/faiss/IndexShardsIVF.cpp +4 -3
- data/vendor/faiss/faiss/SuperKMeans.cpp +87 -22
- data/vendor/faiss/faiss/SuperKMeans.h +12 -6
- data/vendor/faiss/faiss/VectorTransform.cpp +40 -1
- data/vendor/faiss/faiss/VectorTransform.h +3 -0
- data/vendor/faiss/faiss/clone_index.cpp +27 -0
- data/vendor/faiss/faiss/gpu/Dataset.h +112 -0
- data/vendor/faiss/faiss/gpu/GpuCloner.cpp +16 -13
- data/vendor/faiss/faiss/gpu/GpuCloner.h +4 -0
- data/vendor/faiss/faiss/gpu/GpuClonerOptions.h +4 -5
- data/vendor/faiss/faiss/gpu/GpuDistance.h +2 -5
- data/vendor/faiss/faiss/gpu/GpuIndex.h +8 -18
- data/vendor/faiss/faiss/gpu/GpuIndexBinaryCagra.h +26 -13
- data/vendor/faiss/faiss/gpu/GpuIndexCagra.h +109 -63
- data/vendor/faiss/faiss/gpu/GpuIndexFlat.h +11 -0
- data/vendor/faiss/faiss/gpu/GpuIndexIVF.h +6 -0
- data/vendor/faiss/faiss/gpu/test/TestGpuDatasetHeader.cpp +18 -0
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexFlat.cpp +215 -0
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFFlat.cpp +98 -0
- data/vendor/faiss/faiss/gpu/utils/DeviceUtils.h +11 -0
- data/vendor/faiss/faiss/gpu/utils/StackDeviceMemory.cpp +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalCloner.h +11 -0
- data/vendor/faiss/faiss/gpu_metal/MetalDistance.h +92 -0
- data/vendor/faiss/faiss/gpu_metal/MetalIndex.h +4 -0
- data/vendor/faiss/faiss/gpu_metal/MetalIndexBinaryFlat.h +69 -0
- data/vendor/faiss/faiss/gpu_metal/MetalIndexIVFPQ.h +38 -0
- data/vendor/faiss/faiss/gpu_metal/MetalKernels.h +106 -0
- data/vendor/faiss/faiss/gpu_metal/MetalPythonBridge.h +10 -0
- data/vendor/faiss/faiss/impl/AdditiveQuantizer.cpp +1 -1
- data/vendor/faiss/faiss/impl/AuxIndexStructures.cpp +2 -0
- data/vendor/faiss/faiss/impl/AuxIndexStructures.h +1 -6
- data/vendor/faiss/faiss/impl/ClusteringHelpers.cpp +134 -45
- data/vendor/faiss/faiss/impl/ClusteringHelpers.h +36 -0
- data/vendor/faiss/faiss/impl/ClusteringInitialization.cpp +287 -134
- data/vendor/faiss/faiss/impl/DistanceComputer.cpp +63 -0
- data/vendor/faiss/faiss/impl/DistanceComputer.h +3 -29
- data/vendor/faiss/faiss/impl/HNSW.cpp +465 -125
- data/vendor/faiss/faiss/impl/HNSW.h +118 -7
- data/vendor/faiss/faiss/impl/IDSelector.h +44 -0
- data/vendor/faiss/faiss/impl/LocalSearchQuantizer.cpp +6 -19
- data/vendor/faiss/faiss/impl/NNDescent.cpp +12 -4
- data/vendor/faiss/faiss/impl/NSG.cpp +3 -2
- data/vendor/faiss/faiss/impl/Panorama.h +14 -4
- data/vendor/faiss/faiss/impl/PiPNN.cpp +822 -0
- data/vendor/faiss/faiss/impl/PiPNN.h +122 -0
- data/vendor/faiss/faiss/impl/ProductQuantizer.cpp +58 -15
- data/vendor/faiss/faiss/impl/RaBitQUtils.cpp +1 -1
- data/vendor/faiss/faiss/impl/RaBitQUtils.h +1 -1
- data/vendor/faiss/faiss/impl/RaBitQuantizer.cpp +150 -60
- data/vendor/faiss/faiss/impl/RaBitQuantizer.h +62 -4
- data/vendor/faiss/faiss/impl/RaBitQuantizerMultiBit.cpp +2 -2
- data/vendor/faiss/faiss/impl/ResultHandler.h +9 -3
- data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +61 -30
- data/vendor/faiss/faiss/impl/ScalarQuantizer.h +7 -16
- data/vendor/faiss/faiss/impl/approx_topk/avx2.cpp +0 -4
- data/vendor/faiss/faiss/impl/approx_topk/neon.cpp +0 -4
- data/vendor/faiss/faiss/impl/binary_hamming/IndexBinaryHash_impl.h +5 -2
- data/vendor/faiss/faiss/impl/binary_hamming/IndexBinaryIVF_impl.h +89 -13
- data/vendor/faiss/faiss/impl/binary_hamming/avx2.cpp +0 -4
- data/vendor/faiss/faiss/impl/binary_hamming/avx512.cpp +0 -4
- data/vendor/faiss/faiss/impl/binary_hamming/neon.cpp +0 -4
- data/vendor/faiss/faiss/impl/binary_hamming/rvv.cpp +0 -4
- data/vendor/faiss/faiss/impl/expanded_scanners.h +93 -1
- data/vendor/faiss/faiss/impl/fast_scan/FastScanDistancePostProcessing.h +4 -0
- data/vendor/faiss/faiss/impl/fast_scan/accumulate_loops.h +61 -64
- data/vendor/faiss/faiss/impl/fast_scan/accumulate_loops_512.h +13 -14
- data/vendor/faiss/faiss/impl/fast_scan/decompose_qbs.h +18 -129
- data/vendor/faiss/faiss/impl/fast_scan/dispatching.h +25 -19
- data/vendor/faiss/faiss/impl/fast_scan/fast_scan.cpp +5 -0
- data/vendor/faiss/faiss/impl/fast_scan/impl-avx2.cpp +0 -4
- data/vendor/faiss/faiss/impl/fast_scan/impl-avx512.cpp +0 -4
- data/vendor/faiss/faiss/impl/fast_scan/impl-neon.cpp +0 -88
- data/vendor/faiss/faiss/impl/fast_scan/impl-riscv.cpp +0 -4
- data/vendor/faiss/faiss/impl/fast_scan/kernels_neon.h +155 -0
- data/vendor/faiss/faiss/impl/fast_scan/kernels_simd256.h +22 -1
- data/vendor/faiss/faiss/impl/fast_scan/kernels_simd512.h +3 -2
- data/vendor/faiss/faiss/impl/fast_scan/simd_result_handlers.h +41 -23
- data/vendor/faiss/faiss/impl/hnsw/avx2.cpp +0 -4
- data/vendor/faiss/faiss/impl/hnsw/avx512.cpp +0 -4
- data/vendor/faiss/faiss/impl/index_read.cpp +302 -29
- data/vendor/faiss/faiss/impl/index_write.cpp +126 -26
- data/vendor/faiss/faiss/impl/pipnn/HashPrune.cpp +159 -0
- data/vendor/faiss/faiss/impl/pipnn/HashPrune.h +69 -0
- data/vendor/faiss/faiss/impl/pipnn/Partition.cpp +587 -0
- data/vendor/faiss/faiss/impl/pipnn/Partition.h +93 -0
- data/vendor/faiss/faiss/impl/pipnn/kernels.cpp +326 -0
- data/vendor/faiss/faiss/impl/pipnn/kernels.h +92 -0
- data/vendor/faiss/faiss/impl/platform_macros.h +45 -0
- data/vendor/faiss/faiss/impl/polysemous_training/avx512.cpp +0 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/IVFPQScanner_impl.h +152 -43
- data/vendor/faiss/faiss/impl/pq_code_distance/PQDistanceComputer_impl.h +6 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/avx2.cpp +0 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/avx512.cpp +0 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/neon.cpp +0 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-avx2.h +4 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-avx512.h +4 -1
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-generic.cpp +23 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-generic.h +6 -6
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-inl.h +131 -6
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-sve.cpp +0 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_rvv_kernel.h +89 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_scan_impl.h +21 -10
- data/vendor/faiss/faiss/impl/pq_code_distance/rvv.cpp +45 -18
- data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.cpp +2 -1
- data/vendor/faiss/faiss/impl/result_handler/avx2.cpp +0 -4
- data/vendor/faiss/faiss/impl/result_handler/avx512.cpp +0 -4
- data/vendor/faiss/faiss/impl/scalar_quantizer/EDENQuantizer-avx2.cpp +0 -4
- data/vendor/faiss/faiss/impl/scalar_quantizer/EDENQuantizer-avx512.cpp +0 -4
- data/vendor/faiss/faiss/impl/scalar_quantizer/EDENQuantizer.cpp +6 -1
- data/vendor/faiss/faiss/impl/scalar_quantizer/distance_computers.h +7 -3
- data/vendor/faiss/faiss/impl/scalar_quantizer/quantizers.h +28 -52
- data/vendor/faiss/faiss/impl/scalar_quantizer/scanners.h +59 -11
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx2.cpp +232 -79
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512-impl.h +482 -103
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512-spr.cpp +2 -149
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512.cpp +3 -698
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-dispatch.h +101 -72
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-neon.cpp +203 -99
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-rvv.cpp +3185 -144
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq8_coefficients.h +48 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq8_rvv_kernel.h +546 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/training.cpp +2 -2
- data/vendor/faiss/faiss/impl/simd_dispatch.h +47 -22
- data/vendor/faiss/faiss/impl/simdlib/simdlib_avx2.h +14 -0
- data/vendor/faiss/faiss/impl/simdlib/simdlib_dispatch.h +7 -8
- data/vendor/faiss/faiss/impl/sq_fastscan_utils.h +232 -0
- data/vendor/faiss/faiss/index_factory.cpp +84 -1
- data/vendor/faiss/faiss/invlists/InvertedLists.cpp +10 -5
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.cpp +10 -4
- data/vendor/faiss/faiss/svs/IndexSVSVamana.cpp +16 -4
- data/vendor/faiss/faiss/svs/IndexSVSVamana.h +11 -3
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLVQ.cpp +4 -2
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLVQ.h +2 -1
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLeanVec.cpp +9 -2
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLeanVec.h +2 -1
- data/vendor/faiss/faiss/utils/AlignedTable.h +6 -1
- data/vendor/faiss/faiss/utils/Heap.cpp +4 -3
- data/vendor/faiss/faiss/utils/approx_topk_hamming/approx_topk_hamming.h +16 -5
- data/vendor/faiss/faiss/utils/bf16.h +36 -0
- data/vendor/faiss/faiss/utils/distances.cpp +246 -28
- data/vendor/faiss/faiss/utils/distances.h +34 -0
- data/vendor/faiss/faiss/utils/distances_dispatch.h +36 -28
- data/vendor/faiss/faiss/utils/distances_fused/avx512.cpp +2 -5
- data/vendor/faiss/faiss/utils/distances_fused/distances_fused.cpp +1 -15
- data/vendor/faiss/faiss/utils/distances_fused/rvv.cpp +25 -0
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_based.cpp +0 -4
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_based_neon.cpp +0 -4
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_kernel-inl.h +2 -1
- data/vendor/faiss/faiss/utils/distances_simd.cpp +9 -0
- data/vendor/faiss/faiss/utils/fp16-fp16c.h +4 -0
- data/vendor/faiss/faiss/utils/fp16-inl.h +26 -52
- data/vendor/faiss/faiss/utils/hamming.cpp +15 -9
- data/vendor/faiss/faiss/utils/hamming.h +10 -1
- data/vendor/faiss/faiss/utils/hamming_distance/common.h +14 -3
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_avx2.cpp +0 -4
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_avx512.cpp +0 -4
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_avx512_vpopcnt.cpp +20 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-avx512.h +34 -6
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-avx512_vpopcnt.h +217 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-neon.h +0 -4
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_impl.h +143 -1
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_neon.cpp +0 -4
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_rvv.cpp +0 -4
- data/vendor/faiss/faiss/utils/pq_code_distance.h +8 -4
- data/vendor/faiss/faiss/utils/prefetch.h +1 -26
- data/vendor/faiss/faiss/utils/quantize_lut.cpp +26 -27
- data/vendor/faiss/faiss/utils/quantize_lut.h +11 -0
- data/vendor/faiss/faiss/utils/rabitq_simd.h +51 -16
- data/vendor/faiss/faiss/utils/simd_impl/distances_aarch64.cpp +9 -4
- data/vendor/faiss/faiss/utils/simd_impl/distances_arm_sve.cpp +231 -35
- data/vendor/faiss/faiss/utils/simd_impl/distances_avx2.cpp +64 -5
- data/vendor/faiss/faiss/utils/simd_impl/distances_avx512.cpp +64 -5
- data/vendor/faiss/faiss/utils/simd_impl/distances_rvv.cpp +428 -108
- data/vendor/faiss/faiss/utils/simd_impl/distances_rvv_kernel.h +68 -0
- data/vendor/faiss/faiss/utils/simd_impl/exhaustive_L2sqr_blas_cmax.h +93 -0
- data/vendor/faiss/faiss/utils/simd_impl/fp16_kernels.h +76 -0
- data/vendor/faiss/faiss/utils/simd_impl/fp16_kernels_avx2.cpp +52 -0
- data/vendor/faiss/faiss/utils/simd_impl/fp16_kernels_avx512.cpp +52 -0
- data/vendor/faiss/faiss/utils/simd_impl/fp16_kernels_neon.cpp +48 -0
- data/vendor/faiss/faiss/utils/simd_impl/masked_sum-avx2.h +44 -0
- data/vendor/faiss/faiss/utils/simd_impl/masked_sum-avx512.h +43 -0
- data/vendor/faiss/faiss/utils/simd_impl/masked_sum.h +38 -0
- data/vendor/faiss/faiss/utils/simd_impl/partitioning_avx2.cpp +0 -4
- data/vendor/faiss/faiss/utils/simd_impl/partitioning_neon.cpp +0 -4
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_avx2.cpp +54 -15
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_avx512.cpp +89 -55
- data/vendor/faiss/faiss/utils/simd_impl/{rabitq_avx512_spr.cpp → rabitq_avx512_vpopcnt.cpp} +70 -36
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_neon.cpp +297 -10
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_rvv.cpp +0 -4
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_dispatch.h +2 -7
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_kernels.h +6 -1
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_kernels_avx2.cpp +0 -4
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_kernels_avx512.cpp +0 -4
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_kernels_sve.cpp +30 -0
- data/vendor/faiss/faiss/utils/simd_levels.cpp +191 -70
- data/vendor/faiss/faiss/utils/simd_levels.h +100 -16
- data/vendor/faiss/faiss/utils/transpose/transpose-avx2-inl.h +0 -4
- data/vendor/faiss/faiss/utils/transpose/transpose-avx512-inl.h +0 -4
- data/vendor/faiss/faiss/utils/utils.cpp +80 -0
- data/vendor/faiss/faiss/utils/utils.h +24 -0
- metadata +38 -5
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_avx512_spr.cpp +0 -15
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-avx512_spr.h +0 -171
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include <faiss/Index.h>
|
|
11
|
+
|
|
12
|
+
#include <memory>
|
|
13
|
+
|
|
14
|
+
namespace faiss {
|
|
15
|
+
namespace gpu {
|
|
16
|
+
class GpuResourcesProvider;
|
|
17
|
+
|
|
18
|
+
/** Caller-controlled dense vector storage for cuVS CAGRA.
|
|
19
|
+
*
|
|
20
|
+
* Dimensions and row strides are in elements, with contiguous columns. Binary
|
|
21
|
+
* vectors use UInt8, and their dimension is the number of bytes, not bits.
|
|
22
|
+
* Views never own or copy their allocation. An owning Dataset controls the
|
|
23
|
+
* allocation's lifetime; CAGRA always borrows it. Keep the backing allocation
|
|
24
|
+
* alive and unchanged until all indexes using it and queued GPU work finish.
|
|
25
|
+
* Moving an owning Dataset preserves its allocation and existing borrowed
|
|
26
|
+
* views.
|
|
27
|
+
*/
|
|
28
|
+
class Dataset {
|
|
29
|
+
public:
|
|
30
|
+
enum class Layout { Standard, Padded };
|
|
31
|
+
|
|
32
|
+
~Dataset();
|
|
33
|
+
Dataset(Dataset&&) noexcept;
|
|
34
|
+
Dataset& operator=(Dataset&&) noexcept;
|
|
35
|
+
Dataset(const Dataset&) = delete;
|
|
36
|
+
Dataset& operator=(const Dataset&) = delete;
|
|
37
|
+
|
|
38
|
+
/// Borrow host storage. rowStride must be at least dim.
|
|
39
|
+
static Dataset viewHost(
|
|
40
|
+
const void* data,
|
|
41
|
+
idx_t numRows,
|
|
42
|
+
int dim,
|
|
43
|
+
NumericType numericType,
|
|
44
|
+
idx_t rowStride);
|
|
45
|
+
|
|
46
|
+
/// Borrow storage accessible on device. A Standard view can also be
|
|
47
|
+
/// CAGRA-compatible when its physical stride and alignment satisfy padding.
|
|
48
|
+
/// When used by CAGRA, elements between dim and rowStride must be zero.
|
|
49
|
+
static Dataset viewDevice(
|
|
50
|
+
const void* data,
|
|
51
|
+
idx_t numRows,
|
|
52
|
+
int dim,
|
|
53
|
+
NumericType numericType,
|
|
54
|
+
idx_t rowStride,
|
|
55
|
+
int device);
|
|
56
|
+
|
|
57
|
+
/// Borrow CAGRA-compatible device storage without copying. The base address
|
|
58
|
+
/// must be 16-byte aligned and rowStride must equal dim rounded up to a
|
|
59
|
+
/// 16-byte row width. The caller must zero elements between dim and
|
|
60
|
+
/// rowStride, including for compatible Standard views used by CAGRA.
|
|
61
|
+
static Dataset viewDevicePadded(
|
|
62
|
+
const void* data,
|
|
63
|
+
idx_t numRows,
|
|
64
|
+
int dim,
|
|
65
|
+
NumericType numericType,
|
|
66
|
+
idx_t rowStride,
|
|
67
|
+
int device);
|
|
68
|
+
|
|
69
|
+
/// Create padded device storage using cuVS make_device_padded_dataset.
|
|
70
|
+
/// Device/managed input whose stride already matches the required padding
|
|
71
|
+
/// is rejected; use a view for that storage. Copies logical columns and
|
|
72
|
+
/// zeroes padding asynchronously on the resource's stream. Source data must
|
|
73
|
+
/// be ready on that stream and stay alive and unchanged until copying
|
|
74
|
+
/// finishes. Order subsequent use on that stream. Retains the resources
|
|
75
|
+
/// needed to release the allocation.
|
|
76
|
+
static Dataset makeDevicePadded(
|
|
77
|
+
GpuResourcesProvider* resources,
|
|
78
|
+
const Dataset& source,
|
|
79
|
+
int device);
|
|
80
|
+
|
|
81
|
+
const void* getData() const;
|
|
82
|
+
idx_t getNumRows() const;
|
|
83
|
+
int getDim() const;
|
|
84
|
+
idx_t getRowStride() const;
|
|
85
|
+
NumericType getNumericType() const;
|
|
86
|
+
int getDevice() const; // -1 for host storage
|
|
87
|
+
Layout getLayout() const;
|
|
88
|
+
bool isDevice() const;
|
|
89
|
+
bool ownsData() const;
|
|
90
|
+
|
|
91
|
+
/// Reports device residency, base alignment, and exact required row stride.
|
|
92
|
+
/// Does not inspect padding values; zero padding is a caller contract.
|
|
93
|
+
bool isCagraCompatible() const;
|
|
94
|
+
|
|
95
|
+
/// Create a non-owning view of the same storage by copying its metadata.
|
|
96
|
+
/// Does not retain ownership of the backing allocation.
|
|
97
|
+
Dataset view() const;
|
|
98
|
+
|
|
99
|
+
/// Copy logical columns into packed host storage. destination must have
|
|
100
|
+
/// numRows * dim * sizeof(element) bytes. Completes all device work using
|
|
101
|
+
/// the source device before copying and returns with the host data ready.
|
|
102
|
+
void copyToHost(void* destination) const;
|
|
103
|
+
|
|
104
|
+
private:
|
|
105
|
+
struct Impl;
|
|
106
|
+
explicit Dataset(std::unique_ptr<Impl> impl);
|
|
107
|
+
const Impl& getImpl() const;
|
|
108
|
+
std::unique_ptr<Impl> impl_;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
} // namespace gpu
|
|
112
|
+
} // namespace faiss
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
#include <faiss/IndexBinaryFlat.h>
|
|
16
16
|
#include <faiss/IndexFlat.h>
|
|
17
|
-
#if defined
|
|
17
|
+
#if defined USE_NVIDIA_CUVS
|
|
18
18
|
#include <faiss/IndexBinaryHNSW.h>
|
|
19
19
|
#include <faiss/IndexHNSW.h>
|
|
20
20
|
#endif
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
#include <faiss/MetaIndexes.h>
|
|
29
29
|
#include <faiss/gpu/GpuIndex.h>
|
|
30
30
|
#include <faiss/gpu/GpuIndexBinaryFlat.h>
|
|
31
|
-
#if defined
|
|
31
|
+
#if defined USE_NVIDIA_CUVS
|
|
32
32
|
#include <faiss/gpu/GpuIndexBinaryCagra.h>
|
|
33
33
|
#include <faiss/gpu/GpuIndexCagra.h>
|
|
34
34
|
#endif
|
|
@@ -92,7 +92,7 @@ Index* ToCPUCloner::clone_Index(const Index* index) {
|
|
|
92
92
|
// (inverse op of ToGpuClonerMultiple)
|
|
93
93
|
|
|
94
94
|
}
|
|
95
|
-
#if defined
|
|
95
|
+
#if defined USE_NVIDIA_CUVS
|
|
96
96
|
else if (auto icg = dynamic_cast<const GpuIndexCagra*>(index)) {
|
|
97
97
|
IndexHNSWCagra* res = new IndexHNSWCagra();
|
|
98
98
|
if (icg->get_numeric_type() != faiss::NumericType::Float32) {
|
|
@@ -171,6 +171,7 @@ Index* ToGpuCloner::clone_Index(const Index* index) {
|
|
|
171
171
|
config.flatConfig.useFloat16 = useFloat16CoarseQuantizer;
|
|
172
172
|
config.use_cuvs = use_cuvs;
|
|
173
173
|
config.allowCpuCoarseQuantizer = allowCpuCoarseQuantizer;
|
|
174
|
+
config.deterministic_tie_break = deterministic_tie_break;
|
|
174
175
|
|
|
175
176
|
GpuIndexIVFFlat* res = new GpuIndexIVFFlat(
|
|
176
177
|
provider, ifl->d, ifl->nlist, ifl->metric_type, config);
|
|
@@ -189,6 +190,7 @@ Index* ToGpuCloner::clone_Index(const Index* index) {
|
|
|
189
190
|
config.flatConfig.useFloat16 = useFloat16CoarseQuantizer;
|
|
190
191
|
config.use_cuvs = use_cuvs;
|
|
191
192
|
config.allowCpuCoarseQuantizer = allowCpuCoarseQuantizer;
|
|
193
|
+
config.deterministic_tie_break = deterministic_tie_break;
|
|
192
194
|
|
|
193
195
|
GpuIndexIVFScalarQuantizer* res = new GpuIndexIVFScalarQuantizer(
|
|
194
196
|
provider,
|
|
@@ -224,6 +226,7 @@ Index* ToGpuCloner::clone_Index(const Index* index) {
|
|
|
224
226
|
config.use_cuvs = use_cuvs;
|
|
225
227
|
config.interleavedLayout = use_cuvs;
|
|
226
228
|
config.allowCpuCoarseQuantizer = allowCpuCoarseQuantizer;
|
|
229
|
+
config.deterministic_tie_break = deterministic_tie_break;
|
|
227
230
|
|
|
228
231
|
GpuIndexIVFPQ* res = new GpuIndexIVFPQ(provider, ipq, config);
|
|
229
232
|
|
|
@@ -233,14 +236,14 @@ Index* ToGpuCloner::clone_Index(const Index* index) {
|
|
|
233
236
|
|
|
234
237
|
return res;
|
|
235
238
|
}
|
|
236
|
-
#if defined
|
|
239
|
+
#if defined USE_NVIDIA_CUVS
|
|
237
240
|
else if (auto icg = dynamic_cast<const faiss::IndexHNSWCagra*>(index)) {
|
|
238
241
|
GpuIndexCagraConfig config;
|
|
239
242
|
config.device = device;
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
res->
|
|
243
|
-
return res;
|
|
243
|
+
auto res = std::make_unique<GpuIndexCagra>(
|
|
244
|
+
provider, icg->d, icg->metric_type, config);
|
|
245
|
+
res->copyFrom(icg);
|
|
246
|
+
return res.release();
|
|
244
247
|
}
|
|
245
248
|
#endif
|
|
246
249
|
else {
|
|
@@ -533,7 +536,7 @@ faiss::IndexBinary* index_binary_gpu_to_cpu(
|
|
|
533
536
|
ii->copyTo(ret);
|
|
534
537
|
return ret;
|
|
535
538
|
}
|
|
536
|
-
#if defined
|
|
539
|
+
#if defined USE_NVIDIA_CUVS
|
|
537
540
|
else if (auto ii = dynamic_cast<const GpuIndexBinaryCagra*>(gpu_index)) {
|
|
538
541
|
IndexBinaryHNSWCagra* ret = new IndexBinaryHNSWCagra();
|
|
539
542
|
ii->copyTo(ret);
|
|
@@ -555,15 +558,15 @@ faiss::IndexBinary* index_binary_cpu_to_gpu(
|
|
|
555
558
|
config.device = device;
|
|
556
559
|
return new GpuIndexBinaryFlat(provider, ii, config);
|
|
557
560
|
}
|
|
558
|
-
#if defined
|
|
561
|
+
#if defined USE_NVIDIA_CUVS
|
|
559
562
|
else if (
|
|
560
563
|
auto ii = dynamic_cast<const faiss::IndexBinaryHNSWCagra*>(index)) {
|
|
561
564
|
GpuIndexCagraConfig config;
|
|
562
565
|
config.device = device;
|
|
563
|
-
|
|
564
|
-
|
|
566
|
+
auto res =
|
|
567
|
+
std::make_unique<GpuIndexBinaryCagra>(provider, ii->d, config);
|
|
565
568
|
res->copyFrom(ii);
|
|
566
|
-
return res;
|
|
569
|
+
return res.release();
|
|
567
570
|
}
|
|
568
571
|
#endif
|
|
569
572
|
else {
|
|
@@ -70,6 +70,8 @@ struct ToGpuClonerMultiple : faiss::Cloner, GpuMultipleClonerOptions {
|
|
|
70
70
|
faiss::Index* index_gpu_to_cpu(const faiss::Index* gpu_index);
|
|
71
71
|
|
|
72
72
|
/// converts any CPU index that can be converted to GPU
|
|
73
|
+
/// CAGRA clones contain only the graph. Call updateDataset with caller-owned,
|
|
74
|
+
/// compatible device storage before searching.
|
|
73
75
|
faiss::Index* index_cpu_to_gpu(
|
|
74
76
|
GpuResourcesProvider* provider,
|
|
75
77
|
int device,
|
|
@@ -105,6 +107,8 @@ faiss::IndexBinary* index_binary_gpu_to_cpu(
|
|
|
105
107
|
const faiss::IndexBinary* gpu_index);
|
|
106
108
|
|
|
107
109
|
/// converts any CPU index that can be converted to GPU
|
|
110
|
+
/// CAGRA clones contain only the graph. Call updateDataset with caller-owned,
|
|
111
|
+
/// compatible device storage before searching.
|
|
108
112
|
faiss::IndexBinary* index_binary_cpu_to_gpu(
|
|
109
113
|
GpuResourcesProvider* provider,
|
|
110
114
|
int device,
|
|
@@ -39,12 +39,11 @@ struct GpuClonerOptions {
|
|
|
39
39
|
/// Set verbose options on the index
|
|
40
40
|
bool verbose = false;
|
|
41
41
|
|
|
42
|
-
///
|
|
43
|
-
#if defined USE_NVIDIA_CUVS
|
|
44
|
-
bool use_cuvs = true;
|
|
45
|
-
#else
|
|
42
|
+
/// Use the cuVS implementation. Opt-in: see GpuIndexConfig::use_cuvs.
|
|
46
43
|
bool use_cuvs = false;
|
|
47
|
-
|
|
44
|
+
|
|
45
|
+
/// IVF indexes only: see GpuIndexIVFConfig::deterministic_tie_break.
|
|
46
|
+
bool deterministic_tie_break = false;
|
|
48
47
|
|
|
49
48
|
/// This flag controls the CPU fallback logic for coarse quantizer
|
|
50
49
|
/// component of the index. When set to false (default), the cloner will
|
|
@@ -107,12 +107,9 @@ struct GpuDistanceParams {
|
|
|
107
107
|
/// execution
|
|
108
108
|
int device = -1;
|
|
109
109
|
|
|
110
|
-
/// Should the
|
|
111
|
-
|
|
112
|
-
bool use_cuvs = true;
|
|
113
|
-
#else
|
|
110
|
+
/// Should the search dispatch down to cuVS? Opt-in: see
|
|
111
|
+
/// GpuIndexConfig::use_cuvs.
|
|
114
112
|
bool use_cuvs = false;
|
|
115
|
-
#endif
|
|
116
113
|
};
|
|
117
114
|
|
|
118
115
|
/// A function that determines whether cuVS should be used based on various
|
|
@@ -38,12 +38,11 @@ struct GpuIndexConfig {
|
|
|
38
38
|
/// more memory than is available on the GPU.
|
|
39
39
|
MemorySpace memorySpace = MemorySpace::Device;
|
|
40
40
|
|
|
41
|
-
/// Should the index dispatch down to cuVS?
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
/// Should the index dispatch down to cuVS? Opt-in: dispatching to cuVS
|
|
42
|
+
/// selects a different implementation with its own numerical behaviour, so
|
|
43
|
+
/// it must be an explicit choice by the caller rather than a consequence of
|
|
44
|
+
/// how the binary happened to be built.
|
|
45
45
|
bool use_cuvs = false;
|
|
46
|
-
#endif
|
|
47
46
|
};
|
|
48
47
|
|
|
49
48
|
/// A centralized function that determines whether cuVS should
|
|
@@ -214,6 +213,9 @@ class GpuIndex : public faiss::Index {
|
|
|
214
213
|
idx_t* labels,
|
|
215
214
|
const SearchParameters* params) const = 0;
|
|
216
215
|
|
|
216
|
+
/// Search with queries of the given numeric type; all data is guaranteed
|
|
217
|
+
/// to be resident on our device. The default handles Float32 and widens
|
|
218
|
+
/// Float16 queries to float32 on the device before calling searchImpl_
|
|
217
219
|
virtual void searchImpl_ex_(
|
|
218
220
|
idx_t n,
|
|
219
221
|
const void* x,
|
|
@@ -221,19 +223,7 @@ class GpuIndex : public faiss::Index {
|
|
|
221
223
|
int k,
|
|
222
224
|
float* distances,
|
|
223
225
|
idx_t* labels,
|
|
224
|
-
const SearchParameters* params) const
|
|
225
|
-
if (numeric_type == NumericType::Float32) {
|
|
226
|
-
searchImpl_(
|
|
227
|
-
n,
|
|
228
|
-
static_cast<const float*>(x),
|
|
229
|
-
k,
|
|
230
|
-
distances,
|
|
231
|
-
labels,
|
|
232
|
-
params);
|
|
233
|
-
} else {
|
|
234
|
-
FAISS_THROW_MSG("GpuIndex::searchImpl_: unsupported numeric type");
|
|
235
|
-
}
|
|
236
|
-
}
|
|
226
|
+
const SearchParameters* params) const;
|
|
237
227
|
|
|
238
228
|
private:
|
|
239
229
|
/// Calls addImpl_ for a single page of GPU-resident data
|
|
@@ -33,6 +33,7 @@ namespace faiss {
|
|
|
33
33
|
namespace gpu {
|
|
34
34
|
|
|
35
35
|
class BinaryCuvsCagra;
|
|
36
|
+
class Dataset;
|
|
36
37
|
|
|
37
38
|
struct GpuIndexBinaryCagra : public IndexBinary {
|
|
38
39
|
public:
|
|
@@ -49,22 +50,34 @@ struct GpuIndexBinaryCagra : public IndexBinary {
|
|
|
49
50
|
/// stream and handle resources on the GPU
|
|
50
51
|
std::shared_ptr<GpuResources> getResources();
|
|
51
52
|
|
|
52
|
-
///
|
|
53
|
-
/// NB: The use of the add function here is to build the CAGRA graph on
|
|
54
|
-
/// the base dataset. Use this function when you want to add vectors with
|
|
55
|
-
/// ids. Ref: https://github.com/facebookresearch/faiss/issues/4107
|
|
53
|
+
/// Pointer-based construction is unsupported. Use a caller-owned Dataset.
|
|
56
54
|
void add(idx_t n, const uint8_t* x) override;
|
|
57
|
-
|
|
58
|
-
/// Trains CAGRA based on the given vector data.
|
|
59
|
-
/// NB: The use of the train function here is to build the CAGRA graph on
|
|
60
|
-
/// the base dataset and is currently the only function to add the full set
|
|
61
|
-
/// of vectors (without IDs) to the index. There is no external quantizer to
|
|
62
|
-
/// be trained here.
|
|
63
55
|
void train(idx_t n, const uint8_t* x) override;
|
|
64
56
|
|
|
65
|
-
///
|
|
66
|
-
///
|
|
67
|
-
|
|
57
|
+
/// Build the full graph, borrowing UInt8 vectors with dim == d / 8.
|
|
58
|
+
/// The backing storage must remain alive and unchanged until all index
|
|
59
|
+
/// operations have completed. Does nothing if already trained; call reset()
|
|
60
|
+
/// before building again.
|
|
61
|
+
void train(const Dataset& dataset) override;
|
|
62
|
+
void add(const Dataset& dataset) override;
|
|
63
|
+
|
|
64
|
+
/// Rebind search storage without changing the graph. The vectors and their
|
|
65
|
+
/// ordering must match the training data. Requires compatible device data;
|
|
66
|
+
/// any padding must be zero and the caller retains ownership. Previous
|
|
67
|
+
/// work on the index stream completes before rebinding.
|
|
68
|
+
void updateDataset(const Dataset& dataset);
|
|
69
|
+
bool isSearchReady() const;
|
|
70
|
+
|
|
71
|
+
/// Copy the CPU graph. Without a Dataset, import only the graph and
|
|
72
|
+
/// metadata; attach vectors with updateDataset before search or copyTo.
|
|
73
|
+
/// If provided, dataset must describe writable, compatible storage on this
|
|
74
|
+
/// device with the CPU index's shape and UInt8 type. Copy CPU vectors into
|
|
75
|
+
/// that allocation, zero padding, and borrow it for search. The caller owns
|
|
76
|
+
/// the allocation and must keep it alive through index use. Copies complete
|
|
77
|
+
/// before return, so the CPU index can be released in either case.
|
|
78
|
+
void copyFrom(
|
|
79
|
+
const faiss::IndexBinaryHNSWCagra* index,
|
|
80
|
+
Dataset* dataset = nullptr);
|
|
68
81
|
|
|
69
82
|
/// Copy ourselves to the given CPU index; will overwrite all data
|
|
70
83
|
/// in the index instance
|
|
@@ -27,6 +27,11 @@
|
|
|
27
27
|
#include <faiss/gpu/GpuIndex.h>
|
|
28
28
|
#include <faiss/gpu/GpuIndexIVFPQ.h>
|
|
29
29
|
|
|
30
|
+
#ifndef SWIG
|
|
31
|
+
#include <faiss/gpu/Dataset.h>
|
|
32
|
+
#include <optional>
|
|
33
|
+
#endif
|
|
34
|
+
|
|
30
35
|
#include <variant>
|
|
31
36
|
#include <vector>
|
|
32
37
|
#include "faiss/Index.h"
|
|
@@ -47,7 +52,9 @@ enum class graph_build_algo {
|
|
|
47
52
|
/// Use NN-Descent to build all-neighbors knn graph
|
|
48
53
|
NN_DESCENT,
|
|
49
54
|
/// Use iterative search to build knn graph
|
|
50
|
-
ITERATIVE_SEARCH
|
|
55
|
+
ITERATIVE_SEARCH,
|
|
56
|
+
/// Exact knn graph via tiled brute force
|
|
57
|
+
BRUTE_FORCE
|
|
51
58
|
};
|
|
52
59
|
|
|
53
60
|
/// A type for specifying how PQ codebooks are created.
|
|
@@ -173,6 +180,34 @@ struct IVFPQSearchCagraConfig {
|
|
|
173
180
|
uint32_t max_internal_batch_size = 4096;
|
|
174
181
|
};
|
|
175
182
|
|
|
183
|
+
/// Knobs for the multi-GPU build path, selected by listing more than one
|
|
184
|
+
/// device in GpuIndexCagraConfig::devices. Degrees, build_algo and metric
|
|
185
|
+
/// still come from GpuIndexCagraConfig.
|
|
186
|
+
struct AllNeighborsCagraConfig {
|
|
187
|
+
/// Number of overlapping clusters the dataset is partitioned into.
|
|
188
|
+
/// 0 selects max(2 * number of devices, 4).
|
|
189
|
+
size_t n_clusters = 0;
|
|
190
|
+
|
|
191
|
+
/// Clusters each vector is assigned to. Must be >= 2: with 1 there are no
|
|
192
|
+
/// cross-cluster edges and recall collapses. 0 selects 2.
|
|
193
|
+
size_t overlap_factor = 2;
|
|
194
|
+
|
|
195
|
+
/// Bounds IVF-PQ search memory during the knn build. cuVS's default can
|
|
196
|
+
/// exhaust device memory around 100M vectors; 8192 avoids that and does
|
|
197
|
+
/// not change recall. 0 keeps cuVS's default.
|
|
198
|
+
uint32_t ivf_pq_search_batch_size = 0;
|
|
199
|
+
|
|
200
|
+
/// IVF-PQ refinement multiplier. The refine pass runs on the CPU, so cost
|
|
201
|
+
/// scales with this. Raising it above 1.0 measured both slower and less
|
|
202
|
+
/// accurate, so it is separate from the shared refine_rate.
|
|
203
|
+
float refinement_rate = 1.0f;
|
|
204
|
+
|
|
205
|
+
/// Size the IVF-PQ index for one cluster rather than the whole dataset.
|
|
206
|
+
/// cuVS reuses these params for every cluster without rescaling, so
|
|
207
|
+
/// sizing from the full dataset badly over-partitions each one.
|
|
208
|
+
bool ivf_pq_size_from_cluster = true;
|
|
209
|
+
};
|
|
210
|
+
|
|
176
211
|
struct GpuIndexCagraConfig : public GpuIndexConfig {
|
|
177
212
|
/// Degree of input graph for pruning.
|
|
178
213
|
size_t intermediate_graph_degree = 128;
|
|
@@ -186,10 +221,30 @@ struct GpuIndexCagraConfig : public GpuIndexConfig {
|
|
|
186
221
|
std::shared_ptr<IVFPQBuildCagraConfig> ivf_pq_params{nullptr};
|
|
187
222
|
std::shared_ptr<IVFPQSearchCagraConfig> ivf_pq_search_params{nullptr};
|
|
188
223
|
float refine_rate = 2.0f;
|
|
189
|
-
bool store_dataset = true;
|
|
190
224
|
|
|
191
225
|
/// Whether to use MST optimization to guarantee graph connectivity.
|
|
192
226
|
bool guarantee_connectivity = false;
|
|
227
|
+
|
|
228
|
+
/// Devices to build on. More than one selects the multi-GPU build in
|
|
229
|
+
/// train(); see AllNeighborsCagraConfig and train() for its restrictions.
|
|
230
|
+
/// Empty or one device uses GpuIndexConfig::device as usual.
|
|
231
|
+
std::vector<int> devices;
|
|
232
|
+
|
|
233
|
+
AllNeighborsCagraConfig all_neighbors_params;
|
|
234
|
+
|
|
235
|
+
/// Build the HNSW upper levels on the GPU during copyTo() instead of by
|
|
236
|
+
/// CPU insertion. Roughly 10x faster, but measured worse recall than
|
|
237
|
+
/// base_level_only, which is cheaper still. Off by default.
|
|
238
|
+
bool gpu_hnsw_upper_levels = false;
|
|
239
|
+
|
|
240
|
+
/// intermediate_graph_degree for the per-level subgraph builds.
|
|
241
|
+
/// 0 = twice the upper-level degree.
|
|
242
|
+
size_t gpu_hnsw_intermediate_degree = 0;
|
|
243
|
+
|
|
244
|
+
/// MST connectivity pass on the per-level subgraphs. On by default:
|
|
245
|
+
/// upper levels are walked greedily with no backtracking, so a
|
|
246
|
+
/// disconnected component is a trap the descent cannot escape.
|
|
247
|
+
bool gpu_hnsw_guarantee_connectivity = true;
|
|
193
248
|
};
|
|
194
249
|
|
|
195
250
|
enum class search_algo {
|
|
@@ -258,72 +313,47 @@ struct GpuIndexCagra : public GpuIndex {
|
|
|
258
313
|
faiss::MetricType metric = faiss::METRIC_L2,
|
|
259
314
|
GpuIndexCagraConfig config = GpuIndexCagraConfig());
|
|
260
315
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
/// the
|
|
264
|
-
///
|
|
316
|
+
~GpuIndexCagra() override;
|
|
317
|
+
|
|
318
|
+
/// Build the full graph while borrowing dataset storage. The backing
|
|
319
|
+
/// allocation must remain alive and unchanged through index use and all
|
|
320
|
+
/// outstanding GPU work. Does nothing if already trained; call reset()
|
|
321
|
+
/// before building again.
|
|
322
|
+
void train(const Dataset& dataset) override;
|
|
323
|
+
|
|
324
|
+
/// Equivalent to train(dataset); incremental insertion is unsupported.
|
|
325
|
+
void add(const Dataset& dataset) override;
|
|
326
|
+
|
|
327
|
+
/// Attach search-compatible device storage without changing the graph.
|
|
328
|
+
/// Shape, dtype and vector ordering must match the trained dataset. The
|
|
329
|
+
/// values must be the same; this method does not rebuild for changed data.
|
|
330
|
+
/// Previous work on this index's stream completes before rebinding.
|
|
331
|
+
void updateDataset(const Dataset& dataset);
|
|
332
|
+
bool isSearchReady() const;
|
|
333
|
+
|
|
334
|
+
/// Copy the CPU graph and metadata. With no dataset, import only the
|
|
335
|
+
/// graph: no vector storage is retained and GPU search is unavailable.
|
|
336
|
+
/// When supplied, dataset must describe writable CAGRA-compatible device
|
|
337
|
+
/// storage with matching shape and dtype on this index's device. Its
|
|
338
|
+
/// contents are overwritten with CPU vectors and its padding is zeroed.
|
|
339
|
+
/// The index borrows that allocation and becomes search-ready. The caller
|
|
340
|
+
/// retains ownership and must keep the allocation alive through index use
|
|
341
|
+
/// and queued GPU work. Copies finish before return, so the CPU index may
|
|
342
|
+
/// then be released in either mode.
|
|
343
|
+
void copyFrom(
|
|
344
|
+
const faiss::IndexHNSWCagra* index,
|
|
345
|
+
Dataset* dataset = nullptr);
|
|
346
|
+
|
|
347
|
+
/// Legacy pointer entry points throw: use the Dataset overloads.
|
|
265
348
|
void add(idx_t n, const float* x) override;
|
|
266
349
|
void add_ex(idx_t n, const void* x, NumericType numeric_type) override;
|
|
267
|
-
|
|
268
|
-
/// Trains CAGRA based on the given vector data.
|
|
269
|
-
/// NB: The use of the train function here is to build the CAGRA graph on
|
|
270
|
-
/// the base dataset and is currently the only function to add the full set
|
|
271
|
-
/// of vectors (without IDs) to the index. There is no external quantizer to
|
|
272
|
-
/// be trained here.
|
|
273
350
|
void train(idx_t n, const float* x) override;
|
|
274
351
|
void train_ex(idx_t n, const void* x, NumericType numeric_type) override;
|
|
275
352
|
|
|
276
|
-
/// Initialize ourselves from the given CPU index; will overwrite
|
|
277
|
-
/// all data in ourselves
|
|
278
|
-
void copyFrom(const faiss::IndexHNSWCagra* index);
|
|
279
|
-
void copyFrom_ex(
|
|
280
|
-
const faiss::IndexHNSWCagra* index,
|
|
281
|
-
NumericType numeric_type);
|
|
282
|
-
|
|
283
353
|
/// Copy ourselves to the given CPU index; will overwrite all data
|
|
284
354
|
/// in the index instance
|
|
285
355
|
void copyTo(faiss::IndexHNSWCagra* index) const;
|
|
286
356
|
|
|
287
|
-
/// Train CAGRA using multiple GPUs by sharding the dataset.
|
|
288
|
-
/// Uses cuVS native SNMG (single-node multi-GPU) CAGRA build.
|
|
289
|
-
/// Each device builds one shard in parallel via OpenMP.
|
|
290
|
-
/// Float32 only. After training, call copyTo() to produce a CPU
|
|
291
|
-
/// IndexHNSWCagra with full HNSW upper levels.
|
|
292
|
-
/// The training data pointer must remain valid until copyTo() completes.
|
|
293
|
-
/// stitch_mode: 0=CPU HNSW (Approach C), 1=GPU brute-force (Approach B)
|
|
294
|
-
void trainMultiGpu(
|
|
295
|
-
idx_t n,
|
|
296
|
-
const float* x,
|
|
297
|
-
std::vector<GpuResourcesProvider*>& providers,
|
|
298
|
-
std::vector<int>& devices,
|
|
299
|
-
idx_t stitch_per_shard = 0,
|
|
300
|
-
int stitch_k = 2,
|
|
301
|
-
int stitch_mode = 0);
|
|
302
|
-
|
|
303
|
-
/// Build a unified CAGRA graph using cuVS all_neighbors
|
|
304
|
-
/// (multi-GPU kNN graph construction with overlapping clusters) followed
|
|
305
|
-
/// by cagra::optimize (graph pruning). Produces a single unified graph
|
|
306
|
-
/// without stitching. The training data pointer must remain valid until
|
|
307
|
-
/// copyTo() completes.
|
|
308
|
-
/// build_algo: 0=NN-descent (default), 1=brute-force, 2=IVF-PQ
|
|
309
|
-
/// refinement_rate: IVF-PQ refinement multiplier (only used when
|
|
310
|
-
/// build_algo==2). Higher values trade build time for recall; the cuVS
|
|
311
|
-
/// default is 2.0.
|
|
312
|
-
/// ivfpq_search_batch: cap the IVF-PQ search `max_internal_batch_size` used
|
|
313
|
-
/// during the all_neighbors kNN build (build_algo==2). 0 = cuVS default
|
|
314
|
-
/// (128*1024), which can OOM at 100M; a smaller value (e.g. 8192) bounds
|
|
315
|
-
/// the GPU search workspace with no effect on results (recall-neutral).
|
|
316
|
-
void trainAllNeighbors(
|
|
317
|
-
idx_t n,
|
|
318
|
-
const float* x,
|
|
319
|
-
std::vector<int>& devices,
|
|
320
|
-
int n_clusters = 0,
|
|
321
|
-
int overlap_factor = 0,
|
|
322
|
-
bool multi_gpu_optimize = false,
|
|
323
|
-
int build_algo = 0,
|
|
324
|
-
float refinement_rate = 2.0f,
|
|
325
|
-
int ivfpq_search_batch = 0);
|
|
326
|
-
|
|
327
357
|
void reset() override;
|
|
328
358
|
|
|
329
359
|
std::vector<idx_t> get_knngraph() const;
|
|
@@ -357,14 +387,28 @@ struct GpuIndexCagra : public GpuIndex {
|
|
|
357
387
|
idx_t* labels,
|
|
358
388
|
const SearchParameters* search_params) const override;
|
|
359
389
|
|
|
390
|
+
/// Multi-GPU build path taken by train() when cagraConfig_.devices lists
|
|
391
|
+
/// more than one device: cuVS `all_neighbors` knn graph construction over
|
|
392
|
+
/// overlapping clusters, followed by graph pruning. Leaves the result in
|
|
393
|
+
/// merged_knngraph_ for copyTo(); index_ stays empty.
|
|
394
|
+
#ifndef SWIG
|
|
395
|
+
void trainAllNeighbors_(const Dataset& dataset);
|
|
396
|
+
#endif
|
|
397
|
+
|
|
398
|
+
/// Populate HNSW levels >= 1 of `index` by building a CAGRA graph over
|
|
399
|
+
/// each level's node subset on the GPU. Requires the level table to be
|
|
400
|
+
/// prepared and the storage populated. Returns the max level.
|
|
401
|
+
void buildHnswUpperLevelsGpu_(faiss::IndexHNSWCagra* index, int max_lvl)
|
|
402
|
+
const;
|
|
403
|
+
|
|
360
404
|
void copyToMultiGpu_(faiss::IndexHNSWCagra* index) const;
|
|
361
405
|
|
|
362
406
|
/// Our configuration options
|
|
363
407
|
const GpuIndexCagraConfig cagraConfig_;
|
|
364
408
|
|
|
365
|
-
faiss::NumericType numeric_type_;
|
|
409
|
+
faiss::NumericType numeric_type_ = NumericType::Float32;
|
|
366
410
|
|
|
367
|
-
/// Instance that
|
|
411
|
+
/// Instance that owns the CAGRA graph and borrows dataset storage
|
|
368
412
|
std::variant<
|
|
369
413
|
std::monostate,
|
|
370
414
|
std::shared_ptr<CuvsCagra<float>>,
|
|
@@ -372,10 +416,12 @@ struct GpuIndexCagra : public GpuIndex {
|
|
|
372
416
|
std::shared_ptr<CuvsCagra<int8_t>>>
|
|
373
417
|
index_;
|
|
374
418
|
|
|
375
|
-
/// Multi-GPU state: populated by
|
|
419
|
+
/// Multi-GPU state: populated by trainAllNeighbors_(), used by copyTo()
|
|
376
420
|
std::vector<idx_t> merged_knngraph_;
|
|
377
421
|
idx_t merged_knngraph_degree_ = 0;
|
|
378
|
-
|
|
422
|
+
#ifndef SWIG
|
|
423
|
+
std::optional<Dataset> multiGpuDataset_;
|
|
424
|
+
#endif
|
|
379
425
|
};
|
|
380
426
|
|
|
381
427
|
} // namespace gpu
|
|
@@ -131,6 +131,17 @@ class GpuIndexFlat : public GpuIndex {
|
|
|
131
131
|
idx_t* labels,
|
|
132
132
|
const SearchParameters* params) const override;
|
|
133
133
|
|
|
134
|
+
/// Called from GpuIndex for search; Float16 queries are searched without
|
|
135
|
+
/// conversion against float16 storage
|
|
136
|
+
void searchImpl_ex_(
|
|
137
|
+
idx_t n,
|
|
138
|
+
const void* x,
|
|
139
|
+
NumericType numeric_type,
|
|
140
|
+
int k,
|
|
141
|
+
float* distances,
|
|
142
|
+
idx_t* labels,
|
|
143
|
+
const SearchParameters* params) const override;
|
|
144
|
+
|
|
134
145
|
protected:
|
|
135
146
|
/// Our configuration options
|
|
136
147
|
const GpuIndexFlatConfig flatConfig_;
|
|
@@ -32,6 +32,12 @@ struct GpuIndexIVFConfig : public GpuIndexConfig {
|
|
|
32
32
|
/// throw an exception for indices not implemented on GPU. When set to
|
|
33
33
|
/// true, it will fallback to a CPU implementation.
|
|
34
34
|
bool allowCpuCoarseQuantizer = false;
|
|
35
|
+
|
|
36
|
+
/// Break a distance tie on the smaller id, so a search repeats. Honoured
|
|
37
|
+
/// by GpuIndexIVFFlat and GpuIndexIVFScalarQuantizer with the interleaved
|
|
38
|
+
/// layout for k up to 1024, and by the cuVS GpuIndexIVFScalarQuantizer
|
|
39
|
+
/// and GpuIndexIVFPQ for k and nprobe up to 256.
|
|
40
|
+
bool deterministic_tie_break = false;
|
|
35
41
|
};
|
|
36
42
|
|
|
37
43
|
/// Base class of all GPU IVF index types. This (for now) deliberately does not
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// Keep this translation unit ordinary C++ without CUDA, RAFT, or cuVS headers.
|
|
9
|
+
#include <faiss/gpu/Dataset.h>
|
|
10
|
+
|
|
11
|
+
#include <type_traits>
|
|
12
|
+
|
|
13
|
+
using faiss::gpu::Dataset;
|
|
14
|
+
|
|
15
|
+
static_assert(!std::is_copy_constructible_v<Dataset>);
|
|
16
|
+
static_assert(!std::is_copy_assignable_v<Dataset>);
|
|
17
|
+
static_assert(std::is_nothrow_move_constructible_v<Dataset>);
|
|
18
|
+
static_assert(std::is_nothrow_move_assignable_v<Dataset>);
|