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 CC-by-NC 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 protected:
80 GpuIndexIVFConfig ivfConfig_;
81
82 /// Number of inverted lists that we manage
83 int nlist_;
84
85 /// Number of inverted list probes per query
86 int nprobe_;
87
88 /// Ability to override default clustering parameters
89 ClusteringParameters cp_;
90
91 /// Quantizer for inverted lists
92 GpuIndexFlat* quantizer_;
93 };
94
95 } } // namespace
faiss::IndexIVF
Definition: IndexIVF.h:45
faiss::gpu::GpuIndexIVF::getNumProbes
int getNumProbes() const
Returns our current number of list probes per query.
Definition: GpuIndexIVF.cu:210
faiss::gpu::GpuIndexIVF::setNumProbes
void setNumProbes(int nprobe)
Sets the number of list probes per query.
Definition: GpuIndexIVF.cu:202
faiss::gpu::GpuIndexIVF::getNumLists
int getNumLists() const
Returns the number of inverted lists we&#39;re managing.
Definition: GpuIndexIVF.cu:197
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:75
faiss::gpu::GpuIndexIVF::nprobe_
int nprobe_
Number of inverted list probes per query.
Definition: GpuIndexIVF.h:86
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:62
faiss::gpu::GpuIndexIVF::nlist_
int nlist_
Number of inverted lists that we manage.
Definition: GpuIndexIVF.h:83
faiss::gpu::GpuIndexIVF::quantizer_
GpuIndexFlat * quantizer_
Quantizer for inverted lists.
Definition: GpuIndexIVF.h:92
faiss::ClusteringParameters
Definition: Clustering.h:24
faiss::gpu::GpuIndexConfig
Definition: GpuIndex.h:20
faiss::gpu::GpuIndexIVF::cp_
ClusteringParameters cp_
Ability to override default clustering parameters.
Definition: GpuIndexIVF.h:89
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:80
faiss::gpu::GpuIndexIVF::add
void add(Index::idx_t n, const float *x) override
Definition: GpuIndexIVF.cu:215
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 vetsion and a L2 search version.
Definition: Index.h:43