Faiss
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
GpuIndexIVF.h
1 /**
2  * Copyright (c) 2015-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD+Patents license found in the
6  * LICENSE file in the root directory of this source tree.
7  */
8 
9 
10 #pragma once
11 
12 #include "GpuIndex.h"
13 #include "GpuIndexFlat.h"
14 #include "GpuIndicesOptions.h"
15 #include "../Clustering.h"
16 
17 namespace faiss { struct IndexIVF; }
18 
19 namespace faiss { namespace gpu {
20 
21 class GpuIndexFlat;
22 class GpuResources;
23 
25  inline GpuIndexIVFConfig()
26  : indicesOptions(INDICES_64_BIT) {
27  }
28 
29  /// Index storage options for the GPU
30  IndicesOptions indicesOptions;
31 
32  /// Configuration for the coarse quantizer object
34 };
35 
36 class GpuIndexIVF : public GpuIndex {
37  public:
38  GpuIndexIVF(GpuResources* resources,
39  int dims,
40  faiss::MetricType metric,
41  int nlist,
43 
44  ~GpuIndexIVF() override;
45 
46  private:
47  /// Shared initialization functions
48  void init_();
49 
50  public:
51  /// Copy what we need from the CPU equivalent
52  void copyFrom(const faiss::IndexIVF* index);
53 
54  /// Copy what we have to the CPU equivalent
55  void copyTo(faiss::IndexIVF* index) const;
56 
57  /// Returns the number of inverted lists we're managing
58  int getNumLists() const;
59 
60  /// Return the quantizer we're using
62 
63  /// Sets the number of list probes per query
64  void setNumProbes(int nprobe);
65 
66  /// Returns our current number of list probes per query
67  int getNumProbes() const;
68 
69  /// `x` can be resident on the CPU or any GPU; the proper copies are
70  /// performed
71  /// Forwards to add_with_ids; assigns IDs as needed
72  /// FIXME: remove override for C++03 compatibility
73  void add(Index::idx_t n, const float* x) override;
74 
75  protected:
76  void trainQuantizer_(faiss::Index::idx_t n, const float* x);
77 
78  public:
79  /// Exposed as IndexIVF does to allow overriding clustering
80  /// parameters
82 
83  protected:
84  GpuIndexIVFConfig ivfConfig_;
85 
86  /// Number of inverted lists that we manage
87  int nlist_;
88 
89  /// Number of inverted list probes per query
90  int nprobe_;
91 
92  /// Quantizer for inverted lists
94 };
95 
96 } } // namespace
int getNumProbes() const
Returns our current number of list probes per query.
Definition: GpuIndexIVF.cu:208
void setNumProbes(int nprobe)
Sets the number of list probes per query.
Definition: GpuIndexIVF.cu:200
int getNumLists() const
Returns the number of inverted lists we're managing.
Definition: GpuIndexIVF.cu:195
GpuIndexFlatConfig flatConfig
Configuration for the coarse quantizer object.
Definition: GpuIndexIVF.h:33
GpuIndexFlat * getQuantizer()
Return the quantizer we're using.
Definition: GpuIndexIVF.cu:75
int nprobe_
Number of inverted list probes per query.
Definition: GpuIndexIVF.h:90
void copyTo(faiss::IndexIVF *index) const
Copy what we have to the CPU equivalent.
Definition: GpuIndexIVF.cu:148
long idx_t
all indices are this type
Definition: Index.h:64
int nlist_
Number of inverted lists that we manage.
Definition: GpuIndexIVF.h:87
GpuIndexFlat * quantizer_
Quantizer for inverted lists.
Definition: GpuIndexIVF.h:93
void copyFrom(const faiss::IndexIVF *index)
Copy what we need from the CPU equivalent.
Definition: GpuIndexIVF.cu:80
void add(Index::idx_t n, const float *x) override
Definition: GpuIndexIVF.cu:213
ClusteringParameters cp
Definition: GpuIndexIVF.h:81
IndicesOptions indicesOptions
Index storage options for the GPU.
Definition: GpuIndexIVF.h:30
MetricType
Some algorithms support both an inner product version and a L2 search version.
Definition: Index.h:45