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
|
@@ -455,6 +455,36 @@ void knn_L2sqr(
|
|
|
455
455
|
const float* y_norm2 = nullptr,
|
|
456
456
|
const IDSelector* sel = nullptr);
|
|
457
457
|
|
|
458
|
+
/** knn_inner_product for packed IEEE binary16 queries (x: nx * d uint16_t).
|
|
459
|
+
*
|
|
460
|
+
* The BLAS kernels widen each query tile once and reuse it for all database
|
|
461
|
+
* tiles, so there is no fp32 copy of the queries. Results are the same as
|
|
462
|
+
* knn_inner_product on the widened queries.
|
|
463
|
+
*/
|
|
464
|
+
void knn_inner_product_fp16(
|
|
465
|
+
const uint16_t* x,
|
|
466
|
+
const float* y,
|
|
467
|
+
size_t d,
|
|
468
|
+
size_t nx,
|
|
469
|
+
size_t ny,
|
|
470
|
+
size_t k,
|
|
471
|
+
float* distances,
|
|
472
|
+
int64_t* indexes,
|
|
473
|
+
const IDSelector* sel = nullptr);
|
|
474
|
+
|
|
475
|
+
/// knn_L2sqr for packed IEEE binary16 queries, see knn_inner_product_fp16
|
|
476
|
+
void knn_L2sqr_fp16(
|
|
477
|
+
const uint16_t* x,
|
|
478
|
+
const float* y,
|
|
479
|
+
size_t d,
|
|
480
|
+
size_t nx,
|
|
481
|
+
size_t ny,
|
|
482
|
+
size_t k,
|
|
483
|
+
float* distances,
|
|
484
|
+
int64_t* indexes,
|
|
485
|
+
const float* y_norm2 = nullptr,
|
|
486
|
+
const IDSelector* sel = nullptr);
|
|
487
|
+
|
|
458
488
|
/** Find the max inner product neighbors for nx queries in a set of ny vectors
|
|
459
489
|
* indexed by ids. May be useful for re-ranking a pre-selected vector list
|
|
460
490
|
*
|
|
@@ -600,4 +630,8 @@ int fvec_madd_and_argmin(
|
|
|
600
630
|
const float* b,
|
|
601
631
|
float* c);
|
|
602
632
|
|
|
633
|
+
/// sum of x[j] for every j < d whose bit is set in bits (LSB-first per byte)
|
|
634
|
+
template <SIMDLevel>
|
|
635
|
+
float fvec_masked_sum(const float* x, const uint8_t* bits, size_t d);
|
|
636
|
+
|
|
603
637
|
} // namespace faiss
|
|
@@ -29,22 +29,22 @@
|
|
|
29
29
|
namespace faiss {
|
|
30
30
|
|
|
31
31
|
inline float fvec_L1_dispatch(const float* x, const float* y, size_t d) {
|
|
32
|
-
return with_selected_simd_levels<
|
|
32
|
+
return with_selected_simd_levels<AVAILABLE_SIMD_LEVELS_BASE_WITH_SVE>(
|
|
33
33
|
[&]<SIMDLevel SL>() { return fvec_L1<SL>(x, y, d); });
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
inline float fvec_Linf_dispatch(const float* x, const float* y, size_t d) {
|
|
37
|
-
return with_selected_simd_levels<
|
|
37
|
+
return with_selected_simd_levels<AVAILABLE_SIMD_LEVELS_BASE_WITH_SVE>(
|
|
38
38
|
[&]<SIMDLevel SL>() { return fvec_Linf<SL>(x, y, d); });
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
inline float fvec_norm_L2sqr_dispatch(const float* x, size_t d) {
|
|
42
|
-
return with_selected_simd_levels<
|
|
42
|
+
return with_selected_simd_levels<AVAILABLE_SIMD_LEVELS_BASE_WITH_SVE>(
|
|
43
43
|
[&]<SIMDLevel SL>() { return fvec_norm_L2sqr<SL>(x, d); });
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
inline float fvec_L2sqr_dispatch(const float* x, const float* y, size_t d) {
|
|
47
|
-
return with_selected_simd_levels<
|
|
47
|
+
return with_selected_simd_levels<AVAILABLE_SIMD_LEVELS_BASE_WITH_SVE>(
|
|
48
48
|
[&]<SIMDLevel SL>() { return fvec_L2sqr<SL>(x, y, d); });
|
|
49
49
|
}
|
|
50
50
|
|
|
@@ -52,7 +52,7 @@ inline float fvec_inner_product_dispatch(
|
|
|
52
52
|
const float* x,
|
|
53
53
|
const float* y,
|
|
54
54
|
size_t d) {
|
|
55
|
-
return with_selected_simd_levels<
|
|
55
|
+
return with_selected_simd_levels<AVAILABLE_SIMD_LEVELS_BASE_WITH_SVE>(
|
|
56
56
|
[&]<SIMDLevel SL>() { return fvec_inner_product<SL>(x, y, d); });
|
|
57
57
|
}
|
|
58
58
|
|
|
@@ -67,10 +67,11 @@ inline void fvec_inner_product_batch_4_dispatch(
|
|
|
67
67
|
float& dis1,
|
|
68
68
|
float& dis2,
|
|
69
69
|
float& dis3) {
|
|
70
|
-
with_selected_simd_levels<
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
70
|
+
with_selected_simd_levels<AVAILABLE_SIMD_LEVELS_BASE_WITH_SVE>(
|
|
71
|
+
[&]<SIMDLevel SL>() {
|
|
72
|
+
fvec_inner_product_batch_4<SL>(
|
|
73
|
+
x, y0, y1, y2, y3, d, dis0, dis1, dis2, dis3);
|
|
74
|
+
});
|
|
74
75
|
}
|
|
75
76
|
|
|
76
77
|
inline void fvec_L2sqr_batch_4_dispatch(
|
|
@@ -84,9 +85,11 @@ inline void fvec_L2sqr_batch_4_dispatch(
|
|
|
84
85
|
float& dis1,
|
|
85
86
|
float& dis2,
|
|
86
87
|
float& dis3) {
|
|
87
|
-
with_selected_simd_levels<
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
with_selected_simd_levels<AVAILABLE_SIMD_LEVELS_BASE_WITH_SVE>(
|
|
89
|
+
[&]<SIMDLevel SL>() {
|
|
90
|
+
fvec_L2sqr_batch_4<SL>(
|
|
91
|
+
x, y0, y1, y2, y3, d, dis0, dis1, dis2, dis3);
|
|
92
|
+
});
|
|
90
93
|
}
|
|
91
94
|
|
|
92
95
|
inline void fvec_L2sqr_ny_transposed_dispatch(
|
|
@@ -97,9 +100,11 @@ inline void fvec_L2sqr_ny_transposed_dispatch(
|
|
|
97
100
|
size_t d,
|
|
98
101
|
size_t d_offset,
|
|
99
102
|
size_t ny) {
|
|
100
|
-
with_selected_simd_levels<
|
|
101
|
-
|
|
102
|
-
|
|
103
|
+
with_selected_simd_levels<AVAILABLE_SIMD_LEVELS_BASE_WITH_SVE>(
|
|
104
|
+
[&]<SIMDLevel SL>() {
|
|
105
|
+
fvec_L2sqr_ny_transposed<SL>(
|
|
106
|
+
dis, x, y, y_sqlen, d, d_offset, ny);
|
|
107
|
+
});
|
|
103
108
|
}
|
|
104
109
|
|
|
105
110
|
inline void fvec_inner_products_ny_dispatch(
|
|
@@ -108,9 +113,10 @@ inline void fvec_inner_products_ny_dispatch(
|
|
|
108
113
|
const float* y,
|
|
109
114
|
size_t d,
|
|
110
115
|
size_t ny) {
|
|
111
|
-
with_selected_simd_levels<
|
|
112
|
-
|
|
113
|
-
|
|
116
|
+
with_selected_simd_levels<AVAILABLE_SIMD_LEVELS_BASE_WITH_SVE>(
|
|
117
|
+
[&]<SIMDLevel SL>() {
|
|
118
|
+
fvec_inner_products_ny<SL>(ip, x, y, d, ny);
|
|
119
|
+
});
|
|
114
120
|
}
|
|
115
121
|
|
|
116
122
|
inline void fvec_L2sqr_ny_dispatch(
|
|
@@ -119,7 +125,7 @@ inline void fvec_L2sqr_ny_dispatch(
|
|
|
119
125
|
const float* y,
|
|
120
126
|
size_t d,
|
|
121
127
|
size_t ny) {
|
|
122
|
-
with_selected_simd_levels<
|
|
128
|
+
with_selected_simd_levels<AVAILABLE_SIMD_LEVELS_BASE_WITH_SVE>(
|
|
123
129
|
[&]<SIMDLevel SL>() { fvec_L2sqr_ny<SL>(dis, x, y, d, ny); });
|
|
124
130
|
}
|
|
125
131
|
|
|
@@ -129,7 +135,7 @@ inline size_t fvec_L2sqr_ny_nearest_dispatch(
|
|
|
129
135
|
const float* y,
|
|
130
136
|
size_t d,
|
|
131
137
|
size_t ny) {
|
|
132
|
-
return with_selected_simd_levels<
|
|
138
|
+
return with_selected_simd_levels<AVAILABLE_SIMD_LEVELS_BASE_WITH_SVE>(
|
|
133
139
|
[&]<SIMDLevel SL>() {
|
|
134
140
|
return fvec_L2sqr_ny_nearest<SL>(
|
|
135
141
|
distances_tmp_buffer, x, y, d, ny);
|
|
@@ -144,7 +150,7 @@ inline size_t fvec_L2sqr_ny_nearest_y_transposed_dispatch(
|
|
|
144
150
|
size_t d,
|
|
145
151
|
size_t d_offset,
|
|
146
152
|
size_t ny) {
|
|
147
|
-
return with_selected_simd_levels<
|
|
153
|
+
return with_selected_simd_levels<AVAILABLE_SIMD_LEVELS_BASE_WITH_SVE>(
|
|
148
154
|
[&]<SIMDLevel SL>() {
|
|
149
155
|
return fvec_L2sqr_ny_nearest_y_transposed<SL>(
|
|
150
156
|
distances_tmp_buffer, x, y, y_sqlen, d, d_offset, ny);
|
|
@@ -157,7 +163,7 @@ inline void fvec_madd_dispatch(
|
|
|
157
163
|
float bf,
|
|
158
164
|
const float* b,
|
|
159
165
|
float* c) {
|
|
160
|
-
with_selected_simd_levels<
|
|
166
|
+
with_selected_simd_levels<AVAILABLE_SIMD_LEVELS_BASE_WITH_SVE>(
|
|
161
167
|
[&]<SIMDLevel SL>() { fvec_madd<SL>(n, a, bf, b, c); });
|
|
162
168
|
}
|
|
163
169
|
|
|
@@ -167,7 +173,7 @@ inline int fvec_madd_and_argmin_dispatch(
|
|
|
167
173
|
float bf,
|
|
168
174
|
const float* b,
|
|
169
175
|
float* c) {
|
|
170
|
-
return with_selected_simd_levels<
|
|
176
|
+
return with_selected_simd_levels<AVAILABLE_SIMD_LEVELS_BASE_WITH_SVE>(
|
|
171
177
|
[&]<SIMDLevel SL>() {
|
|
172
178
|
return fvec_madd_and_argmin<SL>(n, a, bf, b, c);
|
|
173
179
|
});
|
|
@@ -178,7 +184,7 @@ inline void fvec_sub_dispatch(
|
|
|
178
184
|
const float* a,
|
|
179
185
|
const float* b,
|
|
180
186
|
float* c) {
|
|
181
|
-
|
|
187
|
+
with_selected_simd_levels<AVAILABLE_SIMD_LEVELS_BASE_NO_AVX512>(
|
|
182
188
|
[&]<SIMDLevel level>() { fvec_sub<level>(d, a, b, c); });
|
|
183
189
|
}
|
|
184
190
|
|
|
@@ -187,7 +193,7 @@ inline void fvec_add_dispatch(
|
|
|
187
193
|
const float* a,
|
|
188
194
|
const float* b,
|
|
189
195
|
float* c) {
|
|
190
|
-
|
|
196
|
+
with_selected_simd_levels<AVAILABLE_SIMD_LEVELS_BASE_NO_AVX512>(
|
|
191
197
|
[&]<SIMDLevel level>() { fvec_add<level>(d, a, b, c); });
|
|
192
198
|
}
|
|
193
199
|
|
|
@@ -196,7 +202,7 @@ inline void fvec_add_scalar_dispatch(
|
|
|
196
202
|
const float* a,
|
|
197
203
|
float b,
|
|
198
204
|
float* c) {
|
|
199
|
-
|
|
205
|
+
with_selected_simd_levels<AVAILABLE_SIMD_LEVELS_BASE_NO_AVX512>(
|
|
200
206
|
[&]<SIMDLevel level>() { fvec_add<level>(d, a, b, c); });
|
|
201
207
|
}
|
|
202
208
|
|
|
@@ -208,7 +214,9 @@ inline void compute_PQ_dis_tables_dsub2_dispatch(
|
|
|
208
214
|
const float* x,
|
|
209
215
|
bool is_inner_product,
|
|
210
216
|
float* dis_tables) {
|
|
211
|
-
|
|
217
|
+
constexpr int dsub2_mask =
|
|
218
|
+
AVAILABLE_SIMD_LEVELS_AVX2_NEON | (1 << int(SIMDLevel::RISCV_RVV));
|
|
219
|
+
with_selected_simd_levels<dsub2_mask>([&]<SIMDLevel level>() {
|
|
212
220
|
compute_PQ_dis_tables_dsub2<level>(
|
|
213
221
|
d, ksub, centroids, nx, x, is_inner_product, dis_tables);
|
|
214
222
|
});
|
|
@@ -241,7 +249,7 @@ auto with_VectorDistance(
|
|
|
241
249
|
if constexpr (!has_simd) {
|
|
242
250
|
return call.template operator()<SIMDLevel::NONE>();
|
|
243
251
|
} else {
|
|
244
|
-
return
|
|
252
|
+
return with_simd_level_with_sve(call);
|
|
245
253
|
}
|
|
246
254
|
};
|
|
247
255
|
return with_metric_type(metric, dispatch_metric);
|
|
@@ -7,10 +7,9 @@
|
|
|
7
7
|
|
|
8
8
|
// -*- c++ -*-
|
|
9
9
|
|
|
10
|
+
#include <faiss/impl/platform_macros.h>
|
|
10
11
|
#include <faiss/utils/distances_fused/distances_fused.h>
|
|
11
12
|
|
|
12
|
-
#ifdef COMPILE_SIMD_AVX512
|
|
13
|
-
|
|
14
13
|
#include <immintrin.h>
|
|
15
14
|
|
|
16
15
|
namespace faiss {
|
|
@@ -264,7 +263,7 @@ void exhaustive_L2sqr_fused_cmax(
|
|
|
264
263
|
|
|
265
264
|
const idx_t nx_p = (nx / NX_POINTS_PER_LOOP) * NX_POINTS_PER_LOOP;
|
|
266
265
|
// the main loop.
|
|
267
|
-
#pragma omp parallel for schedule(
|
|
266
|
+
#pragma omp parallel for schedule(FAISS_OMP_DYNAMIC)
|
|
268
267
|
for (idx_t i = 0; i < nx_p; i += NX_POINTS_PER_LOOP) {
|
|
269
268
|
kernel<DIM, NX_POINTS_PER_LOOP, NY_POINTS_PER_LOOP>(
|
|
270
269
|
x, y, y_transposed.data(), ny, res, y_norms, i);
|
|
@@ -343,5 +342,3 @@ bool exhaustive_L2sqr_fused_cmax<SIMDLevel::AVX512>(
|
|
|
343
342
|
}
|
|
344
343
|
|
|
345
344
|
} // namespace faiss
|
|
346
|
-
|
|
347
|
-
#endif // COMPILE_SIMD_AVX512
|
|
@@ -24,20 +24,6 @@ bool exhaustive_L2sqr_fused_cmax<SIMDLevel::NONE>(
|
|
|
24
24
|
return false;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
#ifdef COMPILE_SIMD_RISCV_RVV
|
|
28
|
-
template <>
|
|
29
|
-
bool exhaustive_L2sqr_fused_cmax<SIMDLevel::RISCV_RVV>(
|
|
30
|
-
const float*,
|
|
31
|
-
const float*,
|
|
32
|
-
size_t,
|
|
33
|
-
size_t,
|
|
34
|
-
size_t,
|
|
35
|
-
Top1BlockResultHandler<CMax<float, int64_t>>&,
|
|
36
|
-
const float*) {
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
#endif // COMPILE_SIMD_RISCV_RVV
|
|
40
|
-
|
|
41
27
|
bool exhaustive_L2sqr_fused_cmax(
|
|
42
28
|
const float* x,
|
|
43
29
|
const float* y,
|
|
@@ -51,7 +37,7 @@ bool exhaustive_L2sqr_fused_cmax(
|
|
|
51
37
|
return true;
|
|
52
38
|
}
|
|
53
39
|
|
|
54
|
-
return with_selected_simd_levels<
|
|
40
|
+
return with_selected_simd_levels<AVAILABLE_SIMD_LEVELS_BASE>(
|
|
55
41
|
[&]<SIMDLevel SL>() {
|
|
56
42
|
return exhaustive_L2sqr_fused_cmax<SL>(
|
|
57
43
|
x, y, d, nx, ny, res, y_norms);
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
#include <faiss/utils/distances_fused/distances_fused.h>
|
|
9
|
+
|
|
10
|
+
namespace faiss {
|
|
11
|
+
|
|
12
|
+
// Scalar fallback: no fused kernel available.
|
|
13
|
+
template <>
|
|
14
|
+
bool exhaustive_L2sqr_fused_cmax<SIMDLevel::RISCV_RVV>(
|
|
15
|
+
const float*,
|
|
16
|
+
const float*,
|
|
17
|
+
size_t,
|
|
18
|
+
size_t,
|
|
19
|
+
size_t,
|
|
20
|
+
Top1BlockResultHandler<CMax<float, int64_t>>&,
|
|
21
|
+
const float*) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
} // namespace faiss
|
|
@@ -7,8 +7,6 @@
|
|
|
7
7
|
|
|
8
8
|
// AVX2 compilation unit for the simdlib-based fused distance kernel.
|
|
9
9
|
|
|
10
|
-
#ifdef COMPILE_SIMD_AVX2
|
|
11
|
-
|
|
12
10
|
#include <faiss/impl/simdlib/simdlib_avx2.h>
|
|
13
11
|
// NOLINTNEXTLINE(facebook-hte-InlineHeader)
|
|
14
12
|
#include <faiss/utils/distances_fused/simdlib_kernel-inl.h>
|
|
@@ -71,5 +69,3 @@ bool exhaustive_L2sqr_fused_cmax<SIMDLevel::AVX2>(
|
|
|
71
69
|
}
|
|
72
70
|
|
|
73
71
|
} // namespace faiss
|
|
74
|
-
|
|
75
|
-
#endif // COMPILE_SIMD_AVX2
|
|
@@ -7,8 +7,6 @@
|
|
|
7
7
|
|
|
8
8
|
// ARM NEON compilation unit for the simdlib-based fused distance kernel.
|
|
9
9
|
|
|
10
|
-
#ifdef COMPILE_SIMD_ARM_NEON
|
|
11
|
-
|
|
12
10
|
#include <faiss/impl/simdlib/simdlib_neon.h>
|
|
13
11
|
// NOLINTNEXTLINE(facebook-hte-InlineHeader)
|
|
14
12
|
#include <faiss/utils/distances_fused/simdlib_kernel-inl.h>
|
|
@@ -53,5 +51,3 @@ bool exhaustive_L2sqr_fused_cmax<SIMDLevel::ARM_NEON>(
|
|
|
53
51
|
}
|
|
54
52
|
|
|
55
53
|
} // namespace faiss
|
|
56
|
-
|
|
57
|
-
#endif // COMPILE_SIMD_ARM_NEON
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
#pragma once
|
|
16
16
|
|
|
17
|
+
#include <faiss/impl/platform_macros.h>
|
|
17
18
|
#include <faiss/utils/distances_fused/distances_fused.h>
|
|
18
19
|
|
|
19
20
|
namespace faiss {
|
|
@@ -267,7 +268,7 @@ void exhaustive_L2sqr_fused_cmax(
|
|
|
267
268
|
|
|
268
269
|
const size_t nx_p = (nx / NX_POINTS_PER_LOOP) * NX_POINTS_PER_LOOP;
|
|
269
270
|
// the main loop.
|
|
270
|
-
#pragma omp parallel for schedule(
|
|
271
|
+
#pragma omp parallel for schedule(FAISS_OMP_DYNAMIC)
|
|
271
272
|
for (int64_t i = 0; i < static_cast<int64_t>(nx_p);
|
|
272
273
|
i += NX_POINTS_PER_LOOP) {
|
|
273
274
|
kernel<DIM, NX_POINTS_PER_LOOP, NY_POINTS_PER_LOOP, SL>(
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
// -*- c++ -*-
|
|
9
9
|
|
|
10
10
|
#include <faiss/utils/distances.h>
|
|
11
|
+
#include <faiss/utils/simd_impl/masked_sum.h>
|
|
11
12
|
|
|
12
13
|
#include <cmath>
|
|
13
14
|
#include <cstring>
|
|
@@ -42,6 +43,14 @@ void fvec_madd<SIMDLevel::NONE>(
|
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
|
|
46
|
+
template <>
|
|
47
|
+
float fvec_masked_sum<SIMDLevel::NONE>(
|
|
48
|
+
const float* x,
|
|
49
|
+
const uint8_t* bits,
|
|
50
|
+
size_t d) {
|
|
51
|
+
return masked_sum<SIMDLevel::NONE>(x, bits, d);
|
|
52
|
+
}
|
|
53
|
+
|
|
45
54
|
template <>
|
|
46
55
|
void fvec_L2sqr_ny_transposed<SIMDLevel::NONE>(
|
|
47
56
|
float* dis,
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
|
|
13
13
|
namespace faiss {
|
|
14
14
|
|
|
15
|
+
namespace {
|
|
16
|
+
|
|
15
17
|
inline uint16_t encode_fp16(float x) {
|
|
16
18
|
__m128 xf = _mm_set1_ps(x);
|
|
17
19
|
__m128i xi =
|
|
@@ -25,4 +27,6 @@ inline float decode_fp16(uint16_t x) {
|
|
|
25
27
|
return _mm_cvtss_f32(xf);
|
|
26
28
|
}
|
|
27
29
|
|
|
30
|
+
} // namespace
|
|
31
|
+
|
|
28
32
|
} // namespace faiss
|
|
@@ -27,63 +27,35 @@ inline uint32_t intbits(float f) {
|
|
|
27
27
|
return *(uint32_t*)fptr;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
} // namespace
|
|
31
|
-
|
|
32
30
|
inline uint16_t encode_fp16(float f) {
|
|
33
|
-
//
|
|
34
|
-
//
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
// Rounds to nearest even, as the F16C and Arm conversions do, so that
|
|
32
|
+
// every SIMD level encodes the same bits. Via Fabian "ryg" Giesen
|
|
33
|
+
// (float_to_half_fast3_rtne): https://gist.github.com/2156668
|
|
34
|
+
const uint32_t f32infty = 255u << 23;
|
|
35
|
+
const uint32_t f16max = (127u + 16u) << 23;
|
|
36
|
+
const uint32_t denorm_magic = ((127u - 15u) + (23u - 10u) + 1u) << 23;
|
|
37
|
+
const uint32_t sign_mask = 0x80000000u;
|
|
37
38
|
|
|
38
39
|
uint32_t fint = intbits(f);
|
|
39
|
-
uint32_t sign = fint & sign_mask;
|
|
40
|
+
const uint32_t sign = fint & sign_mask;
|
|
40
41
|
fint ^= sign;
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const uint32_t round_mask = ~0xfffu;
|
|
59
|
-
const uint32_t magic = 15u << 23;
|
|
60
|
-
|
|
61
|
-
// Shift exponent down, denormalize if necessary.
|
|
62
|
-
// NOTE This represents half-float denormals using single
|
|
63
|
-
// precision denormals. The main reason to do this is that
|
|
64
|
-
// there's no shift with per-lane variable shifts in SSE*, which
|
|
65
|
-
// we'd otherwise need. It has some funky side effects though:
|
|
66
|
-
// - This conversion will actually respect the FTZ (Flush To Zero)
|
|
67
|
-
// flag in MXCSR - if it's set, no half-float denormals will be
|
|
68
|
-
// generated. I'm honestly not sure whether this is good or
|
|
69
|
-
// bad. It's definitely interesting.
|
|
70
|
-
// - If the underlying HW doesn't support denormals (not an issue
|
|
71
|
-
// with Intel CPUs, but might be a problem on GPUs or PS3 SPUs),
|
|
72
|
-
// you will always get flush-to-zero behavior. This is bad,
|
|
73
|
-
// unless you're on a CPU where you don't care.
|
|
74
|
-
// - Denormals tend to be slow. FP32 denormals are rare in
|
|
75
|
-
// practice outside of things like recursive filters in DSP -
|
|
76
|
-
// not a typical half-float application. Whether FP16 denormals
|
|
77
|
-
// are rare in practice, I don't know. Whatever slow path your
|
|
78
|
-
// HW may or may not have for denormals, this may well hit it.
|
|
79
|
-
float fscale = floatbits(fint & round_mask) * floatbits(magic);
|
|
80
|
-
fscale = std::min(fscale, floatbits((31u << 23) - 0x1000u));
|
|
81
|
-
int32_t fint2 = intbits(fscale) - round_mask;
|
|
82
|
-
|
|
83
|
-
if (fint < f32infty)
|
|
84
|
-
o = fint2 >> 13; // Take the bits!
|
|
85
|
-
|
|
86
|
-
return (o | (sign >> 16));
|
|
43
|
+
uint32_t o;
|
|
44
|
+
if (fint >= f16max) {
|
|
45
|
+
// Inf->Inf. NaN->qNaN with the top bits of the payload, as F16C.
|
|
46
|
+
o = (fint > f32infty) ? 0x7e00u | ((fint >> 13) & 0x3ffu) : 0x7c00u;
|
|
47
|
+
} else if (fint < (113u << 23)) {
|
|
48
|
+
// The result is subnormal or zero. Adding a magic value aligns the 10
|
|
49
|
+
// mantissa bits at the bottom of the float, and the float addition
|
|
50
|
+
// rounds to nearest even.
|
|
51
|
+
o = intbits(floatbits(fint) + floatbits(denorm_magic)) - denorm_magic;
|
|
52
|
+
} else {
|
|
53
|
+
const uint32_t mant_odd = (fint >> 13) & 1;
|
|
54
|
+
// rebias the exponent, and round to nearest even
|
|
55
|
+
fint += ((15u - 127u) << 23) + 0xfffu + mant_odd;
|
|
56
|
+
o = fint >> 13;
|
|
57
|
+
}
|
|
58
|
+
return static_cast<uint16_t>(o | (sign >> 16));
|
|
87
59
|
}
|
|
88
60
|
|
|
89
61
|
inline float decode_fp16(uint16_t h) {
|
|
@@ -105,4 +77,6 @@ inline float decode_fp16(uint16_t h) {
|
|
|
105
77
|
return floatbits(((exp == shifted_exp) ? infnan_val : reg_val) | sign_bit);
|
|
106
78
|
}
|
|
107
79
|
|
|
80
|
+
} // namespace
|
|
81
|
+
|
|
108
82
|
} // namespace faiss
|
|
@@ -146,8 +146,14 @@ void hammings(
|
|
|
146
146
|
size_t nb,
|
|
147
147
|
size_t ncodes,
|
|
148
148
|
hamdis_t* __restrict dis) {
|
|
149
|
-
|
|
150
|
-
|
|
149
|
+
with_simd_level_with_vpopcnt([&]<SIMDLevel SL>() {
|
|
150
|
+
// Ragged sizes have their own kernel; keeping it out of
|
|
151
|
+
// hammings_fixSL() leaves the word-level paths untouched.
|
|
152
|
+
if (ncodes % 8 != 0) {
|
|
153
|
+
hammings_ragged_fixSL<SL>(a, b, na, nb, ncodes, dis);
|
|
154
|
+
} else {
|
|
155
|
+
hammings_fixSL<SL>(a, b, na, nb, ncodes, dis);
|
|
156
|
+
}
|
|
151
157
|
});
|
|
152
158
|
}
|
|
153
159
|
|
|
@@ -170,7 +176,7 @@ void hammings_knn_hc(
|
|
|
170
176
|
int order,
|
|
171
177
|
ApproxTopK_mode_t approx_topk_mode,
|
|
172
178
|
const faiss::IDSelector* sel) {
|
|
173
|
-
|
|
179
|
+
with_simd_level_with_vpopcnt([&]<SIMDLevel SL>() {
|
|
174
180
|
hammings_knn_hc_fixSL<SL>(
|
|
175
181
|
ha, a, b, nb, ncodes, order, approx_topk_mode, sel);
|
|
176
182
|
});
|
|
@@ -186,7 +192,7 @@ void hammings_knn_mc(
|
|
|
186
192
|
int32_t* __restrict distances,
|
|
187
193
|
int64_t* __restrict labels,
|
|
188
194
|
const faiss::IDSelector* sel) {
|
|
189
|
-
|
|
195
|
+
with_simd_level_with_vpopcnt([&]<SIMDLevel SL>() {
|
|
190
196
|
hammings_knn_mc_fixSL<SL>(
|
|
191
197
|
a, b, na, nb, k, ncodes, distances, labels, sel);
|
|
192
198
|
});
|
|
@@ -201,7 +207,7 @@ void hamming_range_search(
|
|
|
201
207
|
size_t code_size,
|
|
202
208
|
RangeSearchResult* result,
|
|
203
209
|
const faiss::IDSelector* sel) {
|
|
204
|
-
|
|
210
|
+
with_simd_level_with_vpopcnt([&]<SIMDLevel SL>() {
|
|
205
211
|
hamming_range_search_fixSL<SL>(
|
|
206
212
|
a, b, na, nb, radius, code_size, result, sel);
|
|
207
213
|
});
|
|
@@ -215,7 +221,7 @@ void hamming_count_thres(
|
|
|
215
221
|
hamdis_t ht,
|
|
216
222
|
size_t ncodes,
|
|
217
223
|
size_t* nptr) {
|
|
218
|
-
|
|
224
|
+
with_simd_level_with_vpopcnt([&]<SIMDLevel SL>() {
|
|
219
225
|
hamming_count_thres_fixSL<SL>(bs1, bs2, n1, n2, ht, ncodes, nptr);
|
|
220
226
|
});
|
|
221
227
|
}
|
|
@@ -226,7 +232,7 @@ void crosshamming_count_thres(
|
|
|
226
232
|
hamdis_t ht,
|
|
227
233
|
size_t ncodes,
|
|
228
234
|
size_t* nptr) {
|
|
229
|
-
|
|
235
|
+
with_simd_level_with_vpopcnt([&]<SIMDLevel SL>() {
|
|
230
236
|
crosshamming_count_thres_fixSL<SL>(dbs, n, ht, ncodes, nptr);
|
|
231
237
|
});
|
|
232
238
|
}
|
|
@@ -240,7 +246,7 @@ size_t match_hamming_thres(
|
|
|
240
246
|
size_t ncodes,
|
|
241
247
|
int64_t* idx,
|
|
242
248
|
hamdis_t* dis) {
|
|
243
|
-
return
|
|
249
|
+
return with_simd_level_with_vpopcnt([&]<SIMDLevel SL>() -> size_t {
|
|
244
250
|
return match_hamming_thres_fixSL<SL>(
|
|
245
251
|
bs1, bs2, n1, n2, ht, ncodes, idx, dis);
|
|
246
252
|
});
|
|
@@ -253,7 +259,7 @@ void generalized_hammings_knn_hc(
|
|
|
253
259
|
size_t nb,
|
|
254
260
|
size_t code_size,
|
|
255
261
|
int ordered) {
|
|
256
|
-
|
|
262
|
+
with_simd_level_with_vpopcnt([&]<SIMDLevel SL>() {
|
|
257
263
|
generalized_hammings_knn_hc_fixSL<SL>(ha, a, b, nb, code_size, ordered);
|
|
258
264
|
});
|
|
259
265
|
}
|
|
@@ -111,7 +111,7 @@ FAISS_API extern size_t hamming_batch_size;
|
|
|
111
111
|
*
|
|
112
112
|
* @param a size na * nbytespercode
|
|
113
113
|
* @param b size nb * nbytespercode
|
|
114
|
-
* @param nbytespercode
|
|
114
|
+
* @param nbytespercode any size; multiples of 8 take a faster kernel
|
|
115
115
|
* @param dis output distances, size na * nb
|
|
116
116
|
*/
|
|
117
117
|
void hammings(
|
|
@@ -327,6 +327,15 @@ void hamming_range_search_fixSL(
|
|
|
327
327
|
RangeSearchResult* result,
|
|
328
328
|
const IDSelector* sel);
|
|
329
329
|
|
|
330
|
+
template <SIMDLevel SL>
|
|
331
|
+
void hammings_ragged_fixSL(
|
|
332
|
+
const uint8_t* a,
|
|
333
|
+
const uint8_t* b,
|
|
334
|
+
size_t na,
|
|
335
|
+
size_t nb,
|
|
336
|
+
size_t ncodes,
|
|
337
|
+
hamdis_t* dis);
|
|
338
|
+
|
|
330
339
|
template <SIMDLevel SL>
|
|
331
340
|
void hammings_fixSL(
|
|
332
341
|
const uint8_t* a,
|
|
@@ -210,12 +210,23 @@ inline void hammings_impl(
|
|
|
210
210
|
size_t n2,
|
|
211
211
|
hamdis_t* __restrict dis) {
|
|
212
212
|
size_t i, j;
|
|
213
|
-
|
|
213
|
+
constexpr size_t nwords = nbits / 64;
|
|
214
214
|
for (i = 0; i < n1; i++) {
|
|
215
215
|
const uint64_t* __restrict bs1_ = bs1 + i * nwords;
|
|
216
216
|
hamdis_t* __restrict dis_ = dis + i * n2;
|
|
217
|
-
|
|
218
|
-
|
|
217
|
+
if constexpr (nwords >= 4) {
|
|
218
|
+
// Wide codes are quicker one candidate at a time; otherwise the
|
|
219
|
+
// compiler batches candidates and must gather scattered bytes.
|
|
220
|
+
#if defined(__clang__)
|
|
221
|
+
#pragma clang loop vectorize(disable)
|
|
222
|
+
#endif
|
|
223
|
+
for (j = 0; j < n2; j++) {
|
|
224
|
+
dis_[j] = hamming<nbits>(bs1_, bs2 + j * nwords);
|
|
225
|
+
}
|
|
226
|
+
} else {
|
|
227
|
+
for (j = 0; j < n2; j++) {
|
|
228
|
+
dis_[j] = hamming<nbits>(bs1_, bs2 + j * nwords);
|
|
229
|
+
}
|
|
219
230
|
}
|
|
220
231
|
}
|
|
221
232
|
}
|
|
@@ -5,12 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
#ifdef COMPILE_SIMD_AVX2
|
|
9
|
-
|
|
10
8
|
#define THE_SIMD_LEVEL SIMDLevel::AVX2
|
|
11
9
|
// NOLINTBEGIN(facebook-hte-InlineHeader,facebook-unused-include-check)
|
|
12
10
|
#include <faiss/utils/hamming_distance/hamming_computer-avx2.h>
|
|
13
11
|
#include <faiss/utils/hamming_distance/hamming_impl.h>
|
|
14
12
|
// NOLINTEND(facebook-hte-InlineHeader,facebook-unused-include-check)
|
|
15
|
-
|
|
16
|
-
#endif // COMPILE_SIMD_AVX2
|
|
@@ -5,11 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
#ifdef COMPILE_SIMD_AVX512
|
|
9
|
-
|
|
10
8
|
#define THE_SIMD_LEVEL SIMDLevel::AVX512
|
|
11
9
|
// NOLINTNEXTLINE(facebook-hte-InlineHeader)
|
|
12
10
|
#include <faiss/utils/hamming_distance/hamming_computer-avx512.h>
|
|
13
11
|
#include <faiss/utils/hamming_distance/hamming_impl.h>
|
|
14
|
-
|
|
15
|
-
#endif // COMPILE_SIMD_AVX512
|