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
|
@@ -31,6 +31,9 @@
|
|
|
31
31
|
#include <faiss/IndexIVF.h>
|
|
32
32
|
#include <faiss/IndexIVFAdditiveQuantizer.h>
|
|
33
33
|
#include <faiss/IndexIVFAdditiveQuantizerFastScan.h>
|
|
34
|
+
#ifdef FAISS_ENABLE_DISK_IVF
|
|
35
|
+
#include <faiss/IndexIVFRaBitQSSD.h>
|
|
36
|
+
#endif
|
|
34
37
|
#include <faiss/IndexIVFEDEN.h>
|
|
35
38
|
#include <faiss/IndexIVFFlat.h>
|
|
36
39
|
#include <faiss/IndexIVFFlatPanorama.h>
|
|
@@ -40,6 +43,7 @@
|
|
|
40
43
|
#include <faiss/IndexIVFPQR.h>
|
|
41
44
|
#include <faiss/IndexIVFRaBitQ.h>
|
|
42
45
|
#include <faiss/IndexIVFRaBitQFastScan.h>
|
|
46
|
+
#include <faiss/IndexIVFSQFastScan.h>
|
|
43
47
|
#include <faiss/IndexIVFSpectralHash.h>
|
|
44
48
|
#include <faiss/IndexLSH.h>
|
|
45
49
|
#include <faiss/IndexLattice.h>
|
|
@@ -47,11 +51,13 @@
|
|
|
47
51
|
#include <faiss/IndexNSG.h>
|
|
48
52
|
#include <faiss/IndexPQ.h>
|
|
49
53
|
#include <faiss/IndexPQFastScan.h>
|
|
54
|
+
#include <faiss/IndexPiPNN.h>
|
|
50
55
|
#include <faiss/IndexPreTransform.h>
|
|
51
56
|
#include <faiss/IndexRaBitQ.h>
|
|
52
57
|
#include <faiss/IndexRaBitQFastScan.h>
|
|
53
58
|
#include <faiss/IndexRefine.h>
|
|
54
59
|
#include <faiss/IndexRowwiseMinMax.h>
|
|
60
|
+
#include <faiss/IndexSQFastScan.h>
|
|
55
61
|
#ifdef FAISS_ENABLE_SVS
|
|
56
62
|
#include <faiss/impl/svs_io.h>
|
|
57
63
|
#include <faiss/svs/IndexSVSFlat.h>
|
|
@@ -113,7 +119,8 @@ static void write_index_header(const Index* idx, IOWriter* f) {
|
|
|
113
119
|
void write_VectorTransform(const VectorTransform* vt, IOWriter* f) {
|
|
114
120
|
if (const HadamardRotation* hr =
|
|
115
121
|
dynamic_cast<const HadamardRotation*>(vt)) {
|
|
116
|
-
|
|
122
|
+
// HR64: d_out padded to a multiple of 64 rather than a power of 2.
|
|
123
|
+
uint32_t h = fourcc(hr->pad_to_power_of_2 ? "HRot" : "HR64");
|
|
117
124
|
WRITE1(h);
|
|
118
125
|
WRITE1(hr->seed);
|
|
119
126
|
} else if (
|
|
@@ -421,6 +428,29 @@ static void write_NNDescent(const NNDescent* nnd, IOWriter* f) {
|
|
|
421
428
|
WRITEVECTOR(nnd->final_graph);
|
|
422
429
|
}
|
|
423
430
|
|
|
431
|
+
static void write_PiPNN(const PiPNN& pipnn, IOWriter* f) {
|
|
432
|
+
WRITE1(pipnn.R);
|
|
433
|
+
WRITE1(pipnn.leaf_k);
|
|
434
|
+
WRITE1(pipnn.hash_bits);
|
|
435
|
+
WRITE1(pipnn.reservoir_size);
|
|
436
|
+
WRITE1(pipnn.c_max);
|
|
437
|
+
WRITE1(pipnn.c_min);
|
|
438
|
+
WRITE1(pipnn.leader_cap);
|
|
439
|
+
// Former replicas field, kept so that the format does not change.
|
|
440
|
+
const int replicas = 1;
|
|
441
|
+
WRITE1(replicas);
|
|
442
|
+
WRITE1(pipnn.leader_fraction);
|
|
443
|
+
WRITE1(pipnn.alpha);
|
|
444
|
+
WRITEVECTOR(pipnn.fanout);
|
|
445
|
+
WRITE1(pipnn.seed);
|
|
446
|
+
WRITE1(pipnn.ip_partition_by_angle);
|
|
447
|
+
WRITE1(pipnn.search_L);
|
|
448
|
+
WRITE1(pipnn.ntotal);
|
|
449
|
+
WRITE1(pipnn.entry_point);
|
|
450
|
+
WRITEANDCHECK(pipnn.graph.data(), pipnn.graph.size());
|
|
451
|
+
WRITEVECTOR(pipnn.next_copy);
|
|
452
|
+
}
|
|
453
|
+
|
|
424
454
|
// Write RaBitQuantizer for 1-bit format (backward compatible)
|
|
425
455
|
static void write_RaBitQuantizer(
|
|
426
456
|
const RaBitQuantizer* rabitq,
|
|
@@ -938,6 +968,40 @@ void write_index(const Index* idx, IOWriter* f, int io_flags) {
|
|
|
938
968
|
WRITE1(idxnsg->nndescent_iter);
|
|
939
969
|
write_NSG(&idxnsg->nsg, f);
|
|
940
970
|
write_index(idxnsg->storage, f);
|
|
971
|
+
} else if (
|
|
972
|
+
const IndexPiPNN* idxpipnn = dynamic_cast<const IndexPiPNN*>(idx)) {
|
|
973
|
+
FAISS_THROW_IF_NOT_FMT(
|
|
974
|
+
typeid(*idx) == typeid(IndexPiPNN) ||
|
|
975
|
+
typeid(*idx) == typeid(IndexPiPNNFlat) ||
|
|
976
|
+
typeid(*idx) == typeid(IndexPiPNNSQ),
|
|
977
|
+
"don't know how to serialize this IndexPiPNN subtype: %s",
|
|
978
|
+
typeid(*idx).name());
|
|
979
|
+
const Index* storage = idxpipnn->storage;
|
|
980
|
+
const PiPNN& state = idxpipnn->pipnn;
|
|
981
|
+
// The reader rejects these states, so they are not written either.
|
|
982
|
+
FAISS_THROW_IF_NOT_MSG(
|
|
983
|
+
storage, "cannot serialize an IndexPiPNN without storage");
|
|
984
|
+
IndexPiPNN::check_storage_supported(*storage);
|
|
985
|
+
state.check_params();
|
|
986
|
+
FAISS_THROW_IF_NOT_MSG(
|
|
987
|
+
storage->ntotal == idxpipnn->ntotal &&
|
|
988
|
+
storage->d == idxpipnn->d &&
|
|
989
|
+
storage->metric_type == idxpipnn->metric_type,
|
|
990
|
+
"cannot serialize IndexPiPNN: the storage is inconsistent "
|
|
991
|
+
"with the index (was the storage modified directly?)");
|
|
992
|
+
FAISS_THROW_IF_NOT_MSG(
|
|
993
|
+
state.graph.size() == size_t(state.ntotal) * size_t(state.R),
|
|
994
|
+
"cannot serialize IndexPiPNN: graph size != ntotal * R");
|
|
995
|
+
// The subclasses differ only by their constructors: the fourcc names
|
|
996
|
+
// the storage.
|
|
997
|
+
const uint32_t h = dynamic_cast<const IndexScalarQuantizer*>(storage)
|
|
998
|
+
? fourcc("IPNs")
|
|
999
|
+
: fourcc("IPNf");
|
|
1000
|
+
WRITE1(h);
|
|
1001
|
+
write_index_header(idxpipnn, f);
|
|
1002
|
+
WRITE1(idxpipnn->defer_build);
|
|
1003
|
+
write_PiPNN(state, f);
|
|
1004
|
+
write_index(storage, f);
|
|
941
1005
|
} else if (
|
|
942
1006
|
const IndexNNDescent* idxnnd =
|
|
943
1007
|
dynamic_cast<const IndexNNDescent*>(idx)) {
|
|
@@ -951,6 +1015,21 @@ void write_index(const Index* idx, IOWriter* f, int io_flags) {
|
|
|
951
1015
|
write_index_header(idxnnd, f);
|
|
952
1016
|
write_NNDescent(&idxnnd->nndescent, f);
|
|
953
1017
|
write_index(idxnnd->storage, f);
|
|
1018
|
+
} else if (
|
|
1019
|
+
const IndexSQFastScan* idxsqfs =
|
|
1020
|
+
dynamic_cast<const IndexSQFastScan*>(idx)) {
|
|
1021
|
+
uint32_t h = fourcc("ISfs");
|
|
1022
|
+
WRITE1(h);
|
|
1023
|
+
write_index_header(idxsqfs, f);
|
|
1024
|
+
write_ScalarQuantizer(&idxsqfs->sq, f);
|
|
1025
|
+
WRITE1(idxsqfs->implem);
|
|
1026
|
+
WRITE1(idxsqfs->bbs);
|
|
1027
|
+
WRITE1(idxsqfs->qbs);
|
|
1028
|
+
WRITE1(idxsqfs->ntotal2);
|
|
1029
|
+
WRITE1(idxsqfs->M2);
|
|
1030
|
+
WRITEVECTOR(idxsqfs->codes);
|
|
1031
|
+
WRITE1(idxsqfs->rerank_factor);
|
|
1032
|
+
WRITEVECTOR(idxsqfs->lo_codes);
|
|
954
1033
|
} else if (
|
|
955
1034
|
const IndexPQFastScan* idxpqfs =
|
|
956
1035
|
dynamic_cast<const IndexPQFastScan*>(idx)) {
|
|
@@ -964,6 +1043,26 @@ void write_index(const Index* idx, IOWriter* f, int io_flags) {
|
|
|
964
1043
|
WRITE1(idxpqfs->ntotal2);
|
|
965
1044
|
WRITE1(idxpqfs->M2);
|
|
966
1045
|
WRITEVECTOR(idxpqfs->codes);
|
|
1046
|
+
} else if (
|
|
1047
|
+
const IndexIVFSQFastScan* ivfsqfs =
|
|
1048
|
+
dynamic_cast<const IndexIVFSQFastScan*>(idx)) {
|
|
1049
|
+
uint32_t h = fourcc("IwSf");
|
|
1050
|
+
WRITE1(h);
|
|
1051
|
+
write_ivf_header(ivfsqfs, f);
|
|
1052
|
+
WRITE1(ivfsqfs->by_residual);
|
|
1053
|
+
WRITE1(ivfsqfs->code_size);
|
|
1054
|
+
WRITE1(ivfsqfs->bbs);
|
|
1055
|
+
WRITE1(ivfsqfs->M2);
|
|
1056
|
+
WRITE1(ivfsqfs->implem);
|
|
1057
|
+
WRITE1(ivfsqfs->rerank_factor);
|
|
1058
|
+
write_ScalarQuantizer(&ivfsqfs->sq, f);
|
|
1059
|
+
write_InvertedLists(ivfsqfs->invlists, f);
|
|
1060
|
+
// Write lo_codes_invlists if present
|
|
1061
|
+
bool has_orig = (ivfsqfs->lo_codes_invlists != nullptr);
|
|
1062
|
+
WRITE1(has_orig);
|
|
1063
|
+
if (has_orig) {
|
|
1064
|
+
write_InvertedLists(ivfsqfs->lo_codes_invlists, f);
|
|
1065
|
+
}
|
|
967
1066
|
} else if (
|
|
968
1067
|
const IndexIVFPQFastScan* ivpq_2 =
|
|
969
1068
|
dynamic_cast<const IndexIVFPQFastScan*>(idx)) {
|
|
@@ -1072,6 +1171,23 @@ void write_index(const Index* idx, IOWriter* f, int io_flags) {
|
|
|
1072
1171
|
WRITE1(ivrq->qb);
|
|
1073
1172
|
write_InvertedLists(ivrq->invlists, f);
|
|
1074
1173
|
}
|
|
1174
|
+
#ifdef FAISS_ENABLE_DISK_IVF
|
|
1175
|
+
else if (
|
|
1176
|
+
const IndexIVFRaBitQSSD* ivdr =
|
|
1177
|
+
dynamic_cast<const IndexIVFRaBitQSSD*>(idx)) {
|
|
1178
|
+
uint32_t h = fourcc("IwDr");
|
|
1179
|
+
WRITE1(h);
|
|
1180
|
+
write_ivf_header(ivdr, f);
|
|
1181
|
+
write_RaBitQuantizer(&ivdr->rabitq, f, true);
|
|
1182
|
+
WRITE1(ivdr->mem_dim);
|
|
1183
|
+
WRITE1(ivdr->use_hacc);
|
|
1184
|
+
WRITE1(ivdr->drain_alpha);
|
|
1185
|
+
WRITE1(ivdr->qd_per_thread);
|
|
1186
|
+
WRITEVECTOR(ivdr->centroid_norms);
|
|
1187
|
+
WRITEVECTOR(ivdr->centroid_scales);
|
|
1188
|
+
write_InvertedLists(ivdr->invlists, f);
|
|
1189
|
+
}
|
|
1190
|
+
#endif // FAISS_ENABLE_DISK_IVF
|
|
1075
1191
|
#ifdef FAISS_ENABLE_SVS
|
|
1076
1192
|
else if (
|
|
1077
1193
|
const IndexSVSVamana* svs =
|
|
@@ -1133,19 +1249,20 @@ void write_index(const Index* idx, IOWriter* f, int io_flags) {
|
|
|
1133
1249
|
WRITEVECTOR(svs->stored_vectors);
|
|
1134
1250
|
}
|
|
1135
1251
|
} else if (
|
|
1136
|
-
const IndexSVSFlat*
|
|
1252
|
+
const IndexSVSFlat* svs_flat =
|
|
1253
|
+
dynamic_cast<const IndexSVSFlat*>(idx)) {
|
|
1137
1254
|
uint32_t h = fourcc("ISVF");
|
|
1138
1255
|
WRITE1(h);
|
|
1139
1256
|
write_index_header(idx, f);
|
|
1140
1257
|
|
|
1141
|
-
bool initialized = (
|
|
1258
|
+
bool initialized = (svs_flat->impl != nullptr);
|
|
1142
1259
|
WRITE1(initialized);
|
|
1143
1260
|
if (initialized) {
|
|
1144
1261
|
// Wrap SVS I/O and stream to IOWriter
|
|
1145
1262
|
faiss::BufferedIOWriter bwr(f);
|
|
1146
1263
|
faiss::svs_io::WriterStreambuf wbuf(&bwr);
|
|
1147
1264
|
std::ostream os(&wbuf);
|
|
1148
|
-
|
|
1265
|
+
svs_flat->serialize_impl(os);
|
|
1149
1266
|
os.flush();
|
|
1150
1267
|
}
|
|
1151
1268
|
} else if (
|
|
@@ -1303,8 +1420,10 @@ static void write_binary_multi_hash_map(
|
|
|
1303
1420
|
int b,
|
|
1304
1421
|
size_t ntotal,
|
|
1305
1422
|
IOWriter* f) {
|
|
1423
|
+
// id_bits is also used to store the bucket sizes, which can be equal
|
|
1424
|
+
// to ntotal, so it must be able to represent ntotal itself.
|
|
1306
1425
|
int id_bits = 0;
|
|
1307
|
-
while (
|
|
1426
|
+
while (ntotal >= (size_t(1) << id_bits)) {
|
|
1308
1427
|
id_bits++;
|
|
1309
1428
|
}
|
|
1310
1429
|
WRITE1(id_bits);
|
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
#pragma once
|
|
9
9
|
|
|
10
|
+
#include <cerrno>
|
|
11
|
+
|
|
10
12
|
#include <faiss/impl/maybe_owned_vector.h>
|
|
11
13
|
|
|
12
14
|
/*************************************************************
|
|
@@ -73,7 +75,6 @@ size_t get_deserialization_vector_byte_limit();
|
|
|
73
75
|
size_t size; \
|
|
74
76
|
READANDCHECK(&size, 1); \
|
|
75
77
|
FAISS_THROW_IF_NOT( \
|
|
76
|
-
size >= 0 && \
|
|
77
78
|
size < (faiss::get_deserialization_vector_byte_limit() / \
|
|
78
79
|
sizeof(*(vec).data()))); \
|
|
79
80
|
FAISS_THROW_IF_NOT_FMT( \
|
|
@@ -122,7 +123,6 @@ size_t get_deserialization_vector_byte_limit();
|
|
|
122
123
|
size_t size; \
|
|
123
124
|
READANDCHECK(&size, 1); \
|
|
124
125
|
FAISS_THROW_IF_NOT( \
|
|
125
|
-
size >= 0 && \
|
|
126
126
|
size < (faiss::get_deserialization_vector_byte_limit() / \
|
|
127
127
|
(4 * sizeof(*(vec).data())))); \
|
|
128
128
|
size *= 4; \
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
#endif
|
|
22
22
|
|
|
23
|
+
#include <cerrno>
|
|
23
24
|
#include <cstring>
|
|
24
25
|
|
|
25
26
|
#include <faiss/impl/FaissAssert.h>
|
|
@@ -295,7 +296,8 @@ size_t MappedFileIOReader::mmap(void** ptr, size_t size, size_t nitems) {
|
|
|
295
296
|
actual_size = mmap_owner->size() - pos;
|
|
296
297
|
}
|
|
297
298
|
|
|
298
|
-
|
|
299
|
+
// Whole items only, so that reading a truncated vector fails.
|
|
300
|
+
size_t actual_nitems = actual_size / size;
|
|
299
301
|
if (actual_nitems == 0) {
|
|
300
302
|
return 0;
|
|
301
303
|
}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
+
|
|
7
8
|
#pragma once
|
|
8
9
|
|
|
9
10
|
#include <cstddef>
|
|
@@ -27,8 +28,8 @@ template <typename T>
|
|
|
27
28
|
struct MaybeOwnedVector {
|
|
28
29
|
using value_type = T;
|
|
29
30
|
using self_type = MaybeOwnedVector<T>;
|
|
30
|
-
using iterator =
|
|
31
|
-
using const_iterator =
|
|
31
|
+
using iterator = T*;
|
|
32
|
+
using const_iterator = const T*;
|
|
32
33
|
using size_type = typename std::vector<T>::size_type;
|
|
33
34
|
|
|
34
35
|
bool is_owned = true;
|
|
@@ -167,6 +168,14 @@ struct MaybeOwnedVector {
|
|
|
167
168
|
return c_size * sizeof(T);
|
|
168
169
|
}
|
|
169
170
|
|
|
171
|
+
bool empty() const {
|
|
172
|
+
return c_size == 0;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
size_t capacity() const {
|
|
176
|
+
return is_owned ? owned_data.capacity() : view_size;
|
|
177
|
+
}
|
|
178
|
+
|
|
170
179
|
T& operator[](const size_t idx) {
|
|
171
180
|
return c_ptr[idx];
|
|
172
181
|
}
|
|
@@ -175,81 +184,80 @@ struct MaybeOwnedVector {
|
|
|
175
184
|
return c_ptr[idx];
|
|
176
185
|
}
|
|
177
186
|
|
|
178
|
-
T&
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
"This operation cannot be performed on a viewed vector");
|
|
187
|
+
T& front() {
|
|
188
|
+
return c_ptr[0];
|
|
189
|
+
}
|
|
182
190
|
|
|
183
|
-
|
|
191
|
+
const T& front() const {
|
|
192
|
+
return c_ptr[0];
|
|
184
193
|
}
|
|
185
194
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
"This operation cannot be performed on a viewed vector");
|
|
195
|
+
T& back() {
|
|
196
|
+
return c_ptr[c_size - 1];
|
|
197
|
+
}
|
|
190
198
|
|
|
191
|
-
|
|
199
|
+
const T& back() const {
|
|
200
|
+
return c_ptr[c_size - 1];
|
|
192
201
|
}
|
|
193
202
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
203
|
+
T& at(const size_t pos) {
|
|
204
|
+
FAISS_THROW_IF_NOT_FMT(
|
|
205
|
+
pos < c_size, "index %zd out of range [0, %zd)", pos, c_size);
|
|
206
|
+
return c_ptr[pos];
|
|
207
|
+
}
|
|
198
208
|
|
|
199
|
-
|
|
209
|
+
const T& at(const size_t pos) const {
|
|
210
|
+
FAISS_THROW_IF_NOT_FMT(
|
|
211
|
+
pos < c_size, "index %zd out of range [0, %zd)", pos, c_size);
|
|
212
|
+
return c_ptr[pos];
|
|
200
213
|
}
|
|
201
214
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
"This operation cannot be performed on a viewed vector");
|
|
215
|
+
iterator begin() {
|
|
216
|
+
return c_ptr;
|
|
217
|
+
}
|
|
206
218
|
|
|
207
|
-
|
|
219
|
+
const_iterator begin() const {
|
|
220
|
+
return c_ptr;
|
|
208
221
|
}
|
|
209
222
|
|
|
210
223
|
iterator end() {
|
|
211
|
-
|
|
212
|
-
is_owned,
|
|
213
|
-
"This operation cannot be performed on a viewed vector");
|
|
214
|
-
|
|
215
|
-
return owned_data.end();
|
|
224
|
+
return c_ptr + c_size;
|
|
216
225
|
}
|
|
217
226
|
|
|
218
227
|
const_iterator end() const {
|
|
219
|
-
|
|
220
|
-
is_owned,
|
|
221
|
-
"This operation cannot be performed on a viewed vector");
|
|
222
|
-
|
|
223
|
-
return owned_data.end();
|
|
228
|
+
return c_ptr + c_size;
|
|
224
229
|
}
|
|
225
230
|
|
|
226
231
|
iterator erase(const_iterator begin, const_iterator end) {
|
|
227
|
-
|
|
232
|
+
FAISS_THROW_IF_NOT_MSG(
|
|
228
233
|
is_owned,
|
|
229
234
|
"This operation cannot be performed on a viewed vector");
|
|
230
235
|
|
|
231
|
-
auto
|
|
236
|
+
const auto first = owned_data.begin() + (begin - c_ptr);
|
|
237
|
+
const auto last = owned_data.begin() + (end - c_ptr);
|
|
238
|
+
const auto result = owned_data.erase(first, last);
|
|
232
239
|
c_ptr = owned_data.data();
|
|
233
240
|
c_size = owned_data.size();
|
|
234
241
|
|
|
235
|
-
return result;
|
|
242
|
+
return c_ptr + (result - owned_data.begin());
|
|
236
243
|
}
|
|
237
244
|
|
|
238
245
|
template <class InputIt>
|
|
239
246
|
iterator insert(const_iterator pos, InputIt first, InputIt last) {
|
|
240
|
-
|
|
247
|
+
FAISS_THROW_IF_NOT_MSG(
|
|
241
248
|
is_owned,
|
|
242
249
|
"This operation cannot be performed on a viewed vector");
|
|
243
250
|
|
|
244
|
-
auto result = owned_data.insert(
|
|
251
|
+
const auto result = owned_data.insert(
|
|
252
|
+
owned_data.begin() + (pos - c_ptr), first, last);
|
|
245
253
|
c_ptr = owned_data.data();
|
|
246
254
|
c_size = owned_data.size();
|
|
247
255
|
|
|
248
|
-
return result;
|
|
256
|
+
return c_ptr + (result - owned_data.begin());
|
|
249
257
|
}
|
|
250
258
|
|
|
251
259
|
void clear() {
|
|
252
|
-
|
|
260
|
+
FAISS_THROW_IF_NOT_MSG(
|
|
253
261
|
is_owned,
|
|
254
262
|
"This operation cannot be performed on a viewed vector");
|
|
255
263
|
|
|
@@ -259,7 +267,7 @@ struct MaybeOwnedVector {
|
|
|
259
267
|
}
|
|
260
268
|
|
|
261
269
|
void resize(const size_t new_size) {
|
|
262
|
-
|
|
270
|
+
FAISS_THROW_IF_NOT_MSG(
|
|
263
271
|
is_owned,
|
|
264
272
|
"This operation cannot be performed on a viewed vector");
|
|
265
273
|
|
|
@@ -269,7 +277,7 @@ struct MaybeOwnedVector {
|
|
|
269
277
|
}
|
|
270
278
|
|
|
271
279
|
void resize(const size_t new_size, const value_type v) {
|
|
272
|
-
|
|
280
|
+
FAISS_THROW_IF_NOT_MSG(
|
|
273
281
|
is_owned,
|
|
274
282
|
"This operation cannot be performed on a viewed vector");
|
|
275
283
|
|
|
@@ -278,6 +286,35 @@ struct MaybeOwnedVector {
|
|
|
278
286
|
c_size = owned_data.size();
|
|
279
287
|
}
|
|
280
288
|
|
|
289
|
+
void assign(const size_t new_size, const value_type v) {
|
|
290
|
+
FAISS_THROW_IF_NOT_MSG(
|
|
291
|
+
is_owned,
|
|
292
|
+
"This operation cannot be performed on a viewed vector");
|
|
293
|
+
|
|
294
|
+
owned_data.assign(new_size, v);
|
|
295
|
+
c_ptr = owned_data.data();
|
|
296
|
+
c_size = owned_data.size();
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
void push_back(const value_type v) {
|
|
300
|
+
FAISS_THROW_IF_NOT_MSG(
|
|
301
|
+
is_owned,
|
|
302
|
+
"This operation cannot be performed on a viewed vector");
|
|
303
|
+
|
|
304
|
+
owned_data.push_back(v);
|
|
305
|
+
c_ptr = owned_data.data();
|
|
306
|
+
c_size = owned_data.size();
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
void pop_back() {
|
|
310
|
+
FAISS_THROW_IF_NOT_MSG(
|
|
311
|
+
is_owned,
|
|
312
|
+
"This operation cannot be performed on a viewed vector");
|
|
313
|
+
|
|
314
|
+
owned_data.pop_back();
|
|
315
|
+
c_size = owned_data.size();
|
|
316
|
+
}
|
|
317
|
+
|
|
281
318
|
friend void swap(self_type& a, self_type& b) {
|
|
282
319
|
std::swap(a.is_owned, b.is_owned);
|
|
283
320
|
std::swap(a.owned_data, b.owned_data);
|
|
@@ -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/impl/nndescent/gram.h>
|
|
9
|
+
|
|
10
|
+
#include <algorithm>
|
|
11
|
+
#include <cmath>
|
|
12
|
+
|
|
13
|
+
#include <faiss/impl/simdlib/simdlib_avx2.h>
|
|
14
|
+
|
|
15
|
+
namespace faiss {
|
|
16
|
+
namespace nndescent {
|
|
17
|
+
|
|
18
|
+
using VF = simd8float32_tpl<SIMDLevel::AVX2>;
|
|
19
|
+
constexpr size_t W = sizeof(VF) / sizeof(float);
|
|
20
|
+
// tiles of RI x RJ entries: 12 accumulators and 4 operands fill the 16
|
|
21
|
+
// registers
|
|
22
|
+
constexpr int RI = 3, RJ = 4;
|
|
23
|
+
|
|
24
|
+
/** One tile, a block of I x J Gram matrix entries that the kernel computes
|
|
25
|
+
* together: out[i * ldo + j] = <a[i], b[j]> for i < I, j < J. Each vector
|
|
26
|
+
* that the kernel loads serves J or I products. Each product has its own
|
|
27
|
+
* accumulator, and the tail uses std::fma whatever the compiler contracts, so
|
|
28
|
+
* a product depends only on its two rows. */
|
|
29
|
+
template <int I, int J>
|
|
30
|
+
static void tile(
|
|
31
|
+
const float* const* a,
|
|
32
|
+
const float* const* b,
|
|
33
|
+
size_t d,
|
|
34
|
+
float* out,
|
|
35
|
+
size_t ldo) {
|
|
36
|
+
VF acc[I][J];
|
|
37
|
+
for (int i = 0; i < I; i++) {
|
|
38
|
+
for (int j = 0; j < J; j++) {
|
|
39
|
+
acc[i][j] = VF(0.0f);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
size_t k = 0;
|
|
43
|
+
for (; k + W <= d; k += W) {
|
|
44
|
+
VF x[I];
|
|
45
|
+
for (int i = 0; i < I; i++) {
|
|
46
|
+
x[i] = VF(a[i] + k);
|
|
47
|
+
}
|
|
48
|
+
for (int j = 0; j < J; j++) {
|
|
49
|
+
const VF y(b[j] + k);
|
|
50
|
+
for (int i = 0; i < I; i++) {
|
|
51
|
+
acc[i][j] = fmadd(x[i], y, acc[i][j]);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
for (int i = 0; i < I; i++) {
|
|
56
|
+
for (int j = 0; j < J; j++) {
|
|
57
|
+
float v = horizontal_add(acc[i][j]);
|
|
58
|
+
for (size_t t = k; t < d; t++) {
|
|
59
|
+
v = std::fma(a[i][t], b[j][t], v);
|
|
60
|
+
}
|
|
61
|
+
out[i * ldo + j] = v;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/// a tile of I x nj entries, nj <= J
|
|
67
|
+
template <int I, int J = RJ>
|
|
68
|
+
static void run_tile_cols(
|
|
69
|
+
int nj,
|
|
70
|
+
const float* const* a,
|
|
71
|
+
const float* const* b,
|
|
72
|
+
size_t d,
|
|
73
|
+
float* out,
|
|
74
|
+
size_t ldo) {
|
|
75
|
+
if constexpr (J > 1) {
|
|
76
|
+
if (nj < J) {
|
|
77
|
+
run_tile_cols<I, J - 1>(nj, a, b, d, out, ldo);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
tile<I, J>(a, b, d, out, ldo);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/// a tile of ni x nj entries, ni <= I, nj <= RJ
|
|
85
|
+
template <int I = RI>
|
|
86
|
+
static void run_tile(
|
|
87
|
+
int ni,
|
|
88
|
+
int nj,
|
|
89
|
+
const float* const* a,
|
|
90
|
+
const float* const* b,
|
|
91
|
+
size_t d,
|
|
92
|
+
float* out,
|
|
93
|
+
size_t ldo) {
|
|
94
|
+
if constexpr (I > 1) {
|
|
95
|
+
if (ni < I) {
|
|
96
|
+
run_tile<I - 1>(ni, nj, a, b, d, out, ldo);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
run_tile_cols<I>(nj, a, b, d, out, ldo);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
template <>
|
|
104
|
+
void gram_upper_rows<SIMDLevel::AVX2>(
|
|
105
|
+
const float* const* rows,
|
|
106
|
+
size_t r,
|
|
107
|
+
size_t m,
|
|
108
|
+
size_t d,
|
|
109
|
+
float* out) {
|
|
110
|
+
// rows i0 .. i0 + RI - 1 against the rows j > i0, tile by tile
|
|
111
|
+
for (size_t i0 = 0; i0 < r; i0 += RI) {
|
|
112
|
+
const int ni = int(std::min<size_t>(RI, r - i0));
|
|
113
|
+
for (size_t j = i0 + 1; j < m; j += RJ) {
|
|
114
|
+
const int nj = int(std::min<size_t>(RJ, m - j));
|
|
115
|
+
run_tile(ni, nj, rows + i0, rows + j, d, out + i0 * m + j, m);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
} // namespace nndescent
|
|
121
|
+
} // namespace faiss
|