faiss 0.1.4 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (219) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +26 -1
  3. data/README.md +15 -3
  4. data/ext/faiss/ext.cpp +12 -308
  5. data/ext/faiss/extconf.rb +5 -2
  6. data/ext/faiss/index.cpp +189 -0
  7. data/ext/faiss/index_binary.cpp +75 -0
  8. data/ext/faiss/kmeans.cpp +40 -0
  9. data/ext/faiss/numo.hpp +867 -0
  10. data/ext/faiss/pca_matrix.cpp +33 -0
  11. data/ext/faiss/product_quantizer.cpp +53 -0
  12. data/ext/faiss/utils.cpp +13 -0
  13. data/ext/faiss/utils.h +5 -0
  14. data/lib/faiss.rb +0 -5
  15. data/lib/faiss/version.rb +1 -1
  16. data/vendor/faiss/faiss/AutoTune.cpp +292 -291
  17. data/vendor/faiss/faiss/AutoTune.h +55 -56
  18. data/vendor/faiss/faiss/Clustering.cpp +334 -195
  19. data/vendor/faiss/faiss/Clustering.h +88 -35
  20. data/vendor/faiss/faiss/IVFlib.cpp +171 -195
  21. data/vendor/faiss/faiss/IVFlib.h +48 -51
  22. data/vendor/faiss/faiss/Index.cpp +85 -103
  23. data/vendor/faiss/faiss/Index.h +54 -48
  24. data/vendor/faiss/faiss/Index2Layer.cpp +139 -164
  25. data/vendor/faiss/faiss/Index2Layer.h +22 -22
  26. data/vendor/faiss/faiss/IndexBinary.cpp +45 -37
  27. data/vendor/faiss/faiss/IndexBinary.h +140 -132
  28. data/vendor/faiss/faiss/IndexBinaryFlat.cpp +73 -53
  29. data/vendor/faiss/faiss/IndexBinaryFlat.h +29 -24
  30. data/vendor/faiss/faiss/IndexBinaryFromFloat.cpp +46 -43
  31. data/vendor/faiss/faiss/IndexBinaryFromFloat.h +16 -15
  32. data/vendor/faiss/faiss/IndexBinaryHNSW.cpp +215 -232
  33. data/vendor/faiss/faiss/IndexBinaryHNSW.h +25 -24
  34. data/vendor/faiss/faiss/IndexBinaryHash.cpp +182 -177
  35. data/vendor/faiss/faiss/IndexBinaryHash.h +41 -34
  36. data/vendor/faiss/faiss/IndexBinaryIVF.cpp +489 -461
  37. data/vendor/faiss/faiss/IndexBinaryIVF.h +97 -68
  38. data/vendor/faiss/faiss/IndexFlat.cpp +116 -147
  39. data/vendor/faiss/faiss/IndexFlat.h +35 -46
  40. data/vendor/faiss/faiss/IndexHNSW.cpp +372 -348
  41. data/vendor/faiss/faiss/IndexHNSW.h +57 -41
  42. data/vendor/faiss/faiss/IndexIVF.cpp +474 -454
  43. data/vendor/faiss/faiss/IndexIVF.h +146 -113
  44. data/vendor/faiss/faiss/IndexIVFFlat.cpp +248 -250
  45. data/vendor/faiss/faiss/IndexIVFFlat.h +48 -51
  46. data/vendor/faiss/faiss/IndexIVFPQ.cpp +457 -516
  47. data/vendor/faiss/faiss/IndexIVFPQ.h +74 -66
  48. data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +406 -372
  49. data/vendor/faiss/faiss/IndexIVFPQFastScan.h +82 -57
  50. data/vendor/faiss/faiss/IndexIVFPQR.cpp +104 -102
  51. data/vendor/faiss/faiss/IndexIVFPQR.h +33 -28
  52. data/vendor/faiss/faiss/IndexIVFSpectralHash.cpp +125 -133
  53. data/vendor/faiss/faiss/IndexIVFSpectralHash.h +19 -21
  54. data/vendor/faiss/faiss/IndexLSH.cpp +75 -96
  55. data/vendor/faiss/faiss/IndexLSH.h +21 -26
  56. data/vendor/faiss/faiss/IndexLattice.cpp +42 -56
  57. data/vendor/faiss/faiss/IndexLattice.h +11 -16
  58. data/vendor/faiss/faiss/IndexNNDescent.cpp +231 -0
  59. data/vendor/faiss/faiss/IndexNNDescent.h +72 -0
  60. data/vendor/faiss/faiss/IndexNSG.cpp +303 -0
  61. data/vendor/faiss/faiss/IndexNSG.h +85 -0
  62. data/vendor/faiss/faiss/IndexPQ.cpp +405 -464
  63. data/vendor/faiss/faiss/IndexPQ.h +64 -67
  64. data/vendor/faiss/faiss/IndexPQFastScan.cpp +143 -170
  65. data/vendor/faiss/faiss/IndexPQFastScan.h +46 -32
  66. data/vendor/faiss/faiss/IndexPreTransform.cpp +120 -150
  67. data/vendor/faiss/faiss/IndexPreTransform.h +33 -36
  68. data/vendor/faiss/faiss/IndexRefine.cpp +115 -131
  69. data/vendor/faiss/faiss/IndexRefine.h +22 -23
  70. data/vendor/faiss/faiss/IndexReplicas.cpp +147 -153
  71. data/vendor/faiss/faiss/IndexReplicas.h +62 -56
  72. data/vendor/faiss/faiss/IndexResidual.cpp +291 -0
  73. data/vendor/faiss/faiss/IndexResidual.h +152 -0
  74. data/vendor/faiss/faiss/IndexScalarQuantizer.cpp +120 -155
  75. data/vendor/faiss/faiss/IndexScalarQuantizer.h +41 -45
  76. data/vendor/faiss/faiss/IndexShards.cpp +256 -240
  77. data/vendor/faiss/faiss/IndexShards.h +85 -73
  78. data/vendor/faiss/faiss/MatrixStats.cpp +112 -97
  79. data/vendor/faiss/faiss/MatrixStats.h +7 -10
  80. data/vendor/faiss/faiss/MetaIndexes.cpp +135 -157
  81. data/vendor/faiss/faiss/MetaIndexes.h +40 -34
  82. data/vendor/faiss/faiss/MetricType.h +7 -7
  83. data/vendor/faiss/faiss/VectorTransform.cpp +652 -474
  84. data/vendor/faiss/faiss/VectorTransform.h +61 -89
  85. data/vendor/faiss/faiss/clone_index.cpp +77 -73
  86. data/vendor/faiss/faiss/clone_index.h +4 -9
  87. data/vendor/faiss/faiss/gpu/GpuAutoTune.cpp +33 -38
  88. data/vendor/faiss/faiss/gpu/GpuAutoTune.h +11 -9
  89. data/vendor/faiss/faiss/gpu/GpuCloner.cpp +197 -170
  90. data/vendor/faiss/faiss/gpu/GpuCloner.h +53 -35
  91. data/vendor/faiss/faiss/gpu/GpuClonerOptions.cpp +12 -14
  92. data/vendor/faiss/faiss/gpu/GpuClonerOptions.h +27 -25
  93. data/vendor/faiss/faiss/gpu/GpuDistance.h +116 -112
  94. data/vendor/faiss/faiss/gpu/GpuFaissAssert.h +1 -2
  95. data/vendor/faiss/faiss/gpu/GpuIndex.h +134 -137
  96. data/vendor/faiss/faiss/gpu/GpuIndexBinaryFlat.h +76 -73
  97. data/vendor/faiss/faiss/gpu/GpuIndexFlat.h +173 -162
  98. data/vendor/faiss/faiss/gpu/GpuIndexIVF.h +67 -64
  99. data/vendor/faiss/faiss/gpu/GpuIndexIVFFlat.h +89 -86
  100. data/vendor/faiss/faiss/gpu/GpuIndexIVFPQ.h +150 -141
  101. data/vendor/faiss/faiss/gpu/GpuIndexIVFScalarQuantizer.h +101 -103
  102. data/vendor/faiss/faiss/gpu/GpuIndicesOptions.h +17 -16
  103. data/vendor/faiss/faiss/gpu/GpuResources.cpp +116 -128
  104. data/vendor/faiss/faiss/gpu/GpuResources.h +182 -186
  105. data/vendor/faiss/faiss/gpu/StandardGpuResources.cpp +433 -422
  106. data/vendor/faiss/faiss/gpu/StandardGpuResources.h +131 -130
  107. data/vendor/faiss/faiss/gpu/impl/InterleavedCodes.cpp +468 -456
  108. data/vendor/faiss/faiss/gpu/impl/InterleavedCodes.h +25 -19
  109. data/vendor/faiss/faiss/gpu/impl/RemapIndices.cpp +22 -20
  110. data/vendor/faiss/faiss/gpu/impl/RemapIndices.h +9 -8
  111. data/vendor/faiss/faiss/gpu/perf/IndexWrapper-inl.h +39 -44
  112. data/vendor/faiss/faiss/gpu/perf/IndexWrapper.h +16 -14
  113. data/vendor/faiss/faiss/gpu/perf/PerfClustering.cpp +77 -71
  114. data/vendor/faiss/faiss/gpu/perf/PerfIVFPQAdd.cpp +109 -88
  115. data/vendor/faiss/faiss/gpu/perf/WriteIndex.cpp +75 -64
  116. data/vendor/faiss/faiss/gpu/test/TestCodePacking.cpp +230 -215
  117. data/vendor/faiss/faiss/gpu/test/TestGpuIndexBinaryFlat.cpp +80 -86
  118. data/vendor/faiss/faiss/gpu/test/TestGpuIndexFlat.cpp +284 -277
  119. data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFFlat.cpp +416 -416
  120. data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFPQ.cpp +611 -517
  121. data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFScalarQuantizer.cpp +166 -164
  122. data/vendor/faiss/faiss/gpu/test/TestGpuMemoryException.cpp +61 -53
  123. data/vendor/faiss/faiss/gpu/test/TestUtils.cpp +274 -238
  124. data/vendor/faiss/faiss/gpu/test/TestUtils.h +73 -57
  125. data/vendor/faiss/faiss/gpu/test/demo_ivfpq_indexing_gpu.cpp +47 -50
  126. data/vendor/faiss/faiss/gpu/utils/DeviceUtils.h +79 -72
  127. data/vendor/faiss/faiss/gpu/utils/StackDeviceMemory.cpp +140 -146
  128. data/vendor/faiss/faiss/gpu/utils/StackDeviceMemory.h +69 -71
  129. data/vendor/faiss/faiss/gpu/utils/StaticUtils.h +21 -16
  130. data/vendor/faiss/faiss/gpu/utils/Timer.cpp +25 -29
  131. data/vendor/faiss/faiss/gpu/utils/Timer.h +30 -29
  132. data/vendor/faiss/faiss/impl/AdditiveQuantizer.cpp +270 -0
  133. data/vendor/faiss/faiss/impl/AdditiveQuantizer.h +115 -0
  134. data/vendor/faiss/faiss/impl/AuxIndexStructures.cpp +90 -120
  135. data/vendor/faiss/faiss/impl/AuxIndexStructures.h +81 -65
  136. data/vendor/faiss/faiss/impl/FaissAssert.h +73 -58
  137. data/vendor/faiss/faiss/impl/FaissException.cpp +56 -48
  138. data/vendor/faiss/faiss/impl/FaissException.h +41 -29
  139. data/vendor/faiss/faiss/impl/HNSW.cpp +595 -611
  140. data/vendor/faiss/faiss/impl/HNSW.h +179 -200
  141. data/vendor/faiss/faiss/impl/LocalSearchQuantizer.cpp +672 -0
  142. data/vendor/faiss/faiss/impl/LocalSearchQuantizer.h +172 -0
  143. data/vendor/faiss/faiss/impl/NNDescent.cpp +487 -0
  144. data/vendor/faiss/faiss/impl/NNDescent.h +154 -0
  145. data/vendor/faiss/faiss/impl/NSG.cpp +682 -0
  146. data/vendor/faiss/faiss/impl/NSG.h +199 -0
  147. data/vendor/faiss/faiss/impl/PolysemousTraining.cpp +484 -454
  148. data/vendor/faiss/faiss/impl/PolysemousTraining.h +52 -55
  149. data/vendor/faiss/faiss/impl/ProductQuantizer-inl.h +26 -47
  150. data/vendor/faiss/faiss/impl/ProductQuantizer.cpp +469 -459
  151. data/vendor/faiss/faiss/impl/ProductQuantizer.h +76 -87
  152. data/vendor/faiss/faiss/impl/ResidualQuantizer.cpp +448 -0
  153. data/vendor/faiss/faiss/impl/ResidualQuantizer.h +130 -0
  154. data/vendor/faiss/faiss/impl/ResultHandler.h +96 -132
  155. data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +648 -701
  156. data/vendor/faiss/faiss/impl/ScalarQuantizer.h +48 -46
  157. data/vendor/faiss/faiss/impl/ThreadedIndex-inl.h +129 -131
  158. data/vendor/faiss/faiss/impl/ThreadedIndex.h +61 -55
  159. data/vendor/faiss/faiss/impl/index_read.cpp +547 -479
  160. data/vendor/faiss/faiss/impl/index_write.cpp +497 -407
  161. data/vendor/faiss/faiss/impl/io.cpp +75 -94
  162. data/vendor/faiss/faiss/impl/io.h +31 -41
  163. data/vendor/faiss/faiss/impl/io_macros.h +40 -29
  164. data/vendor/faiss/faiss/impl/lattice_Zn.cpp +137 -186
  165. data/vendor/faiss/faiss/impl/lattice_Zn.h +40 -51
  166. data/vendor/faiss/faiss/impl/platform_macros.h +29 -8
  167. data/vendor/faiss/faiss/impl/pq4_fast_scan.cpp +77 -124
  168. data/vendor/faiss/faiss/impl/pq4_fast_scan.h +39 -48
  169. data/vendor/faiss/faiss/impl/pq4_fast_scan_search_1.cpp +41 -52
  170. data/vendor/faiss/faiss/impl/pq4_fast_scan_search_qbs.cpp +80 -117
  171. data/vendor/faiss/faiss/impl/simd_result_handlers.h +109 -137
  172. data/vendor/faiss/faiss/index_factory.cpp +269 -218
  173. data/vendor/faiss/faiss/index_factory.h +6 -7
  174. data/vendor/faiss/faiss/index_io.h +23 -26
  175. data/vendor/faiss/faiss/invlists/BlockInvertedLists.cpp +67 -75
  176. data/vendor/faiss/faiss/invlists/BlockInvertedLists.h +22 -24
  177. data/vendor/faiss/faiss/invlists/DirectMap.cpp +96 -112
  178. data/vendor/faiss/faiss/invlists/DirectMap.h +29 -33
  179. data/vendor/faiss/faiss/invlists/InvertedLists.cpp +307 -364
  180. data/vendor/faiss/faiss/invlists/InvertedLists.h +151 -151
  181. data/vendor/faiss/faiss/invlists/InvertedListsIOHook.cpp +29 -34
  182. data/vendor/faiss/faiss/invlists/InvertedListsIOHook.h +17 -18
  183. data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.cpp +257 -293
  184. data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.h +50 -45
  185. data/vendor/faiss/faiss/python/python_callbacks.cpp +23 -26
  186. data/vendor/faiss/faiss/python/python_callbacks.h +9 -16
  187. data/vendor/faiss/faiss/utils/AlignedTable.h +79 -44
  188. data/vendor/faiss/faiss/utils/Heap.cpp +40 -48
  189. data/vendor/faiss/faiss/utils/Heap.h +186 -209
  190. data/vendor/faiss/faiss/utils/WorkerThread.cpp +67 -76
  191. data/vendor/faiss/faiss/utils/WorkerThread.h +32 -33
  192. data/vendor/faiss/faiss/utils/distances.cpp +301 -310
  193. data/vendor/faiss/faiss/utils/distances.h +133 -118
  194. data/vendor/faiss/faiss/utils/distances_simd.cpp +456 -516
  195. data/vendor/faiss/faiss/utils/extra_distances-inl.h +117 -0
  196. data/vendor/faiss/faiss/utils/extra_distances.cpp +113 -232
  197. data/vendor/faiss/faiss/utils/extra_distances.h +30 -29
  198. data/vendor/faiss/faiss/utils/hamming-inl.h +260 -209
  199. data/vendor/faiss/faiss/utils/hamming.cpp +375 -469
  200. data/vendor/faiss/faiss/utils/hamming.h +62 -85
  201. data/vendor/faiss/faiss/utils/ordered_key_value.h +16 -18
  202. data/vendor/faiss/faiss/utils/partitioning.cpp +393 -318
  203. data/vendor/faiss/faiss/utils/partitioning.h +26 -21
  204. data/vendor/faiss/faiss/utils/quantize_lut.cpp +78 -66
  205. data/vendor/faiss/faiss/utils/quantize_lut.h +22 -20
  206. data/vendor/faiss/faiss/utils/random.cpp +39 -63
  207. data/vendor/faiss/faiss/utils/random.h +13 -16
  208. data/vendor/faiss/faiss/utils/simdlib.h +4 -2
  209. data/vendor/faiss/faiss/utils/simdlib_avx2.h +88 -85
  210. data/vendor/faiss/faiss/utils/simdlib_emulated.h +226 -165
  211. data/vendor/faiss/faiss/utils/simdlib_neon.h +832 -0
  212. data/vendor/faiss/faiss/utils/utils.cpp +304 -287
  213. data/vendor/faiss/faiss/utils/utils.h +53 -48
  214. metadata +31 -10
  215. data/lib/faiss/index.rb +0 -20
  216. data/lib/faiss/index_binary.rb +0 -20
  217. data/lib/faiss/kmeans.rb +0 -15
  218. data/lib/faiss/pca_matrix.rb +0 -15
  219. data/lib/faiss/product_quantizer.rb +0 -22
@@ -5,322 +5,526 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
-
9
8
  #include <faiss/IndexFlat.h>
10
9
  #include <faiss/IndexIVFPQ.h>
11
10
  #include <faiss/gpu/GpuIndexIVFPQ.h>
12
11
  #include <faiss/gpu/StandardGpuResources.h>
13
- #include <faiss/gpu/utils/DeviceUtils.h>
14
12
  #include <faiss/gpu/test/TestUtils.h>
15
- #include <cmath>
13
+ #include <faiss/gpu/utils/DeviceUtils.h>
16
14
  #include <gtest/gtest.h>
15
+ #include <cmath>
17
16
  #include <sstream>
18
17
  #include <vector>
19
18
 
20
-
21
19
  void pickEncoding(int& codes, int& dim) {
22
- std::vector<int> codeSizes{
23
- 3, 4, 8, 12, 16, 20, 24,
24
- 28, 32, 40, 48, 56, 64, 96
25
- };
26
-
27
- // Above 32 doesn't work with no precomputed codes
28
- std::vector<int> dimSizes{4, 8, 10, 12, 16, 20, 24, 28, 32};
29
-
30
- while (true) {
31
- codes = codeSizes[faiss::gpu::randVal(0, codeSizes.size() - 1)];
32
- dim = codes * dimSizes[faiss::gpu::randVal(0, dimSizes.size() - 1)];
33
-
34
- // for such a small test, super-low or high dim is more likely to
35
- // generate comparison errors
36
- if (dim < 256 && dim >= 64) {
37
- return;
20
+ std::vector<int> codeSizes{
21
+ 3, 4, 8, 12, 16, 20, 24, 28, 32, 40, 48, 56, 64, 96};
22
+
23
+ // Above 32 doesn't work with no precomputed codes
24
+ std::vector<int> dimSizes{4, 8, 10, 12, 16, 20, 24, 28, 32};
25
+
26
+ while (true) {
27
+ codes = codeSizes[faiss::gpu::randVal(0, codeSizes.size() - 1)];
28
+ dim = codes * dimSizes[faiss::gpu::randVal(0, dimSizes.size() - 1)];
29
+
30
+ // for such a small test, super-low or high dim is more likely to
31
+ // generate comparison errors
32
+ if (dim < 256 && dim >= 64) {
33
+ return;
34
+ }
38
35
  }
39
- }
40
36
  }
41
37
 
42
38
  struct Options {
43
- Options() {
44
- numAdd = faiss::gpu::randVal(2000, 5000);
45
- numCentroids = std::sqrt((float) numAdd);
46
- numTrain = numCentroids * 40;
47
-
48
- pickEncoding(codes, dim);
49
-
50
- // TODO: Change back to `faiss::gpu::randVal(3, 7)` when we officially
51
- // support non-multiple of 8 subcodes for IVFPQ.
52
- bitsPerCode = 8;
53
- nprobe = std::min(faiss::gpu::randVal(40, 1000), numCentroids);
54
- numQuery = faiss::gpu::randVal(4, 8);
55
-
56
- // Due to the approximate nature of the query and of floating point
57
- // differences between GPU and CPU, to stay within our error bounds, only
58
- // use a small k
59
- k = std::min(faiss::gpu::randVal(5, 20), numAdd / 40);
60
- usePrecomputed = faiss::gpu::randBool();
61
- indicesOpt = faiss::gpu::randSelect({
62
- faiss::gpu::INDICES_CPU,
63
- faiss::gpu::INDICES_32_BIT,
64
- faiss::gpu::INDICES_64_BIT});
65
- if (codes > 48) {
66
- // large codes can only fit using float16
67
- useFloat16 = true;
68
- } else {
69
- useFloat16 = faiss::gpu::randBool();
39
+ Options() {
40
+ numAdd = faiss::gpu::randVal(2000, 5000);
41
+ numCentroids = std::sqrt((float)numAdd);
42
+ numTrain = numCentroids * 40;
43
+
44
+ pickEncoding(codes, dim);
45
+
46
+ // TODO: Change back to `faiss::gpu::randVal(3, 7)` when we officially
47
+ // support non-multiple of 8 subcodes for IVFPQ.
48
+ bitsPerCode = 8;
49
+ nprobe = std::min(faiss::gpu::randVal(40, 1000), numCentroids);
50
+ numQuery = faiss::gpu::randVal(4, 8);
51
+
52
+ // Due to the approximate nature of the query and of floating point
53
+ // differences between GPU and CPU, to stay within our error bounds,
54
+ // only use a small k
55
+ k = std::min(faiss::gpu::randVal(5, 20), numAdd / 40);
56
+ usePrecomputed = faiss::gpu::randBool();
57
+ indicesOpt = faiss::gpu::randSelect(
58
+ {faiss::gpu::INDICES_CPU,
59
+ faiss::gpu::INDICES_32_BIT,
60
+ faiss::gpu::INDICES_64_BIT});
61
+ if (codes > 48) {
62
+ // large codes can only fit using float16
63
+ useFloat16 = true;
64
+ } else {
65
+ useFloat16 = faiss::gpu::randBool();
66
+ }
67
+
68
+ device = faiss::gpu::randVal(0, faiss::gpu::getNumDevices() - 1);
70
69
  }
71
70
 
72
- device = faiss::gpu::randVal(0, faiss::gpu::getNumDevices() - 1);
73
- }
74
-
75
- std::string toString() const {
76
- std::stringstream str;
77
- str << "IVFPQ device " << device
78
- << " numVecs " << numAdd
79
- << " dim " << dim
80
- << " numCentroids " << numCentroids
81
- << " codes " << codes
82
- << " bitsPerCode " << bitsPerCode
83
- << " nprobe " << nprobe
84
- << " numQuery " << numQuery
85
- << " k " << k
86
- << " usePrecomputed " << usePrecomputed
87
- << " indicesOpt " << indicesOpt
88
- << " useFloat16 " << useFloat16;
89
-
90
- return str.str();
91
- }
92
-
93
- float getCompareEpsilon() const {
94
- return 0.035f;
95
- }
96
-
97
- float getPctMaxDiff1() const {
98
- return useFloat16 ? 0.30f : 0.10f;
99
- }
100
-
101
- float getPctMaxDiffN() const {
102
- return useFloat16 ? 0.05f : 0.02f;
103
- }
104
-
105
- int numAdd;
106
- int numCentroids;
107
- int numTrain;
108
- int codes;
109
- int dim;
110
- int bitsPerCode;
111
- int nprobe;
112
- int numQuery;
113
- int k;
114
- bool usePrecomputed;
115
- faiss::gpu::IndicesOptions indicesOpt;
116
- bool useFloat16;
117
- int device;
118
- };
119
-
120
- TEST(TestGpuIndexIVFPQ, Query_L2) {
121
- for (int tries = 0; tries < 2; ++tries) {
122
- Options opt;
71
+ std::string toString() const {
72
+ std::stringstream str;
73
+ str << "IVFPQ device " << device << " numVecs " << numAdd << " dim "
74
+ << dim << " numCentroids " << numCentroids << " codes " << codes
75
+ << " bitsPerCode " << bitsPerCode << " nprobe " << nprobe
76
+ << " numQuery " << numQuery << " k " << k << " usePrecomputed "
77
+ << usePrecomputed << " indicesOpt " << indicesOpt << " useFloat16 "
78
+ << useFloat16;
123
79
 
124
- std::vector<float> trainVecs = faiss::gpu::randVecs(opt.numTrain, opt.dim);
125
- std::vector<float> addVecs = faiss::gpu::randVecs(opt.numAdd, opt.dim);
80
+ return str.str();
81
+ }
126
82
 
127
- faiss::IndexFlatL2 coarseQuantizer(opt.dim);
128
- faiss::IndexIVFPQ cpuIndex(&coarseQuantizer, opt.dim, opt.numCentroids,
129
- opt.codes, opt.bitsPerCode);
130
- cpuIndex.nprobe = opt.nprobe;
131
- cpuIndex.train(opt.numTrain, trainVecs.data());
132
- cpuIndex.add(opt.numAdd, addVecs.data());
83
+ float getCompareEpsilon() const {
84
+ return 0.035f;
85
+ }
133
86
 
134
- // Use the default temporary memory management to test the memory manager
135
- faiss::gpu::StandardGpuResources res;
87
+ float getPctMaxDiff1() const {
88
+ return useFloat16 ? 0.30f : 0.10f;
89
+ }
136
90
 
137
- faiss::gpu::GpuIndexIVFPQConfig config;
138
- config.device = opt.device;
139
- config.usePrecomputedTables = (tries % 2 == 0);
140
- config.indicesOptions = opt.indicesOpt;
141
- config.useFloat16LookupTables = opt.useFloat16;
91
+ float getPctMaxDiffN() const {
92
+ return useFloat16 ? 0.05f : 0.02f;
93
+ }
142
94
 
143
- faiss::gpu::GpuIndexIVFPQ gpuIndex(&res, &cpuIndex, config);
144
- gpuIndex.setNumProbes(opt.nprobe);
95
+ int numAdd;
96
+ int numCentroids;
97
+ int numTrain;
98
+ int codes;
99
+ int dim;
100
+ int bitsPerCode;
101
+ int nprobe;
102
+ int numQuery;
103
+ int k;
104
+ bool usePrecomputed;
105
+ faiss::gpu::IndicesOptions indicesOpt;
106
+ bool useFloat16;
107
+ int device;
108
+ };
145
109
 
146
- faiss::gpu::compareIndices(cpuIndex, gpuIndex,
147
- opt.numQuery, opt.dim, opt.k, opt.toString(),
148
- opt.getCompareEpsilon(),
149
- opt.getPctMaxDiff1(),
150
- opt.getPctMaxDiffN());
151
- }
110
+ TEST(TestGpuIndexIVFPQ, Query_L2) {
111
+ for (int tries = 0; tries < 2; ++tries) {
112
+ Options opt;
113
+
114
+ std::vector<float> trainVecs =
115
+ faiss::gpu::randVecs(opt.numTrain, opt.dim);
116
+ std::vector<float> addVecs = faiss::gpu::randVecs(opt.numAdd, opt.dim);
117
+
118
+ faiss::IndexFlatL2 coarseQuantizer(opt.dim);
119
+ faiss::IndexIVFPQ cpuIndex(
120
+ &coarseQuantizer,
121
+ opt.dim,
122
+ opt.numCentroids,
123
+ opt.codes,
124
+ opt.bitsPerCode);
125
+ cpuIndex.nprobe = opt.nprobe;
126
+ cpuIndex.train(opt.numTrain, trainVecs.data());
127
+ cpuIndex.add(opt.numAdd, addVecs.data());
128
+
129
+ // Use the default temporary memory management to test the memory
130
+ // manager
131
+ faiss::gpu::StandardGpuResources res;
132
+
133
+ faiss::gpu::GpuIndexIVFPQConfig config;
134
+ config.device = opt.device;
135
+ config.usePrecomputedTables = (tries % 2 == 0);
136
+ config.indicesOptions = opt.indicesOpt;
137
+ config.useFloat16LookupTables = opt.useFloat16;
138
+
139
+ faiss::gpu::GpuIndexIVFPQ gpuIndex(&res, &cpuIndex, config);
140
+ gpuIndex.setNumProbes(opt.nprobe);
141
+
142
+ faiss::gpu::compareIndices(
143
+ cpuIndex,
144
+ gpuIndex,
145
+ opt.numQuery,
146
+ opt.dim,
147
+ opt.k,
148
+ opt.toString(),
149
+ opt.getCompareEpsilon(),
150
+ opt.getPctMaxDiff1(),
151
+ opt.getPctMaxDiffN());
152
+ }
152
153
  }
153
154
 
154
155
  void testMMCodeDistance(faiss::MetricType mt) {
155
- // Explicitly test the code distance via batch matrix multiplication route
156
- // (even for dimension sizes that would otherwise be handled by the
157
- // specialized route (via enabling `useMMCodeDistance`)
158
- for (int tries = 0; tries < 2; ++tries) {
159
- Options opt;
160
-
161
- std::vector<float> trainVecs = faiss::gpu::randVecs(opt.numTrain, opt.dim);
162
- std::vector<float> addVecs = faiss::gpu::randVecs(opt.numAdd, opt.dim);
163
-
164
- faiss::IndexFlat coarseQuantizer(opt.dim, mt);
165
- faiss::IndexIVFPQ cpuIndex(&coarseQuantizer, opt.dim, opt.numCentroids,
166
- opt.codes, opt.bitsPerCode);
167
- cpuIndex.nprobe = opt.nprobe;
168
- cpuIndex.train(opt.numTrain, trainVecs.data());
169
- cpuIndex.add(opt.numAdd, addVecs.data());
170
-
171
- // Use the default temporary memory management to test the memory manager
172
- faiss::gpu::StandardGpuResources res;
173
-
174
- faiss::gpu::GpuIndexIVFPQConfig config;
175
- config.device = opt.device;
176
- config.usePrecomputedTables = false;
177
- config.useMMCodeDistance = true;
178
- config.indicesOptions = opt.indicesOpt;
179
-
180
- // Make sure that the float16 version works as well
181
- config.useFloat16LookupTables = (tries % 2 == 0);
182
- config.flatConfig.useFloat16 = (tries % 2 == 1);
183
-
184
- faiss::gpu::GpuIndexIVFPQ gpuIndex(&res, &cpuIndex, config);
185
- gpuIndex.setNumProbes(opt.nprobe);
186
-
187
- faiss::gpu::compareIndices(cpuIndex, gpuIndex,
188
- opt.numQuery, opt.dim, opt.k, opt.toString(),
189
- opt.getCompareEpsilon(),
190
- opt.getPctMaxDiff1(),
191
- opt.getPctMaxDiffN());
192
- }
193
-
194
- // These sizes are not specialized, they will fall back to the MM version
195
- for (int dimPerSubQ : {7, 11}) {
196
- Options opt;
197
-
198
- opt.codes = 12;
199
- opt.dim = dimPerSubQ * opt.codes;
200
-
201
- std::vector<float> trainVecs = faiss::gpu::randVecs(opt.numTrain, opt.dim);
202
- std::vector<float> addVecs = faiss::gpu::randVecs(opt.numAdd, opt.dim);
203
-
204
- faiss::IndexFlat coarseQuantizer(opt.dim, mt);
205
- faiss::IndexIVFPQ cpuIndex(&coarseQuantizer, opt.dim, opt.numCentroids,
206
- opt.codes, opt.bitsPerCode);
207
- cpuIndex.nprobe = opt.nprobe;
208
- cpuIndex.train(opt.numTrain, trainVecs.data());
209
- cpuIndex.add(opt.numAdd, addVecs.data());
210
-
211
- // Use the default temporary memory management to test the memory manager
212
- faiss::gpu::StandardGpuResources res;
213
-
214
- faiss::gpu::GpuIndexIVFPQConfig config;
215
- config.device = opt.device;
216
- config.usePrecomputedTables = false;
217
- config.indicesOptions = opt.indicesOpt;
218
-
219
- // Make sure that the float16 version works as well
220
- config.useFloat16LookupTables = (dimPerSubQ == 7);
221
-
222
- faiss::gpu::GpuIndexIVFPQ gpuIndex(&res, &cpuIndex, config);
223
- gpuIndex.setNumProbes(opt.nprobe);
156
+ // Explicitly test the code distance via batch matrix multiplication route
157
+ // (even for dimension sizes that would otherwise be handled by the
158
+ // specialized route (via enabling `useMMCodeDistance`)
159
+ for (int tries = 0; tries < 2; ++tries) {
160
+ Options opt;
161
+
162
+ std::vector<float> trainVecs =
163
+ faiss::gpu::randVecs(opt.numTrain, opt.dim);
164
+ std::vector<float> addVecs = faiss::gpu::randVecs(opt.numAdd, opt.dim);
165
+
166
+ faiss::IndexFlat coarseQuantizer(opt.dim, mt);
167
+ faiss::IndexIVFPQ cpuIndex(
168
+ &coarseQuantizer,
169
+ opt.dim,
170
+ opt.numCentroids,
171
+ opt.codes,
172
+ opt.bitsPerCode);
173
+ cpuIndex.nprobe = opt.nprobe;
174
+ cpuIndex.train(opt.numTrain, trainVecs.data());
175
+ cpuIndex.add(opt.numAdd, addVecs.data());
176
+
177
+ // Use the default temporary memory management to test the memory
178
+ // manager
179
+ faiss::gpu::StandardGpuResources res;
180
+
181
+ faiss::gpu::GpuIndexIVFPQConfig config;
182
+ config.device = opt.device;
183
+ config.usePrecomputedTables = false;
184
+ config.useMMCodeDistance = true;
185
+ config.indicesOptions = opt.indicesOpt;
186
+
187
+ // Make sure that the float16 version works as well
188
+ config.useFloat16LookupTables = (tries % 2 == 0);
189
+ config.flatConfig.useFloat16 = (tries % 2 == 1);
190
+
191
+ faiss::gpu::GpuIndexIVFPQ gpuIndex(&res, &cpuIndex, config);
192
+ gpuIndex.setNumProbes(opt.nprobe);
193
+
194
+ faiss::gpu::compareIndices(
195
+ cpuIndex,
196
+ gpuIndex,
197
+ opt.numQuery,
198
+ opt.dim,
199
+ opt.k,
200
+ opt.toString(),
201
+ opt.getCompareEpsilon(),
202
+ opt.getPctMaxDiff1(),
203
+ opt.getPctMaxDiffN());
204
+ }
224
205
 
225
- faiss::gpu::compareIndices(cpuIndex, gpuIndex,
226
- opt.numQuery, opt.dim, opt.k, opt.toString(),
227
- opt.getCompareEpsilon(),
228
- opt.getPctMaxDiff1(),
229
- opt.getPctMaxDiffN());
230
- }
206
+ // These sizes are not specialized, they will fall back to the MM version
207
+ for (int dimPerSubQ : {7, 11}) {
208
+ Options opt;
209
+
210
+ opt.codes = 12;
211
+ opt.dim = dimPerSubQ * opt.codes;
212
+
213
+ std::vector<float> trainVecs =
214
+ faiss::gpu::randVecs(opt.numTrain, opt.dim);
215
+ std::vector<float> addVecs = faiss::gpu::randVecs(opt.numAdd, opt.dim);
216
+
217
+ faiss::IndexFlat coarseQuantizer(opt.dim, mt);
218
+ faiss::IndexIVFPQ cpuIndex(
219
+ &coarseQuantizer,
220
+ opt.dim,
221
+ opt.numCentroids,
222
+ opt.codes,
223
+ opt.bitsPerCode);
224
+ cpuIndex.nprobe = opt.nprobe;
225
+ cpuIndex.train(opt.numTrain, trainVecs.data());
226
+ cpuIndex.add(opt.numAdd, addVecs.data());
227
+
228
+ // Use the default temporary memory management to test the memory
229
+ // manager
230
+ faiss::gpu::StandardGpuResources res;
231
+
232
+ faiss::gpu::GpuIndexIVFPQConfig config;
233
+ config.device = opt.device;
234
+ config.usePrecomputedTables = false;
235
+ config.indicesOptions = opt.indicesOpt;
236
+
237
+ // Make sure that the float16 version works as well
238
+ config.useFloat16LookupTables = (dimPerSubQ == 7);
239
+
240
+ faiss::gpu::GpuIndexIVFPQ gpuIndex(&res, &cpuIndex, config);
241
+ gpuIndex.setNumProbes(opt.nprobe);
242
+
243
+ faiss::gpu::compareIndices(
244
+ cpuIndex,
245
+ gpuIndex,
246
+ opt.numQuery,
247
+ opt.dim,
248
+ opt.k,
249
+ opt.toString(),
250
+ opt.getCompareEpsilon(),
251
+ opt.getPctMaxDiff1(),
252
+ opt.getPctMaxDiffN());
253
+ }
231
254
  }
232
255
 
233
256
  TEST(TestGpuIndexIVFPQ, Query_L2_MMCodeDistance) {
234
- testMMCodeDistance(faiss::MetricType::METRIC_L2);
257
+ testMMCodeDistance(faiss::MetricType::METRIC_L2);
235
258
  }
236
259
 
237
260
  TEST(TestGpuIndexIVFPQ, Query_IP_MMCodeDistance) {
238
- testMMCodeDistance(faiss::MetricType::METRIC_INNER_PRODUCT);
261
+ testMMCodeDistance(faiss::MetricType::METRIC_INNER_PRODUCT);
239
262
  }
240
263
 
241
264
  TEST(TestGpuIndexIVFPQ, Query_IP) {
242
- for (int tries = 0; tries < 2; ++tries) {
265
+ for (int tries = 0; tries < 2; ++tries) {
266
+ Options opt;
267
+
268
+ std::vector<float> trainVecs =
269
+ faiss::gpu::randVecs(opt.numTrain, opt.dim);
270
+ std::vector<float> addVecs = faiss::gpu::randVecs(opt.numAdd, opt.dim);
271
+
272
+ faiss::IndexFlatIP coarseQuantizer(opt.dim);
273
+ faiss::IndexIVFPQ cpuIndex(
274
+ &coarseQuantizer,
275
+ opt.dim,
276
+ opt.numCentroids,
277
+ opt.codes,
278
+ opt.bitsPerCode);
279
+ cpuIndex.metric_type = faiss::MetricType::METRIC_INNER_PRODUCT;
280
+
281
+ cpuIndex.nprobe = opt.nprobe;
282
+ cpuIndex.train(opt.numTrain, trainVecs.data());
283
+ cpuIndex.add(opt.numAdd, addVecs.data());
284
+
285
+ // Use the default temporary memory management to test the memory
286
+ // manager
287
+ faiss::gpu::StandardGpuResources res;
288
+
289
+ faiss::gpu::GpuIndexIVFPQConfig config;
290
+ config.device = opt.device;
291
+ config.usePrecomputedTables = false; // not supported/required for IP
292
+ config.indicesOptions = opt.indicesOpt;
293
+ config.useFloat16LookupTables = opt.useFloat16;
294
+
295
+ faiss::gpu::GpuIndexIVFPQ gpuIndex(&res, &cpuIndex, config);
296
+ gpuIndex.setNumProbes(opt.nprobe);
297
+
298
+ faiss::gpu::compareIndices(
299
+ cpuIndex,
300
+ gpuIndex,
301
+ opt.numQuery,
302
+ opt.dim,
303
+ opt.k,
304
+ opt.toString(),
305
+ opt.getCompareEpsilon(),
306
+ opt.getPctMaxDiff1(),
307
+ opt.getPctMaxDiffN());
308
+ }
309
+ }
310
+
311
+ TEST(TestGpuIndexIVFPQ, Float16Coarse) {
243
312
  Options opt;
244
313
 
245
314
  std::vector<float> trainVecs = faiss::gpu::randVecs(opt.numTrain, opt.dim);
246
315
  std::vector<float> addVecs = faiss::gpu::randVecs(opt.numAdd, opt.dim);
247
316
 
248
- faiss::IndexFlatIP coarseQuantizer(opt.dim);
249
- faiss::IndexIVFPQ cpuIndex(&coarseQuantizer, opt.dim, opt.numCentroids,
250
- opt.codes, opt.bitsPerCode);
251
- cpuIndex.metric_type = faiss::MetricType::METRIC_INNER_PRODUCT;
252
-
317
+ faiss::IndexFlatL2 coarseQuantizer(opt.dim);
318
+ faiss::IndexIVFPQ cpuIndex(
319
+ &coarseQuantizer,
320
+ opt.dim,
321
+ opt.numCentroids,
322
+ opt.codes,
323
+ opt.bitsPerCode);
253
324
  cpuIndex.nprobe = opt.nprobe;
254
325
  cpuIndex.train(opt.numTrain, trainVecs.data());
255
- cpuIndex.add(opt.numAdd, addVecs.data());
256
326
 
257
327
  // Use the default temporary memory management to test the memory manager
258
328
  faiss::gpu::StandardGpuResources res;
259
329
 
260
330
  faiss::gpu::GpuIndexIVFPQConfig config;
261
331
  config.device = opt.device;
262
- config.usePrecomputedTables = false; // not supported/required for IP
332
+ config.flatConfig.useFloat16 = true;
333
+ config.usePrecomputedTables = opt.usePrecomputed;
263
334
  config.indicesOptions = opt.indicesOpt;
264
335
  config.useFloat16LookupTables = opt.useFloat16;
265
336
 
266
337
  faiss::gpu::GpuIndexIVFPQ gpuIndex(&res, &cpuIndex, config);
267
338
  gpuIndex.setNumProbes(opt.nprobe);
268
339
 
269
- faiss::gpu::compareIndices(cpuIndex, gpuIndex,
270
- opt.numQuery, opt.dim, opt.k, opt.toString(),
271
- opt.getCompareEpsilon(),
272
- opt.getPctMaxDiff1(),
273
- opt.getPctMaxDiffN());
274
- }
275
- }
340
+ gpuIndex.add(opt.numAdd, addVecs.data());
341
+ cpuIndex.add(opt.numAdd, addVecs.data());
276
342
 
277
- TEST(TestGpuIndexIVFPQ, Float16Coarse) {
278
- Options opt;
279
-
280
- std::vector<float> trainVecs = faiss::gpu::randVecs(opt.numTrain, opt.dim);
281
- std::vector<float> addVecs = faiss::gpu::randVecs(opt.numAdd, opt.dim);
282
-
283
- faiss::IndexFlatL2 coarseQuantizer(opt.dim);
284
- faiss::IndexIVFPQ cpuIndex(&coarseQuantizer, opt.dim, opt.numCentroids,
285
- opt.codes, opt.bitsPerCode);
286
- cpuIndex.nprobe = opt.nprobe;
287
- cpuIndex.train(opt.numTrain, trainVecs.data());
288
-
289
- // Use the default temporary memory management to test the memory manager
290
- faiss::gpu::StandardGpuResources res;
291
-
292
- faiss::gpu::GpuIndexIVFPQConfig config;
293
- config.device = opt.device;
294
- config.flatConfig.useFloat16 = true;
295
- config.usePrecomputedTables = opt.usePrecomputed;
296
- config.indicesOptions = opt.indicesOpt;
297
- config.useFloat16LookupTables = opt.useFloat16;
298
-
299
- faiss::gpu::GpuIndexIVFPQ gpuIndex(&res, &cpuIndex, config);
300
- gpuIndex.setNumProbes(opt.nprobe);
301
-
302
- gpuIndex.add(opt.numAdd, addVecs.data());
303
- cpuIndex.add(opt.numAdd, addVecs.data());
304
-
305
- faiss::gpu::compareIndices(cpuIndex, gpuIndex,
306
- opt.numQuery, opt.dim, opt.k, opt.toString(),
307
- opt.getCompareEpsilon(),
308
- opt.getPctMaxDiff1(),
309
- opt.getPctMaxDiffN());
343
+ faiss::gpu::compareIndices(
344
+ cpuIndex,
345
+ gpuIndex,
346
+ opt.numQuery,
347
+ opt.dim,
348
+ opt.k,
349
+ opt.toString(),
350
+ opt.getCompareEpsilon(),
351
+ opt.getPctMaxDiff1(),
352
+ opt.getPctMaxDiffN());
310
353
  }
311
354
 
312
355
  TEST(TestGpuIndexIVFPQ, Add_L2) {
313
- for (int tries = 0; tries < 2; ++tries) {
314
- Options opt;
356
+ for (int tries = 0; tries < 2; ++tries) {
357
+ Options opt;
358
+
359
+ std::vector<float> trainVecs =
360
+ faiss::gpu::randVecs(opt.numTrain, opt.dim);
361
+ std::vector<float> addVecs = faiss::gpu::randVecs(opt.numAdd, opt.dim);
362
+
363
+ faiss::IndexFlatL2 coarseQuantizer(opt.dim);
364
+ faiss::IndexIVFPQ cpuIndex(
365
+ &coarseQuantizer,
366
+ opt.dim,
367
+ opt.numCentroids,
368
+ opt.codes,
369
+ opt.bitsPerCode);
370
+ cpuIndex.nprobe = opt.nprobe;
371
+ cpuIndex.train(opt.numTrain, trainVecs.data());
372
+
373
+ // Use the default temporary memory management to test the memory
374
+ // manager
375
+ faiss::gpu::StandardGpuResources res;
376
+
377
+ faiss::gpu::GpuIndexIVFPQConfig config;
378
+ config.device = opt.device;
379
+ config.usePrecomputedTables = opt.usePrecomputed;
380
+ config.indicesOptions = opt.indicesOpt;
381
+ config.useFloat16LookupTables = opt.useFloat16;
382
+
383
+ faiss::gpu::GpuIndexIVFPQ gpuIndex(&res, &cpuIndex, config);
384
+ gpuIndex.setNumProbes(opt.nprobe);
385
+
386
+ gpuIndex.add(opt.numAdd, addVecs.data());
387
+ cpuIndex.add(opt.numAdd, addVecs.data());
388
+
389
+ faiss::gpu::compareIndices(
390
+ cpuIndex,
391
+ gpuIndex,
392
+ opt.numQuery,
393
+ opt.dim,
394
+ opt.k,
395
+ opt.toString(),
396
+ opt.getCompareEpsilon(),
397
+ opt.getPctMaxDiff1(),
398
+ opt.getPctMaxDiffN());
399
+ }
400
+ }
401
+
402
+ TEST(TestGpuIndexIVFPQ, Add_IP) {
403
+ for (int tries = 0; tries < 2; ++tries) {
404
+ Options opt;
405
+
406
+ std::vector<float> trainVecs =
407
+ faiss::gpu::randVecs(opt.numTrain, opt.dim);
408
+ std::vector<float> addVecs = faiss::gpu::randVecs(opt.numAdd, opt.dim);
409
+
410
+ faiss::IndexFlatIP coarseQuantizer(opt.dim);
411
+ faiss::IndexIVFPQ cpuIndex(
412
+ &coarseQuantizer,
413
+ opt.dim,
414
+ opt.numCentroids,
415
+ opt.codes,
416
+ opt.bitsPerCode);
417
+ cpuIndex.metric_type = faiss::MetricType::METRIC_INNER_PRODUCT;
418
+ cpuIndex.nprobe = opt.nprobe;
419
+ cpuIndex.train(opt.numTrain, trainVecs.data());
420
+
421
+ // Use the default temporary memory management to test the memory
422
+ // manager
423
+ faiss::gpu::StandardGpuResources res;
424
+
425
+ faiss::gpu::GpuIndexIVFPQConfig config;
426
+ config.device = opt.device;
427
+ config.usePrecomputedTables = opt.usePrecomputed;
428
+ config.indicesOptions = opt.indicesOpt;
429
+ config.useFloat16LookupTables = opt.useFloat16;
430
+
431
+ faiss::gpu::GpuIndexIVFPQ gpuIndex(&res, &cpuIndex, config);
432
+ gpuIndex.setNumProbes(opt.nprobe);
433
+
434
+ gpuIndex.add(opt.numAdd, addVecs.data());
435
+ cpuIndex.add(opt.numAdd, addVecs.data());
436
+
437
+ faiss::gpu::compareIndices(
438
+ cpuIndex,
439
+ gpuIndex,
440
+ opt.numQuery,
441
+ opt.dim,
442
+ opt.k,
443
+ opt.toString(),
444
+ opt.getCompareEpsilon(),
445
+ opt.getPctMaxDiff1(),
446
+ opt.getPctMaxDiffN());
447
+ }
448
+ }
449
+
450
+ TEST(TestGpuIndexIVFPQ, CopyTo) {
451
+ for (int tries = 0; tries < 2; ++tries) {
452
+ Options opt;
453
+ std::vector<float> trainVecs =
454
+ faiss::gpu::randVecs(opt.numTrain, opt.dim);
455
+ std::vector<float> addVecs = faiss::gpu::randVecs(opt.numAdd, opt.dim);
456
+
457
+ // Use the default temporary memory management to test the memory
458
+ // manager
459
+ faiss::gpu::StandardGpuResources res;
460
+
461
+ faiss::gpu::GpuIndexIVFPQConfig config;
462
+ config.device = opt.device;
463
+ config.usePrecomputedTables = (tries % 2 == 0);
464
+ config.indicesOptions = opt.indicesOpt;
465
+ config.useFloat16LookupTables = opt.useFloat16;
466
+
467
+ faiss::gpu::GpuIndexIVFPQ gpuIndex(
468
+ &res,
469
+ opt.dim,
470
+ opt.numCentroids,
471
+ opt.codes,
472
+ opt.bitsPerCode,
473
+ faiss::METRIC_L2,
474
+ config);
475
+ gpuIndex.setNumProbes(opt.nprobe);
476
+ gpuIndex.train(opt.numTrain, trainVecs.data());
477
+ gpuIndex.add(opt.numAdd, addVecs.data());
478
+
479
+ // Use garbage values to see if we overwrite them
480
+ faiss::IndexFlatL2 cpuQuantizer(1);
481
+ faiss::IndexIVFPQ cpuIndex(&cpuQuantizer, 1, 1, 1, 1);
482
+
483
+ gpuIndex.copyTo(&cpuIndex);
484
+
485
+ EXPECT_EQ(cpuIndex.ntotal, gpuIndex.ntotal);
486
+ EXPECT_EQ(gpuIndex.ntotal, opt.numAdd);
487
+
488
+ EXPECT_EQ(cpuIndex.d, gpuIndex.d);
489
+ EXPECT_EQ(cpuIndex.d, opt.dim);
490
+ EXPECT_EQ(cpuIndex.nlist, gpuIndex.getNumLists());
491
+ EXPECT_EQ(cpuIndex.nprobe, gpuIndex.getNumProbes());
492
+ EXPECT_EQ(cpuIndex.pq.M, gpuIndex.getNumSubQuantizers());
493
+ EXPECT_EQ(gpuIndex.getNumSubQuantizers(), opt.codes);
494
+ EXPECT_EQ(cpuIndex.pq.nbits, gpuIndex.getBitsPerCode());
495
+ EXPECT_EQ(gpuIndex.getBitsPerCode(), opt.bitsPerCode);
496
+
497
+ testIVFEquality(cpuIndex, gpuIndex);
498
+
499
+ // Query both objects; results should be equivalent
500
+ faiss::gpu::compareIndices(
501
+ cpuIndex,
502
+ gpuIndex,
503
+ opt.numQuery,
504
+ opt.dim,
505
+ opt.k,
506
+ opt.toString(),
507
+ opt.getCompareEpsilon(),
508
+ opt.getPctMaxDiff1(),
509
+ opt.getPctMaxDiffN());
510
+ }
511
+ }
315
512
 
513
+ TEST(TestGpuIndexIVFPQ, CopyFrom) {
514
+ Options opt;
316
515
  std::vector<float> trainVecs = faiss::gpu::randVecs(opt.numTrain, opt.dim);
317
516
  std::vector<float> addVecs = faiss::gpu::randVecs(opt.numAdd, opt.dim);
318
517
 
319
518
  faiss::IndexFlatL2 coarseQuantizer(opt.dim);
320
- faiss::IndexIVFPQ cpuIndex(&coarseQuantizer, opt.dim, opt.numCentroids,
321
- opt.codes, opt.bitsPerCode);
519
+ faiss::IndexIVFPQ cpuIndex(
520
+ &coarseQuantizer,
521
+ opt.dim,
522
+ opt.numCentroids,
523
+ opt.codes,
524
+ opt.bitsPerCode);
322
525
  cpuIndex.nprobe = opt.nprobe;
323
526
  cpuIndex.train(opt.numTrain, trainVecs.data());
527
+ cpuIndex.add(opt.numAdd, addVecs.data());
324
528
 
325
529
  // Use the default temporary memory management to test the memory manager
326
530
  faiss::gpu::StandardGpuResources res;
@@ -331,34 +535,47 @@ TEST(TestGpuIndexIVFPQ, Add_L2) {
331
535
  config.indicesOptions = opt.indicesOpt;
332
536
  config.useFloat16LookupTables = opt.useFloat16;
333
537
 
334
- faiss::gpu::GpuIndexIVFPQ gpuIndex(&res, &cpuIndex, config);
335
- gpuIndex.setNumProbes(opt.nprobe);
538
+ // Use garbage values to see if we overwrite them
539
+ faiss::gpu::GpuIndexIVFPQ gpuIndex(
540
+ &res, 1, 1, 1, 8, faiss::METRIC_L2, config);
541
+ gpuIndex.setNumProbes(1);
336
542
 
337
- gpuIndex.add(opt.numAdd, addVecs.data());
338
- cpuIndex.add(opt.numAdd, addVecs.data());
543
+ gpuIndex.copyFrom(&cpuIndex);
544
+
545
+ // Make sure we are equivalent
546
+ EXPECT_EQ(cpuIndex.ntotal, gpuIndex.ntotal);
547
+ EXPECT_EQ(gpuIndex.ntotal, opt.numAdd);
548
+
549
+ EXPECT_EQ(cpuIndex.d, gpuIndex.d);
550
+ EXPECT_EQ(cpuIndex.d, opt.dim);
551
+ EXPECT_EQ(cpuIndex.nlist, gpuIndex.getNumLists());
552
+ EXPECT_EQ(cpuIndex.nprobe, gpuIndex.getNumProbes());
553
+ EXPECT_EQ(cpuIndex.pq.M, gpuIndex.getNumSubQuantizers());
554
+ EXPECT_EQ(gpuIndex.getNumSubQuantizers(), opt.codes);
555
+ EXPECT_EQ(cpuIndex.pq.nbits, gpuIndex.getBitsPerCode());
556
+ EXPECT_EQ(gpuIndex.getBitsPerCode(), opt.bitsPerCode);
557
+
558
+ testIVFEquality(cpuIndex, gpuIndex);
339
559
 
340
- faiss::gpu::compareIndices(cpuIndex, gpuIndex,
341
- opt.numQuery, opt.dim, opt.k, opt.toString(),
342
- opt.getCompareEpsilon(),
343
- opt.getPctMaxDiff1(),
344
- opt.getPctMaxDiffN());
345
- }
560
+ // Query both objects; results should be equivalent
561
+ faiss::gpu::compareIndices(
562
+ cpuIndex,
563
+ gpuIndex,
564
+ opt.numQuery,
565
+ opt.dim,
566
+ opt.k,
567
+ opt.toString(),
568
+ opt.getCompareEpsilon(),
569
+ opt.getPctMaxDiff1(),
570
+ opt.getPctMaxDiffN());
346
571
  }
347
572
 
348
- TEST(TestGpuIndexIVFPQ, Add_IP) {
349
- for (int tries = 0; tries < 2; ++tries) {
573
+ TEST(TestGpuIndexIVFPQ, QueryNaN) {
350
574
  Options opt;
351
575
 
352
576
  std::vector<float> trainVecs = faiss::gpu::randVecs(opt.numTrain, opt.dim);
353
577
  std::vector<float> addVecs = faiss::gpu::randVecs(opt.numAdd, opt.dim);
354
578
 
355
- faiss::IndexFlatIP coarseQuantizer(opt.dim);
356
- faiss::IndexIVFPQ cpuIndex(&coarseQuantizer, opt.dim, opt.numCentroids,
357
- opt.codes, opt.bitsPerCode);
358
- cpuIndex.metric_type = faiss::MetricType::METRIC_INNER_PRODUCT;
359
- cpuIndex.nprobe = opt.nprobe;
360
- cpuIndex.train(opt.numTrain, trainVecs.data());
361
-
362
579
  // Use the default temporary memory management to test the memory manager
363
580
  faiss::gpu::StandardGpuResources res;
364
581
 
@@ -368,284 +585,161 @@ TEST(TestGpuIndexIVFPQ, Add_IP) {
368
585
  config.indicesOptions = opt.indicesOpt;
369
586
  config.useFloat16LookupTables = opt.useFloat16;
370
587
 
371
- faiss::gpu::GpuIndexIVFPQ gpuIndex(&res, &cpuIndex, config);
588
+ faiss::gpu::GpuIndexIVFPQ gpuIndex(
589
+ &res,
590
+ opt.dim,
591
+ opt.numCentroids,
592
+ opt.codes,
593
+ opt.bitsPerCode,
594
+ faiss::METRIC_L2,
595
+ config);
596
+
372
597
  gpuIndex.setNumProbes(opt.nprobe);
373
598
 
599
+ gpuIndex.train(opt.numTrain, trainVecs.data());
374
600
  gpuIndex.add(opt.numAdd, addVecs.data());
375
- cpuIndex.add(opt.numAdd, addVecs.data());
376
601
 
377
- faiss::gpu::compareIndices(cpuIndex, gpuIndex,
378
- opt.numQuery, opt.dim, opt.k, opt.toString(),
379
- opt.getCompareEpsilon(),
380
- opt.getPctMaxDiff1(),
381
- opt.getPctMaxDiffN());
382
- }
602
+ int numQuery = 5;
603
+ std::vector<float> nans(
604
+ numQuery * opt.dim, std::numeric_limits<float>::quiet_NaN());
605
+
606
+ std::vector<float> distances(numQuery * opt.k, 0);
607
+ std::vector<faiss::Index::idx_t> indices(numQuery * opt.k, 0);
608
+
609
+ gpuIndex.search(
610
+ numQuery, nans.data(), opt.k, distances.data(), indices.data());
611
+
612
+ for (int q = 0; q < numQuery; ++q) {
613
+ for (int k = 0; k < opt.k; ++k) {
614
+ EXPECT_EQ(indices[q * opt.k + k], -1);
615
+ EXPECT_EQ(
616
+ distances[q * opt.k + k],
617
+ std::numeric_limits<float>::max());
618
+ }
619
+ }
383
620
  }
384
621
 
385
- TEST(TestGpuIndexIVFPQ, CopyTo) {
386
- for (int tries = 0; tries < 2; ++tries) {
622
+ TEST(TestGpuIndexIVFPQ, AddNaN) {
387
623
  Options opt;
388
- std::vector<float> trainVecs = faiss::gpu::randVecs(opt.numTrain, opt.dim);
389
- std::vector<float> addVecs = faiss::gpu::randVecs(opt.numAdd, opt.dim);
390
624
 
391
625
  // Use the default temporary memory management to test the memory manager
392
626
  faiss::gpu::StandardGpuResources res;
393
627
 
394
628
  faiss::gpu::GpuIndexIVFPQConfig config;
395
629
  config.device = opt.device;
396
- config.usePrecomputedTables = (tries % 2 == 0);
630
+ config.usePrecomputedTables = opt.usePrecomputed;
397
631
  config.indicesOptions = opt.indicesOpt;
398
632
  config.useFloat16LookupTables = opt.useFloat16;
399
633
 
400
- faiss::gpu::GpuIndexIVFPQ gpuIndex(&res,
401
- opt.dim,
402
- opt.numCentroids,
403
- opt.codes,
404
- opt.bitsPerCode,
405
- faiss::METRIC_L2,
406
- config);
634
+ faiss::gpu::GpuIndexIVFPQ gpuIndex(
635
+ &res,
636
+ opt.dim,
637
+ opt.numCentroids,
638
+ opt.codes,
639
+ opt.bitsPerCode,
640
+ faiss::METRIC_L2,
641
+ config);
642
+
407
643
  gpuIndex.setNumProbes(opt.nprobe);
644
+
645
+ int numNans = 10;
646
+ std::vector<float> nans(
647
+ numNans * opt.dim, std::numeric_limits<float>::quiet_NaN());
648
+
649
+ // Make one vector valid, which should actually add
650
+ for (int i = 0; i < opt.dim; ++i) {
651
+ nans[i] = 0.0f;
652
+ }
653
+
654
+ std::vector<float> trainVecs = faiss::gpu::randVecs(opt.numTrain, opt.dim);
408
655
  gpuIndex.train(opt.numTrain, trainVecs.data());
409
- gpuIndex.add(opt.numAdd, addVecs.data());
410
656
 
411
- // Use garbage values to see if we overwrite them
412
- faiss::IndexFlatL2 cpuQuantizer(1);
413
- faiss::IndexIVFPQ cpuIndex(&cpuQuantizer, 1, 1, 1, 1);
657
+ // should not crash
658
+ EXPECT_EQ(gpuIndex.ntotal, 0);
659
+ gpuIndex.add(numNans, nans.data());
660
+
661
+ std::vector<float> queryVecs = faiss::gpu::randVecs(opt.numQuery, opt.dim);
662
+ std::vector<float> distance(opt.numQuery * opt.k, 0);
663
+ std::vector<faiss::Index::idx_t> indices(opt.numQuery * opt.k, 0);
664
+
665
+ // should not crash
666
+ gpuIndex.search(
667
+ opt.numQuery,
668
+ queryVecs.data(),
669
+ opt.k,
670
+ distance.data(),
671
+ indices.data());
672
+ }
414
673
 
415
- gpuIndex.copyTo(&cpuIndex);
674
+ TEST(TestGpuIndexIVFPQ, UnifiedMemory) {
675
+ // Construct on a random device to test multi-device, if we have
676
+ // multiple devices
677
+ int device = faiss::gpu::randVal(0, faiss::gpu::getNumDevices() - 1);
416
678
 
417
- EXPECT_EQ(cpuIndex.ntotal, gpuIndex.ntotal);
418
- EXPECT_EQ(gpuIndex.ntotal, opt.numAdd);
679
+ if (!faiss::gpu::getFullUnifiedMemSupport(device)) {
680
+ return;
681
+ }
419
682
 
420
- EXPECT_EQ(cpuIndex.d, gpuIndex.d);
421
- EXPECT_EQ(cpuIndex.d, opt.dim);
422
- EXPECT_EQ(cpuIndex.nlist, gpuIndex.getNumLists());
423
- EXPECT_EQ(cpuIndex.nprobe, gpuIndex.getNumProbes());
424
- EXPECT_EQ(cpuIndex.pq.M, gpuIndex.getNumSubQuantizers());
425
- EXPECT_EQ(gpuIndex.getNumSubQuantizers(), opt.codes);
426
- EXPECT_EQ(cpuIndex.pq.nbits, gpuIndex.getBitsPerCode());
427
- EXPECT_EQ(gpuIndex.getBitsPerCode(), opt.bitsPerCode);
683
+ int dim = 128;
428
684
 
429
- testIVFEquality(cpuIndex, gpuIndex);
685
+ int numCentroids = 256;
686
+ // Unfortunately it would take forever to add 24 GB in IVFPQ data,
687
+ // so just perform a small test with data allocated in the unified
688
+ // memory address space
689
+ size_t numAdd = 10000;
690
+ size_t numTrain = numCentroids * 40;
691
+ int numQuery = 10;
692
+ int k = 10;
693
+ int nprobe = 8;
694
+ int codes = 8;
695
+ int bitsPerCode = 8;
430
696
 
431
- // Query both objects; results should be equivalent
432
- faiss::gpu::compareIndices(cpuIndex, gpuIndex,
433
- opt.numQuery, opt.dim, opt.k, opt.toString(),
434
- opt.getCompareEpsilon(),
435
- opt.getPctMaxDiff1(),
436
- opt.getPctMaxDiffN());
437
- }
438
- }
697
+ std::vector<float> trainVecs = faiss::gpu::randVecs(numTrain, dim);
698
+ std::vector<float> addVecs = faiss::gpu::randVecs(numAdd, dim);
439
699
 
440
- TEST(TestGpuIndexIVFPQ, CopyFrom) {
441
- Options opt;
442
- std::vector<float> trainVecs = faiss::gpu::randVecs(opt.numTrain, opt.dim);
443
- std::vector<float> addVecs = faiss::gpu::randVecs(opt.numAdd, opt.dim);
444
-
445
- faiss::IndexFlatL2 coarseQuantizer(opt.dim);
446
- faiss::IndexIVFPQ cpuIndex(&coarseQuantizer, opt.dim, opt.numCentroids,
447
- opt.codes, opt.bitsPerCode);
448
- cpuIndex.nprobe = opt.nprobe;
449
- cpuIndex.train(opt.numTrain, trainVecs.data());
450
- cpuIndex.add(opt.numAdd, addVecs.data());
451
-
452
- // Use the default temporary memory management to test the memory manager
453
- faiss::gpu::StandardGpuResources res;
454
-
455
- faiss::gpu::GpuIndexIVFPQConfig config;
456
- config.device = opt.device;
457
- config.usePrecomputedTables = opt.usePrecomputed;
458
- config.indicesOptions = opt.indicesOpt;
459
- config.useFloat16LookupTables = opt.useFloat16;
460
-
461
- // Use garbage values to see if we overwrite them
462
- faiss::gpu::GpuIndexIVFPQ
463
- gpuIndex(&res, 1, 1, 1, 8, faiss::METRIC_L2, config);
464
- gpuIndex.setNumProbes(1);
465
-
466
- gpuIndex.copyFrom(&cpuIndex);
467
-
468
- // Make sure we are equivalent
469
- EXPECT_EQ(cpuIndex.ntotal, gpuIndex.ntotal);
470
- EXPECT_EQ(gpuIndex.ntotal, opt.numAdd);
471
-
472
- EXPECT_EQ(cpuIndex.d, gpuIndex.d);
473
- EXPECT_EQ(cpuIndex.d, opt.dim);
474
- EXPECT_EQ(cpuIndex.nlist, gpuIndex.getNumLists());
475
- EXPECT_EQ(cpuIndex.nprobe, gpuIndex.getNumProbes());
476
- EXPECT_EQ(cpuIndex.pq.M, gpuIndex.getNumSubQuantizers());
477
- EXPECT_EQ(gpuIndex.getNumSubQuantizers(), opt.codes);
478
- EXPECT_EQ(cpuIndex.pq.nbits, gpuIndex.getBitsPerCode());
479
- EXPECT_EQ(gpuIndex.getBitsPerCode(), opt.bitsPerCode);
480
-
481
- testIVFEquality(cpuIndex, gpuIndex);
482
-
483
- // Query both objects; results should be equivalent
484
- faiss::gpu::compareIndices(cpuIndex, gpuIndex,
485
- opt.numQuery, opt.dim, opt.k, opt.toString(),
486
- opt.getCompareEpsilon(),
487
- opt.getPctMaxDiff1(),
488
- opt.getPctMaxDiffN());
489
- }
700
+ faiss::IndexFlatL2 quantizer(dim);
701
+ faiss::IndexIVFPQ cpuIndex(
702
+ &quantizer, dim, numCentroids, codes, bitsPerCode);
490
703
 
491
- TEST(TestGpuIndexIVFPQ, QueryNaN) {
492
- Options opt;
493
-
494
- std::vector<float> trainVecs = faiss::gpu::randVecs(opt.numTrain, opt.dim);
495
- std::vector<float> addVecs = faiss::gpu::randVecs(opt.numAdd, opt.dim);
496
-
497
- // Use the default temporary memory management to test the memory manager
498
- faiss::gpu::StandardGpuResources res;
499
-
500
- faiss::gpu::GpuIndexIVFPQConfig config;
501
- config.device = opt.device;
502
- config.usePrecomputedTables = opt.usePrecomputed;
503
- config.indicesOptions = opt.indicesOpt;
504
- config.useFloat16LookupTables = opt.useFloat16;
505
-
506
- faiss::gpu::GpuIndexIVFPQ gpuIndex(&res,
507
- opt.dim,
508
- opt.numCentroids,
509
- opt.codes,
510
- opt.bitsPerCode,
511
- faiss::METRIC_L2,
512
- config);
513
-
514
- gpuIndex.setNumProbes(opt.nprobe);
515
-
516
- gpuIndex.train(opt.numTrain, trainVecs.data());
517
- gpuIndex.add(opt.numAdd, addVecs.data());
518
-
519
- int numQuery = 5;
520
- std::vector<float> nans(numQuery * opt.dim,
521
- std::numeric_limits<float>::quiet_NaN());
522
-
523
- std::vector<float> distances(numQuery * opt.k, 0);
524
- std::vector<faiss::Index::idx_t> indices(numQuery * opt.k, 0);
525
-
526
- gpuIndex.search(numQuery,
527
- nans.data(),
528
- opt.k,
529
- distances.data(),
530
- indices.data());
531
-
532
- for (int q = 0; q < numQuery; ++q) {
533
- for (int k = 0; k < opt.k; ++k) {
534
- EXPECT_EQ(indices[q * opt.k + k], -1);
535
- EXPECT_EQ(distances[q * opt.k + k], std::numeric_limits<float>::max());
536
- }
537
- }
538
- }
704
+ cpuIndex.train(numTrain, trainVecs.data());
705
+ cpuIndex.add(numAdd, addVecs.data());
706
+ cpuIndex.nprobe = nprobe;
539
707
 
540
- TEST(TestGpuIndexIVFPQ, AddNaN) {
541
- Options opt;
542
-
543
- // Use the default temporary memory management to test the memory manager
544
- faiss::gpu::StandardGpuResources res;
545
-
546
- faiss::gpu::GpuIndexIVFPQConfig config;
547
- config.device = opt.device;
548
- config.usePrecomputedTables = opt.usePrecomputed;
549
- config.indicesOptions = opt.indicesOpt;
550
- config.useFloat16LookupTables = opt.useFloat16;
551
-
552
- faiss::gpu::GpuIndexIVFPQ gpuIndex(&res,
553
- opt.dim,
554
- opt.numCentroids,
555
- opt.codes,
556
- opt.bitsPerCode,
557
- faiss::METRIC_L2,
558
- config);
559
-
560
- gpuIndex.setNumProbes(opt.nprobe);
561
-
562
- int numNans = 10;
563
- std::vector<float> nans(numNans * opt.dim,
564
- std::numeric_limits<float>::quiet_NaN());
565
-
566
- // Make one vector valid, which should actually add
567
- for (int i = 0; i < opt.dim; ++i) {
568
- nans[i] = 0.0f;
569
- }
570
-
571
- std::vector<float> trainVecs = faiss::gpu::randVecs(opt.numTrain, opt.dim);
572
- gpuIndex.train(opt.numTrain, trainVecs.data());
573
-
574
- // should not crash
575
- EXPECT_EQ(gpuIndex.ntotal, 0);
576
- gpuIndex.add(numNans, nans.data());
577
-
578
- std::vector<float> queryVecs = faiss::gpu::randVecs(opt.numQuery, opt.dim);
579
- std::vector<float> distance(opt.numQuery * opt.k, 0);
580
- std::vector<faiss::Index::idx_t> indices(opt.numQuery * opt.k, 0);
581
-
582
- // should not crash
583
- gpuIndex.search(opt.numQuery, queryVecs.data(), opt.k,
584
- distance.data(), indices.data());
585
- }
708
+ faiss::gpu::StandardGpuResources res;
709
+ res.noTempMemory();
586
710
 
587
- TEST(TestGpuIndexIVFPQ, UnifiedMemory) {
588
- // Construct on a random device to test multi-device, if we have
589
- // multiple devices
590
- int device = faiss::gpu::randVal(0, faiss::gpu::getNumDevices() - 1);
591
-
592
- if (!faiss::gpu::getFullUnifiedMemSupport(device)) {
593
- return;
594
- }
595
-
596
- int dim = 128;
597
-
598
- int numCentroids = 256;
599
- // Unfortunately it would take forever to add 24 GB in IVFPQ data,
600
- // so just perform a small test with data allocated in the unified
601
- // memory address space
602
- size_t numAdd = 10000;
603
- size_t numTrain = numCentroids * 40;
604
- int numQuery = 10;
605
- int k = 10;
606
- int nprobe = 8;
607
- int codes = 8;
608
- int bitsPerCode = 8;
609
-
610
- std::vector<float> trainVecs = faiss::gpu::randVecs(numTrain, dim);
611
- std::vector<float> addVecs = faiss::gpu::randVecs(numAdd, dim);
612
-
613
- faiss::IndexFlatL2 quantizer(dim);
614
- faiss::IndexIVFPQ cpuIndex(&quantizer, dim, numCentroids, codes, bitsPerCode);
615
-
616
- cpuIndex.train(numTrain, trainVecs.data());
617
- cpuIndex.add(numAdd, addVecs.data());
618
- cpuIndex.nprobe = nprobe;
619
-
620
- faiss::gpu::StandardGpuResources res;
621
- res.noTempMemory();
622
-
623
- faiss::gpu::GpuIndexIVFPQConfig config;
624
- config.device = device;
625
- config.memorySpace = faiss::gpu::MemorySpace::Unified;
626
-
627
- faiss::gpu::GpuIndexIVFPQ gpuIndex(&res,
628
- dim,
629
- numCentroids,
630
- codes,
631
- bitsPerCode,
632
- faiss::METRIC_L2,
633
- config);
634
- gpuIndex.copyFrom(&cpuIndex);
635
- gpuIndex.setNumProbes(nprobe);
636
-
637
- faiss::gpu::compareIndices(cpuIndex, gpuIndex,
638
- numQuery, dim, k, "Unified Memory",
639
- 0.015f,
640
- 0.1f,
641
- 0.015f);
711
+ faiss::gpu::GpuIndexIVFPQConfig config;
712
+ config.device = device;
713
+ config.memorySpace = faiss::gpu::MemorySpace::Unified;
714
+
715
+ faiss::gpu::GpuIndexIVFPQ gpuIndex(
716
+ &res,
717
+ dim,
718
+ numCentroids,
719
+ codes,
720
+ bitsPerCode,
721
+ faiss::METRIC_L2,
722
+ config);
723
+ gpuIndex.copyFrom(&cpuIndex);
724
+ gpuIndex.setNumProbes(nprobe);
725
+
726
+ faiss::gpu::compareIndices(
727
+ cpuIndex,
728
+ gpuIndex,
729
+ numQuery,
730
+ dim,
731
+ k,
732
+ "Unified Memory",
733
+ 0.015f,
734
+ 0.1f,
735
+ 0.015f);
642
736
  }
643
737
 
644
738
  int main(int argc, char** argv) {
645
- testing::InitGoogleTest(&argc, argv);
739
+ testing::InitGoogleTest(&argc, argv);
646
740
 
647
- // just run with a fixed test seed
648
- faiss::gpu::setTestSeed(100);
741
+ // just run with a fixed test seed
742
+ faiss::gpu::setTestSeed(100);
649
743
 
650
- return RUN_ALL_TESTS();
744
+ return RUN_ALL_TESTS();
651
745
  }