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
|
@@ -186,40 +186,25 @@ struct HammingComputerDefault_tpl<SIMDLevel::AVX512_VPOPCNT> {
|
|
|
186
186
|
remainder8 = code_size % 8;
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
+
/// One vector accumulator, reduced once. The partial last block is a
|
|
190
|
+
/// masked load, so no byte past the code is read.
|
|
189
191
|
int hamming(const uint8_t* b8) const {
|
|
190
|
-
int
|
|
191
|
-
|
|
192
|
-
const uint64_t* a64 = reinterpret_cast<const uint64_t*>(a8);
|
|
193
|
-
const uint64_t* b64 = reinterpret_cast<const uint64_t*>(b8);
|
|
194
|
-
|
|
192
|
+
const int code_size = quotient8 * 8 + remainder8;
|
|
193
|
+
__m512i accu = _mm512_setzero_si512();
|
|
195
194
|
int i = 0;
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
_mm512_loadu_si512(&b64[i * 8]));
|
|
201
|
-
__m512i vpcnt = _mm512_popcnt_epi64(vxor);
|
|
202
|
-
accu += _mm512_reduce_add_epi32(vpcnt);
|
|
195
|
+
for (; i + 64 <= code_size; i += 64) {
|
|
196
|
+
const __m512i vxor = _mm512_xor_si512(
|
|
197
|
+
_mm512_loadu_si512(a8 + i), _mm512_loadu_si512(b8 + i));
|
|
198
|
+
accu = _mm512_add_epi64(accu, _mm512_popcnt_epi64(vxor));
|
|
203
199
|
}
|
|
204
|
-
i
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
_mm256_loadu_si256((const __m256i*)&b64[i]));
|
|
211
|
-
__m256i vpcnt = _mm256_popcnt_epi64(vxor);
|
|
212
|
-
__m128i lo = _mm256_castsi256_si128(vpcnt);
|
|
213
|
-
__m128i hi = _mm256_extracti128_si256(vpcnt, 1);
|
|
214
|
-
__m128i sum = _mm_add_epi64(lo, hi);
|
|
215
|
-
accu += static_cast<int>(
|
|
216
|
-
_mm_extract_epi64(sum, 0) + _mm_extract_epi64(sum, 1));
|
|
217
|
-
i += 4;
|
|
200
|
+
if (i < code_size) {
|
|
201
|
+
const __mmask64 mask = _bzhi_u64(~uint64_t(0), code_size - i);
|
|
202
|
+
const __m512i vxor = _mm512_xor_si512(
|
|
203
|
+
_mm512_maskz_loadu_epi8(mask, a8 + i),
|
|
204
|
+
_mm512_maskz_loadu_epi8(mask, b8 + i));
|
|
205
|
+
accu = _mm512_add_epi64(accu, _mm512_popcnt_epi64(vxor));
|
|
218
206
|
}
|
|
219
|
-
|
|
220
|
-
accu += hamming_popcount_tail(
|
|
221
|
-
a64, b64, i, quotient8, a8, b8, remainder8);
|
|
222
|
-
return accu;
|
|
207
|
+
return static_cast<int>(_mm512_reduce_add_epi64(accu));
|
|
223
208
|
}
|
|
224
209
|
|
|
225
210
|
inline int get_code_size() const {
|
|
@@ -16,8 +16,6 @@
|
|
|
16
16
|
// hamming_computer-generic.h. SIMDLevel::ARM_NEON specializations for the
|
|
17
17
|
// ISA-varying HammingComputer and GenHammingComputer structs live in this file.
|
|
18
18
|
|
|
19
|
-
#ifdef __aarch64__
|
|
20
|
-
|
|
21
19
|
#include <arm_neon.h>
|
|
22
20
|
|
|
23
21
|
#include <cassert>
|
|
@@ -318,5 +316,3 @@ struct GenHammingComputerM8_tpl<SIMDLevel::ARM_NEON> {
|
|
|
318
316
|
} // namespace faiss
|
|
319
317
|
|
|
320
318
|
#endif
|
|
321
|
-
|
|
322
|
-
#endif
|
|
@@ -5,11 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
#ifdef COMPILE_SIMD_ARM_NEON
|
|
9
|
-
|
|
10
8
|
#define THE_SIMD_LEVEL SIMDLevel::ARM_NEON
|
|
11
9
|
// NOLINTNEXTLINE(facebook-hte-InlineHeader)
|
|
12
10
|
#include <faiss/utils/hamming_distance/hamming_computer-neon.h>
|
|
13
11
|
#include <faiss/utils/hamming_distance/hamming_impl.h>
|
|
14
|
-
|
|
15
|
-
#endif // COMPILE_SIMD_ARM_NEON
|
|
@@ -5,11 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
#ifdef COMPILE_SIMD_RISCV_RVV
|
|
9
|
-
|
|
10
8
|
#define THE_SIMD_LEVEL SIMDLevel::RISCV_RVV
|
|
11
9
|
// NOLINTNEXTLINE(facebook-hte-InlineHeader)
|
|
12
10
|
#include <faiss/utils/hamming_distance/hamming_computer-rvv.h>
|
|
13
11
|
#include <faiss/utils/hamming_distance/hamming_impl.h>
|
|
14
|
-
|
|
15
|
-
#endif // COMPILE_SIMD_RISCV_RVV
|
|
@@ -204,13 +204,13 @@ typename C::T partition_fuzzy_median3(
|
|
|
204
204
|
thresh = C::Crev::nextafter(thresh);
|
|
205
205
|
n_eq_1 = q;
|
|
206
206
|
} else {
|
|
207
|
-
assert(n_eq_1 <= n_eq);
|
|
207
|
+
assert(static_cast<size_t>(n_eq_1) <= n_eq);
|
|
208
208
|
}
|
|
209
209
|
|
|
210
210
|
[[maybe_unused]] const int wp =
|
|
211
211
|
compress_array<C>(vals, ids, n, thresh, n_eq_1);
|
|
212
212
|
|
|
213
|
-
assert(wp == q);
|
|
213
|
+
assert(static_cast<size_t>(wp) == q);
|
|
214
214
|
if (q_out) {
|
|
215
215
|
*q_out = q;
|
|
216
216
|
}
|
|
@@ -53,10 +53,14 @@ namespace pq_code_distance {
|
|
|
53
53
|
*********************************************************************/
|
|
54
54
|
|
|
55
55
|
/// Scalar PQ code distance implementation.
|
|
56
|
-
/// Templated only on decoder type, independent of SIMD level.
|
|
57
56
|
/// Used directly by non-PQDecoder8 decoders (PQDecoder16,
|
|
58
57
|
/// PQDecoderGeneric) and as fallback for PQDecoder8 at NONE/NEON.
|
|
59
|
-
|
|
58
|
+
// SL keeps each SIMD-level TU's instantiation a distinct symbol. Without it
|
|
59
|
+
// the linker merges them and may keep one compiled with -mavx512*, which
|
|
60
|
+
// then runs on the AVX2 path and raises SIGILL on CPUs without AVX512.
|
|
61
|
+
// The default keeps callers outside faiss that name only the decoder (e.g.
|
|
62
|
+
// unicorn/features/encoders/PQFSTable.h) compiling; faiss passes SL itself.
|
|
63
|
+
template <typename PQDecoderT, SIMDLevel SL = SIMDLevel::NONE>
|
|
60
64
|
struct PQCodeDistanceScalar {
|
|
61
65
|
using PQDecoder = PQDecoderT;
|
|
62
66
|
|
|
@@ -160,7 +164,7 @@ struct PQCodeDistance {
|
|
|
160
164
|
if constexpr (std::is_same_v<PQDecoderT, PQDecoder8>) {
|
|
161
165
|
return pq_code_distance_single_impl<SL>(M, nbits, sim_table, code);
|
|
162
166
|
} else {
|
|
163
|
-
return PQCodeDistanceScalar<PQDecoderT>::distance_single_code(
|
|
167
|
+
return PQCodeDistanceScalar<PQDecoderT, SL>::distance_single_code(
|
|
164
168
|
M, nbits, sim_table, code);
|
|
165
169
|
}
|
|
166
170
|
}
|
|
@@ -191,7 +195,7 @@ struct PQCodeDistance {
|
|
|
191
195
|
result2,
|
|
192
196
|
result3);
|
|
193
197
|
} else {
|
|
194
|
-
PQCodeDistanceScalar<PQDecoderT>::distance_four_codes(
|
|
198
|
+
PQCodeDistanceScalar<PQDecoderT, SL>::distance_four_codes(
|
|
195
199
|
M,
|
|
196
200
|
nbits,
|
|
197
201
|
sim_table,
|
|
@@ -25,34 +25,9 @@ inline void prefetch_L3(const void* address) {
|
|
|
25
25
|
_mm_prefetch((const char*)address, _MM_HINT_T2);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
#elif defined(__aarch64__)
|
|
29
|
-
|
|
30
|
-
// ARM64
|
|
31
|
-
|
|
32
|
-
#ifdef _MSC_VER
|
|
33
|
-
|
|
34
|
-
// todo: arm on MSVC
|
|
35
|
-
inline void prefetch_L1(const void* address) {}
|
|
36
|
-
inline void prefetch_L2(const void* address) {}
|
|
37
|
-
inline void prefetch_L3(const void* address) {}
|
|
38
|
-
|
|
39
|
-
#else
|
|
40
|
-
// arm on non-MSVC
|
|
41
|
-
|
|
42
|
-
inline void prefetch_L1(const void* address) {
|
|
43
|
-
__builtin_prefetch(address, 0, 3);
|
|
44
|
-
}
|
|
45
|
-
inline void prefetch_L2(const void* address) {
|
|
46
|
-
__builtin_prefetch(address, 0, 2);
|
|
47
|
-
}
|
|
48
|
-
inline void prefetch_L3(const void* address) {
|
|
49
|
-
__builtin_prefetch(address, 0, 1);
|
|
50
|
-
}
|
|
51
|
-
#endif
|
|
52
|
-
|
|
53
28
|
#else
|
|
54
29
|
|
|
55
|
-
//
|
|
30
|
+
// other platforms, including ARM64
|
|
56
31
|
|
|
57
32
|
#ifdef _MSC_VER
|
|
58
33
|
|
|
@@ -60,6 +60,19 @@ void round_tab(const float* tab, size_t n, float a, float bi, T* tab_out) {
|
|
|
60
60
|
|
|
61
61
|
} // anonymous namespace
|
|
62
62
|
|
|
63
|
+
float fastscan_lut_scale(
|
|
64
|
+
float max_column_span,
|
|
65
|
+
float max_sum_span,
|
|
66
|
+
size_t n_rounded_terms) {
|
|
67
|
+
const float headroom = 0.5f * float(n_rounded_terms);
|
|
68
|
+
const float sum_budget = 65535.0f - headroom;
|
|
69
|
+
const float a = std::min(
|
|
70
|
+
max_column_span > 0 ? 255.0f / max_column_span : HUGE_VALF,
|
|
71
|
+
(max_sum_span > 0 && sum_budget > 0) ? sum_budget / max_sum_span
|
|
72
|
+
: HUGE_VALF);
|
|
73
|
+
return std::isfinite(a) ? a : 0.0f;
|
|
74
|
+
}
|
|
75
|
+
|
|
63
76
|
void round_uint8_per_column(
|
|
64
77
|
float* tab,
|
|
65
78
|
size_t n,
|
|
@@ -67,6 +80,7 @@ void round_uint8_per_column(
|
|
|
67
80
|
float* a_out,
|
|
68
81
|
float* b_out) {
|
|
69
82
|
float max_span = 0;
|
|
83
|
+
float total_span = 0;
|
|
70
84
|
std::vector<float> mins(n);
|
|
71
85
|
for (size_t i = 0; i < n; i++) {
|
|
72
86
|
mins[i] = tab_min(tab + i * d, d);
|
|
@@ -74,8 +88,9 @@ void round_uint8_per_column(
|
|
|
74
88
|
if (span > max_span) {
|
|
75
89
|
max_span = span;
|
|
76
90
|
}
|
|
91
|
+
total_span += span;
|
|
77
92
|
}
|
|
78
|
-
float a = max_span
|
|
93
|
+
float a = fastscan_lut_scale(max_span, total_span, n);
|
|
79
94
|
float b = 0;
|
|
80
95
|
for (size_t i = 0; i < n; i++) {
|
|
81
96
|
b += mins[i];
|
|
@@ -97,6 +112,7 @@ void round_uint8_per_column_multi(
|
|
|
97
112
|
float* a_out,
|
|
98
113
|
float* b_out) {
|
|
99
114
|
float max_span = 0;
|
|
115
|
+
float total_span = 0;
|
|
100
116
|
std::vector<float> mins(n);
|
|
101
117
|
for (size_t i = 0; i < n; i++) {
|
|
102
118
|
float min_i = HUGE_VAL;
|
|
@@ -110,8 +126,9 @@ void round_uint8_per_column_multi(
|
|
|
110
126
|
if (span > max_span) {
|
|
111
127
|
max_span = span;
|
|
112
128
|
}
|
|
129
|
+
total_span += span;
|
|
113
130
|
}
|
|
114
|
-
float a = max_span
|
|
131
|
+
float a = fastscan_lut_scale(max_span, total_span, n);
|
|
115
132
|
float b = 0;
|
|
116
133
|
for (size_t i = 0; i < n; i++) {
|
|
117
134
|
b += mins[i];
|
|
@@ -155,12 +172,7 @@ void quantize_LUT_and_bias(
|
|
|
155
172
|
max_span_dis += span;
|
|
156
173
|
b += mins[i];
|
|
157
174
|
}
|
|
158
|
-
a =
|
|
159
|
-
max_span_LUT > 0 ? 255.0f / max_span_LUT : HUGE_VALF,
|
|
160
|
-
max_span_dis > 0 ? 65535.0f / max_span_dis : HUGE_VALF);
|
|
161
|
-
if (!std::isfinite(a)) {
|
|
162
|
-
a = 0.0f;
|
|
163
|
-
}
|
|
175
|
+
a = fastscan_lut_scale(max_span_LUT, max_span_dis, M);
|
|
164
176
|
|
|
165
177
|
for (size_t i = 0; i < M; i++) {
|
|
166
178
|
round_tab(LUT + i * ksub, ksub, a, mins[i], LUTq + i * ksub);
|
|
@@ -180,12 +192,7 @@ void quantize_LUT_and_bias(
|
|
|
180
192
|
max_span_dis += span;
|
|
181
193
|
b += mins[i];
|
|
182
194
|
}
|
|
183
|
-
a =
|
|
184
|
-
max_span_LUT > 0 ? 255.0f / max_span_LUT : HUGE_VALF,
|
|
185
|
-
max_span_dis > 0 ? 65535.0f / max_span_dis : HUGE_VALF);
|
|
186
|
-
if (!std::isfinite(a)) {
|
|
187
|
-
a = 0.0f;
|
|
188
|
-
}
|
|
195
|
+
a = fastscan_lut_scale(max_span_LUT, max_span_dis, M);
|
|
189
196
|
b += bias_min;
|
|
190
197
|
|
|
191
198
|
for (size_t i = 0; i < M; i++) {
|
|
@@ -219,12 +226,7 @@ void quantize_LUT_and_bias(
|
|
|
219
226
|
b = std::min(b, b2j);
|
|
220
227
|
}
|
|
221
228
|
|
|
222
|
-
a =
|
|
223
|
-
max_span_LUT > 0 ? 255.0f / max_span_LUT : HUGE_VALF,
|
|
224
|
-
max_span_dis > 0 ? 65535.0f / max_span_dis : HUGE_VALF);
|
|
225
|
-
if (!std::isfinite(a)) {
|
|
226
|
-
a = 0.0f;
|
|
227
|
-
}
|
|
229
|
+
a = fastscan_lut_scale(max_span_LUT, max_span_dis, M);
|
|
228
230
|
|
|
229
231
|
ij = 0;
|
|
230
232
|
size_t ij_2 = 0;
|
|
@@ -266,13 +268,15 @@ void quantize_LUT_and_bias(
|
|
|
266
268
|
}
|
|
267
269
|
|
|
268
270
|
float max_span = -HUGE_VAL;
|
|
271
|
+
float total_span = 0;
|
|
269
272
|
b = 0;
|
|
270
273
|
for (size_t i = 0; i < M; i++) {
|
|
271
274
|
float span = maxs[i] - mins[i];
|
|
272
275
|
max_span = std::max(max_span, span);
|
|
276
|
+
total_span += span;
|
|
273
277
|
b += mins[i];
|
|
274
278
|
}
|
|
275
|
-
a = max_span
|
|
279
|
+
a = fastscan_lut_scale(max_span, total_span, M);
|
|
276
280
|
ij = 0;
|
|
277
281
|
size_t ij_2 = 0;
|
|
278
282
|
for (size_t j = 0; j < nprobe; j++) {
|
|
@@ -321,12 +325,7 @@ void aq_quantize_LUT_and_bias(
|
|
|
321
325
|
max_span_dis += (i >= M - M_norm ? span * norm_scale : span);
|
|
322
326
|
b += mins[i];
|
|
323
327
|
}
|
|
324
|
-
a =
|
|
325
|
-
max_span_LUT > 0 ? 255.0f / max_span_LUT : HUGE_VALF,
|
|
326
|
-
max_span_dis > 0 ? 65535.0f / max_span_dis : HUGE_VALF);
|
|
327
|
-
if (!std::isfinite(a)) {
|
|
328
|
-
a = 0.0f;
|
|
329
|
-
}
|
|
328
|
+
a = fastscan_lut_scale(max_span_LUT, max_span_dis, M);
|
|
330
329
|
b += bias_min;
|
|
331
330
|
|
|
332
331
|
for (size_t i = 0; i < M; i++) {
|
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
#pragma once
|
|
9
9
|
|
|
10
|
+
#include <cstddef>
|
|
11
|
+
|
|
10
12
|
#include <cstdint>
|
|
11
13
|
#include <cstdio>
|
|
12
14
|
|
|
@@ -25,6 +27,15 @@ namespace faiss {
|
|
|
25
27
|
|
|
26
28
|
namespace quantize_lut {
|
|
27
29
|
|
|
30
|
+
/** Scale for a fast scan LUT, bounding both the uint8 entry and the uint16
|
|
31
|
+
* sum the kernel accumulates. `n_rounded_terms` is how many rounded values
|
|
32
|
+
* land in one accumulator: the columns, plus one for a rounded bias term.
|
|
33
|
+
*/
|
|
34
|
+
float fastscan_lut_scale(
|
|
35
|
+
float max_column_span,
|
|
36
|
+
float max_sum_span,
|
|
37
|
+
size_t n_rounded_terms);
|
|
38
|
+
|
|
28
39
|
/* affine quantizer, a and b are the affine coefficients, marginalize over d
|
|
29
40
|
*
|
|
30
41
|
* @param tab input/output, size (n, d)
|
|
@@ -53,6 +53,28 @@ BitwiseAndDotProductResult bitwise_and_dot_product_with_popcount(
|
|
|
53
53
|
size_t size,
|
|
54
54
|
size_t qb);
|
|
55
55
|
|
|
56
|
+
/// Four independent AND-dot-product/popcount pairs for a four-plane query.
|
|
57
|
+
/// Query contains 4 * size bytes; each data pointer contains `size` bytes.
|
|
58
|
+
/// Byte-aligned buffers and arbitrary byte counts are supported.
|
|
59
|
+
template <SIMDLevel SL = SINGLE_SIMD_LEVEL>
|
|
60
|
+
inline void bitwise_q4_batch_4(
|
|
61
|
+
const uint8_t* query,
|
|
62
|
+
const uint8_t* const* data,
|
|
63
|
+
size_t size,
|
|
64
|
+
BitwiseAndDotProductResult* results) {
|
|
65
|
+
for (size_t i = 0; i < 4; ++i) {
|
|
66
|
+
results[i] = bitwise_and_dot_product_with_popcount<SL>(
|
|
67
|
+
query, data[i], size, 4);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
template <>
|
|
72
|
+
void bitwise_q4_batch_4<SIMDLevel::AVX512_VPOPCNT>(
|
|
73
|
+
const uint8_t* query,
|
|
74
|
+
const uint8_t* const* data,
|
|
75
|
+
size_t size,
|
|
76
|
+
BitwiseAndDotProductResult* results);
|
|
77
|
+
|
|
56
78
|
/**
|
|
57
79
|
* Compute dot product between query and binary data using popcount on XOR.
|
|
58
80
|
*
|
|
@@ -140,15 +162,17 @@ inline uint64_t bitwise_and_dot_product<SIMDLevel::NONE>(
|
|
|
140
162
|
uint64_t sum = 0;
|
|
141
163
|
size_t offset = 0;
|
|
142
164
|
for (size_t step = 64 / 8; offset + step <= size; offset += step) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
165
|
+
uint64_t yv;
|
|
166
|
+
std::memcpy(&yv, data + offset, sizeof(yv));
|
|
167
|
+
for (size_t j = 0; j < qb; j++) {
|
|
168
|
+
uint64_t qv;
|
|
169
|
+
std::memcpy(&qv, query + j * size + offset, sizeof(qv));
|
|
146
170
|
sum += popcount64(qv & yv) << j;
|
|
147
171
|
}
|
|
148
172
|
}
|
|
149
173
|
for (; offset < size; ++offset) {
|
|
150
174
|
const auto yv = *(data + offset);
|
|
151
|
-
for (
|
|
175
|
+
for (size_t j = 0; j < qb; j++) {
|
|
152
176
|
const auto qv = *(query + j * size + offset);
|
|
153
177
|
sum += popcount32(qv & yv) << j;
|
|
154
178
|
}
|
|
@@ -167,17 +191,19 @@ inline BitwiseAndDotProductResult bitwise_and_dot_product_with_popcount<
|
|
|
167
191
|
uint64_t popcount_sum = 0;
|
|
168
192
|
size_t offset = 0;
|
|
169
193
|
for (size_t step = 64 / 8; offset + step <= size; offset += step) {
|
|
170
|
-
|
|
194
|
+
uint64_t yv;
|
|
195
|
+
std::memcpy(&yv, data + offset, sizeof(yv));
|
|
171
196
|
popcount_sum += popcount64(yv);
|
|
172
|
-
for (
|
|
173
|
-
|
|
197
|
+
for (size_t j = 0; j < qb; j++) {
|
|
198
|
+
uint64_t qv;
|
|
199
|
+
std::memcpy(&qv, query + j * size + offset, sizeof(qv));
|
|
174
200
|
dot_product += popcount64(qv & yv) << j;
|
|
175
201
|
}
|
|
176
202
|
}
|
|
177
203
|
for (; offset < size; ++offset) {
|
|
178
204
|
const auto yv = *(data + offset);
|
|
179
205
|
popcount_sum += popcount32(yv);
|
|
180
|
-
for (
|
|
206
|
+
for (size_t j = 0; j < qb; j++) {
|
|
181
207
|
const auto qv = *(query + j * size + offset);
|
|
182
208
|
dot_product += popcount32(qv & yv) << j;
|
|
183
209
|
}
|
|
@@ -194,15 +220,17 @@ inline uint64_t bitwise_xor_dot_product<SIMDLevel::NONE>(
|
|
|
194
220
|
uint64_t sum = 0;
|
|
195
221
|
size_t offset = 0;
|
|
196
222
|
for (size_t step = 64 / 8; offset + step <= size; offset += step) {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
223
|
+
uint64_t yv;
|
|
224
|
+
std::memcpy(&yv, data + offset, sizeof(yv));
|
|
225
|
+
for (size_t j = 0; j < qb; j++) {
|
|
226
|
+
uint64_t qv;
|
|
227
|
+
std::memcpy(&qv, query + j * size + offset, sizeof(qv));
|
|
200
228
|
sum += popcount64(qv ^ yv) << j;
|
|
201
229
|
}
|
|
202
230
|
}
|
|
203
231
|
for (; offset < size; ++offset) {
|
|
204
232
|
const auto yv = *(data + offset);
|
|
205
|
-
for (
|
|
233
|
+
for (size_t j = 0; j < qb; j++) {
|
|
206
234
|
const auto qv = *(query + j * size + offset);
|
|
207
235
|
sum += popcount32(qv ^ yv) << j;
|
|
208
236
|
}
|
|
@@ -215,7 +243,8 @@ inline uint64_t popcount<SIMDLevel::NONE>(const uint8_t* data, size_t size) {
|
|
|
215
243
|
uint64_t sum = 0;
|
|
216
244
|
size_t offset = 0;
|
|
217
245
|
for (size_t step = 64 / 8; offset + step <= size; offset += step) {
|
|
218
|
-
|
|
246
|
+
uint64_t yv;
|
|
247
|
+
std::memcpy(&yv, data + offset, sizeof(yv));
|
|
219
248
|
sum += popcount64(yv);
|
|
220
249
|
}
|
|
221
250
|
for (; offset < size; ++offset) {
|
|
@@ -332,16 +361,12 @@ inline void quantize_query_values<SIMDLevel::NONE>(
|
|
|
332
361
|
/*********************************************************
|
|
333
362
|
* Multi-bit RaBitQ inner product kernels.
|
|
334
363
|
*
|
|
335
|
-
*
|
|
364
|
+
* Score = sum_i rotated_q[i] * ((sign_i << ex_bits) + ex_i + cb)
|
|
336
365
|
*
|
|
337
|
-
*
|
|
338
|
-
*
|
|
339
|
-
*
|
|
340
|
-
*
|
|
341
|
-
* ex_bits >= 2: Bit-plane decomposition (BMI2 required) — PEXT extracts
|
|
342
|
-
* each bit plane in one instruction, then the same
|
|
343
|
-
* bit→mask→float kernel computes each plane's dot product.
|
|
344
|
-
* Fallback: Scalar extraction via 64-bit window read + shift + mask.
|
|
366
|
+
* ex_bits == 1: bits map straight to floats. No extraction.
|
|
367
|
+
* ex_bits 2..7: BMI2 PEXT extracts each bit plane.
|
|
368
|
+
* ex_bits == 8: whole bytes. No extraction and no BMI2.
|
|
369
|
+
* Fallback: scalar math reads one code at a time.
|
|
345
370
|
*********************************************************/
|
|
346
371
|
namespace faiss::rabitq::multibit {
|
|
347
372
|
|
|
@@ -357,6 +382,16 @@ inline float ip_scalar(
|
|
|
357
382
|
size_t ex_bits,
|
|
358
383
|
float cb) {
|
|
359
384
|
float result = 0.0f;
|
|
385
|
+
if (ex_bits == 8) {
|
|
386
|
+
// RBQ9 is byte-aligned, including the last dimension. Do not require
|
|
387
|
+
// trailing factor bytes for the scalar reference or SIMD tail.
|
|
388
|
+
for (size_t i = start; i < d; ++i) {
|
|
389
|
+
const int sb = (sign_bits[i / 8] >> (i % 8)) & 1;
|
|
390
|
+
result += rotated_q[i] *
|
|
391
|
+
(static_cast<float>((sb << 8) + ex_code[i]) + cb);
|
|
392
|
+
}
|
|
393
|
+
return result;
|
|
394
|
+
}
|
|
360
395
|
const int sign_shift = static_cast<int>(ex_bits);
|
|
361
396
|
const uint64_t code_mask = (1ULL << ex_bits) - 1;
|
|
362
397
|
for (size_t i = start; i < d; i++) {
|
|
@@ -405,4 +440,118 @@ inline float compute_inner_product<SIMDLevel::NONE>(
|
|
|
405
440
|
return ip_scalar(sign_bits, ex_code, rotated_q, 0, d, ex_bits, cb);
|
|
406
441
|
}
|
|
407
442
|
|
|
443
|
+
/**
|
|
444
|
+
* compute_inner_product with the sign term supplied by the caller:
|
|
445
|
+
*
|
|
446
|
+
* (1 << ex_bits) * sign_ip + sum_i rotated_q[i] * ex_i + cb * q_sum
|
|
447
|
+
*
|
|
448
|
+
* With sign_ip = fvec_masked_sum(rotated_q, sign_bits, d) and
|
|
449
|
+
* q_sum = sum_i rotated_q[i], this equals
|
|
450
|
+
* compute_inner_product(sign_bits, ex_code, rotated_q, d, ex_bits, cb) up to
|
|
451
|
+
* float rounding. It serves codes whose sign bits are not stored next to
|
|
452
|
+
* ex_code, e.g. split between memory and disk: the caller accumulates the
|
|
453
|
+
* sign term piece by piece with fvec_masked_sum. q_sum depends on the
|
|
454
|
+
* query only, so it can be computed once per query.
|
|
455
|
+
*
|
|
456
|
+
* Unlike compute_inner_product, this reads only the (d * ex_bits + 7) / 8
|
|
457
|
+
* bytes of ex_code and never the bytes after them.
|
|
458
|
+
*
|
|
459
|
+
* @param ex_code packed extra-bit codes (ex_bits bits/dim); may be null
|
|
460
|
+
* when ex_bits == 0
|
|
461
|
+
* @param rotated_q rotated query vector (float[d])
|
|
462
|
+
* @param d dimensionality
|
|
463
|
+
* @param ex_bits number of extra bits per dimension, in [0, 8]
|
|
464
|
+
* @param cb constant bias: -(2^ex_bits - 0.5)
|
|
465
|
+
* @param sign_ip sum_i rotated_q[i] * sign_i
|
|
466
|
+
* @param q_sum sum_i rotated_q[i]
|
|
467
|
+
* @return inner product value
|
|
468
|
+
*/
|
|
469
|
+
template <SIMDLevel SL = SINGLE_SIMD_LEVEL>
|
|
470
|
+
float compute_inner_product_with_sign_ip(
|
|
471
|
+
const uint8_t* __restrict ex_code,
|
|
472
|
+
const float* __restrict rotated_q,
|
|
473
|
+
size_t d,
|
|
474
|
+
size_t ex_bits,
|
|
475
|
+
float cb,
|
|
476
|
+
float sign_ip,
|
|
477
|
+
float q_sum);
|
|
478
|
+
|
|
479
|
+
/// SIMD levels with a split inner-product kernel.
|
|
480
|
+
constexpr int RABITQ_SPLIT_IP_SIMD_LEVELS = (1 << int(SIMDLevel::NONE)) |
|
|
481
|
+
(1 << int(SIMDLevel::AVX2)) | (1 << int(SIMDLevel::AVX512));
|
|
482
|
+
|
|
483
|
+
/// Load the code bytes at ex_code + offset into the low bytes of a uint64,
|
|
484
|
+
/// reading 8 bytes when they all lie within the first total_bytes bytes of
|
|
485
|
+
/// ex_code and only the remaining ones otherwise.
|
|
486
|
+
static inline uint64_t load_ex_code_window(
|
|
487
|
+
const uint8_t* ex_code,
|
|
488
|
+
size_t offset,
|
|
489
|
+
size_t total_bytes) {
|
|
490
|
+
uint64_t window = 0;
|
|
491
|
+
if (offset + sizeof(window) <= total_bytes) {
|
|
492
|
+
memcpy(&window, ex_code + offset, sizeof(window));
|
|
493
|
+
} else {
|
|
494
|
+
memcpy(&window, ex_code + offset, total_bytes - offset);
|
|
495
|
+
}
|
|
496
|
+
return window;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/// Scalar sum over [start, d) of rotated_q[i] * ex_i, for ex_bits in [1, 8].
|
|
500
|
+
/// Reads only the (d * ex_bits + 7) / 8 bytes of ex_code. Also serves as the
|
|
501
|
+
/// tail handler of the SIMD kernels.
|
|
502
|
+
static inline float ex_ip_scalar(
|
|
503
|
+
const uint8_t* __restrict ex_code,
|
|
504
|
+
const float* __restrict rotated_q,
|
|
505
|
+
size_t start,
|
|
506
|
+
size_t d,
|
|
507
|
+
size_t ex_bits) {
|
|
508
|
+
float result = 0.0f;
|
|
509
|
+
if (ex_bits == 8) {
|
|
510
|
+
for (size_t i = start; i < d; ++i) {
|
|
511
|
+
result += rotated_q[i] * static_cast<float>(ex_code[i]);
|
|
512
|
+
}
|
|
513
|
+
return result;
|
|
514
|
+
}
|
|
515
|
+
const unsigned code_mask = (1u << ex_bits) - 1;
|
|
516
|
+
for (size_t i = start; i < d; i++) {
|
|
517
|
+
const size_t bit_pos = i * ex_bits;
|
|
518
|
+
const size_t byte_idx = bit_pos / 8;
|
|
519
|
+
const size_t bit_offset = bit_pos % 8;
|
|
520
|
+
// With ex_bits <= 8 a code spans at most two bytes.
|
|
521
|
+
unsigned raw = ex_code[byte_idx];
|
|
522
|
+
if (bit_offset + ex_bits > 8) {
|
|
523
|
+
raw |= static_cast<unsigned>(ex_code[byte_idx + 1]) << 8;
|
|
524
|
+
}
|
|
525
|
+
const unsigned ex_val = (raw >> bit_offset) & code_mask;
|
|
526
|
+
result += rotated_q[i] * static_cast<float>(ex_val);
|
|
527
|
+
}
|
|
528
|
+
return result;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/// The terms compute_inner_product_with_sign_ip adds to the extra-bit inner
|
|
532
|
+
/// product ex_ip.
|
|
533
|
+
static inline float add_sign_and_bias_terms(
|
|
534
|
+
float ex_ip,
|
|
535
|
+
size_t ex_bits,
|
|
536
|
+
float cb,
|
|
537
|
+
float sign_ip,
|
|
538
|
+
float q_sum) {
|
|
539
|
+
return static_cast<float>(1u << ex_bits) * sign_ip + ex_ip + cb * q_sum;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
template <>
|
|
543
|
+
inline float compute_inner_product_with_sign_ip<SIMDLevel::NONE>(
|
|
544
|
+
const uint8_t* __restrict ex_code,
|
|
545
|
+
const float* __restrict rotated_q,
|
|
546
|
+
size_t d,
|
|
547
|
+
size_t ex_bits,
|
|
548
|
+
float cb,
|
|
549
|
+
float sign_ip,
|
|
550
|
+
float q_sum) {
|
|
551
|
+
const float ex_ip = ex_bits == 0
|
|
552
|
+
? 0.0f
|
|
553
|
+
: ex_ip_scalar(ex_code, rotated_q, 0, d, ex_bits);
|
|
554
|
+
return add_sign_and_bias_terms(ex_ip, ex_bits, cb, sign_ip, q_sum);
|
|
555
|
+
}
|
|
556
|
+
|
|
408
557
|
} // namespace faiss::rabitq::multibit
|
|
@@ -6,8 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
#include <faiss/utils/distances.h>
|
|
9
|
-
|
|
10
|
-
#ifdef __aarch64__
|
|
9
|
+
#include <faiss/utils/simd_impl/masked_sum.h>
|
|
11
10
|
|
|
12
11
|
#include <arm_neon.h>
|
|
13
12
|
#include <limits>
|
|
@@ -41,6 +40,14 @@ void fvec_madd<SIMDLevel::ARM_NEON>(
|
|
|
41
40
|
c[i] = a[i] + bf * b[i];
|
|
42
41
|
}
|
|
43
42
|
|
|
43
|
+
template <>
|
|
44
|
+
float fvec_masked_sum<SIMDLevel::ARM_NEON>(
|
|
45
|
+
const float* x,
|
|
46
|
+
const uint8_t* bits,
|
|
47
|
+
size_t d) {
|
|
48
|
+
return masked_sum<SIMDLevel::ARM_NEON>(x, bits, d);
|
|
49
|
+
}
|
|
50
|
+
|
|
44
51
|
template <>
|
|
45
52
|
void fvec_L2sqr_ny_transposed<SIMDLevel::ARM_NEON>(
|
|
46
53
|
float* dis,
|
|
@@ -150,5 +157,3 @@ int fvec_madd_and_argmin<SIMDLevel::ARM_NEON>(
|
|
|
150
157
|
}
|
|
151
158
|
|
|
152
159
|
} // namespace faiss
|
|
153
|
-
|
|
154
|
-
#endif // __aarch64__
|