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
|
@@ -32,30 +32,39 @@ constexpr int AVAILABLE_SIMD_LEVELS_NONE = (1 << int(SIMDLevel::NONE));
|
|
|
32
32
|
constexpr int AVAILABLE_SIMD_LEVELS_AVX2_NEON = AVAILABLE_SIMD_LEVELS_NONE |
|
|
33
33
|
(1 << int(SIMDLevel::AVX2)) | (1 << int(SIMDLevel::ARM_NEON));
|
|
34
34
|
|
|
35
|
-
//
|
|
36
|
-
constexpr int
|
|
35
|
+
// BASE: AVX2_NEON + AVX512 + RISCV_RVV
|
|
36
|
+
constexpr int AVAILABLE_SIMD_LEVELS_BASE = AVAILABLE_SIMD_LEVELS_AVX2_NEON |
|
|
37
37
|
(1 << int(SIMDLevel::AVX512)) | (1 << int(SIMDLevel::RISCV_RVV));
|
|
38
38
|
|
|
39
|
-
//
|
|
40
|
-
//
|
|
41
|
-
//
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
// BASE_NO_AVX512: BASE minus AVX512, for functions implemented at NONE,
|
|
40
|
+
// AVX2, ARM_NEON and RISCV_RVV but with no AVX512 specialization. AVX512
|
|
41
|
+
// machines fall through to AVX2, while RISC-V dispatches directly to the
|
|
42
|
+
// native vector-length-agnostic RVV kernels.
|
|
43
|
+
constexpr int AVAILABLE_SIMD_LEVELS_BASE_NO_AVX512 =
|
|
44
|
+
AVAILABLE_SIMD_LEVELS_BASE & ~(1 << int(SIMDLevel::AVX512));
|
|
44
45
|
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
// BASE_WITH_VPOPCNT: BASE + AVX512_VPOPCNT, for kernels that need only
|
|
47
|
+
// VPOPCNTDQ on top of baseline AVX-512 (Ice Lake, Zen 4, Zen 5).
|
|
48
|
+
constexpr int AVAILABLE_SIMD_LEVELS_BASE_WITH_VPOPCNT =
|
|
49
|
+
AVAILABLE_SIMD_LEVELS_BASE | (1 << int(SIMDLevel::AVX512_VPOPCNT));
|
|
48
50
|
|
|
49
|
-
//
|
|
50
|
-
//
|
|
51
|
-
constexpr int
|
|
52
|
-
|
|
51
|
+
// BASE_WITH_SPR: BASE + AVX512_SPR, for kernels that need the whole SPR
|
|
52
|
+
// feature set rather than VPOPCNTDQ alone.
|
|
53
|
+
constexpr int AVAILABLE_SIMD_LEVELS_BASE_WITH_SPR =
|
|
54
|
+
AVAILABLE_SIMD_LEVELS_BASE | (1 << int(SIMDLevel::AVX512_SPR));
|
|
55
|
+
|
|
56
|
+
// BASE_WITH_SVE: BASE + ARM_SVE, for functions with dedicated SVE
|
|
57
|
+
// implementations.
|
|
58
|
+
constexpr int AVAILABLE_SIMD_LEVELS_BASE_WITH_SVE =
|
|
59
|
+
AVAILABLE_SIMD_LEVELS_BASE | (1 << int(SIMDLevel::ARM_SVE));
|
|
53
60
|
|
|
54
61
|
constexpr int AVAILABLE_SIMD_LEVELS_ALL = -1;
|
|
55
62
|
|
|
56
63
|
constexpr SIMDLevel get_simd_fallback(SIMDLevel level) {
|
|
57
64
|
switch (level) {
|
|
58
65
|
case SIMDLevel::AVX512_SPR:
|
|
66
|
+
return SIMDLevel::AVX512_VPOPCNT;
|
|
67
|
+
case SIMDLevel::AVX512_VPOPCNT:
|
|
59
68
|
return SIMDLevel::AVX512;
|
|
60
69
|
case SIMDLevel::AVX512:
|
|
61
70
|
return SIMDLevel::AVX2;
|
|
@@ -124,6 +133,15 @@ inline auto with_selected_simd_levels(LambdaType&& action) {
|
|
|
124
133
|
[[fallthrough]];
|
|
125
134
|
#endif
|
|
126
135
|
|
|
136
|
+
#ifdef COMPILE_SIMD_AVX512_VPOPCNT
|
|
137
|
+
case SIMDLevel::AVX512_VPOPCNT:
|
|
138
|
+
if constexpr (
|
|
139
|
+
available_levels & (1 << int(SIMDLevel::AVX512_VPOPCNT))) {
|
|
140
|
+
return action.template operator()<SIMDLevel::AVX512_VPOPCNT>();
|
|
141
|
+
}
|
|
142
|
+
[[fallthrough]];
|
|
143
|
+
#endif
|
|
144
|
+
|
|
127
145
|
#ifdef COMPILE_SIMD_AVX512
|
|
128
146
|
case SIMDLevel::AVX512:
|
|
129
147
|
if constexpr (available_levels & (1 << int(SIMDLevel::AVX512))) {
|
|
@@ -171,7 +189,7 @@ inline auto with_selected_simd_levels(LambdaType&& action) {
|
|
|
171
189
|
// In static mode, SINGLE_SIMD_LEVEL is a constexpr resolved at compile
|
|
172
190
|
// time. We mirror the DD fallthrough behavior at compile time via
|
|
173
191
|
// dispatch_with_fallback, which recursively walks get_simd_fallback:
|
|
174
|
-
// x86: AVX512_SPR -> AVX512 -> AVX2 -> NONE
|
|
192
|
+
// x86: AVX512_SPR -> AVX512_VPOPCNT -> AVX512 -> AVX2 -> NONE
|
|
175
193
|
// ARM: ARM_SVE -> ARM_NEON -> NONE
|
|
176
194
|
// RISCV: RISCV_RVV -> NONE
|
|
177
195
|
// The first level in the chain that appears in available_levels is
|
|
@@ -224,7 +242,7 @@ inline auto with_simd_level_fallback(const LambdaType& action) {
|
|
|
224
242
|
*/
|
|
225
243
|
template <typename LambdaType>
|
|
226
244
|
inline auto with_simd_level(LambdaType&& action) {
|
|
227
|
-
return with_selected_simd_levels<
|
|
245
|
+
return with_selected_simd_levels<AVAILABLE_SIMD_LEVELS_BASE>(
|
|
228
246
|
std::forward<LambdaType>(action));
|
|
229
247
|
}
|
|
230
248
|
|
|
@@ -238,13 +256,20 @@ inline auto with_simd_level_256bit(LambdaType&& action) {
|
|
|
238
256
|
std::forward<LambdaType>(action));
|
|
239
257
|
}
|
|
240
258
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
259
|
+
// Plain with_simd_level() uses BASE, which omits the optional levels below.
|
|
260
|
+
// A call site must opt in, or its specialization is never instantiated.
|
|
261
|
+
|
|
262
|
+
/// BASE + ARM_SVE.
|
|
263
|
+
template <typename LambdaType>
|
|
264
|
+
inline auto with_simd_level_with_sve(LambdaType&& action) {
|
|
265
|
+
return with_selected_simd_levels<AVAILABLE_SIMD_LEVELS_BASE_WITH_SVE>(
|
|
266
|
+
std::forward<LambdaType>(action));
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/// BASE + AVX512_VPOPCNT.
|
|
245
270
|
template <typename LambdaType>
|
|
246
|
-
inline auto
|
|
247
|
-
return with_selected_simd_levels<
|
|
271
|
+
inline auto with_simd_level_with_vpopcnt(LambdaType&& action) {
|
|
272
|
+
return with_selected_simd_levels<AVAILABLE_SIMD_LEVELS_BASE_WITH_VPOPCNT>(
|
|
248
273
|
std::forward<LambdaType>(action));
|
|
249
274
|
}
|
|
250
275
|
|
|
@@ -901,6 +901,20 @@ inline float horizontal_add(const simd8float32_tpl<SIMDLevel::AVX2>& a) {
|
|
|
901
901
|
return _mm_cvtss_f32(v3);
|
|
902
902
|
}
|
|
903
903
|
|
|
904
|
+
/// (s[0] + s[2]) + (s[1] + s[3])
|
|
905
|
+
FAISS_ALWAYS_INLINE float reduce_4(__m128 s) {
|
|
906
|
+
const __m128 h = _mm_add_ps(s, _mm_movehl_ps(s, s));
|
|
907
|
+
return _mm_cvtss_f32(_mm_add_ss(h, _mm_movehdup_ps(h)));
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
/// reduce_4 of four vectors at once, with the same order for each, so a
|
|
911
|
+
/// batched distance is bit-identical to the single one.
|
|
912
|
+
FAISS_ALWAYS_INLINE __m128 reduce_4x4(__m128 a, __m128 b, __m128 c, __m128 d) {
|
|
913
|
+
const __m128 ab = _mm_add_ps(_mm_unpacklo_ps(a, b), _mm_unpackhi_ps(a, b));
|
|
914
|
+
const __m128 cd = _mm_add_ps(_mm_unpacklo_ps(c, d), _mm_unpackhi_ps(c, d));
|
|
915
|
+
return _mm_add_ps(_mm_movelh_ps(ab, cd), _mm_movehl_ps(cd, ab));
|
|
916
|
+
}
|
|
917
|
+
|
|
904
918
|
} // namespace
|
|
905
919
|
|
|
906
920
|
} // namespace faiss
|
|
@@ -16,23 +16,22 @@
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
#include <faiss/impl/simdlib/simdlib.h>
|
|
19
|
+
#include <faiss/utils/simd_levels.h>
|
|
19
20
|
|
|
20
|
-
// Platform specializations — guarded by
|
|
21
|
-
//
|
|
22
|
-
//
|
|
23
|
-
// specializations. In static mode: only the compiled-in level is available.
|
|
21
|
+
// Platform specializations — guarded by FAISS_SIMD_TU, so that only per-SIMD
|
|
22
|
+
// TUs (compiled with -mavx2 etc.) see them. In static mode: only the
|
|
23
|
+
// compiled-in level is available.
|
|
24
24
|
|
|
25
|
-
#if (
|
|
26
|
-
defined(__AVX512F__)
|
|
25
|
+
#if FAISS_SIMD_TU(AVX512) || FAISS_SIMD_TU(AVX512_SPR)
|
|
27
26
|
|
|
28
27
|
// AVX512 includes AVX2 (simdlib_avx512.h includes simdlib_avx2.h)
|
|
29
28
|
#include <faiss/impl/simdlib/simdlib_avx512.h>
|
|
30
29
|
|
|
31
|
-
#elif
|
|
30
|
+
#elif FAISS_SIMD_TU(AVX2)
|
|
32
31
|
|
|
33
32
|
#include <faiss/impl/simdlib/simdlib_avx2.h>
|
|
34
33
|
|
|
35
|
-
#elif
|
|
34
|
+
#elif FAISS_SIMD_TU(ARM_NEON)
|
|
36
35
|
|
|
37
36
|
#include <faiss/impl/simdlib/simdlib_neon.h>
|
|
38
37
|
|
|
@@ -0,0 +1,232 @@
|
|
|
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
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include <algorithm>
|
|
11
|
+
#include <cstring>
|
|
12
|
+
|
|
13
|
+
#include <faiss/impl/ScalarQuantizer.h>
|
|
14
|
+
#include <faiss/utils/hamming.h>
|
|
15
|
+
|
|
16
|
+
/** Helpers shared by IndexSQFastScan and IndexIVFSQFastScan.
|
|
17
|
+
*
|
|
18
|
+
* Both re-quantise a higher-precision scalar quantizer down to 4-bit nibbles
|
|
19
|
+
* for the SIMD scan and keep the original codes to rerank with, so the
|
|
20
|
+
* classification of quantizer types and the nibble packing have to agree
|
|
21
|
+
* between them.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
namespace faiss {
|
|
25
|
+
namespace sq_fastscan {
|
|
26
|
+
|
|
27
|
+
inline size_t roundup(size_t a, size_t b) {
|
|
28
|
+
return (a + b - 1) / b * b;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
inline bool is_native_4bit(ScalarQuantizer::QuantizerType qtype) {
|
|
32
|
+
return qtype == ScalarQuantizer::QT_4bit ||
|
|
33
|
+
qtype == ScalarQuantizer::QT_4bit_uniform;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
inline bool needs_rerank(ScalarQuantizer::QuantizerType qtype) {
|
|
37
|
+
return qtype == ScalarQuantizer::QT_6bit ||
|
|
38
|
+
qtype == ScalarQuantizer::QT_8bit ||
|
|
39
|
+
qtype == ScalarQuantizer::QT_8bit_uniform ||
|
|
40
|
+
qtype == ScalarQuantizer::QT_8bit_direct ||
|
|
41
|
+
qtype == ScalarQuantizer::QT_8bit_direct_signed;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
inline bool is_fallback(ScalarQuantizer::QuantizerType qtype) {
|
|
45
|
+
return !is_native_4bit(qtype) && !needs_rerank(qtype);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
inline bool is_uniform_range(ScalarQuantizer::QuantizerType qtype) {
|
|
49
|
+
return qtype == ScalarQuantizer::QT_8bit_uniform ||
|
|
50
|
+
qtype == ScalarQuantizer::QT_8bit_direct ||
|
|
51
|
+
qtype == ScalarQuantizer::QT_8bit_direct_signed;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
inline void get_uniform_range(
|
|
55
|
+
const ScalarQuantizer& sq,
|
|
56
|
+
float& vmin,
|
|
57
|
+
float& vdiff) {
|
|
58
|
+
if (sq.qtype == ScalarQuantizer::QT_8bit_direct) {
|
|
59
|
+
vmin = 0;
|
|
60
|
+
vdiff = 255;
|
|
61
|
+
} else if (sq.qtype == ScalarQuantizer::QT_8bit_direct_signed) {
|
|
62
|
+
vmin = -128;
|
|
63
|
+
vdiff = 255;
|
|
64
|
+
} else {
|
|
65
|
+
vmin = sq.trained[0];
|
|
66
|
+
vdiff = sq.trained[1];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/// Bits per dimension the quantizer stores.
|
|
71
|
+
inline int sq_bits(ScalarQuantizer::QuantizerType qtype) {
|
|
72
|
+
if (qtype == ScalarQuantizer::QT_6bit) {
|
|
73
|
+
return 6;
|
|
74
|
+
}
|
|
75
|
+
return is_native_4bit(qtype) ? 4 : 8;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/// Bits left over once the scan has taken its 4. Zero for a native 4-bit
|
|
79
|
+
/// code, which needs no rerank and therefore stores nothing extra.
|
|
80
|
+
inline int sq_rerank_bits(ScalarQuantizer::QuantizerType qtype) {
|
|
81
|
+
return sq_bits(qtype) - 4;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/// Bytes per vector needed to hold the leftover bits of every dimension.
|
|
85
|
+
inline size_t sq_rerank_size(int d, ScalarQuantizer::QuantizerType qtype) {
|
|
86
|
+
const int bits = sq_rerank_bits(qtype);
|
|
87
|
+
return bits > 0 ? (size_t(d) * bits + 7) / 8 : 0;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/// The code for one value at the quantizer's own width.
|
|
91
|
+
inline int sq_code_of(float x, float vmin, float vdiff, int bits) {
|
|
92
|
+
const int maxv = (1 << bits) - 1;
|
|
93
|
+
const float f = (vdiff > 0) ? (x - vmin) / vdiff : 0.0f;
|
|
94
|
+
return std::min(maxv, std::max(0, int(f * float(maxv))));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/// Per-dimension range of the trained quantizer, resolved once for a batch.
|
|
98
|
+
struct SQRanges {
|
|
99
|
+
SQRanges(const ScalarQuantizer& sq, int d)
|
|
100
|
+
: uniform(is_uniform_range(sq.qtype) ||
|
|
101
|
+
sq.qtype == ScalarQuantizer::QT_4bit_uniform) {
|
|
102
|
+
if (uniform) {
|
|
103
|
+
get_uniform_range(sq, vmin_s, vdiff_s);
|
|
104
|
+
} else {
|
|
105
|
+
vmin_arr = sq.trained.data();
|
|
106
|
+
vdiff_arr = sq.trained.data() + d;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
float vmin(int m) const {
|
|
111
|
+
return uniform ? vmin_s : vmin_arr[m];
|
|
112
|
+
}
|
|
113
|
+
float vdiff(int m) const {
|
|
114
|
+
return uniform ? vdiff_s : vdiff_arr[m];
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const bool uniform;
|
|
118
|
+
const float* vmin_arr = nullptr;
|
|
119
|
+
const float* vdiff_arr = nullptr;
|
|
120
|
+
float vmin_s = 0, vdiff_s = 0;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
/** Split each code into the top 4 bits the SIMD kernel scans and the rest,
|
|
124
|
+
* which rerank keeps. `hi` is packed two dimensions per byte as
|
|
125
|
+
* pq4_pack_codes expects. `lo` is bit-packed at `bits - 4` per dimension.
|
|
126
|
+
* Total width is the quantizer's own, not that width plus 4.
|
|
127
|
+
*/
|
|
128
|
+
inline void float_to_split_codes(
|
|
129
|
+
const float* x,
|
|
130
|
+
uint8_t* hi,
|
|
131
|
+
uint8_t* lo,
|
|
132
|
+
idx_t n,
|
|
133
|
+
int d,
|
|
134
|
+
size_t M2,
|
|
135
|
+
const ScalarQuantizer& sq) {
|
|
136
|
+
const int bits = sq_bits(sq.qtype);
|
|
137
|
+
const int lo_bits = bits - 4;
|
|
138
|
+
const size_t hi_stride = M2 / 2;
|
|
139
|
+
const size_t lo_stride = sq_rerank_size(d, sq.qtype);
|
|
140
|
+
const SQRanges ranges(sq, d);
|
|
141
|
+
for (idx_t i = 0; i < n; i++) {
|
|
142
|
+
const float* xi = x + i * d;
|
|
143
|
+
uint8_t* hdst = hi + i * hi_stride;
|
|
144
|
+
memset(hdst, 0, hi_stride);
|
|
145
|
+
uint8_t* ldst = lo + i * lo_stride;
|
|
146
|
+
memset(ldst, 0, lo_stride);
|
|
147
|
+
BitstringWriter bsw(ldst, lo_stride);
|
|
148
|
+
for (int m = 0; m < d; m++) {
|
|
149
|
+
const int code =
|
|
150
|
+
sq_code_of(xi[m], ranges.vmin(m), ranges.vdiff(m), bits);
|
|
151
|
+
const int h = code >> lo_bits;
|
|
152
|
+
hdst[m / 2] |= (m & 1) ? uint8_t(h << 4) : uint8_t(h);
|
|
153
|
+
bsw.write(code & ((1 << lo_bits) - 1), lo_bits);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/// Rebuild the code values of one vector from its two halves.
|
|
159
|
+
inline void split_to_codes(
|
|
160
|
+
const uint8_t* hi,
|
|
161
|
+
const uint8_t* lo,
|
|
162
|
+
int d,
|
|
163
|
+
ScalarQuantizer::QuantizerType qtype,
|
|
164
|
+
int* codes_out) {
|
|
165
|
+
const int lo_bits = sq_rerank_bits(qtype);
|
|
166
|
+
BitstringReader bsr(lo, sq_rerank_size(d, qtype));
|
|
167
|
+
for (int m = 0; m < d; m++) {
|
|
168
|
+
const int h = (m & 1) ? (hi[m / 2] >> 4) : (hi[m / 2] & 0xF);
|
|
169
|
+
codes_out[m] = (h << lo_bits) | int(bsr.read(lo_bits));
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
inline void float_to_4bit_nibbles(
|
|
174
|
+
const float* x,
|
|
175
|
+
uint8_t* nibbles,
|
|
176
|
+
idx_t n,
|
|
177
|
+
int d,
|
|
178
|
+
int M2,
|
|
179
|
+
const ScalarQuantizer& sq) {
|
|
180
|
+
const bool is_uniform = is_uniform_range(sq.qtype) ||
|
|
181
|
+
sq.qtype == ScalarQuantizer::QT_4bit_uniform;
|
|
182
|
+
const float* vmin_arr = nullptr;
|
|
183
|
+
const float* vdiff_arr = nullptr;
|
|
184
|
+
float vmin_s = 0, inv_vdiff_s = 0;
|
|
185
|
+
|
|
186
|
+
if (is_uniform) {
|
|
187
|
+
float vdiff;
|
|
188
|
+
get_uniform_range(sq, vmin_s, vdiff);
|
|
189
|
+
inv_vdiff_s = (vdiff > 0) ? (1.0f / vdiff) : 0;
|
|
190
|
+
} else {
|
|
191
|
+
vmin_arr = sq.trained.data();
|
|
192
|
+
vdiff_arr = sq.trained.data() + d;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const int half = M2 / 2;
|
|
196
|
+
for (idx_t i = 0; i < n; i++) {
|
|
197
|
+
const float* xi = x + i * d;
|
|
198
|
+
uint8_t* dst = nibbles + i * half;
|
|
199
|
+
memset(dst, 0, half);
|
|
200
|
+
for (int m = 0; m + 1 < d; m += 2) {
|
|
201
|
+
float f0, f1;
|
|
202
|
+
if (is_uniform) {
|
|
203
|
+
f0 = (xi[m] - vmin_s) * inv_vdiff_s;
|
|
204
|
+
f1 = (xi[m + 1] - vmin_s) * inv_vdiff_s;
|
|
205
|
+
} else {
|
|
206
|
+
f0 = (vdiff_arr[m] > 0) ? (xi[m] - vmin_arr[m]) / vdiff_arr[m]
|
|
207
|
+
: 0;
|
|
208
|
+
f1 = (vdiff_arr[m + 1] > 0)
|
|
209
|
+
? (xi[m + 1] - vmin_arr[m + 1]) / vdiff_arr[m + 1]
|
|
210
|
+
: 0;
|
|
211
|
+
}
|
|
212
|
+
uint8_t lo = (uint8_t)std::min(15, std::max(0, (int)(f0 * 15.0f)));
|
|
213
|
+
uint8_t hi = (uint8_t)std::min(15, std::max(0, (int)(f1 * 15.0f)));
|
|
214
|
+
dst[m / 2] = lo | (hi << 4);
|
|
215
|
+
}
|
|
216
|
+
if (d & 1) {
|
|
217
|
+
float f;
|
|
218
|
+
if (is_uniform) {
|
|
219
|
+
f = (xi[d - 1] - vmin_s) * inv_vdiff_s;
|
|
220
|
+
} else {
|
|
221
|
+
f = (vdiff_arr[d - 1] > 0)
|
|
222
|
+
? (xi[d - 1] - vmin_arr[d - 1]) / vdiff_arr[d - 1]
|
|
223
|
+
: 0;
|
|
224
|
+
}
|
|
225
|
+
dst[(d - 1) / 2] =
|
|
226
|
+
(uint8_t)std::min(15, std::max(0, (int)(f * 15.0f)));
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
} // namespace sq_fastscan
|
|
232
|
+
} // namespace faiss
|
|
@@ -35,17 +35,20 @@
|
|
|
35
35
|
#include <faiss/IndexIVFPQR.h>
|
|
36
36
|
#include <faiss/IndexIVFRaBitQ.h>
|
|
37
37
|
#include <faiss/IndexIVFRaBitQFastScan.h>
|
|
38
|
+
#include <faiss/IndexIVFSQFastScan.h>
|
|
38
39
|
#include <faiss/IndexIVFSpectralHash.h>
|
|
39
40
|
#include <faiss/IndexLSH.h>
|
|
40
41
|
#include <faiss/IndexLattice.h>
|
|
41
42
|
#include <faiss/IndexNSG.h>
|
|
42
43
|
#include <faiss/IndexPQ.h>
|
|
43
44
|
#include <faiss/IndexPQFastScan.h>
|
|
45
|
+
#include <faiss/IndexPiPNN.h>
|
|
44
46
|
#include <faiss/IndexPreTransform.h>
|
|
45
47
|
#include <faiss/IndexRaBitQ.h>
|
|
46
48
|
#include <faiss/IndexRaBitQFastScan.h>
|
|
47
49
|
#include <faiss/IndexRefine.h>
|
|
48
50
|
#include <faiss/IndexRowwiseMinMax.h>
|
|
51
|
+
#include <faiss/IndexSQFastScan.h>
|
|
49
52
|
#include <faiss/IndexScalarQuantizer.h>
|
|
50
53
|
#include <faiss/VectorTransform.h>
|
|
51
54
|
|
|
@@ -177,6 +180,11 @@ std::map<std::string, ScalarQuantizer::QuantizerType> sq_types = {
|
|
|
177
180
|
};
|
|
178
181
|
const std::string sq_pattern =
|
|
179
182
|
"(SQ0|SQ4|SQ8|SQ6|SQfp16|SQbf16|SQ8_direct_signed|SQ8_direct|SQtqmse1|SQtqmse2|SQtqmse3|SQtqmse4|SQtqmse8|SQtq2|SQtq3|SQtq4|SQtq5)";
|
|
183
|
+
const std::string sq_fs_pattern =
|
|
184
|
+
"(SQ4|SQ6|SQ8|SQ8_direct_signed|SQ8_direct)fs(_[0-9]+)?";
|
|
185
|
+
// All SQ types with "fs" suffix for IndexIVFSQFastScan, optional _bbs
|
|
186
|
+
const std::string ivf_sq_fs_pattern =
|
|
187
|
+
"(SQ0|SQ4|SQ8|SQ6|SQfp16|SQbf16|SQ8_direct_signed|SQ8_direct|SQtqmse1|SQtqmse2|SQtqmse3|SQtqmse4|SQtqmse8|SQtq2|SQtq3|SQtq4|SQtq5)fs(_[0-9]+)?";
|
|
180
188
|
|
|
181
189
|
std::map<std::string, AdditiveQuantizer::Search_type_t> aq_search_type = {
|
|
182
190
|
{"_Nfloat", AdditiveQuantizer::ST_norm_float},
|
|
@@ -310,6 +318,11 @@ Index* parse_coarse_quantizer(
|
|
|
310
318
|
int R = std::stoi(sm[2]);
|
|
311
319
|
return new IndexNSGFlat(d, R, mt);
|
|
312
320
|
}
|
|
321
|
+
if (match("IVF([0-9]+[kM]?)_PiPNN([0-9]*)")) {
|
|
322
|
+
nlist = parse_nlist(sm[1].str());
|
|
323
|
+
int R = mres_to_int(sm[2], 64);
|
|
324
|
+
return new IndexPiPNNFlat(d, R, mt);
|
|
325
|
+
}
|
|
313
326
|
#ifdef FAISS_ENABLE_SVS
|
|
314
327
|
if (match("IVF([0-9]+[kM]?)_SVSVamana([0-9]*)(_.+)?")) {
|
|
315
328
|
nlist = parse_nlist(sm[1].str());
|
|
@@ -385,10 +398,21 @@ IndexIVF* parse_IndexIVF(
|
|
|
385
398
|
}
|
|
386
399
|
if (match("FlatPanorama([0-9]+)?(_([0-9]+))?")) {
|
|
387
400
|
int nlevels = mres_to_int(sm[1], 8); // default to 8 levels
|
|
388
|
-
int bs = mres_to_int(sm[3],
|
|
401
|
+
int bs = mres_to_int(sm[3], Panorama::kDefaultBatchSize);
|
|
389
402
|
return new IndexIVFFlatPanorama(
|
|
390
403
|
get_q(), d, nlist, nlevels, mt, own_il, bs);
|
|
391
404
|
}
|
|
405
|
+
if (match(ivf_sq_fs_pattern)) {
|
|
406
|
+
int bbs = mres_to_int(sm[2], 32, 1);
|
|
407
|
+
return new IndexIVFSQFastScan(
|
|
408
|
+
get_q(),
|
|
409
|
+
d,
|
|
410
|
+
nlist,
|
|
411
|
+
sq_types[sm[1].str()],
|
|
412
|
+
mt,
|
|
413
|
+
bbs,
|
|
414
|
+
/*by_residual=*/true);
|
|
415
|
+
}
|
|
392
416
|
if (match(sq_pattern)) {
|
|
393
417
|
return new IndexIVFScalarQuantizer(
|
|
394
418
|
get_q(),
|
|
@@ -575,6 +599,13 @@ IndexHNSW* parse_IndexHNSW(
|
|
|
575
599
|
if (match(sq_pattern)) {
|
|
576
600
|
return new IndexHNSWSQ(d, sq_types[sm[1].str()], hnsw_M, mt);
|
|
577
601
|
}
|
|
602
|
+
// Keep the bare RaBitQ token consistent with Flat and IVF: it means 1 bit.
|
|
603
|
+
// Use an explicit width such as RaBitQ4 to enable staged refinement.
|
|
604
|
+
if (match("RaBitQ([1-9])?")) {
|
|
605
|
+
// the capture is the bare digit, so no substr offset here
|
|
606
|
+
int nb_bits = mres_to_int(sm[1], 1);
|
|
607
|
+
return new IndexHNSWRaBitQ(d, hnsw_M, nb_bits, mt);
|
|
608
|
+
}
|
|
578
609
|
if (match("([0-9]+)\\+PQ([0-9]+)?")) {
|
|
579
610
|
int ncent = mres_to_int(sm[1]);
|
|
580
611
|
int pq_m = mres_to_int(sm[2]);
|
|
@@ -630,6 +661,30 @@ IndexNSG* parse_IndexNSG(
|
|
|
630
661
|
return nullptr;
|
|
631
662
|
}
|
|
632
663
|
|
|
664
|
+
/***************************************************************
|
|
665
|
+
* Parse IndexPiPNN
|
|
666
|
+
*/
|
|
667
|
+
|
|
668
|
+
IndexPiPNN* parse_IndexPiPNN(
|
|
669
|
+
const std::string& code_string,
|
|
670
|
+
int d,
|
|
671
|
+
MetricType mt,
|
|
672
|
+
int pipnn_R) {
|
|
673
|
+
std::smatch sm;
|
|
674
|
+
auto match = [&sm, &code_string](const std::string& pattern) {
|
|
675
|
+
return re_match(code_string, pattern, sm);
|
|
676
|
+
};
|
|
677
|
+
|
|
678
|
+
if (match("Flat|")) {
|
|
679
|
+
return new IndexPiPNNFlat(d, pipnn_R, mt);
|
|
680
|
+
}
|
|
681
|
+
if (match(sq_pattern)) {
|
|
682
|
+
return new IndexPiPNNSQ(d, sq_types[sm[1].str()], pipnn_R, mt);
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
return nullptr;
|
|
686
|
+
}
|
|
687
|
+
|
|
633
688
|
#ifdef FAISS_ENABLE_SVS
|
|
634
689
|
/***************************************************************
|
|
635
690
|
* Parse IndexSVS
|
|
@@ -824,6 +879,12 @@ Index* parse_other_indexes(
|
|
|
824
879
|
return new IndexLattice(d, M, nbit, r2);
|
|
825
880
|
}
|
|
826
881
|
|
|
882
|
+
// IndexSQFastScan (must be checked before IndexScalarQuantizer)
|
|
883
|
+
if (match(sq_fs_pattern)) {
|
|
884
|
+
int bbs = mres_to_int(sm[2], 32, 1);
|
|
885
|
+
return new IndexSQFastScan(d, sq_types[sm[1].str()], metric, bbs);
|
|
886
|
+
}
|
|
887
|
+
|
|
827
888
|
// IndexScalarQuantizer
|
|
828
889
|
if (match(sq_pattern)) {
|
|
829
890
|
return new IndexScalarQuantizer(d, sq_types[description], metric);
|
|
@@ -1149,6 +1210,28 @@ std::unique_ptr<Index> index_factory_sub(
|
|
|
1149
1210
|
return std::unique_ptr<Index>(index);
|
|
1150
1211
|
}
|
|
1151
1212
|
|
|
1213
|
+
// PiPNN variants (separator "," or "_", as for HNSW and NSG)
|
|
1214
|
+
if (re_match(description, "PiPNN([0-9]*)([,_].*)?", sm)) {
|
|
1215
|
+
int pipnn_R = mres_to_int(sm[1], 64);
|
|
1216
|
+
// We also accept empty code string (synonym of Flat)
|
|
1217
|
+
std::string code_string =
|
|
1218
|
+
sm[2].length() > 0 ? sm[2].str().substr(1) : "";
|
|
1219
|
+
if (verbose) {
|
|
1220
|
+
printf("parsing PiPNN string %s code_string=%s pipnn_R=%d\n",
|
|
1221
|
+
description.c_str(),
|
|
1222
|
+
code_string.c_str(),
|
|
1223
|
+
pipnn_R);
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
IndexPiPNN* index = parse_IndexPiPNN(code_string, d, metric, pipnn_R);
|
|
1227
|
+
FAISS_THROW_IF_NOT_FMT(
|
|
1228
|
+
index,
|
|
1229
|
+
"could not parse PiPNN code description %s in %s",
|
|
1230
|
+
code_string.c_str(),
|
|
1231
|
+
description.c_str());
|
|
1232
|
+
return std::unique_ptr<Index>(index);
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1152
1235
|
// IndexRowwiseMinMax, fp32 version
|
|
1153
1236
|
if (description.compare(0, 7, "MinMax,") == 0) {
|
|
1154
1237
|
size_t comma = description.find(',');
|
|
@@ -127,7 +127,9 @@ size_t InvertedLists::copy_subset_to(
|
|
|
127
127
|
} else if (subset_type == SUBSET_TYPE_ID_MOD) {
|
|
128
128
|
for (size_t i = 0; i < n; i++) {
|
|
129
129
|
idx_t id = ids_in[i];
|
|
130
|
-
|
|
130
|
+
// C++ gives a negative remainder, so a plain `id % a1` never
|
|
131
|
+
// matches for a negative id. Fold it into [0, a1) instead.
|
|
132
|
+
if (((id % a1) + a1) % a1 == a2) {
|
|
131
133
|
oivf.add_entry(
|
|
132
134
|
list_no,
|
|
133
135
|
get_single_id(list_no, i),
|
|
@@ -440,8 +442,11 @@ void ArrayInvertedListsPanorama::resize(size_t list_no, size_t new_size) {
|
|
|
440
442
|
const uint8_t* ArrayInvertedListsPanorama::get_single_code(
|
|
441
443
|
size_t list_no,
|
|
442
444
|
size_t offset) const {
|
|
443
|
-
assert
|
|
444
|
-
|
|
445
|
+
// Throw rather than assert: Panorama::reconstruct takes an unsized
|
|
446
|
+
// pointer, so these are the only bounds available and they must hold
|
|
447
|
+
// in opt builds too.
|
|
448
|
+
FAISS_THROW_IF_NOT(list_no < nlist);
|
|
449
|
+
FAISS_THROW_IF_NOT(offset < ids[list_no].size());
|
|
445
450
|
|
|
446
451
|
uint8_t* recons_buffer = new uint8_t[code_size];
|
|
447
452
|
|
|
@@ -669,10 +674,10 @@ namespace {
|
|
|
669
674
|
int translate_list_no(const VStackInvertedLists* vil, idx_t list_no) {
|
|
670
675
|
FAISS_THROW_IF_NOT(
|
|
671
676
|
list_no >= 0 && static_cast<size_t>(list_no) < vil->nlist);
|
|
672
|
-
|
|
677
|
+
size_t i0 = 0, i1 = vil->ils.size();
|
|
673
678
|
const idx_t* cumsz = vil->cumsz.data();
|
|
674
679
|
while (i0 + 1 < i1) {
|
|
675
|
-
|
|
680
|
+
size_t imed = i0 + (i1 - i0) / 2;
|
|
676
681
|
if (list_no >= cumsz[imed]) {
|
|
677
682
|
i0 = imed;
|
|
678
683
|
} else {
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
#include <pthread.h>
|
|
13
13
|
|
|
14
|
+
#include <memory>
|
|
14
15
|
#include <unordered_set>
|
|
15
16
|
|
|
16
17
|
#include <sys/mman.h>
|
|
@@ -714,12 +715,17 @@ void OnDiskInvertedListsIOHook::write(const InvertedLists* ils, IOWriter* f)
|
|
|
714
715
|
|
|
715
716
|
InvertedLists* OnDiskInvertedListsIOHook::read(IOReader* f, int io_flags)
|
|
716
717
|
const {
|
|
717
|
-
|
|
718
|
+
auto od = std::make_unique<OnDiskInvertedLists>();
|
|
718
719
|
od->read_only = io_flags & IO_FLAG_READ_ONLY;
|
|
719
720
|
READ1(od->nlist);
|
|
720
721
|
READ1(od->code_size);
|
|
721
722
|
// this is a POD object
|
|
722
723
|
READVECTOR(od->lists);
|
|
724
|
+
FAISS_THROW_IF_NOT_FMT(
|
|
725
|
+
od->lists.size() == od->nlist,
|
|
726
|
+
"OnDisk inverted lists: read %zu lists for nlist %zu",
|
|
727
|
+
od->lists.size(),
|
|
728
|
+
od->nlist);
|
|
723
729
|
{
|
|
724
730
|
std::vector<OnDiskInvertedLists::Slot> v;
|
|
725
731
|
READVECTOR(v);
|
|
@@ -759,7 +765,7 @@ InvertedLists* OnDiskInvertedListsIOHook::read(IOReader* f, int io_flags)
|
|
|
759
765
|
if (!(io_flags & IO_FLAG_SKIP_IVF_DATA)) {
|
|
760
766
|
od->do_mmap();
|
|
761
767
|
}
|
|
762
|
-
return od;
|
|
768
|
+
return od.release();
|
|
763
769
|
}
|
|
764
770
|
|
|
765
771
|
/** read from a ArrayInvertedLists into this invertedlist type */
|
|
@@ -769,7 +775,7 @@ InvertedLists* OnDiskInvertedListsIOHook::read_ArrayInvertedLists(
|
|
|
769
775
|
size_t nlist,
|
|
770
776
|
size_t code_size,
|
|
771
777
|
const std::vector<size_t>& sizes) const {
|
|
772
|
-
auto ails =
|
|
778
|
+
auto ails = std::make_unique<OnDiskInvertedLists>();
|
|
773
779
|
ails->nlist = nlist;
|
|
774
780
|
ails->code_size = code_size;
|
|
775
781
|
ails->read_only = true;
|
|
@@ -819,7 +825,7 @@ InvertedLists* OnDiskInvertedListsIOHook::read_ArrayInvertedLists(
|
|
|
819
825
|
// resume normal reading of file
|
|
820
826
|
fseek(fdesc, o, SEEK_SET);
|
|
821
827
|
|
|
822
|
-
return ails;
|
|
828
|
+
return ails.release();
|
|
823
829
|
}
|
|
824
830
|
|
|
825
831
|
} // namespace faiss
|