Faiss
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
GpuIndexIVF.h
1 
2 /**
3  * Copyright (c) 2015-present, Facebook, Inc.
4  * All rights reserved.
5  *
6  * This source code is licensed under the CC-by-NC license found in the
7  * LICENSE file in the root directory of this source tree.
8  */
9 
10 // Copyright 2004-present Facebook. All Rights Reserved.
11 
12 #pragma once
13 
14 #include "GpuIndex.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 
25 class GpuIndexIVF : public GpuIndex {
26  public:
27  GpuIndexIVF(GpuResources* resources,
28  int device,
29  IndicesOptions indicesOptions,
30  bool useFloat16CoarseQuantizer,
31  int dims,
32  faiss::MetricType metric,
33  int nlist);
34 
35  GpuIndexIVF(GpuResources* resources,
36  int device,
37  IndicesOptions indicesOptions,
38  int dims,
39  faiss::MetricType metric,
40  int nlist,
41  GpuIndexFlat* quantizer);
42 
43  ~GpuIndexIVF() override;
44 
45  private:
46  /// Shared initialization functions
47  void init_();
48 
49  public:
50  /// What indices storage options are we using?
51  IndicesOptions getIndicesOptions() const;
52 
53  /// Is our coarse quantizer storing and performing math in float16?
54  bool getUseFloat16CoarseQuantizer() const;
55 
56  /// Copy what we need from the CPU equivalent
57  void copyFrom(const faiss::IndexIVF* index);
58 
59  /// Copy what we have to the CPU equivalent
60  void copyTo(faiss::IndexIVF* index) const;
61 
62  /// Returns the number of inverted lists we're managing
63  int getNumLists() const;
64 
65  /// Sets the number of list probes per query
66  void setNumProbes(int nprobe);
67 
68  /// Returns our current number of list probes per query
69  int getNumProbes() const;
70 
71  /// `x` can be resident on the CPU or any GPU; the proper copies are
72  /// performed
73  /// Forwards to add_with_ids
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  protected:
80  /// How should indices be stored on the GPU?
81  const IndicesOptions indicesOptions_;
82 
83  /// Do we want to use float16 storage and math in our coarse
84  /// quantizer?
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  /// Ability to override default clustering parameters
95 
96  /// Quantizer for inverted lists
98 
99  /// Do we own the above quantizer instance?
101 };
102 
103 } } // namespace
IndicesOptions getIndicesOptions() const
What indices storage options are we using?
Definition: GpuIndexIVF.cu:107
int getNumProbes() const
Returns our current number of list probes per query.
Definition: GpuIndexIVF.cu:241
void setNumProbes(int nprobe)
Sets the number of list probes per query.
Definition: GpuIndexIVF.cu:235
const bool useFloat16CoarseQuantizer_
Definition: GpuIndexIVF.h:85
int getNumLists() const
Returns the number of inverted lists we're managing.
Definition: GpuIndexIVF.cu:230
bool getUseFloat16CoarseQuantizer() const
Is our coarse quantizer storing and performing math in float16?
Definition: GpuIndexIVF.cu:112
int nprobe_
Number of inverted list probes per query.
Definition: GpuIndexIVF.h:91
const IndicesOptions indicesOptions_
How should indices be stored on the GPU?
Definition: GpuIndexIVF.h:81
void copyTo(faiss::IndexIVF *index) const
Copy what we have to the CPU equivalent.
Definition: GpuIndexIVF.cu:181
long idx_t
all indices are this type
Definition: Index.h:64
int nlist_
Number of inverted lists that we manage.
Definition: GpuIndexIVF.h:88
GpuIndexFlat * quantizer_
Quantizer for inverted lists.
Definition: GpuIndexIVF.h:97
ClusteringParameters cp_
Ability to override default clustering parameters.
Definition: GpuIndexIVF.h:94
void copyFrom(const faiss::IndexIVF *index)
Copy what we need from the CPU equivalent.
Definition: GpuIndexIVF.cu:117
bool ownsQuantizer_
Do we own the above quantizer instance?
Definition: GpuIndexIVF.h:100
void add(Index::idx_t n, const float *x) override
Definition: GpuIndexIVF.cu:247
MetricType
Some algorithms support both an inner product vetsion and a L2 search version.
Definition: Index.h:44