faiss 0.6.4 → 0.6.6
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 +9 -0
- data/ext/faiss/extconf.rb +2 -1
- data/ext/faiss/index.cpp +42 -0
- data/lib/faiss/version.rb +1 -1
- data/vendor/faiss/faiss/AutoTune.cpp +175 -0
- data/vendor/faiss/faiss/Clustering.cpp +150 -60
- data/vendor/faiss/faiss/Clustering.h +29 -0
- data/vendor/faiss/faiss/IVFlib.cpp +147 -51
- data/vendor/faiss/faiss/IVFlib.h +21 -2
- data/vendor/faiss/faiss/Index.cpp +44 -0
- data/vendor/faiss/faiss/Index.h +18 -13
- data/vendor/faiss/faiss/IndexBinary.cpp +8 -0
- data/vendor/faiss/faiss/IndexBinary.h +8 -0
- data/vendor/faiss/faiss/IndexBinaryFlat.cpp +1 -0
- data/vendor/faiss/faiss/IndexBinaryHNSW.cpp +85 -4
- data/vendor/faiss/faiss/IndexBinaryHNSW.h +19 -0
- data/vendor/faiss/faiss/IndexBinaryIVF.cpp +40 -11
- data/vendor/faiss/faiss/IndexFastScan.cpp +34 -18
- data/vendor/faiss/faiss/IndexFastScan.h +6 -3
- data/vendor/faiss/faiss/IndexFlat.cpp +57 -1
- data/vendor/faiss/faiss/IndexFlat.h +31 -0
- data/vendor/faiss/faiss/IndexFlatCodes.cpp +6 -1
- data/vendor/faiss/faiss/IndexHNSW.cpp +461 -13
- data/vendor/faiss/faiss/IndexHNSW.h +40 -5
- data/vendor/faiss/faiss/IndexIDMap.cpp +45 -0
- data/vendor/faiss/faiss/IndexIDMap.h +15 -3
- data/vendor/faiss/faiss/IndexIVF.cpp +349 -68
- data/vendor/faiss/faiss/IndexIVF.h +90 -2
- data/vendor/faiss/faiss/IndexIVFFastScan.cpp +51 -29
- data/vendor/faiss/faiss/IndexIVFFastScan.h +4 -2
- data/vendor/faiss/faiss/IndexIVFFlat.cpp +33 -0
- data/vendor/faiss/faiss/IndexIVFFlat.h +22 -6
- data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +2 -1
- data/vendor/faiss/faiss/IndexIVFRaBitQ.cpp +3 -20
- data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.cpp +78 -58
- data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.h +7 -13
- data/vendor/faiss/faiss/IndexIVFRaBitQSSD.cpp +1694 -0
- data/vendor/faiss/faiss/IndexIVFRaBitQSSD.h +288 -0
- data/vendor/faiss/faiss/IndexIVFSQFastScan.cpp +860 -0
- data/vendor/faiss/faiss/IndexIVFSQFastScan.h +145 -0
- data/vendor/faiss/faiss/IndexNNDescent.cpp +21 -3
- data/vendor/faiss/faiss/IndexPiPNN.cpp +201 -0
- data/vendor/faiss/faiss/IndexPiPNN.h +83 -0
- data/vendor/faiss/faiss/IndexRaBitQ.cpp +189 -41
- data/vendor/faiss/faiss/IndexRaBitQ.h +5 -0
- data/vendor/faiss/faiss/IndexRaBitQFastScan.cpp +7 -4
- data/vendor/faiss/faiss/IndexRaBitQFastScan.h +12 -6
- data/vendor/faiss/faiss/IndexReplicas.cpp +20 -0
- data/vendor/faiss/faiss/IndexReplicas.h +9 -0
- data/vendor/faiss/faiss/IndexSQFastScan.cpp +648 -0
- data/vendor/faiss/faiss/IndexSQFastScan.h +129 -0
- data/vendor/faiss/faiss/IndexShards.cpp +10 -0
- data/vendor/faiss/faiss/IndexShards.h +5 -0
- data/vendor/faiss/faiss/SuperKMeans.cpp +59 -17
- data/vendor/faiss/faiss/SuperKMeans.h +9 -4
- data/vendor/faiss/faiss/VectorTransform.cpp +159 -11
- data/vendor/faiss/faiss/VectorTransform.h +24 -1
- data/vendor/faiss/faiss/clone_index.cpp +24 -0
- data/vendor/faiss/faiss/factory_tools.cpp +19 -1
- data/vendor/faiss/faiss/gpu/Dataset.h +164 -0
- data/vendor/faiss/faiss/gpu/GpuCloner.cpp +16 -13
- data/vendor/faiss/faiss/gpu/GpuCloner.h +4 -0
- data/vendor/faiss/faiss/gpu/GpuClonerOptions.h +3 -0
- data/vendor/faiss/faiss/gpu/GpuIndex.h +4 -13
- data/vendor/faiss/faiss/gpu/GpuIndexBinaryCagra.h +32 -13
- data/vendor/faiss/faiss/gpu/GpuIndexCagra.h +51 -22
- data/vendor/faiss/faiss/gpu/GpuIndexFlat.h +11 -0
- data/vendor/faiss/faiss/gpu/GpuIndexIVF.h +6 -0
- data/vendor/faiss/faiss/gpu/impl/optimal_kmeans/GpuOptimalKMeans.h +184 -0
- data/vendor/faiss/faiss/gpu/test/TestCodePacking.cpp +12 -4
- data/vendor/faiss/faiss/gpu/test/TestGpuDatasetHeader.cpp +18 -0
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexFlat.cpp +215 -0
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFFlat.cpp +98 -0
- data/vendor/faiss/faiss/gpu/test/TestUtils.cpp +6 -5
- data/vendor/faiss/faiss/gpu/utils/DeviceUtils.h +11 -0
- data/vendor/faiss/faiss/gpu/utils/StackDeviceMemory.cpp +1 -1
- data/vendor/faiss/faiss/gpu_metal/GpuIndexFlat.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalCloner.h +12 -1
- data/vendor/faiss/faiss/gpu_metal/MetalDistance.h +93 -1
- data/vendor/faiss/faiss/gpu_metal/MetalFlatKernels.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalIndex.h +5 -1
- data/vendor/faiss/faiss/gpu_metal/MetalIndexBinaryFlat.h +69 -0
- data/vendor/faiss/faiss/gpu_metal/MetalIndexFlat.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalIndexIVFFlat.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalIndexIVFPQ.h +39 -1
- data/vendor/faiss/faiss/gpu_metal/MetalKernels.h +107 -1
- data/vendor/faiss/faiss/gpu_metal/MetalPythonBridge.h +11 -1
- data/vendor/faiss/faiss/gpu_metal/MetalResources.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/StandardMetalResources.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/impl/MetalIVFFlat.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/impl/MetalIVFPQ.h +1 -1
- data/vendor/faiss/faiss/impl/AuxIndexStructures.cpp +3 -1
- data/vendor/faiss/faiss/impl/AuxIndexStructures.h +1 -6
- data/vendor/faiss/faiss/impl/ClusteringHelpers.cpp +134 -45
- data/vendor/faiss/faiss/impl/ClusteringHelpers.h +36 -0
- data/vendor/faiss/faiss/impl/ClusteringInitialization.cpp +267 -136
- data/vendor/faiss/faiss/impl/ClusteringInitialization.h +0 -15
- data/vendor/faiss/faiss/impl/CodePacker.cpp +2 -2
- data/vendor/faiss/faiss/impl/CodePackerRaBitQ.cpp +2 -2
- data/vendor/faiss/faiss/impl/DeterministicNNDescent.cpp +2167 -0
- data/vendor/faiss/faiss/impl/DeterministicNNDescent.h +301 -0
- data/vendor/faiss/faiss/impl/DistanceComputer.cpp +63 -0
- data/vendor/faiss/faiss/impl/DistanceComputer.h +3 -29
- data/vendor/faiss/faiss/impl/HNSW.cpp +48 -12
- data/vendor/faiss/faiss/impl/HNSW.h +74 -2
- data/vendor/faiss/faiss/impl/IDSelector.h +5 -4
- data/vendor/faiss/faiss/impl/LocalSearchQuantizer.cpp +6 -19
- data/vendor/faiss/faiss/impl/NNDescent.cpp +2 -1
- data/vendor/faiss/faiss/impl/NNDescent.h +4 -0
- data/vendor/faiss/faiss/impl/NSG.cpp +3 -2
- data/vendor/faiss/faiss/impl/Panorama.h +3 -2
- data/vendor/faiss/faiss/impl/PiPNN.cpp +824 -0
- data/vendor/faiss/faiss/impl/PiPNN.h +122 -0
- data/vendor/faiss/faiss/impl/PolysemousTraining.cpp +1 -1
- data/vendor/faiss/faiss/impl/ProductQuantizer.cpp +54 -11
- data/vendor/faiss/faiss/impl/RaBitQUtils.cpp +0 -2
- data/vendor/faiss/faiss/impl/RaBitQUtils.h +30 -1
- data/vendor/faiss/faiss/impl/RaBitQuantizer.cpp +91 -66
- data/vendor/faiss/faiss/impl/RaBitQuantizer.h +15 -0
- data/vendor/faiss/faiss/impl/ResultHandler.h +116 -0
- data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +29 -0
- data/vendor/faiss/faiss/impl/ScalarQuantizer.h +1 -6
- data/vendor/faiss/faiss/impl/approx_topk/avx2.cpp +0 -4
- data/vendor/faiss/faiss/impl/approx_topk/neon.cpp +0 -4
- data/vendor/faiss/faiss/impl/binary_hamming/IndexBinaryHash_impl.h +5 -2
- data/vendor/faiss/faiss/impl/binary_hamming/IndexBinaryIVF_impl.h +1 -3
- data/vendor/faiss/faiss/impl/binary_hamming/avx2.cpp +0 -4
- data/vendor/faiss/faiss/impl/binary_hamming/avx512.cpp +0 -4
- data/vendor/faiss/faiss/impl/binary_hamming/neon.cpp +0 -4
- data/vendor/faiss/faiss/impl/binary_hamming/rvv.cpp +0 -4
- data/vendor/faiss/faiss/impl/expanded_scanners.h +93 -0
- data/vendor/faiss/faiss/impl/fast_scan/FastScanDistancePostProcessing.h +4 -0
- data/vendor/faiss/faiss/impl/fast_scan/accumulate_loops.h +61 -64
- data/vendor/faiss/faiss/impl/fast_scan/accumulate_loops_512.h +13 -14
- data/vendor/faiss/faiss/impl/fast_scan/decompose_qbs.h +17 -129
- data/vendor/faiss/faiss/impl/fast_scan/dispatching.h +25 -19
- data/vendor/faiss/faiss/impl/fast_scan/fast_scan.cpp +73 -6
- data/vendor/faiss/faiss/impl/fast_scan/fast_scan.h +43 -0
- data/vendor/faiss/faiss/impl/fast_scan/impl-avx2.cpp +15 -4
- data/vendor/faiss/faiss/impl/fast_scan/impl-avx512.cpp +115 -4
- data/vendor/faiss/faiss/impl/fast_scan/impl-neon.cpp +10 -85
- data/vendor/faiss/faiss/impl/fast_scan/impl-riscv.cpp +0 -4
- data/vendor/faiss/faiss/impl/fast_scan/kernels_neon.h +155 -0
- data/vendor/faiss/faiss/impl/fast_scan/kernels_simd256.h +106 -1
- data/vendor/faiss/faiss/impl/fast_scan/kernels_simd512.h +3 -6
- data/vendor/faiss/faiss/impl/fast_scan/rabitq_result_handler.h +0 -1
- data/vendor/faiss/faiss/impl/fast_scan/simd_result_handlers.h +105 -78
- data/vendor/faiss/faiss/impl/hnsw/LockVector.h +1 -2
- data/vendor/faiss/faiss/impl/hnsw/avx2.cpp +0 -4
- data/vendor/faiss/faiss/impl/hnsw/avx512.cpp +0 -4
- data/vendor/faiss/faiss/impl/index_read.cpp +318 -9
- data/vendor/faiss/faiss/impl/index_write.cpp +124 -5
- data/vendor/faiss/faiss/impl/io.cpp +1 -0
- data/vendor/faiss/faiss/impl/io_macros.h +2 -2
- data/vendor/faiss/faiss/impl/mapped_io.cpp +3 -1
- data/vendor/faiss/faiss/impl/maybe_owned_vector.h +78 -41
- data/vendor/faiss/faiss/impl/nndescent/gram-avx2.cpp +121 -0
- data/vendor/faiss/faiss/impl/nndescent/gram-avx512.cpp +124 -0
- data/vendor/faiss/faiss/impl/nndescent/gram-neon.cpp +114 -0
- data/vendor/faiss/faiss/impl/nndescent/gram.h +66 -0
- data/vendor/faiss/faiss/impl/optimal_kmeans/BlockCombiner-avx512.cpp +431 -0
- data/vendor/faiss/faiss/impl/optimal_kmeans/BlockCombiner-inl.h +1157 -0
- data/vendor/faiss/faiss/impl/optimal_kmeans/OptimalKMeans.cpp +282 -0
- data/vendor/faiss/faiss/impl/optimal_kmeans/OptimalKMeans.h +226 -0
- data/vendor/faiss/faiss/impl/optimal_kmeans/OptimalKMeansCompressed.cpp +1567 -0
- data/vendor/faiss/faiss/impl/optimal_kmeans/OptimalKMeansCompressed.h +281 -0
- data/vendor/faiss/faiss/impl/pipnn/HashPrune.cpp +159 -0
- data/vendor/faiss/faiss/impl/pipnn/HashPrune.h +69 -0
- data/vendor/faiss/faiss/impl/pipnn/Partition.cpp +587 -0
- data/vendor/faiss/faiss/impl/pipnn/Partition.h +93 -0
- data/vendor/faiss/faiss/impl/pipnn/kernels.cpp +326 -0
- data/vendor/faiss/faiss/impl/pipnn/kernels.h +92 -0
- data/vendor/faiss/faiss/impl/platform_macros.h +91 -27
- data/vendor/faiss/faiss/impl/polysemous_training/avx512.cpp +0 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/IVFPQScanner_impl.h +84 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/IVFPQ_QueryTables.cpp +17 -17
- data/vendor/faiss/faiss/impl/pq_code_distance/PQDistanceComputer_impl.h +6 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/avx2.cpp +0 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/avx512.cpp +0 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/neon.cpp +0 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-avx2.h +4 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-avx512.h +4 -1
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-generic.cpp +19 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-generic.h +6 -6
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-inl.h +131 -6
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-sve.cpp +0 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_rvv_kernel.h +89 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_scan_impl.h +21 -10
- data/vendor/faiss/faiss/impl/pq_code_distance/rvv.cpp +45 -18
- data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.cpp +2 -1
- data/vendor/faiss/faiss/impl/result_handler/ResultHandler.cpp +68 -1
- data/vendor/faiss/faiss/impl/result_handler/avx2.cpp +70 -6
- data/vendor/faiss/faiss/impl/result_handler/avx512.cpp +2 -5
- data/vendor/faiss/faiss/impl/scalar_quantizer/EDENQuantizer-avx2.cpp +0 -4
- data/vendor/faiss/faiss/impl/scalar_quantizer/EDENQuantizer-avx512.cpp +0 -4
- data/vendor/faiss/faiss/impl/scalar_quantizer/EDENQuantizer.cpp +1 -1
- data/vendor/faiss/faiss/impl/scalar_quantizer/distance_computers.h +5 -1
- data/vendor/faiss/faiss/impl/scalar_quantizer/quantizers.h +28 -52
- data/vendor/faiss/faiss/impl/scalar_quantizer/scanners.h +85 -37
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx2.cpp +262 -110
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512-impl.h +503 -122
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512-spr.cpp +10 -155
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512.cpp +7 -701
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-dispatch.h +66 -57
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-neon.cpp +133 -127
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-rvv.cpp +3185 -144
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq8_coefficients.h +48 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq8_rvv_kernel.h +546 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/training.cpp +2 -2
- data/vendor/faiss/faiss/impl/simd_dispatch.h +7 -0
- data/vendor/faiss/faiss/impl/simdlib/simdlib_avx2.h +14 -0
- data/vendor/faiss/faiss/impl/simdlib/simdlib_avx512.h +20 -20
- data/vendor/faiss/faiss/impl/simdlib/simdlib_dispatch.h +7 -8
- data/vendor/faiss/faiss/impl/simdlib/simdlib_neon.h +4 -4
- data/vendor/faiss/faiss/impl/sq_fastscan_utils.h +232 -0
- data/vendor/faiss/faiss/impl/zerocopy_io.cpp +2 -1
- data/vendor/faiss/faiss/index_factory.cpp +106 -6
- data/vendor/faiss/faiss/invlists/DirectMap.cpp +1 -1
- data/vendor/faiss/faiss/invlists/DiskIOBackend.cpp +121 -0
- data/vendor/faiss/faiss/invlists/DiskIOBackend.h +71 -0
- data/vendor/faiss/faiss/invlists/InvertedLists.cpp +15 -10
- data/vendor/faiss/faiss/invlists/InvertedListsIOHook.cpp +26 -0
- data/vendor/faiss/faiss/invlists/InvertedListsIOHook.h +5 -0
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.cpp +9 -24
- data/vendor/faiss/faiss/invlists/RaBitQSSDInvertedLists.cpp +751 -0
- data/vendor/faiss/faiss/invlists/RaBitQSSDInvertedLists.h +224 -0
- data/vendor/faiss/faiss/svs/IndexSVSFaissUtils.h +2 -7
- data/vendor/faiss/faiss/svs/IndexSVSFlat.cpp +1 -1
- data/vendor/faiss/faiss/svs/IndexSVSIVF.cpp +2 -2
- data/vendor/faiss/faiss/svs/IndexSVSVamana.cpp +4 -4
- data/vendor/faiss/faiss/svs/IndexSVSVamana.h +3 -2
- data/vendor/faiss/faiss/utils/AlignedTable.h +6 -1
- data/vendor/faiss/faiss/utils/Heap.cpp +4 -3
- data/vendor/faiss/faiss/utils/WorkerThread.h +0 -1
- data/vendor/faiss/faiss/utils/approx_topk_hamming/approx_topk_hamming.h +16 -5
- data/vendor/faiss/faiss/utils/bf16.h +36 -0
- data/vendor/faiss/faiss/utils/distances.cpp +466 -43
- data/vendor/faiss/faiss/utils/distances.h +179 -2
- data/vendor/faiss/faiss/utils/distances_dispatch.h +6 -4
- data/vendor/faiss/faiss/utils/distances_fused/avx512.cpp +2 -5
- data/vendor/faiss/faiss/utils/distances_fused/distances_fused.cpp +0 -14
- data/vendor/faiss/faiss/utils/distances_fused/rvv.cpp +25 -0
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_based.cpp +0 -4
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_based_neon.cpp +0 -4
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_kernel-inl.h +2 -1
- data/vendor/faiss/faiss/utils/distances_simd.cpp +9 -0
- data/vendor/faiss/faiss/utils/extra_distances.h +2 -1
- data/vendor/faiss/faiss/utils/fp16-fp16c.h +4 -0
- data/vendor/faiss/faiss/utils/fp16-inl.h +26 -52
- data/vendor/faiss/faiss/utils/hamming-inl.h +3 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_avx2.cpp +0 -4
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_avx512.cpp +0 -4
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_avx512_vpopcnt.cpp +0 -4
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-avx512.h +33 -5
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-avx512_vpopcnt.h +15 -30
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-neon.h +0 -4
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_impl.h +2 -1
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_neon.cpp +0 -4
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_rvv.cpp +0 -4
- data/vendor/faiss/faiss/utils/partitioning.cpp +2 -2
- data/vendor/faiss/faiss/utils/pq_code_distance.h +8 -4
- data/vendor/faiss/faiss/utils/prefetch.h +1 -26
- data/vendor/faiss/faiss/utils/quantize_lut.cpp +26 -27
- data/vendor/faiss/faiss/utils/quantize_lut.h +11 -0
- data/vendor/faiss/faiss/utils/rabitq_simd.h +171 -22
- data/vendor/faiss/faiss/utils/simd_impl/distances_aarch64.cpp +9 -4
- data/vendor/faiss/faiss/utils/simd_impl/distances_arm_sve.cpp +81 -9
- data/vendor/faiss/faiss/utils/simd_impl/distances_autovec-inl.h +7 -3
- data/vendor/faiss/faiss/utils/simd_impl/distances_avx2.cpp +108 -9
- data/vendor/faiss/faiss/utils/simd_impl/distances_avx512.cpp +111 -12
- data/vendor/faiss/faiss/utils/simd_impl/distances_rvv.cpp +353 -71
- data/vendor/faiss/faiss/utils/simd_impl/distances_rvv_kernel.h +68 -0
- data/vendor/faiss/faiss/utils/simd_impl/distances_simdlib256.h +3 -3
- data/vendor/faiss/faiss/utils/simd_impl/exhaustive_L2sqr_blas_cmax.h +106 -0
- data/vendor/faiss/faiss/utils/simd_impl/fp16_kernels.h +76 -0
- data/vendor/faiss/faiss/utils/simd_impl/fp16_kernels_avx2.cpp +52 -0
- data/vendor/faiss/faiss/utils/simd_impl/fp16_kernels_avx512.cpp +52 -0
- data/vendor/faiss/faiss/utils/simd_impl/fp16_kernels_neon.cpp +48 -0
- data/vendor/faiss/faiss/utils/simd_impl/masked_sum-avx2.h +44 -0
- data/vendor/faiss/faiss/utils/simd_impl/masked_sum-avx512.h +43 -0
- data/vendor/faiss/faiss/utils/simd_impl/masked_sum.h +38 -0
- data/vendor/faiss/faiss/utils/simd_impl/partitioning_avx2.cpp +0 -4
- data/vendor/faiss/faiss/utils/simd_impl/partitioning_neon.cpp +0 -4
- data/vendor/faiss/faiss/utils/simd_impl/partitioning_simdlib256.h +16 -15
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_avx2.cpp +185 -51
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_avx512.cpp +194 -66
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_avx512_vpopcnt.cpp +51 -14
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_neon.cpp +297 -10
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_rvv.cpp +0 -4
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_kernels_avx2.cpp +0 -4
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_kernels_avx512.cpp +0 -4
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_kernels_sve.cpp +0 -4
- data/vendor/faiss/faiss/utils/simd_levels.cpp +22 -6
- data/vendor/faiss/faiss/utils/simd_levels.h +74 -1
- data/vendor/faiss/faiss/utils/sorting.cpp +6 -5
- data/vendor/faiss/faiss/utils/transpose/transpose-avx2-inl.h +0 -4
- data/vendor/faiss/faiss/utils/transpose/transpose-avx512-inl.h +0 -4
- data/vendor/faiss/faiss/utils/utils.cpp +84 -0
- data/vendor/faiss/faiss/utils/utils.h +24 -0
- metadata +52 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @lint-ignore-every LICENSELINT
|
|
2
2
|
/**
|
|
3
|
-
* Copyright (c) Meta Platforms, Inc. and
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -83,5 +83,97 @@ bool runMetalIVFFlatFullSearch(
|
|
|
83
83
|
bool centroidsAreFP16 = false,
|
|
84
84
|
bool waitForCompletion = true);
|
|
85
85
|
|
|
86
|
+
/// Full IVF-PQ search on the GPU: builds per-(query, probe) PQ lookup tables,
|
|
87
|
+
/// scans the assigned inverted lists with 8-bit ADC, and merges the per-list
|
|
88
|
+
/// top-k into the final top-k. Coarse quantization is performed on the CPU and
|
|
89
|
+
/// the assignments are passed in via @p coarseAssign. @p coarseDist carries
|
|
90
|
+
/// the per-(query, probe) coarse scores, added for inner product (the IP
|
|
91
|
+
/// tables hold <q_m, pq_m> only); unused for L2.
|
|
92
|
+
bool runMetalIVFPQFullSearch(
|
|
93
|
+
id<MTLDevice> device,
|
|
94
|
+
id<MTLCommandQueue> queue,
|
|
95
|
+
id<MTLBuffer> queries,
|
|
96
|
+
id<MTLBuffer> coarseAssign,
|
|
97
|
+
id<MTLBuffer> coarseDist,
|
|
98
|
+
id<MTLBuffer> coarseCentroids,
|
|
99
|
+
id<MTLBuffer> pqCentroids,
|
|
100
|
+
id<MTLBuffer> lookupTable,
|
|
101
|
+
id<MTLBuffer> codes,
|
|
102
|
+
id<MTLBuffer> ids,
|
|
103
|
+
id<MTLBuffer> listOffset,
|
|
104
|
+
id<MTLBuffer> listLength,
|
|
105
|
+
int nq,
|
|
106
|
+
int d,
|
|
107
|
+
int M,
|
|
108
|
+
int k,
|
|
109
|
+
int nprobe,
|
|
110
|
+
int nlist,
|
|
111
|
+
int avgListLen,
|
|
112
|
+
bool lookupFp16,
|
|
113
|
+
bool isL2,
|
|
114
|
+
id<MTLBuffer> outDistances,
|
|
115
|
+
id<MTLBuffer> outIndices,
|
|
116
|
+
id<MTLBuffer> perListDistBuf,
|
|
117
|
+
id<MTLBuffer> perListIdxBuf,
|
|
118
|
+
bool waitForCompletion = true);
|
|
119
|
+
|
|
120
|
+
/// Build the query-independent precomputed term of the IVFPQ L2 distance
|
|
121
|
+
/// decomposition on the GPU: term2[l][m][c] = ||pq[m][c]||^2 +
|
|
122
|
+
/// 2 <coarse_l[m], pq[m][c]>, laid out as nlist * M * 256 floats. Run once
|
|
123
|
+
/// per trained index; consumed by runMetalIVFPQPrecompSearch.
|
|
124
|
+
bool runMetalIVFPQPrecomputeTerm2(
|
|
125
|
+
id<MTLDevice> device,
|
|
126
|
+
id<MTLCommandQueue> queue,
|
|
127
|
+
id<MTLBuffer> coarseCentroids,
|
|
128
|
+
id<MTLBuffer> pqCentroids,
|
|
129
|
+
id<MTLBuffer> outTerm2,
|
|
130
|
+
int nlist,
|
|
131
|
+
int d,
|
|
132
|
+
int M);
|
|
133
|
+
|
|
134
|
+
/// IVF-PQ search using the precomputed-table decomposition: a per-query
|
|
135
|
+
/// M*256 term is built once per batch (instead of a full residual LUT per
|
|
136
|
+
/// (query, probe)), combined with @p term2 in threadgroup memory by the scan
|
|
137
|
+
/// kernel, and the coarse distance is added as the constant ||x - c||^2 term.
|
|
138
|
+
/// The scan keeps an exact running top-k over arbitrarily long lists and the
|
|
139
|
+
/// merge runs in rounds, so there is no list-length or nprobe*k cap; the
|
|
140
|
+
/// remaining requirements are k <= 512, M <= 64 and d/M <= 256.
|
|
141
|
+
/// onTheFly evaluates encountered codes directly (d <= 256), using the
|
|
142
|
+
/// supplied coarse centroids; shortLists requires every list to have <= 128
|
|
143
|
+
/// entries and selects a smaller threadgroup and scratch allocation.
|
|
144
|
+
/// @p term2 may be nil for inner product (qterm is the whole table);
|
|
145
|
+
/// @p useDis0 adds the coarse distance (required for L2, by_residual for IP).
|
|
146
|
+
bool runMetalIVFPQPrecompSearch(
|
|
147
|
+
id<MTLDevice> device,
|
|
148
|
+
id<MTLCommandQueue> queue,
|
|
149
|
+
id<MTLBuffer> queries,
|
|
150
|
+
id<MTLBuffer> coarseAssign,
|
|
151
|
+
id<MTLBuffer> coarseDist,
|
|
152
|
+
id<MTLBuffer> term2,
|
|
153
|
+
id<MTLBuffer> qtermScratch,
|
|
154
|
+
id<MTLBuffer> pqCentroids,
|
|
155
|
+
id<MTLBuffer> codes,
|
|
156
|
+
id<MTLBuffer> ids,
|
|
157
|
+
id<MTLBuffer> listOffset,
|
|
158
|
+
id<MTLBuffer> listLength,
|
|
159
|
+
int nq,
|
|
160
|
+
int d,
|
|
161
|
+
int M,
|
|
162
|
+
int k,
|
|
163
|
+
int nprobe,
|
|
164
|
+
bool isL2,
|
|
165
|
+
bool useDis0,
|
|
166
|
+
id<MTLBuffer> outDistances,
|
|
167
|
+
id<MTLBuffer> outIndices,
|
|
168
|
+
id<MTLBuffer> perListDistBuf,
|
|
169
|
+
id<MTLBuffer> perListIdxBuf,
|
|
170
|
+
id<MTLBuffer> mergeScratchDistBuf,
|
|
171
|
+
id<MTLBuffer> mergeScratchIdxBuf,
|
|
172
|
+
bool waitForCompletion = true,
|
|
173
|
+
id<MTLBuffer> coarseCentroids = nil,
|
|
174
|
+
bool onTheFly = false,
|
|
175
|
+
bool shortLists = false,
|
|
176
|
+
bool compactMerge = true);
|
|
177
|
+
|
|
86
178
|
} // namespace gpu_metal
|
|
87
179
|
} // namespace faiss
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @lint-ignore-every LICENSELINT
|
|
2
2
|
/**
|
|
3
|
-
* Copyright (c) Meta Platforms, Inc. and
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @lint-ignore-every LICENSELINT
|
|
2
2
|
/**
|
|
3
|
-
* Copyright (c) Meta Platforms, Inc. and
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -24,6 +24,10 @@ struct MetalIndexConfig {
|
|
|
24
24
|
|
|
25
25
|
bool useFloat16CoarseQuantizer = false;
|
|
26
26
|
|
|
27
|
+
/// Build the IVF-PQ distance lookup tables in half precision. Halves LUT
|
|
28
|
+
/// bandwidth during the GPU scan at a small accuracy cost.
|
|
29
|
+
bool useFloat16 = false;
|
|
30
|
+
|
|
27
31
|
faiss::gpu::IndicesOptions indicesOptions = faiss::gpu::INDICES_64_BIT;
|
|
28
32
|
|
|
29
33
|
bool interleavedLayout = true;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// @lint-ignore-every LICENSELINT
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and 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
|
+
|
|
9
|
+
#pragma once
|
|
10
|
+
|
|
11
|
+
#include <faiss/IndexBinaryFlat.h>
|
|
12
|
+
#include <faiss/gpu_metal/MetalResources.h>
|
|
13
|
+
#include <memory>
|
|
14
|
+
|
|
15
|
+
namespace faiss {
|
|
16
|
+
namespace gpu_metal {
|
|
17
|
+
|
|
18
|
+
/// Exhaustive Hamming search over GPU-resident binary vectors.
|
|
19
|
+
/// Every positive dimension divisible by 8 is supported. GPU search is exact
|
|
20
|
+
/// for k <= 512, with ties ordered by increasing label. Larger k, selectors,
|
|
21
|
+
/// and counts exceeding uint32_t use the CPU copy. GPU failures throw rather
|
|
22
|
+
/// than silently falling back. Range search and remove_ids are not supported.
|
|
23
|
+
/// As with other Metal indexes, callers must serialize mutation and search.
|
|
24
|
+
class MetalIndexBinaryFlat : public faiss::IndexBinary {
|
|
25
|
+
public:
|
|
26
|
+
static constexpr int kMaxGpuK = 512;
|
|
27
|
+
|
|
28
|
+
MetalIndexBinaryFlat(std::shared_ptr<MetalResources> resources, int d);
|
|
29
|
+
MetalIndexBinaryFlat(
|
|
30
|
+
std::shared_ptr<MetalResources> resources,
|
|
31
|
+
const faiss::IndexBinaryFlat* index);
|
|
32
|
+
~MetalIndexBinaryFlat() override;
|
|
33
|
+
|
|
34
|
+
MetalIndexBinaryFlat(const MetalIndexBinaryFlat&) = delete;
|
|
35
|
+
MetalIndexBinaryFlat& operator=(const MetalIndexBinaryFlat&) = delete;
|
|
36
|
+
|
|
37
|
+
void add(idx_t n, const uint8_t* x) override;
|
|
38
|
+
void reset() override;
|
|
39
|
+
void search(
|
|
40
|
+
idx_t n,
|
|
41
|
+
const uint8_t* x,
|
|
42
|
+
idx_t k,
|
|
43
|
+
int32_t* distances,
|
|
44
|
+
idx_t* labels,
|
|
45
|
+
const SearchParameters* params = nullptr) const override;
|
|
46
|
+
void reconstruct(idx_t key, uint8_t* recons) const override;
|
|
47
|
+
|
|
48
|
+
void copyFrom(const faiss::IndexBinaryFlat* index);
|
|
49
|
+
void copyTo(faiss::IndexBinaryFlat* index) const;
|
|
50
|
+
|
|
51
|
+
std::shared_ptr<MetalResources> getResources() const {
|
|
52
|
+
return resources_;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
private:
|
|
56
|
+
std::shared_ptr<MetalResources> resources_;
|
|
57
|
+
faiss::IndexBinaryFlat cpuIndex_;
|
|
58
|
+
id<MTLBuffer> vectorsBuf_ = nil;
|
|
59
|
+
// Search is synchronous and callers serialize access, so scratch buffers
|
|
60
|
+
// can be reused after waitUntilCompleted. ARC releases them on destruction.
|
|
61
|
+
mutable id<MTLBuffer> queryBuf_ = nil;
|
|
62
|
+
mutable id<MTLBuffer> distanceBuf_ = nil;
|
|
63
|
+
mutable id<MTLBuffer> labelBuf_ = nil;
|
|
64
|
+
|
|
65
|
+
id<MTLBuffer> upload(const uint8_t* data, size_t bytes) const;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
} // namespace gpu_metal
|
|
69
|
+
} // namespace faiss
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @lint-ignore-every LICENSELINT
|
|
2
2
|
/**
|
|
3
|
-
* Copyright (c) Meta Platforms, Inc. and
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @lint-ignore-every LICENSELINT
|
|
2
2
|
/**
|
|
3
|
-
* Copyright (c) Meta Platforms, Inc. and
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @lint-ignore-every LICENSELINT
|
|
2
2
|
/**
|
|
3
|
-
* Copyright (c) Meta Platforms, Inc. and
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -75,13 +75,51 @@ class MetalIndexIVFPQ : public MetalIndex {
|
|
|
75
75
|
std::unique_ptr<faiss::IndexIVFPQ> cpuIndex_;
|
|
76
76
|
std::unique_ptr<MetalIVFPQImpl> gpuIvf_;
|
|
77
77
|
|
|
78
|
+
// Reusable GPU scratch buffers for the search path, grown on demand.
|
|
79
|
+
mutable id<MTLBuffer> searchQueriesBuf_ = nil;
|
|
80
|
+
mutable id<MTLBuffer> searchCoarseBuf_ = nil;
|
|
81
|
+
mutable id<MTLBuffer> searchOutDistBuf_ = nil;
|
|
82
|
+
mutable id<MTLBuffer> searchOutIdxBuf_ = nil;
|
|
83
|
+
mutable id<MTLBuffer> searchPerListDistBuf_ = nil;
|
|
84
|
+
mutable id<MTLBuffer> searchPerListIdxBuf_ = nil;
|
|
85
|
+
mutable id<MTLBuffer> lookupTableBuf_ = nil;
|
|
86
|
+
mutable id<MTLBuffer> lookupTableHalfBuf_ = nil;
|
|
87
|
+
mutable id<MTLBuffer> searchCoarseDistBuf_ = nil;
|
|
88
|
+
mutable id<MTLBuffer> searchQTermBuf_ = nil;
|
|
89
|
+
mutable id<MTLBuffer> searchMergeDistBuf_ = nil;
|
|
90
|
+
mutable id<MTLBuffer> searchMergeIdxBuf_ = nil;
|
|
91
|
+
mutable size_t searchQueriesCap_ = 0;
|
|
92
|
+
mutable size_t searchCoarseCap_ = 0;
|
|
93
|
+
mutable size_t searchOutDistCap_ = 0;
|
|
94
|
+
mutable size_t searchOutIdxCap_ = 0;
|
|
95
|
+
mutable size_t searchPerListDistCap_ = 0;
|
|
96
|
+
mutable size_t searchPerListIdxCap_ = 0;
|
|
97
|
+
mutable size_t lookupTableCap_ = 0;
|
|
98
|
+
mutable size_t lookupTableHalfCap_ = 0;
|
|
99
|
+
mutable size_t searchCoarseDistCap_ = 0;
|
|
100
|
+
mutable size_t searchQTermCap_ = 0;
|
|
101
|
+
mutable size_t searchMergeDistCap_ = 0;
|
|
102
|
+
mutable size_t searchMergeIdxCap_ = 0;
|
|
103
|
+
|
|
104
|
+
// Coarse centroids mirrored on the GPU for the L2 lookup-table build.
|
|
105
|
+
mutable id<MTLBuffer> centroidBuf_ = nil;
|
|
106
|
+
|
|
107
|
+
// Query-independent term of the L2 precomputed-table decomposition
|
|
108
|
+
// (nlist * M * 256 floats), built once per trained index on the GPU.
|
|
109
|
+
mutable id<MTLBuffer> term2Buf_ = nil;
|
|
110
|
+
|
|
78
111
|
void verifyPQSettings_() const;
|
|
112
|
+
void precomputeTerm2_() const;
|
|
79
113
|
|
|
80
114
|
void encodeResidualAndAppend_(
|
|
81
115
|
idx_t n,
|
|
82
116
|
const float* x,
|
|
83
117
|
const idx_t* list_nos,
|
|
84
118
|
const idx_t* xids);
|
|
119
|
+
|
|
120
|
+
void ensureSearchBuf_(id<MTLBuffer>& buf, size_t& cap, size_t needed) const;
|
|
121
|
+
void uploadCentroids_() const;
|
|
122
|
+
void uploadPQCentroids_() const;
|
|
85
123
|
};
|
|
86
124
|
|
|
87
125
|
} // namespace gpu_metal
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @lint-ignore-every LICENSELINT
|
|
2
2
|
/**
|
|
3
|
-
* Copyright (c) Meta Platforms, Inc. and
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -91,6 +91,112 @@ class MetalKernels {
|
|
|
91
91
|
id<MTLBuffer> paramsBuf,
|
|
92
92
|
int nq);
|
|
93
93
|
|
|
94
|
+
// ---- IVF-PQ ----
|
|
95
|
+
|
|
96
|
+
void encodeIVFPQBuildLookupTables(
|
|
97
|
+
id<MTLComputeCommandEncoder> enc,
|
|
98
|
+
bool isL2,
|
|
99
|
+
bool outFp16,
|
|
100
|
+
id<MTLBuffer> queries,
|
|
101
|
+
id<MTLBuffer> coarseAssign,
|
|
102
|
+
id<MTLBuffer> coarseCentroids,
|
|
103
|
+
id<MTLBuffer> pqCentroids,
|
|
104
|
+
id<MTLBuffer> outLookup,
|
|
105
|
+
int nq,
|
|
106
|
+
int d,
|
|
107
|
+
int M,
|
|
108
|
+
int nprobe);
|
|
109
|
+
|
|
110
|
+
void encodeIVFPQScanList(
|
|
111
|
+
id<MTLComputeCommandEncoder> enc,
|
|
112
|
+
bool useSmall,
|
|
113
|
+
bool useFp16Lookup,
|
|
114
|
+
id<MTLBuffer> lookupTable,
|
|
115
|
+
id<MTLBuffer> codes,
|
|
116
|
+
id<MTLBuffer> ids,
|
|
117
|
+
id<MTLBuffer> listOffset,
|
|
118
|
+
id<MTLBuffer> listLength,
|
|
119
|
+
id<MTLBuffer> coarseAssign,
|
|
120
|
+
id<MTLBuffer> perListDist,
|
|
121
|
+
id<MTLBuffer> perListIdx,
|
|
122
|
+
id<MTLBuffer> paramsBuf,
|
|
123
|
+
id<MTLBuffer> coarseDist,
|
|
124
|
+
int nq,
|
|
125
|
+
int nprobe);
|
|
126
|
+
|
|
127
|
+
// ---- IVF-PQ precomputed-table path ----
|
|
128
|
+
|
|
129
|
+
void encodeIVFPQPrecomputeTerm2(
|
|
130
|
+
id<MTLComputeCommandEncoder> enc,
|
|
131
|
+
id<MTLBuffer> coarseCentroids,
|
|
132
|
+
id<MTLBuffer> pqCentroids,
|
|
133
|
+
id<MTLBuffer> outTerm2,
|
|
134
|
+
int nlist,
|
|
135
|
+
int d,
|
|
136
|
+
int M);
|
|
137
|
+
|
|
138
|
+
void encodeIVFPQBuildQueryTerm(
|
|
139
|
+
id<MTLComputeCommandEncoder> enc,
|
|
140
|
+
id<MTLBuffer> queries,
|
|
141
|
+
id<MTLBuffer> pqCentroids,
|
|
142
|
+
id<MTLBuffer> outQTerm,
|
|
143
|
+
int nq,
|
|
144
|
+
int d,
|
|
145
|
+
int M,
|
|
146
|
+
bool isL2);
|
|
147
|
+
|
|
148
|
+
void encodeIVFPQScanListPrecomp(
|
|
149
|
+
id<MTLComputeCommandEncoder> enc,
|
|
150
|
+
id<MTLBuffer> term2, // nil when useTerm2 is false (IP path)
|
|
151
|
+
id<MTLBuffer> qterm,
|
|
152
|
+
id<MTLBuffer> coarseDist,
|
|
153
|
+
id<MTLBuffer> codes,
|
|
154
|
+
id<MTLBuffer> ids,
|
|
155
|
+
id<MTLBuffer> listOffset,
|
|
156
|
+
id<MTLBuffer> listLength,
|
|
157
|
+
id<MTLBuffer> coarseAssign,
|
|
158
|
+
id<MTLBuffer> perListDist,
|
|
159
|
+
id<MTLBuffer> perListIdx,
|
|
160
|
+
int nq,
|
|
161
|
+
int M,
|
|
162
|
+
int k,
|
|
163
|
+
int nprobe,
|
|
164
|
+
bool wantMin,
|
|
165
|
+
bool useTerm2,
|
|
166
|
+
bool useDis0,
|
|
167
|
+
id<MTLBuffer> queries,
|
|
168
|
+
id<MTLBuffer> coarseCentroids,
|
|
169
|
+
id<MTLBuffer> pqCentroids,
|
|
170
|
+
int d,
|
|
171
|
+
bool onTheFly,
|
|
172
|
+
bool shortLists);
|
|
173
|
+
|
|
174
|
+
void encodeIVFMergeListsGrouped(
|
|
175
|
+
id<MTLComputeCommandEncoder> enc,
|
|
176
|
+
id<MTLBuffer> inDist,
|
|
177
|
+
id<MTLBuffer> inIdx,
|
|
178
|
+
id<MTLBuffer> outDist,
|
|
179
|
+
id<MTLBuffer> outIdx,
|
|
180
|
+
int nq,
|
|
181
|
+
int numLists,
|
|
182
|
+
int groupSize,
|
|
183
|
+
int k,
|
|
184
|
+
bool wantMin,
|
|
185
|
+
bool compact);
|
|
186
|
+
|
|
187
|
+
// Exact Hamming top-k from the precompiled MetalDistance.metallib.
|
|
188
|
+
// Requires positive uint32-sized counts and 1 <= k <= 512.
|
|
189
|
+
void encodeHammingDistanceTopK(
|
|
190
|
+
id<MTLComputeCommandEncoder> enc,
|
|
191
|
+
id<MTLBuffer> queries,
|
|
192
|
+
id<MTLBuffer> database,
|
|
193
|
+
id<MTLBuffer> outDist,
|
|
194
|
+
id<MTLBuffer> outIdx,
|
|
195
|
+
uint32_t nq,
|
|
196
|
+
uint32_t nb,
|
|
197
|
+
uint32_t codeSize,
|
|
198
|
+
uint32_t k);
|
|
199
|
+
|
|
94
200
|
static int selectTopKVariantIndex(int k);
|
|
95
201
|
|
|
96
202
|
private:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @lint-ignore-every LICENSELINT
|
|
2
2
|
/**
|
|
3
|
-
* Copyright (c) Meta Platforms, Inc. and
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
#pragma once
|
|
13
13
|
|
|
14
14
|
#include <faiss/Index.h>
|
|
15
|
+
#include <faiss/IndexBinary.h>
|
|
15
16
|
|
|
16
17
|
namespace faiss {
|
|
17
18
|
namespace gpu_metal {
|
|
@@ -41,5 +42,14 @@ faiss::Index* index_cpu_to_gpu(
|
|
|
41
42
|
/// Copy Metal index back to CPU. Caller owns returned index.
|
|
42
43
|
faiss::Index* index_gpu_to_cpu(const faiss::Index* index);
|
|
43
44
|
|
|
45
|
+
/// Clone CPU IndexBinaryFlat to Metal. Caller owns the returned index.
|
|
46
|
+
faiss::IndexBinary* index_binary_cpu_to_gpu(
|
|
47
|
+
StandardMetalResourcesHolder* res,
|
|
48
|
+
int device,
|
|
49
|
+
const faiss::IndexBinary* index);
|
|
50
|
+
|
|
51
|
+
/// Clone MetalIndexBinaryFlat back to CPU. Caller owns the returned index.
|
|
52
|
+
faiss::IndexBinary* index_binary_gpu_to_cpu(const faiss::IndexBinary* index);
|
|
53
|
+
|
|
44
54
|
} // namespace gpu_metal
|
|
45
55
|
} // namespace faiss
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @lint-ignore-every LICENSELINT
|
|
2
2
|
/**
|
|
3
|
-
* Copyright (c) Meta Platforms, Inc. and
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @lint-ignore-every LICENSELINT
|
|
2
2
|
/**
|
|
3
|
-
* Copyright (c) Meta Platforms, Inc. and
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @lint-ignore-every LICENSELINT
|
|
2
2
|
/**
|
|
3
|
-
* Copyright (c) Meta Platforms, Inc. and
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @lint-ignore-every LICENSELINT
|
|
2
2
|
/**
|
|
3
|
-
* Copyright (c) Meta Platforms, Inc. and
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -123,7 +123,7 @@ RangeSearchPartialResult::RangeSearchPartialResult(RangeSearchResult* res_in)
|
|
|
123
123
|
|
|
124
124
|
/// begin a new result
|
|
125
125
|
RangeQueryResult& RangeSearchPartialResult::new_result(idx_t qno) {
|
|
126
|
-
RangeQueryResult qres = {qno, 0, this};
|
|
126
|
+
RangeQueryResult qres = {qno, 0, this, {}};
|
|
127
127
|
queries.push_back(qres);
|
|
128
128
|
return queries.back();
|
|
129
129
|
}
|
|
@@ -246,6 +246,8 @@ void TimeoutCallback::set_timeout(double timeout_in_seconds) {
|
|
|
246
246
|
}
|
|
247
247
|
|
|
248
248
|
bool TimeoutCallback::want_interrupt() {
|
|
249
|
+
static std::mutex mutex;
|
|
250
|
+
std::lock_guard<std::mutex> guard(mutex);
|
|
249
251
|
if (timeout == 0) {
|
|
250
252
|
return false;
|
|
251
253
|
}
|
|
@@ -146,12 +146,7 @@ struct FAISS_API InterruptCallback {
|
|
|
146
146
|
|
|
147
147
|
static void clear_instance();
|
|
148
148
|
|
|
149
|
-
|
|
150
|
-
* - an interrupt callback is set
|
|
151
|
-
* - the callback returns true
|
|
152
|
-
* if this is the case, then throw an exception. Should not be called
|
|
153
|
-
* from multiple threads.
|
|
154
|
-
*/
|
|
149
|
+
/// Concurrent calls require a thread-safe want_interrupt().
|
|
155
150
|
static void check();
|
|
156
151
|
|
|
157
152
|
/// same as check() but return true if is interrupted instead of
|