Faiss

- Main Page
- Namespaces
- Classes
- Files

- File List

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; assigns IDs as needed
74 /// FIXME: remove override for C++03 compatibility
75 void add(Index::idx_t n, const float* x) override;
76
77 protected:
78 void trainQuantizer_(faiss::Index::idx_t n, const float* x);
79
80 protected:
81 /// How should indices be stored on the GPU?
82 const IndicesOptions indicesOptions_;
83
84 /// Do we want to use float16 storage and math in our coarse
85 /// quantizer?
86 const bool useFloat16CoarseQuantizer_;
87
88 /// Number of inverted lists that we manage
89 int nlist_;
90
91 /// Number of inverted list probes per query
92 int nprobe_;
93
94 /// Ability to override default clustering parameters
95 ClusteringParameters cp_;
96
97 /// Quantizer for inverted lists
98 GpuIndexFlat* quantizer_;
99
100 /// Do we own the above quantizer instance?
101 bool ownsQuantizer_;
102 };
103
104 } } // namespace
faiss::IndexIVF
Definition: IndexIVF.h:46
faiss::gpu::GpuIndexIVF::getIndicesOptions
IndicesOptions getIndicesOptions() const
What indices storage options are we using?
Definition: GpuIndexIVF.cu:110
faiss::gpu::GpuIndexIVF::getNumProbes
int getNumProbes() const
Returns our current number of list probes per query.
Definition: GpuIndexIVF.cu:247
faiss::gpu::GpuIndexIVF::setNumProbes
void setNumProbes(int nprobe)
Sets the number of list probes per query.
Definition: GpuIndexIVF.cu:241
faiss::gpu::GpuIndexIVF::useFloat16CoarseQuantizer_
const bool useFloat16CoarseQuantizer_
Definition: GpuIndexIVF.h:86
faiss::gpu::GpuIndexIVF::getNumLists
int getNumLists() const
Returns the number of inverted lists we&#39;re managing.
Definition: GpuIndexIVF.cu:236
faiss::gpu::GpuIndexIVF::getUseFloat16CoarseQuantizer
bool getUseFloat16CoarseQuantizer() const
Is our coarse quantizer storing and performing math in float16?
Definition: GpuIndexIVF.cu:115
faiss::gpu::GpuResources
Definition: GpuResources.h:24
faiss::gpu::GpuIndex
Definition: GpuIndex.h:20
faiss::gpu::GpuIndexIVF
Definition: GpuIndexIVF.h:25
faiss::gpu::GpuIndexIVF::nprobe_
int nprobe_
Number of inverted list probes per query.
Definition: GpuIndexIVF.h:92
faiss::gpu::GpuIndexIVF::indicesOptions_
const IndicesOptions indicesOptions_
How should indices be stored on the GPU?
Definition: GpuIndexIVF.h:82
faiss::gpu::GpuIndexIVF::copyTo
void copyTo(faiss::IndexIVF *index) const
Copy what we have to the CPU equivalent.
Definition: GpuIndexIVF.cu:187
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:89
faiss::gpu::GpuIndexIVF::quantizer_
GpuIndexFlat * quantizer_
Quantizer for inverted lists.
Definition: GpuIndexIVF.h:98
faiss::ClusteringParameters
Definition: Clustering.h:25
faiss::gpu::GpuIndexIVF::cp_
ClusteringParameters cp_
Ability to override default clustering parameters.
Definition: GpuIndexIVF.h:95
faiss::gpu::GpuIndexFlat
Definition: GpuIndexFlat.h:43
faiss::gpu::GpuIndexIVF::copyFrom
void copyFrom(const faiss::IndexIVF *index)
Copy what we need from the CPU equivalent.
Definition: GpuIndexIVF.cu:120
faiss::gpu::GpuIndexIVF::ownsQuantizer_
bool ownsQuantizer_
Do we own the above quantizer instance?
Definition: GpuIndexIVF.h:101
faiss::gpu::GpuIndexIVF::add
void add(Index::idx_t n, const float *x) override
Definition: GpuIndexIVF.cu:252
faiss::MetricType
MetricType
Some algorithms support both an inner product vetsion and a L2 search version.
Definition: Index.h:44