faiss 0.6.3 → 0.6.5
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 +8 -0
- data/ext/faiss/extconf.rb +1 -1
- 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 +37 -0
- data/vendor/faiss/faiss/IVFlib.cpp +99 -0
- data/vendor/faiss/faiss/IVFlib.h +15 -0
- 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/IndexBinaryFromFloat.cpp +23 -2
- data/vendor/faiss/faiss/IndexBinaryHNSW.cpp +94 -144
- data/vendor/faiss/faiss/IndexBinaryHNSW.h +18 -5
- data/vendor/faiss/faiss/IndexBinaryIVF.cpp +40 -14
- data/vendor/faiss/faiss/IndexBinaryIVF.h +8 -1
- data/vendor/faiss/faiss/IndexFastScan.cpp +33 -17
- data/vendor/faiss/faiss/IndexFastScan.h +6 -3
- data/vendor/faiss/faiss/IndexFlat.cpp +64 -4
- data/vendor/faiss/faiss/IndexFlat.h +33 -2
- data/vendor/faiss/faiss/IndexFlatCodes.cpp +6 -1
- data/vendor/faiss/faiss/IndexHNSW.cpp +755 -99
- data/vendor/faiss/faiss/IndexHNSW.h +69 -7
- data/vendor/faiss/faiss/IndexIDMap.cpp +43 -6
- data/vendor/faiss/faiss/IndexIDMap.h +7 -0
- data/vendor/faiss/faiss/IndexIVF.cpp +297 -32
- data/vendor/faiss/faiss/IndexIVF.h +53 -1
- data/vendor/faiss/faiss/IndexIVFFastScan.cpp +46 -14
- data/vendor/faiss/faiss/IndexIVFFastScan.h +4 -2
- data/vendor/faiss/faiss/IndexIVFFlat.cpp +33 -0
- data/vendor/faiss/faiss/IndexIVFFlat.h +16 -0
- data/vendor/faiss/faiss/IndexIVFPQ.cpp +9 -1
- data/vendor/faiss/faiss/IndexIVFPQ.h +11 -0
- data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +1 -0
- data/vendor/faiss/faiss/IndexIVFRaBitQ.cpp +3 -20
- data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.cpp +50 -14
- data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.h +5 -2
- data/vendor/faiss/faiss/IndexIVFSQFastScan.cpp +855 -0
- data/vendor/faiss/faiss/IndexIVFSQFastScan.h +145 -0
- data/vendor/faiss/faiss/IndexNNDescent.cpp +0 -3
- data/vendor/faiss/faiss/IndexPiPNN.cpp +201 -0
- data/vendor/faiss/faiss/IndexPiPNN.h +83 -0
- data/vendor/faiss/faiss/IndexRaBitQFastScan.cpp +6 -3
- data/vendor/faiss/faiss/IndexRaBitQFastScan.h +10 -4
- 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 +13 -3
- data/vendor/faiss/faiss/IndexShards.h +5 -0
- data/vendor/faiss/faiss/IndexShardsIVF.cpp +4 -3
- data/vendor/faiss/faiss/SuperKMeans.cpp +87 -22
- data/vendor/faiss/faiss/SuperKMeans.h +12 -6
- data/vendor/faiss/faiss/VectorTransform.cpp +40 -1
- data/vendor/faiss/faiss/VectorTransform.h +3 -0
- data/vendor/faiss/faiss/clone_index.cpp +27 -0
- data/vendor/faiss/faiss/gpu/Dataset.h +112 -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 +4 -5
- data/vendor/faiss/faiss/gpu/GpuDistance.h +2 -5
- data/vendor/faiss/faiss/gpu/GpuIndex.h +8 -18
- data/vendor/faiss/faiss/gpu/GpuIndexBinaryCagra.h +26 -13
- data/vendor/faiss/faiss/gpu/GpuIndexCagra.h +109 -63
- data/vendor/faiss/faiss/gpu/GpuIndexFlat.h +11 -0
- data/vendor/faiss/faiss/gpu/GpuIndexIVF.h +6 -0
- 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/utils/DeviceUtils.h +11 -0
- data/vendor/faiss/faiss/gpu/utils/StackDeviceMemory.cpp +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalCloner.h +11 -0
- data/vendor/faiss/faiss/gpu_metal/MetalDistance.h +92 -0
- data/vendor/faiss/faiss/gpu_metal/MetalIndex.h +4 -0
- data/vendor/faiss/faiss/gpu_metal/MetalIndexBinaryFlat.h +69 -0
- data/vendor/faiss/faiss/gpu_metal/MetalIndexIVFPQ.h +38 -0
- data/vendor/faiss/faiss/gpu_metal/MetalKernels.h +106 -0
- data/vendor/faiss/faiss/gpu_metal/MetalPythonBridge.h +10 -0
- data/vendor/faiss/faiss/impl/AdditiveQuantizer.cpp +1 -1
- data/vendor/faiss/faiss/impl/AuxIndexStructures.cpp +2 -0
- 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 +287 -134
- 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 +465 -125
- data/vendor/faiss/faiss/impl/HNSW.h +118 -7
- data/vendor/faiss/faiss/impl/IDSelector.h +44 -0
- data/vendor/faiss/faiss/impl/LocalSearchQuantizer.cpp +6 -19
- data/vendor/faiss/faiss/impl/NNDescent.cpp +12 -4
- data/vendor/faiss/faiss/impl/NSG.cpp +3 -2
- data/vendor/faiss/faiss/impl/Panorama.h +14 -4
- data/vendor/faiss/faiss/impl/PiPNN.cpp +822 -0
- data/vendor/faiss/faiss/impl/PiPNN.h +122 -0
- data/vendor/faiss/faiss/impl/ProductQuantizer.cpp +58 -15
- data/vendor/faiss/faiss/impl/RaBitQUtils.cpp +1 -1
- data/vendor/faiss/faiss/impl/RaBitQUtils.h +1 -1
- data/vendor/faiss/faiss/impl/RaBitQuantizer.cpp +150 -60
- data/vendor/faiss/faiss/impl/RaBitQuantizer.h +62 -4
- data/vendor/faiss/faiss/impl/RaBitQuantizerMultiBit.cpp +2 -2
- data/vendor/faiss/faiss/impl/ResultHandler.h +9 -3
- data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +61 -30
- data/vendor/faiss/faiss/impl/ScalarQuantizer.h +7 -16
- 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 +89 -13
- 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 -1
- 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 +18 -129
- data/vendor/faiss/faiss/impl/fast_scan/dispatching.h +25 -19
- data/vendor/faiss/faiss/impl/fast_scan/fast_scan.cpp +5 -0
- data/vendor/faiss/faiss/impl/fast_scan/impl-avx2.cpp +0 -4
- data/vendor/faiss/faiss/impl/fast_scan/impl-avx512.cpp +0 -4
- data/vendor/faiss/faiss/impl/fast_scan/impl-neon.cpp +0 -88
- 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 +22 -1
- data/vendor/faiss/faiss/impl/fast_scan/kernels_simd512.h +3 -2
- data/vendor/faiss/faiss/impl/fast_scan/simd_result_handlers.h +41 -23
- 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 +302 -29
- data/vendor/faiss/faiss/impl/index_write.cpp +126 -26
- 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 +45 -0
- data/vendor/faiss/faiss/impl/polysemous_training/avx512.cpp +0 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/IVFPQScanner_impl.h +152 -43
- 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 +23 -4
- 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/avx2.cpp +0 -4
- data/vendor/faiss/faiss/impl/result_handler/avx512.cpp +0 -4
- 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 +6 -1
- data/vendor/faiss/faiss/impl/scalar_quantizer/distance_computers.h +7 -3
- data/vendor/faiss/faiss/impl/scalar_quantizer/quantizers.h +28 -52
- data/vendor/faiss/faiss/impl/scalar_quantizer/scanners.h +59 -11
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx2.cpp +232 -79
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512-impl.h +482 -103
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512-spr.cpp +2 -149
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512.cpp +3 -698
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-dispatch.h +101 -72
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-neon.cpp +203 -99
- 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 +47 -22
- data/vendor/faiss/faiss/impl/simdlib/simdlib_avx2.h +14 -0
- data/vendor/faiss/faiss/impl/simdlib/simdlib_dispatch.h +7 -8
- data/vendor/faiss/faiss/impl/sq_fastscan_utils.h +232 -0
- data/vendor/faiss/faiss/index_factory.cpp +84 -1
- data/vendor/faiss/faiss/invlists/InvertedLists.cpp +10 -5
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.cpp +10 -4
- data/vendor/faiss/faiss/svs/IndexSVSVamana.cpp +16 -4
- data/vendor/faiss/faiss/svs/IndexSVSVamana.h +11 -3
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLVQ.cpp +4 -2
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLVQ.h +2 -1
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLeanVec.cpp +9 -2
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLeanVec.h +2 -1
- data/vendor/faiss/faiss/utils/AlignedTable.h +6 -1
- data/vendor/faiss/faiss/utils/Heap.cpp +4 -3
- 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 +246 -28
- data/vendor/faiss/faiss/utils/distances.h +34 -0
- data/vendor/faiss/faiss/utils/distances_dispatch.h +36 -28
- data/vendor/faiss/faiss/utils/distances_fused/avx512.cpp +2 -5
- data/vendor/faiss/faiss/utils/distances_fused/distances_fused.cpp +1 -15
- 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/fp16-fp16c.h +4 -0
- data/vendor/faiss/faiss/utils/fp16-inl.h +26 -52
- data/vendor/faiss/faiss/utils/hamming.cpp +15 -9
- data/vendor/faiss/faiss/utils/hamming.h +10 -1
- data/vendor/faiss/faiss/utils/hamming_distance/common.h +14 -3
- 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 +20 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-avx512.h +34 -6
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-avx512_vpopcnt.h +217 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-neon.h +0 -4
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_impl.h +143 -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/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 +51 -16
- data/vendor/faiss/faiss/utils/simd_impl/distances_aarch64.cpp +9 -4
- data/vendor/faiss/faiss/utils/simd_impl/distances_arm_sve.cpp +231 -35
- data/vendor/faiss/faiss/utils/simd_impl/distances_avx2.cpp +64 -5
- data/vendor/faiss/faiss/utils/simd_impl/distances_avx512.cpp +64 -5
- data/vendor/faiss/faiss/utils/simd_impl/distances_rvv.cpp +428 -108
- data/vendor/faiss/faiss/utils/simd_impl/distances_rvv_kernel.h +68 -0
- data/vendor/faiss/faiss/utils/simd_impl/exhaustive_L2sqr_blas_cmax.h +93 -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/rabitq_avx2.cpp +54 -15
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_avx512.cpp +89 -55
- data/vendor/faiss/faiss/utils/simd_impl/{rabitq_avx512_spr.cpp → rabitq_avx512_vpopcnt.cpp} +70 -36
- 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_dispatch.h +2 -7
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_kernels.h +6 -1
- 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 +30 -0
- data/vendor/faiss/faiss/utils/simd_levels.cpp +191 -70
- data/vendor/faiss/faiss/utils/simd_levels.h +100 -16
- 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 +80 -0
- data/vendor/faiss/faiss/utils/utils.h +24 -0
- metadata +38 -5
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_avx512_spr.cpp +0 -15
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-avx512_spr.h +0 -171
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#define THE_SIMD_LEVEL SIMDLevel::AVX512_VPOPCNT
|
|
9
|
+
#include <faiss/utils/hamming_distance/hamming_computer-avx512_vpopcnt.h>
|
|
10
|
+
#include <faiss/utils/hamming_distance/hamming_impl.h>
|
|
11
|
+
|
|
12
|
+
// Must follow the computer specializations above.
|
|
13
|
+
// clang-format off
|
|
14
|
+
// NOLINTNEXTLINE(facebook-hte-InlineHeader)
|
|
15
|
+
#include <faiss/impl/binary_hamming/IndexBinaryIVF_impl.h>
|
|
16
|
+
// clang-format on
|
|
17
|
+
|
|
18
|
+
// Fails the build if the batch path stops being selected for this computer.
|
|
19
|
+
static_assert(faiss::has_hamming_batch<
|
|
20
|
+
faiss::HammingComputer20_tpl<faiss::SIMDLevel::AVX512_VPOPCNT>>);
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// Types without custom AVX512 code inherit from the NONE specializations
|
|
13
13
|
// in hamming_computer-generic.h. HammingComputer64 and
|
|
14
14
|
// HammingComputerDefault use scalar popcount here; the VPOPCNTDQ fast
|
|
15
|
-
// path lives in hamming_computer-
|
|
15
|
+
// path lives in hamming_computer-avx512_vpopcnt.h (AVX512_VPOPCNT level).
|
|
16
16
|
// GenHammingComputer classes leverage SSE/AVX2 intrinsics.
|
|
17
17
|
|
|
18
18
|
#include <cassert>
|
|
@@ -103,12 +103,40 @@ struct HammingComputerDefault_tpl<SIMDLevel::AVX512> {
|
|
|
103
103
|
remainder8 = code_size % 8;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
+
/// No VPOPCNTDQ at this level: count the bits of each nibble with a
|
|
107
|
+
/// 16-entry table (vpshufb), then sum the bytes per 64-bit lane (vpsadbw).
|
|
108
|
+
/// The partial last block is a masked load, so no byte past the code is
|
|
109
|
+
/// read.
|
|
106
110
|
int hamming(const uint8_t* b8) const {
|
|
107
|
-
const
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
111
|
+
const int code_size = quotient8 * 8 + remainder8;
|
|
112
|
+
const __m512i lut = _mm512_broadcast_i32x4(
|
|
113
|
+
_mm_setr_epi8(0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4));
|
|
114
|
+
const __m512i low4 = _mm512_set1_epi8(0x0f);
|
|
115
|
+
const auto count = [&](__m512i x) {
|
|
116
|
+
const __m512i lo = _mm512_and_si512(x, low4);
|
|
117
|
+
const __m512i hi = _mm512_and_si512(_mm512_srli_epi16(x, 4), low4);
|
|
118
|
+
const __m512i c = _mm512_add_epi8(
|
|
119
|
+
_mm512_shuffle_epi8(lut, lo), _mm512_shuffle_epi8(lut, hi));
|
|
120
|
+
return _mm512_sad_epu8(c, _mm512_setzero_si512());
|
|
121
|
+
};
|
|
122
|
+
__m512i accu = _mm512_setzero_si512();
|
|
123
|
+
int i = 0;
|
|
124
|
+
for (; i + 64 <= code_size; i += 64) {
|
|
125
|
+
accu = _mm512_add_epi64(
|
|
126
|
+
accu,
|
|
127
|
+
count(_mm512_xor_si512(
|
|
128
|
+
_mm512_loadu_si512(a8 + i),
|
|
129
|
+
_mm512_loadu_si512(b8 + i))));
|
|
130
|
+
}
|
|
131
|
+
if (i < code_size) {
|
|
132
|
+
const __mmask64 mask = _bzhi_u64(~uint64_t(0), code_size - i);
|
|
133
|
+
accu = _mm512_add_epi64(
|
|
134
|
+
accu,
|
|
135
|
+
count(_mm512_xor_si512(
|
|
136
|
+
_mm512_maskz_loadu_epi8(mask, a8 + i),
|
|
137
|
+
_mm512_maskz_loadu_epi8(mask, b8 + i))));
|
|
138
|
+
}
|
|
139
|
+
return static_cast<int>(_mm512_reduce_add_epi64(accu));
|
|
112
140
|
}
|
|
113
141
|
|
|
114
142
|
inline int get_code_size() const {
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#ifndef HAMMING_COMPUTER_AVX512_VPOPCNT_H
|
|
9
|
+
#define HAMMING_COMPUTER_AVX512_VPOPCNT_H
|
|
10
|
+
|
|
11
|
+
// AVX512_VPOPCNT HammingComputer specializations. The 32/64/Default kernels
|
|
12
|
+
// use VPOPCNTDQ; the batched 20-byte kernel uses AVX512_BITALG. This gives
|
|
13
|
+
// a faster path than the scalar popcount fallback used in the base AVX512
|
|
14
|
+
// specializations when compiled without -mavx512vpopcntdq.
|
|
15
|
+
|
|
16
|
+
#include <cassert>
|
|
17
|
+
#include <cstdint>
|
|
18
|
+
#include <cstring>
|
|
19
|
+
|
|
20
|
+
#include <faiss/utils/popcount.h>
|
|
21
|
+
|
|
22
|
+
#include <faiss/impl/platform_macros.h>
|
|
23
|
+
#include <faiss/utils/hamming_distance/hamming_computer-avx512.h>
|
|
24
|
+
|
|
25
|
+
#include <immintrin.h>
|
|
26
|
+
|
|
27
|
+
namespace faiss {
|
|
28
|
+
|
|
29
|
+
/***************************************************************************
|
|
30
|
+
* AVX512_VPOPCNT inheriting specializations without custom VPOPCNT code.
|
|
31
|
+
***************************************************************************/
|
|
32
|
+
|
|
33
|
+
#define FAISS_INHERIT_HAMMING_VPOPCNT(Class) \
|
|
34
|
+
template <> \
|
|
35
|
+
struct Class## \
|
|
36
|
+
_tpl<SIMDLevel::AVX512_VPOPCNT> : Class##_tpl<SIMDLevel::AVX512> { \
|
|
37
|
+
using Class##_tpl<SIMDLevel::AVX512>::Class##_tpl; \
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
FAISS_INHERIT_HAMMING_VPOPCNT(HammingComputer16);
|
|
41
|
+
FAISS_INHERIT_HAMMING_VPOPCNT(GenHammingComputer8);
|
|
42
|
+
FAISS_INHERIT_HAMMING_VPOPCNT(GenHammingComputer16);
|
|
43
|
+
FAISS_INHERIT_HAMMING_VPOPCNT(GenHammingComputer32);
|
|
44
|
+
FAISS_INHERIT_HAMMING_VPOPCNT(GenHammingComputerM8);
|
|
45
|
+
|
|
46
|
+
#undef FAISS_INHERIT_HAMMING_VPOPCNT
|
|
47
|
+
|
|
48
|
+
/***************************************************************************
|
|
49
|
+
* Custom AVX512_VPOPCNT specializations using VPOPCNTDQ.
|
|
50
|
+
***************************************************************************/
|
|
51
|
+
|
|
52
|
+
template <>
|
|
53
|
+
struct HammingComputer20_tpl<SIMDLevel::AVX512_VPOPCNT>
|
|
54
|
+
: HammingComputer20_tpl<SIMDLevel::AVX512> {
|
|
55
|
+
using HammingComputer20_tpl<SIMDLevel::AVX512>::HammingComputer20_tpl;
|
|
56
|
+
|
|
57
|
+
static constexpr size_t batch_size = 8;
|
|
58
|
+
static constexpr size_t kStride = get_code_size();
|
|
59
|
+
// 160 bytes is what the three loads in hamming_batch() cover, and the
|
|
60
|
+
// 16+4 or 4+16 split it applies per lane is written out for 20 bytes:
|
|
61
|
+
// the literal offsets and the two group indices are not derived from
|
|
62
|
+
// kStride, so another width needs the body reworked, not just retuned.
|
|
63
|
+
static_assert(batch_size * kStride == 160);
|
|
64
|
+
static_assert(kStride == 20, "hamming_batch() hardcodes the 16+4 split");
|
|
65
|
+
static constexpr __mmask64 kTailMask = 0xFFFFFFFFull;
|
|
66
|
+
|
|
67
|
+
/// Writes the query repeated batch_size times. The caller owns the buffer,
|
|
68
|
+
/// so a computer used only through hamming() carries no batch state.
|
|
69
|
+
static void build_batch_query(const uint8_t* a8, uint8_t* tile) {
|
|
70
|
+
for (size_t k = 0; k < batch_size; k++) {
|
|
71
|
+
memcpy(tile + k * kStride, a8, kStride);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
static void hamming_batch(
|
|
76
|
+
const uint8_t* tile,
|
|
77
|
+
const uint8_t* codes,
|
|
78
|
+
int32_t* dis) {
|
|
79
|
+
const __m512i zero = _mm512_setzero_si512();
|
|
80
|
+
const __m512i p0 = _mm512_popcnt_epi8(_mm512_xor_si512(
|
|
81
|
+
_mm512_loadu_si512(codes), _mm512_loadu_si512(tile)));
|
|
82
|
+
const __m512i p1 = _mm512_popcnt_epi8(_mm512_xor_si512(
|
|
83
|
+
_mm512_loadu_si512(codes + 64), _mm512_loadu_si512(tile + 64)));
|
|
84
|
+
const __m512i p2 = _mm512_popcnt_epi8(_mm512_xor_si512(
|
|
85
|
+
_mm512_maskz_loadu_epi8(kTailMask, codes + 128),
|
|
86
|
+
_mm512_maskz_loadu_epi8(kTailMask, tile + 128)));
|
|
87
|
+
|
|
88
|
+
alignas(64) uint64_t grp[24];
|
|
89
|
+
_mm512_store_si512(grp, _mm512_sad_epu8(p0, zero));
|
|
90
|
+
_mm512_store_si512(grp + 8, _mm512_sad_epu8(p1, zero));
|
|
91
|
+
_mm512_store_si512(grp + 16, _mm512_sad_epu8(p2, zero));
|
|
92
|
+
|
|
93
|
+
for (size_t k = 0; k < batch_size; k++) {
|
|
94
|
+
const size_t s = k * kStride;
|
|
95
|
+
const size_t g = s / 8;
|
|
96
|
+
uint32_t xh, qh;
|
|
97
|
+
if (s % 8 == 0) {
|
|
98
|
+
memcpy(&xh, codes + s + 16, 4);
|
|
99
|
+
memcpy(&qh, tile + s + 16, 4);
|
|
100
|
+
dis[k] = static_cast<int32_t>(
|
|
101
|
+
grp[g] + grp[g + 1] + popcount32(xh ^ qh));
|
|
102
|
+
} else {
|
|
103
|
+
memcpy(&xh, codes + s, 4);
|
|
104
|
+
memcpy(&qh, tile + s, 4);
|
|
105
|
+
dis[k] = static_cast<int32_t>(
|
|
106
|
+
popcount32(xh ^ qh) + grp[g + 1] + grp[g + 2]);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
template <>
|
|
113
|
+
struct HammingComputer32_tpl<SIMDLevel::AVX512_VPOPCNT> {
|
|
114
|
+
const uint8_t* a8;
|
|
115
|
+
|
|
116
|
+
HammingComputer32_tpl() {}
|
|
117
|
+
|
|
118
|
+
HammingComputer32_tpl(const uint8_t* a8_in, int code_size) {
|
|
119
|
+
set(a8_in, code_size);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
void set(const uint8_t* a8_in, FAISS_MAYBE_UNUSED int code_size) {
|
|
123
|
+
assert(code_size == 32);
|
|
124
|
+
a8 = a8_in;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
inline int hamming(const uint8_t* b8) const {
|
|
128
|
+
__m256i va = _mm256_loadu_si256((const __m256i*)a8);
|
|
129
|
+
__m256i vb = _mm256_loadu_si256((const __m256i*)b8);
|
|
130
|
+
__m256i vxor = _mm256_xor_si256(va, vb);
|
|
131
|
+
__m256i vpcnt = _mm256_popcnt_epi64(vxor);
|
|
132
|
+
__m128i lo = _mm256_castsi256_si128(vpcnt);
|
|
133
|
+
__m128i hi = _mm256_extracti128_si256(vpcnt, 1);
|
|
134
|
+
__m128i sum = _mm_add_epi64(lo, hi);
|
|
135
|
+
return static_cast<int>(
|
|
136
|
+
_mm_extract_epi64(sum, 0) + _mm_extract_epi64(sum, 1));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
inline static constexpr int get_code_size() {
|
|
140
|
+
return 32;
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
template <>
|
|
145
|
+
struct HammingComputer64_tpl<SIMDLevel::AVX512_VPOPCNT> {
|
|
146
|
+
const uint8_t* a8;
|
|
147
|
+
|
|
148
|
+
HammingComputer64_tpl() {}
|
|
149
|
+
|
|
150
|
+
HammingComputer64_tpl(const uint8_t* a8_in, int code_size) {
|
|
151
|
+
set(a8_in, code_size);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
void set(const uint8_t* a8_in, FAISS_MAYBE_UNUSED int code_size) {
|
|
155
|
+
assert(code_size == 64);
|
|
156
|
+
a8 = a8_in;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
inline int hamming(const uint8_t* b8) const {
|
|
160
|
+
__m512i vxor = _mm512_xor_si512(
|
|
161
|
+
_mm512_loadu_si512(a8), _mm512_loadu_si512(b8));
|
|
162
|
+
__m512i vpcnt = _mm512_popcnt_epi64(vxor);
|
|
163
|
+
return _mm512_reduce_add_epi32(vpcnt);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
inline static constexpr int get_code_size() {
|
|
167
|
+
return 64;
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
template <>
|
|
172
|
+
struct HammingComputerDefault_tpl<SIMDLevel::AVX512_VPOPCNT> {
|
|
173
|
+
const uint8_t* a8;
|
|
174
|
+
int quotient8;
|
|
175
|
+
int remainder8;
|
|
176
|
+
|
|
177
|
+
HammingComputerDefault_tpl() {}
|
|
178
|
+
|
|
179
|
+
HammingComputerDefault_tpl(const uint8_t* a8_in, int code_size) {
|
|
180
|
+
set(a8_in, code_size);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
void set(const uint8_t* a8_2, int code_size) {
|
|
184
|
+
this->a8 = a8_2;
|
|
185
|
+
quotient8 = code_size / 8;
|
|
186
|
+
remainder8 = code_size % 8;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/// One vector accumulator, reduced once. The partial last block is a
|
|
190
|
+
/// masked load, so no byte past the code is read.
|
|
191
|
+
int hamming(const uint8_t* b8) const {
|
|
192
|
+
const int code_size = quotient8 * 8 + remainder8;
|
|
193
|
+
__m512i accu = _mm512_setzero_si512();
|
|
194
|
+
int i = 0;
|
|
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));
|
|
199
|
+
}
|
|
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));
|
|
206
|
+
}
|
|
207
|
+
return static_cast<int>(_mm512_reduce_add_epi64(accu));
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
inline int get_code_size() const {
|
|
211
|
+
return quotient8 * 8 + remainder8;
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
} // namespace faiss
|
|
216
|
+
|
|
217
|
+
#endif
|
|
@@ -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
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
|
|
37
37
|
#include <algorithm>
|
|
38
38
|
#include <cstdio>
|
|
39
|
+
#include <cstring>
|
|
39
40
|
#include <limits>
|
|
40
41
|
#include <memory>
|
|
41
42
|
#include <vector>
|
|
@@ -101,7 +102,8 @@ void hammings_knn_hc_impl(
|
|
|
101
102
|
CMax<hamdis_t, int64_t>, \
|
|
102
103
|
NB, \
|
|
103
104
|
BD, \
|
|
104
|
-
HammingComputer
|
|
105
|
+
HammingComputer, \
|
|
106
|
+
THE_SIMD_LEVEL>:: \
|
|
105
107
|
addn(j1 - j0, hc, bs2_, k, bh_val_, bh_ids_, sel); \
|
|
106
108
|
break;
|
|
107
109
|
|
|
@@ -148,6 +150,7 @@ void hammings_knn_mc_impl(
|
|
|
148
150
|
std::unique_ptr<int64_t[]> all_ids_per_dis(new int64_t[na * nBuckets * k]);
|
|
149
151
|
|
|
150
152
|
std::vector<HCounterState<HammingComputer>> cs;
|
|
153
|
+
cs.reserve(na);
|
|
151
154
|
for (size_t i = 0; i < na; ++i) {
|
|
152
155
|
cs.push_back(
|
|
153
156
|
HCounterState<HammingComputer>(
|
|
@@ -298,6 +301,132 @@ void generalized_hammings_knn_hc_impl(
|
|
|
298
301
|
}
|
|
299
302
|
}
|
|
300
303
|
|
|
304
|
+
/* Both number of words and remainder are constants, so the compiler flattens
|
|
305
|
+
* the per-chunk loop. The query is copied into qw/qt once, not re-read for
|
|
306
|
+
* every candidate. */
|
|
307
|
+
template <int NW, int REM>
|
|
308
|
+
void hammings_ragged_fixed(
|
|
309
|
+
const uint8_t* __restrict a,
|
|
310
|
+
const uint8_t* __restrict b,
|
|
311
|
+
size_t na,
|
|
312
|
+
size_t nb,
|
|
313
|
+
size_t ncodes,
|
|
314
|
+
hamdis_t* __restrict dis) {
|
|
315
|
+
for (size_t i = 0; i < na; i++) {
|
|
316
|
+
const uint8_t* __restrict ai = a + i * ncodes;
|
|
317
|
+
hamdis_t* __restrict dis_ = dis + i * nb;
|
|
318
|
+
// Read the query once here, not once per candidate.
|
|
319
|
+
uint64_t qw[NW == 0 ? 1 : NW];
|
|
320
|
+
for (int k = 0; k < NW; k++) {
|
|
321
|
+
memcpy(&qw[k], ai + k * 8, 8);
|
|
322
|
+
}
|
|
323
|
+
uint64_t qt = 0;
|
|
324
|
+
if constexpr (REM > 0) {
|
|
325
|
+
memcpy(&qt, ai + NW * 8, REM);
|
|
326
|
+
}
|
|
327
|
+
for (size_t j = 0; j < nb; j++) {
|
|
328
|
+
const uint8_t* __restrict bj = b + j * ncodes;
|
|
329
|
+
hamdis_t h = 0;
|
|
330
|
+
uint64_t y;
|
|
331
|
+
for (int k = 0; k < NW; k++) {
|
|
332
|
+
memcpy(&y, bj + k * 8, 8);
|
|
333
|
+
h += popcount64(qw[k] ^ y);
|
|
334
|
+
}
|
|
335
|
+
if constexpr (REM > 0) {
|
|
336
|
+
y = 0;
|
|
337
|
+
memcpy(&y, bj + NW * 8, REM);
|
|
338
|
+
h += popcount64(qt ^ y);
|
|
339
|
+
}
|
|
340
|
+
dis_[j] = h;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/* Same loop with the word count read at run time, for codes long enough that
|
|
346
|
+
* a constant count gives no performance improvement. */
|
|
347
|
+
template <int REM>
|
|
348
|
+
void hammings_ragged_var(
|
|
349
|
+
const uint8_t* __restrict a,
|
|
350
|
+
const uint8_t* __restrict b,
|
|
351
|
+
size_t na,
|
|
352
|
+
size_t nb,
|
|
353
|
+
size_t ncodes,
|
|
354
|
+
hamdis_t* __restrict dis) {
|
|
355
|
+
const size_t nwords = ncodes / 8;
|
|
356
|
+
for (size_t i = 0; i < na; i++) {
|
|
357
|
+
const uint8_t* __restrict ai = a + i * ncodes;
|
|
358
|
+
hamdis_t* __restrict dis_ = dis + i * nb;
|
|
359
|
+
for (size_t j = 0; j < nb; j++) {
|
|
360
|
+
const uint8_t* __restrict bj = b + j * ncodes;
|
|
361
|
+
hamdis_t h = 0;
|
|
362
|
+
uint64_t x, y;
|
|
363
|
+
for (size_t k = 0; k < nwords; k++) {
|
|
364
|
+
memcpy(&x, ai + k * 8, 8);
|
|
365
|
+
memcpy(&y, bj + k * 8, 8);
|
|
366
|
+
h += popcount64(x ^ y);
|
|
367
|
+
}
|
|
368
|
+
if constexpr (REM > 0) {
|
|
369
|
+
x = 0;
|
|
370
|
+
y = 0;
|
|
371
|
+
memcpy(&x, ai + nwords * 8, REM);
|
|
372
|
+
memcpy(&y, bj + nwords * 8, REM);
|
|
373
|
+
h += popcount64(x ^ y);
|
|
374
|
+
}
|
|
375
|
+
dis_[j] = h;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/* Makes the word count a constant for short codes when calling
|
|
381
|
+
* hammings_ragged_fixed, worth roughly 2x perf improvement. Longer codes
|
|
382
|
+
* gain nothing from it, so they share hammings_ragged_var. */
|
|
383
|
+
template <int REM>
|
|
384
|
+
void hammings_ragged_by_nwords(
|
|
385
|
+
const uint8_t* __restrict a,
|
|
386
|
+
const uint8_t* __restrict b,
|
|
387
|
+
size_t na,
|
|
388
|
+
size_t nb,
|
|
389
|
+
size_t ncodes,
|
|
390
|
+
hamdis_t* __restrict dis) {
|
|
391
|
+
switch (ncodes / 8) {
|
|
392
|
+
case 0:
|
|
393
|
+
return hammings_ragged_fixed<0, REM>(a, b, na, nb, ncodes, dis);
|
|
394
|
+
case 1:
|
|
395
|
+
return hammings_ragged_fixed<1, REM>(a, b, na, nb, ncodes, dis);
|
|
396
|
+
case 2:
|
|
397
|
+
return hammings_ragged_fixed<2, REM>(a, b, na, nb, ncodes, dis);
|
|
398
|
+
case 3:
|
|
399
|
+
return hammings_ragged_fixed<3, REM>(a, b, na, nb, ncodes, dis);
|
|
400
|
+
default:
|
|
401
|
+
return hammings_ragged_var<REM>(a, b, na, nb, ncodes, dis);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
void hammings_ragged_dispatch(
|
|
406
|
+
const uint8_t* __restrict a,
|
|
407
|
+
const uint8_t* __restrict b,
|
|
408
|
+
size_t na,
|
|
409
|
+
size_t nb,
|
|
410
|
+
size_t ncodes,
|
|
411
|
+
hamdis_t* __restrict dis) {
|
|
412
|
+
switch (ncodes % 8) {
|
|
413
|
+
case 1:
|
|
414
|
+
return hammings_ragged_by_nwords<1>(a, b, na, nb, ncodes, dis);
|
|
415
|
+
case 2:
|
|
416
|
+
return hammings_ragged_by_nwords<2>(a, b, na, nb, ncodes, dis);
|
|
417
|
+
case 3:
|
|
418
|
+
return hammings_ragged_by_nwords<3>(a, b, na, nb, ncodes, dis);
|
|
419
|
+
case 4:
|
|
420
|
+
return hammings_ragged_by_nwords<4>(a, b, na, nb, ncodes, dis);
|
|
421
|
+
case 5:
|
|
422
|
+
return hammings_ragged_by_nwords<5>(a, b, na, nb, ncodes, dis);
|
|
423
|
+
case 6:
|
|
424
|
+
return hammings_ragged_by_nwords<6>(a, b, na, nb, ncodes, dis);
|
|
425
|
+
default:
|
|
426
|
+
return hammings_ragged_by_nwords<7>(a, b, na, nb, ncodes, dis);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
301
430
|
} // anonymous namespace
|
|
302
431
|
|
|
303
432
|
/******************************************************************
|
|
@@ -356,6 +485,19 @@ void hamming_range_search_fixSL<THE_SIMD_LEVEL>(
|
|
|
356
485
|
});
|
|
357
486
|
}
|
|
358
487
|
|
|
488
|
+
/* Its own entry point, so the word-multiple kernels keep the code the
|
|
489
|
+
* compiler already generates for them. */
|
|
490
|
+
template <>
|
|
491
|
+
void hammings_ragged_fixSL<THE_SIMD_LEVEL>(
|
|
492
|
+
const uint8_t* a,
|
|
493
|
+
const uint8_t* b,
|
|
494
|
+
size_t na,
|
|
495
|
+
size_t nb,
|
|
496
|
+
size_t ncodes,
|
|
497
|
+
hamdis_t* dis) {
|
|
498
|
+
hammings_ragged_dispatch(a, b, na, nb, ncodes, dis);
|
|
499
|
+
}
|
|
500
|
+
|
|
359
501
|
template <>
|
|
360
502
|
void hammings_fixSL<THE_SIMD_LEVEL>(
|
|
361
503
|
const uint8_t* a,
|
|
@@ -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
|
|
@@ -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
|
|