faiss 0.3.1 → 0.3.3
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/LICENSE.txt +1 -1
- data/lib/faiss/version.rb +1 -1
- data/vendor/faiss/faiss/AutoTune.cpp +2 -2
- data/vendor/faiss/faiss/AutoTune.h +3 -3
- data/vendor/faiss/faiss/Clustering.cpp +37 -6
- data/vendor/faiss/faiss/Clustering.h +12 -3
- data/vendor/faiss/faiss/IVFlib.cpp +6 -3
- data/vendor/faiss/faiss/IVFlib.h +2 -2
- data/vendor/faiss/faiss/Index.cpp +6 -2
- data/vendor/faiss/faiss/Index.h +30 -8
- data/vendor/faiss/faiss/Index2Layer.cpp +2 -2
- data/vendor/faiss/faiss/Index2Layer.h +2 -2
- data/vendor/faiss/faiss/IndexAdditiveQuantizer.cpp +7 -7
- data/vendor/faiss/faiss/IndexAdditiveQuantizer.h +2 -2
- data/vendor/faiss/faiss/IndexAdditiveQuantizerFastScan.cpp +14 -16
- data/vendor/faiss/faiss/IndexAdditiveQuantizerFastScan.h +2 -2
- data/vendor/faiss/faiss/IndexBinary.cpp +13 -2
- data/vendor/faiss/faiss/IndexBinary.h +8 -2
- data/vendor/faiss/faiss/IndexBinaryFlat.cpp +2 -3
- data/vendor/faiss/faiss/IndexBinaryFlat.h +2 -2
- data/vendor/faiss/faiss/IndexBinaryFromFloat.cpp +2 -2
- data/vendor/faiss/faiss/IndexBinaryFromFloat.h +2 -2
- data/vendor/faiss/faiss/IndexBinaryHNSW.cpp +2 -7
- data/vendor/faiss/faiss/IndexBinaryHNSW.h +3 -3
- data/vendor/faiss/faiss/IndexBinaryHash.cpp +2 -3
- data/vendor/faiss/faiss/IndexBinaryHash.h +2 -2
- data/vendor/faiss/faiss/IndexBinaryIVF.cpp +3 -3
- data/vendor/faiss/faiss/IndexBinaryIVF.h +2 -2
- data/vendor/faiss/faiss/IndexFastScan.cpp +32 -18
- data/vendor/faiss/faiss/IndexFastScan.h +11 -2
- data/vendor/faiss/faiss/IndexFlat.cpp +13 -10
- data/vendor/faiss/faiss/IndexFlat.h +2 -2
- data/vendor/faiss/faiss/IndexFlatCodes.cpp +170 -7
- data/vendor/faiss/faiss/IndexFlatCodes.h +25 -5
- data/vendor/faiss/faiss/IndexHNSW.cpp +156 -96
- data/vendor/faiss/faiss/IndexHNSW.h +54 -5
- data/vendor/faiss/faiss/IndexIDMap.cpp +19 -3
- data/vendor/faiss/faiss/IndexIDMap.h +5 -2
- data/vendor/faiss/faiss/IndexIVF.cpp +5 -6
- data/vendor/faiss/faiss/IndexIVF.h +13 -4
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizer.cpp +21 -7
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizer.h +5 -2
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.cpp +3 -14
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.h +2 -4
- data/vendor/faiss/faiss/IndexIVFFastScan.cpp +201 -91
- data/vendor/faiss/faiss/IndexIVFFastScan.h +33 -9
- data/vendor/faiss/faiss/IndexIVFFlat.cpp +2 -2
- data/vendor/faiss/faiss/IndexIVFFlat.h +2 -2
- data/vendor/faiss/faiss/IndexIVFIndependentQuantizer.cpp +2 -2
- data/vendor/faiss/faiss/IndexIVFIndependentQuantizer.h +2 -2
- data/vendor/faiss/faiss/IndexIVFPQ.cpp +3 -6
- data/vendor/faiss/faiss/IndexIVFPQ.h +2 -2
- data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +7 -14
- data/vendor/faiss/faiss/IndexIVFPQFastScan.h +2 -4
- data/vendor/faiss/faiss/IndexIVFPQR.cpp +2 -2
- data/vendor/faiss/faiss/IndexIVFPQR.h +2 -2
- data/vendor/faiss/faiss/IndexIVFSpectralHash.cpp +2 -3
- data/vendor/faiss/faiss/IndexIVFSpectralHash.h +2 -2
- data/vendor/faiss/faiss/IndexLSH.cpp +2 -3
- data/vendor/faiss/faiss/IndexLSH.h +2 -2
- data/vendor/faiss/faiss/IndexLattice.cpp +3 -21
- data/vendor/faiss/faiss/IndexLattice.h +5 -24
- data/vendor/faiss/faiss/IndexNNDescent.cpp +2 -31
- data/vendor/faiss/faiss/IndexNNDescent.h +3 -3
- data/vendor/faiss/faiss/IndexNSG.cpp +2 -5
- data/vendor/faiss/faiss/IndexNSG.h +3 -3
- data/vendor/faiss/faiss/IndexNeuralNetCodec.cpp +56 -0
- data/vendor/faiss/faiss/IndexNeuralNetCodec.h +49 -0
- data/vendor/faiss/faiss/IndexPQ.cpp +26 -26
- data/vendor/faiss/faiss/IndexPQ.h +2 -2
- data/vendor/faiss/faiss/IndexPQFastScan.cpp +2 -5
- data/vendor/faiss/faiss/IndexPQFastScan.h +2 -11
- data/vendor/faiss/faiss/IndexPreTransform.cpp +2 -2
- data/vendor/faiss/faiss/IndexPreTransform.h +3 -3
- data/vendor/faiss/faiss/IndexRefine.cpp +46 -9
- data/vendor/faiss/faiss/IndexRefine.h +9 -2
- data/vendor/faiss/faiss/IndexReplicas.cpp +2 -2
- data/vendor/faiss/faiss/IndexReplicas.h +2 -2
- data/vendor/faiss/faiss/IndexRowwiseMinMax.cpp +2 -2
- data/vendor/faiss/faiss/IndexRowwiseMinMax.h +2 -2
- data/vendor/faiss/faiss/IndexScalarQuantizer.cpp +5 -4
- data/vendor/faiss/faiss/IndexScalarQuantizer.h +2 -2
- data/vendor/faiss/faiss/IndexShards.cpp +2 -2
- data/vendor/faiss/faiss/IndexShards.h +2 -2
- data/vendor/faiss/faiss/IndexShardsIVF.cpp +2 -2
- data/vendor/faiss/faiss/IndexShardsIVF.h +2 -2
- data/vendor/faiss/faiss/MatrixStats.cpp +2 -2
- data/vendor/faiss/faiss/MatrixStats.h +2 -2
- data/vendor/faiss/faiss/MetaIndexes.cpp +2 -3
- data/vendor/faiss/faiss/MetaIndexes.h +2 -2
- data/vendor/faiss/faiss/MetricType.h +9 -4
- data/vendor/faiss/faiss/VectorTransform.cpp +2 -2
- data/vendor/faiss/faiss/VectorTransform.h +2 -2
- data/vendor/faiss/faiss/clone_index.cpp +2 -2
- data/vendor/faiss/faiss/clone_index.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/SaDecodeKernels.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/detail/CoarseBitType.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/detail/UintReader.h +97 -19
- data/vendor/faiss/faiss/cppcontrib/factory_tools.cpp +192 -0
- data/vendor/faiss/faiss/cppcontrib/factory_tools.h +29 -0
- data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-avx2-inl.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-inl.h +85 -32
- data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-neon-inl.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/sa_decode/MinMax-inl.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/sa_decode/MinMaxFP16-inl.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/sa_decode/PQ-avx2-inl.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/sa_decode/PQ-inl.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/sa_decode/PQ-neon-inl.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuAutoTune.cpp +2 -5
- data/vendor/faiss/faiss/gpu/GpuAutoTune.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuCloner.cpp +45 -13
- data/vendor/faiss/faiss/gpu/GpuCloner.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuClonerOptions.h +12 -6
- data/vendor/faiss/faiss/gpu/GpuDistance.h +11 -7
- data/vendor/faiss/faiss/gpu/GpuFaissAssert.h +3 -3
- data/vendor/faiss/faiss/gpu/GpuIcmEncoder.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuIndex.h +10 -15
- data/vendor/faiss/faiss/gpu/GpuIndexBinaryFlat.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuIndexCagra.h +285 -0
- data/vendor/faiss/faiss/gpu/GpuIndexFlat.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuIndexIVF.h +8 -2
- data/vendor/faiss/faiss/gpu/GpuIndexIVFFlat.h +4 -2
- data/vendor/faiss/faiss/gpu/GpuIndexIVFPQ.h +3 -3
- data/vendor/faiss/faiss/gpu/GpuIndexIVFScalarQuantizer.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuIndicesOptions.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuResources.cpp +7 -2
- data/vendor/faiss/faiss/gpu/GpuResources.h +11 -4
- data/vendor/faiss/faiss/gpu/StandardGpuResources.cpp +66 -11
- data/vendor/faiss/faiss/gpu/StandardGpuResources.h +15 -5
- data/vendor/faiss/faiss/gpu/impl/IndexUtils.h +2 -2
- data/vendor/faiss/faiss/gpu/impl/InterleavedCodes.cpp +28 -23
- data/vendor/faiss/faiss/gpu/impl/InterleavedCodes.h +2 -2
- data/vendor/faiss/faiss/gpu/impl/RemapIndices.cpp +2 -2
- data/vendor/faiss/faiss/gpu/impl/RemapIndices.h +2 -2
- data/vendor/faiss/faiss/gpu/perf/IndexWrapper-inl.h +2 -2
- data/vendor/faiss/faiss/gpu/perf/IndexWrapper.h +2 -2
- data/vendor/faiss/faiss/gpu/perf/PerfClustering.cpp +8 -2
- data/vendor/faiss/faiss/gpu/perf/PerfIVFPQAdd.cpp +2 -3
- data/vendor/faiss/faiss/gpu/perf/WriteIndex.cpp +2 -2
- data/vendor/faiss/faiss/gpu/test/TestCodePacking.cpp +10 -7
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexBinaryFlat.cpp +2 -2
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexFlat.cpp +54 -54
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFFlat.cpp +144 -77
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFPQ.cpp +51 -51
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFScalarQuantizer.cpp +2 -2
- data/vendor/faiss/faiss/gpu/test/TestGpuMemoryException.cpp +3 -3
- data/vendor/faiss/faiss/gpu/test/TestGpuResidualQuantizer.cpp +70 -0
- data/vendor/faiss/faiss/gpu/test/TestUtils.cpp +74 -4
- data/vendor/faiss/faiss/gpu/test/TestUtils.h +2 -2
- data/vendor/faiss/faiss/gpu/test/demo_ivfpq_indexing_gpu.cpp +3 -3
- data/vendor/faiss/faiss/gpu/utils/{RaftUtils.h → CuvsUtils.h} +12 -11
- data/vendor/faiss/faiss/gpu/utils/DeviceUtils.h +8 -2
- data/vendor/faiss/faiss/gpu/utils/StackDeviceMemory.cpp +2 -2
- data/vendor/faiss/faiss/gpu/utils/StackDeviceMemory.h +2 -2
- data/vendor/faiss/faiss/gpu/utils/StaticUtils.h +2 -2
- data/vendor/faiss/faiss/gpu/utils/Timer.cpp +6 -3
- data/vendor/faiss/faiss/gpu/utils/Timer.h +3 -3
- data/vendor/faiss/faiss/impl/AdditiveQuantizer.cpp +79 -11
- data/vendor/faiss/faiss/impl/AdditiveQuantizer.h +17 -5
- data/vendor/faiss/faiss/impl/AuxIndexStructures.cpp +27 -2
- data/vendor/faiss/faiss/impl/AuxIndexStructures.h +11 -3
- data/vendor/faiss/faiss/impl/CodePacker.cpp +2 -2
- data/vendor/faiss/faiss/impl/CodePacker.h +2 -2
- data/vendor/faiss/faiss/impl/DistanceComputer.h +48 -2
- data/vendor/faiss/faiss/impl/FaissAssert.h +6 -4
- data/vendor/faiss/faiss/impl/FaissException.cpp +2 -2
- data/vendor/faiss/faiss/impl/FaissException.h +2 -3
- data/vendor/faiss/faiss/impl/HNSW.cpp +378 -205
- data/vendor/faiss/faiss/impl/HNSW.h +55 -24
- data/vendor/faiss/faiss/impl/IDSelector.cpp +2 -2
- data/vendor/faiss/faiss/impl/IDSelector.h +2 -2
- data/vendor/faiss/faiss/impl/LocalSearchQuantizer.cpp +10 -10
- data/vendor/faiss/faiss/impl/LocalSearchQuantizer.h +2 -2
- data/vendor/faiss/faiss/impl/LookupTableScaler.h +36 -2
- data/vendor/faiss/faiss/impl/NNDescent.cpp +15 -10
- data/vendor/faiss/faiss/impl/NNDescent.h +2 -2
- data/vendor/faiss/faiss/impl/NSG.cpp +26 -49
- data/vendor/faiss/faiss/impl/NSG.h +20 -8
- data/vendor/faiss/faiss/impl/PolysemousTraining.cpp +2 -2
- data/vendor/faiss/faiss/impl/PolysemousTraining.h +2 -2
- data/vendor/faiss/faiss/impl/ProductAdditiveQuantizer.cpp +2 -4
- data/vendor/faiss/faiss/impl/ProductAdditiveQuantizer.h +2 -2
- data/vendor/faiss/faiss/impl/ProductQuantizer-inl.h +2 -2
- data/vendor/faiss/faiss/impl/ProductQuantizer.cpp +3 -2
- data/vendor/faiss/faiss/impl/ProductQuantizer.h +7 -3
- data/vendor/faiss/faiss/impl/Quantizer.h +2 -2
- data/vendor/faiss/faiss/impl/ResidualQuantizer.cpp +2 -36
- data/vendor/faiss/faiss/impl/ResidualQuantizer.h +3 -13
- data/vendor/faiss/faiss/impl/ResultHandler.h +153 -34
- data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +721 -104
- data/vendor/faiss/faiss/impl/ScalarQuantizer.h +5 -2
- data/vendor/faiss/faiss/impl/ThreadedIndex-inl.h +2 -2
- data/vendor/faiss/faiss/impl/ThreadedIndex.h +2 -2
- data/vendor/faiss/faiss/impl/code_distance/code_distance-avx2.h +7 -2
- data/vendor/faiss/faiss/impl/code_distance/code_distance-avx512.h +248 -0
- data/vendor/faiss/faiss/impl/code_distance/code_distance-generic.h +2 -2
- data/vendor/faiss/faiss/impl/code_distance/code_distance-sve.h +440 -0
- data/vendor/faiss/faiss/impl/code_distance/code_distance.h +55 -2
- data/vendor/faiss/faiss/impl/index_read.cpp +31 -20
- data/vendor/faiss/faiss/impl/index_read_utils.h +37 -0
- data/vendor/faiss/faiss/impl/index_write.cpp +30 -16
- data/vendor/faiss/faiss/impl/io.cpp +15 -7
- data/vendor/faiss/faiss/impl/io.h +6 -6
- data/vendor/faiss/faiss/impl/io_macros.h +8 -9
- data/vendor/faiss/faiss/impl/kmeans1d.cpp +2 -3
- data/vendor/faiss/faiss/impl/kmeans1d.h +2 -2
- data/vendor/faiss/faiss/impl/lattice_Zn.cpp +2 -3
- data/vendor/faiss/faiss/impl/lattice_Zn.h +2 -2
- data/vendor/faiss/faiss/impl/platform_macros.h +34 -2
- data/vendor/faiss/faiss/impl/pq4_fast_scan.cpp +13 -2
- data/vendor/faiss/faiss/impl/pq4_fast_scan.h +20 -2
- data/vendor/faiss/faiss/impl/pq4_fast_scan_search_1.cpp +3 -3
- data/vendor/faiss/faiss/impl/pq4_fast_scan_search_qbs.cpp +450 -3
- data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.cpp +8 -8
- data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.h +3 -3
- data/vendor/faiss/faiss/impl/simd_result_handlers.h +151 -67
- data/vendor/faiss/faiss/index_factory.cpp +51 -34
- data/vendor/faiss/faiss/index_factory.h +2 -2
- data/vendor/faiss/faiss/index_io.h +14 -7
- data/vendor/faiss/faiss/invlists/BlockInvertedLists.cpp +30 -10
- data/vendor/faiss/faiss/invlists/BlockInvertedLists.h +5 -2
- data/vendor/faiss/faiss/invlists/DirectMap.cpp +11 -3
- data/vendor/faiss/faiss/invlists/DirectMap.h +2 -2
- data/vendor/faiss/faiss/invlists/InvertedLists.cpp +57 -19
- data/vendor/faiss/faiss/invlists/InvertedLists.h +20 -11
- data/vendor/faiss/faiss/invlists/InvertedListsIOHook.cpp +2 -2
- data/vendor/faiss/faiss/invlists/InvertedListsIOHook.h +2 -2
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.cpp +23 -9
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.h +4 -3
- data/vendor/faiss/faiss/python/python_callbacks.cpp +5 -5
- data/vendor/faiss/faiss/python/python_callbacks.h +2 -2
- data/vendor/faiss/faiss/utils/AlignedTable.h +5 -3
- data/vendor/faiss/faiss/utils/Heap.cpp +2 -2
- data/vendor/faiss/faiss/utils/Heap.h +107 -2
- data/vendor/faiss/faiss/utils/NeuralNet.cpp +346 -0
- data/vendor/faiss/faiss/utils/NeuralNet.h +147 -0
- data/vendor/faiss/faiss/utils/WorkerThread.cpp +2 -2
- data/vendor/faiss/faiss/utils/WorkerThread.h +2 -2
- data/vendor/faiss/faiss/utils/approx_topk/approx_topk.h +2 -2
- data/vendor/faiss/faiss/utils/approx_topk/avx2-inl.h +2 -2
- data/vendor/faiss/faiss/utils/approx_topk/generic.h +2 -2
- data/vendor/faiss/faiss/utils/approx_topk/mode.h +2 -2
- data/vendor/faiss/faiss/utils/approx_topk_hamming/approx_topk_hamming.h +2 -2
- data/vendor/faiss/faiss/utils/bf16.h +36 -0
- data/vendor/faiss/faiss/utils/distances.cpp +249 -90
- data/vendor/faiss/faiss/utils/distances.h +8 -8
- data/vendor/faiss/faiss/utils/distances_fused/avx512.cpp +2 -2
- data/vendor/faiss/faiss/utils/distances_fused/avx512.h +2 -2
- data/vendor/faiss/faiss/utils/distances_fused/distances_fused.cpp +2 -2
- data/vendor/faiss/faiss/utils/distances_fused/distances_fused.h +2 -2
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_based.cpp +2 -2
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_based.h +2 -2
- data/vendor/faiss/faiss/utils/distances_simd.cpp +1543 -56
- data/vendor/faiss/faiss/utils/extra_distances-inl.h +72 -2
- data/vendor/faiss/faiss/utils/extra_distances.cpp +87 -140
- data/vendor/faiss/faiss/utils/extra_distances.h +5 -4
- data/vendor/faiss/faiss/utils/fp16-arm.h +2 -2
- data/vendor/faiss/faiss/utils/fp16-fp16c.h +2 -2
- data/vendor/faiss/faiss/utils/fp16-inl.h +2 -2
- data/vendor/faiss/faiss/utils/fp16.h +2 -2
- data/vendor/faiss/faiss/utils/hamming-inl.h +2 -2
- data/vendor/faiss/faiss/utils/hamming.cpp +3 -4
- data/vendor/faiss/faiss/utils/hamming.h +2 -2
- data/vendor/faiss/faiss/utils/hamming_distance/avx2-inl.h +2 -2
- data/vendor/faiss/faiss/utils/hamming_distance/avx512-inl.h +490 -0
- data/vendor/faiss/faiss/utils/hamming_distance/common.h +2 -2
- data/vendor/faiss/faiss/utils/hamming_distance/generic-inl.h +6 -3
- data/vendor/faiss/faiss/utils/hamming_distance/hamdis-inl.h +7 -3
- data/vendor/faiss/faiss/utils/hamming_distance/neon-inl.h +5 -5
- data/vendor/faiss/faiss/utils/ordered_key_value.h +2 -2
- data/vendor/faiss/faiss/utils/partitioning.cpp +2 -2
- data/vendor/faiss/faiss/utils/partitioning.h +2 -2
- data/vendor/faiss/faiss/utils/prefetch.h +2 -2
- data/vendor/faiss/faiss/utils/quantize_lut.cpp +2 -2
- data/vendor/faiss/faiss/utils/quantize_lut.h +2 -2
- data/vendor/faiss/faiss/utils/random.cpp +45 -2
- data/vendor/faiss/faiss/utils/random.h +27 -2
- data/vendor/faiss/faiss/utils/simdlib.h +12 -3
- data/vendor/faiss/faiss/utils/simdlib_avx2.h +2 -2
- data/vendor/faiss/faiss/utils/simdlib_avx512.h +296 -0
- data/vendor/faiss/faiss/utils/simdlib_emulated.h +2 -2
- data/vendor/faiss/faiss/utils/simdlib_neon.h +7 -4
- data/vendor/faiss/faiss/utils/simdlib_ppc64.h +1084 -0
- data/vendor/faiss/faiss/utils/sorting.cpp +2 -2
- data/vendor/faiss/faiss/utils/sorting.h +2 -2
- data/vendor/faiss/faiss/utils/transpose/transpose-avx2-inl.h +2 -2
- data/vendor/faiss/faiss/utils/transpose/transpose-avx512-inl.h +176 -0
- data/vendor/faiss/faiss/utils/utils.cpp +17 -10
- data/vendor/faiss/faiss/utils/utils.h +7 -3
- metadata +22 -11
- data/vendor/faiss/faiss/impl/code_distance/code_distance_avx512.h +0 -102
@@ -1,3 +1,4 @@
|
|
1
|
+
// @lint-ignore-every LICENSELINT
|
1
2
|
/**
|
2
3
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
3
4
|
*
|
@@ -5,7 +6,7 @@
|
|
5
6
|
* LICENSE file in the root directory of this source tree.
|
6
7
|
*/
|
7
8
|
/*
|
8
|
-
* Copyright (c) 2023, NVIDIA CORPORATION.
|
9
|
+
* Copyright (c) 2023-2024, NVIDIA CORPORATION.
|
9
10
|
*
|
10
11
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
11
12
|
* you may not use this file except in compliance with the License.
|
@@ -57,7 +58,7 @@ struct Options {
|
|
57
58
|
|
58
59
|
device = faiss::gpu::randVal(0, faiss::gpu::getNumDevices() - 1);
|
59
60
|
|
60
|
-
|
61
|
+
useCuvs = false;
|
61
62
|
}
|
62
63
|
|
63
64
|
std::string toString() const {
|
@@ -65,7 +66,7 @@ struct Options {
|
|
65
66
|
str << "IVFFlat device " << device << " numVecs " << numAdd << " dim "
|
66
67
|
<< dim << " numCentroids " << numCentroids << " nprobe " << nprobe
|
67
68
|
<< " numQuery " << numQuery << " k " << k << " indicesOpt "
|
68
|
-
<< indicesOpt << "
|
69
|
+
<< indicesOpt << " useCuvs " << useCuvs;
|
69
70
|
|
70
71
|
return str.str();
|
71
72
|
}
|
@@ -79,7 +80,7 @@ struct Options {
|
|
79
80
|
int k;
|
80
81
|
int device;
|
81
82
|
faiss::gpu::IndicesOptions indicesOpt;
|
82
|
-
bool
|
83
|
+
bool useCuvs;
|
83
84
|
};
|
84
85
|
|
85
86
|
void queryTest(
|
@@ -110,7 +111,7 @@ void queryTest(
|
|
110
111
|
config.device = opt.device;
|
111
112
|
config.indicesOptions = opt.indicesOpt;
|
112
113
|
config.flatConfig.useFloat16 = useFloat16CoarseQuantizer;
|
113
|
-
config.
|
114
|
+
config.use_cuvs = opt.useCuvs;
|
114
115
|
|
115
116
|
faiss::gpu::GpuIndexIVFFlat gpuIndex(
|
116
117
|
&res, cpuIndex.d, cpuIndex.nlist, cpuIndex.metric_type, config);
|
@@ -137,9 +138,10 @@ void queryTest(
|
|
137
138
|
void addTest(
|
138
139
|
faiss::MetricType metricType,
|
139
140
|
bool useFloat16CoarseQuantizer,
|
140
|
-
bool
|
141
|
+
bool useCuvs) {
|
141
142
|
for (int tries = 0; tries < 2; ++tries) {
|
142
143
|
Options opt;
|
144
|
+
opt.useCuvs = useCuvs;
|
143
145
|
|
144
146
|
std::vector<float> trainVecs =
|
145
147
|
faiss::gpu::randVecs(opt.numTrain, opt.dim);
|
@@ -162,9 +164,9 @@ void addTest(
|
|
162
164
|
faiss::gpu::GpuIndexIVFFlatConfig config;
|
163
165
|
config.device = opt.device;
|
164
166
|
config.indicesOptions =
|
165
|
-
|
167
|
+
opt.useCuvs ? faiss::gpu::INDICES_64_BIT : opt.indicesOpt;
|
166
168
|
config.flatConfig.useFloat16 = useFloat16CoarseQuantizer;
|
167
|
-
config.
|
169
|
+
config.use_cuvs = opt.useCuvs;
|
168
170
|
|
169
171
|
faiss::gpu::GpuIndexIVFFlat gpuIndex(
|
170
172
|
&res, cpuIndex.d, cpuIndex.nlist, cpuIndex.metric_type, config);
|
@@ -188,7 +190,7 @@ void addTest(
|
|
188
190
|
}
|
189
191
|
}
|
190
192
|
|
191
|
-
void copyToTest(bool useFloat16CoarseQuantizer, bool
|
193
|
+
void copyToTest(bool useFloat16CoarseQuantizer, bool useCuvs) {
|
192
194
|
Options opt;
|
193
195
|
std::vector<float> trainVecs = faiss::gpu::randVecs(opt.numTrain, opt.dim);
|
194
196
|
std::vector<float> addVecs = faiss::gpu::randVecs(opt.numAdd, opt.dim);
|
@@ -199,9 +201,9 @@ void copyToTest(bool useFloat16CoarseQuantizer, bool useRaft) {
|
|
199
201
|
faiss::gpu::GpuIndexIVFFlatConfig config;
|
200
202
|
config.device = opt.device;
|
201
203
|
config.indicesOptions =
|
202
|
-
|
204
|
+
useCuvs ? faiss::gpu::INDICES_64_BIT : opt.indicesOpt;
|
203
205
|
config.flatConfig.useFloat16 = useFloat16CoarseQuantizer;
|
204
|
-
config.
|
206
|
+
config.use_cuvs = useCuvs;
|
205
207
|
|
206
208
|
faiss::gpu::GpuIndexIVFFlat gpuIndex(
|
207
209
|
&res, opt.dim, opt.numCentroids, faiss::METRIC_L2, config);
|
@@ -241,7 +243,7 @@ void copyToTest(bool useFloat16CoarseQuantizer, bool useRaft) {
|
|
241
243
|
compFloat16 ? 0.30f : 0.015f);
|
242
244
|
}
|
243
245
|
|
244
|
-
void copyFromTest(bool useFloat16CoarseQuantizer, bool
|
246
|
+
void copyFromTest(bool useFloat16CoarseQuantizer, bool useCuvs) {
|
245
247
|
Options opt;
|
246
248
|
std::vector<float> trainVecs = faiss::gpu::randVecs(opt.numTrain, opt.dim);
|
247
249
|
std::vector<float> addVecs = faiss::gpu::randVecs(opt.numAdd, opt.dim);
|
@@ -260,9 +262,9 @@ void copyFromTest(bool useFloat16CoarseQuantizer, bool useRaft) {
|
|
260
262
|
faiss::gpu::GpuIndexIVFFlatConfig config;
|
261
263
|
config.device = opt.device;
|
262
264
|
config.indicesOptions =
|
263
|
-
|
265
|
+
useCuvs ? faiss::gpu::INDICES_64_BIT : opt.indicesOpt;
|
264
266
|
config.flatConfig.useFloat16 = useFloat16CoarseQuantizer;
|
265
|
-
config.
|
267
|
+
config.use_cuvs = useCuvs;
|
266
268
|
|
267
269
|
faiss::gpu::GpuIndexIVFFlat gpuIndex(&res, 1, 1, faiss::METRIC_L2, config);
|
268
270
|
gpuIndex.nprobe = 1;
|
@@ -296,7 +298,7 @@ void copyFromTest(bool useFloat16CoarseQuantizer, bool useRaft) {
|
|
296
298
|
TEST(TestGpuIndexIVFFlat, Float32_32_Add_L2) {
|
297
299
|
addTest(faiss::METRIC_L2, false, false);
|
298
300
|
|
299
|
-
#if defined
|
301
|
+
#if defined USE_NVIDIA_CUVS
|
300
302
|
addTest(faiss::METRIC_L2, false, true);
|
301
303
|
#endif
|
302
304
|
}
|
@@ -304,7 +306,7 @@ TEST(TestGpuIndexIVFFlat, Float32_32_Add_L2) {
|
|
304
306
|
TEST(TestGpuIndexIVFFlat, Float32_32_Add_IP) {
|
305
307
|
addTest(faiss::METRIC_INNER_PRODUCT, false, false);
|
306
308
|
|
307
|
-
#if defined
|
309
|
+
#if defined USE_NVIDIA_CUVS
|
308
310
|
addTest(faiss::METRIC_INNER_PRODUCT, false, true);
|
309
311
|
#endif
|
310
312
|
}
|
@@ -312,7 +314,7 @@ TEST(TestGpuIndexIVFFlat, Float32_32_Add_IP) {
|
|
312
314
|
TEST(TestGpuIndexIVFFlat, Float16_32_Add_L2) {
|
313
315
|
addTest(faiss::METRIC_L2, true, false);
|
314
316
|
|
315
|
-
#if defined
|
317
|
+
#if defined USE_NVIDIA_CUVS
|
316
318
|
addTest(faiss::METRIC_L2, true, true);
|
317
319
|
#endif
|
318
320
|
}
|
@@ -320,7 +322,7 @@ TEST(TestGpuIndexIVFFlat, Float16_32_Add_L2) {
|
|
320
322
|
TEST(TestGpuIndexIVFFlat, Float16_32_Add_IP) {
|
321
323
|
addTest(faiss::METRIC_INNER_PRODUCT, true, false);
|
322
324
|
|
323
|
-
#if defined
|
325
|
+
#if defined USE_NVIDIA_CUVS
|
324
326
|
addTest(faiss::METRIC_INNER_PRODUCT, true, true);
|
325
327
|
#endif
|
326
328
|
}
|
@@ -333,8 +335,8 @@ TEST(TestGpuIndexIVFFlat, Float32_Query_L2) {
|
|
333
335
|
Options opt;
|
334
336
|
queryTest(opt, faiss::METRIC_L2, false);
|
335
337
|
|
336
|
-
#if defined
|
337
|
-
opt.
|
338
|
+
#if defined USE_NVIDIA_CUVS
|
339
|
+
opt.useCuvs = true;
|
338
340
|
opt.indicesOpt = faiss::gpu::INDICES_64_BIT;
|
339
341
|
queryTest(opt, faiss::METRIC_L2, false);
|
340
342
|
#endif
|
@@ -344,8 +346,8 @@ TEST(TestGpuIndexIVFFlat, Float32_Query_IP) {
|
|
344
346
|
Options opt;
|
345
347
|
queryTest(opt, faiss::METRIC_INNER_PRODUCT, false);
|
346
348
|
|
347
|
-
#if defined
|
348
|
-
opt.
|
349
|
+
#if defined USE_NVIDIA_CUVS
|
350
|
+
opt.useCuvs = true;
|
349
351
|
opt.indicesOpt = faiss::gpu::INDICES_64_BIT;
|
350
352
|
queryTest(opt, faiss::METRIC_INNER_PRODUCT, false);
|
351
353
|
#endif
|
@@ -357,8 +359,8 @@ TEST(TestGpuIndexIVFFlat, LargeBatch) {
|
|
357
359
|
opt.numQuery = 100000;
|
358
360
|
queryTest(opt, faiss::METRIC_L2, false);
|
359
361
|
|
360
|
-
#if defined
|
361
|
-
opt.
|
362
|
+
#if defined USE_NVIDIA_CUVS
|
363
|
+
opt.useCuvs = true;
|
362
364
|
opt.indicesOpt = faiss::gpu::INDICES_64_BIT;
|
363
365
|
queryTest(opt, faiss::METRIC_L2, false);
|
364
366
|
#endif
|
@@ -370,8 +372,8 @@ TEST(TestGpuIndexIVFFlat, Float16_32_Query_L2) {
|
|
370
372
|
Options opt;
|
371
373
|
queryTest(opt, faiss::METRIC_L2, true);
|
372
374
|
|
373
|
-
#if defined
|
374
|
-
opt.
|
375
|
+
#if defined USE_NVIDIA_CUVS
|
376
|
+
opt.useCuvs = true;
|
375
377
|
opt.indicesOpt = faiss::gpu::INDICES_64_BIT;
|
376
378
|
queryTest(opt, faiss::METRIC_L2, true);
|
377
379
|
#endif
|
@@ -381,8 +383,8 @@ TEST(TestGpuIndexIVFFlat, Float16_32_Query_IP) {
|
|
381
383
|
Options opt;
|
382
384
|
queryTest(opt, faiss::METRIC_INNER_PRODUCT, true);
|
383
385
|
|
384
|
-
#if defined
|
385
|
-
opt.
|
386
|
+
#if defined USE_NVIDIA_CUVS
|
387
|
+
opt.useCuvs = true;
|
386
388
|
opt.indicesOpt = faiss::gpu::INDICES_64_BIT;
|
387
389
|
queryTest(opt, faiss::METRIC_INNER_PRODUCT, true);
|
388
390
|
#endif
|
@@ -398,8 +400,8 @@ TEST(TestGpuIndexIVFFlat, Float32_Query_L2_64) {
|
|
398
400
|
opt.dim = 64;
|
399
401
|
queryTest(opt, faiss::METRIC_L2, false);
|
400
402
|
|
401
|
-
#if defined
|
402
|
-
opt.
|
403
|
+
#if defined USE_NVIDIA_CUVS
|
404
|
+
opt.useCuvs = true;
|
403
405
|
opt.indicesOpt = faiss::gpu::INDICES_64_BIT;
|
404
406
|
queryTest(opt, faiss::METRIC_L2, false);
|
405
407
|
#endif
|
@@ -410,8 +412,8 @@ TEST(TestGpuIndexIVFFlat, Float32_Query_IP_64) {
|
|
410
412
|
opt.dim = 64;
|
411
413
|
queryTest(opt, faiss::METRIC_INNER_PRODUCT, false);
|
412
414
|
|
413
|
-
#if defined
|
414
|
-
opt.
|
415
|
+
#if defined USE_NVIDIA_CUVS
|
416
|
+
opt.useCuvs = true;
|
415
417
|
opt.indicesOpt = faiss::gpu::INDICES_64_BIT;
|
416
418
|
queryTest(opt, faiss::METRIC_INNER_PRODUCT, false);
|
417
419
|
#endif
|
@@ -422,8 +424,8 @@ TEST(TestGpuIndexIVFFlat, Float32_Query_L2_128) {
|
|
422
424
|
opt.dim = 128;
|
423
425
|
queryTest(opt, faiss::METRIC_L2, false);
|
424
426
|
|
425
|
-
#if defined
|
426
|
-
opt.
|
427
|
+
#if defined USE_NVIDIA_CUVS
|
428
|
+
opt.useCuvs = true;
|
427
429
|
opt.indicesOpt = faiss::gpu::INDICES_64_BIT;
|
428
430
|
queryTest(opt, faiss::METRIC_L2, false);
|
429
431
|
#endif
|
@@ -434,8 +436,8 @@ TEST(TestGpuIndexIVFFlat, Float32_Query_IP_128) {
|
|
434
436
|
opt.dim = 128;
|
435
437
|
queryTest(opt, faiss::METRIC_INNER_PRODUCT, false);
|
436
438
|
|
437
|
-
#if defined
|
438
|
-
opt.
|
439
|
+
#if defined USE_NVIDIA_CUVS
|
440
|
+
opt.useCuvs = true;
|
439
441
|
opt.indicesOpt = faiss::gpu::INDICES_64_BIT;
|
440
442
|
queryTest(opt, faiss::METRIC_INNER_PRODUCT, false);
|
441
443
|
#endif
|
@@ -448,7 +450,7 @@ TEST(TestGpuIndexIVFFlat, Float32_Query_IP_128) {
|
|
448
450
|
TEST(TestGpuIndexIVFFlat, Float32_32_CopyTo) {
|
449
451
|
copyToTest(false, false);
|
450
452
|
|
451
|
-
#if defined
|
453
|
+
#if defined USE_NVIDIA_CUVS
|
452
454
|
copyToTest(false, true);
|
453
455
|
#endif
|
454
456
|
}
|
@@ -456,7 +458,7 @@ TEST(TestGpuIndexIVFFlat, Float32_32_CopyTo) {
|
|
456
458
|
TEST(TestGpuIndexIVFFlat, Float32_32_CopyFrom) {
|
457
459
|
copyFromTest(false, false);
|
458
460
|
|
459
|
-
#if defined
|
461
|
+
#if defined USE_NVIDIA_CUVS
|
460
462
|
copyFromTest(false, true);
|
461
463
|
#endif
|
462
464
|
}
|
@@ -499,7 +501,7 @@ TEST(TestGpuIndexIVFFlat, Float32_negative) {
|
|
499
501
|
faiss::gpu::GpuIndexIVFFlatConfig config;
|
500
502
|
config.device = opt.device;
|
501
503
|
config.indicesOptions = opt.indicesOpt;
|
502
|
-
config.
|
504
|
+
config.use_cuvs = false;
|
503
505
|
|
504
506
|
faiss::gpu::GpuIndexIVFFlat gpuIndex(
|
505
507
|
&res, cpuIndex.d, cpuIndex.nlist, cpuIndex.metric_type, config);
|
@@ -522,19 +524,19 @@ TEST(TestGpuIndexIVFFlat, Float32_negative) {
|
|
522
524
|
compFloat16 ? 0.99f : 0.1f,
|
523
525
|
compFloat16 ? 0.65f : 0.015f);
|
524
526
|
|
525
|
-
#if defined
|
526
|
-
config.
|
527
|
+
#if defined USE_NVIDIA_CUVS
|
528
|
+
config.use_cuvs = true;
|
527
529
|
config.indicesOptions = faiss::gpu::INDICES_64_BIT;
|
528
530
|
|
529
|
-
faiss::gpu::GpuIndexIVFFlat
|
531
|
+
faiss::gpu::GpuIndexIVFFlat cuvsGpuIndex(
|
530
532
|
&res, cpuIndex.d, cpuIndex.nlist, cpuIndex.metric_type, config);
|
531
|
-
|
532
|
-
|
533
|
+
cuvsGpuIndex.copyFrom(&cpuIndex);
|
534
|
+
cuvsGpuIndex.nprobe = opt.nprobe;
|
533
535
|
|
534
536
|
faiss::gpu::compareIndices(
|
535
537
|
queryVecs,
|
536
538
|
cpuIndex,
|
537
|
-
|
539
|
+
cuvsGpuIndex,
|
538
540
|
opt.numQuery,
|
539
541
|
opt.dim,
|
540
542
|
opt.k,
|
@@ -572,7 +574,7 @@ TEST(TestGpuIndexIVFFlat, QueryNaN) {
|
|
572
574
|
config.device = opt.device;
|
573
575
|
config.indicesOptions = opt.indicesOpt;
|
574
576
|
config.flatConfig.useFloat16 = faiss::gpu::randBool();
|
575
|
-
config.
|
577
|
+
config.use_cuvs = false;
|
576
578
|
|
577
579
|
faiss::gpu::GpuIndexIVFFlat gpuIndex(
|
578
580
|
&res, opt.dim, opt.numCentroids, faiss::METRIC_L2, config);
|
@@ -593,19 +595,19 @@ TEST(TestGpuIndexIVFFlat, QueryNaN) {
|
|
593
595
|
}
|
594
596
|
}
|
595
597
|
|
596
|
-
#if defined
|
597
|
-
config.
|
598
|
+
#if defined USE_NVIDIA_CUVS
|
599
|
+
config.use_cuvs = true;
|
598
600
|
config.indicesOptions = faiss::gpu::INDICES_64_BIT;
|
599
601
|
std::fill(distances.begin(), distances.end(), 0);
|
600
602
|
std::fill(indices.begin(), indices.end(), 0);
|
601
|
-
faiss::gpu::GpuIndexIVFFlat
|
603
|
+
faiss::gpu::GpuIndexIVFFlat cuvsGpuIndex(
|
602
604
|
&res, opt.dim, opt.numCentroids, faiss::METRIC_L2, config);
|
603
|
-
|
605
|
+
cuvsGpuIndex.nprobe = opt.nprobe;
|
604
606
|
|
605
|
-
|
606
|
-
|
607
|
+
cuvsGpuIndex.train(opt.numTrain, trainVecs.data());
|
608
|
+
cuvsGpuIndex.add(opt.numAdd, addVecs.data());
|
607
609
|
|
608
|
-
|
610
|
+
cuvsGpuIndex.search(
|
609
611
|
numQuery, nans.data(), opt.k, distances.data(), indices.data());
|
610
612
|
|
611
613
|
for (int q = 0; q < numQuery; ++q) {
|
@@ -641,7 +643,7 @@ TEST(TestGpuIndexIVFFlat, AddNaN) {
|
|
641
643
|
config.device = opt.device;
|
642
644
|
config.indicesOptions = opt.indicesOpt;
|
643
645
|
config.flatConfig.useFloat16 = faiss::gpu::randBool();
|
644
|
-
config.
|
646
|
+
config.use_cuvs = false;
|
645
647
|
faiss::gpu::GpuIndexIVFFlat gpuIndex(
|
646
648
|
&res, opt.dim, opt.numCentroids, faiss::METRIC_L2, config);
|
647
649
|
gpuIndex.nprobe = opt.nprobe;
|
@@ -663,20 +665,20 @@ TEST(TestGpuIndexIVFFlat, AddNaN) {
|
|
663
665
|
distance.data(),
|
664
666
|
indices.data());
|
665
667
|
|
666
|
-
#if defined
|
667
|
-
config.
|
668
|
+
#if defined USE_NVIDIA_CUVS
|
669
|
+
config.use_cuvs = true;
|
668
670
|
config.indicesOptions = faiss::gpu::INDICES_64_BIT;
|
669
|
-
faiss::gpu::GpuIndexIVFFlat
|
671
|
+
faiss::gpu::GpuIndexIVFFlat cuvsGpuIndex(
|
670
672
|
&res, opt.dim, opt.numCentroids, faiss::METRIC_L2, config);
|
671
|
-
|
672
|
-
|
673
|
+
cuvsGpuIndex.nprobe = opt.nprobe;
|
674
|
+
cuvsGpuIndex.train(opt.numTrain, trainVecs.data());
|
673
675
|
|
674
676
|
// should not crash
|
675
|
-
EXPECT_EQ(
|
676
|
-
|
677
|
+
EXPECT_EQ(cuvsGpuIndex.ntotal, 0);
|
678
|
+
cuvsGpuIndex.add(numNans, nans.data());
|
677
679
|
|
678
680
|
// should not crash
|
679
|
-
|
681
|
+
cuvsGpuIndex.search(
|
680
682
|
opt.numQuery,
|
681
683
|
queryVecs.data(),
|
682
684
|
opt.k,
|
@@ -723,7 +725,7 @@ TEST(TestGpuIndexIVFFlat, UnifiedMemory) {
|
|
723
725
|
faiss::gpu::GpuIndexIVFFlatConfig config;
|
724
726
|
config.device = device;
|
725
727
|
config.memorySpace = faiss::gpu::MemorySpace::Unified;
|
726
|
-
config.
|
728
|
+
config.use_cuvs = false;
|
727
729
|
|
728
730
|
faiss::gpu::GpuIndexIVFFlat gpuIndex(
|
729
731
|
&res, dim, numCentroids, faiss::METRIC_L2, config);
|
@@ -741,17 +743,17 @@ TEST(TestGpuIndexIVFFlat, UnifiedMemory) {
|
|
741
743
|
0.1f,
|
742
744
|
0.015f);
|
743
745
|
|
744
|
-
#if defined
|
745
|
-
config.
|
746
|
+
#if defined USE_NVIDIA_CUVS
|
747
|
+
config.use_cuvs = true;
|
746
748
|
config.indicesOptions = faiss::gpu::INDICES_64_BIT;
|
747
|
-
faiss::gpu::GpuIndexIVFFlat
|
749
|
+
faiss::gpu::GpuIndexIVFFlat cuvsGpuIndex(
|
748
750
|
&res, dim, numCentroids, faiss::METRIC_L2, config);
|
749
|
-
|
750
|
-
|
751
|
+
cuvsGpuIndex.copyFrom(&cpuIndex);
|
752
|
+
cuvsGpuIndex.nprobe = nprobe;
|
751
753
|
|
752
754
|
faiss::gpu::compareIndices(
|
753
755
|
cpuIndex,
|
754
|
-
|
756
|
+
cuvsGpuIndex,
|
755
757
|
numQuery,
|
756
758
|
dim,
|
757
759
|
k,
|
@@ -801,7 +803,7 @@ TEST(TestGpuIndexIVFFlat, LongIVFList) {
|
|
801
803
|
|
802
804
|
faiss::gpu::GpuIndexIVFFlatConfig config;
|
803
805
|
config.device = device;
|
804
|
-
config.
|
806
|
+
config.use_cuvs = false;
|
805
807
|
|
806
808
|
faiss::gpu::GpuIndexIVFFlat gpuIndex(
|
807
809
|
&res, dim, numCentroids, faiss::METRIC_L2, config);
|
@@ -820,18 +822,18 @@ TEST(TestGpuIndexIVFFlat, LongIVFList) {
|
|
820
822
|
0.1f,
|
821
823
|
0.015f);
|
822
824
|
|
823
|
-
#if defined
|
824
|
-
config.
|
825
|
+
#if defined USE_NVIDIA_CUVS
|
826
|
+
config.use_cuvs = true;
|
825
827
|
config.indicesOptions = faiss::gpu::INDICES_64_BIT;
|
826
|
-
faiss::gpu::GpuIndexIVFFlat
|
828
|
+
faiss::gpu::GpuIndexIVFFlat cuvsGpuIndex(
|
827
829
|
&res, dim, numCentroids, faiss::METRIC_L2, config);
|
828
|
-
|
829
|
-
|
830
|
-
|
830
|
+
cuvsGpuIndex.train(numTrain, trainVecs.data());
|
831
|
+
cuvsGpuIndex.add(numAdd, addVecs.data());
|
832
|
+
cuvsGpuIndex.nprobe = 1;
|
831
833
|
|
832
834
|
faiss::gpu::compareIndices(
|
833
835
|
cpuIndex,
|
834
|
-
|
836
|
+
cuvsGpuIndex,
|
835
837
|
numQuery,
|
836
838
|
dim,
|
837
839
|
k,
|
@@ -842,6 +844,71 @@ TEST(TestGpuIndexIVFFlat, LongIVFList) {
|
|
842
844
|
#endif
|
843
845
|
}
|
844
846
|
|
847
|
+
TEST(TestGpuIndexIVFFlat, Reconstruct_n) {
|
848
|
+
Options opt;
|
849
|
+
|
850
|
+
std::vector<float> trainVecs = faiss::gpu::randVecs(opt.numTrain, opt.dim);
|
851
|
+
std::vector<float> addVecs = faiss::gpu::randVecs(opt.numAdd, opt.dim);
|
852
|
+
|
853
|
+
faiss::IndexFlatL2 cpuQuantizer(opt.dim);
|
854
|
+
faiss::IndexIVFFlat cpuIndex(
|
855
|
+
&cpuQuantizer, opt.dim, opt.numCentroids, faiss::METRIC_L2);
|
856
|
+
cpuIndex.nprobe = opt.nprobe;
|
857
|
+
cpuIndex.train(opt.numTrain, trainVecs.data());
|
858
|
+
cpuIndex.add(opt.numAdd, addVecs.data());
|
859
|
+
|
860
|
+
faiss::gpu::StandardGpuResources res;
|
861
|
+
res.noTempMemory();
|
862
|
+
|
863
|
+
faiss::gpu::GpuIndexIVFFlatConfig config;
|
864
|
+
config.device = opt.device;
|
865
|
+
config.indicesOptions = faiss::gpu::INDICES_64_BIT;
|
866
|
+
config.use_cuvs = false;
|
867
|
+
|
868
|
+
faiss::gpu::GpuIndexIVFFlat gpuIndex(
|
869
|
+
&res, opt.dim, opt.numCentroids, faiss::METRIC_L2, config);
|
870
|
+
gpuIndex.nprobe = opt.nprobe;
|
871
|
+
|
872
|
+
gpuIndex.train(opt.numTrain, trainVecs.data());
|
873
|
+
gpuIndex.add(opt.numAdd, addVecs.data());
|
874
|
+
|
875
|
+
std::vector<float> gpuVals(opt.numAdd * opt.dim);
|
876
|
+
|
877
|
+
gpuIndex.reconstruct_n(0, gpuIndex.ntotal, gpuVals.data());
|
878
|
+
|
879
|
+
std::vector<float> cpuVals(opt.numAdd * opt.dim);
|
880
|
+
|
881
|
+
cpuIndex.reconstruct_n(0, cpuIndex.ntotal, cpuVals.data());
|
882
|
+
|
883
|
+
EXPECT_EQ(gpuVals, cpuVals);
|
884
|
+
|
885
|
+
config.indicesOptions = faiss::gpu::INDICES_32_BIT;
|
886
|
+
|
887
|
+
faiss::gpu::GpuIndexIVFFlat gpuIndex1(
|
888
|
+
&res, opt.dim, opt.numCentroids, faiss::METRIC_L2, config);
|
889
|
+
gpuIndex1.nprobe = opt.nprobe;
|
890
|
+
|
891
|
+
gpuIndex1.train(opt.numTrain, trainVecs.data());
|
892
|
+
gpuIndex1.add(opt.numAdd, addVecs.data());
|
893
|
+
|
894
|
+
gpuIndex1.reconstruct_n(0, gpuIndex1.ntotal, gpuVals.data());
|
895
|
+
|
896
|
+
EXPECT_EQ(gpuVals, cpuVals);
|
897
|
+
|
898
|
+
config.indicesOptions = faiss::gpu::INDICES_CPU;
|
899
|
+
|
900
|
+
faiss::gpu::GpuIndexIVFFlat gpuIndex2(
|
901
|
+
&res, opt.dim, opt.numCentroids, faiss::METRIC_L2, config);
|
902
|
+
gpuIndex2.nprobe = opt.nprobe;
|
903
|
+
|
904
|
+
gpuIndex2.train(opt.numTrain, trainVecs.data());
|
905
|
+
gpuIndex2.add(opt.numAdd, addVecs.data());
|
906
|
+
|
907
|
+
gpuIndex2.reconstruct_n(0, gpuIndex2.ntotal, gpuVals.data());
|
908
|
+
|
909
|
+
EXPECT_EQ(gpuVals, cpuVals);
|
910
|
+
}
|
911
|
+
|
845
912
|
int main(int argc, char** argv) {
|
846
913
|
testing::InitGoogleTest(&argc, argv);
|
847
914
|
|