faiss 0.6.4 → 0.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/ext/faiss/extconf.rb +2 -1
- data/ext/faiss/index.cpp +42 -0
- data/lib/faiss/version.rb +1 -1
- data/vendor/faiss/faiss/AutoTune.cpp +175 -0
- data/vendor/faiss/faiss/Clustering.cpp +150 -60
- data/vendor/faiss/faiss/Clustering.h +29 -0
- data/vendor/faiss/faiss/IVFlib.cpp +147 -51
- data/vendor/faiss/faiss/IVFlib.h +21 -2
- data/vendor/faiss/faiss/Index.cpp +44 -0
- data/vendor/faiss/faiss/Index.h +18 -13
- data/vendor/faiss/faiss/IndexBinary.cpp +8 -0
- data/vendor/faiss/faiss/IndexBinary.h +8 -0
- data/vendor/faiss/faiss/IndexBinaryFlat.cpp +1 -0
- data/vendor/faiss/faiss/IndexBinaryHNSW.cpp +85 -4
- data/vendor/faiss/faiss/IndexBinaryHNSW.h +19 -0
- data/vendor/faiss/faiss/IndexBinaryIVF.cpp +40 -11
- data/vendor/faiss/faiss/IndexFastScan.cpp +34 -18
- data/vendor/faiss/faiss/IndexFastScan.h +6 -3
- data/vendor/faiss/faiss/IndexFlat.cpp +57 -1
- data/vendor/faiss/faiss/IndexFlat.h +31 -0
- data/vendor/faiss/faiss/IndexFlatCodes.cpp +6 -1
- data/vendor/faiss/faiss/IndexHNSW.cpp +461 -13
- data/vendor/faiss/faiss/IndexHNSW.h +40 -5
- data/vendor/faiss/faiss/IndexIDMap.cpp +45 -0
- data/vendor/faiss/faiss/IndexIDMap.h +15 -3
- data/vendor/faiss/faiss/IndexIVF.cpp +349 -68
- data/vendor/faiss/faiss/IndexIVF.h +90 -2
- data/vendor/faiss/faiss/IndexIVFFastScan.cpp +51 -29
- data/vendor/faiss/faiss/IndexIVFFastScan.h +4 -2
- data/vendor/faiss/faiss/IndexIVFFlat.cpp +33 -0
- data/vendor/faiss/faiss/IndexIVFFlat.h +22 -6
- data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +2 -1
- data/vendor/faiss/faiss/IndexIVFRaBitQ.cpp +3 -20
- data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.cpp +78 -58
- data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.h +7 -13
- data/vendor/faiss/faiss/IndexIVFRaBitQSSD.cpp +1694 -0
- data/vendor/faiss/faiss/IndexIVFRaBitQSSD.h +288 -0
- data/vendor/faiss/faiss/IndexIVFSQFastScan.cpp +860 -0
- data/vendor/faiss/faiss/IndexIVFSQFastScan.h +145 -0
- data/vendor/faiss/faiss/IndexNNDescent.cpp +21 -3
- data/vendor/faiss/faiss/IndexPiPNN.cpp +201 -0
- data/vendor/faiss/faiss/IndexPiPNN.h +83 -0
- data/vendor/faiss/faiss/IndexRaBitQ.cpp +189 -41
- data/vendor/faiss/faiss/IndexRaBitQ.h +5 -0
- data/vendor/faiss/faiss/IndexRaBitQFastScan.cpp +7 -4
- data/vendor/faiss/faiss/IndexRaBitQFastScan.h +12 -6
- data/vendor/faiss/faiss/IndexReplicas.cpp +20 -0
- data/vendor/faiss/faiss/IndexReplicas.h +9 -0
- data/vendor/faiss/faiss/IndexSQFastScan.cpp +648 -0
- data/vendor/faiss/faiss/IndexSQFastScan.h +129 -0
- data/vendor/faiss/faiss/IndexShards.cpp +10 -0
- data/vendor/faiss/faiss/IndexShards.h +5 -0
- data/vendor/faiss/faiss/SuperKMeans.cpp +59 -17
- data/vendor/faiss/faiss/SuperKMeans.h +9 -4
- data/vendor/faiss/faiss/VectorTransform.cpp +159 -11
- data/vendor/faiss/faiss/VectorTransform.h +24 -1
- data/vendor/faiss/faiss/clone_index.cpp +24 -0
- data/vendor/faiss/faiss/factory_tools.cpp +19 -1
- data/vendor/faiss/faiss/gpu/Dataset.h +164 -0
- data/vendor/faiss/faiss/gpu/GpuCloner.cpp +16 -13
- data/vendor/faiss/faiss/gpu/GpuCloner.h +4 -0
- data/vendor/faiss/faiss/gpu/GpuClonerOptions.h +3 -0
- data/vendor/faiss/faiss/gpu/GpuIndex.h +4 -13
- data/vendor/faiss/faiss/gpu/GpuIndexBinaryCagra.h +32 -13
- data/vendor/faiss/faiss/gpu/GpuIndexCagra.h +51 -22
- data/vendor/faiss/faiss/gpu/GpuIndexFlat.h +11 -0
- data/vendor/faiss/faiss/gpu/GpuIndexIVF.h +6 -0
- data/vendor/faiss/faiss/gpu/impl/optimal_kmeans/GpuOptimalKMeans.h +184 -0
- data/vendor/faiss/faiss/gpu/test/TestCodePacking.cpp +12 -4
- data/vendor/faiss/faiss/gpu/test/TestGpuDatasetHeader.cpp +18 -0
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexFlat.cpp +215 -0
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFFlat.cpp +98 -0
- data/vendor/faiss/faiss/gpu/test/TestUtils.cpp +6 -5
- data/vendor/faiss/faiss/gpu/utils/DeviceUtils.h +11 -0
- data/vendor/faiss/faiss/gpu/utils/StackDeviceMemory.cpp +1 -1
- data/vendor/faiss/faiss/gpu_metal/GpuIndexFlat.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalCloner.h +12 -1
- data/vendor/faiss/faiss/gpu_metal/MetalDistance.h +93 -1
- data/vendor/faiss/faiss/gpu_metal/MetalFlatKernels.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalIndex.h +5 -1
- data/vendor/faiss/faiss/gpu_metal/MetalIndexBinaryFlat.h +69 -0
- data/vendor/faiss/faiss/gpu_metal/MetalIndexFlat.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalIndexIVFFlat.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalIndexIVFPQ.h +39 -1
- data/vendor/faiss/faiss/gpu_metal/MetalKernels.h +107 -1
- data/vendor/faiss/faiss/gpu_metal/MetalPythonBridge.h +11 -1
- data/vendor/faiss/faiss/gpu_metal/MetalResources.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/StandardMetalResources.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/impl/MetalIVFFlat.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/impl/MetalIVFPQ.h +1 -1
- data/vendor/faiss/faiss/impl/AuxIndexStructures.cpp +3 -1
- data/vendor/faiss/faiss/impl/AuxIndexStructures.h +1 -6
- data/vendor/faiss/faiss/impl/ClusteringHelpers.cpp +134 -45
- data/vendor/faiss/faiss/impl/ClusteringHelpers.h +36 -0
- data/vendor/faiss/faiss/impl/ClusteringInitialization.cpp +267 -136
- data/vendor/faiss/faiss/impl/ClusteringInitialization.h +0 -15
- data/vendor/faiss/faiss/impl/CodePacker.cpp +2 -2
- data/vendor/faiss/faiss/impl/CodePackerRaBitQ.cpp +2 -2
- data/vendor/faiss/faiss/impl/DeterministicNNDescent.cpp +2167 -0
- data/vendor/faiss/faiss/impl/DeterministicNNDescent.h +301 -0
- data/vendor/faiss/faiss/impl/DistanceComputer.cpp +63 -0
- data/vendor/faiss/faiss/impl/DistanceComputer.h +3 -29
- data/vendor/faiss/faiss/impl/HNSW.cpp +48 -12
- data/vendor/faiss/faiss/impl/HNSW.h +74 -2
- data/vendor/faiss/faiss/impl/IDSelector.h +5 -4
- data/vendor/faiss/faiss/impl/LocalSearchQuantizer.cpp +6 -19
- data/vendor/faiss/faiss/impl/NNDescent.cpp +2 -1
- data/vendor/faiss/faiss/impl/NNDescent.h +4 -0
- data/vendor/faiss/faiss/impl/NSG.cpp +3 -2
- data/vendor/faiss/faiss/impl/Panorama.h +3 -2
- data/vendor/faiss/faiss/impl/PiPNN.cpp +824 -0
- data/vendor/faiss/faiss/impl/PiPNN.h +122 -0
- data/vendor/faiss/faiss/impl/PolysemousTraining.cpp +1 -1
- data/vendor/faiss/faiss/impl/ProductQuantizer.cpp +54 -11
- data/vendor/faiss/faiss/impl/RaBitQUtils.cpp +0 -2
- data/vendor/faiss/faiss/impl/RaBitQUtils.h +30 -1
- data/vendor/faiss/faiss/impl/RaBitQuantizer.cpp +91 -66
- data/vendor/faiss/faiss/impl/RaBitQuantizer.h +15 -0
- data/vendor/faiss/faiss/impl/ResultHandler.h +116 -0
- data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +29 -0
- data/vendor/faiss/faiss/impl/ScalarQuantizer.h +1 -6
- data/vendor/faiss/faiss/impl/approx_topk/avx2.cpp +0 -4
- data/vendor/faiss/faiss/impl/approx_topk/neon.cpp +0 -4
- data/vendor/faiss/faiss/impl/binary_hamming/IndexBinaryHash_impl.h +5 -2
- data/vendor/faiss/faiss/impl/binary_hamming/IndexBinaryIVF_impl.h +1 -3
- data/vendor/faiss/faiss/impl/binary_hamming/avx2.cpp +0 -4
- data/vendor/faiss/faiss/impl/binary_hamming/avx512.cpp +0 -4
- data/vendor/faiss/faiss/impl/binary_hamming/neon.cpp +0 -4
- data/vendor/faiss/faiss/impl/binary_hamming/rvv.cpp +0 -4
- data/vendor/faiss/faiss/impl/expanded_scanners.h +93 -0
- data/vendor/faiss/faiss/impl/fast_scan/FastScanDistancePostProcessing.h +4 -0
- data/vendor/faiss/faiss/impl/fast_scan/accumulate_loops.h +61 -64
- data/vendor/faiss/faiss/impl/fast_scan/accumulate_loops_512.h +13 -14
- data/vendor/faiss/faiss/impl/fast_scan/decompose_qbs.h +17 -129
- data/vendor/faiss/faiss/impl/fast_scan/dispatching.h +25 -19
- data/vendor/faiss/faiss/impl/fast_scan/fast_scan.cpp +73 -6
- data/vendor/faiss/faiss/impl/fast_scan/fast_scan.h +43 -0
- data/vendor/faiss/faiss/impl/fast_scan/impl-avx2.cpp +15 -4
- data/vendor/faiss/faiss/impl/fast_scan/impl-avx512.cpp +115 -4
- data/vendor/faiss/faiss/impl/fast_scan/impl-neon.cpp +10 -85
- data/vendor/faiss/faiss/impl/fast_scan/impl-riscv.cpp +0 -4
- data/vendor/faiss/faiss/impl/fast_scan/kernels_neon.h +155 -0
- data/vendor/faiss/faiss/impl/fast_scan/kernels_simd256.h +106 -1
- data/vendor/faiss/faiss/impl/fast_scan/kernels_simd512.h +3 -6
- data/vendor/faiss/faiss/impl/fast_scan/rabitq_result_handler.h +0 -1
- data/vendor/faiss/faiss/impl/fast_scan/simd_result_handlers.h +105 -78
- data/vendor/faiss/faiss/impl/hnsw/LockVector.h +1 -2
- data/vendor/faiss/faiss/impl/hnsw/avx2.cpp +0 -4
- data/vendor/faiss/faiss/impl/hnsw/avx512.cpp +0 -4
- data/vendor/faiss/faiss/impl/index_read.cpp +318 -9
- data/vendor/faiss/faiss/impl/index_write.cpp +124 -5
- data/vendor/faiss/faiss/impl/io.cpp +1 -0
- data/vendor/faiss/faiss/impl/io_macros.h +2 -2
- data/vendor/faiss/faiss/impl/mapped_io.cpp +3 -1
- data/vendor/faiss/faiss/impl/maybe_owned_vector.h +78 -41
- data/vendor/faiss/faiss/impl/nndescent/gram-avx2.cpp +121 -0
- data/vendor/faiss/faiss/impl/nndescent/gram-avx512.cpp +124 -0
- data/vendor/faiss/faiss/impl/nndescent/gram-neon.cpp +114 -0
- data/vendor/faiss/faiss/impl/nndescent/gram.h +66 -0
- data/vendor/faiss/faiss/impl/optimal_kmeans/BlockCombiner-avx512.cpp +431 -0
- data/vendor/faiss/faiss/impl/optimal_kmeans/BlockCombiner-inl.h +1157 -0
- data/vendor/faiss/faiss/impl/optimal_kmeans/OptimalKMeans.cpp +282 -0
- data/vendor/faiss/faiss/impl/optimal_kmeans/OptimalKMeans.h +226 -0
- data/vendor/faiss/faiss/impl/optimal_kmeans/OptimalKMeansCompressed.cpp +1567 -0
- data/vendor/faiss/faiss/impl/optimal_kmeans/OptimalKMeansCompressed.h +281 -0
- data/vendor/faiss/faiss/impl/pipnn/HashPrune.cpp +159 -0
- data/vendor/faiss/faiss/impl/pipnn/HashPrune.h +69 -0
- data/vendor/faiss/faiss/impl/pipnn/Partition.cpp +587 -0
- data/vendor/faiss/faiss/impl/pipnn/Partition.h +93 -0
- data/vendor/faiss/faiss/impl/pipnn/kernels.cpp +326 -0
- data/vendor/faiss/faiss/impl/pipnn/kernels.h +92 -0
- data/vendor/faiss/faiss/impl/platform_macros.h +91 -27
- data/vendor/faiss/faiss/impl/polysemous_training/avx512.cpp +0 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/IVFPQScanner_impl.h +84 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/IVFPQ_QueryTables.cpp +17 -17
- data/vendor/faiss/faiss/impl/pq_code_distance/PQDistanceComputer_impl.h +6 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/avx2.cpp +0 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/avx512.cpp +0 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/neon.cpp +0 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-avx2.h +4 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-avx512.h +4 -1
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-generic.cpp +19 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-generic.h +6 -6
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-inl.h +131 -6
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-sve.cpp +0 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_rvv_kernel.h +89 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_scan_impl.h +21 -10
- data/vendor/faiss/faiss/impl/pq_code_distance/rvv.cpp +45 -18
- data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.cpp +2 -1
- data/vendor/faiss/faiss/impl/result_handler/ResultHandler.cpp +68 -1
- data/vendor/faiss/faiss/impl/result_handler/avx2.cpp +70 -6
- data/vendor/faiss/faiss/impl/result_handler/avx512.cpp +2 -5
- data/vendor/faiss/faiss/impl/scalar_quantizer/EDENQuantizer-avx2.cpp +0 -4
- data/vendor/faiss/faiss/impl/scalar_quantizer/EDENQuantizer-avx512.cpp +0 -4
- data/vendor/faiss/faiss/impl/scalar_quantizer/EDENQuantizer.cpp +1 -1
- data/vendor/faiss/faiss/impl/scalar_quantizer/distance_computers.h +5 -1
- data/vendor/faiss/faiss/impl/scalar_quantizer/quantizers.h +28 -52
- data/vendor/faiss/faiss/impl/scalar_quantizer/scanners.h +85 -37
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx2.cpp +262 -110
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512-impl.h +503 -122
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512-spr.cpp +10 -155
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512.cpp +7 -701
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-dispatch.h +66 -57
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-neon.cpp +133 -127
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-rvv.cpp +3185 -144
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq8_coefficients.h +48 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq8_rvv_kernel.h +546 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/training.cpp +2 -2
- data/vendor/faiss/faiss/impl/simd_dispatch.h +7 -0
- data/vendor/faiss/faiss/impl/simdlib/simdlib_avx2.h +14 -0
- data/vendor/faiss/faiss/impl/simdlib/simdlib_avx512.h +20 -20
- data/vendor/faiss/faiss/impl/simdlib/simdlib_dispatch.h +7 -8
- data/vendor/faiss/faiss/impl/simdlib/simdlib_neon.h +4 -4
- data/vendor/faiss/faiss/impl/sq_fastscan_utils.h +232 -0
- data/vendor/faiss/faiss/impl/zerocopy_io.cpp +2 -1
- data/vendor/faiss/faiss/index_factory.cpp +106 -6
- data/vendor/faiss/faiss/invlists/DirectMap.cpp +1 -1
- data/vendor/faiss/faiss/invlists/DiskIOBackend.cpp +121 -0
- data/vendor/faiss/faiss/invlists/DiskIOBackend.h +71 -0
- data/vendor/faiss/faiss/invlists/InvertedLists.cpp +15 -10
- data/vendor/faiss/faiss/invlists/InvertedListsIOHook.cpp +26 -0
- data/vendor/faiss/faiss/invlists/InvertedListsIOHook.h +5 -0
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.cpp +9 -24
- data/vendor/faiss/faiss/invlists/RaBitQSSDInvertedLists.cpp +751 -0
- data/vendor/faiss/faiss/invlists/RaBitQSSDInvertedLists.h +224 -0
- data/vendor/faiss/faiss/svs/IndexSVSFaissUtils.h +2 -7
- data/vendor/faiss/faiss/svs/IndexSVSFlat.cpp +1 -1
- data/vendor/faiss/faiss/svs/IndexSVSIVF.cpp +2 -2
- data/vendor/faiss/faiss/svs/IndexSVSVamana.cpp +4 -4
- data/vendor/faiss/faiss/svs/IndexSVSVamana.h +3 -2
- data/vendor/faiss/faiss/utils/AlignedTable.h +6 -1
- data/vendor/faiss/faiss/utils/Heap.cpp +4 -3
- data/vendor/faiss/faiss/utils/WorkerThread.h +0 -1
- data/vendor/faiss/faiss/utils/approx_topk_hamming/approx_topk_hamming.h +16 -5
- data/vendor/faiss/faiss/utils/bf16.h +36 -0
- data/vendor/faiss/faiss/utils/distances.cpp +466 -43
- data/vendor/faiss/faiss/utils/distances.h +179 -2
- data/vendor/faiss/faiss/utils/distances_dispatch.h +6 -4
- data/vendor/faiss/faiss/utils/distances_fused/avx512.cpp +2 -5
- data/vendor/faiss/faiss/utils/distances_fused/distances_fused.cpp +0 -14
- data/vendor/faiss/faiss/utils/distances_fused/rvv.cpp +25 -0
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_based.cpp +0 -4
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_based_neon.cpp +0 -4
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_kernel-inl.h +2 -1
- data/vendor/faiss/faiss/utils/distances_simd.cpp +9 -0
- data/vendor/faiss/faiss/utils/extra_distances.h +2 -1
- data/vendor/faiss/faiss/utils/fp16-fp16c.h +4 -0
- data/vendor/faiss/faiss/utils/fp16-inl.h +26 -52
- data/vendor/faiss/faiss/utils/hamming-inl.h +3 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_avx2.cpp +0 -4
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_avx512.cpp +0 -4
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_avx512_vpopcnt.cpp +0 -4
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-avx512.h +33 -5
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-avx512_vpopcnt.h +15 -30
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-neon.h +0 -4
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_impl.h +2 -1
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_neon.cpp +0 -4
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_rvv.cpp +0 -4
- data/vendor/faiss/faiss/utils/partitioning.cpp +2 -2
- data/vendor/faiss/faiss/utils/pq_code_distance.h +8 -4
- data/vendor/faiss/faiss/utils/prefetch.h +1 -26
- data/vendor/faiss/faiss/utils/quantize_lut.cpp +26 -27
- data/vendor/faiss/faiss/utils/quantize_lut.h +11 -0
- data/vendor/faiss/faiss/utils/rabitq_simd.h +171 -22
- data/vendor/faiss/faiss/utils/simd_impl/distances_aarch64.cpp +9 -4
- data/vendor/faiss/faiss/utils/simd_impl/distances_arm_sve.cpp +81 -9
- data/vendor/faiss/faiss/utils/simd_impl/distances_autovec-inl.h +7 -3
- data/vendor/faiss/faiss/utils/simd_impl/distances_avx2.cpp +108 -9
- data/vendor/faiss/faiss/utils/simd_impl/distances_avx512.cpp +111 -12
- data/vendor/faiss/faiss/utils/simd_impl/distances_rvv.cpp +353 -71
- data/vendor/faiss/faiss/utils/simd_impl/distances_rvv_kernel.h +68 -0
- data/vendor/faiss/faiss/utils/simd_impl/distances_simdlib256.h +3 -3
- data/vendor/faiss/faiss/utils/simd_impl/exhaustive_L2sqr_blas_cmax.h +106 -0
- data/vendor/faiss/faiss/utils/simd_impl/fp16_kernels.h +76 -0
- data/vendor/faiss/faiss/utils/simd_impl/fp16_kernels_avx2.cpp +52 -0
- data/vendor/faiss/faiss/utils/simd_impl/fp16_kernels_avx512.cpp +52 -0
- data/vendor/faiss/faiss/utils/simd_impl/fp16_kernels_neon.cpp +48 -0
- data/vendor/faiss/faiss/utils/simd_impl/masked_sum-avx2.h +44 -0
- data/vendor/faiss/faiss/utils/simd_impl/masked_sum-avx512.h +43 -0
- data/vendor/faiss/faiss/utils/simd_impl/masked_sum.h +38 -0
- data/vendor/faiss/faiss/utils/simd_impl/partitioning_avx2.cpp +0 -4
- data/vendor/faiss/faiss/utils/simd_impl/partitioning_neon.cpp +0 -4
- data/vendor/faiss/faiss/utils/simd_impl/partitioning_simdlib256.h +16 -15
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_avx2.cpp +185 -51
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_avx512.cpp +194 -66
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_avx512_vpopcnt.cpp +51 -14
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_neon.cpp +297 -10
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_rvv.cpp +0 -4
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_kernels_avx2.cpp +0 -4
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_kernels_avx512.cpp +0 -4
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_kernels_sve.cpp +0 -4
- data/vendor/faiss/faiss/utils/simd_levels.cpp +22 -6
- data/vendor/faiss/faiss/utils/simd_levels.h +74 -1
- data/vendor/faiss/faiss/utils/sorting.cpp +6 -5
- data/vendor/faiss/faiss/utils/transpose/transpose-avx2-inl.h +0 -4
- data/vendor/faiss/faiss/utils/transpose/transpose-avx512-inl.h +0 -4
- data/vendor/faiss/faiss/utils/utils.cpp +84 -0
- data/vendor/faiss/faiss/utils/utils.h +24 -0
- metadata +52 -1
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
* Portions 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
|
+
/*
|
|
9
|
+
* Portions Copyright 2026 Arm Limited and/or its affiliates
|
|
10
|
+
* <open-source-office@arm.com>
|
|
3
11
|
*
|
|
4
12
|
* This source code is licensed under the MIT license found in the
|
|
5
13
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -23,8 +31,6 @@
|
|
|
23
31
|
* dispatching.h's conditional include.
|
|
24
32
|
*/
|
|
25
33
|
|
|
26
|
-
#if defined(COMPILE_SIMD_AVX512) && defined(__AVX512F__)
|
|
27
|
-
|
|
28
34
|
#include <cassert>
|
|
29
35
|
|
|
30
36
|
#include <faiss/impl/FaissAssert.h>
|
|
@@ -169,17 +175,10 @@ void pq4_accumulate_loop_qbs_fixed_scaler_512(
|
|
|
169
175
|
|
|
170
176
|
// Fallback for unknown QBS values: use 256-bit path.
|
|
171
177
|
// This is rare — pq4_preferred_qbs() covers all values above.
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
} else {
|
|
177
|
-
NormTableScaler<SIMDLevel::AVX2> scaler_avx2(scaler.scale_int);
|
|
178
|
-
pq4_accumulate_loop_qbs_fixed_scaler_256<SIMDLevel::AVX2>(
|
|
179
|
-
qbs, ntotal2, nsq, codes, LUT0, res, scaler_avx2, block_stride);
|
|
180
|
-
}
|
|
178
|
+
// The caller's AVX512-level scaler gives these instantiations symbol names
|
|
179
|
+
// that the AVX2 TU does not emit.
|
|
180
|
+
pq4_accumulate_loop_qbs_fixed_scaler_simd<SIMDLevel::AVX2>(
|
|
181
|
+
qbs, ntotal2, nsq, codes, LUT0, res, scaler, block_stride);
|
|
181
182
|
}
|
|
182
183
|
|
|
183
184
|
} // namespace faiss
|
|
184
|
-
|
|
185
|
-
#endif // COMPILE_SIMD_AVX512 && __AVX512F__
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
* Portions 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
|
+
/*
|
|
9
|
+
* Portions Copyright 2026 Arm Limited and/or its affiliates
|
|
10
|
+
* <open-source-office@arm.com>
|
|
3
11
|
*
|
|
4
12
|
* This source code is licensed under the MIT license found in the
|
|
5
13
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -12,7 +20,11 @@
|
|
|
12
20
|
#include <faiss/impl/FaissAssert.h>
|
|
13
21
|
#include <faiss/impl/fast_scan/kernels_simd256.h>
|
|
14
22
|
#include <faiss/impl/fast_scan/kernels_simd512.h>
|
|
23
|
+
#if FAISS_SIMD_TU(ARM_NEON)
|
|
24
|
+
#include <faiss/impl/fast_scan/kernels_neon.h>
|
|
25
|
+
#endif
|
|
15
26
|
#include <faiss/impl/fast_scan/simd_result_handlers.h>
|
|
27
|
+
#include <faiss/utils/simd_levels.h>
|
|
16
28
|
|
|
17
29
|
namespace faiss {
|
|
18
30
|
|
|
@@ -20,7 +32,7 @@ using namespace simd_result_handlers;
|
|
|
20
32
|
|
|
21
33
|
/*
|
|
22
34
|
* Unified kernel: selects 256-bit vs 512-bit path based on
|
|
23
|
-
* compile-time __AVX512F__ guard.
|
|
35
|
+
* compile-time COMPILE_SIMD_AVX512 && __AVX512F__ guard.
|
|
24
36
|
*
|
|
25
37
|
* KernelSL selects the SIMD type width used for the inner accumulation
|
|
26
38
|
* loop. In DD mode the caller passes the dispatch level so the kernel
|
|
@@ -37,66 +49,20 @@ void kernel_accumulate_block(
|
|
|
37
49
|
const uint8_t* LUT,
|
|
38
50
|
ResultHandler& res,
|
|
39
51
|
const Scaler& scaler) {
|
|
40
|
-
#
|
|
52
|
+
#if FAISS_SIMD_TU(AVX512)
|
|
41
53
|
if constexpr (
|
|
42
54
|
KernelSL == SIMDLevel::AVX512 ||
|
|
43
55
|
KernelSL == SIMDLevel::AVX512_VPOPCNT ||
|
|
44
56
|
KernelSL == SIMDLevel::AVX512_SPR) {
|
|
45
57
|
pq4_kernel_qbs_512<NQ>(nsq, codes, LUT, res, scaler);
|
|
46
58
|
} else {
|
|
47
|
-
|
|
59
|
+
PQ4QBSKernel<KernelSL>::template run<NQ>(nsq, codes, LUT, res, scaler);
|
|
48
60
|
}
|
|
49
61
|
#else
|
|
50
|
-
|
|
62
|
+
PQ4QBSKernel<KernelSL>::template run<NQ>(nsq, codes, LUT, res, scaler);
|
|
51
63
|
#endif
|
|
52
64
|
}
|
|
53
65
|
|
|
54
|
-
// handle at most 4 blocks of queries
|
|
55
|
-
template <
|
|
56
|
-
int QBS,
|
|
57
|
-
SIMDLevel KernelSL = SINGLE_SIMD_LEVEL,
|
|
58
|
-
class ResultHandler,
|
|
59
|
-
class Scaler>
|
|
60
|
-
void accumulate_q_4step(
|
|
61
|
-
size_t ntotal2,
|
|
62
|
-
int nsq,
|
|
63
|
-
const uint8_t* codes,
|
|
64
|
-
const uint8_t* LUT0,
|
|
65
|
-
ResultHandler& res,
|
|
66
|
-
const Scaler& scaler,
|
|
67
|
-
size_t block_stride) {
|
|
68
|
-
constexpr int Q1 = QBS & 15;
|
|
69
|
-
constexpr int Q2 = (QBS >> 4) & 15;
|
|
70
|
-
constexpr int Q3 = (QBS >> 8) & 15;
|
|
71
|
-
constexpr int Q4 = (QBS >> 12) & 15;
|
|
72
|
-
constexpr int SQ = Q1 + Q2 + Q3 + Q4;
|
|
73
|
-
|
|
74
|
-
for_each_block<32>(ntotal2, codes, block_stride, res, [&](size_t) {
|
|
75
|
-
FixedStorageHandler<SQ, 2, KernelSL> res2;
|
|
76
|
-
const uint8_t* LUT = LUT0;
|
|
77
|
-
kernel_accumulate_block<Q1, KernelSL>(nsq, codes, LUT, res2, scaler);
|
|
78
|
-
LUT += Q1 * nsq * 16;
|
|
79
|
-
if (Q2 > 0) {
|
|
80
|
-
res2.set_block_origin(Q1, 0);
|
|
81
|
-
kernel_accumulate_block<Q2, KernelSL>(
|
|
82
|
-
nsq, codes, LUT, res2, scaler);
|
|
83
|
-
LUT += Q2 * nsq * 16;
|
|
84
|
-
}
|
|
85
|
-
if (Q3 > 0) {
|
|
86
|
-
res2.set_block_origin(Q1 + Q2, 0);
|
|
87
|
-
kernel_accumulate_block<Q3, KernelSL>(
|
|
88
|
-
nsq, codes, LUT, res2, scaler);
|
|
89
|
-
LUT += Q3 * nsq * 16;
|
|
90
|
-
}
|
|
91
|
-
if (Q4 > 0) {
|
|
92
|
-
res2.set_block_origin(Q1 + Q2 + Q3, 0);
|
|
93
|
-
kernel_accumulate_block<Q4, KernelSL>(
|
|
94
|
-
nsq, codes, LUT, res2, scaler);
|
|
95
|
-
}
|
|
96
|
-
res2.to_other_handler(res);
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
|
|
100
66
|
template <
|
|
101
67
|
int NQ,
|
|
102
68
|
SIMDLevel KernelSL = SINGLE_SIMD_LEVEL,
|
|
@@ -149,82 +115,4 @@ void accumulate(
|
|
|
149
115
|
#undef DISPATCH
|
|
150
116
|
}
|
|
151
117
|
|
|
152
|
-
template <
|
|
153
|
-
SIMDLevel KernelSL = SINGLE_SIMD_LEVEL,
|
|
154
|
-
class ResultHandler,
|
|
155
|
-
class Scaler>
|
|
156
|
-
void pq4_accumulate_loop_qbs_fixed_scaler(
|
|
157
|
-
int qbs,
|
|
158
|
-
size_t ntotal2,
|
|
159
|
-
int nsq,
|
|
160
|
-
const uint8_t* codes,
|
|
161
|
-
const uint8_t* LUT0,
|
|
162
|
-
ResultHandler& res,
|
|
163
|
-
const Scaler& scaler,
|
|
164
|
-
size_t block_stride = 0) {
|
|
165
|
-
assert(nsq % 2 == 0);
|
|
166
|
-
assert(is_aligned_pointer(codes));
|
|
167
|
-
assert(is_aligned_pointer(LUT0));
|
|
168
|
-
|
|
169
|
-
// try out optimized versions
|
|
170
|
-
switch (qbs) {
|
|
171
|
-
#define DISPATCH(QBS) \
|
|
172
|
-
case QBS: \
|
|
173
|
-
accumulate_q_4step<QBS, KernelSL>( \
|
|
174
|
-
ntotal2, nsq, codes, LUT0, res, scaler, block_stride); \
|
|
175
|
-
return;
|
|
176
|
-
DISPATCH(0x3333); // 12
|
|
177
|
-
DISPATCH(0x2333); // 11
|
|
178
|
-
DISPATCH(0x2233); // 10
|
|
179
|
-
DISPATCH(0x333); // 9
|
|
180
|
-
DISPATCH(0x2223); // 9
|
|
181
|
-
DISPATCH(0x233); // 8
|
|
182
|
-
DISPATCH(0x1223); // 8
|
|
183
|
-
DISPATCH(0x223); // 7
|
|
184
|
-
DISPATCH(0x34); // 7
|
|
185
|
-
DISPATCH(0x133); // 7
|
|
186
|
-
DISPATCH(0x6); // 6
|
|
187
|
-
DISPATCH(0x33); // 6
|
|
188
|
-
DISPATCH(0x123); // 6
|
|
189
|
-
DISPATCH(0x222); // 6
|
|
190
|
-
DISPATCH(0x23); // 5
|
|
191
|
-
DISPATCH(0x5); // 5
|
|
192
|
-
DISPATCH(0x13); // 4
|
|
193
|
-
DISPATCH(0x22); // 4
|
|
194
|
-
DISPATCH(0x4); // 4
|
|
195
|
-
DISPATCH(0x3); // 3
|
|
196
|
-
DISPATCH(0x21); // 3
|
|
197
|
-
DISPATCH(0x2); // 2
|
|
198
|
-
DISPATCH(0x1); // 1
|
|
199
|
-
#undef DISPATCH
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// default implementation where qbs is not known at compile time
|
|
203
|
-
for_each_block<32>(ntotal2, codes, block_stride, res, [&](size_t j0) {
|
|
204
|
-
const uint8_t* LUT = LUT0;
|
|
205
|
-
int qi = qbs;
|
|
206
|
-
int i0 = 0;
|
|
207
|
-
while (qi) {
|
|
208
|
-
int nq = qi & 15;
|
|
209
|
-
qi >>= 4;
|
|
210
|
-
res.set_block_origin(i0, j0);
|
|
211
|
-
#define DISPATCH(NQ) \
|
|
212
|
-
case NQ: \
|
|
213
|
-
kernel_accumulate_block<NQ, KernelSL>(nsq, codes, LUT, res, scaler); \
|
|
214
|
-
break
|
|
215
|
-
switch (nq) {
|
|
216
|
-
DISPATCH(1);
|
|
217
|
-
DISPATCH(2);
|
|
218
|
-
DISPATCH(3);
|
|
219
|
-
DISPATCH(4);
|
|
220
|
-
#undef DISPATCH
|
|
221
|
-
default:
|
|
222
|
-
FAISS_THROW_FMT("accumulate nq=%d not instantiated", nq);
|
|
223
|
-
}
|
|
224
|
-
i0 += nq;
|
|
225
|
-
LUT += nq * nsq * 16;
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
|
|
230
118
|
} // namespace faiss
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
* Portions 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
|
+
/*
|
|
9
|
+
* Portions Copyright 2026 Arm Limited and/or its affiliates
|
|
10
|
+
* <open-source-office@arm.com>
|
|
3
11
|
*
|
|
4
12
|
* This source code is licensed under the MIT license found in the
|
|
5
13
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -20,8 +28,8 @@
|
|
|
20
28
|
* #define THE_LEVEL_TO_DISPATCH SIMDLevel::AVX2
|
|
21
29
|
* #include <faiss/impl/fast_scan/dispatching.h>
|
|
22
30
|
*
|
|
23
|
-
* Kernel helpers come from accumulate_loops.h (search_1 multi-BB path
|
|
24
|
-
*
|
|
31
|
+
* Kernel helpers come from accumulate_loops.h (search_1 multi-BB path and
|
|
32
|
+
* SIMD-level-selected QBS path) and accumulate_loops_512.h (QBS 512-bit path,
|
|
25
33
|
* AVX512 TU only).
|
|
26
34
|
*/
|
|
27
35
|
|
|
@@ -35,7 +43,7 @@
|
|
|
35
43
|
#include <faiss/impl/fast_scan/fast_scan.h>
|
|
36
44
|
#include <faiss/utils/simd_levels.h>
|
|
37
45
|
|
|
38
|
-
#if
|
|
46
|
+
#if FAISS_SIMD_TU(AVX512)
|
|
39
47
|
#include <faiss/impl/fast_scan/accumulate_loops_512.h>
|
|
40
48
|
#endif
|
|
41
49
|
|
|
@@ -107,7 +115,7 @@ struct ScannerMixIn : FastScanCodeScanner {
|
|
|
107
115
|
const uint8_t* LUT,
|
|
108
116
|
int pq2x4_scale,
|
|
109
117
|
size_t block_stride) override {
|
|
110
|
-
#if
|
|
118
|
+
#if FAISS_SIMD_TU(AVX512)
|
|
111
119
|
constexpr bool use_avx512_qbs =
|
|
112
120
|
(THE_LEVEL_TO_DISPATCH == SIMDLevel::AVX512 ||
|
|
113
121
|
THE_LEVEL_TO_DISPATCH == SIMDLevel::AVX512_SPR);
|
|
@@ -115,18 +123,14 @@ struct ScannerMixIn : FastScanCodeScanner {
|
|
|
115
123
|
constexpr bool use_avx512_qbs = false;
|
|
116
124
|
#endif
|
|
117
125
|
if constexpr (use_avx512_qbs) {
|
|
118
|
-
//
|
|
119
|
-
//
|
|
120
|
-
// throughput gain but pays extra per-block LUT-assembly and
|
|
121
|
-
// cross-lane reduction overhead (measured ~14% search regression
|
|
122
|
-
// for PQ8x4fs / PQ16x4fs). Route those CPUs to the 256-bit (AVX2)
|
|
123
|
-
// QBS kernel instead -- same output, no downside on Zen 4. This is
|
|
124
|
-
// a process-constant runtime branch, hoisted out of the inner
|
|
125
|
-
// accumulate loop. Intel AVX-512 keeps the 512-bit kernel.
|
|
126
|
+
// Zen 4 runs 512-bit ops on a 256-bit datapath, so the 512-bit QBS
|
|
127
|
+
// kernel is slower there; use the AVX2 kernel.
|
|
126
128
|
if (SIMDConfig::avx512_split) {
|
|
129
|
+
// THE_LEVEL_TO_DISPATCH scalers give these AVX2-loop
|
|
130
|
+
// instantiations symbol names that the AVX2 TU does not emit.
|
|
127
131
|
if (pq2x4_scale) {
|
|
128
|
-
NormTableScaler<
|
|
129
|
-
|
|
132
|
+
NormTableScaler<THE_LEVEL_TO_DISPATCH> scaler(pq2x4_scale);
|
|
133
|
+
pq4_accumulate_loop_qbs_fixed_scaler_simd<SIMDLevel::AVX2>(
|
|
130
134
|
qbs,
|
|
131
135
|
nb,
|
|
132
136
|
nsq,
|
|
@@ -136,8 +140,8 @@ struct ScannerMixIn : FastScanCodeScanner {
|
|
|
136
140
|
scaler,
|
|
137
141
|
block_stride);
|
|
138
142
|
} else {
|
|
139
|
-
DummyScaler<
|
|
140
|
-
|
|
143
|
+
DummyScaler<THE_LEVEL_TO_DISPATCH> dummy;
|
|
144
|
+
pq4_accumulate_loop_qbs_fixed_scaler_simd<SIMDLevel::AVX2>(
|
|
141
145
|
qbs,
|
|
142
146
|
nb,
|
|
143
147
|
nsq,
|
|
@@ -174,7 +178,8 @@ struct ScannerMixIn : FastScanCodeScanner {
|
|
|
174
178
|
} else {
|
|
175
179
|
if (pq2x4_scale) {
|
|
176
180
|
NormTableScaler<THE_LEVEL_TO_DISPATCH> scaler(pq2x4_scale);
|
|
177
|
-
|
|
181
|
+
pq4_accumulate_loop_qbs_fixed_scaler_simd<
|
|
182
|
+
THE_LEVEL_TO_DISPATCH>(
|
|
178
183
|
qbs,
|
|
179
184
|
nb,
|
|
180
185
|
nsq,
|
|
@@ -185,7 +190,8 @@ struct ScannerMixIn : FastScanCodeScanner {
|
|
|
185
190
|
block_stride);
|
|
186
191
|
} else {
|
|
187
192
|
DummyScaler<THE_LEVEL_TO_DISPATCH> dummy;
|
|
188
|
-
|
|
193
|
+
pq4_accumulate_loop_qbs_fixed_scaler_simd<
|
|
194
|
+
THE_LEVEL_TO_DISPATCH>(
|
|
189
195
|
qbs,
|
|
190
196
|
nb,
|
|
191
197
|
nsq,
|
|
@@ -12,10 +12,16 @@
|
|
|
12
12
|
#include <faiss/impl/fast_scan/simd_result_handlers.h>
|
|
13
13
|
#include <faiss/impl/simd_dispatch.h>
|
|
14
14
|
|
|
15
|
+
#include <algorithm>
|
|
15
16
|
#include <array>
|
|
16
17
|
|
|
17
18
|
namespace faiss {
|
|
18
19
|
|
|
20
|
+
void SIMDResultHandlerToFloat::end() {
|
|
21
|
+
normalizers = nullptr;
|
|
22
|
+
scan_cnt = 0;
|
|
23
|
+
}
|
|
24
|
+
|
|
19
25
|
using namespace simd_result_handlers;
|
|
20
26
|
|
|
21
27
|
/***************************************************************
|
|
@@ -34,8 +40,8 @@ void get_matrix_column(
|
|
|
34
40
|
int64_t i,
|
|
35
41
|
int64_t j,
|
|
36
42
|
TA& dest) {
|
|
37
|
-
for (int64_t k = 0; k < dest.size(); k++) {
|
|
38
|
-
if (k + i >= 0 && k + i < m) {
|
|
43
|
+
for (int64_t k = 0; k < static_cast<int64_t>(dest.size()); k++) {
|
|
44
|
+
if (k + i >= 0 && k + i < static_cast<int64_t>(m)) {
|
|
39
45
|
dest[k] = src[(k + i) * n + j];
|
|
40
46
|
} else {
|
|
41
47
|
dest[k] = 0;
|
|
@@ -83,7 +89,7 @@ void pq4_pack_codes(
|
|
|
83
89
|
|
|
84
90
|
uint8_t* codes2 = blocks;
|
|
85
91
|
for (size_t i0 = 0; i0 < nb; i0 += bbs) {
|
|
86
|
-
for (
|
|
92
|
+
for (size_t sq = 0; sq < nsq; sq += 2) {
|
|
87
93
|
for (size_t i = 0; i < bbs; i += 32) {
|
|
88
94
|
std::array<uint8_t, 32> c, c0, c1;
|
|
89
95
|
get_matrix_column(
|
|
@@ -142,7 +148,7 @@ void pq4_pack_codes_range(
|
|
|
142
148
|
for (size_t b = block0; b < block1; b++) {
|
|
143
149
|
uint8_t* codes2 = blocks + b * block_stride;
|
|
144
150
|
int64_t i_base = b * bbs - i0;
|
|
145
|
-
for (
|
|
151
|
+
for (size_t sq = 0; sq < nsq; sq += 2) {
|
|
146
152
|
for (size_t i = 0; i < bbs; i += 32) {
|
|
147
153
|
std::array<uint8_t, 32> c, c0, c1;
|
|
148
154
|
get_matrix_column(
|
|
@@ -236,8 +242,8 @@ void pq4_set_packed_element(
|
|
|
236
242
|
* CodePackerPQ4 implementation
|
|
237
243
|
***************************************************************/
|
|
238
244
|
|
|
239
|
-
CodePackerPQ4::CodePackerPQ4(size_t
|
|
240
|
-
|
|
245
|
+
CodePackerPQ4::CodePackerPQ4(size_t nsq_in, size_t bbs) {
|
|
246
|
+
nsq = nsq_in;
|
|
241
247
|
nvec = bbs;
|
|
242
248
|
code_size = (nsq * 4 + 7) / 8;
|
|
243
249
|
block_size = ((nsq + 1) / 2) * bbs;
|
|
@@ -432,6 +438,67 @@ void accumulate_to_mem(
|
|
|
432
438
|
});
|
|
433
439
|
}
|
|
434
440
|
|
|
441
|
+
/***************************************************************
|
|
442
|
+
* accumulate_hacc: NONE specialization + runtime dispatch.
|
|
443
|
+
***************************************************************/
|
|
444
|
+
|
|
445
|
+
template <>
|
|
446
|
+
void accumulate_hacc_impl<SIMDLevel::NONE>(
|
|
447
|
+
int nq,
|
|
448
|
+
size_t ntotal2,
|
|
449
|
+
int nsq,
|
|
450
|
+
const uint8_t* codes,
|
|
451
|
+
const uint8_t* LUT,
|
|
452
|
+
int32_t* accu) {
|
|
453
|
+
// byte j of a 16-byte half holds the codes of elements perm0[j] (low
|
|
454
|
+
// nibble) and perm0[j] + 16 (high nibble), as packed by pq4_pack_codes
|
|
455
|
+
#ifdef FAISS_BIG_ENDIAN
|
|
456
|
+
const uint8_t perm0[16] = {
|
|
457
|
+
8, 0, 9, 1, 10, 2, 11, 3, 12, 4, 13, 5, 14, 6, 15, 7};
|
|
458
|
+
#else
|
|
459
|
+
const uint8_t perm0[16] = {
|
|
460
|
+
0, 8, 1, 9, 2, 10, 3, 11, 4, 12, 5, 13, 6, 14, 7, 15};
|
|
461
|
+
#endif
|
|
462
|
+
const size_t block_stride = 32 * size_t(nsq) / 2;
|
|
463
|
+
for (int q = 0; q < nq; q++) {
|
|
464
|
+
const uint8_t* lut_lo = LUT + size_t(q) * 2 * 16 * nsq;
|
|
465
|
+
const uint8_t* lut_hi = lut_lo + 16 * size_t(nsq);
|
|
466
|
+
for (size_t b = 0; b < ntotal2 / 32; b++) {
|
|
467
|
+
const uint8_t* block = codes + b * block_stride;
|
|
468
|
+
int32_t* out = accu + q * ntotal2 + b * 32;
|
|
469
|
+
std::fill(out, out + 32, 0);
|
|
470
|
+
for (int sq = 0; sq < nsq; sq++) {
|
|
471
|
+
const uint8_t* c = block + (sq / 2) * 32 + (sq % 2) * 16;
|
|
472
|
+
const uint8_t* lo = lut_lo + 16 * sq;
|
|
473
|
+
const uint8_t* hi = lut_hi + 16 * sq;
|
|
474
|
+
for (int j = 0; j < 16; j++) {
|
|
475
|
+
const int c0 = c[j] & 15, c1 = c[j] >> 4;
|
|
476
|
+
out[perm0[j]] += lo[c0] + (int32_t(hi[c0]) << 8);
|
|
477
|
+
out[perm0[j] + 16] += lo[c1] + (int32_t(hi[c1]) << 8);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
void accumulate_hacc(
|
|
485
|
+
int nq,
|
|
486
|
+
size_t ntotal2,
|
|
487
|
+
int nsq,
|
|
488
|
+
const uint8_t* codes,
|
|
489
|
+
const uint8_t* LUT,
|
|
490
|
+
int32_t* accu) {
|
|
491
|
+
FAISS_THROW_IF_NOT(ntotal2 % 32 == 0);
|
|
492
|
+
FAISS_THROW_IF_NOT(nsq % 2 == 0);
|
|
493
|
+
FAISS_THROW_IF_NOT_FMT(
|
|
494
|
+
nsq <= 32768,
|
|
495
|
+
"accumulate_hacc: nsq=%d > 32768 would overflow the int32 sums",
|
|
496
|
+
nsq);
|
|
497
|
+
with_selected_simd_levels<FAST_SCAN_HACC_SIMD_LEVELS>([&]<SIMDLevel SL>() {
|
|
498
|
+
accumulate_hacc_impl<SL>(nq, ntotal2, nsq, codes, LUT, accu);
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
|
|
435
502
|
} // namespace faiss
|
|
436
503
|
|
|
437
504
|
namespace faiss {
|
|
@@ -178,6 +178,49 @@ void accumulate_to_mem_impl(
|
|
|
178
178
|
const uint8_t* LUT,
|
|
179
179
|
uint16_t* accu);
|
|
180
180
|
|
|
181
|
+
/// SIMD levels with high-accuracy FastScan accumulation implementations.
|
|
182
|
+
/// The AVX512 kernel returns wrong sums when compiled with MSVC, where the
|
|
183
|
+
/// AVX2 one is used instead.
|
|
184
|
+
#ifdef _MSC_VER
|
|
185
|
+
constexpr int FAST_SCAN_HACC_SIMD_LEVELS =
|
|
186
|
+
(1 << int(SIMDLevel::NONE)) | (1 << int(SIMDLevel::AVX2));
|
|
187
|
+
#else
|
|
188
|
+
constexpr int FAST_SCAN_HACC_SIMD_LEVELS = (1 << int(SIMDLevel::NONE)) |
|
|
189
|
+
(1 << int(SIMDLevel::AVX2)) | (1 << int(SIMDLevel::AVX512)) |
|
|
190
|
+
(1 << int(SIMDLevel::ARM_NEON));
|
|
191
|
+
#endif
|
|
192
|
+
|
|
193
|
+
/** Same as accumulate_to_mem, but with 16-bit look-up table entries summed
|
|
194
|
+
* exactly into 32-bit accumulators for nsq <= 32768. Each 16-bit table is given
|
|
195
|
+
* as two 8-bit tables: the low bytes of its entries, then the high bytes.
|
|
196
|
+
*
|
|
197
|
+
* @param nq number of queries
|
|
198
|
+
* @param ntotal2 number of database elements (multiple of 32)
|
|
199
|
+
* @param nsq number of sub-quantizers (multiple of 2)
|
|
200
|
+
* @param codes packed codes array, in blocks of 32 elements
|
|
201
|
+
* @param LUT for each query, 16 * nsq bytes of low bytes, then 16 * nsq
|
|
202
|
+
* bytes of high bytes, each laid out as by
|
|
203
|
+
* pq4_pack_LUT(1, nsq, ...)
|
|
204
|
+
* @param accu array to store the results, size nq * ntotal2
|
|
205
|
+
*/
|
|
206
|
+
void accumulate_hacc(
|
|
207
|
+
int nq,
|
|
208
|
+
size_t ntotal2,
|
|
209
|
+
int nsq,
|
|
210
|
+
const uint8_t* codes,
|
|
211
|
+
const uint8_t* LUT,
|
|
212
|
+
int32_t* accu);
|
|
213
|
+
|
|
214
|
+
/// Per-SIMD specialization of accumulate_hacc (defined in per-SIMD TUs)
|
|
215
|
+
template <SIMDLevel SL>
|
|
216
|
+
void accumulate_hacc_impl(
|
|
217
|
+
int nq,
|
|
218
|
+
size_t ntotal2,
|
|
219
|
+
int nsq,
|
|
220
|
+
const uint8_t* codes,
|
|
221
|
+
const uint8_t* LUT,
|
|
222
|
+
int32_t* accu);
|
|
223
|
+
|
|
181
224
|
/***************************************************************
|
|
182
225
|
* FastScanCodeScanner: virtual base that bundles handler + kernel
|
|
183
226
|
* behind the SIMD dispatch boundary. Per-SIMD TUs instantiate this
|
|
@@ -5,13 +5,14 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
#ifdef COMPILE_SIMD_AVX2
|
|
9
|
-
|
|
10
8
|
#define THE_LEVEL_TO_DISPATCH SIMDLevel::AVX2
|
|
11
9
|
#include <faiss/impl/fast_scan/dispatching.h> // IWYU pragma: keep
|
|
12
10
|
#include <faiss/impl/fast_scan/rabitq_dispatching.h> // IWYU pragma: keep
|
|
13
11
|
|
|
14
12
|
#include <faiss/impl/fast_scan/decompose_qbs.h>
|
|
13
|
+
#include <faiss/impl/fast_scan/kernels_simd256.h>
|
|
14
|
+
|
|
15
|
+
#include <cstdint>
|
|
15
16
|
|
|
16
17
|
namespace faiss {
|
|
17
18
|
|
|
@@ -31,6 +32,16 @@ void accumulate_to_mem_impl<SIMDLevel::AVX2>(
|
|
|
31
32
|
nq, ntotal2, nsq, codes, LUT, handler, scaler, 32 * nsq / 2);
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
|
|
35
|
+
template <>
|
|
36
|
+
void accumulate_hacc_impl<SIMDLevel::AVX2>(
|
|
37
|
+
int nq,
|
|
38
|
+
size_t ntotal2,
|
|
39
|
+
int nsq,
|
|
40
|
+
const uint8_t* codes,
|
|
41
|
+
const uint8_t* LUT,
|
|
42
|
+
int32_t* accu) {
|
|
43
|
+
accumulate_hacc_simdlib<SIMDLevel::AVX2>(
|
|
44
|
+
nq, ntotal2, nsq, codes, LUT, accu);
|
|
45
|
+
}
|
|
35
46
|
|
|
36
|
-
|
|
47
|
+
} // namespace faiss
|
|
@@ -5,13 +5,16 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
#ifdef COMPILE_SIMD_AVX512
|
|
9
|
-
|
|
10
8
|
#define THE_LEVEL_TO_DISPATCH SIMDLevel::AVX512
|
|
11
9
|
#include <faiss/impl/fast_scan/dispatching.h> // IWYU pragma: keep
|
|
12
10
|
#include <faiss/impl/fast_scan/rabitq_dispatching.h> // IWYU pragma: keep
|
|
13
11
|
|
|
14
12
|
#include <faiss/impl/fast_scan/decompose_qbs.h>
|
|
13
|
+
#include <faiss/impl/fast_scan/kernels_simd512.h>
|
|
14
|
+
|
|
15
|
+
#include <immintrin.h>
|
|
16
|
+
#include <algorithm>
|
|
17
|
+
#include <cstdint>
|
|
15
18
|
|
|
16
19
|
namespace faiss {
|
|
17
20
|
|
|
@@ -35,6 +38,114 @@ void accumulate_to_mem_impl<SIMDLevel::AVX512>(
|
|
|
35
38
|
nq, ntotal2, nsq, codes, LUT, handler, scaler, 32 * nsq / 2);
|
|
36
39
|
}
|
|
37
40
|
|
|
38
|
-
|
|
41
|
+
/* accumulate_hacc over one block of 32 codes. One 512-bit register holds 4
|
|
42
|
+
* sub-quantizers, one per 128-bit lane. The sums of two lanes are added in
|
|
43
|
+
* 16 bits before widening, so segments of 512 sub-quantizers keep them below
|
|
44
|
+
* 255 * 512 / 2 < 2^16. */
|
|
45
|
+
static inline void accumulate_hacc_block_avx512(
|
|
46
|
+
int nsq,
|
|
47
|
+
const uint8_t* codes,
|
|
48
|
+
const uint8_t* lut_lo,
|
|
49
|
+
const uint8_t* lut_hi,
|
|
50
|
+
int32_t* accu) {
|
|
51
|
+
constexpr int kSegmentSq = 512;
|
|
52
|
+
const __m512i low_mask = _mm512_set1_epi8(0xf);
|
|
53
|
+
__m512i res[2] = {_mm512_setzero_si512(), _mm512_setzero_si512()};
|
|
54
|
+
|
|
55
|
+
for (int seg = 0; seg < nsq; seg += kSegmentSq) {
|
|
56
|
+
const int seg_end = std::min(nsq, seg + kSegmentSq);
|
|
57
|
+
// 4 sub-quantizers from sq on; when only 2 are left, the upper
|
|
58
|
+
// lanes are zero: zero codes look up zero table entries
|
|
59
|
+
auto load4 = [seg_end](const uint8_t* p, int sq) {
|
|
60
|
+
if (sq + 4 <= seg_end) {
|
|
61
|
+
return _mm512_loadu_si512(p);
|
|
62
|
+
}
|
|
63
|
+
return _mm512_inserti64x4(
|
|
64
|
+
_mm512_setzero_si512(),
|
|
65
|
+
_mm256_loadu_si256((const __m256i*)p),
|
|
66
|
+
0);
|
|
67
|
+
};
|
|
68
|
+
// [low or high byte table][elements 0-15 even / odd bytes,
|
|
69
|
+
// elements 16-31 even / odd bytes]
|
|
70
|
+
__m512i acc[2][4];
|
|
71
|
+
for (auto& a : acc) {
|
|
72
|
+
for (auto& reg : a) {
|
|
73
|
+
reg = _mm512_setzero_si512();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
for (int sq = seg; sq < seg_end; sq += 4) {
|
|
77
|
+
const __m512i c = load4(codes + 16 * sq, sq);
|
|
78
|
+
const __m512i clo = _mm512_and_si512(c, low_mask);
|
|
79
|
+
const __m512i chi =
|
|
80
|
+
_mm512_and_si512(_mm512_srli_epi16(c, 4), low_mask);
|
|
81
|
+
const uint8_t* luts[2] = {lut_lo + 16 * sq, lut_hi + 16 * sq};
|
|
82
|
+
for (int t = 0; t < 2; t++) {
|
|
83
|
+
const __m512i lut = load4(luts[t], sq);
|
|
84
|
+
const __m512i res_lo = _mm512_shuffle_epi8(lut, clo);
|
|
85
|
+
const __m512i res_hi = _mm512_shuffle_epi8(lut, chi);
|
|
86
|
+
acc[t][0] = _mm512_add_epi16(acc[t][0], res_lo);
|
|
87
|
+
acc[t][1] = _mm512_add_epi16(
|
|
88
|
+
acc[t][1], _mm512_srli_epi16(res_lo, 8));
|
|
89
|
+
acc[t][2] = _mm512_add_epi16(acc[t][2], res_hi);
|
|
90
|
+
acc[t][3] = _mm512_add_epi16(
|
|
91
|
+
acc[t][3], _mm512_srli_epi16(res_hi, 8));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// add the two 256-bit halves, then the lanes holding the same
|
|
96
|
+
// elements, widening to 32 bits
|
|
97
|
+
auto combine = [](__m512i even, __m512i odd) {
|
|
98
|
+
__m256i e = _mm256_add_epi16(
|
|
99
|
+
_mm512_castsi512_si256(even),
|
|
100
|
+
_mm512_extracti64x4_epi64(even, 1));
|
|
101
|
+
__m256i o = _mm256_add_epi16(
|
|
102
|
+
_mm512_castsi512_si256(odd),
|
|
103
|
+
_mm512_extracti64x4_epi64(odd, 1));
|
|
104
|
+
e = _mm256_sub_epi16(e, _mm256_slli_epi16(o, 8));
|
|
105
|
+
return _mm512_add_epi32(
|
|
106
|
+
_mm512_cvtepu16_epi32(
|
|
107
|
+
_mm256_permute2f128_si256(e, o, 0x21)),
|
|
108
|
+
_mm512_cvtepu16_epi32(_mm256_blend_epi32(e, o, 0xF0)));
|
|
109
|
+
};
|
|
110
|
+
__m512i dis0[2], dis1[2];
|
|
111
|
+
for (int t = 0; t < 2; t++) {
|
|
112
|
+
dis0[t] = combine(acc[t][0], acc[t][1]);
|
|
113
|
+
dis1[t] = combine(acc[t][2], acc[t][3]);
|
|
114
|
+
}
|
|
115
|
+
// low + (high << 8)
|
|
116
|
+
res[0] = _mm512_add_epi32(
|
|
117
|
+
res[0],
|
|
118
|
+
_mm512_add_epi32(dis0[0], _mm512_slli_epi32(dis0[1], 8)));
|
|
119
|
+
res[1] = _mm512_add_epi32(
|
|
120
|
+
res[1],
|
|
121
|
+
_mm512_add_epi32(dis1[0], _mm512_slli_epi32(dis1[1], 8)));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
_mm512_storeu_si512(accu, res[0]); // elements 0 to 15
|
|
125
|
+
_mm512_storeu_si512(accu + 16, res[1]); // elements 16 to 31
|
|
126
|
+
}
|
|
39
127
|
|
|
40
|
-
|
|
128
|
+
template <>
|
|
129
|
+
void accumulate_hacc_impl<SIMDLevel::AVX512>(
|
|
130
|
+
int nq,
|
|
131
|
+
size_t ntotal2,
|
|
132
|
+
int nsq,
|
|
133
|
+
const uint8_t* codes,
|
|
134
|
+
const uint8_t* LUT,
|
|
135
|
+
int32_t* accu) {
|
|
136
|
+
const size_t block_stride = 32 * size_t(nsq) / 2;
|
|
137
|
+
for (int q = 0; q < nq; q++) {
|
|
138
|
+
const uint8_t* lut_lo = LUT + size_t(q) * 2 * 16 * nsq;
|
|
139
|
+
const uint8_t* lut_hi = lut_lo + 16 * size_t(nsq);
|
|
140
|
+
for (size_t b = 0; b < ntotal2 / 32; b++) {
|
|
141
|
+
accumulate_hacc_block_avx512(
|
|
142
|
+
nsq,
|
|
143
|
+
codes + b * block_stride,
|
|
144
|
+
lut_lo,
|
|
145
|
+
lut_hi,
|
|
146
|
+
accu + q * ntotal2 + b * 32);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
} // namespace faiss
|