faiss 0.6.4 → 0.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/ext/faiss/extconf.rb +2 -1
- data/ext/faiss/index.cpp +42 -0
- data/lib/faiss/version.rb +1 -1
- data/vendor/faiss/faiss/AutoTune.cpp +175 -0
- data/vendor/faiss/faiss/Clustering.cpp +150 -60
- data/vendor/faiss/faiss/Clustering.h +29 -0
- data/vendor/faiss/faiss/IVFlib.cpp +147 -51
- data/vendor/faiss/faiss/IVFlib.h +21 -2
- data/vendor/faiss/faiss/Index.cpp +44 -0
- data/vendor/faiss/faiss/Index.h +18 -13
- data/vendor/faiss/faiss/IndexBinary.cpp +8 -0
- data/vendor/faiss/faiss/IndexBinary.h +8 -0
- data/vendor/faiss/faiss/IndexBinaryFlat.cpp +1 -0
- data/vendor/faiss/faiss/IndexBinaryHNSW.cpp +85 -4
- data/vendor/faiss/faiss/IndexBinaryHNSW.h +19 -0
- data/vendor/faiss/faiss/IndexBinaryIVF.cpp +40 -11
- data/vendor/faiss/faiss/IndexFastScan.cpp +34 -18
- data/vendor/faiss/faiss/IndexFastScan.h +6 -3
- data/vendor/faiss/faiss/IndexFlat.cpp +57 -1
- data/vendor/faiss/faiss/IndexFlat.h +31 -0
- data/vendor/faiss/faiss/IndexFlatCodes.cpp +6 -1
- data/vendor/faiss/faiss/IndexHNSW.cpp +461 -13
- data/vendor/faiss/faiss/IndexHNSW.h +40 -5
- data/vendor/faiss/faiss/IndexIDMap.cpp +45 -0
- data/vendor/faiss/faiss/IndexIDMap.h +15 -3
- data/vendor/faiss/faiss/IndexIVF.cpp +349 -68
- data/vendor/faiss/faiss/IndexIVF.h +90 -2
- data/vendor/faiss/faiss/IndexIVFFastScan.cpp +51 -29
- data/vendor/faiss/faiss/IndexIVFFastScan.h +4 -2
- data/vendor/faiss/faiss/IndexIVFFlat.cpp +33 -0
- data/vendor/faiss/faiss/IndexIVFFlat.h +22 -6
- data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +2 -1
- data/vendor/faiss/faiss/IndexIVFRaBitQ.cpp +3 -20
- data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.cpp +78 -58
- data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.h +7 -13
- data/vendor/faiss/faiss/IndexIVFRaBitQSSD.cpp +1694 -0
- data/vendor/faiss/faiss/IndexIVFRaBitQSSD.h +288 -0
- data/vendor/faiss/faiss/IndexIVFSQFastScan.cpp +860 -0
- data/vendor/faiss/faiss/IndexIVFSQFastScan.h +145 -0
- data/vendor/faiss/faiss/IndexNNDescent.cpp +21 -3
- data/vendor/faiss/faiss/IndexPiPNN.cpp +201 -0
- data/vendor/faiss/faiss/IndexPiPNN.h +83 -0
- data/vendor/faiss/faiss/IndexRaBitQ.cpp +189 -41
- data/vendor/faiss/faiss/IndexRaBitQ.h +5 -0
- data/vendor/faiss/faiss/IndexRaBitQFastScan.cpp +7 -4
- data/vendor/faiss/faiss/IndexRaBitQFastScan.h +12 -6
- data/vendor/faiss/faiss/IndexReplicas.cpp +20 -0
- data/vendor/faiss/faiss/IndexReplicas.h +9 -0
- data/vendor/faiss/faiss/IndexSQFastScan.cpp +648 -0
- data/vendor/faiss/faiss/IndexSQFastScan.h +129 -0
- data/vendor/faiss/faiss/IndexShards.cpp +10 -0
- data/vendor/faiss/faiss/IndexShards.h +5 -0
- data/vendor/faiss/faiss/SuperKMeans.cpp +59 -17
- data/vendor/faiss/faiss/SuperKMeans.h +9 -4
- data/vendor/faiss/faiss/VectorTransform.cpp +159 -11
- data/vendor/faiss/faiss/VectorTransform.h +24 -1
- data/vendor/faiss/faiss/clone_index.cpp +24 -0
- data/vendor/faiss/faiss/factory_tools.cpp +19 -1
- data/vendor/faiss/faiss/gpu/Dataset.h +164 -0
- data/vendor/faiss/faiss/gpu/GpuCloner.cpp +16 -13
- data/vendor/faiss/faiss/gpu/GpuCloner.h +4 -0
- data/vendor/faiss/faiss/gpu/GpuClonerOptions.h +3 -0
- data/vendor/faiss/faiss/gpu/GpuIndex.h +4 -13
- data/vendor/faiss/faiss/gpu/GpuIndexBinaryCagra.h +32 -13
- data/vendor/faiss/faiss/gpu/GpuIndexCagra.h +51 -22
- data/vendor/faiss/faiss/gpu/GpuIndexFlat.h +11 -0
- data/vendor/faiss/faiss/gpu/GpuIndexIVF.h +6 -0
- data/vendor/faiss/faiss/gpu/impl/optimal_kmeans/GpuOptimalKMeans.h +184 -0
- data/vendor/faiss/faiss/gpu/test/TestCodePacking.cpp +12 -4
- data/vendor/faiss/faiss/gpu/test/TestGpuDatasetHeader.cpp +18 -0
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexFlat.cpp +215 -0
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFFlat.cpp +98 -0
- data/vendor/faiss/faiss/gpu/test/TestUtils.cpp +6 -5
- data/vendor/faiss/faiss/gpu/utils/DeviceUtils.h +11 -0
- data/vendor/faiss/faiss/gpu/utils/StackDeviceMemory.cpp +1 -1
- data/vendor/faiss/faiss/gpu_metal/GpuIndexFlat.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalCloner.h +12 -1
- data/vendor/faiss/faiss/gpu_metal/MetalDistance.h +93 -1
- data/vendor/faiss/faiss/gpu_metal/MetalFlatKernels.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalIndex.h +5 -1
- data/vendor/faiss/faiss/gpu_metal/MetalIndexBinaryFlat.h +69 -0
- data/vendor/faiss/faiss/gpu_metal/MetalIndexFlat.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalIndexIVFFlat.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalIndexIVFPQ.h +39 -1
- data/vendor/faiss/faiss/gpu_metal/MetalKernels.h +107 -1
- data/vendor/faiss/faiss/gpu_metal/MetalPythonBridge.h +11 -1
- data/vendor/faiss/faiss/gpu_metal/MetalResources.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/StandardMetalResources.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/impl/MetalIVFFlat.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/impl/MetalIVFPQ.h +1 -1
- data/vendor/faiss/faiss/impl/AuxIndexStructures.cpp +3 -1
- data/vendor/faiss/faiss/impl/AuxIndexStructures.h +1 -6
- data/vendor/faiss/faiss/impl/ClusteringHelpers.cpp +134 -45
- data/vendor/faiss/faiss/impl/ClusteringHelpers.h +36 -0
- data/vendor/faiss/faiss/impl/ClusteringInitialization.cpp +267 -136
- data/vendor/faiss/faiss/impl/ClusteringInitialization.h +0 -15
- data/vendor/faiss/faiss/impl/CodePacker.cpp +2 -2
- data/vendor/faiss/faiss/impl/CodePackerRaBitQ.cpp +2 -2
- data/vendor/faiss/faiss/impl/DeterministicNNDescent.cpp +2167 -0
- data/vendor/faiss/faiss/impl/DeterministicNNDescent.h +301 -0
- data/vendor/faiss/faiss/impl/DistanceComputer.cpp +63 -0
- data/vendor/faiss/faiss/impl/DistanceComputer.h +3 -29
- data/vendor/faiss/faiss/impl/HNSW.cpp +48 -12
- data/vendor/faiss/faiss/impl/HNSW.h +74 -2
- data/vendor/faiss/faiss/impl/IDSelector.h +5 -4
- data/vendor/faiss/faiss/impl/LocalSearchQuantizer.cpp +6 -19
- data/vendor/faiss/faiss/impl/NNDescent.cpp +2 -1
- data/vendor/faiss/faiss/impl/NNDescent.h +4 -0
- data/vendor/faiss/faiss/impl/NSG.cpp +3 -2
- data/vendor/faiss/faiss/impl/Panorama.h +3 -2
- data/vendor/faiss/faiss/impl/PiPNN.cpp +824 -0
- data/vendor/faiss/faiss/impl/PiPNN.h +122 -0
- data/vendor/faiss/faiss/impl/PolysemousTraining.cpp +1 -1
- data/vendor/faiss/faiss/impl/ProductQuantizer.cpp +54 -11
- data/vendor/faiss/faiss/impl/RaBitQUtils.cpp +0 -2
- data/vendor/faiss/faiss/impl/RaBitQUtils.h +30 -1
- data/vendor/faiss/faiss/impl/RaBitQuantizer.cpp +91 -66
- data/vendor/faiss/faiss/impl/RaBitQuantizer.h +15 -0
- data/vendor/faiss/faiss/impl/ResultHandler.h +116 -0
- data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +29 -0
- data/vendor/faiss/faiss/impl/ScalarQuantizer.h +1 -6
- data/vendor/faiss/faiss/impl/approx_topk/avx2.cpp +0 -4
- data/vendor/faiss/faiss/impl/approx_topk/neon.cpp +0 -4
- data/vendor/faiss/faiss/impl/binary_hamming/IndexBinaryHash_impl.h +5 -2
- data/vendor/faiss/faiss/impl/binary_hamming/IndexBinaryIVF_impl.h +1 -3
- data/vendor/faiss/faiss/impl/binary_hamming/avx2.cpp +0 -4
- data/vendor/faiss/faiss/impl/binary_hamming/avx512.cpp +0 -4
- data/vendor/faiss/faiss/impl/binary_hamming/neon.cpp +0 -4
- data/vendor/faiss/faiss/impl/binary_hamming/rvv.cpp +0 -4
- data/vendor/faiss/faiss/impl/expanded_scanners.h +93 -0
- data/vendor/faiss/faiss/impl/fast_scan/FastScanDistancePostProcessing.h +4 -0
- data/vendor/faiss/faiss/impl/fast_scan/accumulate_loops.h +61 -64
- data/vendor/faiss/faiss/impl/fast_scan/accumulate_loops_512.h +13 -14
- data/vendor/faiss/faiss/impl/fast_scan/decompose_qbs.h +17 -129
- data/vendor/faiss/faiss/impl/fast_scan/dispatching.h +25 -19
- data/vendor/faiss/faiss/impl/fast_scan/fast_scan.cpp +73 -6
- data/vendor/faiss/faiss/impl/fast_scan/fast_scan.h +43 -0
- data/vendor/faiss/faiss/impl/fast_scan/impl-avx2.cpp +15 -4
- data/vendor/faiss/faiss/impl/fast_scan/impl-avx512.cpp +115 -4
- data/vendor/faiss/faiss/impl/fast_scan/impl-neon.cpp +10 -85
- data/vendor/faiss/faiss/impl/fast_scan/impl-riscv.cpp +0 -4
- data/vendor/faiss/faiss/impl/fast_scan/kernels_neon.h +155 -0
- data/vendor/faiss/faiss/impl/fast_scan/kernels_simd256.h +106 -1
- data/vendor/faiss/faiss/impl/fast_scan/kernels_simd512.h +3 -6
- data/vendor/faiss/faiss/impl/fast_scan/rabitq_result_handler.h +0 -1
- data/vendor/faiss/faiss/impl/fast_scan/simd_result_handlers.h +105 -78
- data/vendor/faiss/faiss/impl/hnsw/LockVector.h +1 -2
- data/vendor/faiss/faiss/impl/hnsw/avx2.cpp +0 -4
- data/vendor/faiss/faiss/impl/hnsw/avx512.cpp +0 -4
- data/vendor/faiss/faiss/impl/index_read.cpp +318 -9
- data/vendor/faiss/faiss/impl/index_write.cpp +124 -5
- data/vendor/faiss/faiss/impl/io.cpp +1 -0
- data/vendor/faiss/faiss/impl/io_macros.h +2 -2
- data/vendor/faiss/faiss/impl/mapped_io.cpp +3 -1
- data/vendor/faiss/faiss/impl/maybe_owned_vector.h +78 -41
- data/vendor/faiss/faiss/impl/nndescent/gram-avx2.cpp +121 -0
- data/vendor/faiss/faiss/impl/nndescent/gram-avx512.cpp +124 -0
- data/vendor/faiss/faiss/impl/nndescent/gram-neon.cpp +114 -0
- data/vendor/faiss/faiss/impl/nndescent/gram.h +66 -0
- data/vendor/faiss/faiss/impl/optimal_kmeans/BlockCombiner-avx512.cpp +431 -0
- data/vendor/faiss/faiss/impl/optimal_kmeans/BlockCombiner-inl.h +1157 -0
- data/vendor/faiss/faiss/impl/optimal_kmeans/OptimalKMeans.cpp +282 -0
- data/vendor/faiss/faiss/impl/optimal_kmeans/OptimalKMeans.h +226 -0
- data/vendor/faiss/faiss/impl/optimal_kmeans/OptimalKMeansCompressed.cpp +1567 -0
- data/vendor/faiss/faiss/impl/optimal_kmeans/OptimalKMeansCompressed.h +281 -0
- data/vendor/faiss/faiss/impl/pipnn/HashPrune.cpp +159 -0
- data/vendor/faiss/faiss/impl/pipnn/HashPrune.h +69 -0
- data/vendor/faiss/faiss/impl/pipnn/Partition.cpp +587 -0
- data/vendor/faiss/faiss/impl/pipnn/Partition.h +93 -0
- data/vendor/faiss/faiss/impl/pipnn/kernels.cpp +326 -0
- data/vendor/faiss/faiss/impl/pipnn/kernels.h +92 -0
- data/vendor/faiss/faiss/impl/platform_macros.h +91 -27
- data/vendor/faiss/faiss/impl/polysemous_training/avx512.cpp +0 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/IVFPQScanner_impl.h +84 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/IVFPQ_QueryTables.cpp +17 -17
- data/vendor/faiss/faiss/impl/pq_code_distance/PQDistanceComputer_impl.h +6 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/avx2.cpp +0 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/avx512.cpp +0 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/neon.cpp +0 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-avx2.h +4 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-avx512.h +4 -1
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-generic.cpp +19 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-generic.h +6 -6
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-inl.h +131 -6
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-sve.cpp +0 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_rvv_kernel.h +89 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_scan_impl.h +21 -10
- data/vendor/faiss/faiss/impl/pq_code_distance/rvv.cpp +45 -18
- data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.cpp +2 -1
- data/vendor/faiss/faiss/impl/result_handler/ResultHandler.cpp +68 -1
- data/vendor/faiss/faiss/impl/result_handler/avx2.cpp +70 -6
- data/vendor/faiss/faiss/impl/result_handler/avx512.cpp +2 -5
- data/vendor/faiss/faiss/impl/scalar_quantizer/EDENQuantizer-avx2.cpp +0 -4
- data/vendor/faiss/faiss/impl/scalar_quantizer/EDENQuantizer-avx512.cpp +0 -4
- data/vendor/faiss/faiss/impl/scalar_quantizer/EDENQuantizer.cpp +1 -1
- data/vendor/faiss/faiss/impl/scalar_quantizer/distance_computers.h +5 -1
- data/vendor/faiss/faiss/impl/scalar_quantizer/quantizers.h +28 -52
- data/vendor/faiss/faiss/impl/scalar_quantizer/scanners.h +85 -37
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx2.cpp +262 -110
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512-impl.h +503 -122
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512-spr.cpp +10 -155
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512.cpp +7 -701
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-dispatch.h +66 -57
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-neon.cpp +133 -127
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-rvv.cpp +3185 -144
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq8_coefficients.h +48 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq8_rvv_kernel.h +546 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/training.cpp +2 -2
- data/vendor/faiss/faiss/impl/simd_dispatch.h +7 -0
- data/vendor/faiss/faiss/impl/simdlib/simdlib_avx2.h +14 -0
- data/vendor/faiss/faiss/impl/simdlib/simdlib_avx512.h +20 -20
- data/vendor/faiss/faiss/impl/simdlib/simdlib_dispatch.h +7 -8
- data/vendor/faiss/faiss/impl/simdlib/simdlib_neon.h +4 -4
- data/vendor/faiss/faiss/impl/sq_fastscan_utils.h +232 -0
- data/vendor/faiss/faiss/impl/zerocopy_io.cpp +2 -1
- data/vendor/faiss/faiss/index_factory.cpp +106 -6
- data/vendor/faiss/faiss/invlists/DirectMap.cpp +1 -1
- data/vendor/faiss/faiss/invlists/DiskIOBackend.cpp +121 -0
- data/vendor/faiss/faiss/invlists/DiskIOBackend.h +71 -0
- data/vendor/faiss/faiss/invlists/InvertedLists.cpp +15 -10
- data/vendor/faiss/faiss/invlists/InvertedListsIOHook.cpp +26 -0
- data/vendor/faiss/faiss/invlists/InvertedListsIOHook.h +5 -0
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.cpp +9 -24
- data/vendor/faiss/faiss/invlists/RaBitQSSDInvertedLists.cpp +751 -0
- data/vendor/faiss/faiss/invlists/RaBitQSSDInvertedLists.h +224 -0
- data/vendor/faiss/faiss/svs/IndexSVSFaissUtils.h +2 -7
- data/vendor/faiss/faiss/svs/IndexSVSFlat.cpp +1 -1
- data/vendor/faiss/faiss/svs/IndexSVSIVF.cpp +2 -2
- data/vendor/faiss/faiss/svs/IndexSVSVamana.cpp +4 -4
- data/vendor/faiss/faiss/svs/IndexSVSVamana.h +3 -2
- data/vendor/faiss/faiss/utils/AlignedTable.h +6 -1
- data/vendor/faiss/faiss/utils/Heap.cpp +4 -3
- data/vendor/faiss/faiss/utils/WorkerThread.h +0 -1
- data/vendor/faiss/faiss/utils/approx_topk_hamming/approx_topk_hamming.h +16 -5
- data/vendor/faiss/faiss/utils/bf16.h +36 -0
- data/vendor/faiss/faiss/utils/distances.cpp +466 -43
- data/vendor/faiss/faiss/utils/distances.h +179 -2
- data/vendor/faiss/faiss/utils/distances_dispatch.h +6 -4
- data/vendor/faiss/faiss/utils/distances_fused/avx512.cpp +2 -5
- data/vendor/faiss/faiss/utils/distances_fused/distances_fused.cpp +0 -14
- data/vendor/faiss/faiss/utils/distances_fused/rvv.cpp +25 -0
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_based.cpp +0 -4
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_based_neon.cpp +0 -4
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_kernel-inl.h +2 -1
- data/vendor/faiss/faiss/utils/distances_simd.cpp +9 -0
- data/vendor/faiss/faiss/utils/extra_distances.h +2 -1
- data/vendor/faiss/faiss/utils/fp16-fp16c.h +4 -0
- data/vendor/faiss/faiss/utils/fp16-inl.h +26 -52
- data/vendor/faiss/faiss/utils/hamming-inl.h +3 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_avx2.cpp +0 -4
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_avx512.cpp +0 -4
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_avx512_vpopcnt.cpp +0 -4
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-avx512.h +33 -5
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-avx512_vpopcnt.h +15 -30
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-neon.h +0 -4
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_impl.h +2 -1
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_neon.cpp +0 -4
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_rvv.cpp +0 -4
- data/vendor/faiss/faiss/utils/partitioning.cpp +2 -2
- data/vendor/faiss/faiss/utils/pq_code_distance.h +8 -4
- data/vendor/faiss/faiss/utils/prefetch.h +1 -26
- data/vendor/faiss/faiss/utils/quantize_lut.cpp +26 -27
- data/vendor/faiss/faiss/utils/quantize_lut.h +11 -0
- data/vendor/faiss/faiss/utils/rabitq_simd.h +171 -22
- data/vendor/faiss/faiss/utils/simd_impl/distances_aarch64.cpp +9 -4
- data/vendor/faiss/faiss/utils/simd_impl/distances_arm_sve.cpp +81 -9
- data/vendor/faiss/faiss/utils/simd_impl/distances_autovec-inl.h +7 -3
- data/vendor/faiss/faiss/utils/simd_impl/distances_avx2.cpp +108 -9
- data/vendor/faiss/faiss/utils/simd_impl/distances_avx512.cpp +111 -12
- data/vendor/faiss/faiss/utils/simd_impl/distances_rvv.cpp +353 -71
- data/vendor/faiss/faiss/utils/simd_impl/distances_rvv_kernel.h +68 -0
- data/vendor/faiss/faiss/utils/simd_impl/distances_simdlib256.h +3 -3
- data/vendor/faiss/faiss/utils/simd_impl/exhaustive_L2sqr_blas_cmax.h +106 -0
- data/vendor/faiss/faiss/utils/simd_impl/fp16_kernels.h +76 -0
- data/vendor/faiss/faiss/utils/simd_impl/fp16_kernels_avx2.cpp +52 -0
- data/vendor/faiss/faiss/utils/simd_impl/fp16_kernels_avx512.cpp +52 -0
- data/vendor/faiss/faiss/utils/simd_impl/fp16_kernels_neon.cpp +48 -0
- data/vendor/faiss/faiss/utils/simd_impl/masked_sum-avx2.h +44 -0
- data/vendor/faiss/faiss/utils/simd_impl/masked_sum-avx512.h +43 -0
- data/vendor/faiss/faiss/utils/simd_impl/masked_sum.h +38 -0
- data/vendor/faiss/faiss/utils/simd_impl/partitioning_avx2.cpp +0 -4
- data/vendor/faiss/faiss/utils/simd_impl/partitioning_neon.cpp +0 -4
- data/vendor/faiss/faiss/utils/simd_impl/partitioning_simdlib256.h +16 -15
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_avx2.cpp +185 -51
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_avx512.cpp +194 -66
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_avx512_vpopcnt.cpp +51 -14
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_neon.cpp +297 -10
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_rvv.cpp +0 -4
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_kernels_avx2.cpp +0 -4
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_kernels_avx512.cpp +0 -4
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_kernels_sve.cpp +0 -4
- data/vendor/faiss/faiss/utils/simd_levels.cpp +22 -6
- data/vendor/faiss/faiss/utils/simd_levels.h +74 -1
- data/vendor/faiss/faiss/utils/sorting.cpp +6 -5
- data/vendor/faiss/faiss/utils/transpose/transpose-avx2-inl.h +0 -4
- data/vendor/faiss/faiss/utils/transpose/transpose-avx512-inl.h +0 -4
- data/vendor/faiss/faiss/utils/utils.cpp +84 -0
- data/vendor/faiss/faiss/utils/utils.h +24 -0
- metadata +52 -1
|
@@ -0,0 +1,184 @@
|
|
|
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 <faiss/impl/optimal_kmeans/OptimalKMeans.h>
|
|
11
|
+
#include <faiss/impl/optimal_kmeans/OptimalKMeansCompressed.h>
|
|
12
|
+
|
|
13
|
+
#include <cstdint>
|
|
14
|
+
#include <memory>
|
|
15
|
+
|
|
16
|
+
/** GPU version of the block combination of the optimal k-means
|
|
17
|
+
* (contrib/optimal_kmeans/06_gpu.md). All the tables are in the memory of
|
|
18
|
+
* one GPU; the pointers passed to the functions below are device pointers.
|
|
19
|
+
* Splits are uint64 (n <= 40). */
|
|
20
|
+
|
|
21
|
+
namespace faiss {
|
|
22
|
+
namespace gpu {
|
|
23
|
+
|
|
24
|
+
class GpuResourcesProvider;
|
|
25
|
+
struct GpuOptimalKMeansState;
|
|
26
|
+
|
|
27
|
+
/** Parameters of the GPU engine (all of them change only the speed). */
|
|
28
|
+
struct GpuOptimalKMeansParams {
|
|
29
|
+
/// 0: automatic, 1: every pair dense (no pruning), 2: pruned engine for
|
|
30
|
+
/// every pair that is not skipped
|
|
31
|
+
int mode = 0;
|
|
32
|
+
/// a pair is dense if the sampled fraction of its level-3 nodes that
|
|
33
|
+
/// survive the bound test exceeds dense_rate
|
|
34
|
+
float dense_rate = 0.06f;
|
|
35
|
+
/// blocks with fewer than 2^dense_work_log2 candidates are evaluated
|
|
36
|
+
/// densely (the pruning setup costs more)
|
|
37
|
+
int dense_work_log2 = 34;
|
|
38
|
+
/// guess pass over the block points (leave one point out)
|
|
39
|
+
bool guess_low = true;
|
|
40
|
+
/// guess pass over the context points: at most this many points per
|
|
41
|
+
/// group (needs the context split table)
|
|
42
|
+
int guess_bits_ctx = 64;
|
|
43
|
+
/// scale of the global offsets
|
|
44
|
+
float offset_scale = 1.0f;
|
|
45
|
+
/// test the 9 level-9 descendants of a root before loading its tiles
|
|
46
|
+
bool root9 = true;
|
|
47
|
+
/// split bits held by the 64-bit keys; n > group_bits processes the
|
|
48
|
+
/// pairs by groups of equal high split bits (tests use small values)
|
|
49
|
+
int group_bits = 32;
|
|
50
|
+
|
|
51
|
+
GpuOptimalKMeansParams() {}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/// shared memory per block needed by the combination kernels
|
|
55
|
+
size_t gpu_optimal_kmeans_shared_bytes();
|
|
56
|
+
|
|
57
|
+
/** Whether the GPU can run the combination kernels: they need
|
|
58
|
+
* gpu_optimal_kmeans_shared_bytes() of shared memory per block (85 KB:
|
|
59
|
+
* compute capability 8.0 or later). The other functions of this file run on
|
|
60
|
+
* any GPU. */
|
|
61
|
+
bool gpu_optimal_kmeans_supported(int device);
|
|
62
|
+
|
|
63
|
+
/** Block combinations on one GPU (same semantics as
|
|
64
|
+
* optimal_kmeans_combine_block). The work is enqueued on the default
|
|
65
|
+
* stream of the device in the resources; the object can be reused for many
|
|
66
|
+
* blocks, but by one thread at a time. */
|
|
67
|
+
struct GpuOptimalKMeansCombiner {
|
|
68
|
+
GpuOptimalKMeansCombiner(
|
|
69
|
+
GpuResourcesProvider* prov,
|
|
70
|
+
int device,
|
|
71
|
+
int L_max,
|
|
72
|
+
int n_max,
|
|
73
|
+
const GpuOptimalKMeansParams& params = GpuOptimalKMeansParams());
|
|
74
|
+
~GpuOptimalKMeansCombiner();
|
|
75
|
+
|
|
76
|
+
/** Combine the block s_hi of A and B into (acc_cost, acc_split).
|
|
77
|
+
*
|
|
78
|
+
* @param A, B device tables of 2^n entries
|
|
79
|
+
* @param ctx_split optional device split table of the whole output
|
|
80
|
+
* (2^n entries): the blocks s_hi ^ (1 << j), j bit of
|
|
81
|
+
* s_hi, must be final; used for the context guesses
|
|
82
|
+
* @param acc_cost device, 2^L entries, in/out
|
|
83
|
+
* @param acc_split device, 2^L entries, in/out
|
|
84
|
+
*/
|
|
85
|
+
void combine_block(
|
|
86
|
+
int n,
|
|
87
|
+
int L,
|
|
88
|
+
uint64_t s_hi,
|
|
89
|
+
const float* A,
|
|
90
|
+
const float* B,
|
|
91
|
+
bool sym,
|
|
92
|
+
const uint64_t* ctx_split,
|
|
93
|
+
float* acc_cost,
|
|
94
|
+
uint64_t* acc_split);
|
|
95
|
+
|
|
96
|
+
/** Streaming combination of one block (07_compressed.md): the input
|
|
97
|
+
* blocks are given per pair, in device memory, instead of whole tables:
|
|
98
|
+
*
|
|
99
|
+
* block_begin(n, L, s_hi, sym, acc_cost, acc_split);
|
|
100
|
+
* block_pairs(...); // one or several batches
|
|
101
|
+
* block_end();
|
|
102
|
+
*
|
|
103
|
+
* Every pair (l_hi, r_hi) of s_hi must be given once (sym: l_hi < r_hi,
|
|
104
|
+
* plus (0, 0) for s_hi = 0). The guess pass only uses the candidates of
|
|
105
|
+
* the first batch. Same result as combine_block. */
|
|
106
|
+
void block_begin(
|
|
107
|
+
int n,
|
|
108
|
+
int L,
|
|
109
|
+
uint64_t s_hi,
|
|
110
|
+
bool sym,
|
|
111
|
+
float* acc_cost,
|
|
112
|
+
uint64_t* acc_split);
|
|
113
|
+
|
|
114
|
+
/** A batch of pairs.
|
|
115
|
+
*
|
|
116
|
+
* @param l_hi, r_hi host arrays of npairs upper divisions of s_hi
|
|
117
|
+
* @param slots device array of blocks of 2^L floats
|
|
118
|
+
* @param a_slot, b_slot host arrays: the A block of pair i is
|
|
119
|
+
* slots + a_slot[i] * 2^L, its B block
|
|
120
|
+
* slots + b_slot[i] * 2^L
|
|
121
|
+
* The blocks must stay unchanged until the work is done (stream order).
|
|
122
|
+
*/
|
|
123
|
+
void block_pairs(
|
|
124
|
+
size_t npairs,
|
|
125
|
+
const uint64_t* l_hi,
|
|
126
|
+
const uint64_t* r_hi,
|
|
127
|
+
const float* slots,
|
|
128
|
+
const int32_t* a_slot,
|
|
129
|
+
const int32_t* b_slot);
|
|
130
|
+
|
|
131
|
+
void block_end();
|
|
132
|
+
|
|
133
|
+
/// add the counters of the blocks combined so far (synchronizes)
|
|
134
|
+
void get_stats(OptimalKMeansStats* stats, bool reset = true);
|
|
135
|
+
|
|
136
|
+
/// synchronize with the work enqueued so far
|
|
137
|
+
void synchronize();
|
|
138
|
+
|
|
139
|
+
GpuOptimalKMeansParams params;
|
|
140
|
+
int device;
|
|
141
|
+
std::shared_ptr<GpuOptimalKMeansState> state;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
/** T1 of the 2^L groups (blk << L) | z, written to out (device), computed
|
|
145
|
+
* on the GPU with the double operations of OptimalKMeansCost1, so the
|
|
146
|
+
* result is the same as on the CPU. */
|
|
147
|
+
void gpu_optimal_kmeans_cost1(
|
|
148
|
+
GpuResourcesProvider* prov,
|
|
149
|
+
int device,
|
|
150
|
+
const OptimalKMeansCost1& gen,
|
|
151
|
+
int L,
|
|
152
|
+
uint64_t blk,
|
|
153
|
+
float* out);
|
|
154
|
+
|
|
155
|
+
struct GpuOptimalKMeansBlockLoaderState;
|
|
156
|
+
|
|
157
|
+
/** Input blocks of 2^L entries generated on the GPU (07_compressed.md):
|
|
158
|
+
* T1, or a block of a compressed level decoded with the same operations as
|
|
159
|
+
* optimal_kmeans_decode_block. The work is enqueued
|
|
160
|
+
* on the default stream of the device in the resources. */
|
|
161
|
+
struct GpuOptimalKMeansBlockLoader {
|
|
162
|
+
GpuOptimalKMeansBlockLoader(
|
|
163
|
+
GpuResourcesProvider* prov,
|
|
164
|
+
int device,
|
|
165
|
+
const OptimalKMeansCost1& t1,
|
|
166
|
+
int L);
|
|
167
|
+
~GpuOptimalKMeansBlockLoader();
|
|
168
|
+
|
|
169
|
+
/// T1 of the 2^L groups (blk << L) | z into out (device)
|
|
170
|
+
void cost1_block(uint64_t blk, float* out);
|
|
171
|
+
|
|
172
|
+
/// decoded block s of the level into out (device, 2^L floats)
|
|
173
|
+
void decode_block(
|
|
174
|
+
const OptimalKMeansCompressedLevel& level,
|
|
175
|
+
uint64_t s,
|
|
176
|
+
float* out);
|
|
177
|
+
|
|
178
|
+
int device;
|
|
179
|
+
int L;
|
|
180
|
+
std::shared_ptr<GpuOptimalKMeansBlockLoaderState> state;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
} // namespace gpu
|
|
184
|
+
} // namespace faiss
|
|
@@ -22,7 +22,9 @@ TEST(TestCodePacking, NonInterleavedCodes_UnpackPack) {
|
|
|
22
22
|
// deterministic
|
|
23
23
|
auto seed = std::random_device()();
|
|
24
24
|
std::mt19937 gen(seed);
|
|
25
|
-
|
|
25
|
+
// uint8_t is not a conforming uniform_int_distribution type (N4950
|
|
26
|
+
// [rand.req.genl]/1.5); MSVC's STL rejects it. Use int over [0,255].
|
|
27
|
+
std::uniform_int_distribution<int> dist{0, 255};
|
|
26
28
|
|
|
27
29
|
std::cout << "seed " << seed << "\n";
|
|
28
30
|
|
|
@@ -74,7 +76,9 @@ TEST(TestCodePacking, NonInterleavedCodes_PackUnpack) {
|
|
|
74
76
|
// deterministic
|
|
75
77
|
std::random_device rd;
|
|
76
78
|
std::mt19937 gen(rd());
|
|
77
|
-
|
|
79
|
+
// uint8_t is not a conforming uniform_int_distribution type (N4950
|
|
80
|
+
// [rand.req.genl]/1.5); MSVC's STL rejects it. Use int over [0,255].
|
|
81
|
+
std::uniform_int_distribution<int> dist{0, 255};
|
|
78
82
|
|
|
79
83
|
for (auto bitsPerCode : {4, 5, 6, 8, 16, 32}) {
|
|
80
84
|
for (auto dims : {1, 7, 8, 31, 32}) {
|
|
@@ -112,7 +116,9 @@ TEST(TestCodePacking, InterleavedCodes_UnpackPack) {
|
|
|
112
116
|
// deterministic
|
|
113
117
|
std::random_device rd;
|
|
114
118
|
std::mt19937 gen(rd());
|
|
115
|
-
|
|
119
|
+
// uint8_t is not a conforming uniform_int_distribution type (N4950
|
|
120
|
+
// [rand.req.genl]/1.5); MSVC's STL rejects it. Use int over [0,255].
|
|
121
|
+
std::uniform_int_distribution<int> dist{0, 255};
|
|
116
122
|
|
|
117
123
|
for (auto bitsPerCode : {4, 5, 6, 8, 16, 32}) {
|
|
118
124
|
for (auto dims : {1, 7, 8, 31, 32}) {
|
|
@@ -249,7 +255,9 @@ TEST(TestCodePacking, InterleavedCodes_PackUnpack) {
|
|
|
249
255
|
// deterministic
|
|
250
256
|
std::random_device rd;
|
|
251
257
|
std::mt19937 gen(rd());
|
|
252
|
-
|
|
258
|
+
// uint8_t is not a conforming uniform_int_distribution type (N4950
|
|
259
|
+
// [rand.req.genl]/1.5); MSVC's STL rejects it. Use int over [0,255].
|
|
260
|
+
std::uniform_int_distribution<int> dist{0, 255};
|
|
253
261
|
|
|
254
262
|
for (auto bitsPerCode : {4, 5, 6, 8, 16, 32}) {
|
|
255
263
|
for (auto dims : {1, 7, 8, 31, 32}) {
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
// Keep this translation unit ordinary C++ without CUDA, RAFT, or cuVS headers.
|
|
9
|
+
#include <faiss/gpu/Dataset.h>
|
|
10
|
+
|
|
11
|
+
#include <type_traits>
|
|
12
|
+
|
|
13
|
+
using faiss::gpu::Dataset;
|
|
14
|
+
|
|
15
|
+
static_assert(!std::is_copy_constructible_v<Dataset>);
|
|
16
|
+
static_assert(!std::is_copy_assignable_v<Dataset>);
|
|
17
|
+
static_assert(std::is_nothrow_move_constructible_v<Dataset>);
|
|
18
|
+
static_assert(std::is_nothrow_move_assignable_v<Dataset>);
|
|
@@ -5,14 +5,19 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
#include <faiss/Clustering.h>
|
|
8
9
|
#include <faiss/IndexFlat.h>
|
|
9
10
|
#include <faiss/gpu/GpuIndexFlat.h>
|
|
11
|
+
#include <faiss/gpu/GpuIndexIVFFlat.h>
|
|
10
12
|
#include <faiss/gpu/StandardGpuResources.h>
|
|
11
13
|
#include <faiss/gpu/impl/IndexUtils.h>
|
|
12
14
|
#include <faiss/gpu/test/TestUtils.h>
|
|
13
15
|
#include <faiss/gpu/utils/DeviceUtils.h>
|
|
14
16
|
#include <faiss/impl/IDSelector.h>
|
|
17
|
+
#include <faiss/utils/fp16.h>
|
|
15
18
|
#include <gtest/gtest.h>
|
|
19
|
+
#include <algorithm>
|
|
20
|
+
#include <cstdint>
|
|
16
21
|
#include <sstream>
|
|
17
22
|
#include <unordered_map>
|
|
18
23
|
#include <vector>
|
|
@@ -807,6 +812,216 @@ TEST(TestCuvsGpuIndexFlat, IDSelector_IP) {
|
|
|
807
812
|
}
|
|
808
813
|
#endif
|
|
809
814
|
|
|
815
|
+
// Packs float vectors as IEEE binary16, the Float16 input of search_ex
|
|
816
|
+
std::vector<uint16_t> toFp16(const std::vector<float>& v) {
|
|
817
|
+
std::vector<uint16_t> out(v.size());
|
|
818
|
+
std::transform(v.begin(), v.end(), out.begin(), [](float f) {
|
|
819
|
+
return faiss::encode_fp16(f);
|
|
820
|
+
});
|
|
821
|
+
return out;
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
std::vector<float> fromFp16(const std::vector<uint16_t>& v) {
|
|
825
|
+
std::vector<float> out(v.size());
|
|
826
|
+
std::transform(v.begin(), v.end(), out.begin(), [](uint16_t h) {
|
|
827
|
+
return faiss::decode_fp16(h);
|
|
828
|
+
});
|
|
829
|
+
return out;
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
// A copy of host data on a GPU device
|
|
833
|
+
struct DeviceCopy {
|
|
834
|
+
DeviceCopy(int device, const void* src, size_t bytes) {
|
|
835
|
+
faiss::gpu::DeviceScope scope(device);
|
|
836
|
+
CUDA_VERIFY(cudaMalloc(&data, bytes));
|
|
837
|
+
CUDA_VERIFY(cudaMemcpy(data, src, bytes, cudaMemcpyHostToDevice));
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
DeviceCopy(const DeviceCopy&) = delete;
|
|
841
|
+
DeviceCopy& operator=(const DeviceCopy&) = delete;
|
|
842
|
+
|
|
843
|
+
~DeviceCopy() {
|
|
844
|
+
CUDA_VERIFY(cudaFree(data));
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
void* data = nullptr;
|
|
848
|
+
};
|
|
849
|
+
|
|
850
|
+
// search_ex on Float16 queries must return exactly what search returns on the
|
|
851
|
+
// float32 queries rounded to fp16, as the rounded values are what the index
|
|
852
|
+
// computes with, whether the queries are on the host (paged or not) or on the
|
|
853
|
+
// device
|
|
854
|
+
void testSearchExFloat16(faiss::gpu::GpuIndex& index) {
|
|
855
|
+
int numQuery = faiss::gpu::randVal(1, 512);
|
|
856
|
+
int k = std::min(faiss::gpu::randVal(1, 50), int(index.ntotal));
|
|
857
|
+
|
|
858
|
+
auto queries = faiss::gpu::randVecs(numQuery, index.d);
|
|
859
|
+
auto queries16 = toFp16(queries);
|
|
860
|
+
auto roundedQueries = fromFp16(queries16);
|
|
861
|
+
|
|
862
|
+
std::vector<float> refDistances(numQuery * k);
|
|
863
|
+
std::vector<faiss::idx_t> refLabels(numQuery * k);
|
|
864
|
+
index.search(
|
|
865
|
+
numQuery,
|
|
866
|
+
roundedQueries.data(),
|
|
867
|
+
k,
|
|
868
|
+
refDistances.data(),
|
|
869
|
+
refLabels.data());
|
|
870
|
+
|
|
871
|
+
auto expectSearchExMatches = [&](const void* x, const std::string& where) {
|
|
872
|
+
std::vector<float> distances(numQuery * k, 0);
|
|
873
|
+
std::vector<faiss::idx_t> labels(numQuery * k, -1);
|
|
874
|
+
index.search_ex(
|
|
875
|
+
numQuery,
|
|
876
|
+
x,
|
|
877
|
+
faiss::NumericType::Float16,
|
|
878
|
+
k,
|
|
879
|
+
distances.data(),
|
|
880
|
+
labels.data());
|
|
881
|
+
|
|
882
|
+
EXPECT_EQ(labels, refLabels) << where;
|
|
883
|
+
EXPECT_EQ(distances, refDistances) << where;
|
|
884
|
+
};
|
|
885
|
+
|
|
886
|
+
expectSearchExMatches(queries16.data(), "host queries");
|
|
887
|
+
|
|
888
|
+
auto minPagingSize = index.getMinPagingSize();
|
|
889
|
+
index.setMinPagingSize(0);
|
|
890
|
+
expectSearchExMatches(queries16.data(), "paged host queries");
|
|
891
|
+
index.setMinPagingSize(minPagingSize);
|
|
892
|
+
|
|
893
|
+
DeviceCopy queries16Device(
|
|
894
|
+
index.getDevice(),
|
|
895
|
+
queries16.data(),
|
|
896
|
+
queries16.size() * sizeof(uint16_t));
|
|
897
|
+
expectSearchExMatches(queries16Device.data, "device queries");
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
// Covers both float32 storage (queries widened on the device) and float16
|
|
901
|
+
// storage (queries searched natively)
|
|
902
|
+
template <typename GpuIndexFlatT>
|
|
903
|
+
void testFlatSearchExFloat16() {
|
|
904
|
+
faiss::gpu::StandardGpuResources res;
|
|
905
|
+
res.noTempMemory();
|
|
906
|
+
|
|
907
|
+
int dim = faiss::gpu::randVal(50, 400);
|
|
908
|
+
int numVecs = faiss::gpu::randVal(1000, 5000);
|
|
909
|
+
auto vecs = faiss::gpu::randVecs(numVecs, dim);
|
|
910
|
+
|
|
911
|
+
for (bool useFloat16 : {false, true}) {
|
|
912
|
+
faiss::gpu::GpuIndexFlatConfig config;
|
|
913
|
+
config.device = faiss::gpu::randVal(0, faiss::gpu::getNumDevices() - 1);
|
|
914
|
+
config.useFloat16 = useFloat16;
|
|
915
|
+
|
|
916
|
+
GpuIndexFlatT gpuIndex(&res, dim, config);
|
|
917
|
+
gpuIndex.add(numVecs, vecs.data());
|
|
918
|
+
|
|
919
|
+
SCOPED_TRACE(useFloat16 ? "useFloat16" : "float32 storage");
|
|
920
|
+
testSearchExFloat16(gpuIndex);
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
TEST(TestGpuIndexFlat, SearchExFloat16_L2) {
|
|
925
|
+
testFlatSearchExFloat16<faiss::gpu::GpuIndexFlatL2>();
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
TEST(TestGpuIndexFlat, SearchExFloat16_IP) {
|
|
929
|
+
testFlatSearchExFloat16<faiss::gpu::GpuIndexFlatIP>();
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
// Indexes without a native fp16 search widen the queries on the device
|
|
933
|
+
TEST(TestGpuIndexFlat, SearchExFloat16_IVFFlatDefault) {
|
|
934
|
+
faiss::gpu::StandardGpuResources res;
|
|
935
|
+
res.noTempMemory();
|
|
936
|
+
|
|
937
|
+
int dim = 64;
|
|
938
|
+
int numVecs = 5000;
|
|
939
|
+
auto vecs = faiss::gpu::randVecs(numVecs, dim);
|
|
940
|
+
|
|
941
|
+
faiss::gpu::GpuIndexIVFFlatConfig config;
|
|
942
|
+
config.device = faiss::gpu::randVal(0, faiss::gpu::getNumDevices() - 1);
|
|
943
|
+
|
|
944
|
+
int numLists = 32;
|
|
945
|
+
faiss::gpu::GpuIndexIVFFlat gpuIndex(
|
|
946
|
+
&res, dim, numLists, faiss::METRIC_L2, config);
|
|
947
|
+
gpuIndex.nprobe = 4;
|
|
948
|
+
gpuIndex.train(numVecs, vecs.data());
|
|
949
|
+
gpuIndex.add(numVecs, vecs.data());
|
|
950
|
+
|
|
951
|
+
testSearchExFloat16(gpuIndex);
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
// k-means on fp16 data with a GPU assignment index must match k-means on the
|
|
955
|
+
// float32 rounding of that data with the same kind of index
|
|
956
|
+
TEST(TestGpuIndexFlat, ClusteringTrainExFloat16) {
|
|
957
|
+
faiss::gpu::StandardGpuResources res;
|
|
958
|
+
res.noTempMemory();
|
|
959
|
+
|
|
960
|
+
int dim = 32;
|
|
961
|
+
int numCentroids = 20;
|
|
962
|
+
// Fits in a single decode block, so that both runs search the same batches
|
|
963
|
+
int numVecs = 2000;
|
|
964
|
+
auto vecs = faiss::gpu::randVecs(numVecs, dim);
|
|
965
|
+
auto vecs16 = toFp16(vecs);
|
|
966
|
+
auto roundedVecs = fromFp16(vecs16);
|
|
967
|
+
|
|
968
|
+
faiss::ClusteringParameters cp;
|
|
969
|
+
cp.niter = 10;
|
|
970
|
+
|
|
971
|
+
for (bool useFloat16 : {false, true}) {
|
|
972
|
+
faiss::gpu::GpuIndexFlatConfig config;
|
|
973
|
+
config.device = faiss::gpu::randVal(0, faiss::gpu::getNumDevices() - 1);
|
|
974
|
+
config.useFloat16 = useFloat16;
|
|
975
|
+
|
|
976
|
+
faiss::gpu::GpuIndexFlatL2 refIndex(&res, dim, config);
|
|
977
|
+
faiss::Clustering refClustering(dim, numCentroids, cp);
|
|
978
|
+
refClustering.train(numVecs, roundedVecs.data(), refIndex);
|
|
979
|
+
|
|
980
|
+
faiss::gpu::GpuIndexFlatL2 gpuIndex(&res, dim, config);
|
|
981
|
+
faiss::Clustering clustering(dim, numCentroids, cp);
|
|
982
|
+
clustering.train_ex(
|
|
983
|
+
numVecs, vecs16.data(), faiss::NumericType::Float16, gpuIndex);
|
|
984
|
+
|
|
985
|
+
ASSERT_EQ(clustering.centroids.size(), refClustering.centroids.size());
|
|
986
|
+
for (size_t i = 0; i < clustering.centroids.size(); ++i) {
|
|
987
|
+
EXPECT_NEAR(
|
|
988
|
+
clustering.centroids[i], refClustering.centroids[i], 1e-5f)
|
|
989
|
+
<< "useFloat16 " << useFloat16 << " element " << i;
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
// add and reconstruct_n copy the whole vector set between host and device in
|
|
995
|
+
// one copy. On ROCm, a pageable copy of more than 64 KiB goes through 16 MiB
|
|
996
|
+
// pinned chunks: 17 vectors take one chunk, and 10,500 vectors take two full
|
|
997
|
+
// chunks and a partial one. Each size has its own resources, so the second
|
|
998
|
+
// size reuses the pinned chunks after the streams of the first are destroyed.
|
|
999
|
+
TEST(TestGpuIndexFlat, LargeHostCopyRoundTrip) {
|
|
1000
|
+
int dim = 1000;
|
|
1001
|
+
int device = faiss::gpu::randVal(0, faiss::gpu::getNumDevices() - 1);
|
|
1002
|
+
|
|
1003
|
+
for (int numVecs : {17, 10500}) {
|
|
1004
|
+
faiss::gpu::StandardGpuResources res;
|
|
1005
|
+
res.noTempMemory();
|
|
1006
|
+
|
|
1007
|
+
faiss::gpu::GpuIndexFlatConfig config;
|
|
1008
|
+
config.device = device;
|
|
1009
|
+
|
|
1010
|
+
faiss::gpu::GpuIndexFlatL2 gpuIndex(&res, dim, config);
|
|
1011
|
+
std::vector<float> vecs = faiss::gpu::randVecs(numVecs, dim);
|
|
1012
|
+
gpuIndex.add(numVecs, vecs.data());
|
|
1013
|
+
|
|
1014
|
+
std::vector<float> out(vecs.size());
|
|
1015
|
+
gpuIndex.reconstruct_n(0, numVecs, out.data());
|
|
1016
|
+
|
|
1017
|
+
// Report the first difference; printing millions of values is useless
|
|
1018
|
+
size_t firstDiff =
|
|
1019
|
+
std::mismatch(out.begin(), out.end(), vecs.begin()).first -
|
|
1020
|
+
out.begin();
|
|
1021
|
+
EXPECT_EQ(firstDiff, out.size()) << "numVecs " << numVecs;
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
|
|
810
1025
|
int main(int argc, char** argv) {
|
|
811
1026
|
testing::InitGoogleTest(&argc, argv);
|
|
812
1027
|
|
|
@@ -31,8 +31,11 @@
|
|
|
31
31
|
#include <faiss/impl/IDSelector.h>
|
|
32
32
|
#include <faiss/utils/distances.h>
|
|
33
33
|
#include <gtest/gtest.h>
|
|
34
|
+
#include <algorithm>
|
|
34
35
|
#include <cmath>
|
|
36
|
+
#include <random>
|
|
35
37
|
#include <sstream>
|
|
38
|
+
#include <unordered_set>
|
|
36
39
|
#include <vector>
|
|
37
40
|
|
|
38
41
|
// FIXME: figure out a better way to test fp16
|
|
@@ -472,6 +475,101 @@ TEST(TestGpuIndexIVFFlat, Float32_32_CopyFrom) {
|
|
|
472
475
|
#endif
|
|
473
476
|
}
|
|
474
477
|
|
|
478
|
+
#if defined USE_NVIDIA_CUVS
|
|
479
|
+
class TestCuvsGpuIndexIVFFlatCopyFrom
|
|
480
|
+
: public testing::TestWithParam<faiss::MetricType> {};
|
|
481
|
+
|
|
482
|
+
TEST_P(TestCuvsGpuIndexIVFFlatCopyFrom, SearchLargeK) {
|
|
483
|
+
constexpr int numVecs = 16384;
|
|
484
|
+
constexpr int dim = 128;
|
|
485
|
+
constexpr int numCentroids = 32;
|
|
486
|
+
const auto metric = GetParam();
|
|
487
|
+
std::mt19937 rng(42);
|
|
488
|
+
std::uniform_int_distribution<int> random(-30, 30);
|
|
489
|
+
std::vector<float> vecs(numVecs * dim);
|
|
490
|
+
for (auto& value : vecs) {
|
|
491
|
+
value = random(rng);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
faiss::IndexFlat quantizer(dim, metric);
|
|
495
|
+
faiss::IndexIVFFlat cpuIndex(&quantizer, dim, numCentroids, metric);
|
|
496
|
+
cpuIndex.cp.niter = 5;
|
|
497
|
+
cpuIndex.train(numVecs, vecs.data());
|
|
498
|
+
cpuIndex.add(numVecs, vecs.data());
|
|
499
|
+
cpuIndex.nprobe = numCentroids;
|
|
500
|
+
|
|
501
|
+
faiss::gpu::StandardGpuResources res;
|
|
502
|
+
faiss::gpu::GpuIndexIVFFlatConfig config;
|
|
503
|
+
config.use_cuvs = true;
|
|
504
|
+
config.indicesOptions = faiss::gpu::INDICES_64_BIT;
|
|
505
|
+
faiss::gpu::GpuIndexIVFFlat gpuIndex(
|
|
506
|
+
&res, dim, numCentroids, metric, config);
|
|
507
|
+
gpuIndex.copyFrom(&cpuIndex);
|
|
508
|
+
|
|
509
|
+
faiss::IndexFlat exact(dim, metric);
|
|
510
|
+
exact.add(numVecs, vecs.data());
|
|
511
|
+
// k > 256 takes the cuVS path that sizes its workspace from the
|
|
512
|
+
// accumulated list sizes. Cloning must populate those sizes first.
|
|
513
|
+
for (int k : {256, 257, 500, 3500}) {
|
|
514
|
+
SCOPED_TRACE(testing::Message() << "k=" << k);
|
|
515
|
+
for (int numQueries : {1, 4}) {
|
|
516
|
+
SCOPED_TRACE(testing::Message() << "numQueries=" << numQueries);
|
|
517
|
+
std::vector<float> expected(numQueries * k);
|
|
518
|
+
std::vector<float> distances(numQueries * k);
|
|
519
|
+
std::vector<faiss::idx_t> expectedIds(numQueries * k);
|
|
520
|
+
std::vector<faiss::idx_t> ids(numQueries * k);
|
|
521
|
+
exact.search(
|
|
522
|
+
numQueries,
|
|
523
|
+
vecs.data(),
|
|
524
|
+
k,
|
|
525
|
+
expected.data(),
|
|
526
|
+
expectedIds.data());
|
|
527
|
+
for (int repeat = 0; repeat < 2; ++repeat) {
|
|
528
|
+
gpuIndex.search(
|
|
529
|
+
numQueries,
|
|
530
|
+
vecs.data(),
|
|
531
|
+
k,
|
|
532
|
+
distances.data(),
|
|
533
|
+
ids.data());
|
|
534
|
+
for (int q = 0; q < numQueries; ++q) {
|
|
535
|
+
std::unordered_set<faiss::idx_t> uniqueIds;
|
|
536
|
+
for (int i = q * k; i < (q + 1) * k; ++i) {
|
|
537
|
+
ASSERT_GE(ids[i], 0);
|
|
538
|
+
ASSERT_LT(ids[i], numVecs);
|
|
539
|
+
EXPECT_TRUE(uniqueIds.insert(ids[i]).second);
|
|
540
|
+
float score = 0;
|
|
541
|
+
for (int j = 0; j < dim; ++j) {
|
|
542
|
+
float a = vecs[q * dim + j];
|
|
543
|
+
float b = vecs[ids[i] * dim + j];
|
|
544
|
+
score += metric == faiss::METRIC_L2
|
|
545
|
+
? (a - b) * (a - b)
|
|
546
|
+
: a * b;
|
|
547
|
+
}
|
|
548
|
+
EXPECT_FLOAT_EQ(score, distances[i]);
|
|
549
|
+
}
|
|
550
|
+
// cuVS need not return sorted results, and tied scores
|
|
551
|
+
// may select different IDs at the top-k boundary.
|
|
552
|
+
std::vector<float> actual(
|
|
553
|
+
distances.begin() + q * k,
|
|
554
|
+
distances.begin() + (q + 1) * k);
|
|
555
|
+
auto begin = expected.begin() + q * k;
|
|
556
|
+
std::sort(begin, begin + k);
|
|
557
|
+
std::sort(actual.begin(), actual.end());
|
|
558
|
+
for (int i = 0; i < k; ++i) {
|
|
559
|
+
EXPECT_FLOAT_EQ(begin[i], actual[i]);
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
INSTANTIATE_TEST_SUITE_P(
|
|
568
|
+
Cuvs,
|
|
569
|
+
TestCuvsGpuIndexIVFFlatCopyFrom,
|
|
570
|
+
testing::Values(faiss::METRIC_L2, faiss::METRIC_INNER_PRODUCT));
|
|
571
|
+
#endif
|
|
572
|
+
|
|
475
573
|
TEST(TestGpuIndexIVFFlat, Float32_negative) {
|
|
476
574
|
Options opt;
|
|
477
575
|
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
#include <faiss/impl/IDSelector.h>
|
|
10
10
|
#include <faiss/utils/random.h>
|
|
11
11
|
#include <gtest/gtest.h>
|
|
12
|
-
#include <
|
|
12
|
+
#include <chrono>
|
|
13
13
|
#include <cmath>
|
|
14
14
|
#include <set>
|
|
15
15
|
#include <sstream>
|
|
@@ -100,10 +100,11 @@ std::mt19937 rng(1);
|
|
|
100
100
|
std::uniform_int_distribution<> distrib;
|
|
101
101
|
|
|
102
102
|
void newTestSeed() {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
103
|
+
auto ns = std::chrono::high_resolution_clock::now().time_since_epoch();
|
|
104
|
+
setTestSeed(
|
|
105
|
+
static_cast<long>(
|
|
106
|
+
std::chrono::duration_cast<std::chrono::nanoseconds>(ns)
|
|
107
|
+
.count()));
|
|
107
108
|
}
|
|
108
109
|
|
|
109
110
|
void setTestSeed(long seed) {
|
|
@@ -63,6 +63,17 @@ size_t getMaxSharedMemPerBlockCurrentDevice();
|
|
|
63
63
|
/// a device (deviceId >= 0) or the host (-1).
|
|
64
64
|
int getDeviceForAddress(const void* p);
|
|
65
65
|
|
|
66
|
+
/// cudaMemcpyAsync, except that on ROCm a copy of more than 64 KiB to or from
|
|
67
|
+
/// pageable host memory goes through pinned staging buffers. As with CUDA's
|
|
68
|
+
/// pageable copies, a host-to-device copy returns once the source can be
|
|
69
|
+
/// reused, and a device-to-host copy returns once the data is on the host.
|
|
70
|
+
void memcpyHostDeviceAsync(
|
|
71
|
+
void* dst,
|
|
72
|
+
const void* src,
|
|
73
|
+
size_t bytes,
|
|
74
|
+
cudaMemcpyKind kind,
|
|
75
|
+
cudaStream_t stream);
|
|
76
|
+
|
|
66
77
|
/// Does the given device support full unified memory sharing host
|
|
67
78
|
/// memory?
|
|
68
79
|
bool getFullUnifiedMemSupport(int device);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @lint-ignore-every LICENSELINT
|
|
2
2
|
/**
|
|
3
|
-
* Copyright (c) Meta Platforms, Inc. and
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @lint-ignore-every LICENSELINT
|
|
2
2
|
/**
|
|
3
|
-
* Copyright (c) Meta Platforms, Inc. and
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
#pragma once
|
|
12
12
|
|
|
13
13
|
#include <faiss/Index.h>
|
|
14
|
+
#include <faiss/IndexBinary.h>
|
|
14
15
|
|
|
15
16
|
namespace faiss {
|
|
16
17
|
namespace gpu_metal {
|
|
@@ -31,5 +32,15 @@ faiss::Index* index_cpu_to_metal_gpu(
|
|
|
31
32
|
/// Caller owns the returned index.
|
|
32
33
|
faiss::Index* index_metal_gpu_to_cpu(const faiss::Index* index);
|
|
33
34
|
|
|
35
|
+
/// Clone IndexBinaryFlat to Metal. device must be 0; caller owns the result.
|
|
36
|
+
faiss::IndexBinary* index_binary_cpu_to_metal_gpu(
|
|
37
|
+
StandardMetalResources* res,
|
|
38
|
+
int device,
|
|
39
|
+
const faiss::IndexBinary* index);
|
|
40
|
+
|
|
41
|
+
/// Clone MetalIndexBinaryFlat to CPU. Caller owns the returned index.
|
|
42
|
+
faiss::IndexBinary* index_binary_metal_gpu_to_cpu(
|
|
43
|
+
const faiss::IndexBinary* index);
|
|
44
|
+
|
|
34
45
|
} // namespace gpu_metal
|
|
35
46
|
} // namespace faiss
|