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
|
@@ -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,9 +162,11 @@ 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
|
-
|
|
165
|
+
uint64_t yv;
|
|
166
|
+
std::memcpy(&yv, data + offset, sizeof(yv));
|
|
144
167
|
for (int j = 0; j < qb; j++) {
|
|
145
|
-
|
|
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
|
}
|
|
@@ -167,10 +191,12 @@ 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
197
|
for (int j = 0; j < qb; j++) {
|
|
173
|
-
|
|
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
|
}
|
|
@@ -194,9 +220,11 @@ 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
|
-
|
|
223
|
+
uint64_t yv;
|
|
224
|
+
std::memcpy(&yv, data + offset, sizeof(yv));
|
|
198
225
|
for (int j = 0; j < qb; j++) {
|
|
199
|
-
|
|
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
|
}
|
|
@@ -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++) {
|
|
@@ -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__
|
|
@@ -129,6 +129,22 @@ struct ElementOpIP {
|
|
|
129
129
|
}
|
|
130
130
|
};
|
|
131
131
|
|
|
132
|
+
struct ElementOpL2 {
|
|
133
|
+
static svfloat32_t op(svbool_t pg, svfloat32_t x, svfloat32_t y) {
|
|
134
|
+
const svfloat32_t diff = svsub_f32_x(pg, x, y);
|
|
135
|
+
return svmul_f32_x(pg, diff, diff);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
static svfloat32_t merge(
|
|
139
|
+
svbool_t pg,
|
|
140
|
+
svfloat32_t z,
|
|
141
|
+
svfloat32_t x,
|
|
142
|
+
svfloat32_t y) {
|
|
143
|
+
const svfloat32_t diff = svsub_f32_x(pg, x, y);
|
|
144
|
+
return svmla_f32_x(pg, z, diff, diff);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
|
|
132
148
|
template <typename ElementOp>
|
|
133
149
|
void fvec_op_ny_sve_d1(float* dis, const float* x, const float* y, size_t ny) {
|
|
134
150
|
const size_t lanes = svcntw();
|
|
@@ -513,13 +529,87 @@ void fvec_L2sqr_ny<SIMDLevel::ARM_SVE>(
|
|
|
513
529
|
const float* y,
|
|
514
530
|
size_t d,
|
|
515
531
|
size_t ny) {
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
532
|
+
const size_t lanes = static_cast<size_t>(svcntw());
|
|
533
|
+
|
|
534
|
+
switch (d) {
|
|
535
|
+
case 1:
|
|
536
|
+
fvec_op_ny_sve_d1<ElementOpL2>(dis, x, y, ny);
|
|
537
|
+
break;
|
|
538
|
+
|
|
539
|
+
case 2:
|
|
540
|
+
fvec_op_ny_sve_d2<ElementOpL2>(dis, x, y, ny);
|
|
541
|
+
break;
|
|
542
|
+
|
|
543
|
+
case 4:
|
|
544
|
+
fvec_op_ny_sve_d4<ElementOpL2>(dis, x, y, ny);
|
|
545
|
+
break;
|
|
546
|
+
|
|
547
|
+
case 8:
|
|
548
|
+
fvec_op_ny_sve_d8<ElementOpL2>(dis, x, y, ny);
|
|
549
|
+
break;
|
|
550
|
+
|
|
551
|
+
default:
|
|
552
|
+
if (d == lanes)
|
|
553
|
+
fvec_op_ny_sve_lanes1<ElementOpL2>(dis, x, y, ny);
|
|
554
|
+
else if (d == lanes * 2)
|
|
555
|
+
fvec_op_ny_sve_lanes2<ElementOpL2>(dis, x, y, ny);
|
|
556
|
+
else if (d == lanes * 3)
|
|
557
|
+
fvec_op_ny_sve_lanes3<ElementOpL2>(dis, x, y, ny);
|
|
558
|
+
else if (d == lanes * 4)
|
|
559
|
+
fvec_op_ny_sve_lanes4<ElementOpL2>(dis, x, y, ny);
|
|
560
|
+
else {
|
|
561
|
+
// Fallback: use autovectorized L2sqr
|
|
562
|
+
for (size_t i = 0; i < ny; i++) {
|
|
563
|
+
dis[i] = fvec_L2sqr<SIMDLevel::ARM_SVE>(x, y, d);
|
|
564
|
+
y += d;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
break;
|
|
520
568
|
}
|
|
521
569
|
}
|
|
522
570
|
|
|
571
|
+
namespace {
|
|
572
|
+
|
|
573
|
+
/// Low-dimensional L2sqr nearest (D in {2,4,8}). The data is row-major
|
|
574
|
+
/// (centroid c is y[c*D .. c*D+D]). Each SVE lane tracks one centroid across
|
|
575
|
+
/// batches, keeping the lane-local minimum and index in registers. The scratch
|
|
576
|
+
/// buffer is not written, matching the AVX2/AVX512 D2/D4/D8 implementations.
|
|
577
|
+
template <int D>
|
|
578
|
+
size_t fvec_L2sqr_ny_nearest_lowdim(
|
|
579
|
+
float* /*distances_tmp_buffer*/,
|
|
580
|
+
const float* x,
|
|
581
|
+
const float* y,
|
|
582
|
+
size_t ny) {
|
|
583
|
+
const size_t lanes = svcntw();
|
|
584
|
+
svfloat32_t global_mins = svdup_n_f32(HUGE_VALF);
|
|
585
|
+
svuint32_t global_ids = svdup_n_u32(0);
|
|
586
|
+
svuint32_t current_ids = svindex_u32(0, 1);
|
|
587
|
+
|
|
588
|
+
for (size_t c = 0; c < ny; c += lanes) {
|
|
589
|
+
const svbool_t pg = svwhilelt_b32_u64(c, ny);
|
|
590
|
+
svfloat32_t distances = svdup_n_f32(0.0f);
|
|
591
|
+
for (uint32_t j = 0; j < D; ++j) {
|
|
592
|
+
const svuint32_t offsets = svindex_u32(j, D);
|
|
593
|
+
const svfloat32_t yv =
|
|
594
|
+
svld1_gather_u32index_f32(pg, y + c * D, offsets);
|
|
595
|
+
const svfloat32_t diff = svsub_n_f32_x(pg, yv, x[j]);
|
|
596
|
+
distances = svmla_f32_m(pg, distances, diff, diff);
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
const svbool_t closer = svcmplt_f32(pg, distances, global_mins);
|
|
600
|
+
global_mins = svsel_f32(closer, distances, global_mins);
|
|
601
|
+
global_ids = svsel_u32(closer, current_ids, global_ids);
|
|
602
|
+
current_ids =
|
|
603
|
+
svadd_n_u32_x(pg, current_ids, static_cast<uint32_t>(lanes));
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
const svbool_t all = svptrue_b32();
|
|
607
|
+
const float global_min = svminv_f32(all, global_mins);
|
|
608
|
+
return svminv_u32(svcmpeq_n_f32(all, global_mins, global_min), global_ids);
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
} // namespace
|
|
612
|
+
|
|
523
613
|
template <>
|
|
524
614
|
size_t fvec_L2sqr_ny_nearest<SIMDLevel::ARM_SVE>(
|
|
525
615
|
float* distances_tmp_buffer,
|
|
@@ -527,14 +617,52 @@ size_t fvec_L2sqr_ny_nearest<SIMDLevel::ARM_SVE>(
|
|
|
527
617
|
const float* y,
|
|
528
618
|
size_t d,
|
|
529
619
|
size_t ny) {
|
|
530
|
-
|
|
620
|
+
switch (d) {
|
|
621
|
+
case 2:
|
|
622
|
+
return fvec_L2sqr_ny_nearest_lowdim<2>(
|
|
623
|
+
distances_tmp_buffer, x, y, ny);
|
|
624
|
+
case 4:
|
|
625
|
+
return fvec_L2sqr_ny_nearest_lowdim<4>(
|
|
626
|
+
distances_tmp_buffer, x, y, ny);
|
|
627
|
+
case 8:
|
|
628
|
+
return fvec_L2sqr_ny_nearest_lowdim<8>(
|
|
629
|
+
distances_tmp_buffer, x, y, ny);
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
const size_t lanes = static_cast<size_t>(svcntw());
|
|
531
633
|
|
|
532
634
|
size_t nearest_idx = 0;
|
|
533
635
|
float min_dis = HUGE_VALF;
|
|
534
636
|
|
|
535
|
-
for (size_t i = 0; i < ny; i
|
|
536
|
-
|
|
537
|
-
|
|
637
|
+
for (size_t i = 0; i < ny; ++i) {
|
|
638
|
+
const float* yi = y + i * d;
|
|
639
|
+
size_t j = 0;
|
|
640
|
+
|
|
641
|
+
svfloat32_t accv = svdup_n_f32(0.0f);
|
|
642
|
+
|
|
643
|
+
for (; j + lanes <= d; j += lanes) {
|
|
644
|
+
const svbool_t pg = svptrue_b32();
|
|
645
|
+
const svfloat32_t xv = svld1_f32(pg, x + j);
|
|
646
|
+
const svfloat32_t yv = svld1_f32(pg, yi + j);
|
|
647
|
+
const svfloat32_t diff = svsub_f32_x(pg, xv, yv);
|
|
648
|
+
accv = svmla_f32_x(pg, accv, diff, diff);
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
if (j < d) {
|
|
652
|
+
const svbool_t pg = svwhilelt_b32_u64(j, d);
|
|
653
|
+
const svfloat32_t xv = svld1_f32(pg, x + j);
|
|
654
|
+
const svfloat32_t yv = svld1_f32(pg, yi + j);
|
|
655
|
+
const svfloat32_t diff = svsub_f32_x(pg, xv, yv);
|
|
656
|
+
// Merging predication: lanes outside the tail keep the partial
|
|
657
|
+
// sums accumulated above, which the reduction below still adds in.
|
|
658
|
+
// `_x` would leave them unspecified.
|
|
659
|
+
accv = svmla_f32_m(pg, accv, diff, diff);
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
const float dist = svaddv_f32(svptrue_b32(), accv);
|
|
663
|
+
distances_tmp_buffer[i] = dist;
|
|
664
|
+
if (dist < min_dis) {
|
|
665
|
+
min_dis = dist;
|
|
538
666
|
nearest_idx = i;
|
|
539
667
|
}
|
|
540
668
|
}
|
|
@@ -542,7 +670,6 @@ size_t fvec_L2sqr_ny_nearest<SIMDLevel::ARM_SVE>(
|
|
|
542
670
|
return nearest_idx;
|
|
543
671
|
}
|
|
544
672
|
|
|
545
|
-
FAISS_PRAGMA_IMPRECISE_FUNCTION_BEGIN
|
|
546
673
|
template <>
|
|
547
674
|
void fvec_L2sqr_ny_transposed<SIMDLevel::ARM_SVE>(
|
|
548
675
|
float* dis,
|
|
@@ -552,22 +679,26 @@ void fvec_L2sqr_ny_transposed<SIMDLevel::ARM_SVE>(
|
|
|
552
679
|
size_t d,
|
|
553
680
|
size_t d_offset,
|
|
554
681
|
size_t ny) {
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
682
|
+
const size_t lanes = static_cast<size_t>(svcntw());
|
|
683
|
+
const float x_sq = fvec_norm_L2sqr(x, d);
|
|
684
|
+
|
|
685
|
+
for (size_t k = 0; k < ny; k += lanes) {
|
|
686
|
+
svbool_t pg = svwhilelt_b32_u64(k, ny);
|
|
687
|
+
svfloat32_t acc = svdup_n_f32(0.0f);
|
|
560
688
|
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
dp += x[j] * y[i + j * d_offset];
|
|
689
|
+
for (size_t j = 0; j < d; ++j) {
|
|
690
|
+
svfloat32_t ychunk = svld1_f32(pg, y + j * d_offset + k);
|
|
691
|
+
svfloat32_t xj = svdup_n_f32(x[j]);
|
|
692
|
+
acc = svmla_f32_x(pg, acc, xj, ychunk);
|
|
566
693
|
}
|
|
567
|
-
|
|
694
|
+
|
|
695
|
+
svfloat32_t ysq = svld1_f32(pg, y_sqlen + k);
|
|
696
|
+
svfloat32_t two_acc = svmul_f32_x(pg, acc, svdup_n_f32(2.0f));
|
|
697
|
+
svfloat32_t sum = svadd_f32_x(pg, svdup_n_f32(x_sq), ysq);
|
|
698
|
+
svfloat32_t res = svsub_f32_x(pg, sum, two_acc);
|
|
699
|
+
svst1_f32(pg, dis + k, res);
|
|
568
700
|
}
|
|
569
701
|
}
|
|
570
|
-
FAISS_PRAGMA_IMPRECISE_FUNCTION_END
|
|
571
702
|
|
|
572
703
|
template <>
|
|
573
704
|
size_t fvec_L2sqr_ny_nearest_y_transposed<SIMDLevel::ARM_SVE>(
|
|
@@ -578,25 +709,60 @@ size_t fvec_L2sqr_ny_nearest_y_transposed<SIMDLevel::ARM_SVE>(
|
|
|
578
709
|
size_t d,
|
|
579
710
|
size_t d_offset,
|
|
580
711
|
size_t ny) {
|
|
581
|
-
|
|
582
|
-
|
|
712
|
+
const size_t lanes = svcntw();
|
|
713
|
+
const float x_sq = fvec_norm_L2sqr(x, d);
|
|
583
714
|
|
|
584
|
-
size_t
|
|
585
|
-
|
|
715
|
+
size_t current_min_idx = 0;
|
|
716
|
+
svfloat32_t current_min_v = svdup_n_f32(HUGE_VALF);
|
|
586
717
|
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
718
|
+
// Max SVE vector length is 2048 bits → 64 fp32 lanes
|
|
719
|
+
float tmp_buf[64];
|
|
720
|
+
|
|
721
|
+
for (size_t k = 0; k < ny; k += lanes) {
|
|
722
|
+
svbool_t pg = svwhilelt_b32_u64(k, ny);
|
|
723
|
+
svfloat32_t acc = svdup_n_f32(0.0f);
|
|
724
|
+
|
|
725
|
+
for (size_t j = 0; j < d; ++j) {
|
|
726
|
+
svfloat32_t ychunk = svld1_f32(pg, y + j * d_offset + k);
|
|
727
|
+
svfloat32_t xj = svdup_n_f32(x[j]);
|
|
728
|
+
acc = svmla_f32_x(pg, acc, xj, ychunk);
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
svfloat32_t ysq = svld1_f32(pg, y_sqlen + k);
|
|
732
|
+
svfloat32_t two_acc = svmul_f32_x(pg, acc, svdup_n_f32(2.0f));
|
|
733
|
+
svfloat32_t sum = svadd_f32_x(pg, svdup_n_f32(x_sq), ysq);
|
|
734
|
+
svfloat32_t res = svsub_f32_x(pg, sum, two_acc);
|
|
735
|
+
|
|
736
|
+
svst1_f32(pg, distances_tmp_buffer + k, res);
|
|
737
|
+
|
|
738
|
+
svbool_t less_mask = svcmplt_f32(pg, res, current_min_v);
|
|
739
|
+
|
|
740
|
+
if (svptest_any(pg, less_mask)) {
|
|
741
|
+
float vec_min = svminv_f32(pg, res);
|
|
742
|
+
|
|
743
|
+
current_min_v =
|
|
744
|
+
svmin_f32_x(pg, current_min_v, svdup_n_f32(vec_min));
|
|
745
|
+
|
|
746
|
+
svst1_f32(pg, tmp_buf, res);
|
|
747
|
+
|
|
748
|
+
size_t cnt = (size_t)svcntw();
|
|
749
|
+
for (size_t lane = 0; lane < cnt && (k + lane) < ny; ++lane) {
|
|
750
|
+
if (tmp_buf[lane] == vec_min) {
|
|
751
|
+
current_min_idx = k + lane;
|
|
752
|
+
break;
|
|
753
|
+
}
|
|
754
|
+
}
|
|
591
755
|
}
|
|
592
756
|
}
|
|
593
757
|
|
|
594
|
-
return
|
|
758
|
+
return current_min_idx;
|
|
595
759
|
}
|
|
596
760
|
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
761
|
+
namespace {
|
|
762
|
+
|
|
763
|
+
template <class QueryTiles>
|
|
764
|
+
void exhaustive_L2sqr_blas_cmax_sve(
|
|
765
|
+
QueryTiles& queries,
|
|
600
766
|
const float* y,
|
|
601
767
|
size_t d,
|
|
602
768
|
size_t nx,
|
|
@@ -615,7 +781,7 @@ void exhaustive_L2sqr_blas_cmax<SIMDLevel::ARM_SVE>(
|
|
|
615
781
|
std::unique_ptr<float[]> x_norms(new float[nx]);
|
|
616
782
|
std::unique_ptr<float[]> del2;
|
|
617
783
|
|
|
618
|
-
|
|
784
|
+
queries.prepare_norms(nx, x_norms.get());
|
|
619
785
|
|
|
620
786
|
const size_t lanes = svcntw();
|
|
621
787
|
|
|
@@ -631,6 +797,8 @@ void exhaustive_L2sqr_blas_cmax<SIMDLevel::ARM_SVE>(
|
|
|
631
797
|
if (i1 > nx)
|
|
632
798
|
i1 = nx;
|
|
633
799
|
|
|
800
|
+
const float* xt = queries.tile(i0, i1, x_norms.get());
|
|
801
|
+
|
|
634
802
|
res.begin_multiple(i0, i1);
|
|
635
803
|
|
|
636
804
|
for (size_t j0 = 0; j0 < ny; j0 += bs_y) {
|
|
@@ -649,7 +817,7 @@ void exhaustive_L2sqr_blas_cmax<SIMDLevel::ARM_SVE>(
|
|
|
649
817
|
&one,
|
|
650
818
|
y + j0 * d,
|
|
651
819
|
&di,
|
|
652
|
-
|
|
820
|
+
xt,
|
|
653
821
|
&di,
|
|
654
822
|
&zero,
|
|
655
823
|
ip_block.get(),
|
|
@@ -774,4 +942,32 @@ void exhaustive_L2sqr_blas_cmax<SIMDLevel::ARM_SVE>(
|
|
|
774
942
|
}
|
|
775
943
|
}
|
|
776
944
|
|
|
945
|
+
} // namespace
|
|
946
|
+
|
|
947
|
+
template <>
|
|
948
|
+
void exhaustive_L2sqr_blas_cmax<SIMDLevel::ARM_SVE>(
|
|
949
|
+
const float* x,
|
|
950
|
+
const float* y,
|
|
951
|
+
size_t d,
|
|
952
|
+
size_t nx,
|
|
953
|
+
size_t ny,
|
|
954
|
+
Top1BlockResultHandler<CMax<float, int64_t>>& res,
|
|
955
|
+
const float* y_norms) {
|
|
956
|
+
Fp32QueryTiles queries{x, d};
|
|
957
|
+
exhaustive_L2sqr_blas_cmax_sve(queries, y, d, nx, ny, res, y_norms);
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
template <>
|
|
961
|
+
void exhaustive_L2sqr_blas_cmax_fp16<SIMDLevel::ARM_SVE>(
|
|
962
|
+
const uint16_t* x,
|
|
963
|
+
const float* y,
|
|
964
|
+
size_t d,
|
|
965
|
+
size_t nx,
|
|
966
|
+
size_t ny,
|
|
967
|
+
Top1BlockResultHandler<CMax<float, int64_t>>& res,
|
|
968
|
+
const float* y_norms) {
|
|
969
|
+
Fp16QueryTiles queries(x, d, nx);
|
|
970
|
+
exhaustive_L2sqr_blas_cmax_sve(queries, y, d, nx, ny, res, y_norms);
|
|
971
|
+
}
|
|
972
|
+
|
|
777
973
|
} // namespace faiss
|