faiss 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/ext/faiss/extconf.rb +1 -1
- data/lib/faiss/version.rb +1 -1
- data/vendor/faiss/benchs/bench_6bit_codec.cpp +80 -0
- data/vendor/faiss/c_api/AutoTune_c.h +2 -0
- data/vendor/faiss/c_api/IndexShards_c.cpp +0 -6
- data/vendor/faiss/c_api/IndexShards_c.h +1 -4
- data/vendor/faiss/c_api/gpu/GpuAutoTune_c.cpp +4 -2
- data/vendor/faiss/c_api/gpu/GpuClonerOptions_c.cpp +1 -1
- data/vendor/faiss/c_api/gpu/GpuIndex_c.cpp +1 -1
- data/vendor/faiss/c_api/gpu/GpuResources_c.cpp +1 -1
- data/vendor/faiss/c_api/gpu/StandardGpuResources_c.cpp +1 -1
- data/vendor/faiss/demos/demo_imi_flat.cpp +5 -2
- data/vendor/faiss/demos/demo_imi_pq.cpp +6 -2
- data/vendor/faiss/demos/demo_ivfpq_indexing.cpp +7 -2
- data/vendor/faiss/{AutoTune.cpp → faiss/AutoTune.cpp} +9 -9
- data/vendor/faiss/{AutoTune.h → faiss/AutoTune.h} +0 -0
- data/vendor/faiss/{Clustering.cpp → faiss/Clustering.cpp} +13 -12
- data/vendor/faiss/{Clustering.h → faiss/Clustering.h} +0 -0
- data/vendor/faiss/{DirectMap.cpp → faiss/DirectMap.cpp} +0 -0
- data/vendor/faiss/{DirectMap.h → faiss/DirectMap.h} +0 -0
- data/vendor/faiss/{IVFlib.cpp → faiss/IVFlib.cpp} +86 -11
- data/vendor/faiss/{IVFlib.h → faiss/IVFlib.h} +26 -8
- data/vendor/faiss/{Index.cpp → faiss/Index.cpp} +0 -0
- data/vendor/faiss/{Index.h → faiss/Index.h} +1 -1
- data/vendor/faiss/{Index2Layer.cpp → faiss/Index2Layer.cpp} +12 -11
- data/vendor/faiss/{Index2Layer.h → faiss/Index2Layer.h} +0 -0
- data/vendor/faiss/{IndexBinary.cpp → faiss/IndexBinary.cpp} +2 -1
- data/vendor/faiss/{IndexBinary.h → faiss/IndexBinary.h} +0 -0
- data/vendor/faiss/{IndexBinaryFlat.cpp → faiss/IndexBinaryFlat.cpp} +0 -0
- data/vendor/faiss/{IndexBinaryFlat.h → faiss/IndexBinaryFlat.h} +0 -0
- data/vendor/faiss/{IndexBinaryFromFloat.cpp → faiss/IndexBinaryFromFloat.cpp} +1 -0
- data/vendor/faiss/{IndexBinaryFromFloat.h → faiss/IndexBinaryFromFloat.h} +0 -0
- data/vendor/faiss/{IndexBinaryHNSW.cpp → faiss/IndexBinaryHNSW.cpp} +1 -2
- data/vendor/faiss/{IndexBinaryHNSW.h → faiss/IndexBinaryHNSW.h} +0 -0
- data/vendor/faiss/{IndexBinaryHash.cpp → faiss/IndexBinaryHash.cpp} +16 -7
- data/vendor/faiss/{IndexBinaryHash.h → faiss/IndexBinaryHash.h} +2 -1
- data/vendor/faiss/{IndexBinaryIVF.cpp → faiss/IndexBinaryIVF.cpp} +10 -16
- data/vendor/faiss/{IndexBinaryIVF.h → faiss/IndexBinaryIVF.h} +1 -1
- data/vendor/faiss/{IndexFlat.cpp → faiss/IndexFlat.cpp} +0 -0
- data/vendor/faiss/{IndexFlat.h → faiss/IndexFlat.h} +0 -0
- data/vendor/faiss/{IndexHNSW.cpp → faiss/IndexHNSW.cpp} +63 -32
- data/vendor/faiss/{IndexHNSW.h → faiss/IndexHNSW.h} +0 -0
- data/vendor/faiss/{IndexIVF.cpp → faiss/IndexIVF.cpp} +129 -46
- data/vendor/faiss/{IndexIVF.h → faiss/IndexIVF.h} +7 -3
- data/vendor/faiss/{IndexIVFFlat.cpp → faiss/IndexIVFFlat.cpp} +6 -5
- data/vendor/faiss/{IndexIVFFlat.h → faiss/IndexIVFFlat.h} +0 -0
- data/vendor/faiss/{IndexIVFPQ.cpp → faiss/IndexIVFPQ.cpp} +9 -8
- data/vendor/faiss/{IndexIVFPQ.h → faiss/IndexIVFPQ.h} +4 -2
- data/vendor/faiss/{IndexIVFPQR.cpp → faiss/IndexIVFPQR.cpp} +3 -1
- data/vendor/faiss/{IndexIVFPQR.h → faiss/IndexIVFPQR.h} +0 -0
- data/vendor/faiss/{IndexIVFSpectralHash.cpp → faiss/IndexIVFSpectralHash.cpp} +1 -1
- data/vendor/faiss/{IndexIVFSpectralHash.h → faiss/IndexIVFSpectralHash.h} +0 -0
- data/vendor/faiss/{IndexLSH.cpp → faiss/IndexLSH.cpp} +0 -0
- data/vendor/faiss/{IndexLSH.h → faiss/IndexLSH.h} +0 -0
- data/vendor/faiss/{IndexLattice.cpp → faiss/IndexLattice.cpp} +0 -0
- data/vendor/faiss/{IndexLattice.h → faiss/IndexLattice.h} +0 -0
- data/vendor/faiss/{IndexPQ.cpp → faiss/IndexPQ.cpp} +6 -6
- data/vendor/faiss/{IndexPQ.h → faiss/IndexPQ.h} +3 -1
- data/vendor/faiss/{IndexPreTransform.cpp → faiss/IndexPreTransform.cpp} +0 -0
- data/vendor/faiss/{IndexPreTransform.h → faiss/IndexPreTransform.h} +0 -0
- data/vendor/faiss/{IndexReplicas.cpp → faiss/IndexReplicas.cpp} +102 -10
- data/vendor/faiss/{IndexReplicas.h → faiss/IndexReplicas.h} +6 -0
- data/vendor/faiss/{IndexScalarQuantizer.cpp → faiss/IndexScalarQuantizer.cpp} +3 -3
- data/vendor/faiss/{IndexScalarQuantizer.h → faiss/IndexScalarQuantizer.h} +0 -0
- data/vendor/faiss/{IndexShards.cpp → faiss/IndexShards.cpp} +37 -12
- data/vendor/faiss/{IndexShards.h → faiss/IndexShards.h} +3 -4
- data/vendor/faiss/{InvertedLists.cpp → faiss/InvertedLists.cpp} +2 -2
- data/vendor/faiss/{InvertedLists.h → faiss/InvertedLists.h} +1 -0
- data/vendor/faiss/{MatrixStats.cpp → faiss/MatrixStats.cpp} +0 -0
- data/vendor/faiss/{MatrixStats.h → faiss/MatrixStats.h} +0 -0
- data/vendor/faiss/{MetaIndexes.cpp → faiss/MetaIndexes.cpp} +5 -3
- data/vendor/faiss/{MetaIndexes.h → faiss/MetaIndexes.h} +0 -0
- data/vendor/faiss/{MetricType.h → faiss/MetricType.h} +0 -0
- data/vendor/faiss/{OnDiskInvertedLists.cpp → faiss/OnDiskInvertedLists.cpp} +141 -3
- data/vendor/faiss/{OnDiskInvertedLists.h → faiss/OnDiskInvertedLists.h} +27 -7
- data/vendor/faiss/{VectorTransform.cpp → faiss/VectorTransform.cpp} +4 -3
- data/vendor/faiss/{VectorTransform.h → faiss/VectorTransform.h} +0 -0
- data/vendor/faiss/{clone_index.cpp → faiss/clone_index.cpp} +0 -0
- data/vendor/faiss/{clone_index.h → faiss/clone_index.h} +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/GpuAutoTune.cpp +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/GpuAutoTune.h +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/GpuCloner.cpp +14 -14
- data/vendor/faiss/{gpu → faiss/gpu}/GpuCloner.h +6 -7
- data/vendor/faiss/{gpu → faiss/gpu}/GpuClonerOptions.cpp +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/GpuClonerOptions.h +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/GpuDistance.h +12 -4
- data/vendor/faiss/{gpu → faiss/gpu}/GpuFaissAssert.h +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/GpuIndex.h +3 -9
- data/vendor/faiss/{gpu → faiss/gpu}/GpuIndexBinaryFlat.h +7 -7
- data/vendor/faiss/{gpu → faiss/gpu}/GpuIndexFlat.h +35 -10
- data/vendor/faiss/{gpu → faiss/gpu}/GpuIndexIVF.h +1 -2
- data/vendor/faiss/{gpu → faiss/gpu}/GpuIndexIVFFlat.h +4 -3
- data/vendor/faiss/{gpu → faiss/gpu}/GpuIndexIVFPQ.h +21 -4
- data/vendor/faiss/{gpu → faiss/gpu}/GpuIndexIVFScalarQuantizer.h +4 -3
- data/vendor/faiss/{gpu → faiss/gpu}/GpuIndicesOptions.h +0 -0
- data/vendor/faiss/faiss/gpu/GpuResources.cpp +200 -0
- data/vendor/faiss/faiss/gpu/GpuResources.h +264 -0
- data/vendor/faiss/faiss/gpu/StandardGpuResources.cpp +572 -0
- data/vendor/faiss/{gpu → faiss/gpu}/StandardGpuResources.h +83 -15
- data/vendor/faiss/{gpu → faiss/gpu}/impl/RemapIndices.cpp +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/impl/RemapIndices.h +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/perf/IndexWrapper-inl.h +1 -1
- data/vendor/faiss/{gpu → faiss/gpu}/perf/IndexWrapper.h +1 -1
- data/vendor/faiss/{gpu → faiss/gpu}/perf/PerfClustering.cpp +1 -1
- data/vendor/faiss/{gpu → faiss/gpu}/perf/PerfIVFPQAdd.cpp +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/perf/WriteIndex.cpp +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/test/TestGpuIndexBinaryFlat.cpp +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/test/TestGpuIndexFlat.cpp +1 -1
- data/vendor/faiss/{gpu → faiss/gpu}/test/TestGpuIndexIVFFlat.cpp +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/test/TestGpuIndexIVFPQ.cpp +141 -52
- data/vendor/faiss/{gpu → faiss/gpu}/test/TestGpuMemoryException.cpp +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/test/TestUtils.cpp +4 -2
- data/vendor/faiss/{gpu → faiss/gpu}/test/TestUtils.h +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/test/demo_ivfpq_indexing_gpu.cpp +7 -5
- data/vendor/faiss/{gpu → faiss/gpu}/utils/DeviceUtils.h +1 -1
- data/vendor/faiss/faiss/gpu/utils/StackDeviceMemory.cpp +213 -0
- data/vendor/faiss/{gpu → faiss/gpu}/utils/StackDeviceMemory.h +25 -40
- data/vendor/faiss/{gpu → faiss/gpu}/utils/StaticUtils.h +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/utils/Timer.cpp +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/utils/Timer.h +0 -0
- data/vendor/faiss/{impl → faiss/impl}/AuxIndexStructures.cpp +1 -0
- data/vendor/faiss/{impl → faiss/impl}/AuxIndexStructures.h +3 -1
- data/vendor/faiss/{impl → faiss/impl}/FaissAssert.h +1 -0
- data/vendor/faiss/{impl → faiss/impl}/FaissException.cpp +26 -0
- data/vendor/faiss/{impl → faiss/impl}/FaissException.h +4 -0
- data/vendor/faiss/{impl → faiss/impl}/HNSW.cpp +26 -26
- data/vendor/faiss/{impl → faiss/impl}/HNSW.h +19 -11
- data/vendor/faiss/{impl → faiss/impl}/PolysemousTraining.cpp +1 -1
- data/vendor/faiss/{impl → faiss/impl}/PolysemousTraining.h +1 -1
- data/vendor/faiss/{impl → faiss/impl}/ProductQuantizer-inl.h +0 -1
- data/vendor/faiss/{impl → faiss/impl}/ProductQuantizer.cpp +9 -9
- data/vendor/faiss/{impl → faiss/impl}/ProductQuantizer.h +0 -0
- data/vendor/faiss/{impl → faiss/impl}/ScalarQuantizer.cpp +63 -39
- data/vendor/faiss/{impl → faiss/impl}/ScalarQuantizer.h +1 -1
- data/vendor/faiss/{impl → faiss/impl}/ThreadedIndex-inl.h +0 -0
- data/vendor/faiss/{impl → faiss/impl}/ThreadedIndex.h +0 -0
- data/vendor/faiss/{impl → faiss/impl}/index_read.cpp +99 -116
- data/vendor/faiss/{impl → faiss/impl}/index_write.cpp +15 -50
- data/vendor/faiss/{impl → faiss/impl}/io.cpp +15 -10
- data/vendor/faiss/{impl → faiss/impl}/io.h +22 -8
- data/vendor/faiss/faiss/impl/io_macros.h +57 -0
- data/vendor/faiss/{impl → faiss/impl}/lattice_Zn.cpp +52 -36
- data/vendor/faiss/{impl → faiss/impl}/lattice_Zn.h +3 -3
- data/vendor/faiss/faiss/impl/platform_macros.h +24 -0
- data/vendor/faiss/{index_factory.cpp → faiss/index_factory.cpp} +33 -12
- data/vendor/faiss/{index_factory.h → faiss/index_factory.h} +0 -0
- data/vendor/faiss/{index_io.h → faiss/index_io.h} +55 -1
- data/vendor/faiss/faiss/python/python_callbacks.cpp +112 -0
- data/vendor/faiss/faiss/python/python_callbacks.h +45 -0
- data/vendor/faiss/{utils → faiss/utils}/Heap.cpp +5 -5
- data/vendor/faiss/{utils → faiss/utils}/Heap.h +1 -3
- data/vendor/faiss/{utils → faiss/utils}/WorkerThread.cpp +0 -0
- data/vendor/faiss/{utils → faiss/utils}/WorkerThread.h +0 -0
- data/vendor/faiss/{utils → faiss/utils}/distances.cpp +28 -13
- data/vendor/faiss/{utils → faiss/utils}/distances.h +2 -1
- data/vendor/faiss/{utils → faiss/utils}/distances_simd.cpp +5 -5
- data/vendor/faiss/{utils → faiss/utils}/extra_distances.cpp +8 -7
- data/vendor/faiss/{utils → faiss/utils}/extra_distances.h +0 -0
- data/vendor/faiss/{utils → faiss/utils}/hamming-inl.h +1 -3
- data/vendor/faiss/{utils → faiss/utils}/hamming.cpp +8 -7
- data/vendor/faiss/{utils → faiss/utils}/hamming.h +7 -1
- data/vendor/faiss/{utils → faiss/utils}/random.cpp +5 -5
- data/vendor/faiss/{utils → faiss/utils}/random.h +0 -0
- data/vendor/faiss/{utils → faiss/utils}/utils.cpp +27 -28
- data/vendor/faiss/{utils → faiss/utils}/utils.h +4 -0
- data/vendor/faiss/misc/test_blas.cpp +4 -1
- data/vendor/faiss/tests/test_binary_flat.cpp +0 -2
- data/vendor/faiss/tests/test_dealloc_invlists.cpp +6 -1
- data/vendor/faiss/tests/test_ivfpq_codec.cpp +4 -1
- data/vendor/faiss/tests/test_ivfpq_indexing.cpp +6 -4
- data/vendor/faiss/tests/test_lowlevel_ivf.cpp +12 -5
- data/vendor/faiss/tests/test_merge.cpp +6 -3
- data/vendor/faiss/tests/test_ondisk_ivf.cpp +7 -2
- data/vendor/faiss/tests/test_pairs_decoding.cpp +5 -1
- data/vendor/faiss/tests/test_params_override.cpp +7 -2
- data/vendor/faiss/tests/test_sliding_ivf.cpp +10 -4
- data/vendor/faiss/tutorial/cpp/1-Flat.cpp +14 -8
- data/vendor/faiss/tutorial/cpp/2-IVFFlat.cpp +11 -7
- data/vendor/faiss/tutorial/cpp/3-IVFPQ.cpp +12 -7
- data/vendor/faiss/tutorial/cpp/4-GPU.cpp +6 -3
- data/vendor/faiss/tutorial/cpp/5-Multiple-GPUs.cpp +7 -3
- metadata +154 -153
- data/vendor/faiss/gpu/GpuResources.cpp +0 -52
- data/vendor/faiss/gpu/GpuResources.h +0 -73
- data/vendor/faiss/gpu/StandardGpuResources.cpp +0 -303
- data/vendor/faiss/gpu/utils/DeviceMemory.cpp +0 -77
- data/vendor/faiss/gpu/utils/DeviceMemory.h +0 -71
- data/vendor/faiss/gpu/utils/MemorySpace.cpp +0 -89
- data/vendor/faiss/gpu/utils/MemorySpace.h +0 -44
- data/vendor/faiss/gpu/utils/StackDeviceMemory.cpp +0 -239
@@ -9,6 +9,7 @@
|
|
9
9
|
|
10
10
|
#include <faiss/VectorTransform.h>
|
11
11
|
|
12
|
+
#include <cinttypes>
|
12
13
|
#include <cstdio>
|
13
14
|
#include <cmath>
|
14
15
|
#include <cstring>
|
@@ -270,7 +271,7 @@ void RandomRotationMatrix::init (int seed)
|
|
270
271
|
is_trained = true;
|
271
272
|
}
|
272
273
|
|
273
|
-
void RandomRotationMatrix::train (Index::idx_t /*n*/, const float
|
274
|
+
void RandomRotationMatrix::train (Index::idx_t /*n*/, const float * /*x*/)
|
274
275
|
{
|
275
276
|
// initialize with some arbitrary seed
|
276
277
|
init (12345);
|
@@ -867,7 +868,7 @@ void OPQMatrix::train (Index::idx_t n, const float *x)
|
|
867
868
|
|
868
869
|
if (verbose) {
|
869
870
|
printf ("OPQMatrix::train: training an OPQ rotation matrix "
|
870
|
-
"for M=%d from %
|
871
|
+
"for M=%d from %" PRId64 " vectors in %dD -> %dD\n",
|
871
872
|
M, n, d_in, d_out);
|
872
873
|
}
|
873
874
|
|
@@ -895,7 +896,7 @@ void OPQMatrix::train (Index::idx_t n, const float *x)
|
|
895
896
|
A.resize (d * d);
|
896
897
|
rotation = A.data();
|
897
898
|
if (verbose)
|
898
|
-
printf(" OPQMatrix::train: making random %
|
899
|
+
printf(" OPQMatrix::train: making random %zd*%zd rotation\n",
|
899
900
|
d, d);
|
900
901
|
float_randn (rotation, d * d, 1234);
|
901
902
|
matrix_qr (d, d, rotation);
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -114,9 +114,9 @@ faiss::Index * index_gpu_to_cpu(const faiss::Index *gpu_index)
|
|
114
114
|
* Cloning to 1 GPU
|
115
115
|
**********************************************************/
|
116
116
|
|
117
|
-
ToGpuCloner::ToGpuCloner(
|
117
|
+
ToGpuCloner::ToGpuCloner(GpuResourcesProvider *prov, int device,
|
118
118
|
const GpuClonerOptions &options):
|
119
|
-
GpuClonerOptions(options),
|
119
|
+
GpuClonerOptions(options), provider(prov), device(device)
|
120
120
|
{}
|
121
121
|
|
122
122
|
Index *ToGpuCloner::clone_Index(const Index *index)
|
@@ -127,7 +127,7 @@ Index *ToGpuCloner::clone_Index(const Index *index)
|
|
127
127
|
config.useFloat16 = useFloat16;
|
128
128
|
config.storeTransposed = storeTransposed;
|
129
129
|
|
130
|
-
return new GpuIndexFlat(
|
130
|
+
return new GpuIndexFlat(provider, ifl, config);
|
131
131
|
} else if(auto ifl = dynamic_cast<const faiss::IndexIVFFlat *>(index)) {
|
132
132
|
GpuIndexIVFFlatConfig config;
|
133
133
|
config.device = device;
|
@@ -136,7 +136,7 @@ Index *ToGpuCloner::clone_Index(const Index *index)
|
|
136
136
|
config.flatConfig.storeTransposed = storeTransposed;
|
137
137
|
|
138
138
|
GpuIndexIVFFlat *res =
|
139
|
-
new GpuIndexIVFFlat(
|
139
|
+
new GpuIndexIVFFlat(provider,
|
140
140
|
ifl->d,
|
141
141
|
ifl->nlist,
|
142
142
|
ifl->metric_type,
|
@@ -156,7 +156,7 @@ Index *ToGpuCloner::clone_Index(const Index *index)
|
|
156
156
|
config.flatConfig.storeTransposed = storeTransposed;
|
157
157
|
|
158
158
|
GpuIndexIVFScalarQuantizer *res =
|
159
|
-
new GpuIndexIVFScalarQuantizer(
|
159
|
+
new GpuIndexIVFScalarQuantizer(provider,
|
160
160
|
ifl->d,
|
161
161
|
ifl->nlist,
|
162
162
|
ifl->sq.qtype,
|
@@ -184,7 +184,7 @@ Index *ToGpuCloner::clone_Index(const Index *index)
|
|
184
184
|
config.useFloat16LookupTables = useFloat16;
|
185
185
|
config.usePrecomputedTables = usePrecomputed;
|
186
186
|
|
187
|
-
GpuIndexIVFPQ *res = new GpuIndexIVFPQ(
|
187
|
+
GpuIndexIVFPQ *res = new GpuIndexIVFPQ(provider, ipq, config);
|
188
188
|
|
189
189
|
if(reserveVecs > 0 && ipq->ntotal == 0) {
|
190
190
|
res->reserveMemory(reserveVecs);
|
@@ -198,12 +198,12 @@ Index *ToGpuCloner::clone_Index(const Index *index)
|
|
198
198
|
|
199
199
|
|
200
200
|
faiss::Index * index_cpu_to_gpu(
|
201
|
-
|
201
|
+
GpuResourcesProvider* provider, int device,
|
202
202
|
const faiss::Index *index,
|
203
203
|
const GpuClonerOptions *options)
|
204
204
|
{
|
205
205
|
GpuClonerOptions defaults;
|
206
|
-
ToGpuCloner cl(
|
206
|
+
ToGpuCloner cl(provider, device, options ? *options : defaults);
|
207
207
|
return cl.clone_Index(index);
|
208
208
|
}
|
209
209
|
|
@@ -213,14 +213,14 @@ faiss::Index * index_cpu_to_gpu(
|
|
213
213
|
**********************************************************/
|
214
214
|
|
215
215
|
ToGpuClonerMultiple::ToGpuClonerMultiple(
|
216
|
-
std::vector<
|
216
|
+
std::vector<GpuResourcesProvider *> & provider,
|
217
217
|
std::vector<int>& devices,
|
218
218
|
const GpuMultipleClonerOptions &options):
|
219
219
|
GpuMultipleClonerOptions(options)
|
220
220
|
{
|
221
|
-
FAISS_ASSERT(
|
222
|
-
for(int i = 0; i <
|
223
|
-
sub_cloners.push_back(ToGpuCloner(
|
221
|
+
FAISS_ASSERT(provider.size() == devices.size());
|
222
|
+
for(int i = 0; i < provider.size(); i++) {
|
223
|
+
sub_cloners.push_back(ToGpuCloner(provider[i], devices[i], options));
|
224
224
|
}
|
225
225
|
}
|
226
226
|
|
@@ -394,13 +394,13 @@ Index *ToGpuClonerMultiple::clone_Index(const Index *index)
|
|
394
394
|
|
395
395
|
|
396
396
|
faiss::Index * index_cpu_to_gpu_multiple(
|
397
|
-
std::vector<
|
397
|
+
std::vector<GpuResourcesProvider*> & provider,
|
398
398
|
std::vector<int> &devices,
|
399
399
|
const faiss::Index *index,
|
400
400
|
const GpuMultipleClonerOptions *options)
|
401
401
|
{
|
402
402
|
GpuMultipleClonerOptions defaults;
|
403
|
-
ToGpuClonerMultiple cl(
|
403
|
+
ToGpuClonerMultiple cl(provider, devices, options ? *options : defaults);
|
404
404
|
return cl.clone_Index(index);
|
405
405
|
}
|
406
406
|
|
@@ -17,8 +17,7 @@
|
|
17
17
|
|
18
18
|
namespace faiss { namespace gpu {
|
19
19
|
|
20
|
-
class
|
21
|
-
|
20
|
+
class GpuResourcesProvider;
|
22
21
|
|
23
22
|
/// Cloner specialized for GPU -> CPU
|
24
23
|
struct ToCPUCloner: faiss::Cloner {
|
@@ -29,10 +28,10 @@ struct ToCPUCloner: faiss::Cloner {
|
|
29
28
|
|
30
29
|
/// Cloner specialized for CPU -> 1 GPU
|
31
30
|
struct ToGpuCloner: faiss::Cloner, GpuClonerOptions {
|
32
|
-
|
31
|
+
GpuResourcesProvider *provider;
|
33
32
|
int device;
|
34
33
|
|
35
|
-
ToGpuCloner(
|
34
|
+
ToGpuCloner(GpuResourcesProvider *prov, int device,
|
36
35
|
const GpuClonerOptions &options);
|
37
36
|
|
38
37
|
Index *clone_Index(const Index *index) override;
|
@@ -43,7 +42,7 @@ struct ToGpuCloner: faiss::Cloner, GpuClonerOptions {
|
|
43
42
|
struct ToGpuClonerMultiple: faiss::Cloner, GpuMultipleClonerOptions {
|
44
43
|
std::vector<ToGpuCloner> sub_cloners;
|
45
44
|
|
46
|
-
ToGpuClonerMultiple(std::vector<
|
45
|
+
ToGpuClonerMultiple(std::vector<GpuResourcesProvider *> & provider,
|
47
46
|
std::vector<int>& devices,
|
48
47
|
const GpuMultipleClonerOptions &options);
|
49
48
|
|
@@ -67,12 +66,12 @@ faiss::Index * index_gpu_to_cpu(const faiss::Index *gpu_index);
|
|
67
66
|
|
68
67
|
/// converts any CPU index that can be converted to GPU
|
69
68
|
faiss::Index * index_cpu_to_gpu(
|
70
|
-
|
69
|
+
GpuResourcesProvider* provider, int device,
|
71
70
|
const faiss::Index *index,
|
72
71
|
const GpuClonerOptions *options = nullptr);
|
73
72
|
|
74
73
|
faiss::Index * index_cpu_to_gpu_multiple(
|
75
|
-
std::vector<
|
74
|
+
std::vector<GpuResourcesProvider*> & provider,
|
76
75
|
std::vector<int> &devices,
|
77
76
|
const faiss::Index *index,
|
78
77
|
const GpuMultipleClonerOptions *options = nullptr);
|
File without changes
|
File without changes
|
@@ -12,7 +12,7 @@
|
|
12
12
|
|
13
13
|
namespace faiss { namespace gpu {
|
14
14
|
|
15
|
-
class
|
15
|
+
class GpuResourcesProvider;
|
16
16
|
|
17
17
|
// Scalar type of the vector data
|
18
18
|
enum class DistanceDataType {
|
@@ -20,6 +20,12 @@ enum class DistanceDataType {
|
|
20
20
|
F16,
|
21
21
|
};
|
22
22
|
|
23
|
+
// Scalar type of the indices data
|
24
|
+
enum class IndicesDataType {
|
25
|
+
I64 = 1,
|
26
|
+
I32,
|
27
|
+
};
|
28
|
+
|
23
29
|
/// Arguments to brute-force GPU k-nearest neighbor searching
|
24
30
|
struct GpuDistanceParams {
|
25
31
|
GpuDistanceParams()
|
@@ -38,6 +44,7 @@ struct GpuDistanceParams {
|
|
38
44
|
numQueries(0),
|
39
45
|
outDistances(nullptr),
|
40
46
|
ignoreOutDistances(false),
|
47
|
+
outIndicesType(IndicesDataType::I64),
|
41
48
|
outIndices(nullptr) {
|
42
49
|
}
|
43
50
|
|
@@ -101,7 +108,8 @@ struct GpuDistanceParams {
|
|
101
108
|
|
102
109
|
// A region of memory size numQueries x k, with k
|
103
110
|
// innermost (row major)
|
104
|
-
|
111
|
+
IndicesDataType outIndicesType;
|
112
|
+
void* outIndices;
|
105
113
|
};
|
106
114
|
|
107
115
|
/// A wrapper for gpu/impl/Distance.cuh to expose direct brute-force k-nearest
|
@@ -116,10 +124,10 @@ struct GpuDistanceParams {
|
|
116
124
|
///
|
117
125
|
/// For each vector in `queries`, searches all of `vectors` to find its k
|
118
126
|
/// nearest neighbors with respect to the given metric
|
119
|
-
void bfKnn(
|
127
|
+
void bfKnn(GpuResourcesProvider* resources, const GpuDistanceParams& args);
|
120
128
|
|
121
129
|
/// Deprecated legacy implementation
|
122
|
-
void bruteForceKnn(
|
130
|
+
void bruteForceKnn(GpuResourcesProvider* resources,
|
123
131
|
faiss::MetricType metric,
|
124
132
|
// If vectorsRowMajor is true, this is
|
125
133
|
// numVectors x dims, with dims innermost; otherwise,
|
File without changes
|
@@ -9,12 +9,10 @@
|
|
9
9
|
#pragma once
|
10
10
|
|
11
11
|
#include <faiss/Index.h>
|
12
|
-
#include <faiss/gpu/
|
12
|
+
#include <faiss/gpu/GpuResources.h>
|
13
13
|
|
14
14
|
namespace faiss { namespace gpu {
|
15
15
|
|
16
|
-
class GpuResources;
|
17
|
-
|
18
16
|
struct GpuIndexConfig {
|
19
17
|
inline GpuIndexConfig()
|
20
18
|
: device(0),
|
@@ -32,7 +30,7 @@ struct GpuIndexConfig {
|
|
32
30
|
|
33
31
|
class GpuIndex : public faiss::Index {
|
34
32
|
public:
|
35
|
-
GpuIndex(GpuResources
|
33
|
+
GpuIndex(std::shared_ptr<GpuResources> resources,
|
36
34
|
int dims,
|
37
35
|
faiss::MetricType metric,
|
38
36
|
float metricArg,
|
@@ -42,10 +40,6 @@ class GpuIndex : public faiss::Index {
|
|
42
40
|
return device_;
|
43
41
|
}
|
44
42
|
|
45
|
-
inline GpuResources* getResources() {
|
46
|
-
return resources_;
|
47
|
-
}
|
48
|
-
|
49
43
|
/// Set the minimum data size for searches (in MiB) for which we use
|
50
44
|
/// CPU -> GPU paging
|
51
45
|
void setMinPagingSize(size_t size);
|
@@ -140,7 +134,7 @@ private:
|
|
140
134
|
|
141
135
|
protected:
|
142
136
|
/// Manages streams, cuBLAS handles and scratch memory for devices
|
143
|
-
GpuResources
|
137
|
+
std::shared_ptr<GpuResources> resources_;
|
144
138
|
|
145
139
|
/// The GPU device we are resident on
|
146
140
|
const int device_;
|
@@ -9,11 +9,12 @@
|
|
9
9
|
|
10
10
|
#include <faiss/IndexBinaryFlat.h>
|
11
11
|
#include <faiss/gpu/GpuIndex.h>
|
12
|
+
#include <faiss/gpu/GpuResources.h>
|
13
|
+
#include <memory>
|
12
14
|
|
13
15
|
namespace faiss { namespace gpu {
|
14
16
|
|
15
17
|
class BinaryFlatIndex;
|
16
|
-
class GpuResources;
|
17
18
|
|
18
19
|
struct GpuIndexBinaryFlatConfig : public GpuIndexConfig {
|
19
20
|
};
|
@@ -24,13 +25,13 @@ class GpuIndexBinaryFlat : public IndexBinary {
|
|
24
25
|
public:
|
25
26
|
/// Construct from a pre-existing faiss::IndexBinaryFlat instance, copying
|
26
27
|
/// data over to the given GPU
|
27
|
-
GpuIndexBinaryFlat(
|
28
|
+
GpuIndexBinaryFlat(GpuResourcesProvider* resources,
|
28
29
|
const faiss::IndexBinaryFlat* index,
|
29
30
|
GpuIndexBinaryFlatConfig config =
|
30
31
|
GpuIndexBinaryFlatConfig());
|
31
32
|
|
32
33
|
/// Construct an empty instance that can be added to
|
33
|
-
GpuIndexBinaryFlat(
|
34
|
+
GpuIndexBinaryFlat(GpuResourcesProvider* resources,
|
34
35
|
int dims,
|
35
36
|
GpuIndexBinaryFlatConfig config =
|
36
37
|
GpuIndexBinaryFlatConfig());
|
@@ -76,14 +77,13 @@ class GpuIndexBinaryFlat : public IndexBinary {
|
|
76
77
|
|
77
78
|
protected:
|
78
79
|
/// Manages streans, cuBLAS handles and scratch memory for devices
|
79
|
-
GpuResources
|
80
|
+
std::shared_ptr<GpuResources> resources_;
|
80
81
|
|
81
82
|
/// Configuration options
|
82
83
|
GpuIndexBinaryFlatConfig config_;
|
83
84
|
|
84
|
-
/// Holds our GPU data containing the list of vectors
|
85
|
-
|
86
|
-
BinaryFlatIndex* data_;
|
85
|
+
/// Holds our GPU data containing the list of vectors
|
86
|
+
std::unique_ptr<BinaryFlatIndex> data_;
|
87
87
|
};
|
88
88
|
|
89
89
|
} } // namespace gpu
|
@@ -9,6 +9,7 @@
|
|
9
9
|
#pragma once
|
10
10
|
|
11
11
|
#include <faiss/gpu/GpuIndex.h>
|
12
|
+
#include <memory>
|
12
13
|
|
13
14
|
namespace faiss {
|
14
15
|
|
@@ -47,12 +48,21 @@ class GpuIndexFlat : public GpuIndex {
|
|
47
48
|
public:
|
48
49
|
/// Construct from a pre-existing faiss::IndexFlat instance, copying
|
49
50
|
/// data over to the given GPU
|
50
|
-
GpuIndexFlat(
|
51
|
+
GpuIndexFlat(GpuResourcesProvider* provider,
|
52
|
+
const faiss::IndexFlat* index,
|
53
|
+
GpuIndexFlatConfig config = GpuIndexFlatConfig());
|
54
|
+
|
55
|
+
GpuIndexFlat(std::shared_ptr<GpuResources> resources,
|
51
56
|
const faiss::IndexFlat* index,
|
52
57
|
GpuIndexFlatConfig config = GpuIndexFlatConfig());
|
53
58
|
|
54
59
|
/// Construct an empty instance that can be added to
|
55
|
-
GpuIndexFlat(
|
60
|
+
GpuIndexFlat(GpuResourcesProvider* provider,
|
61
|
+
int dims,
|
62
|
+
faiss::MetricType metric,
|
63
|
+
GpuIndexFlatConfig config = GpuIndexFlatConfig());
|
64
|
+
|
65
|
+
GpuIndexFlat(std::shared_ptr<GpuResources> resources,
|
56
66
|
int dims,
|
57
67
|
faiss::MetricType metric,
|
58
68
|
GpuIndexFlatConfig config = GpuIndexFlatConfig());
|
@@ -100,7 +110,7 @@ class GpuIndexFlat : public GpuIndex {
|
|
100
110
|
const faiss::Index::idx_t* keys) const override;
|
101
111
|
|
102
112
|
/// For internal access
|
103
|
-
inline FlatIndex* getGpuData() { return data_; }
|
113
|
+
inline FlatIndex* getGpuData() { return data_.get(); }
|
104
114
|
|
105
115
|
protected:
|
106
116
|
/// Flat index does not require IDs as there is no storage available for them
|
@@ -122,9 +132,8 @@ class GpuIndexFlat : public GpuIndex {
|
|
122
132
|
/// Our config object
|
123
133
|
const GpuIndexFlatConfig config_;
|
124
134
|
|
125
|
-
/// Holds our GPU data containing the list of vectors
|
126
|
-
|
127
|
-
FlatIndex* data_;
|
135
|
+
/// Holds our GPU data containing the list of vectors
|
136
|
+
std::unique_ptr<FlatIndex> data_;
|
128
137
|
};
|
129
138
|
|
130
139
|
/// Wrapper around the GPU implementation that looks like
|
@@ -134,12 +143,20 @@ class GpuIndexFlatL2 : public GpuIndexFlat {
|
|
134
143
|
public:
|
135
144
|
/// Construct from a pre-existing faiss::IndexFlatL2 instance, copying
|
136
145
|
/// data over to the given GPU
|
137
|
-
GpuIndexFlatL2(
|
146
|
+
GpuIndexFlatL2(GpuResourcesProvider* provider,
|
147
|
+
faiss::IndexFlatL2* index,
|
148
|
+
GpuIndexFlatConfig config = GpuIndexFlatConfig());
|
149
|
+
|
150
|
+
GpuIndexFlatL2(std::shared_ptr<GpuResources> resources,
|
138
151
|
faiss::IndexFlatL2* index,
|
139
152
|
GpuIndexFlatConfig config = GpuIndexFlatConfig());
|
140
153
|
|
141
154
|
/// Construct an empty instance that can be added to
|
142
|
-
GpuIndexFlatL2(
|
155
|
+
GpuIndexFlatL2(GpuResourcesProvider* provider,
|
156
|
+
int dims,
|
157
|
+
GpuIndexFlatConfig config = GpuIndexFlatConfig());
|
158
|
+
|
159
|
+
GpuIndexFlatL2(std::shared_ptr<GpuResources> resources,
|
143
160
|
int dims,
|
144
161
|
GpuIndexFlatConfig config = GpuIndexFlatConfig());
|
145
162
|
|
@@ -159,12 +176,20 @@ class GpuIndexFlatIP : public GpuIndexFlat {
|
|
159
176
|
public:
|
160
177
|
/// Construct from a pre-existing faiss::IndexFlatIP instance, copying
|
161
178
|
/// data over to the given GPU
|
162
|
-
GpuIndexFlatIP(
|
179
|
+
GpuIndexFlatIP(GpuResourcesProvider* provider,
|
180
|
+
faiss::IndexFlatIP* index,
|
181
|
+
GpuIndexFlatConfig config = GpuIndexFlatConfig());
|
182
|
+
|
183
|
+
GpuIndexFlatIP(std::shared_ptr<GpuResources> resources,
|
163
184
|
faiss::IndexFlatIP* index,
|
164
185
|
GpuIndexFlatConfig config = GpuIndexFlatConfig());
|
165
186
|
|
166
187
|
/// Construct an empty instance that can be added to
|
167
|
-
GpuIndexFlatIP(
|
188
|
+
GpuIndexFlatIP(GpuResourcesProvider* provider,
|
189
|
+
int dims,
|
190
|
+
GpuIndexFlatConfig config = GpuIndexFlatConfig());
|
191
|
+
|
192
|
+
GpuIndexFlatIP(std::shared_ptr<GpuResources> resources,
|
168
193
|
int dims,
|
169
194
|
GpuIndexFlatConfig config = GpuIndexFlatConfig());
|
170
195
|
|
@@ -18,7 +18,6 @@ namespace faiss { struct IndexIVF; }
|
|
18
18
|
namespace faiss { namespace gpu {
|
19
19
|
|
20
20
|
class GpuIndexFlat;
|
21
|
-
class GpuResources;
|
22
21
|
|
23
22
|
struct GpuIndexIVFConfig : public GpuIndexConfig {
|
24
23
|
inline GpuIndexIVFConfig()
|
@@ -34,7 +33,7 @@ struct GpuIndexIVFConfig : public GpuIndexConfig {
|
|
34
33
|
|
35
34
|
class GpuIndexIVF : public GpuIndex {
|
36
35
|
public:
|
37
|
-
GpuIndexIVF(
|
36
|
+
GpuIndexIVF(GpuResourcesProvider* provider,
|
38
37
|
int dims,
|
39
38
|
faiss::MetricType metric,
|
40
39
|
float metricArg,
|
@@ -9,6 +9,7 @@
|
|
9
9
|
#pragma once
|
10
10
|
|
11
11
|
#include <faiss/gpu/GpuIndexIVF.h>
|
12
|
+
#include <memory>
|
12
13
|
|
13
14
|
namespace faiss { struct IndexIVFFlat; }
|
14
15
|
|
@@ -26,13 +27,13 @@ class GpuIndexIVFFlat : public GpuIndexIVF {
|
|
26
27
|
public:
|
27
28
|
/// Construct from a pre-existing faiss::IndexIVFFlat instance, copying
|
28
29
|
/// data over to the given GPU, if the input index is trained.
|
29
|
-
GpuIndexIVFFlat(
|
30
|
+
GpuIndexIVFFlat(GpuResourcesProvider* provider,
|
30
31
|
const faiss::IndexIVFFlat* index,
|
31
32
|
GpuIndexIVFFlatConfig config = GpuIndexIVFFlatConfig());
|
32
33
|
|
33
34
|
/// Constructs a new instance with an empty flat quantizer; the user
|
34
35
|
/// provides the number of lists desired.
|
35
|
-
GpuIndexIVFFlat(
|
36
|
+
GpuIndexIVFFlat(GpuResourcesProvider* provider,
|
36
37
|
int dims,
|
37
38
|
int nlist,
|
38
39
|
faiss::MetricType metric,
|
@@ -79,7 +80,7 @@ class GpuIndexIVFFlat : public GpuIndexIVF {
|
|
79
80
|
size_t reserveMemoryVecs_;
|
80
81
|
|
81
82
|
/// Instance that we own; contains the inverted list
|
82
|
-
IVFFlat
|
83
|
+
std::unique_ptr<IVFFlat> index_;
|
83
84
|
};
|
84
85
|
|
85
86
|
} } // namespace
|