Faiss
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
IndexWrapper.h
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 
9 #pragma once
10 
11 #include "../../IndexReplicas.h"
12 #include "../StandardGpuResources.h"
13 #include <functional>
14 #include <memory>
15 #include <vector>
16 
17 namespace faiss { namespace gpu {
18 
19 // If we want to run multi-GPU, create a proxy to wrap the indices.
20 // If we don't want multi-GPU, don't involve the proxy, so it doesn't
21 // affect the timings.
22 template <typename GpuIndex>
23 struct IndexWrapper {
24  std::vector<std::unique_ptr<faiss::gpu::StandardGpuResources>> resources;
25  std::vector<std::unique_ptr<GpuIndex>> subIndex;
26  std::unique_ptr<faiss::IndexReplicas> replicaIndex;
27 
29  int numGpus,
30  std::function<std::unique_ptr<GpuIndex>(GpuResources*, int)> init);
31  faiss::Index* getIndex();
32 
33  void runOnIndices(std::function<void(GpuIndex*)> f);
34  void setNumProbes(int nprobe);
35 };
36 
37 } }
38 
39 #include "IndexWrapper-inl.h"