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.
Files changed (301) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/ext/faiss/extconf.rb +2 -1
  4. data/ext/faiss/index.cpp +42 -0
  5. data/lib/faiss/version.rb +1 -1
  6. data/vendor/faiss/faiss/AutoTune.cpp +175 -0
  7. data/vendor/faiss/faiss/Clustering.cpp +150 -60
  8. data/vendor/faiss/faiss/Clustering.h +29 -0
  9. data/vendor/faiss/faiss/IVFlib.cpp +147 -51
  10. data/vendor/faiss/faiss/IVFlib.h +21 -2
  11. data/vendor/faiss/faiss/Index.cpp +44 -0
  12. data/vendor/faiss/faiss/Index.h +18 -13
  13. data/vendor/faiss/faiss/IndexBinary.cpp +8 -0
  14. data/vendor/faiss/faiss/IndexBinary.h +8 -0
  15. data/vendor/faiss/faiss/IndexBinaryFlat.cpp +1 -0
  16. data/vendor/faiss/faiss/IndexBinaryHNSW.cpp +85 -4
  17. data/vendor/faiss/faiss/IndexBinaryHNSW.h +19 -0
  18. data/vendor/faiss/faiss/IndexBinaryIVF.cpp +40 -11
  19. data/vendor/faiss/faiss/IndexFastScan.cpp +34 -18
  20. data/vendor/faiss/faiss/IndexFastScan.h +6 -3
  21. data/vendor/faiss/faiss/IndexFlat.cpp +57 -1
  22. data/vendor/faiss/faiss/IndexFlat.h +31 -0
  23. data/vendor/faiss/faiss/IndexFlatCodes.cpp +6 -1
  24. data/vendor/faiss/faiss/IndexHNSW.cpp +461 -13
  25. data/vendor/faiss/faiss/IndexHNSW.h +40 -5
  26. data/vendor/faiss/faiss/IndexIDMap.cpp +45 -0
  27. data/vendor/faiss/faiss/IndexIDMap.h +15 -3
  28. data/vendor/faiss/faiss/IndexIVF.cpp +349 -68
  29. data/vendor/faiss/faiss/IndexIVF.h +90 -2
  30. data/vendor/faiss/faiss/IndexIVFFastScan.cpp +51 -29
  31. data/vendor/faiss/faiss/IndexIVFFastScan.h +4 -2
  32. data/vendor/faiss/faiss/IndexIVFFlat.cpp +33 -0
  33. data/vendor/faiss/faiss/IndexIVFFlat.h +22 -6
  34. data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +2 -1
  35. data/vendor/faiss/faiss/IndexIVFRaBitQ.cpp +3 -20
  36. data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.cpp +78 -58
  37. data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.h +7 -13
  38. data/vendor/faiss/faiss/IndexIVFRaBitQSSD.cpp +1694 -0
  39. data/vendor/faiss/faiss/IndexIVFRaBitQSSD.h +288 -0
  40. data/vendor/faiss/faiss/IndexIVFSQFastScan.cpp +860 -0
  41. data/vendor/faiss/faiss/IndexIVFSQFastScan.h +145 -0
  42. data/vendor/faiss/faiss/IndexNNDescent.cpp +21 -3
  43. data/vendor/faiss/faiss/IndexPiPNN.cpp +201 -0
  44. data/vendor/faiss/faiss/IndexPiPNN.h +83 -0
  45. data/vendor/faiss/faiss/IndexRaBitQ.cpp +189 -41
  46. data/vendor/faiss/faiss/IndexRaBitQ.h +5 -0
  47. data/vendor/faiss/faiss/IndexRaBitQFastScan.cpp +7 -4
  48. data/vendor/faiss/faiss/IndexRaBitQFastScan.h +12 -6
  49. data/vendor/faiss/faiss/IndexReplicas.cpp +20 -0
  50. data/vendor/faiss/faiss/IndexReplicas.h +9 -0
  51. data/vendor/faiss/faiss/IndexSQFastScan.cpp +648 -0
  52. data/vendor/faiss/faiss/IndexSQFastScan.h +129 -0
  53. data/vendor/faiss/faiss/IndexShards.cpp +10 -0
  54. data/vendor/faiss/faiss/IndexShards.h +5 -0
  55. data/vendor/faiss/faiss/SuperKMeans.cpp +59 -17
  56. data/vendor/faiss/faiss/SuperKMeans.h +9 -4
  57. data/vendor/faiss/faiss/VectorTransform.cpp +159 -11
  58. data/vendor/faiss/faiss/VectorTransform.h +24 -1
  59. data/vendor/faiss/faiss/clone_index.cpp +24 -0
  60. data/vendor/faiss/faiss/factory_tools.cpp +19 -1
  61. data/vendor/faiss/faiss/gpu/Dataset.h +164 -0
  62. data/vendor/faiss/faiss/gpu/GpuCloner.cpp +16 -13
  63. data/vendor/faiss/faiss/gpu/GpuCloner.h +4 -0
  64. data/vendor/faiss/faiss/gpu/GpuClonerOptions.h +3 -0
  65. data/vendor/faiss/faiss/gpu/GpuIndex.h +4 -13
  66. data/vendor/faiss/faiss/gpu/GpuIndexBinaryCagra.h +32 -13
  67. data/vendor/faiss/faiss/gpu/GpuIndexCagra.h +51 -22
  68. data/vendor/faiss/faiss/gpu/GpuIndexFlat.h +11 -0
  69. data/vendor/faiss/faiss/gpu/GpuIndexIVF.h +6 -0
  70. data/vendor/faiss/faiss/gpu/impl/optimal_kmeans/GpuOptimalKMeans.h +184 -0
  71. data/vendor/faiss/faiss/gpu/test/TestCodePacking.cpp +12 -4
  72. data/vendor/faiss/faiss/gpu/test/TestGpuDatasetHeader.cpp +18 -0
  73. data/vendor/faiss/faiss/gpu/test/TestGpuIndexFlat.cpp +215 -0
  74. data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFFlat.cpp +98 -0
  75. data/vendor/faiss/faiss/gpu/test/TestUtils.cpp +6 -5
  76. data/vendor/faiss/faiss/gpu/utils/DeviceUtils.h +11 -0
  77. data/vendor/faiss/faiss/gpu/utils/StackDeviceMemory.cpp +1 -1
  78. data/vendor/faiss/faiss/gpu_metal/GpuIndexFlat.h +1 -1
  79. data/vendor/faiss/faiss/gpu_metal/MetalCloner.h +12 -1
  80. data/vendor/faiss/faiss/gpu_metal/MetalDistance.h +93 -1
  81. data/vendor/faiss/faiss/gpu_metal/MetalFlatKernels.h +1 -1
  82. data/vendor/faiss/faiss/gpu_metal/MetalIndex.h +5 -1
  83. data/vendor/faiss/faiss/gpu_metal/MetalIndexBinaryFlat.h +69 -0
  84. data/vendor/faiss/faiss/gpu_metal/MetalIndexFlat.h +1 -1
  85. data/vendor/faiss/faiss/gpu_metal/MetalIndexIVFFlat.h +1 -1
  86. data/vendor/faiss/faiss/gpu_metal/MetalIndexIVFPQ.h +39 -1
  87. data/vendor/faiss/faiss/gpu_metal/MetalKernels.h +107 -1
  88. data/vendor/faiss/faiss/gpu_metal/MetalPythonBridge.h +11 -1
  89. data/vendor/faiss/faiss/gpu_metal/MetalResources.h +1 -1
  90. data/vendor/faiss/faiss/gpu_metal/StandardMetalResources.h +1 -1
  91. data/vendor/faiss/faiss/gpu_metal/impl/MetalIVFFlat.h +1 -1
  92. data/vendor/faiss/faiss/gpu_metal/impl/MetalIVFPQ.h +1 -1
  93. data/vendor/faiss/faiss/impl/AuxIndexStructures.cpp +3 -1
  94. data/vendor/faiss/faiss/impl/AuxIndexStructures.h +1 -6
  95. data/vendor/faiss/faiss/impl/ClusteringHelpers.cpp +134 -45
  96. data/vendor/faiss/faiss/impl/ClusteringHelpers.h +36 -0
  97. data/vendor/faiss/faiss/impl/ClusteringInitialization.cpp +267 -136
  98. data/vendor/faiss/faiss/impl/ClusteringInitialization.h +0 -15
  99. data/vendor/faiss/faiss/impl/CodePacker.cpp +2 -2
  100. data/vendor/faiss/faiss/impl/CodePackerRaBitQ.cpp +2 -2
  101. data/vendor/faiss/faiss/impl/DeterministicNNDescent.cpp +2167 -0
  102. data/vendor/faiss/faiss/impl/DeterministicNNDescent.h +301 -0
  103. data/vendor/faiss/faiss/impl/DistanceComputer.cpp +63 -0
  104. data/vendor/faiss/faiss/impl/DistanceComputer.h +3 -29
  105. data/vendor/faiss/faiss/impl/HNSW.cpp +48 -12
  106. data/vendor/faiss/faiss/impl/HNSW.h +74 -2
  107. data/vendor/faiss/faiss/impl/IDSelector.h +5 -4
  108. data/vendor/faiss/faiss/impl/LocalSearchQuantizer.cpp +6 -19
  109. data/vendor/faiss/faiss/impl/NNDescent.cpp +2 -1
  110. data/vendor/faiss/faiss/impl/NNDescent.h +4 -0
  111. data/vendor/faiss/faiss/impl/NSG.cpp +3 -2
  112. data/vendor/faiss/faiss/impl/Panorama.h +3 -2
  113. data/vendor/faiss/faiss/impl/PiPNN.cpp +824 -0
  114. data/vendor/faiss/faiss/impl/PiPNN.h +122 -0
  115. data/vendor/faiss/faiss/impl/PolysemousTraining.cpp +1 -1
  116. data/vendor/faiss/faiss/impl/ProductQuantizer.cpp +54 -11
  117. data/vendor/faiss/faiss/impl/RaBitQUtils.cpp +0 -2
  118. data/vendor/faiss/faiss/impl/RaBitQUtils.h +30 -1
  119. data/vendor/faiss/faiss/impl/RaBitQuantizer.cpp +91 -66
  120. data/vendor/faiss/faiss/impl/RaBitQuantizer.h +15 -0
  121. data/vendor/faiss/faiss/impl/ResultHandler.h +116 -0
  122. data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +29 -0
  123. data/vendor/faiss/faiss/impl/ScalarQuantizer.h +1 -6
  124. data/vendor/faiss/faiss/impl/approx_topk/avx2.cpp +0 -4
  125. data/vendor/faiss/faiss/impl/approx_topk/neon.cpp +0 -4
  126. data/vendor/faiss/faiss/impl/binary_hamming/IndexBinaryHash_impl.h +5 -2
  127. data/vendor/faiss/faiss/impl/binary_hamming/IndexBinaryIVF_impl.h +1 -3
  128. data/vendor/faiss/faiss/impl/binary_hamming/avx2.cpp +0 -4
  129. data/vendor/faiss/faiss/impl/binary_hamming/avx512.cpp +0 -4
  130. data/vendor/faiss/faiss/impl/binary_hamming/neon.cpp +0 -4
  131. data/vendor/faiss/faiss/impl/binary_hamming/rvv.cpp +0 -4
  132. data/vendor/faiss/faiss/impl/expanded_scanners.h +93 -0
  133. data/vendor/faiss/faiss/impl/fast_scan/FastScanDistancePostProcessing.h +4 -0
  134. data/vendor/faiss/faiss/impl/fast_scan/accumulate_loops.h +61 -64
  135. data/vendor/faiss/faiss/impl/fast_scan/accumulate_loops_512.h +13 -14
  136. data/vendor/faiss/faiss/impl/fast_scan/decompose_qbs.h +17 -129
  137. data/vendor/faiss/faiss/impl/fast_scan/dispatching.h +25 -19
  138. data/vendor/faiss/faiss/impl/fast_scan/fast_scan.cpp +73 -6
  139. data/vendor/faiss/faiss/impl/fast_scan/fast_scan.h +43 -0
  140. data/vendor/faiss/faiss/impl/fast_scan/impl-avx2.cpp +15 -4
  141. data/vendor/faiss/faiss/impl/fast_scan/impl-avx512.cpp +115 -4
  142. data/vendor/faiss/faiss/impl/fast_scan/impl-neon.cpp +10 -85
  143. data/vendor/faiss/faiss/impl/fast_scan/impl-riscv.cpp +0 -4
  144. data/vendor/faiss/faiss/impl/fast_scan/kernels_neon.h +155 -0
  145. data/vendor/faiss/faiss/impl/fast_scan/kernels_simd256.h +106 -1
  146. data/vendor/faiss/faiss/impl/fast_scan/kernels_simd512.h +3 -6
  147. data/vendor/faiss/faiss/impl/fast_scan/rabitq_result_handler.h +0 -1
  148. data/vendor/faiss/faiss/impl/fast_scan/simd_result_handlers.h +105 -78
  149. data/vendor/faiss/faiss/impl/hnsw/LockVector.h +1 -2
  150. data/vendor/faiss/faiss/impl/hnsw/avx2.cpp +0 -4
  151. data/vendor/faiss/faiss/impl/hnsw/avx512.cpp +0 -4
  152. data/vendor/faiss/faiss/impl/index_read.cpp +318 -9
  153. data/vendor/faiss/faiss/impl/index_write.cpp +124 -5
  154. data/vendor/faiss/faiss/impl/io.cpp +1 -0
  155. data/vendor/faiss/faiss/impl/io_macros.h +2 -2
  156. data/vendor/faiss/faiss/impl/mapped_io.cpp +3 -1
  157. data/vendor/faiss/faiss/impl/maybe_owned_vector.h +78 -41
  158. data/vendor/faiss/faiss/impl/nndescent/gram-avx2.cpp +121 -0
  159. data/vendor/faiss/faiss/impl/nndescent/gram-avx512.cpp +124 -0
  160. data/vendor/faiss/faiss/impl/nndescent/gram-neon.cpp +114 -0
  161. data/vendor/faiss/faiss/impl/nndescent/gram.h +66 -0
  162. data/vendor/faiss/faiss/impl/optimal_kmeans/BlockCombiner-avx512.cpp +431 -0
  163. data/vendor/faiss/faiss/impl/optimal_kmeans/BlockCombiner-inl.h +1157 -0
  164. data/vendor/faiss/faiss/impl/optimal_kmeans/OptimalKMeans.cpp +282 -0
  165. data/vendor/faiss/faiss/impl/optimal_kmeans/OptimalKMeans.h +226 -0
  166. data/vendor/faiss/faiss/impl/optimal_kmeans/OptimalKMeansCompressed.cpp +1567 -0
  167. data/vendor/faiss/faiss/impl/optimal_kmeans/OptimalKMeansCompressed.h +281 -0
  168. data/vendor/faiss/faiss/impl/pipnn/HashPrune.cpp +159 -0
  169. data/vendor/faiss/faiss/impl/pipnn/HashPrune.h +69 -0
  170. data/vendor/faiss/faiss/impl/pipnn/Partition.cpp +587 -0
  171. data/vendor/faiss/faiss/impl/pipnn/Partition.h +93 -0
  172. data/vendor/faiss/faiss/impl/pipnn/kernels.cpp +326 -0
  173. data/vendor/faiss/faiss/impl/pipnn/kernels.h +92 -0
  174. data/vendor/faiss/faiss/impl/platform_macros.h +91 -27
  175. data/vendor/faiss/faiss/impl/polysemous_training/avx512.cpp +0 -4
  176. data/vendor/faiss/faiss/impl/pq_code_distance/IVFPQScanner_impl.h +84 -4
  177. data/vendor/faiss/faiss/impl/pq_code_distance/IVFPQ_QueryTables.cpp +17 -17
  178. data/vendor/faiss/faiss/impl/pq_code_distance/PQDistanceComputer_impl.h +6 -0
  179. data/vendor/faiss/faiss/impl/pq_code_distance/avx2.cpp +0 -4
  180. data/vendor/faiss/faiss/impl/pq_code_distance/avx512.cpp +0 -4
  181. data/vendor/faiss/faiss/impl/pq_code_distance/neon.cpp +0 -4
  182. data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-avx2.h +4 -0
  183. data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-avx512.h +4 -1
  184. data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-generic.cpp +19 -0
  185. data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-generic.h +6 -6
  186. data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-inl.h +131 -6
  187. data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-sve.cpp +0 -4
  188. data/vendor/faiss/faiss/impl/pq_code_distance/pq_rvv_kernel.h +89 -0
  189. data/vendor/faiss/faiss/impl/pq_code_distance/pq_scan_impl.h +21 -10
  190. data/vendor/faiss/faiss/impl/pq_code_distance/rvv.cpp +45 -18
  191. data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.cpp +2 -1
  192. data/vendor/faiss/faiss/impl/result_handler/ResultHandler.cpp +68 -1
  193. data/vendor/faiss/faiss/impl/result_handler/avx2.cpp +70 -6
  194. data/vendor/faiss/faiss/impl/result_handler/avx512.cpp +2 -5
  195. data/vendor/faiss/faiss/impl/scalar_quantizer/EDENQuantizer-avx2.cpp +0 -4
  196. data/vendor/faiss/faiss/impl/scalar_quantizer/EDENQuantizer-avx512.cpp +0 -4
  197. data/vendor/faiss/faiss/impl/scalar_quantizer/EDENQuantizer.cpp +1 -1
  198. data/vendor/faiss/faiss/impl/scalar_quantizer/distance_computers.h +5 -1
  199. data/vendor/faiss/faiss/impl/scalar_quantizer/quantizers.h +28 -52
  200. data/vendor/faiss/faiss/impl/scalar_quantizer/scanners.h +85 -37
  201. data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx2.cpp +262 -110
  202. data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512-impl.h +503 -122
  203. data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512-spr.cpp +10 -155
  204. data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512.cpp +7 -701
  205. data/vendor/faiss/faiss/impl/scalar_quantizer/sq-dispatch.h +66 -57
  206. data/vendor/faiss/faiss/impl/scalar_quantizer/sq-neon.cpp +133 -127
  207. data/vendor/faiss/faiss/impl/scalar_quantizer/sq-rvv.cpp +3185 -144
  208. data/vendor/faiss/faiss/impl/scalar_quantizer/sq8_coefficients.h +48 -0
  209. data/vendor/faiss/faiss/impl/scalar_quantizer/sq8_rvv_kernel.h +546 -0
  210. data/vendor/faiss/faiss/impl/scalar_quantizer/training.cpp +2 -2
  211. data/vendor/faiss/faiss/impl/simd_dispatch.h +7 -0
  212. data/vendor/faiss/faiss/impl/simdlib/simdlib_avx2.h +14 -0
  213. data/vendor/faiss/faiss/impl/simdlib/simdlib_avx512.h +20 -20
  214. data/vendor/faiss/faiss/impl/simdlib/simdlib_dispatch.h +7 -8
  215. data/vendor/faiss/faiss/impl/simdlib/simdlib_neon.h +4 -4
  216. data/vendor/faiss/faiss/impl/sq_fastscan_utils.h +232 -0
  217. data/vendor/faiss/faiss/impl/zerocopy_io.cpp +2 -1
  218. data/vendor/faiss/faiss/index_factory.cpp +106 -6
  219. data/vendor/faiss/faiss/invlists/DirectMap.cpp +1 -1
  220. data/vendor/faiss/faiss/invlists/DiskIOBackend.cpp +121 -0
  221. data/vendor/faiss/faiss/invlists/DiskIOBackend.h +71 -0
  222. data/vendor/faiss/faiss/invlists/InvertedLists.cpp +15 -10
  223. data/vendor/faiss/faiss/invlists/InvertedListsIOHook.cpp +26 -0
  224. data/vendor/faiss/faiss/invlists/InvertedListsIOHook.h +5 -0
  225. data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.cpp +9 -24
  226. data/vendor/faiss/faiss/invlists/RaBitQSSDInvertedLists.cpp +751 -0
  227. data/vendor/faiss/faiss/invlists/RaBitQSSDInvertedLists.h +224 -0
  228. data/vendor/faiss/faiss/svs/IndexSVSFaissUtils.h +2 -7
  229. data/vendor/faiss/faiss/svs/IndexSVSFlat.cpp +1 -1
  230. data/vendor/faiss/faiss/svs/IndexSVSIVF.cpp +2 -2
  231. data/vendor/faiss/faiss/svs/IndexSVSVamana.cpp +4 -4
  232. data/vendor/faiss/faiss/svs/IndexSVSVamana.h +3 -2
  233. data/vendor/faiss/faiss/utils/AlignedTable.h +6 -1
  234. data/vendor/faiss/faiss/utils/Heap.cpp +4 -3
  235. data/vendor/faiss/faiss/utils/WorkerThread.h +0 -1
  236. data/vendor/faiss/faiss/utils/approx_topk_hamming/approx_topk_hamming.h +16 -5
  237. data/vendor/faiss/faiss/utils/bf16.h +36 -0
  238. data/vendor/faiss/faiss/utils/distances.cpp +466 -43
  239. data/vendor/faiss/faiss/utils/distances.h +179 -2
  240. data/vendor/faiss/faiss/utils/distances_dispatch.h +6 -4
  241. data/vendor/faiss/faiss/utils/distances_fused/avx512.cpp +2 -5
  242. data/vendor/faiss/faiss/utils/distances_fused/distances_fused.cpp +0 -14
  243. data/vendor/faiss/faiss/utils/distances_fused/rvv.cpp +25 -0
  244. data/vendor/faiss/faiss/utils/distances_fused/simdlib_based.cpp +0 -4
  245. data/vendor/faiss/faiss/utils/distances_fused/simdlib_based_neon.cpp +0 -4
  246. data/vendor/faiss/faiss/utils/distances_fused/simdlib_kernel-inl.h +2 -1
  247. data/vendor/faiss/faiss/utils/distances_simd.cpp +9 -0
  248. data/vendor/faiss/faiss/utils/extra_distances.h +2 -1
  249. data/vendor/faiss/faiss/utils/fp16-fp16c.h +4 -0
  250. data/vendor/faiss/faiss/utils/fp16-inl.h +26 -52
  251. data/vendor/faiss/faiss/utils/hamming-inl.h +3 -0
  252. data/vendor/faiss/faiss/utils/hamming_distance/hamming_avx2.cpp +0 -4
  253. data/vendor/faiss/faiss/utils/hamming_distance/hamming_avx512.cpp +0 -4
  254. data/vendor/faiss/faiss/utils/hamming_distance/hamming_avx512_vpopcnt.cpp +0 -4
  255. data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-avx512.h +33 -5
  256. data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-avx512_vpopcnt.h +15 -30
  257. data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-neon.h +0 -4
  258. data/vendor/faiss/faiss/utils/hamming_distance/hamming_impl.h +2 -1
  259. data/vendor/faiss/faiss/utils/hamming_distance/hamming_neon.cpp +0 -4
  260. data/vendor/faiss/faiss/utils/hamming_distance/hamming_rvv.cpp +0 -4
  261. data/vendor/faiss/faiss/utils/partitioning.cpp +2 -2
  262. data/vendor/faiss/faiss/utils/pq_code_distance.h +8 -4
  263. data/vendor/faiss/faiss/utils/prefetch.h +1 -26
  264. data/vendor/faiss/faiss/utils/quantize_lut.cpp +26 -27
  265. data/vendor/faiss/faiss/utils/quantize_lut.h +11 -0
  266. data/vendor/faiss/faiss/utils/rabitq_simd.h +171 -22
  267. data/vendor/faiss/faiss/utils/simd_impl/distances_aarch64.cpp +9 -4
  268. data/vendor/faiss/faiss/utils/simd_impl/distances_arm_sve.cpp +81 -9
  269. data/vendor/faiss/faiss/utils/simd_impl/distances_autovec-inl.h +7 -3
  270. data/vendor/faiss/faiss/utils/simd_impl/distances_avx2.cpp +108 -9
  271. data/vendor/faiss/faiss/utils/simd_impl/distances_avx512.cpp +111 -12
  272. data/vendor/faiss/faiss/utils/simd_impl/distances_rvv.cpp +353 -71
  273. data/vendor/faiss/faiss/utils/simd_impl/distances_rvv_kernel.h +68 -0
  274. data/vendor/faiss/faiss/utils/simd_impl/distances_simdlib256.h +3 -3
  275. data/vendor/faiss/faiss/utils/simd_impl/exhaustive_L2sqr_blas_cmax.h +106 -0
  276. data/vendor/faiss/faiss/utils/simd_impl/fp16_kernels.h +76 -0
  277. data/vendor/faiss/faiss/utils/simd_impl/fp16_kernels_avx2.cpp +52 -0
  278. data/vendor/faiss/faiss/utils/simd_impl/fp16_kernels_avx512.cpp +52 -0
  279. data/vendor/faiss/faiss/utils/simd_impl/fp16_kernels_neon.cpp +48 -0
  280. data/vendor/faiss/faiss/utils/simd_impl/masked_sum-avx2.h +44 -0
  281. data/vendor/faiss/faiss/utils/simd_impl/masked_sum-avx512.h +43 -0
  282. data/vendor/faiss/faiss/utils/simd_impl/masked_sum.h +38 -0
  283. data/vendor/faiss/faiss/utils/simd_impl/partitioning_avx2.cpp +0 -4
  284. data/vendor/faiss/faiss/utils/simd_impl/partitioning_neon.cpp +0 -4
  285. data/vendor/faiss/faiss/utils/simd_impl/partitioning_simdlib256.h +16 -15
  286. data/vendor/faiss/faiss/utils/simd_impl/rabitq_avx2.cpp +185 -51
  287. data/vendor/faiss/faiss/utils/simd_impl/rabitq_avx512.cpp +194 -66
  288. data/vendor/faiss/faiss/utils/simd_impl/rabitq_avx512_vpopcnt.cpp +51 -14
  289. data/vendor/faiss/faiss/utils/simd_impl/rabitq_neon.cpp +297 -10
  290. data/vendor/faiss/faiss/utils/simd_impl/rabitq_rvv.cpp +0 -4
  291. data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_kernels_avx2.cpp +0 -4
  292. data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_kernels_avx512.cpp +0 -4
  293. data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_kernels_sve.cpp +0 -4
  294. data/vendor/faiss/faiss/utils/simd_levels.cpp +22 -6
  295. data/vendor/faiss/faiss/utils/simd_levels.h +74 -1
  296. data/vendor/faiss/faiss/utils/sorting.cpp +6 -5
  297. data/vendor/faiss/faiss/utils/transpose/transpose-avx2-inl.h +0 -4
  298. data/vendor/faiss/faiss/utils/transpose/transpose-avx512-inl.h +0 -4
  299. data/vendor/faiss/faiss/utils/utils.cpp +84 -0
  300. data/vendor/faiss/faiss/utils/utils.h +24 -0
  301. metadata +52 -1
@@ -256,6 +256,112 @@ struct Top1BlockResultHandler : TopkBlockResultHandler<C, use_sel> {
256
256
  }
257
257
  };
258
258
 
259
+ /*****************************************************************
260
+ * Two best results handler.
261
+ * Keeps the two best results of each query, best first, without a heap.
262
+ *****************************************************************/
263
+
264
+ /** Insert a result into a pair sorted best first.
265
+ *
266
+ * Results are ordered by C::cmp2, as in the heaps: equal distances are
267
+ * ordered by id (the lower id first for CMax, the higher id first for CMin).
268
+ *
269
+ * @param dis distance of the result
270
+ * @param idx id of the result
271
+ * @param dis2 in/out: the two best distances, best first, size 2
272
+ * @param ids2 in/out: their ids (-1 for none), size 2
273
+ */
274
+ template <class C>
275
+ inline void top2_insert(
276
+ typename C::T dis,
277
+ typename C::TI idx,
278
+ typename C::T* dis2,
279
+ typename C::TI* ids2) {
280
+ if (C::cmp2(dis2[1], dis, ids2[1], idx)) {
281
+ const bool first = C::cmp2(dis2[0], dis, ids2[0], idx);
282
+ dis2[1] = first ? dis2[0] : dis;
283
+ ids2[1] = first ? ids2[0] : idx;
284
+ if (first) {
285
+ dis2[0] = dis;
286
+ ids2[0] = idx;
287
+ }
288
+ }
289
+ }
290
+
291
+ /** Top-2 search results: query i's two best results, best first, are stored
292
+ * at dis_tab[2 * i] and ids_tab[2 * i]. Queries with fewer than two results
293
+ * get C::neutral() and id -1. Results are admitted as in the heaps (strict
294
+ * comparison against the current second best, so NaN is never admitted) and
295
+ * equal distances are ordered as in top2_insert, so the results match the
296
+ * heap handler's.
297
+ */
298
+ template <class C, bool use_sel = false>
299
+ struct Top2BlockResultHandler : TopkBlockResultHandler<C, use_sel> {
300
+ using T = typename C::T;
301
+ using TI = typename C::TI;
302
+ using BlockResultHandler<C, use_sel>::i0;
303
+ using BlockResultHandler<C, use_sel>::i1;
304
+
305
+ Top2BlockResultHandler(
306
+ size_t nq_,
307
+ T* dis_tab_,
308
+ TI* ids_tab_,
309
+ const IDSelector* sel_ = nullptr)
310
+ : TopkBlockResultHandler<C, use_sel>(
311
+ nq_,
312
+ dis_tab_,
313
+ ids_tab_,
314
+ 2,
315
+ sel_) {}
316
+
317
+ struct SingleResultHandler : ResultHandlerT<C> {
318
+ Top2BlockResultHandler& hr;
319
+ using ResultHandlerT<C>::threshold;
320
+
321
+ T dis2[2];
322
+ TI ids2[2];
323
+ size_t current_idx = 0;
324
+
325
+ explicit SingleResultHandler(Top2BlockResultHandler& hr_) : hr(hr_) {}
326
+
327
+ /// begin results for query # i
328
+ void begin(const size_t current_idx_2) {
329
+ current_idx = current_idx_2;
330
+ threshold = dis2[0] = dis2[1] = C::neutral();
331
+ ids2[0] = ids2[1] = -1;
332
+ }
333
+
334
+ /// add one result for query i; threshold is the second best
335
+ bool add_result(T dis, TI idx) final {
336
+ if (C::cmp(threshold, dis)) {
337
+ top2_insert<C>(dis, idx, dis2, ids2);
338
+ threshold = dis2[1];
339
+ return true;
340
+ }
341
+ return false;
342
+ }
343
+
344
+ /// series of results for query i is done
345
+ void end() {
346
+ std::copy(dis2, dis2 + 2, hr.dis_tab + 2 * current_idx);
347
+ std::copy(ids2, ids2 + 2, hr.ids_tab + 2 * current_idx);
348
+ }
349
+ };
350
+
351
+ /// begin
352
+ void begin_multiple(size_t i0_in, size_t i1_in) final {
353
+ this->i0 = i0_in;
354
+ this->i1 = i1_in;
355
+ std::fill(this->dis_tab + 2 * i0, this->dis_tab + 2 * i1, C::neutral());
356
+ std::fill(this->ids_tab + 2 * i0, this->ids_tab + 2 * i1, TI(-1));
357
+ }
358
+
359
+ /// add results for query i0..i1 and j0..j1
360
+ /// Implemented in result_handler.cpp; dispatches via
361
+ /// with_selected_simd_levels to top2_add_results_tpl<C, use_sel, SL>.
362
+ void add_results(size_t j0, size_t j1, const T* dis_tab_2) final;
363
+ };
364
+
259
365
  /*****************************************************************
260
366
  * Heap based result handler
261
367
  *****************************************************************/
@@ -725,6 +831,9 @@ typename Consumer::T dispatch_knn_ResultHandler(
725
831
  if (k == 1) { \
726
832
  Top1BlockResultHandler<C, use_sel> res(nx, vals, ids, sel); \
727
833
  return consumer.template f<>(res, args...); \
834
+ } else if (k == 2) { \
835
+ Top2BlockResultHandler<C, use_sel> res(nx, vals, ids, sel); \
836
+ return consumer.template f<>(res, args...); \
728
837
  } else if (k < static_cast<size_t>(distance_compute_min_k_reservoir)) { \
729
838
  HeapBlockResultHandler<C, use_sel> res(nx, vals, ids, k, sel); \
730
839
  return consumer.template f<>(res, args...); \
@@ -792,6 +901,13 @@ void top1_add_results_tpl(
792
901
  size_t j1,
793
902
  const typename C::T* dis_tab);
794
903
 
904
+ template <class C, bool use_sel, SIMDLevel SL>
905
+ void top2_add_results_tpl(
906
+ Top2BlockResultHandler<C, use_sel>* self,
907
+ size_t j0,
908
+ size_t j1,
909
+ const typename C::T* dis_tab);
910
+
795
911
  template <class C, bool use_sel, SIMDLevel SL>
796
912
  void reservoir_add_results_tpl(
797
913
  ReservoirBlockResultHandler<C, use_sel>* self,
@@ -453,6 +453,35 @@ float unit_norm_component_scale(size_t d) {
453
453
 
454
454
  } // namespace
455
455
 
456
+ void ScalarQuantizer::SQDistanceComputer::query_to_codes_batch_4(
457
+ const uint8_t* code_0,
458
+ const uint8_t* code_1,
459
+ const uint8_t* code_2,
460
+ const uint8_t* code_3,
461
+ float& dis0,
462
+ float& dis1,
463
+ float& dis2,
464
+ float& dis3) const {
465
+ dis0 = query_to_code(code_0);
466
+ dis1 = query_to_code(code_1);
467
+ dis2 = query_to_code(code_2);
468
+ dis3 = query_to_code(code_3);
469
+ }
470
+
471
+ namespace scalar_quantizer {
472
+
473
+ void IVFCoarseDistanceScanner::set_list(idx_t list_no_in, float coarse_dis_in) {
474
+ this->list_no = list_no_in;
475
+ this->coarse_dis = coarse_dis_in;
476
+ }
477
+
478
+ float IVFCoarseDistanceScanner::distance_to_code(
479
+ const uint8_t* /*code*/) const {
480
+ return coarse_dis;
481
+ }
482
+
483
+ } // namespace scalar_quantizer
484
+
456
485
  /*******************************************************************
457
486
  * ScalarQuantizer implementation
458
487
  ********************************************************************/
@@ -133,12 +133,7 @@ struct ScalarQuantizer : Quantizer {
133
133
  float& dis0,
134
134
  float& dis1,
135
135
  float& dis2,
136
- float& dis3) const {
137
- dis0 = query_to_code(code_0);
138
- dis1 = query_to_code(code_1);
139
- dis2 = query_to_code(code_2);
140
- dis3 = query_to_code(code_3);
141
- }
136
+ float& dis3) const;
142
137
 
143
138
  float distance_to_code(const uint8_t* code) final {
144
139
  return query_to_code(code);
@@ -8,8 +8,6 @@
8
8
  // Explicit template instantiations of HeapWithBucketsCMaxFloat and
9
9
  // accum_and_*_tab for SIMDLevel::AVX2.
10
10
 
11
- #ifdef COMPILE_SIMD_AVX2
12
-
13
11
  #include <faiss/impl/approx_topk/rq_beam_search_tab-inl.h>
14
12
  #include <faiss/impl/approx_topk/simdlib256-inl.h>
15
13
  #include <faiss/impl/simdlib/simdlib_avx2.h>
@@ -64,5 +62,3 @@ INSTANTIATE_ACCUM_TAB(8)
64
62
  #undef INSTANTIATE_ACCUM_TAB
65
63
 
66
64
  } // namespace faiss
67
-
68
- #endif // COMPILE_SIMD_AVX2
@@ -8,8 +8,6 @@
8
8
  // Explicit template instantiations of HeapWithBucketsCMaxFloat and
9
9
  // accum_and_*_tab for SIMDLevel::ARM_NEON.
10
10
 
11
- #ifdef COMPILE_SIMD_ARM_NEON
12
-
13
11
  #include <faiss/impl/approx_topk/rq_beam_search_tab-inl.h>
14
12
  #include <faiss/impl/approx_topk/simdlib256-inl.h>
15
13
  #include <faiss/impl/simdlib/simdlib_neon.h>
@@ -64,5 +62,3 @@ INSTANTIATE_ACCUM_TAB(8)
64
62
  #undef INSTANTIATE_ACCUM_TAB
65
63
 
66
64
  } // namespace faiss
67
-
68
- #endif // COMPILE_SIMD_ARM_NEON
@@ -139,11 +139,14 @@ void search_single_query_template(
139
139
  } while (fe.next());
140
140
  }
141
141
 
142
+ // A hash type with internal linkage makes the functions of the set local.
143
+ struct ShortlistHash : std::hash<idx_t> {};
144
+
142
145
  template <class HammingComputer, class SearchResults>
143
146
  static void verify_shortlist(
144
147
  const IndexBinaryFlat* index,
145
148
  const uint8_t* q,
146
- const std::unordered_set<idx_t>& shortlist,
149
+ const std::unordered_set<idx_t, ShortlistHash>& shortlist,
147
150
  SearchResults& res) {
148
151
  size_t code_size = index->code_size;
149
152
 
@@ -164,7 +167,7 @@ void search_1_query_multihash(
164
167
  size_t& n0,
165
168
  size_t& nlist,
166
169
  size_t& ndis) {
167
- std::unordered_set<idx_t> shortlist;
170
+ std::unordered_set<idx_t, ShortlistHash> shortlist;
168
171
  int b = index.b;
169
172
 
170
173
  BitstringReader br(xi, index.code_size);
@@ -271,9 +271,7 @@ void search_knn_hamming_count(
271
271
  }
272
272
  }
273
273
 
274
- indexIVF_stats.nq += nx;
275
- indexIVF_stats.nlist += nlistv;
276
- indexIVF_stats.ndis += ndis;
274
+ add_search_stats(nx, nlistv, ndis);
277
275
  }
278
276
 
279
277
  /* Manages NQ queries at a time, stores results */
@@ -5,8 +5,6 @@
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
 
12
10
  // NOLINTNEXTLINE(facebook-hte-InlineHeader,facebook-unused-include-check)
@@ -22,5 +20,3 @@
22
20
  #include <faiss/impl/binary_hamming/IndexIVFSpectralHash_impl.h> // IWYU pragma: keep
23
21
  // NOLINTNEXTLINE(facebook-hte-InlineHeader)
24
22
  #include <faiss/impl/binary_hamming/IndexPQ_impl.h>
25
-
26
- #endif // COMPILE_SIMD_AVX2
@@ -5,8 +5,6 @@
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
 
12
10
  // NOLINTNEXTLINE(facebook-hte-InlineHeader)
@@ -22,5 +20,3 @@
22
20
  #include <faiss/impl/binary_hamming/IndexIVFSpectralHash_impl.h>
23
21
  // NOLINTNEXTLINE(facebook-hte-InlineHeader)
24
22
  #include <faiss/impl/binary_hamming/IndexPQ_impl.h>
25
-
26
- #endif // COMPILE_SIMD_AVX512
@@ -5,8 +5,6 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- #ifdef COMPILE_SIMD_ARM_NEON
9
-
10
8
  #define THE_SIMD_LEVEL SIMDLevel::ARM_NEON
11
9
 
12
10
  // NOLINTNEXTLINE(facebook-hte-InlineHeader)
@@ -22,5 +20,3 @@
22
20
  #include <faiss/impl/binary_hamming/IndexIVFSpectralHash_impl.h>
23
21
  // NOLINTNEXTLINE(facebook-hte-InlineHeader)
24
22
  #include <faiss/impl/binary_hamming/IndexPQ_impl.h>
25
-
26
- #endif // COMPILE_SIMD_ARM_NEON
@@ -5,8 +5,6 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- #ifdef COMPILE_SIMD_RISCV_RVV
9
-
10
8
  #define THE_SIMD_LEVEL SIMDLevel::RISCV_RVV
11
9
 
12
10
  // NOLINTNEXTLINE(facebook-hte-InlineHeader)
@@ -22,5 +20,3 @@
22
20
  #include <faiss/impl/binary_hamming/IndexIVFSpectralHash_impl.h>
23
21
  // NOLINTNEXTLINE(facebook-hte-InlineHeader)
24
22
  #include <faiss/impl/binary_hamming/IndexPQ_impl.h>
25
-
26
- #endif // COMPILE_SIMD_RISCV_RVV
@@ -67,6 +67,66 @@ size_t run_scan_codes1(
67
67
  return nup;
68
68
  }
69
69
 
70
+ // Batched variant of run_scan_codes1 for the SQ scanners: distances four codes
71
+ // per step via distance_to_codes_batch_4, then applies the threshold and heap
72
+ // updates in id order so results match run_scan_codes1. With use_sel, the
73
+ // selector is tested only on codes that beat the threshold.
74
+ template <class ScannerType, typename C, bool store_pairs, bool use_sel>
75
+ size_t run_scan_codes4(
76
+ const ScannerType& scanner,
77
+ size_t list_size,
78
+ const uint8_t* codes,
79
+ const idx_t* ids,
80
+ ResultHandler& handler) {
81
+ size_t nup = 0;
82
+ size_t list_no = scanner.list_no;
83
+ size_t code_size = scanner.code_size;
84
+ float threshold = handler.threshold;
85
+ auto add = [&](size_t j, float dis) {
86
+ if (!C::cmp(threshold, dis)) {
87
+ return;
88
+ }
89
+ int64_t id = store_pairs ? lo_build(list_no, j) : ids[j];
90
+ // No scan context: few codes get here, so a lookahead would be wasted.
91
+ if (use_sel && !scanner.sel->is_member(id)) {
92
+ return;
93
+ }
94
+ if (handler.add_result(dis, id)) {
95
+ handler.stats.nheap_updates++;
96
+ nup++;
97
+ threshold = handler.threshold;
98
+ }
99
+ };
100
+
101
+ size_t j = 0;
102
+ for (; j + 4 <= list_size; j += 4) {
103
+ float dis[4];
104
+ scanner.distance_to_codes_batch_4(
105
+ codes,
106
+ codes + code_size,
107
+ codes + 2 * code_size,
108
+ codes + 3 * code_size,
109
+ dis[0],
110
+ dis[1],
111
+ dis[2],
112
+ dis[3]);
113
+ handler.stats.scan_cnt += 4;
114
+ for (size_t b = 0; b < 4; b++) {
115
+ add(j + b, dis[b]);
116
+ }
117
+ codes += 4 * code_size;
118
+ }
119
+
120
+ // tail: the final < 4 codes, one at a time
121
+ for (; j < list_size; j++) {
122
+ handler.stats.scan_cnt++;
123
+ add(j, scanner.distance_to_code(codes));
124
+ codes += code_size;
125
+ }
126
+
127
+ return nup;
128
+ }
129
+
70
130
  /*****************************************************************************
71
131
  * The following functions dispatch runtime parameters to templates, with
72
132
  * possibly some already-fixed templates.
@@ -136,6 +196,39 @@ size_t run_scan_codes_fix_C(
136
196
  }
137
197
  }
138
198
 
199
+ // Routing wrapper for the SQ scanners: the no-selector path and a selector
200
+ // tested after the distance take the batched run_scan_codes4, a selector tested
201
+ // first stays on run_scan_codes1.
202
+ template <class C, class ScannerType>
203
+ size_t run_scan_codes4_fix_C(
204
+ const ScannerType& scanner,
205
+ size_t list_size,
206
+ const uint8_t* codes,
207
+ const idx_t* ids,
208
+ ResultHandler& handler) {
209
+ if (scanner.sel && scanner.sel_after_distance && !scanner.store_pairs) {
210
+ return run_scan_codes4<ScannerType, C, false, true>(
211
+ scanner, list_size, codes, ids, handler);
212
+ }
213
+ if (scanner.sel) {
214
+ if (scanner.store_pairs) {
215
+ return run_scan_codes1<ScannerType, C, true, true>(
216
+ scanner, list_size, codes, ids, handler);
217
+ } else {
218
+ return run_scan_codes1<ScannerType, C, false, true>(
219
+ scanner, list_size, codes, ids, handler);
220
+ }
221
+ } else {
222
+ if (scanner.store_pairs) {
223
+ return run_scan_codes4<ScannerType, C, true, false>(
224
+ scanner, list_size, codes, ids, handler);
225
+ } else {
226
+ return run_scan_codes4<ScannerType, C, false, false>(
227
+ scanner, list_size, codes, ids, handler);
228
+ }
229
+ }
230
+ }
231
+
139
232
  template <class ScannerType>
140
233
  size_t run_scan_codes(
141
234
  const ScannerType& scanner,
@@ -29,6 +29,10 @@ struct FastScanDistancePostProcessing {
29
29
  /// QueryFactorsData subset for this context.
30
30
  rabitq_utils::QueryFactorsData* query_factors = nullptr;
31
31
 
32
+ /// Multi-bit IVF RaBitQ: rotated query per (query, probe), d floats each,
33
+ /// indexed like query_factors (nullptr if unused).
34
+ float* rotated_q = nullptr;
35
+
32
36
  /// The nprobe value used when allocating query_factors storage.
33
37
  /// This is needed because the allocation size (n * nprobe) may use a
34
38
  /// different nprobe than index->nprobe if search params override it.
@@ -1,5 +1,13 @@
1
1
  /*
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ * Portions 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
+ /*
9
+ * Portions Copyright 2026 Arm Limited and/or its affiliates
10
+ * <open-source-office@arm.com>
3
11
  *
4
12
  * This source code is licensed under the MIT license found in the
5
13
  * LICENSE file in the root directory of this source tree.
@@ -14,22 +22,14 @@
14
22
  * Contains:
15
23
  * - accumulate_fixed_blocks / pq4_accumulate_loop_fixed_scaler
16
24
  * (search_1 multi-BB path, bbs > 32)
17
- * - accumulate_q_4step_256 / pq4_accumulate_loop_qbs_fixed_scaler_256
18
- * (QBS path, bbs == 32, 256-bit kernel only)
25
+ * - SIMD-level-selected QBS traversal (bbs == 32)
19
26
  *
20
- * The QBS helpers here use pq4_kernel_qbs_256 exclusively (not
21
- * decompose_qbs.h) because decompose_qbs.h includes kernels_simd512.h
22
- * whose 512-bit types need explicit SIMD levels. The 512-bit QBS path
23
- * lives in accumulate_loops_512.h, used by the AVX512 per-ISA TU.
27
+ * The default PQ4QBSKernel<SL> uses the 256-bit kernel. Architecture-specific
28
+ * headers may specialize it while reusing the traversal and QBS dispatch.
24
29
  *
25
30
  * All functions live in `namespace faiss` (not anonymous) so they can be
26
31
  * shared by both the per-SIMD TU dispatcher (dispatching.h) and the old
27
32
  * free-function search paths (pq4_fast_scan_search_1.cpp).
28
- *
29
- * The QBS helpers here always use pq4_kernel_qbs_256 (never 512-bit).
30
- * This is required for the per-SIMD DD TUs where SINGLE_SIMD_LEVEL=NONE
31
- * leaves 512-bit types empty. The old pq4_fast_scan_search_qbs.cpp
32
- * continues to use decompose_qbs.h which includes both 256 and 512 paths.
33
33
  */
34
34
 
35
35
  #include <cassert>
@@ -37,7 +37,11 @@
37
37
  #include <faiss/impl/FaissAssert.h>
38
38
  #include <faiss/impl/fast_scan/LookupTableScaler.h>
39
39
  #include <faiss/impl/fast_scan/kernels_simd256.h>
40
+ #if FAISS_SIMD_TU(ARM_NEON)
41
+ #include <faiss/impl/fast_scan/kernels_neon.h>
42
+ #endif
40
43
  #include <faiss/impl/fast_scan/simd_result_handlers.h>
44
+ #include <faiss/utils/simd_levels.h>
41
45
 
42
46
  namespace faiss {
43
47
 
@@ -112,15 +116,11 @@ void pq4_accumulate_loop_fixed_scaler(
112
116
  }
113
117
 
114
118
  /***************************************************************
115
- * QBS path helpers (bbs == 32, 256-bit kernel only)
119
+ * QBS path helpers (bbs == 32)
116
120
  ***************************************************************/
117
121
 
118
- template <
119
- int QBS,
120
- SIMDLevel KernelSL = SINGLE_SIMD_LEVEL,
121
- class ResultHandler,
122
- class Scaler>
123
- void accumulate_q_4step_256(
122
+ template <int QBS, SIMDLevel SL, class ResultHandler, class Scaler>
123
+ void accumulate_q_4step_for_simd(
124
124
  size_t ntotal2,
125
125
  int nsq,
126
126
  const uint8_t* codes,
@@ -135,33 +135,31 @@ void accumulate_q_4step_256(
135
135
  constexpr int SQ = Q1 + Q2 + Q3 + Q4;
136
136
 
137
137
  for_each_block<32>(ntotal2, codes, block_stride, res, [&](size_t) {
138
- FixedStorageHandler<SQ, 2, KernelSL> res2;
138
+ // Scaler as LinkageTag: see FixedStorageHandler.
139
+ FixedStorageHandler<SQ, 2, SL, Scaler> res2;
139
140
  const uint8_t* LUT = LUT0;
140
- pq4_kernel_qbs_256<Q1, KernelSL>(nsq, codes, LUT, res2, scaler);
141
+ PQ4QBSKernel<SL>::template run<Q1>(nsq, codes, LUT, res2, scaler);
141
142
  LUT += Q1 * nsq * 16;
142
143
  if (Q2 > 0) {
143
144
  res2.set_block_origin(Q1, 0);
144
- pq4_kernel_qbs_256<Q2, KernelSL>(nsq, codes, LUT, res2, scaler);
145
+ PQ4QBSKernel<SL>::template run<Q2>(nsq, codes, LUT, res2, scaler);
145
146
  LUT += Q2 * nsq * 16;
146
147
  }
147
148
  if (Q3 > 0) {
148
149
  res2.set_block_origin(Q1 + Q2, 0);
149
- pq4_kernel_qbs_256<Q3, KernelSL>(nsq, codes, LUT, res2, scaler);
150
+ PQ4QBSKernel<SL>::template run<Q3>(nsq, codes, LUT, res2, scaler);
150
151
  LUT += Q3 * nsq * 16;
151
152
  }
152
153
  if (Q4 > 0) {
153
154
  res2.set_block_origin(Q1 + Q2 + Q3, 0);
154
- pq4_kernel_qbs_256<Q4, KernelSL>(nsq, codes, LUT, res2, scaler);
155
+ PQ4QBSKernel<SL>::template run<Q4>(nsq, codes, LUT, res2, scaler);
155
156
  }
156
157
  res2.to_other_handler(res);
157
158
  });
158
159
  }
159
160
 
160
- template <
161
- SIMDLevel KernelSL = SINGLE_SIMD_LEVEL,
162
- class ResultHandler,
163
- class Scaler>
164
- void pq4_accumulate_loop_qbs_fixed_scaler_256(
161
+ template <SIMDLevel SL = SINGLE_SIMD_LEVEL, class ResultHandler, class Scaler>
162
+ void pq4_accumulate_loop_qbs_fixed_scaler_simd(
165
163
  int qbs,
166
164
  size_t ntotal2,
167
165
  int nsq,
@@ -175,38 +173,37 @@ void pq4_accumulate_loop_qbs_fixed_scaler_256(
175
173
  assert(is_aligned_pointer(LUT0));
176
174
 
177
175
  switch (qbs) {
178
- #define FAISS_QBS256_DISPATCH(QBS) \
176
+ #define FAISS_QBS_DISPATCH(QBS) \
179
177
  case QBS: \
180
- accumulate_q_4step_256<QBS, KernelSL>( \
178
+ accumulate_q_4step_for_simd<QBS, SL>( \
181
179
  ntotal2, nsq, codes, LUT0, res, scaler, block_stride); \
182
180
  return;
183
- FAISS_QBS256_DISPATCH(0x3333); // 12
184
- FAISS_QBS256_DISPATCH(0x2333); // 11
185
- FAISS_QBS256_DISPATCH(0x2233); // 10
186
- FAISS_QBS256_DISPATCH(0x333); // 9
187
- FAISS_QBS256_DISPATCH(0x2223); // 9
188
- FAISS_QBS256_DISPATCH(0x233); // 8
189
- FAISS_QBS256_DISPATCH(0x1223); // 8
190
- FAISS_QBS256_DISPATCH(0x223); // 7
191
- FAISS_QBS256_DISPATCH(0x34); // 7
192
- FAISS_QBS256_DISPATCH(0x133); // 7
193
- FAISS_QBS256_DISPATCH(0x6); // 6
194
- FAISS_QBS256_DISPATCH(0x33); // 6
195
- FAISS_QBS256_DISPATCH(0x123); // 6
196
- FAISS_QBS256_DISPATCH(0x222); // 6
197
- FAISS_QBS256_DISPATCH(0x23); // 5
198
- FAISS_QBS256_DISPATCH(0x5); // 5
199
- FAISS_QBS256_DISPATCH(0x13); // 4
200
- FAISS_QBS256_DISPATCH(0x22); // 4
201
- FAISS_QBS256_DISPATCH(0x4); // 4
202
- FAISS_QBS256_DISPATCH(0x3); // 3
203
- FAISS_QBS256_DISPATCH(0x21); // 3
204
- FAISS_QBS256_DISPATCH(0x2); // 2
205
- FAISS_QBS256_DISPATCH(0x1); // 1
206
- #undef FAISS_QBS256_DISPATCH
181
+ FAISS_QBS_DISPATCH(0x3333); // 12
182
+ FAISS_QBS_DISPATCH(0x2333); // 11
183
+ FAISS_QBS_DISPATCH(0x2233); // 10
184
+ FAISS_QBS_DISPATCH(0x333); // 9
185
+ FAISS_QBS_DISPATCH(0x2223); // 9
186
+ FAISS_QBS_DISPATCH(0x233); // 8
187
+ FAISS_QBS_DISPATCH(0x1223); // 8
188
+ FAISS_QBS_DISPATCH(0x223); // 7
189
+ FAISS_QBS_DISPATCH(0x34); // 7
190
+ FAISS_QBS_DISPATCH(0x133); // 7
191
+ FAISS_QBS_DISPATCH(0x6); // 6
192
+ FAISS_QBS_DISPATCH(0x33); // 6
193
+ FAISS_QBS_DISPATCH(0x123); // 6
194
+ FAISS_QBS_DISPATCH(0x222); // 6
195
+ FAISS_QBS_DISPATCH(0x23); // 5
196
+ FAISS_QBS_DISPATCH(0x5); // 5
197
+ FAISS_QBS_DISPATCH(0x13); // 4
198
+ FAISS_QBS_DISPATCH(0x22); // 4
199
+ FAISS_QBS_DISPATCH(0x4); // 4
200
+ FAISS_QBS_DISPATCH(0x3); // 3
201
+ FAISS_QBS_DISPATCH(0x21); // 3
202
+ FAISS_QBS_DISPATCH(0x2); // 2
203
+ FAISS_QBS_DISPATCH(0x1); // 1
204
+ #undef FAISS_QBS_DISPATCH
207
205
  }
208
206
 
209
- // Default: qbs not known at compile time
210
207
  for_each_block<32>(ntotal2, codes, block_stride, res, [&](size_t j0) {
211
208
  const uint8_t* LUT = LUT0;
212
209
  int qi = qbs;
@@ -215,16 +212,16 @@ void pq4_accumulate_loop_qbs_fixed_scaler_256(
215
212
  int nq = qi & 15;
216
213
  qi >>= 4;
217
214
  res.set_block_origin(i0, j0);
218
- #define FAISS_NQ256_DISPATCH(NQ) \
219
- case NQ: \
220
- pq4_kernel_qbs_256<NQ, KernelSL>(nsq, codes, LUT, res, scaler); \
215
+ #define FAISS_NQ_DISPATCH(NQ) \
216
+ case NQ: \
217
+ PQ4QBSKernel<SL>::template run<NQ>(nsq, codes, LUT, res, scaler); \
221
218
  break
222
219
  switch (nq) {
223
- FAISS_NQ256_DISPATCH(1);
224
- FAISS_NQ256_DISPATCH(2);
225
- FAISS_NQ256_DISPATCH(3);
226
- FAISS_NQ256_DISPATCH(4);
227
- #undef FAISS_NQ256_DISPATCH
220
+ FAISS_NQ_DISPATCH(1);
221
+ FAISS_NQ_DISPATCH(2);
222
+ FAISS_NQ_DISPATCH(3);
223
+ FAISS_NQ_DISPATCH(4);
224
+ #undef FAISS_NQ_DISPATCH
228
225
  default:
229
226
  FAISS_THROW_FMT("accumulate nq=%d not instantiated", nq);
230
227
  }