faiss 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -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 +2 -2
- data/vendor/faiss/faiss/Clustering.cpp +2 -2
- data/vendor/faiss/faiss/Clustering.h +2 -2
- data/vendor/faiss/faiss/IVFlib.cpp +2 -2
- data/vendor/faiss/faiss/IVFlib.h +2 -2
- data/vendor/faiss/faiss/Index.cpp +6 -2
- data/vendor/faiss/faiss/Index.h +10 -3
- 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 +2 -2
- data/vendor/faiss/faiss/IndexBinaryHash.cpp +2 -3
- data/vendor/faiss/faiss/IndexBinaryHash.h +2 -2
- data/vendor/faiss/faiss/IndexBinaryIVF.cpp +2 -2
- data/vendor/faiss/faiss/IndexBinaryIVF.h +2 -2
- data/vendor/faiss/faiss/IndexFastScan.cpp +10 -14
- data/vendor/faiss/faiss/IndexFastScan.h +11 -2
- data/vendor/faiss/faiss/IndexFlat.cpp +2 -3
- data/vendor/faiss/faiss/IndexFlat.h +2 -2
- data/vendor/faiss/faiss/IndexFlatCodes.cpp +11 -2
- data/vendor/faiss/faiss/IndexFlatCodes.h +5 -2
- data/vendor/faiss/faiss/IndexHNSW.cpp +13 -6
- data/vendor/faiss/faiss/IndexHNSW.h +2 -2
- data/vendor/faiss/faiss/IndexIDMap.cpp +19 -3
- data/vendor/faiss/faiss/IndexIDMap.h +5 -2
- data/vendor/faiss/faiss/IndexIVF.cpp +2 -3
- data/vendor/faiss/faiss/IndexIVF.h +5 -4
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizer.cpp +6 -7
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizer.h +2 -2
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.cpp +3 -14
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.h +2 -4
- data/vendor/faiss/faiss/IndexIVFFastScan.cpp +71 -34
- data/vendor/faiss/faiss/IndexIVFFastScan.h +19 -2
- 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 +2 -3
- data/vendor/faiss/faiss/IndexIVFPQ.h +2 -2
- data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +7 -33
- 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 +2 -2
- data/vendor/faiss/faiss/IndexLattice.h +2 -2
- data/vendor/faiss/faiss/IndexNNDescent.cpp +2 -2
- data/vendor/faiss/faiss/IndexNNDescent.h +2 -2
- data/vendor/faiss/faiss/IndexNSG.cpp +2 -5
- data/vendor/faiss/faiss/IndexNSG.h +2 -2
- data/vendor/faiss/faiss/IndexNeuralNetCodec.cpp +2 -2
- data/vendor/faiss/faiss/IndexNeuralNetCodec.h +2 -2
- 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 +2 -2
- data/vendor/faiss/faiss/IndexRefine.cpp +41 -4
- 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 +2 -3
- 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 +2 -2
- 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 +2 -2
- data/vendor/faiss/faiss/cppcontrib/factory_tools.cpp +44 -4
- data/vendor/faiss/faiss/cppcontrib/factory_tools.h +7 -2
- data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-avx2-inl.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-inl.h +2 -2
- 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 +13 -13
- data/vendor/faiss/faiss/gpu/GpuCloner.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuClonerOptions.h +6 -6
- data/vendor/faiss/faiss/gpu/GpuDistance.h +11 -7
- data/vendor/faiss/faiss/gpu/GpuFaissAssert.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuIcmEncoder.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuIndex.h +8 -7
- data/vendor/faiss/faiss/gpu/GpuIndexBinaryFlat.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuIndexCagra.h +6 -3
- data/vendor/faiss/faiss/gpu/GpuIndexFlat.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuIndexIVF.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuIndexIVFFlat.h +2 -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 +51 -21
- 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 +2 -2
- 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 +2 -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 +2 -2
- 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 +80 -78
- 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 +2 -2
- data/vendor/faiss/faiss/gpu/utils/{RaftUtils.h → CuvsUtils.h} +12 -11
- data/vendor/faiss/faiss/gpu/utils/DeviceUtils.h +2 -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 +2 -2
- data/vendor/faiss/faiss/gpu/utils/Timer.h +2 -2
- 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 +2 -2
- data/vendor/faiss/faiss/impl/AuxIndexStructures.h +2 -2
- 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 +2 -2
- data/vendor/faiss/faiss/impl/FaissAssert.h +2 -2
- 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 +24 -19
- data/vendor/faiss/faiss/impl/HNSW.h +12 -2
- 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 +2 -2
- data/vendor/faiss/faiss/impl/LocalSearchQuantizer.h +2 -2
- data/vendor/faiss/faiss/impl/LookupTableScaler.h +2 -2
- data/vendor/faiss/faiss/impl/NNDescent.cpp +2 -2
- data/vendor/faiss/faiss/impl/NNDescent.h +2 -2
- data/vendor/faiss/faiss/impl/NSG.cpp +27 -21
- 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 +2 -2
- data/vendor/faiss/faiss/impl/ProductQuantizer.h +2 -2
- 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 +2 -2
- data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +2 -2
- data/vendor/faiss/faiss/impl/ScalarQuantizer.h +2 -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 +2 -2
- data/vendor/faiss/faiss/impl/code_distance/code_distance-avx512.h +2 -2
- 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 +2 -5
- data/vendor/faiss/faiss/impl/index_read_utils.h +2 -2
- data/vendor/faiss/faiss/impl/index_write.cpp +2 -6
- data/vendor/faiss/faiss/impl/io.cpp +2 -2
- data/vendor/faiss/faiss/impl/io.h +2 -2
- data/vendor/faiss/faiss/impl/io_macros.h +2 -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 +12 -2
- data/vendor/faiss/faiss/impl/pq4_fast_scan.cpp +2 -2
- data/vendor/faiss/faiss/impl/pq4_fast_scan.h +20 -2
- data/vendor/faiss/faiss/impl/pq4_fast_scan_search_1.cpp +2 -2
- data/vendor/faiss/faiss/impl/pq4_fast_scan_search_qbs.cpp +2 -2
- data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.cpp +3 -3
- data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.h +2 -2
- data/vendor/faiss/faiss/impl/simd_result_handlers.h +18 -18
- data/vendor/faiss/faiss/index_factory.cpp +20 -21
- data/vendor/faiss/faiss/index_factory.h +2 -2
- data/vendor/faiss/faiss/index_io.h +2 -2
- data/vendor/faiss/faiss/invlists/BlockInvertedLists.cpp +2 -2
- data/vendor/faiss/faiss/invlists/BlockInvertedLists.h +2 -2
- data/vendor/faiss/faiss/invlists/DirectMap.cpp +2 -2
- data/vendor/faiss/faiss/invlists/DirectMap.h +2 -2
- data/vendor/faiss/faiss/invlists/InvertedLists.cpp +2 -2
- data/vendor/faiss/faiss/invlists/InvertedLists.h +2 -2
- 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 +2 -3
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.h +2 -2
- data/vendor/faiss/faiss/python/python_callbacks.cpp +2 -2
- 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 +2 -2
- data/vendor/faiss/faiss/utils/NeuralNet.cpp +11 -7
- data/vendor/faiss/faiss/utils/NeuralNet.h +2 -2
- 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 +2 -2
- data/vendor/faiss/faiss/utils/distances.cpp +191 -2
- data/vendor/faiss/faiss/utils/distances.h +3 -3
- 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 +502 -3
- data/vendor/faiss/faiss/utils/extra_distances-inl.h +2 -2
- data/vendor/faiss/faiss/utils/extra_distances.cpp +2 -3
- data/vendor/faiss/faiss/utils/extra_distances.h +2 -2
- 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 +2 -3
- 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 +2 -2
- data/vendor/faiss/faiss/utils/hamming_distance/hamdis-inl.h +5 -2
- 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 +2 -2
- data/vendor/faiss/faiss/utils/random.h +2 -2
- data/vendor/faiss/faiss/utils/simdlib.h +2 -2
- data/vendor/faiss/faiss/utils/simdlib_avx2.h +2 -2
- data/vendor/faiss/faiss/utils/simdlib_avx512.h +2 -2
- data/vendor/faiss/faiss/utils/simdlib_emulated.h +2 -2
- data/vendor/faiss/faiss/utils/simdlib_neon.h +2 -2
- data/vendor/faiss/faiss/utils/simdlib_ppc64.h +2 -2
- 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 +2 -2
- data/vendor/faiss/faiss/utils/utils.cpp +7 -7
- data/vendor/faiss/faiss/utils/utils.h +4 -3
- metadata +9 -10
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
* Copyright (c)
|
1
|
+
/*
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -35,7 +35,7 @@ void pickEncoding(int& codes, int& dim) {
|
|
35
35
|
}
|
36
36
|
}
|
37
37
|
|
38
|
-
void
|
38
|
+
void pickCuvsEncoding(int& codes, int& dim, int bitsPerCode) {
|
39
39
|
// Above 32 doesn't work with no precomputed codes
|
40
40
|
std::vector<int> dimSizes{4, 8, 10, 12, 16, 20, 24, 28, 32};
|
41
41
|
|
@@ -85,7 +85,7 @@ struct Options {
|
|
85
85
|
device = faiss::gpu::randVal(0, faiss::gpu::getNumDevices() - 1);
|
86
86
|
|
87
87
|
interleavedLayout = false;
|
88
|
-
|
88
|
+
useCuvs = false;
|
89
89
|
}
|
90
90
|
|
91
91
|
std::string toString() const {
|
@@ -126,7 +126,7 @@ struct Options {
|
|
126
126
|
bool useFloat16;
|
127
127
|
int device;
|
128
128
|
bool interleavedLayout;
|
129
|
-
bool
|
129
|
+
bool useCuvs;
|
130
130
|
};
|
131
131
|
|
132
132
|
void queryTest(Options opt, faiss::MetricType metricType) {
|
@@ -156,7 +156,7 @@ void queryTest(Options opt, faiss::MetricType metricType) {
|
|
156
156
|
config.indicesOptions = opt.indicesOpt;
|
157
157
|
config.useFloat16LookupTables = opt.useFloat16;
|
158
158
|
config.interleavedLayout = opt.interleavedLayout;
|
159
|
-
config.
|
159
|
+
config.use_cuvs = opt.useCuvs;
|
160
160
|
|
161
161
|
faiss::gpu::GpuIndexIVFPQ gpuIndex(&res, &cpuIndex, config);
|
162
162
|
gpuIndex.nprobe = opt.nprobe;
|
@@ -235,7 +235,7 @@ void testMMCodeDistance(faiss::MetricType mt) {
|
|
235
235
|
config.usePrecomputedTables = false;
|
236
236
|
config.useMMCodeDistance = true;
|
237
237
|
config.indicesOptions = opt.indicesOpt;
|
238
|
-
config.
|
238
|
+
config.use_cuvs = false;
|
239
239
|
|
240
240
|
// Make sure that the float16 version works as well
|
241
241
|
config.useFloat16LookupTables = (tries % 2 == 0);
|
@@ -286,7 +286,7 @@ void testMMCodeDistance(faiss::MetricType mt) {
|
|
286
286
|
config.device = opt.device;
|
287
287
|
config.usePrecomputedTables = false;
|
288
288
|
config.indicesOptions = opt.indicesOpt;
|
289
|
-
config.
|
289
|
+
config.use_cuvs = false;
|
290
290
|
|
291
291
|
// Make sure that the float16 version works as well
|
292
292
|
config.useFloat16LookupTables = (dimPerSubQ == 7);
|
@@ -340,7 +340,7 @@ TEST(TestGpuIndexIVFPQ, Float16Coarse) {
|
|
340
340
|
config.usePrecomputedTables = opt.usePrecomputed;
|
341
341
|
config.indicesOptions = opt.indicesOpt;
|
342
342
|
config.useFloat16LookupTables = opt.useFloat16;
|
343
|
-
config.
|
343
|
+
config.use_cuvs = false;
|
344
344
|
|
345
345
|
faiss::gpu::GpuIndexIVFPQ gpuIndex(&res, &cpuIndex, config);
|
346
346
|
gpuIndex.nprobe = opt.nprobe;
|
@@ -386,7 +386,7 @@ void addTest(Options opt, faiss::MetricType metricType) {
|
|
386
386
|
config.indicesOptions = opt.indicesOpt;
|
387
387
|
config.useFloat16LookupTables = opt.useFloat16;
|
388
388
|
config.interleavedLayout = opt.interleavedLayout;
|
389
|
-
config.
|
389
|
+
config.use_cuvs = opt.useCuvs;
|
390
390
|
|
391
391
|
faiss::gpu::GpuIndexIVFPQ gpuIndex(&res, &cpuIndex, config);
|
392
392
|
gpuIndex.nprobe = opt.nprobe;
|
@@ -436,7 +436,7 @@ void copyToTest(Options opt) {
|
|
436
436
|
config.indicesOptions = opt.indicesOpt;
|
437
437
|
config.useFloat16LookupTables = opt.useFloat16;
|
438
438
|
config.interleavedLayout = opt.interleavedLayout;
|
439
|
-
config.
|
439
|
+
config.use_cuvs = opt.useCuvs;
|
440
440
|
|
441
441
|
faiss::gpu::GpuIndexIVFPQ gpuIndex(
|
442
442
|
&res,
|
@@ -513,7 +513,7 @@ void copyFromTest(Options opt) {
|
|
513
513
|
config.indicesOptions = opt.indicesOpt;
|
514
514
|
config.useFloat16LookupTables = opt.useFloat16;
|
515
515
|
config.interleavedLayout = opt.interleavedLayout;
|
516
|
-
config.
|
516
|
+
config.use_cuvs = opt.useCuvs;
|
517
517
|
|
518
518
|
// Use garbage values to see if we overwrite them
|
519
519
|
faiss::gpu::GpuIndexIVFPQ gpuIndex(
|
@@ -567,8 +567,8 @@ void queryNaNTest(Options opt) {
|
|
567
567
|
config.usePrecomputedTables = opt.usePrecomputed;
|
568
568
|
config.indicesOptions = opt.indicesOpt;
|
569
569
|
config.useFloat16LookupTables = opt.useFloat16;
|
570
|
-
config.
|
571
|
-
config.interleavedLayout = opt.
|
570
|
+
config.use_cuvs = opt.useCuvs;
|
571
|
+
config.interleavedLayout = opt.useCuvs ? true : opt.interleavedLayout;
|
572
572
|
|
573
573
|
faiss::gpu::GpuIndexIVFPQ gpuIndex(
|
574
574
|
&res,
|
@@ -606,7 +606,7 @@ void queryNaNTest(Options opt) {
|
|
606
606
|
|
607
607
|
TEST(TestGpuIndexIVFPQ, QueryNaN) {
|
608
608
|
Options opt;
|
609
|
-
opt.
|
609
|
+
opt.useCuvs = false;
|
610
610
|
queryNaNTest(opt);
|
611
611
|
}
|
612
612
|
|
@@ -620,7 +620,7 @@ void addNaNTest(Options opt) {
|
|
620
620
|
config.indicesOptions = opt.indicesOpt;
|
621
621
|
config.useFloat16LookupTables = opt.useFloat16;
|
622
622
|
config.interleavedLayout = opt.interleavedLayout;
|
623
|
-
config.
|
623
|
+
config.use_cuvs = opt.useCuvs;
|
624
624
|
|
625
625
|
faiss::gpu::GpuIndexIVFPQ gpuIndex(
|
626
626
|
&res,
|
@@ -664,46 +664,46 @@ void addNaNTest(Options opt) {
|
|
664
664
|
|
665
665
|
TEST(TestGpuIndexIVFPQ, AddNaN) {
|
666
666
|
Options opt;
|
667
|
-
opt.
|
667
|
+
opt.useCuvs = false;
|
668
668
|
addNaNTest(opt);
|
669
669
|
}
|
670
670
|
|
671
|
-
#if defined
|
672
|
-
TEST(TestGpuIndexIVFPQ,
|
671
|
+
#if defined USE_NVIDIA_CUVS
|
672
|
+
TEST(TestGpuIndexIVFPQ, Query_L2_Cuvs) {
|
673
673
|
for (int tries = 0; tries < 2; ++tries) {
|
674
674
|
Options opt;
|
675
675
|
opt.bitsPerCode = faiss::gpu::randVal(4, 8);
|
676
|
-
opt.
|
676
|
+
opt.useCuvs = true;
|
677
677
|
opt.interleavedLayout = true;
|
678
678
|
opt.usePrecomputed = false;
|
679
679
|
opt.indicesOpt = faiss::gpu::INDICES_64_BIT;
|
680
|
-
|
680
|
+
pickCuvsEncoding(opt.codes, opt.dim, opt.bitsPerCode);
|
681
681
|
queryTest(opt, faiss::MetricType::METRIC_L2);
|
682
682
|
}
|
683
683
|
}
|
684
684
|
|
685
|
-
TEST(TestGpuIndexIVFPQ,
|
685
|
+
TEST(TestGpuIndexIVFPQ, Query_IP_Cuvs) {
|
686
686
|
for (int tries = 0; tries < 2; ++tries) {
|
687
687
|
Options opt;
|
688
688
|
opt.bitsPerCode = faiss::gpu::randVal(4, 8);
|
689
|
-
opt.
|
689
|
+
opt.useCuvs = true;
|
690
690
|
opt.interleavedLayout = true;
|
691
691
|
opt.usePrecomputed = false;
|
692
692
|
opt.indicesOpt = faiss::gpu::INDICES_64_BIT;
|
693
|
-
|
693
|
+
pickCuvsEncoding(opt.codes, opt.dim, opt.bitsPerCode);
|
694
694
|
queryTest(opt, faiss::MetricType::METRIC_INNER_PRODUCT);
|
695
695
|
}
|
696
696
|
}
|
697
697
|
|
698
698
|
// Large batch sizes (>= 65536) should also work
|
699
|
-
TEST(TestGpuIndexIVFPQ,
|
699
|
+
TEST(TestGpuIndexIVFPQ, LargeBatch_Cuvs) {
|
700
700
|
Options opt;
|
701
701
|
|
702
702
|
// override for large sizes
|
703
703
|
opt.dim = 4;
|
704
704
|
opt.numQuery = 100000;
|
705
705
|
opt.codes = 2;
|
706
|
-
opt.
|
706
|
+
opt.useCuvs = true;
|
707
707
|
opt.interleavedLayout = true;
|
708
708
|
opt.usePrecomputed = false;
|
709
709
|
opt.useFloat16 = false;
|
@@ -713,73 +713,73 @@ TEST(TestGpuIndexIVFPQ, LargeBatch_Raft) {
|
|
713
713
|
queryTest(opt, faiss::MetricType::METRIC_L2);
|
714
714
|
}
|
715
715
|
|
716
|
-
TEST(TestGpuIndexIVFPQ,
|
716
|
+
TEST(TestGpuIndexIVFPQ, CopyFrom_Cuvs) {
|
717
717
|
Options opt;
|
718
|
-
opt.
|
718
|
+
opt.useCuvs = true;
|
719
719
|
opt.interleavedLayout = true;
|
720
720
|
opt.bitsPerCode = faiss::gpu::randVal(4, 8);
|
721
721
|
opt.usePrecomputed = false;
|
722
722
|
opt.indicesOpt = faiss::gpu::INDICES_64_BIT;
|
723
|
-
|
723
|
+
pickCuvsEncoding(opt.codes, opt.dim, opt.bitsPerCode);
|
724
724
|
copyFromTest(opt);
|
725
725
|
}
|
726
726
|
|
727
|
-
TEST(TestGpuIndexIVFPQ,
|
727
|
+
TEST(TestGpuIndexIVFPQ, Add_L2_Cuvs) {
|
728
728
|
for (int tries = 0; tries < 2; ++tries) {
|
729
729
|
Options opt;
|
730
|
-
opt.
|
730
|
+
opt.useCuvs = true;
|
731
731
|
opt.interleavedLayout = true;
|
732
732
|
opt.bitsPerCode = faiss::gpu::randVal(4, 8);
|
733
733
|
opt.usePrecomputed = false;
|
734
734
|
opt.indicesOpt = faiss::gpu::INDICES_64_BIT;
|
735
|
-
|
735
|
+
pickCuvsEncoding(opt.codes, opt.dim, opt.bitsPerCode);
|
736
736
|
addTest(opt, faiss::METRIC_L2);
|
737
737
|
}
|
738
738
|
}
|
739
739
|
|
740
|
-
TEST(TestGpuIndexIVFPQ,
|
740
|
+
TEST(TestGpuIndexIVFPQ, Add_IP_Cuvs) {
|
741
741
|
for (int tries = 0; tries < 2; ++tries) {
|
742
742
|
Options opt;
|
743
|
-
opt.
|
743
|
+
opt.useCuvs = true;
|
744
744
|
opt.interleavedLayout = true;
|
745
745
|
opt.bitsPerCode = faiss::gpu::randVal(4, 8);
|
746
746
|
opt.usePrecomputed = false;
|
747
747
|
opt.indicesOpt = faiss::gpu::INDICES_64_BIT;
|
748
|
-
|
748
|
+
pickCuvsEncoding(opt.codes, opt.dim, opt.bitsPerCode);
|
749
749
|
addTest(opt, faiss::METRIC_INNER_PRODUCT);
|
750
750
|
}
|
751
751
|
}
|
752
752
|
|
753
|
-
TEST(TestGpuIndexIVFPQ,
|
753
|
+
TEST(TestGpuIndexIVFPQ, QueryNaN_Cuvs) {
|
754
754
|
Options opt;
|
755
|
-
opt.
|
755
|
+
opt.useCuvs = true;
|
756
756
|
opt.interleavedLayout = true;
|
757
757
|
opt.bitsPerCode = faiss::gpu::randVal(4, 8);
|
758
758
|
opt.usePrecomputed = false;
|
759
759
|
opt.indicesOpt = faiss::gpu::INDICES_64_BIT;
|
760
|
-
|
760
|
+
pickCuvsEncoding(opt.codes, opt.dim, opt.bitsPerCode);
|
761
761
|
queryNaNTest(opt);
|
762
762
|
}
|
763
763
|
|
764
|
-
TEST(TestGpuIndexIVFPQ,
|
764
|
+
TEST(TestGpuIndexIVFPQ, AddNaN_Cuvs) {
|
765
765
|
Options opt;
|
766
|
-
opt.
|
766
|
+
opt.useCuvs = true;
|
767
767
|
opt.interleavedLayout = true;
|
768
768
|
opt.bitsPerCode = faiss::gpu::randVal(4, 8);
|
769
769
|
opt.usePrecomputed = false;
|
770
770
|
opt.indicesOpt = faiss::gpu::INDICES_64_BIT;
|
771
|
-
|
771
|
+
pickCuvsEncoding(opt.codes, opt.dim, opt.bitsPerCode);
|
772
772
|
addNaNTest(opt);
|
773
773
|
}
|
774
774
|
|
775
|
-
TEST(TestGpuIndexIVFPQ,
|
775
|
+
TEST(TestGpuIndexIVFPQ, CopyTo_Cuvs) {
|
776
776
|
Options opt;
|
777
|
-
opt.
|
777
|
+
opt.useCuvs = true;
|
778
778
|
opt.interleavedLayout = true;
|
779
779
|
opt.bitsPerCode = faiss::gpu::randVal(4, 8);
|
780
780
|
opt.usePrecomputed = false;
|
781
781
|
opt.indicesOpt = faiss::gpu::INDICES_64_BIT;
|
782
|
-
|
782
|
+
pickCuvsEncoding(opt.codes, opt.dim, opt.bitsPerCode);
|
783
783
|
copyToTest(opt);
|
784
784
|
}
|
785
785
|
#endif
|
@@ -824,7 +824,7 @@ TEST(TestGpuIndexIVFPQ, UnifiedMemory) {
|
|
824
824
|
faiss::gpu::GpuIndexIVFPQConfig config;
|
825
825
|
config.device = device;
|
826
826
|
config.memorySpace = faiss::gpu::MemorySpace::Unified;
|
827
|
-
config.
|
827
|
+
config.use_cuvs = false;
|
828
828
|
|
829
829
|
faiss::gpu::GpuIndexIVFPQ gpuIndex(
|
830
830
|
&res,
|
@@ -848,12 +848,12 @@ TEST(TestGpuIndexIVFPQ, UnifiedMemory) {
|
|
848
848
|
0.1f,
|
849
849
|
0.015f);
|
850
850
|
|
851
|
-
#if defined
|
851
|
+
#if defined USE_NVIDIA_CUVS
|
852
852
|
config.interleavedLayout = true;
|
853
|
-
config.
|
853
|
+
config.use_cuvs = true;
|
854
854
|
config.indicesOptions = faiss::gpu::INDICES_64_BIT;
|
855
855
|
|
856
|
-
faiss::gpu::GpuIndexIVFPQ
|
856
|
+
faiss::gpu::GpuIndexIVFPQ cuvsGpuIndex(
|
857
857
|
&res,
|
858
858
|
dim,
|
859
859
|
numCentroids,
|
@@ -861,12 +861,12 @@ TEST(TestGpuIndexIVFPQ, UnifiedMemory) {
|
|
861
861
|
bitsPerCode,
|
862
862
|
faiss::METRIC_L2,
|
863
863
|
config);
|
864
|
-
|
865
|
-
|
864
|
+
cuvsGpuIndex.copyFrom(&cpuIndex);
|
865
|
+
cuvsGpuIndex.nprobe = nprobe;
|
866
866
|
|
867
867
|
faiss::gpu::compareIndices(
|
868
868
|
cpuIndex,
|
869
|
-
|
869
|
+
cuvsGpuIndex,
|
870
870
|
numQuery,
|
871
871
|
dim,
|
872
872
|
k,
|
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
* Copyright (c)
|
1
|
+
/*
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -31,7 +31,7 @@ TEST(TestGpuMemoryException, AddException) {
|
|
31
31
|
|
32
32
|
faiss::gpu::GpuIndexFlatConfig config;
|
33
33
|
config.device = faiss::gpu::randVal(0, faiss::gpu::getNumDevices() - 1);
|
34
|
-
config.
|
34
|
+
config.use_cuvs = false;
|
35
35
|
|
36
36
|
faiss::gpu::GpuIndexFlatL2 gpuIndexL2Broken(
|
37
37
|
&res, (int)brokenAddDims, config);
|
@@ -0,0 +1,70 @@
|
|
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
|
+
#include <faiss/IndexFlat.h>
|
9
|
+
#include <faiss/gpu/GpuCloner.h>
|
10
|
+
#include <faiss/gpu/GpuIndexFlat.h>
|
11
|
+
#include <faiss/gpu/StandardGpuResources.h>
|
12
|
+
#include <faiss/gpu/test/TestUtils.h>
|
13
|
+
#include <faiss/impl/ResidualQuantizer.h>
|
14
|
+
#include <gtest/gtest.h>
|
15
|
+
|
16
|
+
using namespace ::testing;
|
17
|
+
|
18
|
+
float eval_codec(faiss::ResidualQuantizer* q, int nb, float* xb) {
|
19
|
+
// Compute codes
|
20
|
+
uint8_t* codes = new uint8_t[q->code_size * nb];
|
21
|
+
std::cout << "code size: " << q->code_size << std::endl;
|
22
|
+
q->compute_codes(xb, codes, nb);
|
23
|
+
// Decode codes
|
24
|
+
float* decoded = new float[nb * q->d];
|
25
|
+
q->decode(codes, decoded, nb);
|
26
|
+
// Compute reconstruction error
|
27
|
+
float err = 0.0f;
|
28
|
+
for (int i = 0; i < nb; i++) {
|
29
|
+
for (int j = 0; j < q->d; j++) {
|
30
|
+
float diff = xb[i * q->d + j] - decoded[i * q->d + j];
|
31
|
+
err = err + (diff * diff);
|
32
|
+
}
|
33
|
+
}
|
34
|
+
delete[] codes;
|
35
|
+
delete[] decoded;
|
36
|
+
return err;
|
37
|
+
}
|
38
|
+
|
39
|
+
TEST(TestGpuResidualQuantizer, TestNcall) {
|
40
|
+
int d = 32;
|
41
|
+
int nt = 3000;
|
42
|
+
int nb = 1000;
|
43
|
+
// Assuming get_dataset_2 is a function that returns xt and xb
|
44
|
+
std::vector<float> xt = faiss::gpu::randVecs(nt, d);
|
45
|
+
std::vector<float> xb = faiss::gpu::randVecs(nb, d);
|
46
|
+
faiss::ResidualQuantizer rq0(d, 4, 6);
|
47
|
+
rq0.train(nt, xt.data());
|
48
|
+
float err_rq0 = eval_codec(&rq0, nb, xb.data());
|
49
|
+
faiss::ResidualQuantizer rq1(d, 4, 6);
|
50
|
+
faiss::gpu::GpuProgressiveDimIndexFactory fac(1);
|
51
|
+
rq1.assign_index_factory = &fac;
|
52
|
+
rq1.train(nt, xt.data());
|
53
|
+
ASSERT_GT(fac.ncall, 0);
|
54
|
+
int ncall_train = fac.ncall;
|
55
|
+
float err_rq1 = eval_codec(&rq1, nb, xb.data());
|
56
|
+
ASSERT_GT(fac.ncall, ncall_train);
|
57
|
+
std::cout << "Error RQ0: " << err_rq0 << ", Error RQ1: " << err_rq1
|
58
|
+
<< std::endl;
|
59
|
+
ASSERT_TRUE(0.9 * err_rq0 < err_rq1);
|
60
|
+
ASSERT_TRUE(err_rq1 < 1.1 * err_rq0);
|
61
|
+
}
|
62
|
+
|
63
|
+
int main(int argc, char** argv) {
|
64
|
+
testing::InitGoogleTest(&argc, argv);
|
65
|
+
|
66
|
+
// just run with a fixed test seed
|
67
|
+
faiss::gpu::setTestSeed(100);
|
68
|
+
|
69
|
+
return RUN_ALL_TESTS();
|
70
|
+
}
|
@@ -1,11 +1,10 @@
|
|
1
|
-
|
2
|
-
* Copyright (c)
|
1
|
+
/*
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*/
|
7
7
|
|
8
|
-
#include <cuda_fp16.h>
|
9
8
|
#include <faiss/gpu/test/TestUtils.h>
|
10
9
|
#include <faiss/utils/random.h>
|
11
10
|
#include <gtest/gtest.h>
|
@@ -18,6 +17,77 @@
|
|
18
17
|
namespace faiss {
|
19
18
|
namespace gpu {
|
20
19
|
|
20
|
+
inline float half2float(const unsigned short h) {
|
21
|
+
unsigned int sign = ((static_cast<unsigned int>(h) >> 15U) & 1U);
|
22
|
+
unsigned int exponent = ((static_cast<unsigned int>(h) >> 10U) & 0x1fU);
|
23
|
+
unsigned int mantissa = ((static_cast<unsigned int>(h) & 0x3ffU) << 13U);
|
24
|
+
float f;
|
25
|
+
if (exponent == 0x1fU) { /* NaN or Inf */
|
26
|
+
/* discard sign of a NaN */
|
27
|
+
sign = ((mantissa != 0U) ? (sign >> 1U) : sign);
|
28
|
+
mantissa = ((mantissa != 0U) ? 0x7fffffU : 0U);
|
29
|
+
exponent = 0xffU;
|
30
|
+
} else if (exponent == 0U) { /* Denorm or Zero */
|
31
|
+
if (mantissa != 0U) {
|
32
|
+
unsigned int msb;
|
33
|
+
exponent = 0x71U;
|
34
|
+
do {
|
35
|
+
msb = (mantissa & 0x400000U);
|
36
|
+
mantissa <<= 1U; /* normalize */
|
37
|
+
--exponent;
|
38
|
+
} while (msb == 0U);
|
39
|
+
mantissa &= 0x7fffffU; /* 1.mantissa is implicit */
|
40
|
+
}
|
41
|
+
} else {
|
42
|
+
exponent += 0x70U;
|
43
|
+
}
|
44
|
+
const unsigned int u = ((sign << 31U) | (exponent << 23U) | mantissa);
|
45
|
+
std::memcpy(&f, &u, sizeof(u));
|
46
|
+
return f;
|
47
|
+
}
|
48
|
+
|
49
|
+
unsigned short float2half(const float f) {
|
50
|
+
unsigned int sign;
|
51
|
+
unsigned int remainder;
|
52
|
+
unsigned int x;
|
53
|
+
unsigned int u;
|
54
|
+
unsigned int result;
|
55
|
+
(void)std::memcpy(&x, &f, sizeof(f));
|
56
|
+
|
57
|
+
u = (x & 0x7fffffffU);
|
58
|
+
sign = ((x >> 16U) & 0x8000U);
|
59
|
+
// NaN/+Inf/-Inf
|
60
|
+
if (u >= 0x7f800000U) {
|
61
|
+
remainder = 0U;
|
62
|
+
result = ((u == 0x7f800000U) ? (sign | 0x7c00U) : 0x7fffU);
|
63
|
+
} else if (u > 0x477fefffU) { // Overflows
|
64
|
+
remainder = 0x80000000U;
|
65
|
+
result = (sign | 0x7bffU);
|
66
|
+
} else if (u >= 0x38800000U) { // Normal numbers
|
67
|
+
remainder = u << 19U;
|
68
|
+
u -= 0x38000000U;
|
69
|
+
result = (sign | (u >> 13U));
|
70
|
+
} else if (u < 0x33000001U) { // +0/-0
|
71
|
+
remainder = u;
|
72
|
+
result = sign;
|
73
|
+
} else { // Denormal numbers
|
74
|
+
const unsigned int exponent = u >> 23U;
|
75
|
+
const unsigned int shift = 0x7eU - exponent;
|
76
|
+
unsigned int mantissa = (u & 0x7fffffU);
|
77
|
+
mantissa |= 0x800000U;
|
78
|
+
remainder = mantissa << (32U - shift);
|
79
|
+
result = (sign | (mantissa >> shift));
|
80
|
+
result &= 0x0000FFFFU;
|
81
|
+
}
|
82
|
+
|
83
|
+
if ((remainder > 0x80000000U) ||
|
84
|
+
((remainder == 0x80000000U) && ((result & 0x1U) != 0U))) {
|
85
|
+
return static_cast<unsigned short>(result) + 1;
|
86
|
+
} else {
|
87
|
+
return static_cast<unsigned short>(result);
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
21
91
|
inline float relativeError(float a, float b) {
|
22
92
|
return std::abs(a - b) / (0.5f * (std::abs(a) + std::abs(b)));
|
23
93
|
}
|
@@ -78,7 +148,7 @@ std::vector<unsigned char> randBinaryVecs(size_t num, size_t dim) {
|
|
78
148
|
std::vector<float> roundToHalf(const std::vector<float>& v) {
|
79
149
|
auto out = std::vector<float>(v.size());
|
80
150
|
for (int i = 0; i < v.size(); ++i) {
|
81
|
-
out[i] =
|
151
|
+
out[i] = half2float(float2half(v[i]));
|
82
152
|
}
|
83
153
|
|
84
154
|
return out;
|
@@ -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)
|
9
|
+
* Copyright (c) 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.
|
@@ -26,32 +27,32 @@
|
|
26
27
|
#include <faiss/gpu/GpuResources.h>
|
27
28
|
#include <faiss/gpu/utils/Tensor.cuh>
|
28
29
|
|
29
|
-
#include <
|
30
|
+
#include <cuvs/distance/distance.h>
|
30
31
|
|
31
32
|
#pragma GCC visibility push(default)
|
32
33
|
namespace faiss {
|
33
34
|
namespace gpu {
|
34
35
|
|
35
|
-
inline
|
36
|
+
inline cuvsDistanceType metricFaissToCuvs(
|
36
37
|
MetricType metric,
|
37
38
|
bool exactDistance) {
|
38
39
|
switch (metric) {
|
39
40
|
case MetricType::METRIC_INNER_PRODUCT:
|
40
|
-
return
|
41
|
+
return cuvsDistanceType::InnerProduct;
|
41
42
|
case MetricType::METRIC_L2:
|
42
|
-
return
|
43
|
+
return cuvsDistanceType::L2Expanded;
|
43
44
|
case MetricType::METRIC_L1:
|
44
|
-
return
|
45
|
+
return cuvsDistanceType::L1;
|
45
46
|
case MetricType::METRIC_Linf:
|
46
|
-
return
|
47
|
+
return cuvsDistanceType::Linf;
|
47
48
|
case MetricType::METRIC_Lp:
|
48
|
-
return
|
49
|
+
return cuvsDistanceType::LpUnexpanded;
|
49
50
|
case MetricType::METRIC_Canberra:
|
50
|
-
return
|
51
|
+
return cuvsDistanceType::Canberra;
|
51
52
|
case MetricType::METRIC_BrayCurtis:
|
52
|
-
return
|
53
|
+
return cuvsDistanceType::BrayCurtis;
|
53
54
|
case MetricType::METRIC_JensenShannon:
|
54
|
-
return
|
55
|
+
return cuvsDistanceType::JensenShannon;
|
55
56
|
default:
|
56
57
|
RAFT_FAIL("Distance type not supported");
|
57
58
|
}
|