Faiss
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
GpuIndexIVF.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 "GpuIndex.h"
12 #include "GpuIndexFlat.h"
13 #include "GpuIndicesOptions.h"
14 #include "../Clustering.h"
15 
16 namespace faiss { struct IndexIVF; }
17 
18 namespace faiss { namespace gpu {
19 
20 class GpuIndexFlat;
21 class GpuResources;
22 
24  inline GpuIndexIVFConfig()
25  : indicesOptions(INDICES_64_BIT) {
26  }
27 
28  /// Index storage options for the GPU
29  IndicesOptions indicesOptions;
30 
31  /// Configuration for the coarse quantizer object
33 };
34 
35 class GpuIndexIVF : public GpuIndex {
36  public:
37  GpuIndexIVF(GpuResources* resources,
38  int dims,
39  faiss::MetricType metric,
40  int nlist,
42 
43  ~GpuIndexIVF() override;
44 
45  private:
46  /// Shared initialization functions
47  void init_();
48 
49  public:
50  /// Copy what we need from the CPU equivalent
51  void copyFrom(const faiss::IndexIVF* index);
52 
53  /// Copy what we have to the CPU equivalent
54  void copyTo(faiss::IndexIVF* index) const;
55 
56  /// Returns the number of inverted lists we're managing
57  int getNumLists() const;
58 
59  /// Return the quantizer we're using
61 
62  /// Sets the number of list probes per query
63  void setNumProbes(int nprobe);
64 
65  /// Returns our current number of list probes per query
66  int getNumProbes() const;
67 
68  protected:
69  bool addImplRequiresIDs_() const override;
70  void trainQuantizer_(faiss::Index::idx_t n, const float* x);
71 
72  public:
73  /// Exposed as IndexIVF does to allow overriding clustering
74  /// parameters
76 
77  protected:
78  GpuIndexIVFConfig ivfConfig_;
79 
80  /// Number of inverted lists that we manage
81  int nlist_;
82 
83  /// Number of inverted list probes per query
84  int nprobe_;
85 
86  /// Quantizer for inverted lists
88 };
89 
90 } } // namespace
int getNumProbes() const
Returns our current number of list probes per query.
Definition: GpuIndexIVF.cu:214
void setNumProbes(int nprobe)
Sets the number of list probes per query.
Definition: GpuIndexIVF.cu:205
int getNumLists() const
Returns the number of inverted lists we're managing.
Definition: GpuIndexIVF.cu:200
bool addImplRequiresIDs_() const override
Definition: GpuIndexIVF.cu:219
long idx_t
all indices are this type
Definition: Index.h:62
GpuIndexFlatConfig flatConfig
Configuration for the coarse quantizer object.
Definition: GpuIndexIVF.h:32
GpuIndexFlat * getQuantizer()
Return the quantizer we're using.
Definition: GpuIndexIVF.cu:74
int nprobe_
Number of inverted list probes per query.
Definition: GpuIndexIVF.h:84
void copyTo(faiss::IndexIVF *index) const
Copy what we have to the CPU equivalent.
Definition: GpuIndexIVF.cu:153
int nlist_
Number of inverted lists that we manage.
Definition: GpuIndexIVF.h:81
GpuIndexFlat * quantizer_
Quantizer for inverted lists.
Definition: GpuIndexIVF.h:87
void copyFrom(const faiss::IndexIVF *index)
Copy what we need from the CPU equivalent.
Definition: GpuIndexIVF.cu:79
ClusteringParameters cp
Definition: GpuIndexIVF.h:75
IndicesOptions indicesOptions
Index storage options for the GPU.
Definition: GpuIndexIVF.h:29
MetricType
Some algorithms support both an inner product version and a L2 search version.
Definition: Index.h:44