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
|
@@ -0,0 +1,121 @@
|
|
|
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/invlists/DiskIOBackend.h>
|
|
9
|
+
|
|
10
|
+
#include <libaio.h>
|
|
11
|
+
#include <sys/types.h>
|
|
12
|
+
#include <unistd.h>
|
|
13
|
+
|
|
14
|
+
#include <algorithm>
|
|
15
|
+
#include <cerrno>
|
|
16
|
+
#include <cstring>
|
|
17
|
+
#include <ctime>
|
|
18
|
+
#include <vector>
|
|
19
|
+
|
|
20
|
+
#include <faiss/impl/FaissAssert.h>
|
|
21
|
+
|
|
22
|
+
namespace faiss {
|
|
23
|
+
|
|
24
|
+
DiskIOBackend::DiskIOBackend(int max_events_in) {
|
|
25
|
+
FAISS_THROW_IF_NOT(max_events_in > 0);
|
|
26
|
+
const int ret = io_setup(max_events_in, &ctx);
|
|
27
|
+
FAISS_THROW_IF_NOT_FMT(
|
|
28
|
+
ret == 0,
|
|
29
|
+
"io_setup failed: %s%s",
|
|
30
|
+
strerror(-ret),
|
|
31
|
+
ret == -EAGAIN ? " (too many libaio contexts, see fs.aio-max-nr)"
|
|
32
|
+
: "");
|
|
33
|
+
pid = getpid();
|
|
34
|
+
max_events = max_events_in;
|
|
35
|
+
iocbs.resize(max_events);
|
|
36
|
+
iocb_ptrs.resize(max_events);
|
|
37
|
+
events.resize(max_events);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
DiskIOBackend::~DiskIOBackend() {
|
|
41
|
+
// blocks until the reads in flight are done, so the caller can free their
|
|
42
|
+
// buffers afterwards. The context of a parent process is not ours to
|
|
43
|
+
// destroy.
|
|
44
|
+
if (owned_by_this_process()) {
|
|
45
|
+
io_destroy(ctx);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
void DiskIOBackend::stage(
|
|
50
|
+
int fd,
|
|
51
|
+
void* buf,
|
|
52
|
+
size_t len,
|
|
53
|
+
size_t offset,
|
|
54
|
+
void* user_data) {
|
|
55
|
+
FAISS_THROW_IF_NOT_MSG(
|
|
56
|
+
n_staged < max_events, "DiskIOBackend: too many reads staged");
|
|
57
|
+
iocb* cb = &iocbs[n_staged];
|
|
58
|
+
io_prep_pread(cb, fd, buf, len, static_cast<long long>(offset));
|
|
59
|
+
cb->data = user_data;
|
|
60
|
+
iocb_ptrs[n_staged] = cb;
|
|
61
|
+
n_staged++;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
void DiskIOBackend::submit() {
|
|
65
|
+
int done = 0;
|
|
66
|
+
while (done < n_staged) {
|
|
67
|
+
const int ret =
|
|
68
|
+
io_submit(ctx, n_staged - done, iocb_ptrs.data() + done);
|
|
69
|
+
if (ret == -EINTR || ret == -EAGAIN) {
|
|
70
|
+
continue; // transient, the queue is sized for all reads in flight
|
|
71
|
+
}
|
|
72
|
+
FAISS_THROW_IF_NOT_FMT(
|
|
73
|
+
ret > 0,
|
|
74
|
+
"io_submit failed: %s",
|
|
75
|
+
ret < 0 ? strerror(-ret) : "no read accepted");
|
|
76
|
+
done += ret;
|
|
77
|
+
n_in_flight += ret;
|
|
78
|
+
}
|
|
79
|
+
n_staged = 0;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
int DiskIOBackend::reap(void** user_data, long* res, int max, int min_nr) {
|
|
83
|
+
max = std::min(max, max_events);
|
|
84
|
+
min_nr = std::min(min_nr, std::min(max, n_in_flight));
|
|
85
|
+
struct timespec no_wait = {0, 0};
|
|
86
|
+
const int ret = io_getevents(
|
|
87
|
+
ctx, min_nr, max, events.data(), min_nr > 0 ? nullptr : &no_wait);
|
|
88
|
+
if (ret == -EINTR) {
|
|
89
|
+
return 0;
|
|
90
|
+
}
|
|
91
|
+
FAISS_THROW_IF_NOT_FMT(ret >= 0, "io_getevents failed: %s", strerror(-ret));
|
|
92
|
+
n_in_flight -= ret;
|
|
93
|
+
for (int i = 0; i < ret; i++) {
|
|
94
|
+
user_data[i] = events[i].data;
|
|
95
|
+
// bytes read or a negative errno, in an unsigned field
|
|
96
|
+
res[i] = static_cast<long>(events[i].res);
|
|
97
|
+
}
|
|
98
|
+
return ret;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
bool DiskIOBackend::wait_all() noexcept {
|
|
102
|
+
n_staged = 0;
|
|
103
|
+
while (n_in_flight > 0) {
|
|
104
|
+
const int ret = io_getevents(
|
|
105
|
+
ctx, n_in_flight, max_events, events.data(), nullptr);
|
|
106
|
+
if (ret == -EINTR) {
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (ret < 0) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
n_in_flight -= ret;
|
|
113
|
+
}
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
bool DiskIOBackend::owned_by_this_process() const {
|
|
118
|
+
return pid == getpid();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
} // namespace faiss
|
|
@@ -0,0 +1,71 @@
|
|
|
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 <libaio.h>
|
|
11
|
+
#include <sys/types.h>
|
|
12
|
+
|
|
13
|
+
#include <cstddef>
|
|
14
|
+
#include <vector>
|
|
15
|
+
|
|
16
|
+
namespace faiss {
|
|
17
|
+
|
|
18
|
+
/** Asynchronous reads with Linux libaio, for one thread.
|
|
19
|
+
*
|
|
20
|
+
* Reads are staged with stage(), sent to the kernel together with submit(),
|
|
21
|
+
* and collected with reap(). With a file opened with
|
|
22
|
+
* O_DIRECT, the buffer address, offset and length of every read must be
|
|
23
|
+
* multiples of the device sector size.
|
|
24
|
+
*/
|
|
25
|
+
struct DiskIOBackend {
|
|
26
|
+
io_context_t ctx = nullptr;
|
|
27
|
+
pid_t pid = 0; ///< process that created ctx
|
|
28
|
+
int max_events = 0; ///< at most max_events reads can be in flight
|
|
29
|
+
int n_staged = 0; ///< reads staged for the next submit()
|
|
30
|
+
int n_in_flight = 0; ///< submitted and not reaped
|
|
31
|
+
std::vector<iocb> iocbs;
|
|
32
|
+
std::vector<iocb*> iocb_ptrs;
|
|
33
|
+
std::vector<io_event> events;
|
|
34
|
+
|
|
35
|
+
explicit DiskIOBackend(int max_events);
|
|
36
|
+
~DiskIOBackend();
|
|
37
|
+
|
|
38
|
+
DiskIOBackend(const DiskIOBackend&) = delete;
|
|
39
|
+
DiskIOBackend& operator=(const DiskIOBackend&) = delete;
|
|
40
|
+
|
|
41
|
+
/// add a read of len bytes at offset into buf to the next submit();
|
|
42
|
+
/// user_data identifies it in reap()
|
|
43
|
+
void stage(int fd, void* buf, size_t len, size_t offset, void* user_data);
|
|
44
|
+
|
|
45
|
+
/// send the staged reads to the kernel
|
|
46
|
+
void submit();
|
|
47
|
+
|
|
48
|
+
/** Collect up to max completed reads, waiting until at least min_nr
|
|
49
|
+
* have completed (without waiting if min_nr is 0). min_nr is capped by
|
|
50
|
+
* max and by the reads in flight, and a signal can end the wait early.
|
|
51
|
+
*
|
|
52
|
+
* @param user_data output, the user_data of each completed read
|
|
53
|
+
* @param res output, the bytes read, or a negative errno
|
|
54
|
+
* @return number of completed reads
|
|
55
|
+
*/
|
|
56
|
+
int reap(void** user_data, long* res, int max, int min_nr = 0);
|
|
57
|
+
|
|
58
|
+
/** Drop the staged reads and wait for the submitted ones to complete,
|
|
59
|
+
* ignoring their results, so that their buffers can be freed and the
|
|
60
|
+
* context reused.
|
|
61
|
+
*
|
|
62
|
+
* @return false if waiting failed: reads may still be in flight
|
|
63
|
+
*/
|
|
64
|
+
bool wait_all() noexcept;
|
|
65
|
+
|
|
66
|
+
/// false in a process forked after the context was created: the context
|
|
67
|
+
/// belongs to the parent process and cannot be used
|
|
68
|
+
bool owned_by_this_process() const;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
} // namespace faiss
|
|
@@ -127,7 +127,9 @@ size_t InvertedLists::copy_subset_to(
|
|
|
127
127
|
} else if (subset_type == SUBSET_TYPE_ID_MOD) {
|
|
128
128
|
for (size_t i = 0; i < n; i++) {
|
|
129
129
|
idx_t id = ids_in[i];
|
|
130
|
-
|
|
130
|
+
// C++ gives a negative remainder, so a plain `id % a1` never
|
|
131
|
+
// matches for a negative id. Fold it into [0, a1) instead.
|
|
132
|
+
if (((id % a1) + a1) % a1 == a2) {
|
|
131
133
|
oivf.add_entry(
|
|
132
134
|
list_no,
|
|
133
135
|
get_single_id(list_no, i),
|
|
@@ -296,23 +298,24 @@ size_t ArrayInvertedLists::add_entries(
|
|
|
296
298
|
}
|
|
297
299
|
|
|
298
300
|
size_t ArrayInvertedLists::list_size(size_t list_no) const {
|
|
299
|
-
|
|
301
|
+
FAISS_THROW_IF_NOT(list_no < nlist);
|
|
300
302
|
return ids[list_no].size();
|
|
301
303
|
}
|
|
302
304
|
|
|
303
305
|
bool ArrayInvertedLists::is_empty(size_t list_no, void* inverted_list_context)
|
|
304
306
|
const {
|
|
305
307
|
FAISS_THROW_IF_NOT(inverted_list_context == nullptr);
|
|
308
|
+
FAISS_THROW_IF_NOT(list_no < nlist);
|
|
306
309
|
return ids[list_no].size() == 0;
|
|
307
310
|
}
|
|
308
311
|
|
|
309
312
|
const uint8_t* ArrayInvertedLists::get_codes(size_t list_no) const {
|
|
310
|
-
|
|
313
|
+
FAISS_THROW_IF_NOT(list_no < nlist);
|
|
311
314
|
return codes[list_no].data();
|
|
312
315
|
}
|
|
313
316
|
|
|
314
317
|
const idx_t* ArrayInvertedLists::get_ids(size_t list_no) const {
|
|
315
|
-
|
|
318
|
+
FAISS_THROW_IF_NOT(list_no < nlist);
|
|
316
319
|
return ids[list_no].data();
|
|
317
320
|
}
|
|
318
321
|
|
|
@@ -929,10 +932,12 @@ void StopWordsInvertedLists::prefetch_lists(const idx_t* list_nos, int nlist_in)
|
|
|
929
932
|
* CappedInvertedLists implementation
|
|
930
933
|
******************************************/
|
|
931
934
|
|
|
932
|
-
CappedInvertedLists::CappedInvertedLists(
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
935
|
+
CappedInvertedLists::CappedInvertedLists(
|
|
936
|
+
InvertedLists* il0_in,
|
|
937
|
+
size_t maxsize_in)
|
|
938
|
+
: InvertedLists(il0_in->nlist, il0_in->code_size),
|
|
939
|
+
il0(il0_in),
|
|
940
|
+
maxsize(maxsize_in) {}
|
|
936
941
|
|
|
937
942
|
size_t CappedInvertedLists::list_size(size_t list_no) const {
|
|
938
943
|
size_t sz = il0->list_size(list_no);
|
|
@@ -972,9 +977,9 @@ const uint8_t* CappedInvertedLists::get_single_code(
|
|
|
972
977
|
return il0->get_single_code(list_no, offset);
|
|
973
978
|
}
|
|
974
979
|
|
|
975
|
-
void CappedInvertedLists::prefetch_lists(const idx_t* list_nos, int
|
|
980
|
+
void CappedInvertedLists::prefetch_lists(const idx_t* list_nos, int nlist_in)
|
|
976
981
|
const {
|
|
977
|
-
il0->prefetch_lists(list_nos,
|
|
982
|
+
il0->prefetch_lists(list_nos, nlist_in);
|
|
978
983
|
}
|
|
979
984
|
|
|
980
985
|
size_t CappedInvertedLists::add_entries(
|
|
@@ -17,6 +17,10 @@
|
|
|
17
17
|
#include <faiss/invlists/OnDiskInvertedLists.h>
|
|
18
18
|
#endif // !_WIN32
|
|
19
19
|
|
|
20
|
+
#ifdef FAISS_ENABLE_DISK_IVF
|
|
21
|
+
#include <faiss/invlists/RaBitQSSDInvertedLists.h>
|
|
22
|
+
#endif
|
|
23
|
+
|
|
20
24
|
namespace faiss {
|
|
21
25
|
|
|
22
26
|
/**********************************************************
|
|
@@ -35,6 +39,9 @@ struct IOHookTable : std::vector<InvertedListsIOHook*> {
|
|
|
35
39
|
IOHookTable() {
|
|
36
40
|
#ifndef _WIN32
|
|
37
41
|
push_back(new OnDiskInvertedListsIOHook());
|
|
42
|
+
#endif
|
|
43
|
+
#ifdef FAISS_ENABLE_DISK_IVF
|
|
44
|
+
push_back(new RaBitQSSDInvertedListsIOHook());
|
|
38
45
|
#endif
|
|
39
46
|
push_back(new BlockInvertedListsIOHook());
|
|
40
47
|
}
|
|
@@ -90,6 +97,25 @@ void InvertedListsIOHook::print_callbacks() {
|
|
|
90
97
|
}
|
|
91
98
|
}
|
|
92
99
|
|
|
100
|
+
std::string ondisk_same_dir_filename(IOReader* f, const std::string& filename) {
|
|
101
|
+
FileIOReader* reader = dynamic_cast<FileIOReader*>(f);
|
|
102
|
+
FAISS_THROW_IF_NOT_MSG(
|
|
103
|
+
reader,
|
|
104
|
+
"IO_FLAG_ONDISK_SAME_DIR only supported "
|
|
105
|
+
"when reading from file");
|
|
106
|
+
std::string dirname = "./";
|
|
107
|
+
size_t slash = reader->name.find_last_of('/');
|
|
108
|
+
if (slash != std::string::npos) {
|
|
109
|
+
dirname = reader->name.substr(0, slash + 1);
|
|
110
|
+
}
|
|
111
|
+
std::string basename = filename;
|
|
112
|
+
slash = basename.find_last_of('/');
|
|
113
|
+
if (slash != std::string::npos) {
|
|
114
|
+
basename = basename.substr(slash + 1);
|
|
115
|
+
}
|
|
116
|
+
return dirname + basename;
|
|
117
|
+
}
|
|
118
|
+
|
|
93
119
|
InvertedLists* InvertedListsIOHook::read_ArrayInvertedLists(
|
|
94
120
|
IOReader*,
|
|
95
121
|
int,
|
|
@@ -59,4 +59,9 @@ struct InvertedListsIOHook {
|
|
|
59
59
|
static InvertedListsIOHook* lookup_classname(const std::string& classname);
|
|
60
60
|
};
|
|
61
61
|
|
|
62
|
+
/** For IO_FLAG_ONDISK_SAME_DIR: the path of a data file with the base name of
|
|
63
|
+
* filename, in the directory of the index file f is reading from.
|
|
64
|
+
*/
|
|
65
|
+
std::string ondisk_same_dir_filename(IOReader* f, const std::string& filename);
|
|
66
|
+
|
|
62
67
|
} // namespace faiss
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
#include <pthread.h>
|
|
13
13
|
|
|
14
|
+
#include <cerrno>
|
|
14
15
|
#include <memory>
|
|
15
16
|
#include <unordered_set>
|
|
16
17
|
|
|
@@ -152,22 +153,22 @@ struct OnDiskInvertedLists::OngoingPrefetch {
|
|
|
152
153
|
if (list_no == -1) {
|
|
153
154
|
return false;
|
|
154
155
|
}
|
|
155
|
-
const OnDiskInvertedLists*
|
|
156
|
-
|
|
157
|
-
size_t n =
|
|
158
|
-
const idx_t* idx =
|
|
159
|
-
const uint8_t* codes =
|
|
156
|
+
const OnDiskInvertedLists* invlists = pf->od;
|
|
157
|
+
invlists->locks->lock_1(static_cast<int>(list_no));
|
|
158
|
+
size_t n = invlists->list_size(list_no);
|
|
159
|
+
const idx_t* idx = invlists->get_ids(list_no);
|
|
160
|
+
const uint8_t* codes = invlists->get_codes(list_no);
|
|
160
161
|
int cs = 0;
|
|
161
162
|
for (size_t i = 0; i < n; i++) {
|
|
162
163
|
cs += idx[i];
|
|
163
164
|
}
|
|
164
165
|
const idx_t* codes8 = (const idx_t*)codes;
|
|
165
|
-
size_t n8 = n *
|
|
166
|
+
size_t n8 = n * invlists->code_size / 8;
|
|
166
167
|
|
|
167
168
|
for (size_t i = 0; i < n8; i++) {
|
|
168
169
|
cs += codes8[i];
|
|
169
170
|
}
|
|
170
|
-
|
|
171
|
+
invlists->locks->unlock_1(static_cast<int>(list_no));
|
|
171
172
|
|
|
172
173
|
global_cs += cs & 1;
|
|
173
174
|
return true;
|
|
@@ -737,23 +738,7 @@ InvertedLists* OnDiskInvertedListsIOHook::read(IOReader* f, int io_flags)
|
|
|
737
738
|
od->filename.assign(x.begin(), x.end());
|
|
738
739
|
|
|
739
740
|
if (io_flags & IO_FLAG_ONDISK_SAME_DIR) {
|
|
740
|
-
|
|
741
|
-
FAISS_THROW_IF_NOT_MSG(
|
|
742
|
-
reader,
|
|
743
|
-
"IO_FLAG_ONDISK_SAME_DIR only supported "
|
|
744
|
-
"when reading from file");
|
|
745
|
-
std::string indexname = reader->name;
|
|
746
|
-
std::string dirname = "./";
|
|
747
|
-
size_t slash = indexname.find_last_of('/');
|
|
748
|
-
if (slash != std::string::npos) {
|
|
749
|
-
dirname = indexname.substr(0, slash + 1);
|
|
750
|
-
}
|
|
751
|
-
std::string filename = od->filename;
|
|
752
|
-
slash = filename.find_last_of('/');
|
|
753
|
-
if (slash != std::string::npos) {
|
|
754
|
-
filename = filename.substr(slash + 1);
|
|
755
|
-
}
|
|
756
|
-
filename = dirname + filename;
|
|
741
|
+
std::string filename = ondisk_same_dir_filename(f, od->filename);
|
|
757
742
|
printf("IO_FLAG_ONDISK_SAME_DIR: "
|
|
758
743
|
"updating ondisk filename from %s to %s\n",
|
|
759
744
|
od->filename.c_str(),
|