faiss 0.5.3 → 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 +12 -0
- data/ext/faiss/ext.cpp +1 -1
- data/ext/faiss/extconf.rb +4 -4
- data/ext/faiss/index.cpp +63 -45
- data/ext/faiss/index_binary.cpp +37 -27
- data/ext/faiss/kmeans.cpp +9 -8
- data/ext/faiss/pca_matrix.cpp +9 -7
- data/ext/faiss/product_quantizer.cpp +13 -11
- data/ext/faiss/utils.cpp +4 -2
- data/ext/faiss/utils.h +4 -0
- data/lib/faiss/version.rb +1 -1
- data/lib/faiss.rb +1 -1
- data/vendor/faiss/faiss/AutoTune.cpp +214 -82
- data/vendor/faiss/faiss/AutoTune.h +14 -1
- data/vendor/faiss/faiss/Clustering.cpp +97 -249
- data/vendor/faiss/faiss/Clustering.h +18 -0
- data/vendor/faiss/faiss/IVFlib.cpp +67 -44
- data/vendor/faiss/faiss/Index.cpp +25 -12
- data/vendor/faiss/faiss/Index.h +26 -4
- data/vendor/faiss/faiss/Index2Layer.cpp +37 -53
- data/vendor/faiss/faiss/IndexAdditiveQuantizer.cpp +68 -61
- data/vendor/faiss/faiss/IndexAdditiveQuantizerFastScan.cpp +36 -34
- data/vendor/faiss/faiss/IndexAdditiveQuantizerFastScan.h +4 -1
- data/vendor/faiss/faiss/IndexBinary.cpp +6 -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 +92 -95
- 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 +120 -414
- data/vendor/faiss/faiss/IndexFastScan.cpp +105 -129
- data/vendor/faiss/faiss/IndexFastScan.h +35 -24
- data/vendor/faiss/faiss/IndexFlat.cpp +216 -152
- data/vendor/faiss/faiss/IndexFlat.h +32 -14
- data/vendor/faiss/faiss/IndexFlatCodes.cpp +88 -41
- data/vendor/faiss/faiss/IndexFlatCodes.h +7 -1
- data/vendor/faiss/faiss/IndexHNSW.cpp +299 -187
- data/vendor/faiss/faiss/IndexHNSW.h +30 -14
- data/vendor/faiss/faiss/IndexIDMap.cpp +26 -22
- data/vendor/faiss/faiss/IndexIDMap.h +9 -7
- data/vendor/faiss/faiss/IndexIVF.cpp +535 -405
- data/vendor/faiss/faiss/IndexIVF.h +47 -16
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizer.cpp +77 -74
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.cpp +105 -99
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.h +6 -3
- data/vendor/faiss/faiss/IndexIVFFastScan.cpp +379 -249
- data/vendor/faiss/faiss/IndexIVFFastScan.h +65 -60
- data/vendor/faiss/faiss/IndexIVFFlat.cpp +41 -124
- data/vendor/faiss/faiss/IndexIVFFlat.h +32 -0
- data/vendor/faiss/faiss/IndexIVFFlatPanorama.cpp +89 -138
- data/vendor/faiss/faiss/IndexIVFFlatPanorama.h +3 -1
- data/vendor/faiss/faiss/IndexIVFIndependentQuantizer.cpp +18 -15
- data/vendor/faiss/faiss/IndexIVFPQ.cpp +77 -907
- data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +184 -122
- data/vendor/faiss/faiss/IndexIVFPQFastScan.h +3 -0
- data/vendor/faiss/faiss/IndexIVFPQR.cpp +23 -18
- data/vendor/faiss/faiss/IndexIVFRaBitQ.cpp +59 -60
- data/vendor/faiss/faiss/IndexIVFRaBitQ.h +4 -3
- data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.cpp +564 -416
- data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.h +269 -111
- data/vendor/faiss/faiss/IndexIVFSpectralHash.cpp +41 -127
- data/vendor/faiss/faiss/IndexIVFSpectralHash.h +1 -1
- data/vendor/faiss/faiss/IndexLSH.cpp +44 -25
- data/vendor/faiss/faiss/IndexLattice.cpp +41 -36
- data/vendor/faiss/faiss/IndexNNDescent.cpp +37 -21
- data/vendor/faiss/faiss/IndexNNDescent.h +2 -2
- data/vendor/faiss/faiss/IndexNSG.cpp +40 -23
- data/vendor/faiss/faiss/IndexNSG.h +0 -2
- data/vendor/faiss/faiss/IndexNeuralNetCodec.cpp +32 -12
- data/vendor/faiss/faiss/IndexPQ.cpp +129 -213
- 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 +31 -43
- data/vendor/faiss/faiss/IndexRaBitQ.h +4 -3
- data/vendor/faiss/faiss/IndexRaBitQFastScan.cpp +135 -317
- data/vendor/faiss/faiss/IndexRaBitQFastScan.h +192 -34
- data/vendor/faiss/faiss/IndexRefine.cpp +30 -55
- 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 +13 -13
- 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 +29 -6
- data/vendor/faiss/faiss/SuperKMeans.cpp +656 -0
- data/vendor/faiss/faiss/SuperKMeans.h +97 -0
- data/vendor/faiss/faiss/VectorTransform.cpp +349 -141
- data/vendor/faiss/faiss/VectorTransform.h +39 -16
- data/vendor/faiss/faiss/build.cpp +23 -0
- data/vendor/faiss/faiss/build.h +15 -0
- data/vendor/faiss/faiss/clone_index.cpp +55 -51
- 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/{cppcontrib/factory_tools.cpp → factory_tools.cpp} +6 -1
- data/vendor/faiss/faiss/gpu/GpuCloner.cpp +1 -1
- 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 +64 -34
- 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 -28
- 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 +367 -0
- data/vendor/faiss/faiss/impl/ClusteringInitialization.h +107 -0
- data/vendor/faiss/faiss/impl/CodePacker.cpp +7 -3
- data/vendor/faiss/faiss/impl/CodePacker.h +11 -3
- data/vendor/faiss/faiss/impl/CodePackerRaBitQ.cpp +83 -0
- data/vendor/faiss/faiss/impl/CodePackerRaBitQ.h +47 -0
- data/vendor/faiss/faiss/impl/DistanceComputer.h +8 -8
- data/vendor/faiss/faiss/impl/FaissAssert.h +64 -3
- data/vendor/faiss/faiss/impl/FaissException.h +50 -3
- data/vendor/faiss/faiss/impl/HNSW.cpp +117 -351
- data/vendor/faiss/faiss/impl/HNSW.h +21 -40
- 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 +114 -102
- data/vendor/faiss/faiss/impl/NNDescent.cpp +63 -26
- data/vendor/faiss/faiss/impl/NNDescent.h +6 -2
- data/vendor/faiss/faiss/impl/NSG.cpp +44 -26
- data/vendor/faiss/faiss/impl/NSG.h +20 -10
- data/vendor/faiss/faiss/impl/Panorama.cpp +76 -52
- data/vendor/faiss/faiss/impl/Panorama.h +265 -78
- 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 +62 -37
- 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 +99 -80
- data/vendor/faiss/faiss/impl/Quantizer.h +2 -2
- data/vendor/faiss/faiss/impl/RaBitQUtils.cpp +135 -37
- data/vendor/faiss/faiss/impl/RaBitQUtils.h +148 -21
- data/vendor/faiss/faiss/impl/RaBitQuantizer.cpp +298 -301
- data/vendor/faiss/faiss/impl/RaBitQuantizer.h +3 -10
- data/vendor/faiss/faiss/impl/RaBitQuantizerMultiBit.cpp +15 -41
- data/vendor/faiss/faiss/impl/RaBitQuantizerMultiBit.h +0 -4
- data/vendor/faiss/faiss/impl/ResidualQuantizer.cpp +40 -32
- data/vendor/faiss/faiss/impl/ResidualQuantizer.h +1 -1
- data/vendor/faiss/faiss/impl/ResultHandler.h +218 -113
- data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +119 -2362
- data/vendor/faiss/faiss/impl/ScalarQuantizer.h +27 -3
- data/vendor/faiss/faiss/impl/ThreadedIndex-inl.h +14 -11
- data/vendor/faiss/faiss/impl/VisitedTable.cpp +42 -0
- data/vendor/faiss/faiss/impl/VisitedTable.h +76 -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 +163 -0
- 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} +176 -4
- 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 -348
- 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} +290 -142
- 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 +1950 -505
- data/vendor/faiss/faiss/impl/index_read_utils.h +1 -2
- data/vendor/faiss/faiss/impl/index_write.cpp +112 -21
- 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 +81 -40
- data/vendor/faiss/faiss/impl/lattice_Zn.h +6 -6
- data/vendor/faiss/faiss/impl/mapped_io.cpp +15 -8
- 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/{code_distance/code_distance-avx2.h → pq_code_distance/pq_code_distance-avx2.h} +43 -220
- data/vendor/faiss/faiss/impl/{code_distance/code_distance-avx512.h → pq_code_distance/pq_code_distance-avx512.h} +25 -112
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-generic.cpp +59 -0
- 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 +256 -0
- data/vendor/faiss/faiss/impl/{code_distance/code_distance-sve.h → pq_code_distance/pq_code_distance-sve.cpp} +57 -146
- data/vendor/faiss/faiss/impl/pq_code_distance/rvv.cpp +68 -0
- data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.cpp +320 -483
- data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.h +1 -1
- data/vendor/faiss/faiss/impl/scalar_quantizer/codecs.h +121 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/distance_computers.h +137 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/quantizers.h +371 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/scanners.h +190 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/similarities.h +94 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx2.cpp +603 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512.cpp +597 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-dispatch.h +388 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-neon.cpp +630 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-rvv.cpp +311 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/training.cpp +387 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/training.h +54 -0
- data/vendor/faiss/faiss/impl/simd_dispatch.h +173 -0
- data/vendor/faiss/faiss/impl/simdlib/simdlib.h +57 -0
- data/vendor/faiss/faiss/{utils → impl/simdlib}/simdlib_avx2.h +274 -171
- 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 +275 -217
- 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 +115 -28
- data/vendor/faiss/faiss/index_io.h +53 -3
- data/vendor/faiss/faiss/invlists/BlockInvertedLists.cpp +73 -20
- 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 +14 -14
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.h +1 -1
- data/vendor/faiss/faiss/svs/IndexSVSFaissUtils.h +9 -19
- data/vendor/faiss/faiss/svs/IndexSVSFlat.cpp +2 -2
- data/vendor/faiss/faiss/svs/IndexSVSFlat.h +2 -0
- 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 +19 -2
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLVQ.h +1 -1
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLeanVec.cpp +19 -2
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLeanVec.h +14 -0
- data/vendor/faiss/faiss/utils/Heap.cpp +56 -10
- data/vendor/faiss/faiss/utils/Heap.h +21 -0
- data/vendor/faiss/faiss/utils/NeuralNet.cpp +54 -40
- 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 +507 -559
- data/vendor/faiss/faiss/utils/distances.h +118 -1
- data/vendor/faiss/faiss/utils/distances_dispatch.h +250 -0
- 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 +72 -3681
- data/vendor/faiss/faiss/utils/extra_distances.cpp +60 -102
- data/vendor/faiss/faiss/utils/extra_distances.h +79 -7
- 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 +251 -0
- 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 +124 -343
- 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 +154 -0
- data/vendor/faiss/faiss/utils/simd_impl/distances_arm_sve.cpp +777 -0
- data/vendor/faiss/faiss/utils/simd_impl/distances_autovec-inl.h +306 -0
- data/vendor/faiss/faiss/utils/simd_impl/distances_avx2.cpp +1431 -0
- data/vendor/faiss/faiss/utils/simd_impl/distances_avx512.cpp +1095 -0
- 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 +392 -0
- 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 +334 -0
- data/vendor/faiss/faiss/utils/simd_levels.h +183 -0
- data/vendor/faiss/faiss/utils/sorting.cpp +48 -36
- data/vendor/faiss/faiss/utils/utils.cpp +21 -14
- data/vendor/faiss/faiss/utils/utils.h +3 -3
- metadata +156 -42
- data/vendor/faiss/faiss/impl/RaBitQStats.cpp +0 -29
- data/vendor/faiss/faiss/impl/RaBitQStats.h +0 -56
- data/vendor/faiss/faiss/impl/code_distance/code_distance-generic.h +0 -81
- data/vendor/faiss/faiss/impl/code_distance/code_distance.h +0 -186
- data/vendor/faiss/faiss/impl/pq4_fast_scan.h +0 -216
- data/vendor/faiss/faiss/impl/pq4_fast_scan_search_1.cpp +0 -224
- 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 -228
- 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 -450
- 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 -296
- /data/vendor/faiss/faiss/{cppcontrib/factory_tools.h → factory_tools.h} +0 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// @lint-ignore-every LICENSELINT
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*
|
|
8
|
+
* Objective-C++ header. Runs L2/IP distance + top-k via Metal compute.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
#pragma once
|
|
12
|
+
|
|
13
|
+
#import <Metal/Metal.h>
|
|
14
|
+
|
|
15
|
+
#include <cstddef>
|
|
16
|
+
|
|
17
|
+
namespace faiss {
|
|
18
|
+
namespace gpu_metal {
|
|
19
|
+
|
|
20
|
+
/// Runs GPU search: distance matrix (L2 or IP) then top-k. Uses shared buffers
|
|
21
|
+
/// (queries, vectors, outDistances, outIndices). outIndices are int32
|
|
22
|
+
/// (0..nb-1). Maximum k supported by the GPU top-k kernel (256).
|
|
23
|
+
int getMetalFlatSearchMaxK();
|
|
24
|
+
|
|
25
|
+
/// Returns true on success; false if pipeline creation failed.
|
|
26
|
+
bool runFlatSearchGPU(
|
|
27
|
+
id<MTLDevice> device,
|
|
28
|
+
id<MTLCommandQueue> queue,
|
|
29
|
+
id<MTLBuffer> queries, // (nq * d) float, row-major
|
|
30
|
+
id<MTLBuffer> vectors, // (nb * d) float, row-major
|
|
31
|
+
int nq,
|
|
32
|
+
int nb,
|
|
33
|
+
int d,
|
|
34
|
+
int k,
|
|
35
|
+
bool isL2, // true = L2 squared, false = inner product
|
|
36
|
+
id<MTLBuffer> outDistances, // (nq * k) float
|
|
37
|
+
id<MTLBuffer> outIndices); // (nq * k) int32
|
|
38
|
+
|
|
39
|
+
} // namespace gpu_metal
|
|
40
|
+
} // namespace faiss
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// @lint-ignore-every LICENSELINT
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*
|
|
8
|
+
* Objective-C++ header (uses MetalResources).
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
#pragma once
|
|
12
|
+
|
|
13
|
+
#include <faiss/Index.h>
|
|
14
|
+
#include <faiss/gpu_metal/MetalResources.h>
|
|
15
|
+
#include <memory>
|
|
16
|
+
|
|
17
|
+
namespace faiss {
|
|
18
|
+
namespace gpu_metal {
|
|
19
|
+
|
|
20
|
+
/// Configuration for Metal index (mirrors GpuIndexConfig roles).
|
|
21
|
+
struct MetalIndexConfig {
|
|
22
|
+
int device = 0;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/// Base class for Metal-backed indexes. Mirrors faiss::gpu::GpuIndex.
|
|
26
|
+
class MetalIndex : public faiss::Index {
|
|
27
|
+
public:
|
|
28
|
+
MetalIndex(
|
|
29
|
+
std::shared_ptr<MetalResources> resources,
|
|
30
|
+
int dims,
|
|
31
|
+
faiss::MetricType metric,
|
|
32
|
+
float metricArg,
|
|
33
|
+
MetalIndexConfig config = MetalIndexConfig());
|
|
34
|
+
|
|
35
|
+
int getDevice() const {
|
|
36
|
+
return config_.device;
|
|
37
|
+
}
|
|
38
|
+
std::shared_ptr<MetalResources> getResources() {
|
|
39
|
+
return resources_;
|
|
40
|
+
}
|
|
41
|
+
std::shared_ptr<const MetalResources> getResources() const {
|
|
42
|
+
return resources_;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
protected:
|
|
46
|
+
std::shared_ptr<MetalResources> resources_;
|
|
47
|
+
MetalIndexConfig config_;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
} // namespace gpu_metal
|
|
51
|
+
} // namespace faiss
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// @lint-ignore-every LICENSELINT
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*
|
|
8
|
+
* Objective-C++ header (uses Metal types).
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
#pragma once
|
|
12
|
+
|
|
13
|
+
#import <Metal/Metal.h>
|
|
14
|
+
|
|
15
|
+
#include <faiss/Index.h>
|
|
16
|
+
#include <faiss/gpu_metal/MetalIndex.h>
|
|
17
|
+
|
|
18
|
+
namespace faiss {
|
|
19
|
+
struct IndexFlat;
|
|
20
|
+
}
|
|
21
|
+
#include <memory>
|
|
22
|
+
|
|
23
|
+
namespace faiss {
|
|
24
|
+
namespace gpu_metal {
|
|
25
|
+
|
|
26
|
+
/// Flat index that stores vectors in an MTLBuffer. Supports L2 and inner
|
|
27
|
+
/// product. Search runs on GPU via Metal compute (distance + top-k kernels).
|
|
28
|
+
class MetalIndexFlat : public MetalIndex {
|
|
29
|
+
public:
|
|
30
|
+
MetalIndexFlat(
|
|
31
|
+
std::shared_ptr<MetalResources> resources,
|
|
32
|
+
int dims,
|
|
33
|
+
faiss::MetricType metric,
|
|
34
|
+
float metricArg = 0.0f,
|
|
35
|
+
MetalIndexConfig config = MetalIndexConfig());
|
|
36
|
+
|
|
37
|
+
~MetalIndexFlat() override;
|
|
38
|
+
|
|
39
|
+
void add(idx_t n, const float* x) override;
|
|
40
|
+
void add_with_ids(idx_t n, const float* x, const idx_t* xids) override;
|
|
41
|
+
void reset() override;
|
|
42
|
+
void search(
|
|
43
|
+
idx_t n,
|
|
44
|
+
const float* x,
|
|
45
|
+
idx_t k,
|
|
46
|
+
float* distances,
|
|
47
|
+
idx_t* labels,
|
|
48
|
+
const SearchParameters* params = nullptr) const override;
|
|
49
|
+
|
|
50
|
+
/// Copy vectors to a CPU IndexFlat (e.g. for index_metal_gpu_to_cpu).
|
|
51
|
+
void copyTo(::faiss::IndexFlat* index) const;
|
|
52
|
+
|
|
53
|
+
private:
|
|
54
|
+
/// Ensures vector buffer can hold at least \p newNtotal vectors; grows
|
|
55
|
+
/// buffer if necessary.
|
|
56
|
+
void ensureCapacity(idx_t newNtotal);
|
|
57
|
+
|
|
58
|
+
/// Vector storage (row-major, ntotal * d floats). Nil when empty.
|
|
59
|
+
id<MTLBuffer> vectorsBuffer_;
|
|
60
|
+
/// Capacity of vectorsBuffer_ in number of vectors (0 if buffer is nil).
|
|
61
|
+
size_t capacityVecs_;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
} // namespace gpu_metal
|
|
65
|
+
} // namespace faiss
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// @lint-ignore-every LICENSELINT
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*
|
|
8
|
+
* MetalKernels: typed wrapper around Metal compute kernels.
|
|
9
|
+
* Owns library compilation, pipeline caching, and dispatch encoding.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
#pragma once
|
|
13
|
+
|
|
14
|
+
#import <Metal/Metal.h>
|
|
15
|
+
#include <faiss/MetricType.h>
|
|
16
|
+
#include <string>
|
|
17
|
+
#include <unordered_map>
|
|
18
|
+
|
|
19
|
+
namespace faiss {
|
|
20
|
+
namespace gpu_metal {
|
|
21
|
+
|
|
22
|
+
class MetalKernels {
|
|
23
|
+
public:
|
|
24
|
+
explicit MetalKernels(id<MTLDevice> device);
|
|
25
|
+
~MetalKernels();
|
|
26
|
+
|
|
27
|
+
bool isValid() const;
|
|
28
|
+
static constexpr int kMaxK = 256;
|
|
29
|
+
|
|
30
|
+
void encodeDistanceMatrix(
|
|
31
|
+
id<MTLComputeCommandEncoder> enc,
|
|
32
|
+
id<MTLBuffer> queries,
|
|
33
|
+
id<MTLBuffer> vectors,
|
|
34
|
+
id<MTLBuffer> distances,
|
|
35
|
+
int nq,
|
|
36
|
+
int nb,
|
|
37
|
+
int d,
|
|
38
|
+
MetricType metric);
|
|
39
|
+
|
|
40
|
+
void encodeTopKThreadgroup(
|
|
41
|
+
id<MTLComputeCommandEncoder> enc,
|
|
42
|
+
id<MTLBuffer> distances,
|
|
43
|
+
id<MTLBuffer> outDist,
|
|
44
|
+
id<MTLBuffer> outIdx,
|
|
45
|
+
int nq,
|
|
46
|
+
int nb,
|
|
47
|
+
int k,
|
|
48
|
+
bool wantMin);
|
|
49
|
+
|
|
50
|
+
static int selectTopKVariantIndex(int k);
|
|
51
|
+
|
|
52
|
+
private:
|
|
53
|
+
id<MTLComputePipelineState> pipeline(const char* name);
|
|
54
|
+
|
|
55
|
+
id<MTLDevice> device_;
|
|
56
|
+
id<MTLLibrary> library_;
|
|
57
|
+
std::unordered_map<std::string, id<MTLComputePipelineState>> cache_;
|
|
58
|
+
|
|
59
|
+
static constexpr int kTopKVariantSizes[] = {32, 64, 128, 256};
|
|
60
|
+
static constexpr int kNumTopKVariants = 4;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
MetalKernels& getMetalKernels(id<MTLDevice> device);
|
|
64
|
+
|
|
65
|
+
} // namespace gpu_metal
|
|
66
|
+
} // namespace faiss
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// @lint-ignore-every LICENSELINT
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*
|
|
8
|
+
* This header uses Objective-C types (Metal framework: id, nil, MTLDevice,
|
|
9
|
+
* etc.). For correct IDE/linter behavior, associate this file with
|
|
10
|
+
* "Objective-C++":
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
#pragma once
|
|
15
|
+
|
|
16
|
+
#import <Foundation/Foundation.h>
|
|
17
|
+
#import <Metal/Metal.h>
|
|
18
|
+
|
|
19
|
+
#include <cstddef>
|
|
20
|
+
|
|
21
|
+
namespace faiss {
|
|
22
|
+
namespace gpu_metal {
|
|
23
|
+
|
|
24
|
+
/// Allocation type for Metal buffers (mirrors faiss::gpu::AllocType roles).
|
|
25
|
+
enum MetalAllocType {
|
|
26
|
+
Other = 0,
|
|
27
|
+
FlatData = 1,
|
|
28
|
+
IVFLists = 2,
|
|
29
|
+
Quantizer = 3,
|
|
30
|
+
QuantizerPrecomputedCodes = 4,
|
|
31
|
+
TemporaryMemoryBuffer = 10,
|
|
32
|
+
TemporaryMemoryOverflow = 11,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/// Owns Metal device, command queue, and provides buffer allocation.
|
|
36
|
+
/// Mirrors the roles of faiss::gpu::GpuResources for the Metal backend.
|
|
37
|
+
class MetalResources {
|
|
38
|
+
public:
|
|
39
|
+
MetalResources();
|
|
40
|
+
~MetalResources();
|
|
41
|
+
|
|
42
|
+
MetalResources(const MetalResources&) = delete;
|
|
43
|
+
MetalResources& operator=(const MetalResources&) = delete;
|
|
44
|
+
|
|
45
|
+
/// Returns the Metal device (nil if no Metal-capable device is available).
|
|
46
|
+
id<MTLDevice> getDevice() const {
|
|
47
|
+
return device_;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/// Returns the command queue for the device (nil if device is nil).
|
|
51
|
+
id<MTLCommandQueue> getCommandQueue() const {
|
|
52
|
+
return commandQueue_;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/// Allocates a buffer of the given size (bytes). Caller owns the returned
|
|
56
|
+
/// buffer and must call deallocBuffer when done, or the buffer will leak.
|
|
57
|
+
/// Returns nil on failure (e.g. device nil or allocation failure).
|
|
58
|
+
id<MTLBuffer> allocBuffer(size_t size, MetalAllocType type);
|
|
59
|
+
|
|
60
|
+
/// Releases a buffer previously returned by allocBuffer. The caller must
|
|
61
|
+
/// not use the buffer after this call.
|
|
62
|
+
void deallocBuffer(id<MTLBuffer> buffer, MetalAllocType type);
|
|
63
|
+
|
|
64
|
+
/// Blocks until all work submitted to the default command queue has
|
|
65
|
+
/// completed.
|
|
66
|
+
void synchronize();
|
|
67
|
+
|
|
68
|
+
/// Returns true if the Metal device and queue are available.
|
|
69
|
+
bool isAvailable() const {
|
|
70
|
+
return device_ != nil && commandQueue_ != nil;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
private:
|
|
74
|
+
id<MTLDevice> device_;
|
|
75
|
+
id<MTLCommandQueue> commandQueue_;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
} // namespace gpu_metal
|
|
79
|
+
} // namespace faiss
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// @lint-ignore-every LICENSELINT
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*
|
|
8
|
+
* Mirrors the role of StandardGpuResources for the Metal backend.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
#pragma once
|
|
12
|
+
|
|
13
|
+
#include <faiss/gpu_metal/MetalResources.h>
|
|
14
|
+
#include <memory>
|
|
15
|
+
|
|
16
|
+
namespace faiss {
|
|
17
|
+
namespace gpu_metal {
|
|
18
|
+
|
|
19
|
+
/// Default Metal resources (single device). Use with index_cpu_to_metal_gpu.
|
|
20
|
+
class StandardMetalResources {
|
|
21
|
+
public:
|
|
22
|
+
StandardMetalResources();
|
|
23
|
+
std::shared_ptr<MetalResources> getResources() const {
|
|
24
|
+
return res_;
|
|
25
|
+
}
|
|
26
|
+
bool isAvailable() const {
|
|
27
|
+
return res_ && res_->isAvailable();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
private:
|
|
31
|
+
std::shared_ptr<MetalResources> res_;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
} // namespace gpu_metal
|
|
35
|
+
} // namespace faiss
|
|
@@ -0,0 +1,103 @@
|
|
|
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/AdSampling.h>
|
|
9
|
+
|
|
10
|
+
#include <cmath>
|
|
11
|
+
|
|
12
|
+
#include <faiss/impl/FaissAssert.h>
|
|
13
|
+
|
|
14
|
+
namespace faiss {
|
|
15
|
+
namespace detail {
|
|
16
|
+
|
|
17
|
+
double normal_quantile(double p) {
|
|
18
|
+
// Three-branch rational polynomial; branch breakpoint p_low = 0.02425.
|
|
19
|
+
static constexpr double a[] = {
|
|
20
|
+
-3.969683028665376e+01,
|
|
21
|
+
2.209460984245205e+02,
|
|
22
|
+
-2.759285104469687e+02,
|
|
23
|
+
1.383577518672690e+02,
|
|
24
|
+
-3.066479806614716e+01,
|
|
25
|
+
2.506628277459239e+00,
|
|
26
|
+
};
|
|
27
|
+
static constexpr double b[] = {
|
|
28
|
+
-5.447609879822406e+01,
|
|
29
|
+
1.615858368580409e+02,
|
|
30
|
+
-1.556989798598866e+02,
|
|
31
|
+
6.680131188771972e+01,
|
|
32
|
+
-1.328068155288572e+01,
|
|
33
|
+
};
|
|
34
|
+
static constexpr double c[] = {
|
|
35
|
+
-7.784894002430293e-03,
|
|
36
|
+
-3.223964580411365e-01,
|
|
37
|
+
-2.400758277161838e+00,
|
|
38
|
+
-2.549732539343734e+00,
|
|
39
|
+
4.374664141464968e+00,
|
|
40
|
+
2.938163982698783e+00,
|
|
41
|
+
};
|
|
42
|
+
static constexpr double d[] = {
|
|
43
|
+
7.784695709041462e-03,
|
|
44
|
+
3.224671290700398e-01,
|
|
45
|
+
2.445134137142996e+00,
|
|
46
|
+
3.754408661907416e+00,
|
|
47
|
+
};
|
|
48
|
+
constexpr double p_low = 0.02425;
|
|
49
|
+
constexpr double p_high = 1.0 - p_low;
|
|
50
|
+
if (p < p_low) {
|
|
51
|
+
const double q = std::sqrt(-2.0 * std::log(p));
|
|
52
|
+
return (((((c[0] * q + c[1]) * q + c[2]) * q + c[3]) * q + c[4]) * q +
|
|
53
|
+
c[5]) /
|
|
54
|
+
((((d[0] * q + d[1]) * q + d[2]) * q + d[3]) * q + 1.0);
|
|
55
|
+
} else if (p <= p_high) {
|
|
56
|
+
const double q = p - 0.5;
|
|
57
|
+
const double r = q * q;
|
|
58
|
+
return (((((a[0] * r + a[1]) * r + a[2]) * r + a[3]) * r + a[4]) * r +
|
|
59
|
+
a[5]) *
|
|
60
|
+
q /
|
|
61
|
+
(((((b[0] * r + b[1]) * r + b[2]) * r + b[3]) * r + b[4]) * r +
|
|
62
|
+
1.0);
|
|
63
|
+
} else {
|
|
64
|
+
const double q = std::sqrt(-2.0 * std::log(1.0 - p));
|
|
65
|
+
return -(((((c[0] * q + c[1]) * q + c[2]) * q + c[3]) * q + c[4]) * q +
|
|
66
|
+
c[5]) /
|
|
67
|
+
((((d[0] * q + d[1]) * q + d[2]) * q + d[3]) * q + 1.0);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
double chi2_quantile_wh(int p, double alpha) {
|
|
72
|
+
FAISS_THROW_IF_NOT(p > 0);
|
|
73
|
+
// Wilson-Hilferty cube-root approximation:
|
|
74
|
+
// ((X/p)^(1/3) - (1 - 2/(9p))) / sqrt(2/(9p)) ~ N(0,1)
|
|
75
|
+
// inverted into a quantile formula.
|
|
76
|
+
//
|
|
77
|
+
// Domain constraint: for very small alpha (< ~0.001) and small p
|
|
78
|
+
// (< 4), t can go negative, producing a negative chi-squared quantile
|
|
79
|
+
// (physically impossible). In practice this cannot happen here:
|
|
80
|
+
// precompute_ad_thresholds calls with alpha = 1 - epsilon where
|
|
81
|
+
// epsilon = ad_epsilon_factor / d, and d_prime_min >= 16, so
|
|
82
|
+
// p >= 16 and alpha >= 1 - 1/16 = 0.9375 — well inside the accurate
|
|
83
|
+
// region of the approximation.
|
|
84
|
+
const double z = normal_quantile(alpha);
|
|
85
|
+
const double t = 1.0 - 2.0 / (9.0 * p) + z * std::sqrt(2.0 / (9.0 * p));
|
|
86
|
+
return p * t * t * t;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
std::vector<float> precompute_ad_thresholds(int d, double epsilon) {
|
|
90
|
+
FAISS_THROW_IF_NOT_MSG(
|
|
91
|
+
epsilon > 0.0 && epsilon < 1.0,
|
|
92
|
+
"precompute_ad_thresholds: epsilon must be in (0, 1)");
|
|
93
|
+
FAISS_THROW_IF_NOT_MSG(
|
|
94
|
+
d > 0, "precompute_ad_thresholds: d must be positive");
|
|
95
|
+
std::vector<float> coeff(d + 1);
|
|
96
|
+
for (int p = 1; p <= d; p++) {
|
|
97
|
+
coeff[p] = static_cast<float>(chi2_quantile_wh(p, 1.0 - epsilon) / d);
|
|
98
|
+
}
|
|
99
|
+
return coeff;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
} // namespace detail
|
|
103
|
+
} // namespace faiss
|
|
@@ -0,0 +1,35 @@
|
|
|
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 <vector>
|
|
11
|
+
|
|
12
|
+
namespace faiss {
|
|
13
|
+
namespace detail {
|
|
14
|
+
|
|
15
|
+
/** Inverse standard normal CDF. Three-branch rational polynomial,
|
|
16
|
+
* absolute error < 1.15e-9 over `p in (0, 1)`. Behavior at the boundaries
|
|
17
|
+
* (p <= 0 or p >= 1) is unspecified — returns NaN or +/-inf. */
|
|
18
|
+
double normal_quantile(double p);
|
|
19
|
+
|
|
20
|
+
/** Chi-squared quantile via cube-root approximation. Validated to within
|
|
21
|
+
* 2% of scipy for `p in [16, d]` and `alpha <= 1 - 1e-6`. Accuracy
|
|
22
|
+
* degrades for smaller `p` or for `alpha` near 1. */
|
|
23
|
+
double chi2_quantile_wh(int p, double alpha);
|
|
24
|
+
|
|
25
|
+
/** Build ADSampling threshold table of size `d + 1`:
|
|
26
|
+
* coeff[p] = chi2_quantile_wh(p, 1 - epsilon) / d.
|
|
27
|
+
*
|
|
28
|
+
* Indexing: coeff[0] is reserved (left at 0.0f). coeff[1..15] are
|
|
29
|
+
* computed but NOT accuracy-bounded — callers requiring the 2% scipy
|
|
30
|
+
* tolerance must consume only coeff[16..d]. SuperKMeans enforces
|
|
31
|
+
* this via its `d_prime_min = 16` parameter. */
|
|
32
|
+
std::vector<float> precompute_ad_thresholds(int d, double epsilon);
|
|
33
|
+
|
|
34
|
+
} // namespace detail
|
|
35
|
+
} // namespace faiss
|