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
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 /// How should indices be stored on the GPU?
81 const IndicesOptions indicesOptions_;
82
83 /// Do we want to use float16 storage and math in our coarse
84 /// quantizer?
85 const bool useFloat16CoarseQuantizer_;
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 /// Ability to override default clustering parameters
94 ClusteringParameters cp_;
95
96 /// Quantizer for inverted lists
97 GpuIndexFlat* quantizer_;
98
99 /// Do we own the above quantizer instance?
100 bool ownsQuantizer_;
101 };
102
103 } } // namespace
faiss::IndexIVF
Definition: IndexIVF.h:46
faiss::gpu::GpuIndexIVF::getIndicesOptions
IndicesOptions getIndicesOptions() const
What indices storage options are we using?
Definition: GpuIndexIVF.cu:107
faiss::gpu::GpuIndexIVF::getNumProbes
int getNumProbes() const
Returns our current number of list probes per query.
Definition: GpuIndexIVF.cu:241
faiss::gpu::GpuIndexIVF::setNumProbes
void setNumProbes(int nprobe)
Sets the number of list probes per query.
Definition: GpuIndexIVF.cu:235
faiss::gpu::GpuIndexIVF::useFloat16CoarseQuantizer_
const bool useFloat16CoarseQuantizer_
Definition: GpuIndexIVF.h:85
faiss::gpu::GpuIndexIVF::getNumLists
int getNumLists() const
Returns the number of inverted lists we&#39;re managing.
Definition: GpuIndexIVF.cu:230
faiss::gpu::GpuIndexIVF::getUseFloat16CoarseQuantizer
bool getUseFloat16CoarseQuantizer() const
Is our coarse quantizer storing and performing math in float16?
Definition: GpuIndexIVF.cu:112
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:91
faiss::gpu::GpuIndexIVF::indicesOptions_
const IndicesOptions indicesOptions_
How should indices be stored on the GPU?
Definition: GpuIndexIVF.h:81
faiss::gpu::GpuIndexIVF::copyTo
void copyTo(faiss::IndexIVF *index) const
Copy what we have to the CPU equivalent.
Definition: GpuIndexIVF.cu:181
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:88
faiss::gpu::GpuIndexIVF::quantizer_
GpuIndexFlat * quantizer_
Quantizer for inverted lists.
Definition: GpuIndexIVF.h:97
faiss::ClusteringParameters
Definition: Clustering.h:25
faiss::gpu::GpuIndexIVF::cp_
ClusteringParameters cp_
Ability to override default clustering parameters.
Definition: GpuIndexIVF.h:94
faiss::gpu::GpuIndexFlat
Definition: GpuIndexFlat.h:31
faiss::gpu::GpuIndexIVF::copyFrom
void copyFrom(const faiss::IndexIVF *index)
Copy what we need from the CPU equivalent.
Definition: GpuIndexIVF.cu:117
faiss::gpu::GpuIndexIVF::ownsQuantizer_
bool ownsQuantizer_
Do we own the above quantizer instance?
Definition: GpuIndexIVF.h:100
faiss::gpu::GpuIndexIVF::add
void add(Index::idx_t n, const float *x) override
Definition: GpuIndexIVF.cu:247
faiss::MetricType
MetricType
Some algorithms support both an inner product vetsion and a L2 search version.
Definition: Index.h:44