faiss 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +103 -3
- data/ext/faiss/ext.cpp +99 -32
- data/ext/faiss/extconf.rb +12 -2
- data/lib/faiss/ext.bundle +0 -0
- data/lib/faiss/index.rb +3 -3
- data/lib/faiss/index_binary.rb +3 -3
- data/lib/faiss/kmeans.rb +1 -1
- data/lib/faiss/pca_matrix.rb +2 -2
- data/lib/faiss/product_quantizer.rb +3 -3
- data/lib/faiss/version.rb +1 -1
- data/vendor/faiss/AutoTune.cpp +719 -0
- data/vendor/faiss/AutoTune.h +212 -0
- data/vendor/faiss/Clustering.cpp +261 -0
- data/vendor/faiss/Clustering.h +101 -0
- data/vendor/faiss/IVFlib.cpp +339 -0
- data/vendor/faiss/IVFlib.h +132 -0
- data/vendor/faiss/Index.cpp +171 -0
- data/vendor/faiss/Index.h +261 -0
- data/vendor/faiss/Index2Layer.cpp +437 -0
- data/vendor/faiss/Index2Layer.h +85 -0
- data/vendor/faiss/IndexBinary.cpp +77 -0
- data/vendor/faiss/IndexBinary.h +163 -0
- data/vendor/faiss/IndexBinaryFlat.cpp +83 -0
- data/vendor/faiss/IndexBinaryFlat.h +54 -0
- data/vendor/faiss/IndexBinaryFromFloat.cpp +78 -0
- data/vendor/faiss/IndexBinaryFromFloat.h +52 -0
- data/vendor/faiss/IndexBinaryHNSW.cpp +325 -0
- data/vendor/faiss/IndexBinaryHNSW.h +56 -0
- data/vendor/faiss/IndexBinaryIVF.cpp +671 -0
- data/vendor/faiss/IndexBinaryIVF.h +211 -0
- data/vendor/faiss/IndexFlat.cpp +508 -0
- data/vendor/faiss/IndexFlat.h +175 -0
- data/vendor/faiss/IndexHNSW.cpp +1090 -0
- data/vendor/faiss/IndexHNSW.h +170 -0
- data/vendor/faiss/IndexIVF.cpp +909 -0
- data/vendor/faiss/IndexIVF.h +353 -0
- data/vendor/faiss/IndexIVFFlat.cpp +502 -0
- data/vendor/faiss/IndexIVFFlat.h +118 -0
- data/vendor/faiss/IndexIVFPQ.cpp +1207 -0
- data/vendor/faiss/IndexIVFPQ.h +161 -0
- data/vendor/faiss/IndexIVFPQR.cpp +219 -0
- data/vendor/faiss/IndexIVFPQR.h +65 -0
- data/vendor/faiss/IndexIVFSpectralHash.cpp +331 -0
- data/vendor/faiss/IndexIVFSpectralHash.h +75 -0
- data/vendor/faiss/IndexLSH.cpp +225 -0
- data/vendor/faiss/IndexLSH.h +87 -0
- data/vendor/faiss/IndexLattice.cpp +143 -0
- data/vendor/faiss/IndexLattice.h +68 -0
- data/vendor/faiss/IndexPQ.cpp +1188 -0
- data/vendor/faiss/IndexPQ.h +199 -0
- data/vendor/faiss/IndexPreTransform.cpp +288 -0
- data/vendor/faiss/IndexPreTransform.h +91 -0
- data/vendor/faiss/IndexReplicas.cpp +123 -0
- data/vendor/faiss/IndexReplicas.h +76 -0
- data/vendor/faiss/IndexScalarQuantizer.cpp +317 -0
- data/vendor/faiss/IndexScalarQuantizer.h +127 -0
- data/vendor/faiss/IndexShards.cpp +317 -0
- data/vendor/faiss/IndexShards.h +100 -0
- data/vendor/faiss/InvertedLists.cpp +623 -0
- data/vendor/faiss/InvertedLists.h +334 -0
- data/vendor/faiss/LICENSE +21 -0
- data/vendor/faiss/MatrixStats.cpp +252 -0
- data/vendor/faiss/MatrixStats.h +62 -0
- data/vendor/faiss/MetaIndexes.cpp +351 -0
- data/vendor/faiss/MetaIndexes.h +126 -0
- data/vendor/faiss/OnDiskInvertedLists.cpp +674 -0
- data/vendor/faiss/OnDiskInvertedLists.h +127 -0
- data/vendor/faiss/VectorTransform.cpp +1157 -0
- data/vendor/faiss/VectorTransform.h +322 -0
- data/vendor/faiss/c_api/AutoTune_c.cpp +83 -0
- data/vendor/faiss/c_api/AutoTune_c.h +64 -0
- data/vendor/faiss/c_api/Clustering_c.cpp +139 -0
- data/vendor/faiss/c_api/Clustering_c.h +117 -0
- data/vendor/faiss/c_api/IndexFlat_c.cpp +140 -0
- data/vendor/faiss/c_api/IndexFlat_c.h +115 -0
- data/vendor/faiss/c_api/IndexIVFFlat_c.cpp +64 -0
- data/vendor/faiss/c_api/IndexIVFFlat_c.h +58 -0
- data/vendor/faiss/c_api/IndexIVF_c.cpp +92 -0
- data/vendor/faiss/c_api/IndexIVF_c.h +135 -0
- data/vendor/faiss/c_api/IndexLSH_c.cpp +37 -0
- data/vendor/faiss/c_api/IndexLSH_c.h +40 -0
- data/vendor/faiss/c_api/IndexShards_c.cpp +44 -0
- data/vendor/faiss/c_api/IndexShards_c.h +42 -0
- data/vendor/faiss/c_api/Index_c.cpp +105 -0
- data/vendor/faiss/c_api/Index_c.h +183 -0
- data/vendor/faiss/c_api/MetaIndexes_c.cpp +49 -0
- data/vendor/faiss/c_api/MetaIndexes_c.h +49 -0
- data/vendor/faiss/c_api/clone_index_c.cpp +23 -0
- data/vendor/faiss/c_api/clone_index_c.h +32 -0
- data/vendor/faiss/c_api/error_c.h +42 -0
- data/vendor/faiss/c_api/error_impl.cpp +27 -0
- data/vendor/faiss/c_api/error_impl.h +16 -0
- data/vendor/faiss/c_api/faiss_c.h +58 -0
- data/vendor/faiss/c_api/gpu/GpuAutoTune_c.cpp +96 -0
- data/vendor/faiss/c_api/gpu/GpuAutoTune_c.h +56 -0
- data/vendor/faiss/c_api/gpu/GpuClonerOptions_c.cpp +52 -0
- data/vendor/faiss/c_api/gpu/GpuClonerOptions_c.h +68 -0
- data/vendor/faiss/c_api/gpu/GpuIndex_c.cpp +17 -0
- data/vendor/faiss/c_api/gpu/GpuIndex_c.h +30 -0
- data/vendor/faiss/c_api/gpu/GpuIndicesOptions_c.h +38 -0
- data/vendor/faiss/c_api/gpu/GpuResources_c.cpp +86 -0
- data/vendor/faiss/c_api/gpu/GpuResources_c.h +66 -0
- data/vendor/faiss/c_api/gpu/StandardGpuResources_c.cpp +54 -0
- data/vendor/faiss/c_api/gpu/StandardGpuResources_c.h +53 -0
- data/vendor/faiss/c_api/gpu/macros_impl.h +42 -0
- data/vendor/faiss/c_api/impl/AuxIndexStructures_c.cpp +220 -0
- data/vendor/faiss/c_api/impl/AuxIndexStructures_c.h +149 -0
- data/vendor/faiss/c_api/index_factory_c.cpp +26 -0
- data/vendor/faiss/c_api/index_factory_c.h +30 -0
- data/vendor/faiss/c_api/index_io_c.cpp +42 -0
- data/vendor/faiss/c_api/index_io_c.h +50 -0
- data/vendor/faiss/c_api/macros_impl.h +110 -0
- data/vendor/faiss/clone_index.cpp +147 -0
- data/vendor/faiss/clone_index.h +38 -0
- data/vendor/faiss/demos/demo_imi_flat.cpp +151 -0
- data/vendor/faiss/demos/demo_imi_pq.cpp +199 -0
- data/vendor/faiss/demos/demo_ivfpq_indexing.cpp +146 -0
- data/vendor/faiss/demos/demo_sift1M.cpp +252 -0
- data/vendor/faiss/gpu/GpuAutoTune.cpp +95 -0
- data/vendor/faiss/gpu/GpuAutoTune.h +27 -0
- data/vendor/faiss/gpu/GpuCloner.cpp +403 -0
- data/vendor/faiss/gpu/GpuCloner.h +82 -0
- data/vendor/faiss/gpu/GpuClonerOptions.cpp +28 -0
- data/vendor/faiss/gpu/GpuClonerOptions.h +53 -0
- data/vendor/faiss/gpu/GpuDistance.h +52 -0
- data/vendor/faiss/gpu/GpuFaissAssert.h +29 -0
- data/vendor/faiss/gpu/GpuIndex.h +148 -0
- data/vendor/faiss/gpu/GpuIndexBinaryFlat.h +89 -0
- data/vendor/faiss/gpu/GpuIndexFlat.h +190 -0
- data/vendor/faiss/gpu/GpuIndexIVF.h +89 -0
- data/vendor/faiss/gpu/GpuIndexIVFFlat.h +85 -0
- data/vendor/faiss/gpu/GpuIndexIVFPQ.h +143 -0
- data/vendor/faiss/gpu/GpuIndexIVFScalarQuantizer.h +100 -0
- data/vendor/faiss/gpu/GpuIndicesOptions.h +30 -0
- data/vendor/faiss/gpu/GpuResources.cpp +52 -0
- data/vendor/faiss/gpu/GpuResources.h +73 -0
- data/vendor/faiss/gpu/StandardGpuResources.cpp +295 -0
- data/vendor/faiss/gpu/StandardGpuResources.h +114 -0
- data/vendor/faiss/gpu/impl/RemapIndices.cpp +43 -0
- data/vendor/faiss/gpu/impl/RemapIndices.h +24 -0
- data/vendor/faiss/gpu/perf/IndexWrapper-inl.h +71 -0
- data/vendor/faiss/gpu/perf/IndexWrapper.h +39 -0
- data/vendor/faiss/gpu/perf/PerfClustering.cpp +115 -0
- data/vendor/faiss/gpu/perf/PerfIVFPQAdd.cpp +139 -0
- data/vendor/faiss/gpu/perf/WriteIndex.cpp +102 -0
- data/vendor/faiss/gpu/test/TestGpuIndexBinaryFlat.cpp +130 -0
- data/vendor/faiss/gpu/test/TestGpuIndexFlat.cpp +371 -0
- data/vendor/faiss/gpu/test/TestGpuIndexIVFFlat.cpp +550 -0
- data/vendor/faiss/gpu/test/TestGpuIndexIVFPQ.cpp +450 -0
- data/vendor/faiss/gpu/test/TestGpuMemoryException.cpp +84 -0
- data/vendor/faiss/gpu/test/TestUtils.cpp +315 -0
- data/vendor/faiss/gpu/test/TestUtils.h +93 -0
- data/vendor/faiss/gpu/test/demo_ivfpq_indexing_gpu.cpp +159 -0
- data/vendor/faiss/gpu/utils/DeviceMemory.cpp +77 -0
- data/vendor/faiss/gpu/utils/DeviceMemory.h +71 -0
- data/vendor/faiss/gpu/utils/DeviceUtils.h +185 -0
- data/vendor/faiss/gpu/utils/MemorySpace.cpp +89 -0
- data/vendor/faiss/gpu/utils/MemorySpace.h +44 -0
- data/vendor/faiss/gpu/utils/StackDeviceMemory.cpp +239 -0
- data/vendor/faiss/gpu/utils/StackDeviceMemory.h +129 -0
- data/vendor/faiss/gpu/utils/StaticUtils.h +83 -0
- data/vendor/faiss/gpu/utils/Timer.cpp +60 -0
- data/vendor/faiss/gpu/utils/Timer.h +52 -0
- data/vendor/faiss/impl/AuxIndexStructures.cpp +305 -0
- data/vendor/faiss/impl/AuxIndexStructures.h +246 -0
- data/vendor/faiss/impl/FaissAssert.h +95 -0
- data/vendor/faiss/impl/FaissException.cpp +66 -0
- data/vendor/faiss/impl/FaissException.h +71 -0
- data/vendor/faiss/impl/HNSW.cpp +818 -0
- data/vendor/faiss/impl/HNSW.h +275 -0
- data/vendor/faiss/impl/PolysemousTraining.cpp +953 -0
- data/vendor/faiss/impl/PolysemousTraining.h +158 -0
- data/vendor/faiss/impl/ProductQuantizer.cpp +876 -0
- data/vendor/faiss/impl/ProductQuantizer.h +242 -0
- data/vendor/faiss/impl/ScalarQuantizer.cpp +1628 -0
- data/vendor/faiss/impl/ScalarQuantizer.h +120 -0
- data/vendor/faiss/impl/ThreadedIndex-inl.h +192 -0
- data/vendor/faiss/impl/ThreadedIndex.h +80 -0
- data/vendor/faiss/impl/index_read.cpp +793 -0
- data/vendor/faiss/impl/index_write.cpp +558 -0
- data/vendor/faiss/impl/io.cpp +142 -0
- data/vendor/faiss/impl/io.h +98 -0
- data/vendor/faiss/impl/lattice_Zn.cpp +712 -0
- data/vendor/faiss/impl/lattice_Zn.h +199 -0
- data/vendor/faiss/index_factory.cpp +392 -0
- data/vendor/faiss/index_factory.h +25 -0
- data/vendor/faiss/index_io.h +75 -0
- data/vendor/faiss/misc/test_blas.cpp +84 -0
- data/vendor/faiss/tests/test_binary_flat.cpp +64 -0
- data/vendor/faiss/tests/test_dealloc_invlists.cpp +183 -0
- data/vendor/faiss/tests/test_ivfpq_codec.cpp +67 -0
- data/vendor/faiss/tests/test_ivfpq_indexing.cpp +98 -0
- data/vendor/faiss/tests/test_lowlevel_ivf.cpp +566 -0
- data/vendor/faiss/tests/test_merge.cpp +258 -0
- data/vendor/faiss/tests/test_omp_threads.cpp +14 -0
- data/vendor/faiss/tests/test_ondisk_ivf.cpp +220 -0
- data/vendor/faiss/tests/test_pairs_decoding.cpp +189 -0
- data/vendor/faiss/tests/test_params_override.cpp +231 -0
- data/vendor/faiss/tests/test_pq_encoding.cpp +98 -0
- data/vendor/faiss/tests/test_sliding_ivf.cpp +240 -0
- data/vendor/faiss/tests/test_threaded_index.cpp +253 -0
- data/vendor/faiss/tests/test_transfer_invlists.cpp +159 -0
- data/vendor/faiss/tutorial/cpp/1-Flat.cpp +98 -0
- data/vendor/faiss/tutorial/cpp/2-IVFFlat.cpp +81 -0
- data/vendor/faiss/tutorial/cpp/3-IVFPQ.cpp +93 -0
- data/vendor/faiss/tutorial/cpp/4-GPU.cpp +119 -0
- data/vendor/faiss/tutorial/cpp/5-Multiple-GPUs.cpp +99 -0
- data/vendor/faiss/utils/Heap.cpp +122 -0
- data/vendor/faiss/utils/Heap.h +495 -0
- data/vendor/faiss/utils/WorkerThread.cpp +126 -0
- data/vendor/faiss/utils/WorkerThread.h +61 -0
- data/vendor/faiss/utils/distances.cpp +765 -0
- data/vendor/faiss/utils/distances.h +243 -0
- data/vendor/faiss/utils/distances_simd.cpp +809 -0
- data/vendor/faiss/utils/extra_distances.cpp +336 -0
- data/vendor/faiss/utils/extra_distances.h +54 -0
- data/vendor/faiss/utils/hamming-inl.h +472 -0
- data/vendor/faiss/utils/hamming.cpp +792 -0
- data/vendor/faiss/utils/hamming.h +220 -0
- data/vendor/faiss/utils/random.cpp +192 -0
- data/vendor/faiss/utils/random.h +60 -0
- data/vendor/faiss/utils/utils.cpp +783 -0
- data/vendor/faiss/utils/utils.h +181 -0
- metadata +216 -2
@@ -0,0 +1,32 @@
|
|
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
|
@@ -0,0 +1,42 @@
|
|
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
|
@@ -0,0 +1,27 @@
|
|
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
|
+
}
|
@@ -0,0 +1,16 @@
|
|
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;
|
@@ -0,0 +1,58 @@
|
|
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
|
@@ -0,0 +1,96 @@
|
|
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 "gpu/GpuAutoTune.h"
|
16
|
+
#include "gpu/GpuClonerOptions.h"
|
17
|
+
#include <vector>
|
18
|
+
|
19
|
+
using faiss::Index;
|
20
|
+
using faiss::gpu::GpuResources;
|
21
|
+
using faiss::gpu::GpuClonerOptions;
|
22
|
+
using faiss::gpu::GpuMultipleClonerOptions;
|
23
|
+
|
24
|
+
int faiss_index_gpu_to_cpu(const FaissIndex* gpu_index, FaissIndex** p_out) {
|
25
|
+
try {
|
26
|
+
auto cpu_index = faiss::gpu::index_gpu_to_cpu(
|
27
|
+
reinterpret_cast<const Index*>(gpu_index)
|
28
|
+
);
|
29
|
+
*p_out = reinterpret_cast<FaissIndex*>(cpu_index);
|
30
|
+
} CATCH_AND_HANDLE
|
31
|
+
}
|
32
|
+
|
33
|
+
/// converts any CPU index that can be converted to GPU
|
34
|
+
int faiss_index_cpu_to_gpu(FaissGpuResources* resources, int device, const FaissIndex *index, FaissGpuIndex** p_out) {
|
35
|
+
try {
|
36
|
+
auto res = reinterpret_cast<GpuResources*>(resources);
|
37
|
+
auto gpu_index = faiss::gpu::index_cpu_to_gpu(
|
38
|
+
res, device, reinterpret_cast<const Index*>(index)
|
39
|
+
);
|
40
|
+
*p_out = reinterpret_cast<FaissGpuIndex*>(gpu_index);
|
41
|
+
} CATCH_AND_HANDLE
|
42
|
+
}
|
43
|
+
|
44
|
+
int faiss_index_cpu_to_gpu_with_options(
|
45
|
+
FaissGpuResources* resources, int device,
|
46
|
+
const FaissIndex *index, const FaissGpuClonerOptions* options,
|
47
|
+
FaissGpuIndex** p_out)
|
48
|
+
{
|
49
|
+
try {
|
50
|
+
auto res = reinterpret_cast<GpuResources*>(resources);
|
51
|
+
auto gpu_index = faiss::gpu::index_cpu_to_gpu(
|
52
|
+
res, device, reinterpret_cast<const Index*>(index),
|
53
|
+
reinterpret_cast<const GpuClonerOptions*>(options));
|
54
|
+
*p_out = reinterpret_cast<FaissGpuIndex*>(gpu_index);
|
55
|
+
} CATCH_AND_HANDLE
|
56
|
+
}
|
57
|
+
|
58
|
+
int faiss_index_cpu_to_gpu_multiple(
|
59
|
+
FaissGpuResources* const* resources_vec,
|
60
|
+
const int* devices, size_t devices_size,
|
61
|
+
const FaissIndex* index, FaissGpuIndex** p_out)
|
62
|
+
{
|
63
|
+
try {
|
64
|
+
std::vector<GpuResources*> res(devices_size);
|
65
|
+
for (auto i = 0u; i < devices_size; ++i) {
|
66
|
+
res[i] = reinterpret_cast<GpuResources*>(resources_vec[i]);
|
67
|
+
}
|
68
|
+
|
69
|
+
std::vector<int> dev(devices, devices + devices_size);
|
70
|
+
|
71
|
+
auto gpu_index = faiss::gpu::index_cpu_to_gpu_multiple(
|
72
|
+
res, dev, reinterpret_cast<const Index*>(index));
|
73
|
+
*p_out = reinterpret_cast<FaissGpuIndex*>(gpu_index);
|
74
|
+
} CATCH_AND_HANDLE
|
75
|
+
}
|
76
|
+
|
77
|
+
int faiss_index_cpu_to_gpu_multiple_with_options(
|
78
|
+
FaissGpuResources** resources_vec, size_t resources_vec_size,
|
79
|
+
int* devices, size_t devices_size,
|
80
|
+
const FaissIndex* index, const FaissGpuMultipleClonerOptions* options,
|
81
|
+
FaissGpuIndex** p_out)
|
82
|
+
{
|
83
|
+
try {
|
84
|
+
std::vector<GpuResources*> res(resources_vec_size);
|
85
|
+
for (auto i = 0u; i < resources_vec_size; ++i) {
|
86
|
+
res[i] = reinterpret_cast<GpuResources*>(resources_vec[i]);
|
87
|
+
}
|
88
|
+
|
89
|
+
std::vector<int> dev(devices, devices + devices_size);
|
90
|
+
|
91
|
+
auto gpu_index = faiss::gpu::index_cpu_to_gpu_multiple(
|
92
|
+
res, dev, reinterpret_cast<const Index*>(index),
|
93
|
+
reinterpret_cast<const GpuMultipleClonerOptions*>(options));
|
94
|
+
*p_out = reinterpret_cast<FaissGpuIndex*>(gpu_index);
|
95
|
+
} CATCH_AND_HANDLE
|
96
|
+
}
|
@@ -0,0 +1,56 @@
|
|
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
|
@@ -0,0 +1,52 @@
|
|
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 "GpuClonerOptions_c.h"
|
12
|
+
#include "gpu/GpuClonerOptions.h"
|
13
|
+
#include "macros_impl.h"
|
14
|
+
|
15
|
+
using faiss::gpu::IndicesOptions;
|
16
|
+
using faiss::gpu::GpuClonerOptions;
|
17
|
+
using faiss::gpu::GpuMultipleClonerOptions;
|
18
|
+
|
19
|
+
int faiss_GpuClonerOptions_new(FaissGpuClonerOptions** p) {
|
20
|
+
try {
|
21
|
+
*p = reinterpret_cast<FaissGpuClonerOptions*>(new GpuClonerOptions());
|
22
|
+
} CATCH_AND_HANDLE
|
23
|
+
}
|
24
|
+
|
25
|
+
int faiss_GpuMultipleClonerOptions_new(FaissGpuMultipleClonerOptions** p) {
|
26
|
+
try {
|
27
|
+
*p = reinterpret_cast<FaissGpuMultipleClonerOptions*>(new GpuMultipleClonerOptions());
|
28
|
+
} CATCH_AND_HANDLE
|
29
|
+
}
|
30
|
+
|
31
|
+
DEFINE_DESTRUCTOR(GpuClonerOptions)
|
32
|
+
DEFINE_DESTRUCTOR(GpuMultipleClonerOptions)
|
33
|
+
|
34
|
+
DEFINE_GETTER(GpuClonerOptions, FaissIndicesOptions, indicesOptions)
|
35
|
+
DEFINE_GETTER(GpuClonerOptions, int, useFloat16CoarseQuantizer)
|
36
|
+
DEFINE_GETTER(GpuClonerOptions, int, useFloat16)
|
37
|
+
DEFINE_GETTER(GpuClonerOptions, int, usePrecomputed)
|
38
|
+
DEFINE_GETTER(GpuClonerOptions, long, reserveVecs)
|
39
|
+
DEFINE_GETTER(GpuClonerOptions, int, storeTransposed)
|
40
|
+
DEFINE_GETTER(GpuClonerOptions, int, verbose)
|
41
|
+
DEFINE_GETTER(GpuMultipleClonerOptions, int, shard)
|
42
|
+
DEFINE_GETTER(GpuMultipleClonerOptions, int, shard_type)
|
43
|
+
|
44
|
+
DEFINE_SETTER_STATIC(GpuClonerOptions, IndicesOptions, FaissIndicesOptions, indicesOptions)
|
45
|
+
DEFINE_SETTER_STATIC(GpuClonerOptions, bool, int, useFloat16CoarseQuantizer)
|
46
|
+
DEFINE_SETTER_STATIC(GpuClonerOptions, bool, int, useFloat16)
|
47
|
+
DEFINE_SETTER_STATIC(GpuClonerOptions, bool, int, usePrecomputed)
|
48
|
+
DEFINE_SETTER(GpuClonerOptions, long, reserveVecs)
|
49
|
+
DEFINE_SETTER_STATIC(GpuClonerOptions, bool, int, storeTransposed)
|
50
|
+
DEFINE_SETTER_STATIC(GpuClonerOptions, bool, int, verbose)
|
51
|
+
DEFINE_SETTER_STATIC(GpuMultipleClonerOptions, bool, int, shard)
|
52
|
+
DEFINE_SETTER(GpuMultipleClonerOptions, int, shard_type)
|
@@ -0,0 +1,68 @@
|
|
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_CLONER_OPTIONS_C_H
|
12
|
+
#define FAISS_GPU_CLONER_OPTIONS_C_H
|
13
|
+
|
14
|
+
#include "faiss_c.h"
|
15
|
+
#include "GpuIndicesOptions_c.h"
|
16
|
+
|
17
|
+
#ifdef __cplusplus
|
18
|
+
extern "C" {
|
19
|
+
#endif
|
20
|
+
|
21
|
+
FAISS_DECLARE_CLASS(GpuClonerOptions)
|
22
|
+
|
23
|
+
FAISS_DECLARE_DESTRUCTOR(GpuClonerOptions)
|
24
|
+
|
25
|
+
/// Default constructor for GpuClonerOptions
|
26
|
+
int faiss_GpuClonerOptions_new(FaissGpuClonerOptions**);
|
27
|
+
|
28
|
+
/// how should indices be stored on index types that support indices
|
29
|
+
/// (anything but GpuIndexFlat*)?
|
30
|
+
FAISS_DECLARE_GETTER_SETTER(GpuClonerOptions, FaissIndicesOptions, indicesOptions)
|
31
|
+
|
32
|
+
/// (boolean) is the coarse quantizer in float16?
|
33
|
+
FAISS_DECLARE_GETTER_SETTER(GpuClonerOptions, int, useFloat16CoarseQuantizer)
|
34
|
+
|
35
|
+
/// (boolean) for GpuIndexIVFFlat, is storage in float16?
|
36
|
+
/// for GpuIndexIVFPQ, are intermediate calculations in float16?
|
37
|
+
FAISS_DECLARE_GETTER_SETTER(GpuClonerOptions, int, useFloat16)
|
38
|
+
|
39
|
+
/// (boolean) use precomputed tables?
|
40
|
+
FAISS_DECLARE_GETTER_SETTER(GpuClonerOptions, int, usePrecomputed)
|
41
|
+
|
42
|
+
/// reserve vectors in the invfiles?
|
43
|
+
FAISS_DECLARE_GETTER_SETTER(GpuClonerOptions, long, reserveVecs)
|
44
|
+
|
45
|
+
/// (boolean) For GpuIndexFlat, store data in transposed layout?
|
46
|
+
FAISS_DECLARE_GETTER_SETTER(GpuClonerOptions, int, storeTransposed)
|
47
|
+
|
48
|
+
/// (boolean) Set verbose options on the index
|
49
|
+
FAISS_DECLARE_GETTER_SETTER(GpuClonerOptions, int, verbose)
|
50
|
+
|
51
|
+
FAISS_DECLARE_CLASS_INHERITED(GpuMultipleClonerOptions, GpuClonerOptions)
|
52
|
+
|
53
|
+
FAISS_DECLARE_DESTRUCTOR(GpuMultipleClonerOptions)
|
54
|
+
|
55
|
+
/// Default constructor for GpuMultipleClonerOptions
|
56
|
+
int faiss_GpuMultipleClonerOptions_new(FaissGpuMultipleClonerOptions**);
|
57
|
+
|
58
|
+
/// (boolean) Whether to shard the index across GPUs, versus replication
|
59
|
+
/// across GPUs
|
60
|
+
FAISS_DECLARE_GETTER_SETTER(GpuMultipleClonerOptions, int, shard)
|
61
|
+
|
62
|
+
/// IndexIVF::copy_subset_to subset type
|
63
|
+
FAISS_DECLARE_GETTER_SETTER(GpuMultipleClonerOptions, int, shard_type)
|
64
|
+
|
65
|
+
#ifdef __cplusplus
|
66
|
+
}
|
67
|
+
#endif
|
68
|
+
#endif
|