Faiss

- Main Page
- Namespaces
- Classes
- Files

- File List

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
24 struct GpuIndexIVFConfig : public GpuIndexConfig {
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
33 GpuIndexFlatConfig flatConfig;
34 };
35
36 class GpuIndexIVF : public GpuIndex {
37 public:
38 GpuIndexIVF(GpuResources* resources,
39 int dims,
40 faiss::MetricType metric,
41 int nlist,
42 GpuIndexIVFConfig config = GpuIndexIVFConfig());
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
61 GpuIndexFlat* getQuantizer();
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
81 ClusteringParameters cp;
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
93 GpuIndexFlat* quantizer_;
94 };
95
96 } } // namespace
faiss::IndexIVF
Definition: IndexIVF.h:91
faiss::gpu::GpuIndexIVF::getNumProbes
int getNumProbes() const
Returns our current number of list probes per query.
Definition: GpuIndexIVF.cu:208
faiss::gpu::GpuIndexIVF::setNumProbes
void setNumProbes(int nprobe)
Sets the number of list probes per query.
Definition: GpuIndexIVF.cu:200
faiss::gpu::GpuIndexIVF::getNumLists
int getNumLists() const
Returns the number of inverted lists we&#39;re managing.
Definition: GpuIndexIVF.cu:195
faiss::gpu::GpuIndexIVFConfig
Definition: GpuIndexIVF.h:24
faiss::gpu::GpuResources
Definition: GpuResources.h:22
faiss::gpu::GpuIndex
Definition: GpuIndex.h:34
faiss::gpu::GpuIndexIVF
Definition: GpuIndexIVF.h:36
faiss::gpu::GpuIndexFlatConfig
Definition: GpuIndexFlat.h:26
faiss::gpu::GpuIndexIVFConfig::flatConfig
GpuIndexFlatConfig flatConfig
Configuration for the coarse quantizer object.
Definition: GpuIndexIVF.h:33
faiss::gpu::GpuIndexIVF::getQuantizer
GpuIndexFlat * getQuantizer()
Return the quantizer we&#39;re using.
Definition: GpuIndexIVF.cu:75
faiss::gpu::GpuIndexIVF::nprobe_
int nprobe_
Number of inverted list probes per query.
Definition: GpuIndexIVF.h:90
faiss::gpu::GpuIndexIVF::copyTo
void copyTo(faiss::IndexIVF *index) const
Copy what we have to the CPU equivalent.
Definition: GpuIndexIVF.cu:148
faiss::Index::idx_t
long idx_t
all indices are this type
Definition: Index.h:64
faiss::gpu::GpuIndexIVF::nlist_
int nlist_
Number of inverted lists that we manage.
Definition: GpuIndexIVF.h:87
faiss::gpu::GpuIndexIVF::quantizer_
GpuIndexFlat * quantizer_
Quantizer for inverted lists.
Definition: GpuIndexIVF.h:93
faiss::ClusteringParameters
Definition: Clustering.h:23
faiss::gpu::GpuIndexConfig
Definition: GpuIndex.h:19
faiss::gpu::GpuIndexFlat
Definition: GpuIndexFlat.h:53
faiss::gpu::GpuIndexIVF::copyFrom
void copyFrom(const faiss::IndexIVF *index)
Copy what we need from the CPU equivalent.
Definition: GpuIndexIVF.cu:80
faiss::gpu::GpuIndexIVF::add
void add(Index::idx_t n, const float *x) override
Definition: GpuIndexIVF.cu:213
faiss::gpu::GpuIndexIVF::cp
ClusteringParameters cp
Definition: GpuIndexIVF.h:81
faiss::gpu::GpuIndexIVFConfig::indicesOptions
IndicesOptions indicesOptions
Index storage options for the GPU.
Definition: GpuIndexIVF.h:30
faiss::MetricType
MetricType
Some algorithms support both an inner product version and a L2 search version.
Definition: Index.h:45