faiss 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +25 -0
- data/LICENSE.txt +1 -1
- data/README.md +16 -4
- data/ext/faiss/ext.cpp +12 -308
- data/ext/faiss/extconf.rb +6 -3
- data/ext/faiss/index.cpp +189 -0
- data/ext/faiss/index_binary.cpp +75 -0
- data/ext/faiss/kmeans.cpp +40 -0
- data/ext/faiss/numo.hpp +867 -0
- data/ext/faiss/pca_matrix.cpp +33 -0
- data/ext/faiss/product_quantizer.cpp +53 -0
- data/ext/faiss/utils.cpp +13 -0
- data/ext/faiss/utils.h +5 -0
- data/lib/faiss.rb +0 -5
- data/lib/faiss/version.rb +1 -1
- data/vendor/faiss/faiss/AutoTune.cpp +36 -33
- data/vendor/faiss/faiss/AutoTune.h +6 -3
- data/vendor/faiss/faiss/Clustering.cpp +16 -12
- data/vendor/faiss/faiss/Index.cpp +3 -4
- data/vendor/faiss/faiss/Index.h +3 -3
- data/vendor/faiss/faiss/IndexBinary.cpp +3 -4
- data/vendor/faiss/faiss/IndexBinary.h +1 -1
- data/vendor/faiss/faiss/IndexBinaryHash.cpp +2 -12
- data/vendor/faiss/faiss/IndexBinaryIVF.cpp +1 -2
- data/vendor/faiss/faiss/IndexFlat.cpp +0 -148
- data/vendor/faiss/faiss/IndexFlat.h +0 -51
- data/vendor/faiss/faiss/IndexHNSW.cpp +4 -5
- data/vendor/faiss/faiss/IndexIVF.cpp +118 -31
- data/vendor/faiss/faiss/IndexIVF.h +22 -15
- data/vendor/faiss/faiss/IndexIVFFlat.cpp +3 -3
- data/vendor/faiss/faiss/IndexIVFFlat.h +2 -1
- data/vendor/faiss/faiss/IndexIVFPQ.cpp +39 -15
- data/vendor/faiss/faiss/IndexIVFPQ.h +25 -9
- data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +1116 -0
- data/vendor/faiss/faiss/IndexIVFPQFastScan.h +166 -0
- data/vendor/faiss/faiss/IndexIVFPQR.cpp +8 -9
- data/vendor/faiss/faiss/IndexIVFPQR.h +2 -1
- data/vendor/faiss/faiss/IndexIVFSpectralHash.cpp +1 -2
- data/vendor/faiss/faiss/IndexPQ.cpp +34 -18
- data/vendor/faiss/faiss/IndexPQFastScan.cpp +536 -0
- data/vendor/faiss/faiss/IndexPQFastScan.h +111 -0
- data/vendor/faiss/faiss/IndexPreTransform.cpp +47 -0
- data/vendor/faiss/faiss/IndexPreTransform.h +2 -0
- data/vendor/faiss/faiss/IndexRefine.cpp +256 -0
- data/vendor/faiss/faiss/IndexRefine.h +73 -0
- data/vendor/faiss/faiss/IndexScalarQuantizer.cpp +2 -2
- data/vendor/faiss/faiss/IndexScalarQuantizer.h +1 -1
- data/vendor/faiss/faiss/gpu/GpuDistance.h +1 -1
- data/vendor/faiss/faiss/gpu/GpuIndex.h +16 -9
- data/vendor/faiss/faiss/gpu/GpuIndexBinaryFlat.h +8 -1
- data/vendor/faiss/faiss/gpu/GpuIndexFlat.h +11 -11
- data/vendor/faiss/faiss/gpu/GpuIndexIVF.h +19 -2
- data/vendor/faiss/faiss/gpu/GpuIndexIVFFlat.h +28 -2
- data/vendor/faiss/faiss/gpu/GpuIndexIVFPQ.h +24 -14
- data/vendor/faiss/faiss/gpu/GpuIndexIVFScalarQuantizer.h +29 -2
- data/vendor/faiss/faiss/gpu/GpuResources.h +4 -0
- data/vendor/faiss/faiss/gpu/StandardGpuResources.cpp +60 -27
- data/vendor/faiss/faiss/gpu/StandardGpuResources.h +28 -6
- data/vendor/faiss/faiss/gpu/impl/InterleavedCodes.cpp +547 -0
- data/vendor/faiss/faiss/gpu/impl/InterleavedCodes.h +51 -0
- data/vendor/faiss/faiss/gpu/impl/RemapIndices.cpp +3 -3
- data/vendor/faiss/faiss/gpu/impl/RemapIndices.h +3 -2
- data/vendor/faiss/faiss/gpu/test/TestCodePacking.cpp +274 -0
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFFlat.cpp +7 -2
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFPQ.cpp +5 -1
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFScalarQuantizer.cpp +231 -0
- data/vendor/faiss/faiss/gpu/test/TestUtils.h +33 -0
- data/vendor/faiss/faiss/gpu/utils/StackDeviceMemory.cpp +1 -0
- data/vendor/faiss/faiss/gpu/utils/StaticUtils.h +6 -0
- data/vendor/faiss/faiss/gpu/utils/Timer.cpp +5 -6
- data/vendor/faiss/faiss/gpu/utils/Timer.h +2 -2
- data/vendor/faiss/faiss/impl/AuxIndexStructures.h +5 -4
- data/vendor/faiss/faiss/impl/HNSW.cpp +2 -4
- data/vendor/faiss/faiss/impl/PolysemousTraining.h +4 -4
- data/vendor/faiss/faiss/impl/ProductQuantizer.cpp +22 -12
- data/vendor/faiss/faiss/impl/ProductQuantizer.h +2 -0
- data/vendor/faiss/faiss/impl/ResultHandler.h +452 -0
- data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +29 -19
- data/vendor/faiss/faiss/impl/ScalarQuantizer.h +6 -0
- data/vendor/faiss/faiss/impl/index_read.cpp +64 -96
- data/vendor/faiss/faiss/impl/index_write.cpp +34 -25
- data/vendor/faiss/faiss/impl/io.cpp +33 -2
- data/vendor/faiss/faiss/impl/io.h +7 -2
- data/vendor/faiss/faiss/impl/lattice_Zn.cpp +1 -15
- data/vendor/faiss/faiss/impl/platform_macros.h +44 -0
- data/vendor/faiss/faiss/impl/pq4_fast_scan.cpp +272 -0
- data/vendor/faiss/faiss/impl/pq4_fast_scan.h +169 -0
- data/vendor/faiss/faiss/impl/pq4_fast_scan_search_1.cpp +180 -0
- data/vendor/faiss/faiss/impl/pq4_fast_scan_search_qbs.cpp +354 -0
- data/vendor/faiss/faiss/impl/simd_result_handlers.h +559 -0
- data/vendor/faiss/faiss/index_factory.cpp +112 -7
- data/vendor/faiss/faiss/index_io.h +1 -48
- data/vendor/faiss/faiss/invlists/BlockInvertedLists.cpp +151 -0
- data/vendor/faiss/faiss/invlists/BlockInvertedLists.h +76 -0
- data/vendor/faiss/faiss/{DirectMap.cpp → invlists/DirectMap.cpp} +1 -1
- data/vendor/faiss/faiss/{DirectMap.h → invlists/DirectMap.h} +1 -1
- data/vendor/faiss/faiss/{InvertedLists.cpp → invlists/InvertedLists.cpp} +72 -1
- data/vendor/faiss/faiss/{InvertedLists.h → invlists/InvertedLists.h} +32 -1
- data/vendor/faiss/faiss/invlists/InvertedListsIOHook.cpp +107 -0
- data/vendor/faiss/faiss/invlists/InvertedListsIOHook.h +63 -0
- data/vendor/faiss/faiss/{OnDiskInvertedLists.cpp → invlists/OnDiskInvertedLists.cpp} +21 -6
- data/vendor/faiss/faiss/{OnDiskInvertedLists.h → invlists/OnDiskInvertedLists.h} +5 -2
- data/vendor/faiss/faiss/python/python_callbacks.h +8 -1
- data/vendor/faiss/faiss/utils/AlignedTable.h +141 -0
- data/vendor/faiss/faiss/utils/Heap.cpp +2 -4
- data/vendor/faiss/faiss/utils/Heap.h +61 -50
- data/vendor/faiss/faiss/utils/distances.cpp +164 -319
- data/vendor/faiss/faiss/utils/distances.h +28 -20
- data/vendor/faiss/faiss/utils/distances_simd.cpp +277 -49
- data/vendor/faiss/faiss/utils/extra_distances.cpp +1 -2
- data/vendor/faiss/faiss/utils/hamming-inl.h +4 -4
- data/vendor/faiss/faiss/utils/hamming.cpp +3 -6
- data/vendor/faiss/faiss/utils/hamming.h +2 -7
- data/vendor/faiss/faiss/utils/ordered_key_value.h +98 -0
- data/vendor/faiss/faiss/utils/partitioning.cpp +1256 -0
- data/vendor/faiss/faiss/utils/partitioning.h +69 -0
- data/vendor/faiss/faiss/utils/quantize_lut.cpp +277 -0
- data/vendor/faiss/faiss/utils/quantize_lut.h +80 -0
- data/vendor/faiss/faiss/utils/simdlib.h +31 -0
- data/vendor/faiss/faiss/utils/simdlib_avx2.h +461 -0
- data/vendor/faiss/faiss/utils/simdlib_emulated.h +589 -0
- metadata +54 -149
- data/lib/faiss/index.rb +0 -20
- data/lib/faiss/index_binary.rb +0 -20
- data/lib/faiss/kmeans.rb +0 -15
- data/lib/faiss/pca_matrix.rb +0 -15
- data/lib/faiss/product_quantizer.rb +0 -22
- data/vendor/faiss/benchs/bench_6bit_codec.cpp +0 -80
- data/vendor/faiss/c_api/AutoTune_c.cpp +0 -83
- data/vendor/faiss/c_api/AutoTune_c.h +0 -66
- data/vendor/faiss/c_api/Clustering_c.cpp +0 -145
- data/vendor/faiss/c_api/Clustering_c.h +0 -123
- data/vendor/faiss/c_api/IndexFlat_c.cpp +0 -140
- data/vendor/faiss/c_api/IndexFlat_c.h +0 -115
- data/vendor/faiss/c_api/IndexIVFFlat_c.cpp +0 -64
- data/vendor/faiss/c_api/IndexIVFFlat_c.h +0 -58
- data/vendor/faiss/c_api/IndexIVF_c.cpp +0 -99
- data/vendor/faiss/c_api/IndexIVF_c.h +0 -142
- data/vendor/faiss/c_api/IndexLSH_c.cpp +0 -37
- data/vendor/faiss/c_api/IndexLSH_c.h +0 -40
- data/vendor/faiss/c_api/IndexPreTransform_c.cpp +0 -21
- data/vendor/faiss/c_api/IndexPreTransform_c.h +0 -32
- data/vendor/faiss/c_api/IndexShards_c.cpp +0 -38
- data/vendor/faiss/c_api/IndexShards_c.h +0 -39
- data/vendor/faiss/c_api/Index_c.cpp +0 -105
- data/vendor/faiss/c_api/Index_c.h +0 -183
- data/vendor/faiss/c_api/MetaIndexes_c.cpp +0 -49
- data/vendor/faiss/c_api/MetaIndexes_c.h +0 -49
- data/vendor/faiss/c_api/clone_index_c.cpp +0 -23
- data/vendor/faiss/c_api/clone_index_c.h +0 -32
- data/vendor/faiss/c_api/error_c.h +0 -42
- data/vendor/faiss/c_api/error_impl.cpp +0 -27
- data/vendor/faiss/c_api/error_impl.h +0 -16
- data/vendor/faiss/c_api/faiss_c.h +0 -58
- data/vendor/faiss/c_api/gpu/GpuAutoTune_c.cpp +0 -98
- data/vendor/faiss/c_api/gpu/GpuAutoTune_c.h +0 -56
- data/vendor/faiss/c_api/gpu/GpuClonerOptions_c.cpp +0 -52
- data/vendor/faiss/c_api/gpu/GpuClonerOptions_c.h +0 -68
- data/vendor/faiss/c_api/gpu/GpuIndex_c.cpp +0 -17
- data/vendor/faiss/c_api/gpu/GpuIndex_c.h +0 -30
- data/vendor/faiss/c_api/gpu/GpuIndicesOptions_c.h +0 -38
- data/vendor/faiss/c_api/gpu/GpuResources_c.cpp +0 -86
- data/vendor/faiss/c_api/gpu/GpuResources_c.h +0 -66
- data/vendor/faiss/c_api/gpu/StandardGpuResources_c.cpp +0 -54
- data/vendor/faiss/c_api/gpu/StandardGpuResources_c.h +0 -53
- data/vendor/faiss/c_api/gpu/macros_impl.h +0 -42
- data/vendor/faiss/c_api/impl/AuxIndexStructures_c.cpp +0 -220
- data/vendor/faiss/c_api/impl/AuxIndexStructures_c.h +0 -149
- data/vendor/faiss/c_api/index_factory_c.cpp +0 -26
- data/vendor/faiss/c_api/index_factory_c.h +0 -30
- data/vendor/faiss/c_api/index_io_c.cpp +0 -42
- data/vendor/faiss/c_api/index_io_c.h +0 -50
- data/vendor/faiss/c_api/macros_impl.h +0 -110
- data/vendor/faiss/demos/demo_imi_flat.cpp +0 -154
- data/vendor/faiss/demos/demo_imi_pq.cpp +0 -203
- data/vendor/faiss/demos/demo_ivfpq_indexing.cpp +0 -151
- data/vendor/faiss/demos/demo_sift1M.cpp +0 -252
- data/vendor/faiss/demos/demo_weighted_kmeans.cpp +0 -185
- data/vendor/faiss/misc/test_blas.cpp +0 -87
- data/vendor/faiss/tests/test_binary_flat.cpp +0 -62
- data/vendor/faiss/tests/test_dealloc_invlists.cpp +0 -188
- data/vendor/faiss/tests/test_ivfpq_codec.cpp +0 -70
- data/vendor/faiss/tests/test_ivfpq_indexing.cpp +0 -100
- data/vendor/faiss/tests/test_lowlevel_ivf.cpp +0 -573
- data/vendor/faiss/tests/test_merge.cpp +0 -260
- data/vendor/faiss/tests/test_omp_threads.cpp +0 -14
- data/vendor/faiss/tests/test_ondisk_ivf.cpp +0 -225
- data/vendor/faiss/tests/test_pairs_decoding.cpp +0 -193
- data/vendor/faiss/tests/test_params_override.cpp +0 -236
- data/vendor/faiss/tests/test_pq_encoding.cpp +0 -98
- data/vendor/faiss/tests/test_sliding_ivf.cpp +0 -246
- data/vendor/faiss/tests/test_threaded_index.cpp +0 -253
- data/vendor/faiss/tests/test_transfer_invlists.cpp +0 -159
- data/vendor/faiss/tutorial/cpp/1-Flat.cpp +0 -104
- data/vendor/faiss/tutorial/cpp/2-IVFFlat.cpp +0 -85
- data/vendor/faiss/tutorial/cpp/3-IVFPQ.cpp +0 -98
- data/vendor/faiss/tutorial/cpp/4-GPU.cpp +0 -122
- data/vendor/faiss/tutorial/cpp/5-Multiple-GPUs.cpp +0 -104
@@ -1,52 +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 "GpuClonerOptions_c.h"
|
12
|
-
#include <faiss/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)
|
@@ -1,68 +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_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
|
@@ -1,17 +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 <faiss/gpu/GpuIndex.h>
|
12
|
-
#include "GpuIndex_c.h"
|
13
|
-
#include "macros_impl.h"
|
14
|
-
|
15
|
-
using faiss::gpu::GpuIndexConfig;
|
16
|
-
|
17
|
-
DEFINE_GETTER(GpuIndexConfig, int, device)
|
@@ -1,30 +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_INDEX_C_H
|
12
|
-
#define FAISS_GPU_INDEX_C_H
|
13
|
-
|
14
|
-
#include "faiss_c.h"
|
15
|
-
|
16
|
-
#ifdef __cplusplus
|
17
|
-
extern "C" {
|
18
|
-
#endif
|
19
|
-
|
20
|
-
FAISS_DECLARE_CLASS(GpuIndexConfig)
|
21
|
-
|
22
|
-
FAISS_DECLARE_GETTER(GpuIndexConfig, int, device)
|
23
|
-
|
24
|
-
FAISS_DECLARE_CLASS_INHERITED(GpuIndex, Index)
|
25
|
-
|
26
|
-
#ifdef __cplusplus
|
27
|
-
}
|
28
|
-
#endif
|
29
|
-
|
30
|
-
#endif
|
@@ -1,38 +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_INDICES_OPTIONS_C_H
|
12
|
-
#define FAISS_GPU_INDICES_OPTIONS_C_H
|
13
|
-
|
14
|
-
#ifdef __cplusplus
|
15
|
-
extern "C" {
|
16
|
-
#endif
|
17
|
-
|
18
|
-
/// How user vector index data is stored on the GPU
|
19
|
-
typedef enum FaissIndicesOptions {
|
20
|
-
/// The user indices are only stored on the CPU; the GPU returns
|
21
|
-
/// (inverted list, offset) to the CPU which is then translated to
|
22
|
-
/// the real user index.
|
23
|
-
INDICES_CPU = 0,
|
24
|
-
/// The indices are not stored at all, on either the CPU or
|
25
|
-
/// GPU. Only (inverted list, offset) is returned to the user as the
|
26
|
-
/// index.
|
27
|
-
INDICES_IVF = 1,
|
28
|
-
/// Indices are stored as 32 bit integers on the GPU, but returned
|
29
|
-
/// as 64 bit integers
|
30
|
-
INDICES_32_BIT = 2,
|
31
|
-
/// Indices are stored as 64 bit integers on the GPU
|
32
|
-
INDICES_64_BIT = 3,
|
33
|
-
} FaissIndicesOptions;
|
34
|
-
|
35
|
-
#ifdef __cplusplus
|
36
|
-
}
|
37
|
-
#endif
|
38
|
-
#endif
|
@@ -1,86 +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 "gpu/GpuResources_c.h"
|
12
|
-
#include <faiss/gpu/GpuResources.h>
|
13
|
-
#include "macros_impl.h"
|
14
|
-
|
15
|
-
using faiss::gpu::GpuResources;
|
16
|
-
|
17
|
-
DEFINE_DESTRUCTOR(GpuResources)
|
18
|
-
|
19
|
-
int faiss_GpuResources_initializeForDevice(FaissGpuResources* res, int device) {
|
20
|
-
try {
|
21
|
-
reinterpret_cast<GpuResources*>(res)->initializeForDevice(device);
|
22
|
-
} CATCH_AND_HANDLE
|
23
|
-
}
|
24
|
-
|
25
|
-
int faiss_GpuResources_getBlasHandle(FaissGpuResources* res, int device, cublasHandle_t* out) {
|
26
|
-
try {
|
27
|
-
auto o = reinterpret_cast<GpuResources*>(res)->getBlasHandle(device);
|
28
|
-
*out = o;
|
29
|
-
} CATCH_AND_HANDLE
|
30
|
-
}
|
31
|
-
|
32
|
-
int faiss_GpuResources_getDefaultStream(FaissGpuResources* res, int device, cudaStream_t* out) {
|
33
|
-
try {
|
34
|
-
auto o = reinterpret_cast<GpuResources*>(res)->getDefaultStream(device);
|
35
|
-
*out = o;
|
36
|
-
} CATCH_AND_HANDLE
|
37
|
-
}
|
38
|
-
|
39
|
-
int faiss_GpuResources_getPinnedMemory(FaissGpuResources* res, void** p_buffer, size_t* p_size) {
|
40
|
-
try {
|
41
|
-
auto o = reinterpret_cast<GpuResources*>(res)->getPinnedMemory();
|
42
|
-
*p_buffer = o.first;
|
43
|
-
*p_size = o.second;
|
44
|
-
} CATCH_AND_HANDLE
|
45
|
-
}
|
46
|
-
|
47
|
-
int faiss_GpuResources_getAsyncCopyStream(FaissGpuResources* res, int device, cudaStream_t* out) {
|
48
|
-
try {
|
49
|
-
auto o = reinterpret_cast<GpuResources*>(res)->getAsyncCopyStream(device);
|
50
|
-
*out = o;
|
51
|
-
} CATCH_AND_HANDLE
|
52
|
-
}
|
53
|
-
|
54
|
-
int faiss_GpuResources_getBlasHandleCurrentDevice(FaissGpuResources* res, cublasHandle_t* out) {
|
55
|
-
try {
|
56
|
-
auto o = reinterpret_cast<GpuResources*>(res)->getBlasHandleCurrentDevice();
|
57
|
-
*out = o;
|
58
|
-
} CATCH_AND_HANDLE
|
59
|
-
}
|
60
|
-
|
61
|
-
int faiss_GpuResources_getDefaultStreamCurrentDevice(FaissGpuResources* res, cudaStream_t* out) {
|
62
|
-
try {
|
63
|
-
auto o = reinterpret_cast<GpuResources*>(res)->getDefaultStreamCurrentDevice();
|
64
|
-
*out = o;
|
65
|
-
} CATCH_AND_HANDLE
|
66
|
-
}
|
67
|
-
|
68
|
-
int faiss_GpuResources_syncDefaultStream(FaissGpuResources* res, int device) {
|
69
|
-
try {
|
70
|
-
reinterpret_cast<GpuResources*>(res)->syncDefaultStream(device);
|
71
|
-
} CATCH_AND_HANDLE
|
72
|
-
}
|
73
|
-
|
74
|
-
int faiss_GpuResources_syncDefaultStreamCurrentDevice(FaissGpuResources* res) {
|
75
|
-
try {
|
76
|
-
reinterpret_cast<GpuResources*>(res)->syncDefaultStreamCurrentDevice();
|
77
|
-
} CATCH_AND_HANDLE
|
78
|
-
}
|
79
|
-
|
80
|
-
int faiss_GpuResources_getAsyncCopyStreamCurrentDevice(FaissGpuResources* res, cudaStream_t* out) {
|
81
|
-
try {
|
82
|
-
auto o = reinterpret_cast<GpuResources*>(res)->getAsyncCopyStreamCurrentDevice();
|
83
|
-
*out = o;
|
84
|
-
} CATCH_AND_HANDLE
|
85
|
-
}
|
86
|
-
|
@@ -1,66 +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_RESOURCES_C_H
|
12
|
-
#define FAISS_GPU_RESOURCES_C_H
|
13
|
-
|
14
|
-
#include <cuda_runtime_api.h>
|
15
|
-
#include <cublas.h>
|
16
|
-
#include "faiss_c.h"
|
17
|
-
|
18
|
-
#ifdef __cplusplus
|
19
|
-
extern "C" {
|
20
|
-
#endif
|
21
|
-
|
22
|
-
/// Base class of GPU-side resource provider; hides provision of
|
23
|
-
/// cuBLAS handles, CUDA streams and a temporary memory manager
|
24
|
-
FAISS_DECLARE_CLASS(GpuResources)
|
25
|
-
|
26
|
-
FAISS_DECLARE_DESTRUCTOR(GpuResources)
|
27
|
-
|
28
|
-
/// Call to pre-allocate resources for a particular device. If this is
|
29
|
-
/// not called, then resources will be allocated at the first time
|
30
|
-
/// of demand
|
31
|
-
int faiss_GpuResources_initializeForDevice(FaissGpuResources*, int);
|
32
|
-
|
33
|
-
/// Returns the cuBLAS handle that we use for the given device
|
34
|
-
int faiss_GpuResources_getBlasHandle(FaissGpuResources*, int, cublasHandle_t*);
|
35
|
-
|
36
|
-
/// Returns the stream that we order all computation on for the
|
37
|
-
/// given device
|
38
|
-
int faiss_GpuResources_getDefaultStream(FaissGpuResources*, int, cudaStream_t*);
|
39
|
-
|
40
|
-
/// Returns the available CPU pinned memory buffer
|
41
|
-
int faiss_GpuResources_getPinnedMemory(FaissGpuResources*, void**, size_t*);
|
42
|
-
|
43
|
-
/// Returns the stream on which we perform async CPU <-> GPU copies
|
44
|
-
int faiss_GpuResources_getAsyncCopyStream(FaissGpuResources*, int, cudaStream_t*);
|
45
|
-
|
46
|
-
/// Calls getBlasHandle with the current device
|
47
|
-
int faiss_GpuResources_getBlasHandleCurrentDevice(FaissGpuResources*, cublasHandle_t*);
|
48
|
-
|
49
|
-
/// Calls getDefaultStream with the current device
|
50
|
-
int faiss_GpuResources_getDefaultStreamCurrentDevice(FaissGpuResources*, cudaStream_t*);
|
51
|
-
|
52
|
-
/// Synchronizes the CPU with respect to the default stream for the
|
53
|
-
/// given device
|
54
|
-
// equivalent to cudaDeviceSynchronize(getDefaultStream(device))
|
55
|
-
int faiss_GpuResources_syncDefaultStream(FaissGpuResources*, int);
|
56
|
-
|
57
|
-
/// Calls syncDefaultStream for the current device
|
58
|
-
int faiss_GpuResources_syncDefaultStreamCurrentDevice(FaissGpuResources*);
|
59
|
-
|
60
|
-
/// Calls getAsyncCopyStream for the current device
|
61
|
-
int faiss_GpuResources_getAsyncCopyStreamCurrentDevice(FaissGpuResources*, cudaStream_t*);
|
62
|
-
|
63
|
-
#ifdef __cplusplus
|
64
|
-
}
|
65
|
-
#endif
|
66
|
-
#endif
|
@@ -1,54 +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 "gpu/StandardGpuResources_c.h"
|
12
|
-
#include <faiss/gpu/StandardGpuResources.h>
|
13
|
-
#include "macros_impl.h"
|
14
|
-
|
15
|
-
using faiss::gpu::StandardGpuResources;
|
16
|
-
|
17
|
-
DEFINE_DESTRUCTOR(StandardGpuResources)
|
18
|
-
|
19
|
-
int faiss_StandardGpuResources_new(FaissStandardGpuResources** p_res) {
|
20
|
-
try {
|
21
|
-
auto p = new StandardGpuResources();
|
22
|
-
*p_res = reinterpret_cast<FaissStandardGpuResources*>(p);
|
23
|
-
} CATCH_AND_HANDLE
|
24
|
-
}
|
25
|
-
|
26
|
-
int faiss_StandardGpuResources_noTempMemory(FaissStandardGpuResources* res) {
|
27
|
-
try {
|
28
|
-
reinterpret_cast<StandardGpuResources*>(res)->noTempMemory();
|
29
|
-
} CATCH_AND_HANDLE
|
30
|
-
}
|
31
|
-
|
32
|
-
int faiss_StandardGpuResources_setTempMemory(FaissStandardGpuResources* res, size_t size) {
|
33
|
-
try {
|
34
|
-
reinterpret_cast<StandardGpuResources*>(res)->setTempMemory(size);
|
35
|
-
} CATCH_AND_HANDLE
|
36
|
-
}
|
37
|
-
|
38
|
-
int faiss_StandardGpuResources_setPinnedMemory(FaissStandardGpuResources* res, size_t size) {
|
39
|
-
try {
|
40
|
-
reinterpret_cast<StandardGpuResources*>(res)->setPinnedMemory(size);
|
41
|
-
} CATCH_AND_HANDLE
|
42
|
-
}
|
43
|
-
|
44
|
-
int faiss_StandardGpuResources_setDefaultStream(FaissStandardGpuResources* res, int device, cudaStream_t stream) {
|
45
|
-
try {
|
46
|
-
reinterpret_cast<StandardGpuResources*>(res)->setDefaultStream(device, stream);
|
47
|
-
} CATCH_AND_HANDLE
|
48
|
-
}
|
49
|
-
|
50
|
-
int faiss_StandardGpuResources_setDefaultNullStreamAllDevices(FaissStandardGpuResources* res) {
|
51
|
-
try {
|
52
|
-
reinterpret_cast<StandardGpuResources*>(res)->setDefaultNullStreamAllDevices();
|
53
|
-
} CATCH_AND_HANDLE
|
54
|
-
}
|
@@ -1,53 +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_STANDARD_GPURESOURCES_C_H
|
12
|
-
#define FAISS_STANDARD_GPURESOURCES_C_H
|
13
|
-
|
14
|
-
#include <cuda_runtime_api.h>
|
15
|
-
#include "faiss_c.h"
|
16
|
-
#include "gpu/GpuResources_c.h"
|
17
|
-
|
18
|
-
#ifdef __cplusplus
|
19
|
-
extern "C" {
|
20
|
-
#endif
|
21
|
-
|
22
|
-
/// Default implementation of GpuResources that allocates a cuBLAS
|
23
|
-
/// stream and 2 streams for use, as well as temporary memory
|
24
|
-
FAISS_DECLARE_CLASS_INHERITED(StandardGpuResources, GpuResources)
|
25
|
-
|
26
|
-
FAISS_DECLARE_DESTRUCTOR(StandardGpuResources)
|
27
|
-
|
28
|
-
/// Default constructor for StandardGpuResources
|
29
|
-
int faiss_StandardGpuResources_new(FaissStandardGpuResources**);
|
30
|
-
|
31
|
-
/// Disable allocation of temporary memory; all temporary memory
|
32
|
-
/// requests will call cudaMalloc / cudaFree at the point of use
|
33
|
-
int faiss_StandardGpuResources_noTempMemory(FaissStandardGpuResources*);
|
34
|
-
|
35
|
-
/// Specify that we wish to use a certain fixed size of memory on
|
36
|
-
/// all devices as temporary memory
|
37
|
-
int faiss_StandardGpuResources_setTempMemory(FaissStandardGpuResources*, size_t size);
|
38
|
-
|
39
|
-
/// Set amount of pinned memory to allocate, for async GPU <-> CPU
|
40
|
-
/// transfers
|
41
|
-
int faiss_StandardGpuResources_setPinnedMemory(FaissStandardGpuResources*, size_t size);
|
42
|
-
|
43
|
-
/// Called to change the stream for work ordering
|
44
|
-
int faiss_StandardGpuResources_setDefaultStream(FaissStandardGpuResources*, int device, cudaStream_t stream);
|
45
|
-
|
46
|
-
/// Called to change the work ordering streams to the null stream
|
47
|
-
/// for all devices
|
48
|
-
int faiss_StandardGpuResources_setDefaultNullStreamAllDevices(FaissStandardGpuResources*);
|
49
|
-
|
50
|
-
#ifdef __cplusplus
|
51
|
-
}
|
52
|
-
#endif
|
53
|
-
#endif
|