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 // 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
25 struct GpuIndexIVFConfig : public GpuIndexConfig {
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
34 GpuIndexFlatConfig flatConfig;
35 };
36
37 class GpuIndexIVF : public GpuIndex {
38 public:
39 GpuIndexIVF(GpuResources* resources,
40 int dims,
41 faiss::MetricType metric,
42 int nlist,
43 GpuIndexIVFConfig config = GpuIndexIVFConfig());
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
62 GpuIndexFlat* getQuantizer();
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
82 ClusteringParameters cp;
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
94 GpuIndexFlat* quantizer_;
95 };
96
97 } } // namespace
faiss::IndexIVF
Definition: IndexIVF.h:77
faiss::gpu::GpuIndexIVF::getNumProbes
int getNumProbes() const
Returns our current number of list probes per query.
Definition: GpuIndexIVF.cu:211
faiss::gpu::GpuIndexIVF::setNumProbes
void setNumProbes(int nprobe)
Sets the number of list probes per query.
Definition: GpuIndexIVF.cu:203
faiss::gpu::GpuIndexIVF::getNumLists
int getNumLists() const
Returns the number of inverted lists we&#39;re managing.
Definition: GpuIndexIVF.cu:198
faiss::gpu::GpuIndexIVFConfig
Definition: GpuIndexIVF.h:25
faiss::gpu::GpuResources
Definition: GpuResources.h:23
faiss::gpu::GpuIndex
Definition: GpuIndex.h:35
faiss::gpu::GpuIndexIVF
Definition: GpuIndexIVF.h:37
faiss::gpu::GpuIndexFlatConfig
Definition: GpuIndexFlat.h:27
faiss::gpu::GpuIndexIVFConfig::flatConfig
GpuIndexFlatConfig flatConfig
Configuration for the coarse quantizer object.
Definition: GpuIndexIVF.h:34
faiss::gpu::GpuIndexIVF::getQuantizer
GpuIndexFlat * getQuantizer()
Return the quantizer we&#39;re using.
Definition: GpuIndexIVF.cu:76
faiss::gpu::GpuIndexIVF::nprobe_
int nprobe_
Number of inverted list probes per query.
Definition: GpuIndexIVF.h:91
faiss::gpu::GpuIndexIVF::copyTo
void copyTo(faiss::IndexIVF *index) const
Copy what we have to the CPU equivalent.
Definition: GpuIndexIVF.cu:149
faiss::Index::idx_t
long idx_t
all indices are this type
Definition: Index.h:62
faiss::gpu::GpuIndexIVF::nlist_
int nlist_
Number of inverted lists that we manage.
Definition: GpuIndexIVF.h:88
faiss::gpu::GpuIndexIVF::quantizer_
GpuIndexFlat * quantizer_
Quantizer for inverted lists.
Definition: GpuIndexIVF.h:94
faiss::ClusteringParameters
Definition: Clustering.h:24
faiss::gpu::GpuIndexConfig
Definition: GpuIndex.h:20
faiss::gpu::GpuIndexFlat
Definition: GpuIndexFlat.h:54
faiss::gpu::GpuIndexIVF::copyFrom
void copyFrom(const faiss::IndexIVF *index)
Copy what we need from the CPU equivalent.
Definition: GpuIndexIVF.cu:81
faiss::gpu::GpuIndexIVF::add
void add(Index::idx_t n, const float *x) override
Definition: GpuIndexIVF.cu:216
faiss::gpu::GpuIndexIVF::cp
ClusteringParameters cp
Definition: GpuIndexIVF.h:82
faiss::gpu::GpuIndexIVFConfig::indicesOptions
IndicesOptions indicesOptions
Index storage options for the GPU.
Definition: GpuIndexIVF.h:31
faiss::MetricType
MetricType
Some algorithms support both an inner product version and a L2 search version.
Definition: Index.h:43