faiss 0.3.1 → 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 +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,12 +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
|
-
// -*- c++ -*-
|
9
|
-
|
10
8
|
#include <faiss/index_io.h>
|
11
9
|
|
12
10
|
#include <faiss/impl/io.h>
|
@@ -15,13 +13,9 @@
|
|
15
13
|
#include <cstdio>
|
16
14
|
#include <cstdlib>
|
17
15
|
|
18
|
-
#include <sys/stat.h>
|
19
|
-
#include <sys/types.h>
|
20
|
-
|
21
16
|
#include <faiss/invlists/InvertedListsIOHook.h>
|
22
17
|
|
23
18
|
#include <faiss/impl/FaissAssert.h>
|
24
|
-
#include <faiss/impl/io.h>
|
25
19
|
#include <faiss/impl/io_macros.h>
|
26
20
|
#include <faiss/utils/hamming.h>
|
27
21
|
|
@@ -314,7 +308,11 @@ static void write_HNSW(const HNSW* hnsw, IOWriter* f) {
|
|
314
308
|
WRITE1(hnsw->max_level);
|
315
309
|
WRITE1(hnsw->efConstruction);
|
316
310
|
WRITE1(hnsw->efSearch);
|
317
|
-
|
311
|
+
|
312
|
+
// // deprecated field
|
313
|
+
// WRITE1(hnsw->upper_beam);
|
314
|
+
constexpr int tmp_upper_beam = 1;
|
315
|
+
WRITE1(tmp_upper_beam);
|
318
316
|
}
|
319
317
|
|
320
318
|
static void write_NSG(const NSG* nsg, IOWriter* f) {
|
@@ -390,8 +388,12 @@ static void write_ivf_header(const IndexIVF* ivf, IOWriter* f) {
|
|
390
388
|
write_direct_map(&ivf->direct_map, f);
|
391
389
|
}
|
392
390
|
|
393
|
-
void write_index(const Index* idx, IOWriter* f) {
|
394
|
-
if (
|
391
|
+
void write_index(const Index* idx, IOWriter* f, int io_flags) {
|
392
|
+
if (idx == nullptr) {
|
393
|
+
// eg. for a storage component of HNSW that is set to nullptr
|
394
|
+
uint32_t h = fourcc("null");
|
395
|
+
WRITE1(h);
|
396
|
+
} else if (const IndexFlat* idxf = dynamic_cast<const IndexFlat*>(idx)) {
|
395
397
|
uint32_t h =
|
396
398
|
fourcc(idxf->metric_type == METRIC_INNER_PRODUCT ? "IxFI"
|
397
399
|
: idxf->metric_type == METRIC_L2 ? "IxF2"
|
@@ -760,12 +762,24 @@ void write_index(const Index* idx, IOWriter* f) {
|
|
760
762
|
: dynamic_cast<const IndexHNSWPQ*>(idx) ? fourcc("IHNp")
|
761
763
|
: dynamic_cast<const IndexHNSWSQ*>(idx) ? fourcc("IHNs")
|
762
764
|
: dynamic_cast<const IndexHNSW2Level*>(idx) ? fourcc("IHN2")
|
765
|
+
: dynamic_cast<const IndexHNSWCagra*>(idx) ? fourcc("IHNc")
|
763
766
|
: 0;
|
764
767
|
FAISS_THROW_IF_NOT(h != 0);
|
765
768
|
WRITE1(h);
|
766
769
|
write_index_header(idxhnsw, f);
|
770
|
+
if (h == fourcc("IHNc")) {
|
771
|
+
WRITE1(idxhnsw->keep_max_size_level0);
|
772
|
+
auto idx_hnsw_cagra = dynamic_cast<const IndexHNSWCagra*>(idxhnsw);
|
773
|
+
WRITE1(idx_hnsw_cagra->base_level_only);
|
774
|
+
WRITE1(idx_hnsw_cagra->num_base_level_search_entrypoints);
|
775
|
+
}
|
767
776
|
write_HNSW(&idxhnsw->hnsw, f);
|
768
|
-
|
777
|
+
if (io_flags & IO_FLAG_SKIP_STORAGE) {
|
778
|
+
uint32_t n4 = fourcc("null");
|
779
|
+
WRITE1(n4);
|
780
|
+
} else {
|
781
|
+
write_index(idxhnsw->storage, f);
|
782
|
+
}
|
769
783
|
} else if (const IndexNSG* idxnsg = dynamic_cast<const IndexNSG*>(idx)) {
|
770
784
|
uint32_t h = dynamic_cast<const IndexNSGFlat*>(idx) ? fourcc("INSf")
|
771
785
|
: dynamic_cast<const IndexNSGPQ*>(idx) ? fourcc("INSp")
|
@@ -841,14 +855,14 @@ void write_index(const Index* idx, IOWriter* f) {
|
|
841
855
|
}
|
842
856
|
}
|
843
857
|
|
844
|
-
void write_index(const Index* idx, FILE* f) {
|
858
|
+
void write_index(const Index* idx, FILE* f, int io_flags) {
|
845
859
|
FileIOWriter writer(f);
|
846
|
-
write_index(idx, &writer);
|
860
|
+
write_index(idx, &writer, io_flags);
|
847
861
|
}
|
848
862
|
|
849
|
-
void write_index(const Index* idx, const char* fname) {
|
863
|
+
void write_index(const Index* idx, const char* fname, int io_flags) {
|
850
864
|
FileIOWriter writer(fname);
|
851
|
-
write_index(idx, &writer);
|
865
|
+
write_index(idx, &writer, io_flags);
|
852
866
|
}
|
853
867
|
|
854
868
|
void write_VectorTransform(const VectorTransform* vt, const char* fname) {
|
@@ -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.
|
@@ -20,11 +20,11 @@ namespace faiss {
|
|
20
20
|
* IO functions
|
21
21
|
***********************************************************************/
|
22
22
|
|
23
|
-
int IOReader::
|
23
|
+
int IOReader::filedescriptor() {
|
24
24
|
FAISS_THROW_MSG("IOReader does not support memory mapping");
|
25
25
|
}
|
26
26
|
|
27
|
-
int IOWriter::
|
27
|
+
int IOWriter::filedescriptor() {
|
28
28
|
FAISS_THROW_MSG("IOWriter does not support memory mapping");
|
29
29
|
}
|
30
30
|
|
@@ -85,8 +85,12 @@ size_t FileIOReader::operator()(void* ptr, size_t size, size_t nitems) {
|
|
85
85
|
return fread(ptr, size, nitems, f);
|
86
86
|
}
|
87
87
|
|
88
|
-
int FileIOReader::
|
88
|
+
int FileIOReader::filedescriptor() {
|
89
|
+
#ifdef _AIX
|
90
|
+
return fileno(f);
|
91
|
+
#else
|
89
92
|
return ::fileno(f);
|
93
|
+
#endif
|
90
94
|
}
|
91
95
|
|
92
96
|
FileIOWriter::FileIOWriter(FILE* wf) : f(wf) {}
|
@@ -116,8 +120,12 @@ size_t FileIOWriter::operator()(const void* ptr, size_t size, size_t nitems) {
|
|
116
120
|
return fwrite(ptr, size, nitems, f);
|
117
121
|
}
|
118
122
|
|
119
|
-
int FileIOWriter::
|
123
|
+
int FileIOWriter::filedescriptor() {
|
124
|
+
#ifdef _AIX
|
125
|
+
return fileno(f);
|
126
|
+
#else
|
120
127
|
return ::fileno(f);
|
128
|
+
#endif
|
121
129
|
}
|
122
130
|
|
123
131
|
/***********************************************************************
|
@@ -259,7 +267,7 @@ std::string fourcc_inv_printable(uint32_t x) {
|
|
259
267
|
str += c;
|
260
268
|
} else {
|
261
269
|
char buf[10];
|
262
|
-
|
270
|
+
snprintf(buf, sizeof(buf), "\\x%02x", c);
|
263
271
|
str += buf;
|
264
272
|
}
|
265
273
|
}
|
@@ -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.
|
@@ -32,7 +32,7 @@ struct IOReader {
|
|
32
32
|
virtual size_t operator()(void* ptr, size_t size, size_t nitems) = 0;
|
33
33
|
|
34
34
|
// return a file number that can be memory-mapped
|
35
|
-
virtual int
|
35
|
+
virtual int filedescriptor();
|
36
36
|
|
37
37
|
virtual ~IOReader() {}
|
38
38
|
};
|
@@ -45,7 +45,7 @@ struct IOWriter {
|
|
45
45
|
virtual size_t operator()(const void* ptr, size_t size, size_t nitems) = 0;
|
46
46
|
|
47
47
|
// return a file number that can be memory-mapped
|
48
|
-
virtual int
|
48
|
+
virtual int filedescriptor();
|
49
49
|
|
50
50
|
virtual ~IOWriter() noexcept(false) {}
|
51
51
|
};
|
@@ -73,7 +73,7 @@ struct FileIOReader : IOReader {
|
|
73
73
|
|
74
74
|
size_t operator()(void* ptr, size_t size, size_t nitems) override;
|
75
75
|
|
76
|
-
int
|
76
|
+
int filedescriptor() override;
|
77
77
|
};
|
78
78
|
|
79
79
|
struct FileIOWriter : IOWriter {
|
@@ -88,7 +88,7 @@ struct FileIOWriter : IOWriter {
|
|
88
88
|
|
89
89
|
size_t operator()(const void* ptr, size_t size, size_t nitems) override;
|
90
90
|
|
91
|
-
int
|
91
|
+
int filedescriptor() override;
|
92
92
|
};
|
93
93
|
|
94
94
|
/*******************************************************
|
@@ -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.
|
@@ -29,6 +29,12 @@
|
|
29
29
|
|
30
30
|
#define READ1(x) READANDCHECK(&(x), 1)
|
31
31
|
|
32
|
+
#define READ1_DUMMY(x_type) \
|
33
|
+
{ \
|
34
|
+
x_type x = {}; \
|
35
|
+
READ1(x); \
|
36
|
+
}
|
37
|
+
|
32
38
|
// will fail if we write 256G of data at once...
|
33
39
|
#define READVECTOR(vec) \
|
34
40
|
{ \
|
@@ -39,13 +45,6 @@
|
|
39
45
|
READANDCHECK((vec).data(), size); \
|
40
46
|
}
|
41
47
|
|
42
|
-
#define READSTRING(s) \
|
43
|
-
{ \
|
44
|
-
size_t size = (s).size(); \
|
45
|
-
WRITEANDCHECK(&size, 1); \
|
46
|
-
WRITEANDCHECK((s).c_str(), size); \
|
47
|
-
}
|
48
|
-
|
49
48
|
#define WRITEANDCHECK(ptr, n) \
|
50
49
|
{ \
|
51
50
|
size_t ret = (*f)(ptr, sizeof(*(ptr)), n); \
|
@@ -1,12 +1,11 @@
|
|
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
8
|
#include <algorithm>
|
9
|
-
#include <cstdint>
|
10
9
|
#include <cstring>
|
11
10
|
#include <functional>
|
12
11
|
#include <numeric>
|
@@ -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.
|
@@ -16,7 +16,6 @@
|
|
16
16
|
|
17
17
|
#include <algorithm>
|
18
18
|
#include <queue>
|
19
|
-
#include <unordered_map>
|
20
19
|
#include <unordered_set>
|
21
20
|
|
22
21
|
#include <faiss/impl/platform_macros.h>
|
@@ -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.
|
@@ -39,6 +39,7 @@
|
|
39
39
|
// redefine the GCC intrinsics with Windows equivalents
|
40
40
|
|
41
41
|
#include <intrin.h>
|
42
|
+
#include <limits.h>
|
42
43
|
|
43
44
|
#ifndef __clang__
|
44
45
|
inline int __builtin_ctzll(uint64_t x) {
|
@@ -59,7 +60,16 @@ inline int __builtin_ctz(unsigned long x) {
|
|
59
60
|
|
60
61
|
#ifndef __clang__
|
61
62
|
inline int __builtin_clzll(uint64_t x) {
|
63
|
+
#if defined(_M_X64) || defined(__x86_64__)
|
62
64
|
return (int)__lzcnt64(x);
|
65
|
+
#elif defined(_M_ARM64)
|
66
|
+
unsigned long index;
|
67
|
+
int count = sizeof(uint64_t) * CHAR_BIT;
|
68
|
+
if (_BitScanReverse64(&index, x)) {
|
69
|
+
count = count - 1 - index;
|
70
|
+
}
|
71
|
+
return count;
|
72
|
+
#endif
|
63
73
|
}
|
64
74
|
#endif
|
65
75
|
|
@@ -127,6 +137,13 @@ inline int __builtin_clzll(uint64_t x) {
|
|
127
137
|
__pragma(float_control(precise, off, push))
|
128
138
|
#define FAISS_PRAGMA_IMPRECISE_FUNCTION_END __pragma(float_control(pop))
|
129
139
|
#elif defined(__clang__)
|
140
|
+
#if defined(__PPC__)
|
141
|
+
#define FAISS_PRAGMA_IMPRECISE_LOOP \
|
142
|
+
_Pragma("clang loop vectorize_width(4) interleave_count(8)")
|
143
|
+
#define FAISS_PRAGMA_IMPRECISE_FUNCTION_BEGIN \
|
144
|
+
_Pragma("float_control(precise, off, push)")
|
145
|
+
#define FAISS_PRAGMA_IMPRECISE_FUNCTION_END _Pragma("float_control(pop)")
|
146
|
+
#else
|
130
147
|
#define FAISS_PRAGMA_IMPRECISE_LOOP \
|
131
148
|
_Pragma("clang loop vectorize(enable) interleave(enable)")
|
132
149
|
|
@@ -144,6 +161,7 @@ inline int __builtin_clzll(uint64_t x) {
|
|
144
161
|
#define FAISS_PRAGMA_IMPRECISE_FUNCTION_BEGIN
|
145
162
|
#define FAISS_PRAGMA_IMPRECISE_FUNCTION_END
|
146
163
|
#endif
|
164
|
+
#endif
|
147
165
|
#elif defined(__GNUC__)
|
148
166
|
// Unfortunately, GCC does not provide a pragma for detecting it.
|
149
167
|
// So, we have to stick to GNUC, which is defined by MANY compilers.
|
@@ -165,3 +183,17 @@ inline int __builtin_clzll(uint64_t x) {
|
|
165
183
|
#endif
|
166
184
|
|
167
185
|
// clang-format on
|
186
|
+
|
187
|
+
/*******************************************************
|
188
|
+
* BIGENDIAN specific macros
|
189
|
+
*******************************************************/
|
190
|
+
#if !defined(_MSC_VER) && \
|
191
|
+
(defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))
|
192
|
+
#define FAISS_BIG_ENDIAN
|
193
|
+
#endif
|
194
|
+
|
195
|
+
#define Swap2Bytes(val) ((((val) >> 8) & 0x00FF) | (((val) << 8) & 0xFF00))
|
196
|
+
|
197
|
+
#define Swap4Bytes(val) \
|
198
|
+
((((val) >> 24) & 0x000000FF) | (((val) >> 8) & 0x0000FF00) | \
|
199
|
+
(((val) << 8) & 0x00FF0000) | (((val) << 24) & 0xFF000000))
|
@@ -1,11 +1,12 @@
|
|
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
8
|
#include <faiss/impl/FaissAssert.h>
|
9
|
+
#include <faiss/impl/platform_macros.h>
|
9
10
|
#include <faiss/impl/pq4_fast_scan.h>
|
10
11
|
#include <faiss/impl/simd_result_handlers.h>
|
11
12
|
|
@@ -58,8 +59,13 @@ void pq4_pack_codes(
|
|
58
59
|
return;
|
59
60
|
}
|
60
61
|
memset(blocks, 0, nb * nsq / 2);
|
62
|
+
#ifdef FAISS_BIG_ENDIAN
|
63
|
+
const uint8_t perm0[16] = {
|
64
|
+
8, 0, 9, 1, 10, 2, 11, 3, 12, 4, 13, 5, 14, 6, 15, 7};
|
65
|
+
#else
|
61
66
|
const uint8_t perm0[16] = {
|
62
67
|
0, 8, 1, 9, 2, 10, 3, 11, 4, 12, 5, 13, 6, 14, 7, 15};
|
68
|
+
#endif
|
63
69
|
|
64
70
|
uint8_t* codes2 = blocks;
|
65
71
|
for (size_t i0 = 0; i0 < nb; i0 += bbs) {
|
@@ -93,8 +99,13 @@ void pq4_pack_codes_range(
|
|
93
99
|
size_t bbs,
|
94
100
|
size_t nsq,
|
95
101
|
uint8_t* blocks) {
|
102
|
+
#ifdef FAISS_BIG_ENDIAN
|
103
|
+
const uint8_t perm0[16] = {
|
104
|
+
8, 0, 9, 1, 10, 2, 11, 3, 12, 4, 13, 5, 14, 6, 15, 7};
|
105
|
+
#else
|
96
106
|
const uint8_t perm0[16] = {
|
97
107
|
0, 8, 1, 9, 2, 10, 3, 11, 4, 12, 5, 13, 6, 14, 7, 15};
|
108
|
+
#endif
|
98
109
|
|
99
110
|
// range of affected blocks
|
100
111
|
size_t block0 = i0 / bbs;
|
@@ -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.
|
@@ -189,4 +189,22 @@ void pq4_accumulate_loop_qbs(
|
|
189
189
|
SIMDResultHandler& res,
|
190
190
|
const NormTableScaler* scaler = nullptr);
|
191
191
|
|
192
|
+
/** Wrapper of pq4_accumulate_loop_qbs using simple StoreResultHandler
|
193
|
+
* and DummyScaler
|
194
|
+
*
|
195
|
+
* @param nq number of queries
|
196
|
+
* @param ntotal2 number of database elements (multiple of 32)
|
197
|
+
* @param nsq number of sub-quantizers (muliple of 2)
|
198
|
+
* @param codes packed codes array
|
199
|
+
* @param LUT packed look-up table
|
200
|
+
* @param accu array to store the results
|
201
|
+
*/
|
202
|
+
void accumulate_to_mem(
|
203
|
+
int nq,
|
204
|
+
size_t ntotal2,
|
205
|
+
int nsq,
|
206
|
+
const uint8_t* codes,
|
207
|
+
const uint8_t* LUT,
|
208
|
+
uint16_t* accu);
|
209
|
+
|
192
210
|
} // namespace faiss
|
@@ -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.
|
@@ -217,7 +217,7 @@ void pq4_accumulate_loop(
|
|
217
217
|
SIMDResultHandler& res,
|
218
218
|
const NormTableScaler* scaler) {
|
219
219
|
Run_pq4_accumulate_loop consumer;
|
220
|
-
|
220
|
+
dispatch_SIMDResultHandler(
|
221
221
|
res, consumer, nq, nb, bbs, nsq, codes, LUT, scaler);
|
222
222
|
}
|
223
223
|
|