Faiss

- Main Page
- Namespaces
- Classes
- Files

- File List

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
23 struct GpuIndexIVFConfig : public GpuIndexConfig {
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
32 GpuIndexFlatConfig flatConfig;
33 };
34
35 class GpuIndexIVF : public GpuIndex {
36 public:
37 GpuIndexIVF(GpuResources* resources,
38 int dims,
39 faiss::MetricType metric,
40 int nlist,
41 GpuIndexIVFConfig config = GpuIndexIVFConfig());
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
60 GpuIndexFlat* getQuantizer();
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
75 ClusteringParameters cp;
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
87 GpuIndexFlat* quantizer_;
88 };
89
90 } } // namespace
faiss::IndexIVF
Definition: IndexIVF.h:90
faiss::gpu::GpuIndexIVF::getNumProbes
int getNumProbes() const
Returns our current number of list probes per query.
Definition: GpuIndexIVF.cu:214
faiss::gpu::GpuIndexIVF::setNumProbes
void setNumProbes(int nprobe)
Sets the number of list probes per query.
Definition: GpuIndexIVF.cu:205
faiss::gpu::GpuIndexIVF::getNumLists
int getNumLists() const
Returns the number of inverted lists we&#39;re managing.
Definition: GpuIndexIVF.cu:200
faiss::gpu::GpuIndexIVFConfig
Definition: GpuIndexIVF.h:23
faiss::gpu::GpuResources
Definition: GpuResources.h:21
faiss::gpu::GpuIndex
Definition: GpuIndex.h:33
faiss::gpu::GpuIndexIVF::addImplRequiresIDs_
bool addImplRequiresIDs_() const override
Definition: GpuIndexIVF.cu:219
faiss::gpu::GpuIndexIVF
Definition: GpuIndexIVF.h:35
faiss::Index::idx_t
long idx_t
all indices are this type
Definition: Index.h:62
faiss::gpu::GpuIndexFlatConfig
Definition: GpuIndexFlat.h:25
faiss::gpu::GpuIndexIVFConfig::flatConfig
GpuIndexFlatConfig flatConfig
Configuration for the coarse quantizer object.
Definition: GpuIndexIVF.h:32
faiss::gpu::GpuIndexIVF::getQuantizer
GpuIndexFlat * getQuantizer()
Return the quantizer we&#39;re using.
Definition: GpuIndexIVF.cu:74
faiss::gpu::GpuIndexIVF::nprobe_
int nprobe_
Number of inverted list probes per query.
Definition: GpuIndexIVF.h:84
faiss::gpu::GpuIndexIVF::copyTo
void copyTo(faiss::IndexIVF *index) const
Copy what we have to the CPU equivalent.
Definition: GpuIndexIVF.cu:153
faiss::gpu::GpuIndexIVF::nlist_
int nlist_
Number of inverted lists that we manage.
Definition: GpuIndexIVF.h:81
faiss::gpu::GpuIndexIVF::quantizer_
GpuIndexFlat * quantizer_
Quantizer for inverted lists.
Definition: GpuIndexIVF.h:87
faiss::ClusteringParameters
Definition: Clustering.h:22
faiss::gpu::GpuIndexConfig
Definition: GpuIndex.h:18
faiss::gpu::GpuIndexFlat
Definition: GpuIndexFlat.h:52
faiss::gpu::GpuIndexIVF::copyFrom
void copyFrom(const faiss::IndexIVF *index)
Copy what we need from the CPU equivalent.
Definition: GpuIndexIVF.cu:79
faiss::gpu::GpuIndexIVF::cp
ClusteringParameters cp
Definition: GpuIndexIVF.h:75
faiss::gpu::GpuIndexIVFConfig::indicesOptions
IndicesOptions indicesOptions
Index storage options for the GPU.
Definition: GpuIndexIVF.h:29
faiss::MetricType
MetricType
Some algorithms support both an inner product version and a L2 search version.
Definition: Index.h:44