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
|
@@ -19,7 +19,7 @@ namespace pq_code_distance {
|
|
|
19
19
|
|
|
20
20
|
namespace {
|
|
21
21
|
|
|
22
|
-
template <class C>
|
|
22
|
+
template <class C, class PQCodeDist>
|
|
23
23
|
void pq_scan_8bit_at_level(
|
|
24
24
|
size_t M,
|
|
25
25
|
const float* dis_table,
|
|
@@ -33,8 +33,9 @@ void pq_scan_8bit_at_level(
|
|
|
33
33
|
size_t j = 0;
|
|
34
34
|
for (; j + 3 < ncodes; j += 4) {
|
|
35
35
|
float d0, d1, d2, d3;
|
|
36
|
-
|
|
36
|
+
PQCodeDist::distance_four_codes(
|
|
37
37
|
M,
|
|
38
|
+
8,
|
|
38
39
|
dis_table,
|
|
39
40
|
codes + j * code_size,
|
|
40
41
|
codes + (j + 1) * code_size,
|
|
@@ -60,8 +61,8 @@ void pq_scan_8bit_at_level(
|
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
for (; j < ncodes; j++) {
|
|
63
|
-
float dis =
|
|
64
|
-
M, dis_table, codes + j * code_size);
|
|
64
|
+
float dis = PQCodeDist::distance_single_code(
|
|
65
|
+
M, 8, dis_table, codes + j * code_size);
|
|
65
66
|
if (C::cmp(heap_dis[0], dis)) {
|
|
66
67
|
heap_replace_top<C>(k, heap_dis, heap_ids, dis, j);
|
|
67
68
|
}
|
|
@@ -92,13 +93,23 @@ void pq_scan_8bit_impl<THE_SIMD_LEVEL>(
|
|
|
92
93
|
float* heap_dis,
|
|
93
94
|
int64_t* heap_ids,
|
|
94
95
|
bool max_heap) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
96
|
+
auto scan = [&]<class PQCodeDist>() {
|
|
97
|
+
if (max_heap) {
|
|
98
|
+
pq_scan_8bit_at_level<CMax<float, int64_t>, PQCodeDist>(
|
|
99
|
+
M, dis_table, codes, ncodes, k, heap_dis, heap_ids);
|
|
100
|
+
} else {
|
|
101
|
+
pq_scan_8bit_at_level<CMin<float, int64_t>, PQCodeDist>(
|
|
102
|
+
M, dis_table, codes, ncodes, k, heap_dis, heap_ids);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
if constexpr (has_scalar_8bit_kernel<THE_SIMD_LEVEL>()) {
|
|
106
|
+
if (use_scalar_8bit_kernel<THE_SIMD_LEVEL>(M)) {
|
|
107
|
+
scan.template
|
|
108
|
+
operator()<PQCodeDistanceScalar8Dist<THE_SIMD_LEVEL>>();
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
101
111
|
}
|
|
112
|
+
scan.template operator()<PQCodeDistance<PQDecoder8, THE_SIMD_LEVEL>>();
|
|
102
113
|
}
|
|
103
114
|
|
|
104
115
|
} // namespace pq_code_distance
|
|
@@ -5,14 +5,15 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
#
|
|
8
|
+
#include <riscv_vector.h>
|
|
9
9
|
|
|
10
10
|
#include <faiss/impl/pq_code_distance/pq_code_distance-inl.h>
|
|
11
|
+
#include <faiss/impl/pq_code_distance/pq_rvv_kernel.h>
|
|
11
12
|
|
|
12
13
|
namespace faiss {
|
|
13
14
|
namespace pq_code_distance {
|
|
14
15
|
|
|
15
|
-
//
|
|
16
|
+
// The kernel lives in pq_rvv_kernel.h. See that header for the gather layout.
|
|
16
17
|
|
|
17
18
|
// NOLINTNEXTLINE(facebook-hte-MisplacedTemplateSpecialization)
|
|
18
19
|
template <>
|
|
@@ -20,8 +21,7 @@ float pq_code_distance_8bit_single_impl<SIMDLevel::RISCV_RVV>(
|
|
|
20
21
|
size_t M,
|
|
21
22
|
const float* sim_table,
|
|
22
23
|
const uint8_t* code) {
|
|
23
|
-
return
|
|
24
|
-
M, 8, sim_table, code);
|
|
24
|
+
return pq_rvv_kernel::distance_8bit(M, sim_table, code);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
// NOLINTNEXTLINE(facebook-hte-MisplacedTemplateSpecialization)
|
|
@@ -37,18 +37,47 @@ void pq_code_distance_8bit_four_impl<SIMDLevel::RISCV_RVV>(
|
|
|
37
37
|
float& result1,
|
|
38
38
|
float& result2,
|
|
39
39
|
float& result3) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
40
|
+
const size_t vlmax = __riscv_vsetvlmax_e32m4();
|
|
41
|
+
vfloat32m4_t acc0 = __riscv_vfmv_v_f_f32m4(0.0f, vlmax);
|
|
42
|
+
vfloat32m4_t acc1 = __riscv_vfmv_v_f_f32m4(0.0f, vlmax);
|
|
43
|
+
vfloat32m4_t acc2 = __riscv_vfmv_v_f_f32m4(0.0f, vlmax);
|
|
44
|
+
vfloat32m4_t acc3 = __riscv_vfmv_v_f_f32m4(0.0f, vlmax);
|
|
45
|
+
|
|
46
|
+
size_t m = 0;
|
|
47
|
+
while (m < M) {
|
|
48
|
+
const size_t vl = __riscv_vsetvl_e32m4(M - m);
|
|
49
|
+
// The row term is the same for all four codes, so compute it once.
|
|
50
|
+
vuint32m4_t row_off = pq_rvv_kernel::row_offsets(m, vl);
|
|
51
|
+
|
|
52
|
+
vfloat32m4_t v0 = __riscv_vluxei32_v_f32m4(
|
|
53
|
+
sim_table,
|
|
54
|
+
pq_rvv_kernel::byte_offsets(row_off, code0, m, vl),
|
|
55
|
+
vl);
|
|
56
|
+
vfloat32m4_t v1 = __riscv_vluxei32_v_f32m4(
|
|
57
|
+
sim_table,
|
|
58
|
+
pq_rvv_kernel::byte_offsets(row_off, code1, m, vl),
|
|
59
|
+
vl);
|
|
60
|
+
vfloat32m4_t v2 = __riscv_vluxei32_v_f32m4(
|
|
61
|
+
sim_table,
|
|
62
|
+
pq_rvv_kernel::byte_offsets(row_off, code2, m, vl),
|
|
63
|
+
vl);
|
|
64
|
+
vfloat32m4_t v3 = __riscv_vluxei32_v_f32m4(
|
|
65
|
+
sim_table,
|
|
66
|
+
pq_rvv_kernel::byte_offsets(row_off, code3, m, vl),
|
|
67
|
+
vl);
|
|
68
|
+
|
|
69
|
+
acc0 = __riscv_vfadd_vv_f32m4_tu(acc0, acc0, v0, vl);
|
|
70
|
+
acc1 = __riscv_vfadd_vv_f32m4_tu(acc1, acc1, v1, vl);
|
|
71
|
+
acc2 = __riscv_vfadd_vv_f32m4_tu(acc2, acc2, v2, vl);
|
|
72
|
+
acc3 = __riscv_vfadd_vv_f32m4_tu(acc3, acc3, v3, vl);
|
|
73
|
+
|
|
74
|
+
m += vl;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
result0 = pq_rvv_kernel::reduce(acc0, vlmax);
|
|
78
|
+
result1 = pq_rvv_kernel::reduce(acc1, vlmax);
|
|
79
|
+
result2 = pq_rvv_kernel::reduce(acc2, vlmax);
|
|
80
|
+
result3 = pq_rvv_kernel::reduce(acc3, vlmax);
|
|
52
81
|
}
|
|
53
82
|
|
|
54
83
|
} // namespace pq_code_distance
|
|
@@ -66,5 +95,3 @@ void pq_code_distance_8bit_four_impl<SIMDLevel::RISCV_RVV>(
|
|
|
66
95
|
#include <faiss/impl/pq_code_distance/IVFPQScanner_impl.h>
|
|
67
96
|
|
|
68
97
|
#undef THE_SIMD_LEVEL
|
|
69
|
-
|
|
70
|
-
#endif // COMPILE_SIMD_RISCV_RVV
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
#include <faiss/impl/approx_topk/approx_topk.h>
|
|
19
19
|
#include <faiss/impl/approx_topk/rq_beam_search_tab.h>
|
|
20
|
+
#include <faiss/impl/platform_macros.h>
|
|
20
21
|
|
|
21
22
|
extern "C" {
|
|
22
23
|
|
|
@@ -367,7 +368,7 @@ void beam_search_encode_step_tab(
|
|
|
367
368
|
|
|
368
369
|
// Resolve SIMD level once, not per iteration of the n-parallel loop.
|
|
369
370
|
with_simd_level_256bit([&]<SIMDLevel SL>() {
|
|
370
|
-
#pragma omp parallel for if (n > 100) schedule(
|
|
371
|
+
#pragma omp parallel for if (n > 100) schedule(FAISS_OMP_DYNAMIC)
|
|
371
372
|
for (int64_t i = 0; i < static_cast<int64_t>(n); i++) {
|
|
372
373
|
std::vector<float> cent_distances(beam_size * K);
|
|
373
374
|
std::vector<float> cd_common(K);
|
|
@@ -22,6 +22,12 @@ namespace faiss {
|
|
|
22
22
|
constexpr int TOP1_SIMD_LEVELS = (1 << int(SIMDLevel::NONE)) |
|
|
23
23
|
(1 << int(SIMDLevel::AVX2)) | (1 << int(SIMDLevel::AVX512));
|
|
24
24
|
|
|
25
|
+
// Top-2: scalar fallback + AVX2 (8 lanes of best and second best), for CMax
|
|
26
|
+
// only: the AVX2 lanes keep the first of equal distances, which matches the
|
|
27
|
+
// CMax order of ids but not the CMin one.
|
|
28
|
+
constexpr int TOP2_SIMD_LEVELS =
|
|
29
|
+
(1 << int(SIMDLevel::NONE)) | (1 << int(SIMDLevel::AVX2));
|
|
30
|
+
|
|
25
31
|
// Reservoir: scalar fallback + AVX512 compress path.
|
|
26
32
|
// VPCOMPRESSPS/VPCOMPRESSD require AVX512F so there is no AVX2 path.
|
|
27
33
|
// On non-AVX512 hosts the dispatch falls back to NONE automatically.
|
|
@@ -43,7 +49,8 @@ void top1_add_results_none(
|
|
|
43
49
|
using T = typename C::T;
|
|
44
50
|
using TI = typename C::TI;
|
|
45
51
|
|
|
46
|
-
|
|
52
|
+
#pragma omp parallel for if (self->i1 - self->i0 >= 16)
|
|
53
|
+
for (int64_t qi = self->i0; qi < static_cast<int64_t>(self->i1); qi++) {
|
|
47
54
|
const T* dis_tab_i = dis_tab_in + (j1 - j0) * (qi - self->i0) - j0;
|
|
48
55
|
|
|
49
56
|
// Hoist best_dis / best_idx into locals so the compiler keeps them in
|
|
@@ -63,6 +70,26 @@ void top1_add_results_none(
|
|
|
63
70
|
}
|
|
64
71
|
}
|
|
65
72
|
|
|
73
|
+
template <class C, bool use_sel>
|
|
74
|
+
void top2_add_results_none(
|
|
75
|
+
Top2BlockResultHandler<C, use_sel>* self,
|
|
76
|
+
size_t j0,
|
|
77
|
+
size_t j1,
|
|
78
|
+
const float* dis_tab_in) {
|
|
79
|
+
using TI = typename C::TI;
|
|
80
|
+
#pragma omp parallel for if (self->i1 - self->i0 >= 16)
|
|
81
|
+
for (int64_t qi = self->i0; qi < static_cast<int64_t>(self->i1); qi++) {
|
|
82
|
+
const float* dis_tab_i = dis_tab_in + (j1 - j0) * (qi - self->i0) - j0;
|
|
83
|
+
float* dis2 = self->dis_tab + 2 * qi;
|
|
84
|
+
TI* ids2 = self->ids_tab + 2 * qi;
|
|
85
|
+
for (size_t j = j0; j < j1; j++) {
|
|
86
|
+
if (C::cmp(dis2[1], dis_tab_i[j]) && self->is_in_selection(j)) {
|
|
87
|
+
top2_insert<C>(dis_tab_i[j], TI(j), dis2, ids2);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
66
93
|
template <class C, bool use_sel>
|
|
67
94
|
void reservoir_add_results_none(
|
|
68
95
|
ReservoirBlockResultHandler<C, use_sel>* self,
|
|
@@ -119,6 +146,14 @@ void reservoir_add_results_none(
|
|
|
119
146
|
top1_add_results_none<C, use_sel>(self, j0, j1, dis_tab); \
|
|
120
147
|
} \
|
|
121
148
|
template <> \
|
|
149
|
+
void top2_add_results_tpl<C, use_sel, SIMDLevel::NONE>( \
|
|
150
|
+
Top2BlockResultHandler<C, use_sel> * self, \
|
|
151
|
+
size_t j0, \
|
|
152
|
+
size_t j1, \
|
|
153
|
+
const float* dis_tab) { \
|
|
154
|
+
top2_add_results_none<C, use_sel>(self, j0, j1, dis_tab); \
|
|
155
|
+
} \
|
|
156
|
+
template <> \
|
|
122
157
|
void reservoir_add_results_tpl<C, use_sel, SIMDLevel::NONE>( \
|
|
123
158
|
ReservoirBlockResultHandler<C, use_sel> * self, \
|
|
124
159
|
size_t j0, \
|
|
@@ -152,6 +187,21 @@ void Top1BlockResultHandler<C, use_sel>::add_results(
|
|
|
152
187
|
});
|
|
153
188
|
}
|
|
154
189
|
|
|
190
|
+
template <class C, bool use_sel>
|
|
191
|
+
void Top2BlockResultHandler<C, use_sel>::add_results(
|
|
192
|
+
size_t j0,
|
|
193
|
+
size_t j1,
|
|
194
|
+
const T* dis_tab_2) {
|
|
195
|
+
if constexpr (use_sel || !C::is_max) {
|
|
196
|
+
top2_add_results_tpl<C, use_sel, SIMDLevel::NONE>(
|
|
197
|
+
this, j0, j1, dis_tab_2);
|
|
198
|
+
} else {
|
|
199
|
+
with_selected_simd_levels<TOP2_SIMD_LEVELS>([&]<SIMDLevel SL>() {
|
|
200
|
+
top2_add_results_tpl<C, use_sel, SL>(this, j0, j1, dis_tab_2);
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
155
205
|
template <class C, bool use_sel>
|
|
156
206
|
void ReservoirBlockResultHandler<C, use_sel>::add_results(
|
|
157
207
|
size_t j0,
|
|
@@ -183,6 +233,23 @@ template void Top1BlockResultHandler<CMin<float, int64_t>, true>::add_results(
|
|
|
183
233
|
size_t,
|
|
184
234
|
const float*);
|
|
185
235
|
|
|
236
|
+
template void Top2BlockResultHandler<CMax<float, int64_t>, false>::add_results(
|
|
237
|
+
size_t,
|
|
238
|
+
size_t,
|
|
239
|
+
const float*);
|
|
240
|
+
template void Top2BlockResultHandler<CMax<float, int64_t>, true>::add_results(
|
|
241
|
+
size_t,
|
|
242
|
+
size_t,
|
|
243
|
+
const float*);
|
|
244
|
+
template void Top2BlockResultHandler<CMin<float, int64_t>, false>::add_results(
|
|
245
|
+
size_t,
|
|
246
|
+
size_t,
|
|
247
|
+
const float*);
|
|
248
|
+
template void Top2BlockResultHandler<CMin<float, int64_t>, true>::add_results(
|
|
249
|
+
size_t,
|
|
250
|
+
size_t,
|
|
251
|
+
const float*);
|
|
252
|
+
|
|
186
253
|
template void ReservoirBlockResultHandler<CMax<float, int64_t>, false>::
|
|
187
254
|
add_results(size_t, size_t, const float*);
|
|
188
255
|
template void ReservoirBlockResultHandler<CMax<float, int64_t>, true>::
|
|
@@ -5,11 +5,10 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
// AVX2
|
|
8
|
+
// AVX2 specialisations of Top1 add_results (8-wide branchless argmin/argmax)
|
|
9
|
+
// and Top2 add_results for CMax (8 lanes of best and second best).
|
|
9
10
|
// Reservoir stays on the NONE path — VPCOMPRESSPS requires AVX512F.
|
|
10
11
|
|
|
11
|
-
#ifdef COMPILE_SIMD_AVX2
|
|
12
|
-
|
|
13
12
|
#include <faiss/impl/ResultHandler.h>
|
|
14
13
|
|
|
15
14
|
#include <immintrin.h>
|
|
@@ -33,7 +32,8 @@ void top1_add_results_avx2(
|
|
|
33
32
|
using TI = typename C::TI;
|
|
34
33
|
const __m256i vstep = _mm256_setr_epi32(0, 1, 2, 3, 4, 5, 6, 7);
|
|
35
34
|
|
|
36
|
-
|
|
35
|
+
#pragma omp parallel for if (self->i1 - self->i0 >= 16)
|
|
36
|
+
for (int64_t qi = self->i0; qi < static_cast<int64_t>(self->i1); qi++) {
|
|
37
37
|
const float* dis_tab_i = dis_tab_in + (j1 - j0) * (qi - self->i0) - j0;
|
|
38
38
|
|
|
39
39
|
// Hoist best_dis / best_idx into locals so the compiler keeps them in
|
|
@@ -88,10 +88,76 @@ void top1_add_results_avx2(
|
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
/// AVX2 Top2 add_results for L2: each lane keeps its best and second best
|
|
92
|
+
/// with strict comparisons (the first of equal distances, NaN never), then
|
|
93
|
+
/// the lanes and the tail are merged into the query's pair, lower id first.
|
|
94
|
+
template <class C>
|
|
95
|
+
void top2_add_results_avx2(
|
|
96
|
+
Top2BlockResultHandler<C, false>* self,
|
|
97
|
+
size_t j0,
|
|
98
|
+
size_t j1,
|
|
99
|
+
const float* dis_tab_in) {
|
|
100
|
+
using TI = typename C::TI;
|
|
101
|
+
const size_t n = j1 - j0;
|
|
102
|
+
#pragma omp parallel for if (self->i1 - self->i0 >= 16)
|
|
103
|
+
for (int64_t qi = self->i0; qi < static_cast<int64_t>(self->i1); qi++) {
|
|
104
|
+
const float* dis_tab_i = dis_tab_in + n * (qi - self->i0);
|
|
105
|
+
float* dis2 = self->dis_tab + 2 * qi;
|
|
106
|
+
TI* ids2 = self->ids_tab + 2 * qi;
|
|
107
|
+
__m256 m1 = _mm256_set1_ps(C::neutral()), m2 = m1;
|
|
108
|
+
__m256i a1 = _mm256_set1_epi32(-1), a2 = a1;
|
|
109
|
+
__m256i current = _mm256_setr_epi32(0, 1, 2, 3, 4, 5, 6, 7);
|
|
110
|
+
size_t j = 0;
|
|
111
|
+
for (; j + 8 <= n; j += 8) {
|
|
112
|
+
const __m256 s = _mm256_loadu_ps(dis_tab_i + j);
|
|
113
|
+
const __m256 first = _mm256_cmp_ps(s, m1, _CMP_LT_OQ);
|
|
114
|
+
const __m256 second = _mm256_cmp_ps(s, m2, _CMP_LT_OQ);
|
|
115
|
+
m2 = _mm256_min_ps(_mm256_max_ps(m1, s), m2);
|
|
116
|
+
m1 = _mm256_min_ps(s, m1);
|
|
117
|
+
const __m256 offered = _mm256_blendv_ps(
|
|
118
|
+
_mm256_castsi256_ps(current),
|
|
119
|
+
_mm256_castsi256_ps(a1),
|
|
120
|
+
first);
|
|
121
|
+
a2 = _mm256_castps_si256(
|
|
122
|
+
_mm256_blendv_ps(_mm256_castsi256_ps(a2), offered, second));
|
|
123
|
+
a1 = _mm256_castps_si256(_mm256_blendv_ps(
|
|
124
|
+
_mm256_castsi256_ps(a1),
|
|
125
|
+
_mm256_castsi256_ps(current),
|
|
126
|
+
first));
|
|
127
|
+
current = _mm256_add_epi32(current, _mm256_set1_epi32(8));
|
|
128
|
+
}
|
|
129
|
+
alignas(32) float lane_dis[16];
|
|
130
|
+
alignas(32) int32_t lane_ids[16];
|
|
131
|
+
_mm256_store_ps(lane_dis, m1);
|
|
132
|
+
_mm256_store_ps(lane_dis + 8, m2);
|
|
133
|
+
_mm256_store_si256((__m256i*)lane_ids, a1);
|
|
134
|
+
_mm256_store_si256((__m256i*)(lane_ids + 8), a2);
|
|
135
|
+
for (int l = 0; l < 16; l++) {
|
|
136
|
+
if (lane_ids[l] >= 0) {
|
|
137
|
+
top2_insert<C>(lane_dis[l], TI(j0 + lane_ids[l]), dis2, ids2);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
for (; j < n; j++) {
|
|
141
|
+
if (C::cmp(dis2[1], dis_tab_i[j])) {
|
|
142
|
+
top2_insert<C>(dis_tab_i[j], TI(j0 + j), dis2, ids2);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
91
148
|
} // namespace
|
|
92
149
|
|
|
93
150
|
// Explicit specialisations for AVX2
|
|
94
151
|
|
|
152
|
+
template <>
|
|
153
|
+
void top2_add_results_tpl<CMax<float, int64_t>, false, SIMDLevel::AVX2>(
|
|
154
|
+
Top2BlockResultHandler<CMax<float, int64_t>, false>* self,
|
|
155
|
+
size_t j0,
|
|
156
|
+
size_t j1,
|
|
157
|
+
const float* dis_tab) {
|
|
158
|
+
top2_add_results_avx2<CMax<float, int64_t>>(self, j0, j1, dis_tab);
|
|
159
|
+
}
|
|
160
|
+
|
|
95
161
|
template <>
|
|
96
162
|
void top1_add_results_tpl<CMax<float, int64_t>, false, SIMDLevel::AVX2>(
|
|
97
163
|
Top1BlockResultHandler<CMax<float, int64_t>, false>* self,
|
|
@@ -129,5 +195,3 @@ void top1_add_results_tpl<CMin<float, int64_t>, true, SIMDLevel::AVX2>(
|
|
|
129
195
|
}
|
|
130
196
|
|
|
131
197
|
} // namespace faiss
|
|
132
|
-
|
|
133
|
-
#endif // COMPILE_SIMD_AVX2
|
|
@@ -11,8 +11,6 @@
|
|
|
11
11
|
// Reservoir: VPCOMPRESSPS / VPCOMPRESSD bulk-insert of passing elements,
|
|
12
12
|
// eliminating the per-element threshold branch entirely.
|
|
13
13
|
|
|
14
|
-
#ifdef COMPILE_SIMD_AVX512
|
|
15
|
-
|
|
16
14
|
#include <faiss/impl/ResultHandler.h>
|
|
17
15
|
#include <faiss/utils/popcount.h>
|
|
18
16
|
|
|
@@ -38,7 +36,8 @@ void top1_add_results_avx512(
|
|
|
38
36
|
const __m512i vstep = _mm512_set_epi32(
|
|
39
37
|
15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0);
|
|
40
38
|
|
|
41
|
-
|
|
39
|
+
#pragma omp parallel for if (self->i1 - self->i0 >= 16)
|
|
40
|
+
for (int64_t qi = self->i0; qi < static_cast<int64_t>(self->i1); qi++) {
|
|
42
41
|
const float* dis_tab_i = dis_tab_in + (j1 - j0) * (qi - self->i0) - j0;
|
|
43
42
|
|
|
44
43
|
// Hoist best_dis / best_idx into locals so the compiler keeps them in
|
|
@@ -277,5 +276,3 @@ void reservoir_add_results_tpl<CMin<float, int64_t>, true, SIMDLevel::AVX512>(
|
|
|
277
276
|
}
|
|
278
277
|
|
|
279
278
|
} // namespace faiss
|
|
280
|
-
|
|
281
|
-
#endif // COMPILE_SIMD_AVX512
|
|
@@ -5,8 +5,6 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
#ifdef COMPILE_SIMD_AVX2
|
|
9
|
-
|
|
10
8
|
#include <faiss/impl/EDENQuantizer.h>
|
|
11
9
|
#include <faiss/impl/simdlib/simdlib_avx2.h>
|
|
12
10
|
|
|
@@ -68,5 +66,3 @@ void compute_code_dot_lut_batch_8_avx2(
|
|
|
68
66
|
} // namespace eden_distance
|
|
69
67
|
|
|
70
68
|
} // namespace faiss
|
|
71
|
-
|
|
72
|
-
#endif
|
|
@@ -5,8 +5,6 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
#ifdef COMPILE_SIMD_AVX512
|
|
9
|
-
|
|
10
8
|
#include <faiss/impl/EDENQuantizer.h>
|
|
11
9
|
#include <faiss/impl/simdlib/simdlib_avx2.h>
|
|
12
10
|
#include <faiss/impl/simdlib/simdlib_avx512.h>
|
|
@@ -224,5 +222,3 @@ void compute_code_dot_lut_batch_16_avx512(
|
|
|
224
222
|
} // namespace eden_distance
|
|
225
223
|
|
|
226
224
|
} // namespace faiss
|
|
227
|
-
|
|
228
|
-
#endif
|
|
@@ -508,7 +508,7 @@ EDENFlatCodesDistanceComputer* make_reference_distance_computer(
|
|
|
508
508
|
return dc.release();
|
|
509
509
|
}
|
|
510
510
|
|
|
511
|
-
EDENFlatCodesDistanceComputer* make_optimized_distance_computer(
|
|
511
|
+
[[maybe_unused]] EDENFlatCodesDistanceComputer* make_optimized_distance_computer(
|
|
512
512
|
MetricType metric_type,
|
|
513
513
|
size_t d,
|
|
514
514
|
size_t nb_bits,
|
|
@@ -22,7 +22,11 @@ using SQDistanceComputer = ScalarQuantizer::SQDistanceComputer;
|
|
|
22
22
|
* code-to-vector or code-to-code comparisons
|
|
23
23
|
*******************************************************************/
|
|
24
24
|
|
|
25
|
-
template <
|
|
25
|
+
template <
|
|
26
|
+
class Quantizer,
|
|
27
|
+
class Similarity,
|
|
28
|
+
SIMDLevel SL,
|
|
29
|
+
bool four_acc = false>
|
|
26
30
|
struct DCTemplate : SQDistanceComputer {};
|
|
27
31
|
|
|
28
32
|
template <class Quantizer, class Similarity>
|
|
@@ -149,11 +149,11 @@ struct QuantizerTemplate<
|
|
|
149
149
|
/*******************************************************************
|
|
150
150
|
* Lloyd-Max scalar quantizer
|
|
151
151
|
*******************************************************************/
|
|
152
|
+
// Each QuantizerXBase<SL> holds the scalar code of a quantizer. It takes the
|
|
153
|
+
// SIMD level of the file that uses it, so each per-level file compiles its own
|
|
154
|
+
// copy under its own name.
|
|
152
155
|
template <int NBits, SIMDLevel SL>
|
|
153
|
-
struct
|
|
154
|
-
|
|
155
|
-
template <int NBits>
|
|
156
|
-
struct QuantizerLloydMax<NBits, SIMDLevel::NONE> : ScalarQuantizer::SQuantizer {
|
|
156
|
+
struct QuantizerLloydMaxBase : ScalarQuantizer::SQuantizer {
|
|
157
157
|
static_assert(NBits >= 1 && NBits <= 8);
|
|
158
158
|
|
|
159
159
|
static constexpr size_t kCentroidsCount = size_t(1) << NBits;
|
|
@@ -164,7 +164,7 @@ struct QuantizerLloydMax<NBits, SIMDLevel::NONE> : ScalarQuantizer::SQuantizer {
|
|
|
164
164
|
const float* centroids;
|
|
165
165
|
const float* boundaries;
|
|
166
166
|
|
|
167
|
-
|
|
167
|
+
QuantizerLloydMaxBase(size_t d_in, const std::vector<float>& trained)
|
|
168
168
|
: d(d_in), centroids(nullptr), boundaries(nullptr) {
|
|
169
169
|
FAISS_THROW_IF_NOT(trained.size() == 2 * kCentroidsCount - 1);
|
|
170
170
|
centroids = trained.data();
|
|
@@ -220,8 +220,8 @@ struct QuantizerLloydMax<NBits, SIMDLevel::NONE> : ScalarQuantizer::SQuantizer {
|
|
|
220
220
|
};
|
|
221
221
|
|
|
222
222
|
template <int NBits, SIMDLevel SL>
|
|
223
|
-
struct QuantizerLloydMax :
|
|
224
|
-
using
|
|
223
|
+
struct QuantizerLloydMax : QuantizerLloydMaxBase<NBits, SL> {
|
|
224
|
+
using QuantizerLloydMaxBase<NBits, SL>::QuantizerLloydMaxBase;
|
|
225
225
|
};
|
|
226
226
|
|
|
227
227
|
template <int NBits, SIMDLevel SL>
|
|
@@ -232,13 +232,10 @@ using QuantizerTurboQuantMSE = QuantizerLloydMax<NBits, SL>;
|
|
|
232
232
|
*******************************************************************/
|
|
233
233
|
|
|
234
234
|
template <SIMDLevel SL>
|
|
235
|
-
struct
|
|
236
|
-
|
|
237
|
-
template <>
|
|
238
|
-
struct QuantizerFP16<SIMDLevel::NONE> : ScalarQuantizer::SQuantizer {
|
|
235
|
+
struct QuantizerFP16Base : ScalarQuantizer::SQuantizer {
|
|
239
236
|
const size_t d;
|
|
240
237
|
|
|
241
|
-
|
|
238
|
+
QuantizerFP16Base(size_t d_in, const std::vector<float>& /* unused */)
|
|
242
239
|
: d(d_in) {}
|
|
243
240
|
|
|
244
241
|
void encode_vector(const float* x, uint8_t* code) const final {
|
|
@@ -247,7 +244,7 @@ struct QuantizerFP16<SIMDLevel::NONE> : ScalarQuantizer::SQuantizer {
|
|
|
247
244
|
}
|
|
248
245
|
}
|
|
249
246
|
|
|
250
|
-
void decode_vector(const uint8_t* code, float* x) const
|
|
247
|
+
void decode_vector(const uint8_t* code, float* x) const override {
|
|
251
248
|
for (size_t i = 0; i < d; i++) {
|
|
252
249
|
x[i] = decode_fp16(((uint16_t*)code)[i]);
|
|
253
250
|
}
|
|
@@ -261,8 +258,8 @@ struct QuantizerFP16<SIMDLevel::NONE> : ScalarQuantizer::SQuantizer {
|
|
|
261
258
|
};
|
|
262
259
|
|
|
263
260
|
template <SIMDLevel SL>
|
|
264
|
-
struct QuantizerFP16 :
|
|
265
|
-
using
|
|
261
|
+
struct QuantizerFP16 : QuantizerFP16Base<SL> {
|
|
262
|
+
using QuantizerFP16Base<SL>::QuantizerFP16Base;
|
|
266
263
|
};
|
|
267
264
|
|
|
268
265
|
/*******************************************************************
|
|
@@ -270,13 +267,10 @@ struct QuantizerFP16 : QuantizerFP16<SIMDLevel::NONE> {
|
|
|
270
267
|
*******************************************************************/
|
|
271
268
|
|
|
272
269
|
template <SIMDLevel SL>
|
|
273
|
-
struct
|
|
274
|
-
|
|
275
|
-
template <>
|
|
276
|
-
struct QuantizerBF16<SIMDLevel::NONE> : ScalarQuantizer::SQuantizer {
|
|
270
|
+
struct QuantizerBF16Base : ScalarQuantizer::SQuantizer {
|
|
277
271
|
const size_t d;
|
|
278
272
|
|
|
279
|
-
|
|
273
|
+
QuantizerBF16Base(size_t d_in, const std::vector<float>& /* unused */)
|
|
280
274
|
: d(d_in) {}
|
|
281
275
|
|
|
282
276
|
void encode_vector(const float* x, uint8_t* code) const override {
|
|
@@ -295,8 +289,8 @@ struct QuantizerBF16<SIMDLevel::NONE> : ScalarQuantizer::SQuantizer {
|
|
|
295
289
|
};
|
|
296
290
|
|
|
297
291
|
template <SIMDLevel SL>
|
|
298
|
-
struct QuantizerBF16 :
|
|
299
|
-
using
|
|
292
|
+
struct QuantizerBF16 : QuantizerBF16Base<SL> {
|
|
293
|
+
using QuantizerBF16Base<SL>::QuantizerBF16Base;
|
|
300
294
|
};
|
|
301
295
|
|
|
302
296
|
template <>
|
|
@@ -309,22 +303,19 @@ struct QuantizerBF16<SIMDLevel::AVX512_SPR>;
|
|
|
309
303
|
*******************************************************************/
|
|
310
304
|
|
|
311
305
|
template <SIMDLevel SL>
|
|
312
|
-
struct
|
|
313
|
-
|
|
314
|
-
template <>
|
|
315
|
-
struct Quantizer8bitDirect<SIMDLevel::NONE> : ScalarQuantizer::SQuantizer {
|
|
306
|
+
struct Quantizer8bitDirectBase : ScalarQuantizer::SQuantizer {
|
|
316
307
|
const size_t d;
|
|
317
308
|
|
|
318
|
-
|
|
309
|
+
Quantizer8bitDirectBase(size_t d_in, const std::vector<float>& /* unused */)
|
|
319
310
|
: d(d_in) {}
|
|
320
311
|
|
|
321
|
-
void encode_vector(const float* x, uint8_t* code) const
|
|
312
|
+
void encode_vector(const float* x, uint8_t* code) const override {
|
|
322
313
|
for (size_t i = 0; i < d; i++) {
|
|
323
314
|
code[i] = (uint8_t)x[i];
|
|
324
315
|
}
|
|
325
316
|
}
|
|
326
317
|
|
|
327
|
-
void decode_vector(const uint8_t* code, float* x) const
|
|
318
|
+
void decode_vector(const uint8_t* code, float* x) const override {
|
|
328
319
|
for (size_t i = 0; i < d; i++) {
|
|
329
320
|
x[i] = code[i];
|
|
330
321
|
}
|
|
@@ -338,8 +329,8 @@ struct Quantizer8bitDirect<SIMDLevel::NONE> : ScalarQuantizer::SQuantizer {
|
|
|
338
329
|
};
|
|
339
330
|
|
|
340
331
|
template <SIMDLevel SL>
|
|
341
|
-
struct Quantizer8bitDirect :
|
|
342
|
-
using
|
|
332
|
+
struct Quantizer8bitDirect : Quantizer8bitDirectBase<SL> {
|
|
333
|
+
using Quantizer8bitDirectBase<SL>::Quantizer8bitDirectBase;
|
|
343
334
|
};
|
|
344
335
|
|
|
345
336
|
/*******************************************************************
|
|
@@ -347,14 +338,10 @@ struct Quantizer8bitDirect : Quantizer8bitDirect<SIMDLevel::NONE> {
|
|
|
347
338
|
*******************************************************************/
|
|
348
339
|
|
|
349
340
|
template <SIMDLevel SL>
|
|
350
|
-
struct
|
|
351
|
-
|
|
352
|
-
template <>
|
|
353
|
-
struct Quantizer8bitDirectSigned<SIMDLevel::NONE>
|
|
354
|
-
: ScalarQuantizer::SQuantizer {
|
|
341
|
+
struct Quantizer8bitDirectSignedBase : ScalarQuantizer::SQuantizer {
|
|
355
342
|
const size_t d;
|
|
356
343
|
|
|
357
|
-
|
|
344
|
+
Quantizer8bitDirectSignedBase(
|
|
358
345
|
size_t d_in,
|
|
359
346
|
const std::vector<float>& /* unused */)
|
|
360
347
|
: d(d_in) {}
|
|
@@ -365,7 +352,7 @@ struct Quantizer8bitDirectSigned<SIMDLevel::NONE>
|
|
|
365
352
|
}
|
|
366
353
|
}
|
|
367
354
|
|
|
368
|
-
void decode_vector(const uint8_t* code, float* x) const
|
|
355
|
+
void decode_vector(const uint8_t* code, float* x) const override {
|
|
369
356
|
for (size_t i = 0; i < d; i++) {
|
|
370
357
|
x[i] = code[i] - 128;
|
|
371
358
|
}
|
|
@@ -379,8 +366,8 @@ struct Quantizer8bitDirectSigned<SIMDLevel::NONE>
|
|
|
379
366
|
};
|
|
380
367
|
|
|
381
368
|
template <SIMDLevel SL>
|
|
382
|
-
struct Quantizer8bitDirectSigned :
|
|
383
|
-
using
|
|
369
|
+
struct Quantizer8bitDirectSigned : Quantizer8bitDirectSignedBase<SL> {
|
|
370
|
+
using Quantizer8bitDirectSignedBase<SL>::Quantizer8bitDirectSignedBase;
|
|
384
371
|
};
|
|
385
372
|
|
|
386
373
|
/*******************************************************************
|
|
@@ -403,11 +390,7 @@ struct SQTurboQFactors {
|
|
|
403
390
|
FAISS_PACK_STRUCTS_END
|
|
404
391
|
|
|
405
392
|
template <int NBits, SIMDLevel SL>
|
|
406
|
-
struct QuantizerTurboQuantFull
|
|
407
|
-
|
|
408
|
-
template <int NBits>
|
|
409
|
-
struct QuantizerTurboQuantFull<NBits, SIMDLevel::NONE>
|
|
410
|
-
: ScalarQuantizer::SQuantizer {
|
|
393
|
+
struct QuantizerTurboQuantFull : ScalarQuantizer::SQuantizer {
|
|
411
394
|
static_assert(NBits >= 2 && NBits <= 5);
|
|
412
395
|
|
|
413
396
|
static constexpr int kMSEBits = NBits - 1;
|
|
@@ -658,13 +641,6 @@ struct QuantizerTurboQuantFull<NBits, SIMDLevel::NONE>
|
|
|
658
641
|
}
|
|
659
642
|
};
|
|
660
643
|
|
|
661
|
-
template <int NBits, SIMDLevel SL>
|
|
662
|
-
struct QuantizerTurboQuantFull
|
|
663
|
-
: QuantizerTurboQuantFull<NBits, SIMDLevel::NONE> {
|
|
664
|
-
using QuantizerTurboQuantFull<NBits, SIMDLevel::NONE>::
|
|
665
|
-
QuantizerTurboQuantFull;
|
|
666
|
-
};
|
|
667
|
-
|
|
668
644
|
/*******************************************************************
|
|
669
645
|
* Selection function
|
|
670
646
|
*******************************************************************/
|