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 // Copyright 2004-present Facebook. All Rights Reserved.
10 
11 #pragma once
12 
13 #include "GpuIndex.h"
14 #include "GpuIndexFlat.h"
15 #include "GpuIndicesOptions.h"
16 #include "../Clustering.h"
17 
18 namespace faiss { struct IndexIVF; }
19 
20 namespace faiss { namespace gpu {
21 
22 class GpuIndexFlat;
23 class GpuResources;
24 
26  inline GpuIndexIVFConfig()
27  : indicesOptions(INDICES_64_BIT) {
28  }
29 
30  /// Index storage options for the GPU
31  IndicesOptions indicesOptions;
32 
33  /// Configuration for the coarse quantizer object
35 };
36 
37 class GpuIndexIVF : public GpuIndex {
38  public:
39  GpuIndexIVF(GpuResources* resources,
40  int dims,
41  faiss::MetricType metric,
42  int nlist,
44 
45  ~GpuIndexIVF() override;
46 
47  private:
48  /// Shared initialization functions
49  void init_();
50 
51  public:
52  /// Copy what we need from the CPU equivalent
53  void copyFrom(const faiss::IndexIVF* index);
54 
55  /// Copy what we have to the CPU equivalent
56  void copyTo(faiss::IndexIVF* index) const;
57 
58  /// Returns the number of inverted lists we're managing
59  int getNumLists() const;
60 
61  /// Return the quantizer we're using
63 
64  /// Sets the number of list probes per query
65  void setNumProbes(int nprobe);
66 
67  /// Returns our current number of list probes per query
68  int getNumProbes() const;
69 
70  /// `x` can be resident on the CPU or any GPU; the proper copies are
71  /// performed
72  /// Forwards to add_with_ids; assigns IDs as needed
73  /// FIXME: remove override for C++03 compatibility
74  void add(Index::idx_t n, const float* x) override;
75 
76  protected:
77  void trainQuantizer_(faiss::Index::idx_t n, const float* x);
78 
79  public:
80  /// Exposed as IndexIVF does to allow overriding clustering
81  /// parameters
83 
84  protected:
85  GpuIndexIVFConfig ivfConfig_;
86 
87  /// Number of inverted lists that we manage
88  int nlist_;
89 
90  /// Number of inverted list probes per query
91  int nprobe_;
92 
93  /// Quantizer for inverted lists
95 };
96 
97 } } // namespace
int getNumProbes() const
Returns our current number of list probes per query.
Definition: GpuIndexIVF.cu:210
void setNumProbes(int nprobe)
Sets the number of list probes per query.
Definition: GpuIndexIVF.cu:202
int getNumLists() const
Returns the number of inverted lists we're managing.
Definition: GpuIndexIVF.cu:197
GpuIndexFlatConfig flatConfig
Configuration for the coarse quantizer object.
Definition: GpuIndexIVF.h:34
GpuIndexFlat * getQuantizer()
Return the quantizer we're using.
Definition: GpuIndexIVF.cu:75
int nprobe_
Number of inverted list probes per query.
Definition: GpuIndexIVF.h:91
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:62
int nlist_
Number of inverted lists that we manage.
Definition: GpuIndexIVF.h:88
GpuIndexFlat * quantizer_
Quantizer for inverted lists.
Definition: GpuIndexIVF.h:94
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:215
ClusteringParameters cp
Definition: GpuIndexIVF.h:82
IndicesOptions indicesOptions
Index storage options for the GPU.
Definition: GpuIndexIVF.h:31
MetricType
Some algorithms support both an inner product vetsion and a L2 search version.
Definition: Index.h:43