faiss 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (199) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +25 -0
  3. data/LICENSE.txt +1 -1
  4. data/README.md +16 -4
  5. data/ext/faiss/ext.cpp +12 -308
  6. data/ext/faiss/extconf.rb +6 -3
  7. data/ext/faiss/index.cpp +189 -0
  8. data/ext/faiss/index_binary.cpp +75 -0
  9. data/ext/faiss/kmeans.cpp +40 -0
  10. data/ext/faiss/numo.hpp +867 -0
  11. data/ext/faiss/pca_matrix.cpp +33 -0
  12. data/ext/faiss/product_quantizer.cpp +53 -0
  13. data/ext/faiss/utils.cpp +13 -0
  14. data/ext/faiss/utils.h +5 -0
  15. data/lib/faiss.rb +0 -5
  16. data/lib/faiss/version.rb +1 -1
  17. data/vendor/faiss/faiss/AutoTune.cpp +36 -33
  18. data/vendor/faiss/faiss/AutoTune.h +6 -3
  19. data/vendor/faiss/faiss/Clustering.cpp +16 -12
  20. data/vendor/faiss/faiss/Index.cpp +3 -4
  21. data/vendor/faiss/faiss/Index.h +3 -3
  22. data/vendor/faiss/faiss/IndexBinary.cpp +3 -4
  23. data/vendor/faiss/faiss/IndexBinary.h +1 -1
  24. data/vendor/faiss/faiss/IndexBinaryHash.cpp +2 -12
  25. data/vendor/faiss/faiss/IndexBinaryIVF.cpp +1 -2
  26. data/vendor/faiss/faiss/IndexFlat.cpp +0 -148
  27. data/vendor/faiss/faiss/IndexFlat.h +0 -51
  28. data/vendor/faiss/faiss/IndexHNSW.cpp +4 -5
  29. data/vendor/faiss/faiss/IndexIVF.cpp +118 -31
  30. data/vendor/faiss/faiss/IndexIVF.h +22 -15
  31. data/vendor/faiss/faiss/IndexIVFFlat.cpp +3 -3
  32. data/vendor/faiss/faiss/IndexIVFFlat.h +2 -1
  33. data/vendor/faiss/faiss/IndexIVFPQ.cpp +39 -15
  34. data/vendor/faiss/faiss/IndexIVFPQ.h +25 -9
  35. data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +1116 -0
  36. data/vendor/faiss/faiss/IndexIVFPQFastScan.h +166 -0
  37. data/vendor/faiss/faiss/IndexIVFPQR.cpp +8 -9
  38. data/vendor/faiss/faiss/IndexIVFPQR.h +2 -1
  39. data/vendor/faiss/faiss/IndexIVFSpectralHash.cpp +1 -2
  40. data/vendor/faiss/faiss/IndexPQ.cpp +34 -18
  41. data/vendor/faiss/faiss/IndexPQFastScan.cpp +536 -0
  42. data/vendor/faiss/faiss/IndexPQFastScan.h +111 -0
  43. data/vendor/faiss/faiss/IndexPreTransform.cpp +47 -0
  44. data/vendor/faiss/faiss/IndexPreTransform.h +2 -0
  45. data/vendor/faiss/faiss/IndexRefine.cpp +256 -0
  46. data/vendor/faiss/faiss/IndexRefine.h +73 -0
  47. data/vendor/faiss/faiss/IndexScalarQuantizer.cpp +2 -2
  48. data/vendor/faiss/faiss/IndexScalarQuantizer.h +1 -1
  49. data/vendor/faiss/faiss/gpu/GpuDistance.h +1 -1
  50. data/vendor/faiss/faiss/gpu/GpuIndex.h +16 -9
  51. data/vendor/faiss/faiss/gpu/GpuIndexBinaryFlat.h +8 -1
  52. data/vendor/faiss/faiss/gpu/GpuIndexFlat.h +11 -11
  53. data/vendor/faiss/faiss/gpu/GpuIndexIVF.h +19 -2
  54. data/vendor/faiss/faiss/gpu/GpuIndexIVFFlat.h +28 -2
  55. data/vendor/faiss/faiss/gpu/GpuIndexIVFPQ.h +24 -14
  56. data/vendor/faiss/faiss/gpu/GpuIndexIVFScalarQuantizer.h +29 -2
  57. data/vendor/faiss/faiss/gpu/GpuResources.h +4 -0
  58. data/vendor/faiss/faiss/gpu/StandardGpuResources.cpp +60 -27
  59. data/vendor/faiss/faiss/gpu/StandardGpuResources.h +28 -6
  60. data/vendor/faiss/faiss/gpu/impl/InterleavedCodes.cpp +547 -0
  61. data/vendor/faiss/faiss/gpu/impl/InterleavedCodes.h +51 -0
  62. data/vendor/faiss/faiss/gpu/impl/RemapIndices.cpp +3 -3
  63. data/vendor/faiss/faiss/gpu/impl/RemapIndices.h +3 -2
  64. data/vendor/faiss/faiss/gpu/test/TestCodePacking.cpp +274 -0
  65. data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFFlat.cpp +7 -2
  66. data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFPQ.cpp +5 -1
  67. data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFScalarQuantizer.cpp +231 -0
  68. data/vendor/faiss/faiss/gpu/test/TestUtils.h +33 -0
  69. data/vendor/faiss/faiss/gpu/utils/StackDeviceMemory.cpp +1 -0
  70. data/vendor/faiss/faiss/gpu/utils/StaticUtils.h +6 -0
  71. data/vendor/faiss/faiss/gpu/utils/Timer.cpp +5 -6
  72. data/vendor/faiss/faiss/gpu/utils/Timer.h +2 -2
  73. data/vendor/faiss/faiss/impl/AuxIndexStructures.h +5 -4
  74. data/vendor/faiss/faiss/impl/HNSW.cpp +2 -4
  75. data/vendor/faiss/faiss/impl/PolysemousTraining.h +4 -4
  76. data/vendor/faiss/faiss/impl/ProductQuantizer.cpp +22 -12
  77. data/vendor/faiss/faiss/impl/ProductQuantizer.h +2 -0
  78. data/vendor/faiss/faiss/impl/ResultHandler.h +452 -0
  79. data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +29 -19
  80. data/vendor/faiss/faiss/impl/ScalarQuantizer.h +6 -0
  81. data/vendor/faiss/faiss/impl/index_read.cpp +64 -96
  82. data/vendor/faiss/faiss/impl/index_write.cpp +34 -25
  83. data/vendor/faiss/faiss/impl/io.cpp +33 -2
  84. data/vendor/faiss/faiss/impl/io.h +7 -2
  85. data/vendor/faiss/faiss/impl/lattice_Zn.cpp +1 -15
  86. data/vendor/faiss/faiss/impl/platform_macros.h +44 -0
  87. data/vendor/faiss/faiss/impl/pq4_fast_scan.cpp +272 -0
  88. data/vendor/faiss/faiss/impl/pq4_fast_scan.h +169 -0
  89. data/vendor/faiss/faiss/impl/pq4_fast_scan_search_1.cpp +180 -0
  90. data/vendor/faiss/faiss/impl/pq4_fast_scan_search_qbs.cpp +354 -0
  91. data/vendor/faiss/faiss/impl/simd_result_handlers.h +559 -0
  92. data/vendor/faiss/faiss/index_factory.cpp +112 -7
  93. data/vendor/faiss/faiss/index_io.h +1 -48
  94. data/vendor/faiss/faiss/invlists/BlockInvertedLists.cpp +151 -0
  95. data/vendor/faiss/faiss/invlists/BlockInvertedLists.h +76 -0
  96. data/vendor/faiss/faiss/{DirectMap.cpp → invlists/DirectMap.cpp} +1 -1
  97. data/vendor/faiss/faiss/{DirectMap.h → invlists/DirectMap.h} +1 -1
  98. data/vendor/faiss/faiss/{InvertedLists.cpp → invlists/InvertedLists.cpp} +72 -1
  99. data/vendor/faiss/faiss/{InvertedLists.h → invlists/InvertedLists.h} +32 -1
  100. data/vendor/faiss/faiss/invlists/InvertedListsIOHook.cpp +107 -0
  101. data/vendor/faiss/faiss/invlists/InvertedListsIOHook.h +63 -0
  102. data/vendor/faiss/faiss/{OnDiskInvertedLists.cpp → invlists/OnDiskInvertedLists.cpp} +21 -6
  103. data/vendor/faiss/faiss/{OnDiskInvertedLists.h → invlists/OnDiskInvertedLists.h} +5 -2
  104. data/vendor/faiss/faiss/python/python_callbacks.h +8 -1
  105. data/vendor/faiss/faiss/utils/AlignedTable.h +141 -0
  106. data/vendor/faiss/faiss/utils/Heap.cpp +2 -4
  107. data/vendor/faiss/faiss/utils/Heap.h +61 -50
  108. data/vendor/faiss/faiss/utils/distances.cpp +164 -319
  109. data/vendor/faiss/faiss/utils/distances.h +28 -20
  110. data/vendor/faiss/faiss/utils/distances_simd.cpp +277 -49
  111. data/vendor/faiss/faiss/utils/extra_distances.cpp +1 -2
  112. data/vendor/faiss/faiss/utils/hamming-inl.h +4 -4
  113. data/vendor/faiss/faiss/utils/hamming.cpp +3 -6
  114. data/vendor/faiss/faiss/utils/hamming.h +2 -7
  115. data/vendor/faiss/faiss/utils/ordered_key_value.h +98 -0
  116. data/vendor/faiss/faiss/utils/partitioning.cpp +1256 -0
  117. data/vendor/faiss/faiss/utils/partitioning.h +69 -0
  118. data/vendor/faiss/faiss/utils/quantize_lut.cpp +277 -0
  119. data/vendor/faiss/faiss/utils/quantize_lut.h +80 -0
  120. data/vendor/faiss/faiss/utils/simdlib.h +31 -0
  121. data/vendor/faiss/faiss/utils/simdlib_avx2.h +461 -0
  122. data/vendor/faiss/faiss/utils/simdlib_emulated.h +589 -0
  123. metadata +54 -149
  124. data/lib/faiss/index.rb +0 -20
  125. data/lib/faiss/index_binary.rb +0 -20
  126. data/lib/faiss/kmeans.rb +0 -15
  127. data/lib/faiss/pca_matrix.rb +0 -15
  128. data/lib/faiss/product_quantizer.rb +0 -22
  129. data/vendor/faiss/benchs/bench_6bit_codec.cpp +0 -80
  130. data/vendor/faiss/c_api/AutoTune_c.cpp +0 -83
  131. data/vendor/faiss/c_api/AutoTune_c.h +0 -66
  132. data/vendor/faiss/c_api/Clustering_c.cpp +0 -145
  133. data/vendor/faiss/c_api/Clustering_c.h +0 -123
  134. data/vendor/faiss/c_api/IndexFlat_c.cpp +0 -140
  135. data/vendor/faiss/c_api/IndexFlat_c.h +0 -115
  136. data/vendor/faiss/c_api/IndexIVFFlat_c.cpp +0 -64
  137. data/vendor/faiss/c_api/IndexIVFFlat_c.h +0 -58
  138. data/vendor/faiss/c_api/IndexIVF_c.cpp +0 -99
  139. data/vendor/faiss/c_api/IndexIVF_c.h +0 -142
  140. data/vendor/faiss/c_api/IndexLSH_c.cpp +0 -37
  141. data/vendor/faiss/c_api/IndexLSH_c.h +0 -40
  142. data/vendor/faiss/c_api/IndexPreTransform_c.cpp +0 -21
  143. data/vendor/faiss/c_api/IndexPreTransform_c.h +0 -32
  144. data/vendor/faiss/c_api/IndexShards_c.cpp +0 -38
  145. data/vendor/faiss/c_api/IndexShards_c.h +0 -39
  146. data/vendor/faiss/c_api/Index_c.cpp +0 -105
  147. data/vendor/faiss/c_api/Index_c.h +0 -183
  148. data/vendor/faiss/c_api/MetaIndexes_c.cpp +0 -49
  149. data/vendor/faiss/c_api/MetaIndexes_c.h +0 -49
  150. data/vendor/faiss/c_api/clone_index_c.cpp +0 -23
  151. data/vendor/faiss/c_api/clone_index_c.h +0 -32
  152. data/vendor/faiss/c_api/error_c.h +0 -42
  153. data/vendor/faiss/c_api/error_impl.cpp +0 -27
  154. data/vendor/faiss/c_api/error_impl.h +0 -16
  155. data/vendor/faiss/c_api/faiss_c.h +0 -58
  156. data/vendor/faiss/c_api/gpu/GpuAutoTune_c.cpp +0 -98
  157. data/vendor/faiss/c_api/gpu/GpuAutoTune_c.h +0 -56
  158. data/vendor/faiss/c_api/gpu/GpuClonerOptions_c.cpp +0 -52
  159. data/vendor/faiss/c_api/gpu/GpuClonerOptions_c.h +0 -68
  160. data/vendor/faiss/c_api/gpu/GpuIndex_c.cpp +0 -17
  161. data/vendor/faiss/c_api/gpu/GpuIndex_c.h +0 -30
  162. data/vendor/faiss/c_api/gpu/GpuIndicesOptions_c.h +0 -38
  163. data/vendor/faiss/c_api/gpu/GpuResources_c.cpp +0 -86
  164. data/vendor/faiss/c_api/gpu/GpuResources_c.h +0 -66
  165. data/vendor/faiss/c_api/gpu/StandardGpuResources_c.cpp +0 -54
  166. data/vendor/faiss/c_api/gpu/StandardGpuResources_c.h +0 -53
  167. data/vendor/faiss/c_api/gpu/macros_impl.h +0 -42
  168. data/vendor/faiss/c_api/impl/AuxIndexStructures_c.cpp +0 -220
  169. data/vendor/faiss/c_api/impl/AuxIndexStructures_c.h +0 -149
  170. data/vendor/faiss/c_api/index_factory_c.cpp +0 -26
  171. data/vendor/faiss/c_api/index_factory_c.h +0 -30
  172. data/vendor/faiss/c_api/index_io_c.cpp +0 -42
  173. data/vendor/faiss/c_api/index_io_c.h +0 -50
  174. data/vendor/faiss/c_api/macros_impl.h +0 -110
  175. data/vendor/faiss/demos/demo_imi_flat.cpp +0 -154
  176. data/vendor/faiss/demos/demo_imi_pq.cpp +0 -203
  177. data/vendor/faiss/demos/demo_ivfpq_indexing.cpp +0 -151
  178. data/vendor/faiss/demos/demo_sift1M.cpp +0 -252
  179. data/vendor/faiss/demos/demo_weighted_kmeans.cpp +0 -185
  180. data/vendor/faiss/misc/test_blas.cpp +0 -87
  181. data/vendor/faiss/tests/test_binary_flat.cpp +0 -62
  182. data/vendor/faiss/tests/test_dealloc_invlists.cpp +0 -188
  183. data/vendor/faiss/tests/test_ivfpq_codec.cpp +0 -70
  184. data/vendor/faiss/tests/test_ivfpq_indexing.cpp +0 -100
  185. data/vendor/faiss/tests/test_lowlevel_ivf.cpp +0 -573
  186. data/vendor/faiss/tests/test_merge.cpp +0 -260
  187. data/vendor/faiss/tests/test_omp_threads.cpp +0 -14
  188. data/vendor/faiss/tests/test_ondisk_ivf.cpp +0 -225
  189. data/vendor/faiss/tests/test_pairs_decoding.cpp +0 -193
  190. data/vendor/faiss/tests/test_params_override.cpp +0 -236
  191. data/vendor/faiss/tests/test_pq_encoding.cpp +0 -98
  192. data/vendor/faiss/tests/test_sliding_ivf.cpp +0 -246
  193. data/vendor/faiss/tests/test_threaded_index.cpp +0 -253
  194. data/vendor/faiss/tests/test_transfer_invlists.cpp +0 -159
  195. data/vendor/faiss/tutorial/cpp/1-Flat.cpp +0 -104
  196. data/vendor/faiss/tutorial/cpp/2-IVFFlat.cpp +0 -85
  197. data/vendor/faiss/tutorial/cpp/3-IVFPQ.cpp +0 -98
  198. data/vendor/faiss/tutorial/cpp/4-GPU.cpp +0 -122
  199. data/vendor/faiss/tutorial/cpp/5-Multiple-GPUs.cpp +0 -104
@@ -1,49 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its 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
- // Copyright 2004-present Facebook. All Rights Reserved.
9
- // -*- c++ -*-
10
-
11
- #include "MetaIndexes_c.h"
12
- #include "MetaIndexes.h"
13
- #include "macros_impl.h"
14
-
15
- using faiss::Index;
16
- using faiss::IndexIDMap;
17
- using faiss::IndexIDMap2;
18
-
19
- DEFINE_GETTER(IndexIDMap, int, own_fields)
20
- DEFINE_SETTER(IndexIDMap, int, own_fields)
21
-
22
- int faiss_IndexIDMap_new(FaissIndexIDMap** p_index, FaissIndex* index) {
23
- try {
24
- auto out = new IndexIDMap(reinterpret_cast<Index*>(index));
25
- *p_index = reinterpret_cast<FaissIndexIDMap*>(out);
26
- } CATCH_AND_HANDLE
27
- }
28
-
29
- void faiss_IndexIDMap_id_map(FaissIndexIDMap* index, idx_t** p_id_map, size_t* p_size) {
30
- auto idx = reinterpret_cast<IndexIDMap*>(index);
31
- if (p_id_map)
32
- *p_id_map = idx->id_map.data();
33
- if (p_size)
34
- *p_size = idx->id_map.size();
35
- }
36
-
37
- int faiss_IndexIDMap2_new(FaissIndexIDMap2** p_index, FaissIndex* index) {
38
- try {
39
- auto out = new IndexIDMap2(reinterpret_cast<Index*>(index));
40
- *p_index = reinterpret_cast<FaissIndexIDMap2*>(out);
41
- } CATCH_AND_HANDLE
42
- }
43
-
44
- int faiss_IndexIDMap2_construct_rev_map(FaissIndexIDMap2* index) {
45
- try {
46
- reinterpret_cast<IndexIDMap2*>(index)->construct_rev_map();
47
- } CATCH_AND_HANDLE
48
- }
49
-
@@ -1,49 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its 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
- // Copyright 2004-present Facebook. All Rights Reserved.
9
- // -*- c++ -*-
10
-
11
- #ifndef METAINDEXES_C_H
12
- #define METAINDEXES_C_H
13
-
14
- #include "faiss_c.h"
15
- #include "Index_c.h"
16
-
17
- #ifdef __cplusplus
18
- extern "C" {
19
- #endif
20
-
21
- /** Index that translates search results to ids */
22
- FAISS_DECLARE_CLASS_INHERITED(IndexIDMap, Index)
23
-
24
- FAISS_DECLARE_GETTER_SETTER(IndexIDMap, int, own_fields)
25
-
26
- int faiss_IndexIDMap_new(FaissIndexIDMap** p_index, FaissIndex* index);
27
-
28
- /** get a pointer to the index map's internal ID vector (the `id_map` field). The
29
- * outputs of this function become invalid after any operation that can modify the index.
30
- *
31
- * @param index opaque pointer to index object
32
- * @param p_id_map output, the pointer to the beginning of `id_map`.
33
- * @param p_size output, the current length of `id_map`.
34
- */
35
- void faiss_IndexIDMap_id_map(FaissIndexIDMap* index, idx_t** p_id_map, size_t* p_size);
36
-
37
- /** same as IndexIDMap but also provides an efficient reconstruction
38
- implementation via a 2-way index */
39
- FAISS_DECLARE_CLASS_INHERITED(IndexIDMap2, IndexIDMap)
40
-
41
- int faiss_IndexIDMap2_new(FaissIndexIDMap2** p_index, FaissIndex* index);
42
-
43
- /// make the rev_map from scratch
44
- int faiss_IndexIDMap2_construct_rev_map(FaissIndexIDMap2* index);
45
-
46
- #ifdef __cplusplus
47
- }
48
- #endif
49
- #endif
@@ -1,23 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its 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
- // Copyright 2004-present Facebook. All Rights Reserved
9
- // -*- c++ -*-
10
- // I/O code for indexes
11
-
12
- #include "clone_index_c.h"
13
- #include "clone_index.h"
14
- #include "macros_impl.h"
15
-
16
- using faiss::Index;
17
-
18
- int faiss_clone_index (const FaissIndex *idx, FaissIndex **p_out) {
19
- try {
20
- auto out = faiss::clone_index(reinterpret_cast<const Index*>(idx));
21
- *p_out = reinterpret_cast<FaissIndex*>(out);
22
- } CATCH_AND_HANDLE
23
- }
@@ -1,32 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its 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
- // Copyright 2004-present Facebook. All Rights Reserved
9
- // -*- c++ -*-
10
- // I/O code for indexes
11
-
12
-
13
- #ifndef FAISS_CLONE_INDEX_C_H
14
- #define FAISS_CLONE_INDEX_C_H
15
-
16
- #include <stdio.h>
17
- #include "faiss_c.h"
18
- #include "Index_c.h"
19
-
20
- #ifdef __cplusplus
21
- extern "C" {
22
- #endif
23
-
24
- /* cloning functions */
25
-
26
- /** Clone an index. This is equivalent to `faiss::clone_index` */
27
- int faiss_clone_index (const FaissIndex *, FaissIndex ** p_out);
28
-
29
- #ifdef __cplusplus
30
- }
31
- #endif
32
- #endif
@@ -1,42 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its 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
- // Copyright 2004-present Facebook. All Rights Reserved.
9
- // -*- c -*-
10
-
11
- #ifndef FAISS_ERROR_C_H
12
- #define FAISS_ERROR_C_H
13
-
14
- #ifdef __cplusplus
15
- extern "C" {
16
- #endif
17
-
18
- /// An error code which depends on the exception thrown from the previous
19
- /// operation. See `faiss_get_last_error` to retrieve the error message.
20
- typedef enum FaissErrorCode {
21
- /// No error
22
- OK = 0,
23
- /// Any exception other than Faiss or standard C++ library exceptions
24
- UNKNOWN_EXCEPT = -1,
25
- /// Faiss library exception
26
- FAISS_EXCEPT = -2,
27
- /// Standard C++ library exception
28
- STD_EXCEPT = -4
29
- } FaissErrorCode;
30
-
31
- /**
32
- * Get the error message of the last failed operation performed by Faiss.
33
- * The given pointer is only invalid until another Faiss function is
34
- * called.
35
- */
36
- const char* faiss_get_last_error();
37
-
38
- #ifdef __cplusplus
39
- }
40
- #endif
41
-
42
- #endif
@@ -1,27 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its 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
- // Copyright 2004-present Facebook. All Rights Reserved.
9
- // -*- c++ -*-
10
-
11
- #include "error_c.h"
12
- #include "error_impl.h"
13
- #include "FaissException.h"
14
- #include <exception>
15
-
16
- thread_local std::exception_ptr faiss_last_exception;
17
-
18
- const char* faiss_get_last_error() {
19
- if (faiss_last_exception) {
20
- try {
21
- std::rethrow_exception(faiss_last_exception);
22
- } catch (std::exception& e) {
23
- return e.what();
24
- }
25
- }
26
- return nullptr;
27
- }
@@ -1,16 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its 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
- // Copyright 2004-present Facebook. All Rights Reserved.
9
- // -*- c++ -*-
10
-
11
- #include <exception>
12
-
13
- /** global variable for holding the last exception thrown by
14
- * calls to Faiss functions through the C API
15
- */
16
- extern thread_local std::exception_ptr faiss_last_exception;
@@ -1,58 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its 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
- // Copyright 2004-present Facebook. All Rights Reserved.
9
- // -*- c -*-
10
-
11
- /// Macros and typedefs for C wrapper API declarations
12
-
13
- #ifndef FAISS_C_H
14
- #define FAISS_C_H
15
-
16
- #include <stdint.h>
17
-
18
- typedef int64_t faiss_idx_t; ///< all indices are this type
19
- typedef faiss_idx_t idx_t;
20
- typedef float faiss_component_t; ///< all vector components are this type
21
- typedef float faiss_distance_t; ///< all distances between vectors are this type
22
-
23
- /// Declare an opaque type for a class type `clazz`.
24
- #define FAISS_DECLARE_CLASS(clazz) \
25
- typedef struct Faiss ## clazz ## _H Faiss ## clazz;
26
-
27
- /// Declare an opaque type for a class type `clazz`, while
28
- /// actually aliasing it to an existing parent class type `parent`.
29
- #define FAISS_DECLARE_CLASS_INHERITED(clazz, parent) \
30
- typedef struct Faiss ## parent ## _H Faiss ## clazz;
31
-
32
- /// Declare a dynamic downcast operation from a base `FaissIndex*` pointer
33
- /// type to a more specific index type. The function returns the same pointer
34
- /// if the downcast is valid, and `NULL` otherwise.
35
- #define FAISS_DECLARE_INDEX_DOWNCAST(clazz) \
36
- Faiss ## clazz * faiss_ ## clazz ## _cast (FaissIndex*);
37
-
38
- /// Declare a getter for the field `name` in class `clazz`,
39
- /// of return type `ty`
40
- #define FAISS_DECLARE_GETTER(clazz, ty, name) \
41
- ty faiss_ ## clazz ## _ ## name (const Faiss ## clazz *);
42
-
43
- /// Declare a setter for the field `name` in class `clazz`,
44
- /// in which the user provides a value of type `ty`
45
- #define FAISS_DECLARE_SETTER(clazz, ty, name) \
46
- void faiss_ ## clazz ## _set_ ## name (Faiss ## clazz *, ty);
47
-
48
- /// Declare a getter and setter for the field `name` in class `clazz`.
49
- #define FAISS_DECLARE_GETTER_SETTER(clazz, ty, name) \
50
- FAISS_DECLARE_GETTER(clazz, ty, name) \
51
- FAISS_DECLARE_SETTER(clazz, ty, name)
52
-
53
- /// Declare a destructor function which frees an object of
54
- /// type `clazz`.
55
- #define FAISS_DECLARE_DESTRUCTOR(clazz) \
56
- void faiss_ ## clazz ## _free (Faiss ## clazz *obj);
57
-
58
- #endif
@@ -1,98 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its 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
- // Copyright 2004-present Facebook. All Rights Reserved.
9
- // -*- c++ -*-
10
-
11
- #include "GpuAutoTune_c.h"
12
- #include "GpuClonerOptions_c.h"
13
- #include "macros_impl.h"
14
- #include "Index.h"
15
- #include <faiss/gpu/GpuCloner.h>
16
- #include <faiss/gpu/GpuResources.h>
17
- #include <faiss/gpu/GpuAutoTune.h>
18
- #include <faiss/gpu/GpuClonerOptions.h>
19
- #include <vector>
20
-
21
- using faiss::Index;
22
- using faiss::gpu::GpuResources;
23
- using faiss::gpu::GpuClonerOptions;
24
- using faiss::gpu::GpuMultipleClonerOptions;
25
-
26
- int faiss_index_gpu_to_cpu(const FaissIndex* gpu_index, FaissIndex** p_out) {
27
- try {
28
- auto cpu_index = faiss::gpu::index_gpu_to_cpu(
29
- reinterpret_cast<const Index*>(gpu_index)
30
- );
31
- *p_out = reinterpret_cast<FaissIndex*>(cpu_index);
32
- } CATCH_AND_HANDLE
33
- }
34
-
35
- /// converts any CPU index that can be converted to GPU
36
- int faiss_index_cpu_to_gpu(FaissGpuResources* resources, int device, const FaissIndex *index, FaissGpuIndex** p_out) {
37
- try {
38
- auto res = reinterpret_cast<GpuResources*>(resources);
39
- auto gpu_index = faiss::gpu::index_cpu_to_gpu(
40
- res, device, reinterpret_cast<const Index*>(index)
41
- );
42
- *p_out = reinterpret_cast<FaissGpuIndex*>(gpu_index);
43
- } CATCH_AND_HANDLE
44
- }
45
-
46
- int faiss_index_cpu_to_gpu_with_options(
47
- FaissGpuResources* resources, int device,
48
- const FaissIndex *index, const FaissGpuClonerOptions* options,
49
- FaissGpuIndex** p_out)
50
- {
51
- try {
52
- auto res = reinterpret_cast<GpuResources*>(resources);
53
- auto gpu_index = faiss::gpu::index_cpu_to_gpu(
54
- res, device, reinterpret_cast<const Index*>(index),
55
- reinterpret_cast<const GpuClonerOptions*>(options));
56
- *p_out = reinterpret_cast<FaissGpuIndex*>(gpu_index);
57
- } CATCH_AND_HANDLE
58
- }
59
-
60
- int faiss_index_cpu_to_gpu_multiple(
61
- FaissGpuResources* const* resources_vec,
62
- const int* devices, size_t devices_size,
63
- const FaissIndex* index, FaissGpuIndex** p_out)
64
- {
65
- try {
66
- std::vector<GpuResources*> res(devices_size);
67
- for (auto i = 0u; i < devices_size; ++i) {
68
- res[i] = reinterpret_cast<GpuResources*>(resources_vec[i]);
69
- }
70
-
71
- std::vector<int> dev(devices, devices + devices_size);
72
-
73
- auto gpu_index = faiss::gpu::index_cpu_to_gpu_multiple(
74
- res, dev, reinterpret_cast<const Index*>(index));
75
- *p_out = reinterpret_cast<FaissGpuIndex*>(gpu_index);
76
- } CATCH_AND_HANDLE
77
- }
78
-
79
- int faiss_index_cpu_to_gpu_multiple_with_options(
80
- FaissGpuResources** resources_vec, size_t resources_vec_size,
81
- int* devices, size_t devices_size,
82
- const FaissIndex* index, const FaissGpuMultipleClonerOptions* options,
83
- FaissGpuIndex** p_out)
84
- {
85
- try {
86
- std::vector<GpuResources*> res(resources_vec_size);
87
- for (auto i = 0u; i < resources_vec_size; ++i) {
88
- res[i] = reinterpret_cast<GpuResources*>(resources_vec[i]);
89
- }
90
-
91
- std::vector<int> dev(devices, devices + devices_size);
92
-
93
- auto gpu_index = faiss::gpu::index_cpu_to_gpu_multiple(
94
- res, dev, reinterpret_cast<const Index*>(index),
95
- reinterpret_cast<const GpuMultipleClonerOptions*>(options));
96
- *p_out = reinterpret_cast<FaissGpuIndex*>(gpu_index);
97
- } CATCH_AND_HANDLE
98
- }
@@ -1,56 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its 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
- // Copyright 2004-present Facebook. All Rights Reserved.
9
- // -*- c -*-
10
-
11
- #ifndef FAISS_GPU_AUTO_TUNE_C_H
12
- #define FAISS_GPU_AUTO_TUNE_C_H
13
-
14
- #include <stddef.h>
15
- #include "faiss_c.h"
16
- #include "GpuClonerOptions_c.h"
17
- #include "GpuResources_c.h"
18
- #include "GpuIndex_c.h"
19
- #include "Index_c.h"
20
-
21
- #ifdef __cplusplus
22
- extern "C" {
23
- #endif
24
-
25
- /// converts any GPU index inside gpu_index to a CPU index
26
- int faiss_index_gpu_to_cpu(const FaissIndex* gpu_index, FaissIndex** p_out);
27
-
28
- /// converts any CPU index that can be converted to GPU
29
- int faiss_index_cpu_to_gpu(
30
- FaissGpuResources* resources, int device,
31
- const FaissIndex *index, FaissGpuIndex** p_out);
32
-
33
- /// converts any CPU index that can be converted to GPU
34
- int faiss_index_cpu_to_gpu_with_options(
35
- FaissGpuResources* resources, int device,
36
- const FaissIndex *index, const FaissGpuClonerOptions* options,
37
- FaissGpuIndex** p_out);
38
-
39
- /// converts any CPU index that can be converted to GPU
40
- int faiss_index_cpu_to_gpu_multiple(
41
- FaissGpuResources* const* resources_vec, const int* devices, size_t devices_size,
42
- const FaissIndex* index, FaissGpuIndex** p_out);
43
-
44
- /// converts any CPU index that can be converted to GPU
45
- int faiss_index_cpu_to_gpu_multiple_with_options(
46
- FaissGpuResources* const* resources_vec, const int* devices, size_t devices_size,
47
- const FaissIndex* index, const FaissGpuMultipleClonerOptions* options,
48
- FaissGpuIndex** p_out);
49
-
50
- /// parameter space and setters for GPU indexes
51
- FAISS_DECLARE_CLASS_INHERITED(GpuParameterSpace, ParameterSpace)
52
-
53
- #ifdef __cplusplus
54
- }
55
- #endif
56
- #endif