faiss 0.6.0 → 0.6.1
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 +4 -0
- data/ext/faiss/extconf.rb +2 -1
- data/ext/faiss/{index_rb.cpp → index.cpp} +1 -1
- data/ext/faiss/index_binary.cpp +1 -1
- data/ext/faiss/kmeans.cpp +1 -1
- data/ext/faiss/pca_matrix.cpp +1 -1
- data/ext/faiss/product_quantizer.cpp +1 -1
- data/ext/faiss/{utils_rb.cpp → utils.cpp} +1 -1
- data/lib/faiss/version.rb +1 -1
- data/vendor/faiss/faiss/AutoTune.cpp +93 -80
- data/vendor/faiss/faiss/Clustering.cpp +39 -240
- data/vendor/faiss/faiss/Clustering.h +6 -0
- data/vendor/faiss/faiss/IVFlib.cpp +41 -21
- data/vendor/faiss/faiss/Index.cpp +6 -5
- data/vendor/faiss/faiss/Index.h +5 -5
- data/vendor/faiss/faiss/Index2Layer.cpp +37 -53
- data/vendor/faiss/faiss/IndexAdditiveQuantizer.cpp +49 -37
- data/vendor/faiss/faiss/IndexAdditiveQuantizerFastScan.cpp +36 -34
- data/vendor/faiss/faiss/IndexAdditiveQuantizerFastScan.h +4 -1
- data/vendor/faiss/faiss/IndexBinary.cpp +5 -3
- data/vendor/faiss/faiss/IndexBinary.h +4 -4
- data/vendor/faiss/faiss/IndexBinaryFlat.cpp +1 -1
- data/vendor/faiss/faiss/IndexBinaryFlat.h +1 -1
- data/vendor/faiss/faiss/IndexBinaryFromFloat.cpp +4 -4
- data/vendor/faiss/faiss/IndexBinaryHNSW.cpp +84 -92
- data/vendor/faiss/faiss/IndexBinaryHNSW.h +9 -3
- data/vendor/faiss/faiss/IndexBinaryHash.cpp +45 -236
- data/vendor/faiss/faiss/IndexBinaryHash.h +6 -6
- data/vendor/faiss/faiss/IndexBinaryIVF.cpp +87 -415
- data/vendor/faiss/faiss/IndexFastScan.cpp +72 -109
- data/vendor/faiss/faiss/IndexFastScan.h +25 -23
- data/vendor/faiss/faiss/IndexFlat.cpp +27 -20
- data/vendor/faiss/faiss/IndexFlat.h +21 -18
- data/vendor/faiss/faiss/IndexFlatCodes.cpp +42 -19
- data/vendor/faiss/faiss/IndexHNSW.cpp +283 -145
- data/vendor/faiss/faiss/IndexHNSW.h +16 -2
- data/vendor/faiss/faiss/IndexIDMap.cpp +25 -21
- data/vendor/faiss/faiss/IndexIDMap.h +9 -7
- data/vendor/faiss/faiss/IndexIVF.cpp +465 -362
- data/vendor/faiss/faiss/IndexIVF.h +33 -12
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizer.cpp +77 -74
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.cpp +96 -93
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.h +4 -1
- data/vendor/faiss/faiss/IndexIVFFastScan.cpp +357 -238
- data/vendor/faiss/faiss/IndexIVFFastScan.h +42 -41
- data/vendor/faiss/faiss/IndexIVFFlat.cpp +36 -68
- data/vendor/faiss/faiss/IndexIVFFlat.h +32 -0
- data/vendor/faiss/faiss/IndexIVFFlatPanorama.cpp +53 -30
- data/vendor/faiss/faiss/IndexIVFFlatPanorama.h +3 -1
- data/vendor/faiss/faiss/IndexIVFIndependentQuantizer.cpp +18 -15
- data/vendor/faiss/faiss/IndexIVFPQ.cpp +71 -843
- data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +151 -121
- data/vendor/faiss/faiss/IndexIVFPQFastScan.h +3 -0
- data/vendor/faiss/faiss/IndexIVFPQR.cpp +21 -17
- data/vendor/faiss/faiss/IndexIVFRaBitQ.cpp +26 -39
- data/vendor/faiss/faiss/IndexIVFRaBitQ.h +2 -1
- data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.cpp +475 -476
- data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.h +248 -93
- data/vendor/faiss/faiss/IndexIVFSpectralHash.cpp +41 -127
- data/vendor/faiss/faiss/IndexIVFSpectralHash.h +1 -1
- data/vendor/faiss/faiss/IndexLSH.cpp +36 -19
- data/vendor/faiss/faiss/IndexLattice.cpp +13 -13
- data/vendor/faiss/faiss/IndexNNDescent.cpp +36 -21
- data/vendor/faiss/faiss/IndexNNDescent.h +2 -2
- data/vendor/faiss/faiss/IndexNSG.cpp +39 -23
- data/vendor/faiss/faiss/IndexNeuralNetCodec.cpp +31 -11
- data/vendor/faiss/faiss/IndexPQ.cpp +128 -221
- data/vendor/faiss/faiss/IndexPQ.h +3 -2
- data/vendor/faiss/faiss/IndexPQFastScan.cpp +20 -14
- data/vendor/faiss/faiss/IndexPQFastScan.h +3 -0
- data/vendor/faiss/faiss/IndexPreTransform.cpp +25 -18
- data/vendor/faiss/faiss/IndexPreTransform.h +1 -1
- data/vendor/faiss/faiss/IndexRaBitQ.cpp +11 -36
- data/vendor/faiss/faiss/IndexRaBitQ.h +2 -1
- data/vendor/faiss/faiss/IndexRaBitQFastScan.cpp +41 -277
- data/vendor/faiss/faiss/IndexRaBitQFastScan.h +183 -27
- data/vendor/faiss/faiss/IndexRefine.cpp +30 -25
- data/vendor/faiss/faiss/IndexRefine.h +4 -4
- data/vendor/faiss/faiss/IndexReplicas.cpp +6 -6
- data/vendor/faiss/faiss/IndexRowwiseMinMax.cpp +15 -14
- data/vendor/faiss/faiss/IndexRowwiseMinMax.h +1 -1
- data/vendor/faiss/faiss/IndexScalarQuantizer.cpp +82 -14
- data/vendor/faiss/faiss/IndexShards.cpp +10 -9
- data/vendor/faiss/faiss/IndexShardsIVF.cpp +21 -15
- data/vendor/faiss/faiss/MatrixStats.cpp +5 -4
- data/vendor/faiss/faiss/MetaIndexes.cpp +19 -17
- data/vendor/faiss/faiss/MetaIndexes.h +1 -1
- data/vendor/faiss/faiss/MetricType.h +14 -7
- data/vendor/faiss/faiss/SuperKMeans.cpp +656 -0
- data/vendor/faiss/faiss/SuperKMeans.h +97 -0
- data/vendor/faiss/faiss/VectorTransform.cpp +237 -149
- data/vendor/faiss/faiss/VectorTransform.h +16 -16
- data/vendor/faiss/faiss/build.cpp +23 -0
- data/vendor/faiss/faiss/build.h +15 -0
- data/vendor/faiss/faiss/clone_index.cpp +48 -47
- data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-avx2-inl.h +47 -47
- data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-inl.h +11 -0
- data/vendor/faiss/faiss/cppcontrib/sa_decode/PQ-avx2-inl.h +38 -38
- data/vendor/faiss/faiss/cppcontrib/sa_decode/PQ-inl.h +11 -0
- data/vendor/faiss/faiss/factory_tools.cpp +5 -0
- data/vendor/faiss/faiss/gpu/GpuIndexCagra.h +6 -5
- data/vendor/faiss/faiss/gpu/GpuResources.h +1 -1
- data/vendor/faiss/faiss/gpu/StandardGpuResources.cpp +9 -9
- data/vendor/faiss/faiss/gpu/StandardGpuResources.h +4 -3
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexFlat.cpp +46 -0
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFFlat.cpp +56 -0
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFPQ.cpp +78 -1
- data/vendor/faiss/faiss/gpu/test/TestUtils.cpp +72 -0
- data/vendor/faiss/faiss/gpu/test/TestUtils.h +23 -0
- data/vendor/faiss/faiss/gpu/utils/CuvsFilterConvert.h +1 -1
- data/vendor/faiss/faiss/gpu/utils/CuvsUtils.h +21 -10
- data/vendor/faiss/faiss/gpu_metal/GpuIndexFlat.h +22 -0
- data/vendor/faiss/faiss/gpu_metal/MetalCloner.h +35 -0
- data/vendor/faiss/faiss/gpu_metal/MetalFlatKernels.h +40 -0
- data/vendor/faiss/faiss/gpu_metal/MetalIndex.h +51 -0
- data/vendor/faiss/faiss/gpu_metal/MetalIndexFlat.h +65 -0
- data/vendor/faiss/faiss/gpu_metal/MetalKernels.h +66 -0
- data/vendor/faiss/faiss/gpu_metal/MetalResources.h +79 -0
- data/vendor/faiss/faiss/gpu_metal/StandardMetalResources.h +35 -0
- data/vendor/faiss/faiss/impl/AdSampling.cpp +103 -0
- data/vendor/faiss/faiss/impl/AdSampling.h +35 -0
- data/vendor/faiss/faiss/impl/AdditiveQuantizer.cpp +29 -25
- data/vendor/faiss/faiss/impl/AdditiveQuantizer.h +1 -0
- data/vendor/faiss/faiss/impl/AuxIndexStructures.cpp +10 -9
- data/vendor/faiss/faiss/impl/AuxIndexStructures.h +3 -0
- data/vendor/faiss/faiss/impl/ClusteringHelpers.cpp +244 -0
- data/vendor/faiss/faiss/impl/ClusteringHelpers.h +94 -0
- data/vendor/faiss/faiss/impl/ClusteringInitialization.cpp +16 -16
- data/vendor/faiss/faiss/impl/CodePacker.cpp +3 -3
- data/vendor/faiss/faiss/impl/CodePackerRaBitQ.cpp +1 -1
- data/vendor/faiss/faiss/impl/DistanceComputer.h +8 -8
- data/vendor/faiss/faiss/impl/FaissAssert.h +6 -3
- data/vendor/faiss/faiss/impl/FaissException.h +50 -3
- data/vendor/faiss/faiss/impl/HNSW.cpp +92 -317
- data/vendor/faiss/faiss/impl/HNSW.h +13 -34
- data/vendor/faiss/faiss/impl/IDSelector.cpp +15 -11
- data/vendor/faiss/faiss/impl/IDSelector.h +8 -8
- data/vendor/faiss/faiss/impl/InvertedListScannerStats.h +26 -0
- data/vendor/faiss/faiss/impl/LocalSearchQuantizer.cpp +82 -77
- data/vendor/faiss/faiss/impl/NNDescent.cpp +62 -25
- data/vendor/faiss/faiss/impl/NNDescent.h +6 -2
- data/vendor/faiss/faiss/impl/NSG.cpp +38 -21
- data/vendor/faiss/faiss/impl/NSG.h +4 -4
- data/vendor/faiss/faiss/impl/Panorama.cpp +23 -6
- data/vendor/faiss/faiss/impl/Panorama.h +258 -87
- data/vendor/faiss/faiss/impl/PdxLayout.cpp +93 -0
- data/vendor/faiss/faiss/impl/PdxLayout.h +41 -0
- data/vendor/faiss/faiss/impl/PolysemousTraining.cpp +46 -32
- data/vendor/faiss/faiss/impl/PolysemousTraining.h +3 -3
- data/vendor/faiss/faiss/impl/ProductAdditiveQuantizer.cpp +35 -35
- data/vendor/faiss/faiss/impl/ProductQuantizer-inl.h +21 -16
- data/vendor/faiss/faiss/impl/ProductQuantizer.cpp +30 -23
- data/vendor/faiss/faiss/impl/Quantizer.h +2 -2
- data/vendor/faiss/faiss/impl/RaBitQUtils.cpp +55 -49
- data/vendor/faiss/faiss/impl/RaBitQUtils.h +65 -0
- data/vendor/faiss/faiss/impl/RaBitQuantizer.cpp +296 -283
- data/vendor/faiss/faiss/impl/ResidualQuantizer.cpp +26 -23
- data/vendor/faiss/faiss/impl/ResidualQuantizer.h +1 -1
- data/vendor/faiss/faiss/impl/ResultHandler.h +99 -75
- data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +52 -4
- data/vendor/faiss/faiss/impl/ScalarQuantizer.h +27 -1
- data/vendor/faiss/faiss/impl/ThreadedIndex-inl.h +14 -11
- data/vendor/faiss/faiss/impl/VisitedTable.h +7 -0
- data/vendor/faiss/faiss/impl/approx_topk/approx_topk.h +276 -0
- data/vendor/faiss/faiss/impl/approx_topk/avx2.cpp +68 -0
- data/vendor/faiss/faiss/{utils → impl}/approx_topk/generic.h +15 -8
- data/vendor/faiss/faiss/impl/approx_topk/neon.cpp +68 -0
- data/vendor/faiss/faiss/impl/approx_topk/rq_beam_search_tab-inl.h +169 -0
- data/vendor/faiss/faiss/impl/approx_topk/rq_beam_search_tab.h +117 -0
- data/vendor/faiss/faiss/impl/approx_topk/simdlib256-inl.h +146 -0
- data/vendor/faiss/faiss/impl/binary_hamming/IndexBinaryHNSW_impl.h +73 -0
- data/vendor/faiss/faiss/impl/binary_hamming/IndexBinaryHash_impl.h +270 -0
- data/vendor/faiss/faiss/impl/binary_hamming/IndexBinaryIVF_impl.h +460 -0
- data/vendor/faiss/faiss/impl/binary_hamming/IndexIVFSpectralHash_impl.h +159 -0
- data/vendor/faiss/faiss/impl/binary_hamming/IndexPQ_impl.h +92 -0
- data/vendor/faiss/faiss/impl/binary_hamming/avx2.cpp +26 -0
- data/vendor/faiss/faiss/impl/binary_hamming/avx512.cpp +26 -0
- data/vendor/faiss/faiss/impl/binary_hamming/dispatch.h +143 -0
- data/vendor/faiss/faiss/impl/binary_hamming/neon.cpp +26 -0
- data/vendor/faiss/faiss/impl/binary_hamming/rvv.cpp +26 -0
- data/vendor/faiss/faiss/impl/expanded_scanners.h +8 -3
- data/vendor/faiss/faiss/impl/{FastScanDistancePostProcessing.h → fast_scan/FastScanDistancePostProcessing.h} +13 -6
- data/vendor/faiss/faiss/impl/{LookupTableScaler.h → fast_scan/LookupTableScaler.h} +16 -5
- data/vendor/faiss/faiss/impl/fast_scan/accumulate_loops.h +237 -0
- data/vendor/faiss/faiss/impl/fast_scan/accumulate_loops_512.h +185 -0
- data/vendor/faiss/faiss/impl/fast_scan/decompose_qbs.h +229 -0
- data/vendor/faiss/faiss/impl/fast_scan/dispatching.h +268 -0
- data/vendor/faiss/faiss/impl/{pq4_fast_scan.cpp → fast_scan/fast_scan.cpp} +169 -2
- data/vendor/faiss/faiss/impl/fast_scan/fast_scan.h +341 -0
- data/vendor/faiss/faiss/impl/fast_scan/impl-avx2.cpp +36 -0
- data/vendor/faiss/faiss/impl/fast_scan/impl-avx512.cpp +40 -0
- data/vendor/faiss/faiss/impl/fast_scan/impl-neon.cpp +120 -0
- data/vendor/faiss/faiss/impl/fast_scan/impl-riscv.cpp +104 -0
- data/vendor/faiss/faiss/impl/fast_scan/kernels_simd256.h +213 -0
- data/vendor/faiss/faiss/impl/{pq4_fast_scan_search_qbs.cpp → fast_scan/kernels_simd512.h} +26 -356
- data/vendor/faiss/faiss/impl/fast_scan/rabitq_dispatching.h +90 -0
- data/vendor/faiss/faiss/impl/fast_scan/rabitq_result_handler.h +108 -0
- data/vendor/faiss/faiss/impl/{simd_result_handlers.h → fast_scan/simd_result_handlers.h} +282 -134
- data/vendor/faiss/faiss/impl/hnsw/LockVector.cpp +54 -0
- data/vendor/faiss/faiss/impl/hnsw/LockVector.h +64 -0
- data/vendor/faiss/faiss/impl/hnsw/MinimaxHeap.cpp +91 -0
- data/vendor/faiss/faiss/impl/hnsw/MinimaxHeap.h +64 -0
- data/vendor/faiss/faiss/impl/hnsw/avx2.cpp +104 -0
- data/vendor/faiss/faiss/impl/hnsw/avx512.cpp +111 -0
- data/vendor/faiss/faiss/impl/index_read.cpp +1132 -45
- data/vendor/faiss/faiss/impl/index_read_utils.h +1 -1
- data/vendor/faiss/faiss/impl/index_write.cpp +95 -13
- data/vendor/faiss/faiss/impl/io.cpp +6 -6
- data/vendor/faiss/faiss/impl/io_macros.h +33 -16
- data/vendor/faiss/faiss/impl/kmeans1d.cpp +10 -10
- data/vendor/faiss/faiss/impl/lattice_Zn.cpp +37 -23
- data/vendor/faiss/faiss/impl/lattice_Zn.h +6 -6
- data/vendor/faiss/faiss/impl/mapped_io.cpp +6 -6
- data/vendor/faiss/faiss/impl/platform_macros.h +11 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/IVFPQScanner_impl.h +549 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/IVFPQ_QueryTables.cpp +245 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/IVFPQ_QueryTables.h +105 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/PQDistanceComputer_impl.h +106 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/avx2.cpp +21 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/avx512.cpp +21 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/neon.cpp +21 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/{pq_code_distance-avx2.cpp → pq_code_distance-avx2.h} +9 -13
- data/vendor/faiss/faiss/impl/pq_code_distance/{pq_code_distance-avx512.cpp → pq_code_distance-avx512.h} +9 -57
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-generic.cpp +29 -111
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-generic.h +96 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-inl.h +238 -5
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-sve.cpp +5 -7
- data/vendor/faiss/faiss/impl/pq_code_distance/rvv.cpp +68 -0
- data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.cpp +311 -477
- data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.h +1 -1
- data/vendor/faiss/faiss/impl/scalar_quantizer/codecs.h +1 -1
- data/vendor/faiss/faiss/impl/scalar_quantizer/distance_computers.h +3 -2
- data/vendor/faiss/faiss/impl/scalar_quantizer/quantizers.h +102 -11
- data/vendor/faiss/faiss/impl/scalar_quantizer/scanners.h +27 -1
- data/vendor/faiss/faiss/impl/scalar_quantizer/similarities.h +3 -3
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx2.cpp +148 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512.cpp +167 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-dispatch.h +59 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-neon.cpp +163 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-rvv.cpp +311 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/training.cpp +192 -8
- data/vendor/faiss/faiss/impl/scalar_quantizer/training.h +12 -0
- data/vendor/faiss/faiss/impl/simd_dispatch.h +100 -66
- data/vendor/faiss/faiss/impl/simdlib/simdlib.h +57 -0
- data/vendor/faiss/faiss/{utils → impl/simdlib}/simdlib_avx2.h +264 -172
- data/vendor/faiss/faiss/impl/simdlib/simdlib_avx512.h +414 -0
- data/vendor/faiss/faiss/impl/simdlib/simdlib_dispatch.h +44 -0
- data/vendor/faiss/faiss/{utils → impl/simdlib}/simdlib_emulated.h +231 -166
- data/vendor/faiss/faiss/{utils → impl/simdlib}/simdlib_neon.h +270 -218
- data/vendor/faiss/faiss/{utils → impl/simdlib}/simdlib_ppc64.h +201 -160
- data/vendor/faiss/faiss/impl/svs_io.cpp +12 -3
- data/vendor/faiss/faiss/impl/svs_io.h +8 -2
- data/vendor/faiss/faiss/index_factory.cpp +86 -18
- data/vendor/faiss/faiss/index_io.h +24 -0
- data/vendor/faiss/faiss/invlists/BlockInvertedLists.cpp +66 -16
- data/vendor/faiss/faiss/invlists/DirectMap.cpp +24 -14
- data/vendor/faiss/faiss/invlists/DirectMap.h +4 -3
- data/vendor/faiss/faiss/invlists/InvertedLists.cpp +157 -73
- data/vendor/faiss/faiss/invlists/InvertedLists.h +86 -23
- data/vendor/faiss/faiss/invlists/InvertedListsIOHook.cpp +4 -4
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.cpp +13 -13
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.h +1 -1
- data/vendor/faiss/faiss/svs/IndexSVSFaissUtils.h +1 -1
- data/vendor/faiss/faiss/svs/IndexSVSFlat.cpp +2 -2
- data/vendor/faiss/faiss/svs/IndexSVSIVF.cpp +350 -0
- data/vendor/faiss/faiss/svs/IndexSVSIVF.h +128 -0
- data/vendor/faiss/faiss/svs/IndexSVSIVFLVQ.cpp +40 -0
- data/vendor/faiss/faiss/svs/IndexSVSIVFLVQ.h +43 -0
- data/vendor/faiss/faiss/svs/IndexSVSIVFLeanVec.cpp +225 -0
- data/vendor/faiss/faiss/svs/IndexSVSIVFLeanVec.h +71 -0
- data/vendor/faiss/faiss/svs/IndexSVSVamana.cpp +25 -1
- data/vendor/faiss/faiss/svs/IndexSVSVamana.h +18 -2
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLVQ.h +1 -1
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLeanVec.cpp +12 -3
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLeanVec.h +7 -2
- data/vendor/faiss/faiss/utils/Heap.cpp +10 -10
- data/vendor/faiss/faiss/utils/NeuralNet.cpp +47 -36
- data/vendor/faiss/faiss/utils/NeuralNet.h +1 -1
- data/vendor/faiss/faiss/utils/approx_topk_hamming/approx_topk_hamming.h +10 -4
- data/vendor/faiss/faiss/utils/distances.cpp +390 -560
- data/vendor/faiss/faiss/utils/distances.h +20 -1
- data/vendor/faiss/faiss/utils/distances_dispatch.h +117 -37
- data/vendor/faiss/faiss/utils/distances_fused/avx512.cpp +8 -7
- data/vendor/faiss/faiss/utils/distances_fused/distances_fused.cpp +33 -14
- data/vendor/faiss/faiss/utils/distances_fused/distances_fused.h +12 -1
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_based.cpp +16 -293
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_based_neon.cpp +57 -0
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_kernel-inl.h +290 -0
- data/vendor/faiss/faiss/utils/distances_simd.cpp +5 -177
- data/vendor/faiss/faiss/utils/extra_distances.cpp +9 -8
- data/vendor/faiss/faiss/utils/extra_distances.h +32 -6
- data/vendor/faiss/faiss/utils/hamming-inl.h +13 -11
- data/vendor/faiss/faiss/utils/hamming.cpp +66 -517
- data/vendor/faiss/faiss/utils/hamming.h +92 -2
- data/vendor/faiss/faiss/utils/hamming_distance/common.h +287 -10
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_avx2.cpp +15 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_avx512.cpp +15 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-avx2.h +142 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-avx512.h +234 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-generic.h +368 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-neon.h +322 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-rvv.h +39 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer.h +146 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_impl.h +481 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_neon.cpp +15 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_rvv.cpp +15 -0
- data/vendor/faiss/faiss/utils/partitioning.cpp +66 -987
- data/vendor/faiss/faiss/utils/partitioning.h +31 -0
- data/vendor/faiss/faiss/utils/popcount.h +29 -0
- data/vendor/faiss/faiss/utils/pq_code_distance.h +2 -2
- data/vendor/faiss/faiss/utils/prefetch.h +2 -2
- data/vendor/faiss/faiss/utils/quantize_lut.cpp +30 -30
- data/vendor/faiss/faiss/utils/quantize_lut.h +1 -1
- data/vendor/faiss/faiss/utils/rabitq_simd.h +57 -536
- data/vendor/faiss/faiss/utils/random.cpp +6 -6
- data/vendor/faiss/faiss/utils/simd_impl/IVFFlatScanner-inl.h +51 -0
- data/vendor/faiss/faiss/utils/simd_impl/distances_aarch64.cpp +5 -1
- data/vendor/faiss/faiss/utils/simd_impl/distances_arm_sve.cpp +213 -4
- data/vendor/faiss/faiss/utils/simd_impl/distances_autovec-inl.h +163 -10
- data/vendor/faiss/faiss/utils/simd_impl/distances_avx2.cpp +250 -4
- data/vendor/faiss/faiss/utils/simd_impl/distances_avx512.cpp +7 -4
- data/vendor/faiss/faiss/utils/simd_impl/distances_rvv.cpp +189 -0
- data/vendor/faiss/faiss/utils/simd_impl/distances_simdlib256.h +195 -0
- data/vendor/faiss/faiss/utils/simd_impl/distances_sse-inl.h +2 -1
- data/vendor/faiss/faiss/utils/{distances_fused/simdlib_based.h → simd_impl/exhaustive_L2sqr_blas_cmax.h} +5 -10
- data/vendor/faiss/faiss/utils/simd_impl/hamming_impl.h +481 -0
- data/vendor/faiss/faiss/utils/simd_impl/partitioning_avx2.cpp +14 -0
- data/vendor/faiss/faiss/utils/simd_impl/partitioning_neon.cpp +14 -0
- data/vendor/faiss/faiss/utils/simd_impl/partitioning_simdlib256.h +1085 -0
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_avx2.cpp +355 -0
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_avx512.cpp +477 -0
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_neon.cpp +55 -0
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_rvv.cpp +55 -0
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_dispatch.h +32 -0
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_kernels.h +43 -0
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_kernels_avx2.cpp +57 -0
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_kernels_avx512.cpp +45 -0
- data/vendor/faiss/faiss/utils/simd_levels.cpp +17 -5
- data/vendor/faiss/faiss/utils/simd_levels.h +93 -1
- data/vendor/faiss/faiss/utils/sorting.cpp +48 -36
- data/vendor/faiss/faiss/utils/utils.cpp +5 -5
- data/vendor/faiss/faiss/utils/utils.h +3 -3
- metadata +119 -34
- data/vendor/faiss/faiss/impl/RaBitQStats.cpp +0 -29
- data/vendor/faiss/faiss/impl/RaBitQStats.h +0 -56
- data/vendor/faiss/faiss/impl/pq4_fast_scan.h +0 -224
- data/vendor/faiss/faiss/impl/pq4_fast_scan_search_1.cpp +0 -230
- data/vendor/faiss/faiss/utils/approx_topk/approx_topk.h +0 -84
- data/vendor/faiss/faiss/utils/approx_topk/avx2-inl.h +0 -196
- data/vendor/faiss/faiss/utils/approx_topk/mode.h +0 -34
- data/vendor/faiss/faiss/utils/distances_fused/avx512.h +0 -36
- data/vendor/faiss/faiss/utils/extra_distances-inl.h +0 -235
- data/vendor/faiss/faiss/utils/hamming_distance/avx2-inl.h +0 -462
- data/vendor/faiss/faiss/utils/hamming_distance/avx512-inl.h +0 -490
- data/vendor/faiss/faiss/utils/hamming_distance/generic-inl.h +0 -449
- data/vendor/faiss/faiss/utils/hamming_distance/hamdis-inl.h +0 -87
- data/vendor/faiss/faiss/utils/hamming_distance/neon-inl.h +0 -524
- data/vendor/faiss/faiss/utils/simdlib.h +0 -42
- data/vendor/faiss/faiss/utils/simdlib_avx512.h +0 -365
- /data/ext/faiss/{utils_rb.h → utils.h} +0 -0
|
@@ -0,0 +1,245 @@
|
|
|
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/impl/pq_code_distance/IVFPQ_QueryTables.h>
|
|
9
|
+
|
|
10
|
+
#include <faiss/Clustering.h>
|
|
11
|
+
#include <faiss/utils/distances_dispatch.h>
|
|
12
|
+
|
|
13
|
+
namespace faiss {
|
|
14
|
+
namespace pq_code_distance {
|
|
15
|
+
|
|
16
|
+
QueryTables::QueryTables(
|
|
17
|
+
const IndexIVFPQ& ivfpq_in,
|
|
18
|
+
const IVFSearchParameters* params_in)
|
|
19
|
+
: ivfpq(ivfpq_in),
|
|
20
|
+
params(params_in),
|
|
21
|
+
d(ivfpq_in.d),
|
|
22
|
+
pq(ivfpq_in.pq),
|
|
23
|
+
metric_type(ivfpq_in.metric_type),
|
|
24
|
+
by_residual(ivfpq_in.by_residual),
|
|
25
|
+
use_precomputed_table(ivfpq_in.use_precomputed_table) {
|
|
26
|
+
mem.resize(pq.ksub * pq.M * 2 + d * 2);
|
|
27
|
+
sim_table = mem.data();
|
|
28
|
+
sim_table_2 = sim_table + pq.ksub * pq.M;
|
|
29
|
+
residual_vec = sim_table_2 + pq.ksub * pq.M;
|
|
30
|
+
decoded_vec = residual_vec + d;
|
|
31
|
+
|
|
32
|
+
// for polysemous
|
|
33
|
+
polysemous_ht = ivfpq_in.polysemous_ht;
|
|
34
|
+
if (auto ivfpq_params =
|
|
35
|
+
dynamic_cast<const IVFPQSearchParameters*>(params_in)) {
|
|
36
|
+
polysemous_ht = ivfpq_params->polysemous_ht;
|
|
37
|
+
}
|
|
38
|
+
if (polysemous_ht != 0) {
|
|
39
|
+
q_code.resize(pq.code_size);
|
|
40
|
+
}
|
|
41
|
+
init_list_cycles = 0;
|
|
42
|
+
sim_table_ptrs.resize(pq.M);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
void QueryTables::init_query(const float* qi_in) {
|
|
46
|
+
this->qi = qi_in;
|
|
47
|
+
if (metric_type == METRIC_INNER_PRODUCT) {
|
|
48
|
+
init_query_IP();
|
|
49
|
+
} else {
|
|
50
|
+
init_query_L2();
|
|
51
|
+
}
|
|
52
|
+
if (!by_residual && polysemous_ht != 0) {
|
|
53
|
+
pq.compute_code(qi_in, q_code.data());
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
void QueryTables::init_query_IP() {
|
|
58
|
+
// precompute some tables specific to the query qi
|
|
59
|
+
pq.compute_inner_prod_table(qi, sim_table);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
void QueryTables::init_query_L2() {
|
|
63
|
+
if (!by_residual) {
|
|
64
|
+
pq.compute_distance_table(qi, sim_table);
|
|
65
|
+
} else if (use_precomputed_table) {
|
|
66
|
+
pq.compute_inner_prod_table(qi, sim_table_2);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
float QueryTables::precompute_list_tables() {
|
|
71
|
+
float dis0 = 0;
|
|
72
|
+
uint64_t t0;
|
|
73
|
+
TIC;
|
|
74
|
+
if (by_residual) {
|
|
75
|
+
if (metric_type == METRIC_INNER_PRODUCT) {
|
|
76
|
+
dis0 = precompute_list_tables_IP();
|
|
77
|
+
} else {
|
|
78
|
+
dis0 = precompute_list_tables_L2();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
init_list_cycles += TOC;
|
|
82
|
+
return dis0;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
float QueryTables::precompute_list_table_pointers() {
|
|
86
|
+
float dis0 = 0;
|
|
87
|
+
uint64_t t0;
|
|
88
|
+
TIC;
|
|
89
|
+
if (by_residual) {
|
|
90
|
+
if (metric_type == METRIC_INNER_PRODUCT) {
|
|
91
|
+
FAISS_THROW_MSG("not implemented");
|
|
92
|
+
} else {
|
|
93
|
+
dis0 = precompute_list_table_pointers_L2();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
init_list_cycles += TOC;
|
|
97
|
+
return dis0;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
void QueryTables::init_list(idx_t list_no, float coarse_dis_in, int mode) {
|
|
101
|
+
this->key = list_no;
|
|
102
|
+
this->coarse_dis = coarse_dis_in;
|
|
103
|
+
|
|
104
|
+
if (mode == 2) {
|
|
105
|
+
dis0 = precompute_list_tables();
|
|
106
|
+
} else if (mode == 1) {
|
|
107
|
+
dis0 = precompute_list_table_pointers();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
float QueryTables::precompute_list_tables_IP() {
|
|
112
|
+
// prepare the sim_table that will be used for accumulation
|
|
113
|
+
// and dis0, the initial value
|
|
114
|
+
ivfpq.quantizer->reconstruct(key, decoded_vec);
|
|
115
|
+
// decoded_vec = centroid
|
|
116
|
+
float dis0 = fvec_inner_product_dispatch(qi, decoded_vec, d);
|
|
117
|
+
|
|
118
|
+
if (polysemous_ht) {
|
|
119
|
+
for (int i = 0; i < d; i++) {
|
|
120
|
+
residual_vec[i] = qi[i] - decoded_vec[i];
|
|
121
|
+
}
|
|
122
|
+
pq.compute_code(residual_vec, q_code.data());
|
|
123
|
+
}
|
|
124
|
+
return dis0;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
float QueryTables::precompute_list_tables_L2() {
|
|
128
|
+
float dis0 = 0;
|
|
129
|
+
|
|
130
|
+
if (use_precomputed_table == 0 || use_precomputed_table == -1) {
|
|
131
|
+
ivfpq.quantizer->compute_residual(qi, residual_vec, key);
|
|
132
|
+
pq.compute_distance_table(residual_vec, sim_table);
|
|
133
|
+
|
|
134
|
+
if (polysemous_ht != 0) {
|
|
135
|
+
pq.compute_code(residual_vec, q_code.data());
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
} else if (use_precomputed_table == 1) {
|
|
139
|
+
dis0 = coarse_dis;
|
|
140
|
+
|
|
141
|
+
fvec_madd_dispatch(
|
|
142
|
+
pq.M * pq.ksub,
|
|
143
|
+
ivfpq.precomputed_table.data() + key * pq.ksub * pq.M,
|
|
144
|
+
-2.0,
|
|
145
|
+
sim_table_2,
|
|
146
|
+
sim_table);
|
|
147
|
+
|
|
148
|
+
if (polysemous_ht != 0) {
|
|
149
|
+
ivfpq.quantizer->compute_residual(qi, residual_vec, key);
|
|
150
|
+
pq.compute_code(residual_vec, q_code.data());
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
} else if (use_precomputed_table == 2) {
|
|
154
|
+
dis0 = coarse_dis;
|
|
155
|
+
|
|
156
|
+
const MultiIndexQuantizer* miq =
|
|
157
|
+
dynamic_cast<const MultiIndexQuantizer*>(ivfpq.quantizer);
|
|
158
|
+
FAISS_THROW_IF_NOT(miq);
|
|
159
|
+
const ProductQuantizer& cpq = miq->pq;
|
|
160
|
+
size_t Mf = pq.M / cpq.M;
|
|
161
|
+
|
|
162
|
+
const float* qtab = sim_table_2; // query-specific table
|
|
163
|
+
float* ltab = sim_table; // (output) list-specific table
|
|
164
|
+
|
|
165
|
+
long k = key;
|
|
166
|
+
for (size_t cm = 0; cm < cpq.M; cm++) {
|
|
167
|
+
// compute PQ index
|
|
168
|
+
size_t ki = k & ((uint64_t(1) << cpq.nbits) - 1);
|
|
169
|
+
k >>= cpq.nbits;
|
|
170
|
+
|
|
171
|
+
// get corresponding table
|
|
172
|
+
const float* pc = ivfpq.precomputed_table.data() +
|
|
173
|
+
(ki * pq.M + cm * Mf) * pq.ksub;
|
|
174
|
+
|
|
175
|
+
if (polysemous_ht == 0) {
|
|
176
|
+
// sum up with query-specific table
|
|
177
|
+
fvec_madd_dispatch(Mf * pq.ksub, pc, -2.0, qtab, ltab);
|
|
178
|
+
ltab += Mf * pq.ksub;
|
|
179
|
+
qtab += Mf * pq.ksub;
|
|
180
|
+
} else {
|
|
181
|
+
for (size_t m = cm * Mf; m < (cm + 1) * Mf; m++) {
|
|
182
|
+
q_code[m] = fvec_madd_and_argmin_dispatch(
|
|
183
|
+
pq.ksub, pc, -2, qtab, ltab);
|
|
184
|
+
pc += pq.ksub;
|
|
185
|
+
ltab += pq.ksub;
|
|
186
|
+
qtab += pq.ksub;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return dis0;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
float QueryTables::precompute_list_table_pointers_L2() {
|
|
196
|
+
float dis0 = 0;
|
|
197
|
+
|
|
198
|
+
if (use_precomputed_table == 1) {
|
|
199
|
+
dis0 = coarse_dis;
|
|
200
|
+
|
|
201
|
+
const float* s = ivfpq.precomputed_table.data() + key * pq.ksub * pq.M;
|
|
202
|
+
for (size_t m = 0; m < pq.M; m++) {
|
|
203
|
+
sim_table_ptrs[m] = s;
|
|
204
|
+
s += pq.ksub;
|
|
205
|
+
}
|
|
206
|
+
} else if (use_precomputed_table == 2) {
|
|
207
|
+
dis0 = coarse_dis;
|
|
208
|
+
|
|
209
|
+
const MultiIndexQuantizer* miq =
|
|
210
|
+
dynamic_cast<const MultiIndexQuantizer*>(ivfpq.quantizer);
|
|
211
|
+
FAISS_THROW_IF_NOT(miq);
|
|
212
|
+
const ProductQuantizer& cpq = miq->pq;
|
|
213
|
+
size_t Mf = pq.M / cpq.M;
|
|
214
|
+
|
|
215
|
+
long k = key;
|
|
216
|
+
size_t m0 = 0;
|
|
217
|
+
for (size_t cm = 0; cm < cpq.M; cm++) {
|
|
218
|
+
size_t ki = k & ((uint64_t(1) << cpq.nbits) - 1);
|
|
219
|
+
k >>= cpq.nbits;
|
|
220
|
+
|
|
221
|
+
const float* pc = ivfpq.precomputed_table.data() +
|
|
222
|
+
(ki * pq.M + cm * Mf) * pq.ksub;
|
|
223
|
+
|
|
224
|
+
for (size_t m = m0; m < m0 + Mf; m++) {
|
|
225
|
+
sim_table_ptrs[m] = pc;
|
|
226
|
+
pc += pq.ksub;
|
|
227
|
+
}
|
|
228
|
+
m0 += Mf;
|
|
229
|
+
}
|
|
230
|
+
} else {
|
|
231
|
+
FAISS_THROW_MSG("need precomputed tables");
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (polysemous_ht) {
|
|
235
|
+
FAISS_THROW_MSG("not implemented");
|
|
236
|
+
// Not clear that it makes sense to implemente this,
|
|
237
|
+
// because it costs M * ksub, which is what we wanted to
|
|
238
|
+
// avoid with the tables pointers.
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return dis0;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
} // namespace pq_code_distance
|
|
245
|
+
} // namespace faiss
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include <cstdint>
|
|
11
|
+
#include <vector>
|
|
12
|
+
|
|
13
|
+
#include <faiss/IndexIVFPQ.h>
|
|
14
|
+
#include <faiss/impl/FaissAssert.h>
|
|
15
|
+
#include <faiss/impl/ProductQuantizer.h>
|
|
16
|
+
#include <faiss/utils/utils.h>
|
|
17
|
+
|
|
18
|
+
namespace faiss {
|
|
19
|
+
namespace pq_code_distance {
|
|
20
|
+
|
|
21
|
+
#define TIC t0 = get_cycles()
|
|
22
|
+
#define TOC get_cycles() - t0
|
|
23
|
+
|
|
24
|
+
/** QueryTables manages the various ways of searching an
|
|
25
|
+
* IndexIVFPQ. The code contains a lot of branches, depending on:
|
|
26
|
+
* - metric_type: are we computing L2 or Inner product similarity?
|
|
27
|
+
* - by_residual: do we encode raw vectors or residuals?
|
|
28
|
+
* - use_precomputed_table: are x_R|x_C tables precomputed?
|
|
29
|
+
* - polysemous_ht: are we filtering with polysemous codes?
|
|
30
|
+
*/
|
|
31
|
+
struct QueryTables {
|
|
32
|
+
/*****************************************************
|
|
33
|
+
* General data from the IVFPQ
|
|
34
|
+
*****************************************************/
|
|
35
|
+
|
|
36
|
+
const IndexIVFPQ& ivfpq;
|
|
37
|
+
const IVFSearchParameters* params;
|
|
38
|
+
|
|
39
|
+
// copied from IndexIVFPQ for easier access
|
|
40
|
+
int d;
|
|
41
|
+
const ProductQuantizer& pq;
|
|
42
|
+
MetricType metric_type;
|
|
43
|
+
bool by_residual;
|
|
44
|
+
int use_precomputed_table;
|
|
45
|
+
int polysemous_ht;
|
|
46
|
+
|
|
47
|
+
// pre-allocated data buffers
|
|
48
|
+
float *sim_table, *sim_table_2;
|
|
49
|
+
float *residual_vec, *decoded_vec;
|
|
50
|
+
|
|
51
|
+
// single data buffer
|
|
52
|
+
std::vector<float> mem;
|
|
53
|
+
|
|
54
|
+
// for table pointers
|
|
55
|
+
std::vector<const float*> sim_table_ptrs;
|
|
56
|
+
|
|
57
|
+
explicit QueryTables(
|
|
58
|
+
const IndexIVFPQ& ivfpq_in,
|
|
59
|
+
const IVFSearchParameters* params_in);
|
|
60
|
+
|
|
61
|
+
/*****************************************************
|
|
62
|
+
* What we do when query is known
|
|
63
|
+
*****************************************************/
|
|
64
|
+
|
|
65
|
+
// field specific to query
|
|
66
|
+
const float* qi = nullptr;
|
|
67
|
+
|
|
68
|
+
// query-specific initialization
|
|
69
|
+
void init_query(const float* qi_in);
|
|
70
|
+
|
|
71
|
+
void init_query_IP();
|
|
72
|
+
|
|
73
|
+
void init_query_L2();
|
|
74
|
+
|
|
75
|
+
/*****************************************************
|
|
76
|
+
* When inverted list is known: prepare computations
|
|
77
|
+
*****************************************************/
|
|
78
|
+
|
|
79
|
+
// fields specific to list
|
|
80
|
+
idx_t key = 0;
|
|
81
|
+
float coarse_dis = 0.0f;
|
|
82
|
+
std::vector<uint8_t> q_code;
|
|
83
|
+
|
|
84
|
+
uint64_t init_list_cycles;
|
|
85
|
+
|
|
86
|
+
/// once we know the query and the centroid, we can prepare the
|
|
87
|
+
/// sim_table that will be used for accumulation
|
|
88
|
+
/// and dis0, the initial value
|
|
89
|
+
float precompute_list_tables();
|
|
90
|
+
|
|
91
|
+
float precompute_list_table_pointers();
|
|
92
|
+
|
|
93
|
+
float dis0 = 0.0f;
|
|
94
|
+
|
|
95
|
+
void init_list(idx_t list_no, float coarse_dis_in, int mode);
|
|
96
|
+
|
|
97
|
+
float precompute_list_tables_IP();
|
|
98
|
+
|
|
99
|
+
float precompute_list_tables_L2();
|
|
100
|
+
|
|
101
|
+
float precompute_list_table_pointers_L2();
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
} // namespace pq_code_distance
|
|
105
|
+
} // namespace faiss
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#ifndef THE_SIMD_LEVEL
|
|
11
|
+
#error "THE_SIMD_LEVEL must be defined before including PQDistanceComputer_impl.h"
|
|
12
|
+
#endif
|
|
13
|
+
|
|
14
|
+
#include <faiss/IndexPQ.h>
|
|
15
|
+
#include <faiss/impl/DistanceComputer.h>
|
|
16
|
+
#include <faiss/impl/FaissAssert.h>
|
|
17
|
+
#include <faiss/impl/pq_code_distance/pq_code_distance-inl.h>
|
|
18
|
+
|
|
19
|
+
namespace faiss {
|
|
20
|
+
namespace pq_code_distance {
|
|
21
|
+
|
|
22
|
+
template <class PQCodeDist>
|
|
23
|
+
struct PQDistanceComputer : FlatCodesDistanceComputer {
|
|
24
|
+
using PQDecoder = typename PQCodeDist::PQDecoder;
|
|
25
|
+
size_t d;
|
|
26
|
+
MetricType metric;
|
|
27
|
+
idx_t nb;
|
|
28
|
+
const ProductQuantizer& pq;
|
|
29
|
+
const float* sdc;
|
|
30
|
+
std::vector<float> precomputed_table;
|
|
31
|
+
size_t ndis;
|
|
32
|
+
const float* q;
|
|
33
|
+
|
|
34
|
+
float distance_to_code(const uint8_t* code) final {
|
|
35
|
+
ndis++;
|
|
36
|
+
|
|
37
|
+
float dis = PQCodeDist::distance_single_code(
|
|
38
|
+
pq.M, pq.nbits, precomputed_table.data(), code);
|
|
39
|
+
return dis;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
float symmetric_dis(idx_t i, idx_t j) override {
|
|
43
|
+
FAISS_THROW_IF_NOT(sdc);
|
|
44
|
+
const float* sdci = sdc;
|
|
45
|
+
float accu = 0;
|
|
46
|
+
PQDecoder codei(codes + i * code_size, pq.nbits);
|
|
47
|
+
PQDecoder codej(codes + j * code_size, pq.nbits);
|
|
48
|
+
|
|
49
|
+
for (size_t l = 0; l < pq.M; l++) {
|
|
50
|
+
accu += sdci[codei.decode() + (codej.decode() << codei.nbits)];
|
|
51
|
+
sdci += uint64_t(1) << (2 * codei.nbits);
|
|
52
|
+
}
|
|
53
|
+
ndis++;
|
|
54
|
+
return accu;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
explicit PQDistanceComputer(const IndexPQ& storage)
|
|
58
|
+
: FlatCodesDistanceComputer(
|
|
59
|
+
storage.codes.data(),
|
|
60
|
+
storage.code_size),
|
|
61
|
+
pq(storage.pq),
|
|
62
|
+
q(nullptr) {
|
|
63
|
+
precomputed_table.resize(pq.M * pq.ksub);
|
|
64
|
+
nb = storage.ntotal;
|
|
65
|
+
d = storage.d;
|
|
66
|
+
metric = storage.metric_type;
|
|
67
|
+
if (pq.sdc_table.size() == pq.ksub * pq.ksub * pq.M) {
|
|
68
|
+
sdc = pq.sdc_table.data();
|
|
69
|
+
} else {
|
|
70
|
+
sdc = nullptr;
|
|
71
|
+
}
|
|
72
|
+
ndis = 0;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
void set_query(const float* x) override {
|
|
76
|
+
q = x;
|
|
77
|
+
if (metric == METRIC_L2) {
|
|
78
|
+
pq.compute_distance_table(x, precomputed_table.data());
|
|
79
|
+
} else {
|
|
80
|
+
pq.compute_inner_prod_table(x, precomputed_table.data());
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
template <SIMDLevel SL>
|
|
86
|
+
FlatCodesDistanceComputer* get_PQFlatCodesDistanceComputer(
|
|
87
|
+
const IndexPQ& index);
|
|
88
|
+
|
|
89
|
+
// NOLINTNEXTLINE(facebook-hte-MisplacedTemplateSpecialization)
|
|
90
|
+
template <>
|
|
91
|
+
FlatCodesDistanceComputer* get_PQFlatCodesDistanceComputer<THE_SIMD_LEVEL>(
|
|
92
|
+
const IndexPQ& index) {
|
|
93
|
+
if (index.pq.nbits == 8) {
|
|
94
|
+
return new PQDistanceComputer<
|
|
95
|
+
PQCodeDistance<PQDecoder8, THE_SIMD_LEVEL>>(index);
|
|
96
|
+
} else if (index.pq.nbits == 16) {
|
|
97
|
+
return new PQDistanceComputer<
|
|
98
|
+
PQCodeDistance<PQDecoder16, THE_SIMD_LEVEL>>(index);
|
|
99
|
+
} else {
|
|
100
|
+
return new PQDistanceComputer<
|
|
101
|
+
PQCodeDistance<PQDecoderGeneric, THE_SIMD_LEVEL>>(index);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
} // namespace pq_code_distance
|
|
106
|
+
} // namespace faiss
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
#ifdef COMPILE_SIMD_AVX2
|
|
9
|
+
|
|
10
|
+
#define THE_SIMD_LEVEL SIMDLevel::AVX2
|
|
11
|
+
|
|
12
|
+
// NOLINTNEXTLINE(facebook-hte-InlineHeader)
|
|
13
|
+
#include <faiss/impl/pq_code_distance/pq_code_distance-avx2.h>
|
|
14
|
+
// NOLINTNEXTLINE(facebook-hte-InlineHeader)
|
|
15
|
+
#include <faiss/utils/hamming_distance/hamming_computer-avx2.h>
|
|
16
|
+
// NOLINTNEXTLINE(facebook-hte-InlineHeader)
|
|
17
|
+
#include <faiss/impl/pq_code_distance/PQDistanceComputer_impl.h>
|
|
18
|
+
// NOLINTNEXTLINE(facebook-hte-InlineHeader)
|
|
19
|
+
#include <faiss/impl/pq_code_distance/IVFPQScanner_impl.h>
|
|
20
|
+
|
|
21
|
+
#endif // COMPILE_SIMD_AVX2
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
#ifdef COMPILE_SIMD_AVX512
|
|
9
|
+
|
|
10
|
+
#define THE_SIMD_LEVEL SIMDLevel::AVX512
|
|
11
|
+
|
|
12
|
+
// NOLINTNEXTLINE(facebook-hte-InlineHeader)
|
|
13
|
+
#include <faiss/impl/pq_code_distance/pq_code_distance-avx512.h>
|
|
14
|
+
// NOLINTNEXTLINE(facebook-hte-InlineHeader)
|
|
15
|
+
#include <faiss/utils/hamming_distance/hamming_computer-avx512.h>
|
|
16
|
+
// NOLINTNEXTLINE(facebook-hte-InlineHeader)
|
|
17
|
+
#include <faiss/impl/pq_code_distance/PQDistanceComputer_impl.h>
|
|
18
|
+
// NOLINTNEXTLINE(facebook-hte-InlineHeader)
|
|
19
|
+
#include <faiss/impl/pq_code_distance/IVFPQScanner_impl.h>
|
|
20
|
+
|
|
21
|
+
#endif // COMPILE_SIMD_AVX512
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
#ifdef COMPILE_SIMD_ARM_NEON
|
|
9
|
+
|
|
10
|
+
#define THE_SIMD_LEVEL SIMDLevel::ARM_NEON
|
|
11
|
+
|
|
12
|
+
// NOLINTNEXTLINE(facebook-hte-InlineHeader)
|
|
13
|
+
#include <faiss/impl/pq_code_distance/pq_code_distance-generic.h>
|
|
14
|
+
// NOLINTNEXTLINE(facebook-hte-InlineHeader)
|
|
15
|
+
#include <faiss/utils/hamming_distance/hamming_computer-neon.h>
|
|
16
|
+
// NOLINTNEXTLINE(facebook-hte-InlineHeader)
|
|
17
|
+
#include <faiss/impl/pq_code_distance/PQDistanceComputer_impl.h>
|
|
18
|
+
// NOLINTNEXTLINE(facebook-hte-InlineHeader)
|
|
19
|
+
#include <faiss/impl/pq_code_distance/IVFPQScanner_impl.h>
|
|
20
|
+
|
|
21
|
+
#endif // COMPILE_SIMD_ARM_NEON
|
data/vendor/faiss/faiss/impl/pq_code_distance/{pq_code_distance-avx2.cpp → pq_code_distance-avx2.h}
RENAMED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
#
|
|
8
|
+
#pragma once
|
|
9
9
|
|
|
10
10
|
#include <immintrin.h>
|
|
11
11
|
|
|
@@ -162,9 +162,8 @@ namespace pq_code_distance {
|
|
|
162
162
|
|
|
163
163
|
// NOLINTNEXTLINE(facebook-hte-MisplacedTemplateSpecialization)
|
|
164
164
|
template <>
|
|
165
|
-
float
|
|
165
|
+
float pq_code_distance_8bit_single_impl<SIMDLevel::AVX2>(
|
|
166
166
|
size_t M,
|
|
167
|
-
size_t nbits,
|
|
168
167
|
const float* sim_table,
|
|
169
168
|
const uint8_t* code) {
|
|
170
169
|
if (M == 4) {
|
|
@@ -223,7 +222,7 @@ float pq_code_distance_single_impl<SIMDLevel::AVX2>(
|
|
|
223
222
|
|
|
224
223
|
// Process leftovers.
|
|
225
224
|
if (m < M) {
|
|
226
|
-
PQDecoder8 decoder(code + m,
|
|
225
|
+
PQDecoder8 decoder(code + m, 8);
|
|
227
226
|
for (; m < M; m++) {
|
|
228
227
|
result += tab[decoder.decode()];
|
|
229
228
|
tab += ksub;
|
|
@@ -233,12 +232,11 @@ float pq_code_distance_single_impl<SIMDLevel::AVX2>(
|
|
|
233
232
|
return result;
|
|
234
233
|
}
|
|
235
234
|
|
|
236
|
-
// Combines 4 operations of
|
|
235
|
+
// Combines 4 operations of pq_code_distance_8bit_single_impl().
|
|
237
236
|
// NOLINTNEXTLINE(facebook-hte-MisplacedTemplateSpecialization)
|
|
238
237
|
template <>
|
|
239
|
-
void
|
|
238
|
+
void pq_code_distance_8bit_four_impl<SIMDLevel::AVX2>(
|
|
240
239
|
size_t M,
|
|
241
|
-
size_t nbits,
|
|
242
240
|
const float* sim_table,
|
|
243
241
|
const uint8_t* __restrict code0,
|
|
244
242
|
const uint8_t* __restrict code1,
|
|
@@ -341,10 +339,10 @@ void pq_code_distance_four_impl<SIMDLevel::AVX2>(
|
|
|
341
339
|
|
|
342
340
|
// Process leftovers.
|
|
343
341
|
if (m < M) {
|
|
344
|
-
PQDecoder8 decoder0(code0 + m,
|
|
345
|
-
PQDecoder8 decoder1(code1 + m,
|
|
346
|
-
PQDecoder8 decoder2(code2 + m,
|
|
347
|
-
PQDecoder8 decoder3(code3 + m,
|
|
342
|
+
PQDecoder8 decoder0(code0 + m, 8);
|
|
343
|
+
PQDecoder8 decoder1(code1 + m, 8);
|
|
344
|
+
PQDecoder8 decoder2(code2 + m, 8);
|
|
345
|
+
PQDecoder8 decoder3(code3 + m, 8);
|
|
348
346
|
for (; m < M; m++) {
|
|
349
347
|
result0 += tab[decoder0.decode()];
|
|
350
348
|
result1 += tab[decoder1.decode()];
|
|
@@ -357,5 +355,3 @@ void pq_code_distance_four_impl<SIMDLevel::AVX2>(
|
|
|
357
355
|
|
|
358
356
|
} // namespace pq_code_distance
|
|
359
357
|
} // namespace faiss
|
|
360
|
-
|
|
361
|
-
#endif // COMPILE_SIMD_AVX2
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
#
|
|
8
|
+
#pragma once
|
|
9
9
|
|
|
10
10
|
#include <immintrin.h>
|
|
11
11
|
|
|
@@ -22,9 +22,8 @@ namespace pq_code_distance {
|
|
|
22
22
|
|
|
23
23
|
// NOLINTNEXTLINE(facebook-hte-MisplacedTemplateSpecialization)
|
|
24
24
|
template <>
|
|
25
|
-
float
|
|
25
|
+
float pq_code_distance_8bit_single_impl<SIMDLevel::AVX512>(
|
|
26
26
|
size_t M,
|
|
27
|
-
size_t nbits,
|
|
28
27
|
const float* sim_table,
|
|
29
28
|
const uint8_t* code0) {
|
|
30
29
|
float result0 = 0;
|
|
@@ -69,7 +68,7 @@ float pq_code_distance_single_impl<SIMDLevel::AVX512>(
|
|
|
69
68
|
|
|
70
69
|
// Process leftovers.
|
|
71
70
|
if (m < M) {
|
|
72
|
-
PQDecoder8 decoder0(code0 + m,
|
|
71
|
+
PQDecoder8 decoder0(code0 + m, 8);
|
|
73
72
|
for (; m < M; m++) {
|
|
74
73
|
result0 += tab[decoder0.decode()];
|
|
75
74
|
tab += ksub;
|
|
@@ -79,12 +78,11 @@ float pq_code_distance_single_impl<SIMDLevel::AVX512>(
|
|
|
79
78
|
return result0;
|
|
80
79
|
}
|
|
81
80
|
|
|
82
|
-
// Combines 4 operations of
|
|
81
|
+
// Combines 4 operations of pq_code_distance_8bit_single_impl().
|
|
83
82
|
// NOLINTNEXTLINE(facebook-hte-MisplacedTemplateSpecialization)
|
|
84
83
|
template <>
|
|
85
|
-
void
|
|
84
|
+
void pq_code_distance_8bit_four_impl<SIMDLevel::AVX512>(
|
|
86
85
|
size_t M,
|
|
87
|
-
size_t nbits,
|
|
88
86
|
const float* sim_table,
|
|
89
87
|
const uint8_t* __restrict code0,
|
|
90
88
|
const uint8_t* __restrict code1,
|
|
@@ -145,10 +143,10 @@ void pq_code_distance_four_impl<SIMDLevel::AVX512>(
|
|
|
145
143
|
|
|
146
144
|
// Process leftovers.
|
|
147
145
|
if (m < M) {
|
|
148
|
-
PQDecoder8 decoder0(code0 + m,
|
|
149
|
-
PQDecoder8 decoder1(code1 + m,
|
|
150
|
-
PQDecoder8 decoder2(code2 + m,
|
|
151
|
-
PQDecoder8 decoder3(code3 + m,
|
|
146
|
+
PQDecoder8 decoder0(code0 + m, 8);
|
|
147
|
+
PQDecoder8 decoder1(code1 + m, 8);
|
|
148
|
+
PQDecoder8 decoder2(code2 + m, 8);
|
|
149
|
+
PQDecoder8 decoder3(code3 + m, 8);
|
|
152
150
|
for (; m < M; m++) {
|
|
153
151
|
result0 += tab[decoder0.decode()];
|
|
154
152
|
result1 += tab[decoder1.decode()];
|
|
@@ -159,51 +157,5 @@ void pq_code_distance_four_impl<SIMDLevel::AVX512>(
|
|
|
159
157
|
}
|
|
160
158
|
}
|
|
161
159
|
|
|
162
|
-
#ifdef COMPILE_SIMD_AVX512_SPR
|
|
163
|
-
// AVX512_SPR: Sapphire Rapids is a superset of AVX512. Reuse the
|
|
164
|
-
// AVX512 implementation until a dedicated SPR specialization is written.
|
|
165
|
-
|
|
166
|
-
// NOLINTNEXTLINE(facebook-hte-MisplacedTemplateSpecialization)
|
|
167
|
-
template <>
|
|
168
|
-
float pq_code_distance_single_impl<SIMDLevel::AVX512_SPR>(
|
|
169
|
-
size_t M,
|
|
170
|
-
size_t nbits,
|
|
171
|
-
const float* sim_table,
|
|
172
|
-
const uint8_t* code) {
|
|
173
|
-
return pq_code_distance_single_impl<SIMDLevel::AVX512>(
|
|
174
|
-
M, nbits, sim_table, code);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// NOLINTNEXTLINE(facebook-hte-MisplacedTemplateSpecialization)
|
|
178
|
-
template <>
|
|
179
|
-
void pq_code_distance_four_impl<SIMDLevel::AVX512_SPR>(
|
|
180
|
-
size_t M,
|
|
181
|
-
size_t nbits,
|
|
182
|
-
const float* sim_table,
|
|
183
|
-
const uint8_t* __restrict code0,
|
|
184
|
-
const uint8_t* __restrict code1,
|
|
185
|
-
const uint8_t* __restrict code2,
|
|
186
|
-
const uint8_t* __restrict code3,
|
|
187
|
-
float& result0,
|
|
188
|
-
float& result1,
|
|
189
|
-
float& result2,
|
|
190
|
-
float& result3) {
|
|
191
|
-
pq_code_distance_four_impl<SIMDLevel::AVX512>(
|
|
192
|
-
M,
|
|
193
|
-
nbits,
|
|
194
|
-
sim_table,
|
|
195
|
-
code0,
|
|
196
|
-
code1,
|
|
197
|
-
code2,
|
|
198
|
-
code3,
|
|
199
|
-
result0,
|
|
200
|
-
result1,
|
|
201
|
-
result2,
|
|
202
|
-
result3);
|
|
203
|
-
}
|
|
204
|
-
#endif // COMPILE_SIMD_AVX512_SPR
|
|
205
|
-
|
|
206
160
|
} // namespace pq_code_distance
|
|
207
161
|
} // namespace faiss
|
|
208
|
-
|
|
209
|
-
#endif // COMPILE_SIMD_AVX512
|