Faiss

- Main Page
- Namespaces
- Classes
- Files

- File List

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
GpuIndexIVFPQ.cu
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 #include "GpuIndexIVFPQ.h"
12 #include "../IndexFlat.h"
13 #include "../IndexIVFPQ.h"
14 #include "../ProductQuantizer.h"
15 #include "GpuIndexFlat.h"
16 #include "GpuResources.h"
17 #include "impl/IVFPQ.cuh"
18 #include "utils/CopyUtils.cuh"
19 #include "utils/DeviceUtils.h"
20
21 #include <limits>
22
23 namespace faiss { namespace gpu {
24
25 GpuIndexIVFPQ::GpuIndexIVFPQ(GpuResources* resources,
26 const faiss::IndexIVFPQ* index,
27 GpuIndexIVFPQConfig config) :
28 GpuIndexIVF(resources,
29 index->d,
30 index->metric_type,
31 index->nlist,
32 config),
33 ivfpqConfig_(config),
34 subQuantizers_(0),
35 bitsPerCode_(0),
36 reserveMemoryVecs_(0),
37 index_(nullptr) {
38 #ifndef FAISS_USE_FLOAT16
39 FAISS_ASSERT(!ivfpqConfig_.useFloat16LookupTables);
40 #endif
41
42 copyFrom(index);
43 }
44
45 GpuIndexIVFPQ::GpuIndexIVFPQ(GpuResources* resources,
46 int dims,
47 int nlist,
48 int subQuantizers,
49 int bitsPerCode,
50 faiss::MetricType metric,
51 GpuIndexIVFPQConfig config) :
52 GpuIndexIVF(resources,
53 dims,
54 metric,
55 nlist,
56 config),
57 ivfpqConfig_(config),
58 subQuantizers_(subQuantizers),
59 bitsPerCode_(bitsPerCode),
60 reserveMemoryVecs_(0),
61 index_(nullptr) {
62 #ifndef FAISS_USE_FLOAT16
63 FAISS_ASSERT(!useFloat16LookupTables_);
64 #endif
65
66 verifySettings_();
67
68 // FIXME make IP work fully
69 FAISS_ASSERT(this->metric_type == faiss::METRIC_L2);
70
71 // We haven't trained ourselves, so don't construct the PQ index yet
72 this->is_trained = false;
73 }
74
75 GpuIndexIVFPQ::~GpuIndexIVFPQ() {
76 delete index_;
77 }
78
79 void
80 GpuIndexIVFPQ::copyFrom(const faiss::IndexIVFPQ* index) {
81 DeviceScope scope(device_);
82
83 // FIXME: support this
84 FAISS_THROW_IF_NOT_MSG(index->metric_type == faiss::METRIC_L2,
85 "inner product unsupported");
86 GpuIndexIVF::copyFrom(index);
87
88 // Clear out our old data
89 delete index_;
90 index_ = nullptr;
91
92 subQuantizers_ = index->pq.M;
93 bitsPerCode_ = index->pq.nbits;
94
95 // We only support this
96 FAISS_ASSERT(index->pq.byte_per_idx == 1);
97 FAISS_ASSERT(index->by_residual);
98 FAISS_ASSERT(index->polysemous_ht == 0);
99 ivfpqConfig_.usePrecomputedTables = (bool) index->use_precomputed_table;
100
101 verifySettings_();
102
103 // The other index might not be trained
104 if (!index->is_trained) {
105 return;
106 }
107
108 // Otherwise, we can populate ourselves from the other index
109 this->is_trained = true;
110
111 // Copy our lists as well
112 // The product quantizer must have data in it
113 FAISS_ASSERT(index->pq.centroids.size() > 0);
114 index_ = new IVFPQ(resources_,
115 quantizer_->getGpuData(),
116 subQuantizers_,
117 bitsPerCode_,
118 (float*) index->pq.centroids.data(),
119 ivfpqConfig_.indicesOptions,
120 ivfpqConfig_.useFloat16LookupTables,
121 memorySpace_);
122 // Doesn't make sense to reserve memory here
123 index_->setPrecomputedCodes(ivfpqConfig_.usePrecomputedTables);
124
125 // Copy database vectors, if any
126 for (size_t i = 0; i < index->codes.size(); ++i) {
127 auto& codes = index->codes[i];
128 auto& ids = index->ids[i];
129
130 FAISS_ASSERT(ids.size() * subQuantizers_ == codes.size());
131
132 // GPU index can only support max int entries per list
133 FAISS_THROW_IF_NOT_FMT(ids.size() <=
134 (size_t) std::numeric_limits<int>::max(),
135 "GPU inverted list can only support "
136 "%zu entries; %zu found",
137 (size_t) std::numeric_limits<int>::max(),
138 ids.size());
139
140 index_->addCodeVectorsFromCpu(i, codes.data(), ids.data(), ids.size());
141 }
142 }
143
144 void
145 GpuIndexIVFPQ::copyTo(faiss::IndexIVFPQ* index) const {
146 DeviceScope scope(device_);
147
148 // We must have the indices in order to copy to ourselves
149 FAISS_THROW_IF_NOT_MSG(ivfpqConfig_.indicesOptions != INDICES_IVF,
150 "Cannot copy to CPU as GPU index doesn't retain "
151 "indices (INDICES_IVF)");
152
153 GpuIndexIVF::copyTo(index);
154
155 //
156 // IndexIVFPQ information
157 //
158 index->by_residual = true;
159 index->use_precomputed_table = 0;
160 index->code_size = subQuantizers_;
161 index->pq = faiss::ProductQuantizer(this->d, subQuantizers_, bitsPerCode_);
162
163 index->do_polysemous_training = false;
164 index->polysemous_training = nullptr;
165
166 index->scan_table_threshold = 0;
167 index->max_codes = 0;
168 index->polysemous_ht = 0;
169 index->codes.clear();
170 index->codes.resize(nlist_);
171 index->precomputed_table.clear();
172
173 if (index_) {
174 // Copy the inverted lists
175 for (int i = 0; i < nlist_; ++i) {
176 index->ids[i] = getListIndices(i);
177 index->codes[i] = getListCodes(i);
178 }
179
180 // Copy PQ centroids
181 auto devPQCentroids = index_->getPQCentroids();
182 index->pq.centroids.resize(devPQCentroids.numElements());
183
184 fromDevice<float, 3>(devPQCentroids,
185 index->pq.centroids.data(),
186 resources_->getDefaultStream(device_));
187
188 if (ivfpqConfig_.usePrecomputedTables) {
189 index->precompute_table();
190 }
191 }
192 }
193
194 void
195 GpuIndexIVFPQ::reserveMemory(size_t numVecs) {
196 reserveMemoryVecs_ = numVecs;
197 if (index_) {
198 DeviceScope scope(device_);
199 index_->reserveMemory(numVecs);
200 }
201 }
202
203 void
204 GpuIndexIVFPQ::setPrecomputedCodes(bool enable) {
205 ivfpqConfig_.usePrecomputedTables = enable;
206 if (index_) {
207 DeviceScope scope(device_);
208 index_->setPrecomputedCodes(enable);
209 }
210
211 verifySettings_();
212 }
213
214 bool
215 GpuIndexIVFPQ::getPrecomputedCodes() const {
216 return ivfpqConfig_.usePrecomputedTables;
217 }
218
219 int
220 GpuIndexIVFPQ::getNumSubQuantizers() const {
221 return subQuantizers_;
222 }
223
224 int
225 GpuIndexIVFPQ::getBitsPerCode() const {
226 return bitsPerCode_;
227 }
228
229 int
230 GpuIndexIVFPQ::getCentroidsPerSubQuantizer() const {
231 return utils::pow2(bitsPerCode_);
232 }
233
234 size_t
235 GpuIndexIVFPQ::reclaimMemory() {
236 if (index_) {
237 DeviceScope scope(device_);
238 return index_->reclaimMemory();
239 }
240
241 return 0;
242 }
243
244 void
245 GpuIndexIVFPQ::reset() {
246 if (index_) {
247 DeviceScope scope(device_);
248
249 index_->reset();
250 this->ntotal = 0;
251 } else {
252 FAISS_ASSERT(this->ntotal == 0);
253 }
254 }
255
256 void
257 GpuIndexIVFPQ::trainResidualQuantizer_(Index::idx_t n, const float* x) {
258 // Code largely copied from faiss::IndexIVFPQ
259 // FIXME: GPUize more of this
260 n = std::min(n, (Index::idx_t) (1 << bitsPerCode_) * 64);
261
262 if (this->verbose) {
263 printf("computing residuals\n");
264 }
265
266 std::vector<Index::idx_t> assign(n);
267 quantizer_->assign (n, x, assign.data());
268
269 std::vector<float> residuals(n * d);
270
271 for (idx_t i = 0; i < n; i++) {
272 quantizer_->compute_residual(x + i * d, &residuals[i * d], assign[i]);
273 }
274
275 if (this->verbose) {
276 printf("training %d x %d product quantizer on %ld vectors in %dD\n",
277 subQuantizers_, getCentroidsPerSubQuantizer(), n, this->d);
278 }
279
280 // Just use the CPU product quantizer to determine sub-centroids
281 faiss::ProductQuantizer pq(this->d, subQuantizers_, bitsPerCode_);
282 pq.verbose = this->verbose;
283 pq.train(n, residuals.data());
284
285 index_ = new IVFPQ(resources_,
286 quantizer_->getGpuData(),
287 subQuantizers_,
288 bitsPerCode_,
289 pq.centroids.data(),
290 ivfpqConfig_.indicesOptions,
291 ivfpqConfig_.useFloat16LookupTables,
292 memorySpace_);
293 if (reserveMemoryVecs_) {
294 index_->reserveMemory(reserveMemoryVecs_);
295 }
296
297 index_->setPrecomputedCodes(ivfpqConfig_.usePrecomputedTables);
298 }
299
300 void
301 GpuIndexIVFPQ::train(Index::idx_t n, const float* x) {
302 DeviceScope scope(device_);
303
304 if (this->is_trained) {
305 FAISS_ASSERT(quantizer_->is_trained);
306 FAISS_ASSERT(quantizer_->ntotal == nlist_);
307 FAISS_ASSERT(index_);
308 return;
309 }
310
311 FAISS_ASSERT(!index_);
312
313 trainQuantizer_(n, x);
314 trainResidualQuantizer_(n, x);
315
316 this->is_trained = true;
317 }
318
319 void
320 GpuIndexIVFPQ::addImpl_(Index::idx_t n,
321 const float* x,
322 const Index::idx_t* xids) {
323 // Device is already set in GpuIndex::addInternal_
324 FAISS_ASSERT(index_);
325 FAISS_ASSERT(n > 0);
326
327 auto stream = resources_->getDefaultStreamCurrentDevice();
328
329 auto deviceVecs =
330 toDevice<float, 2>(resources_,
331 device_,
332 const_cast<float*>(x),
333 stream,
334 {(int) n, index_->getDim()});
335
336 auto deviceIndices =
337 toDevice<Index::idx_t, 1>(resources_,
338 device_,
339 const_cast<Index::idx_t*>(xids),
340 stream,
341 {(int) n});
342
343 // Not all vectors may be able to be added (some may contain NaNs
344 // etc)
345 ntotal += index_->classifyAndAddVectors(deviceVecs, deviceIndices);
346 }
347
348 void
349 GpuIndexIVFPQ::searchImpl_(faiss::Index::idx_t n,
350 const float* x,
351 faiss::Index::idx_t k,
352 float* distances,
353 faiss::Index::idx_t* labels) const {
354 // Device is already set in GpuIndex::search
355
356 FAISS_ASSERT(index_);
357 FAISS_ASSERT(n > 0);
358
359 // Make sure arguments are on the device we desire; use temporary
360 // memory allocations to move it if necessary
361 auto devX =
362 toDevice<float, 2>(resources_,
363 device_,
364 const_cast<float*>(x),
365 resources_->getDefaultStream(device_),
366 {(int) n, index_->getDim()});
367 auto devDistances =
368 toDevice<float, 2>(resources_,
369 device_,
370 distances,
371 resources_->getDefaultStream(device_),
372 {(int) n, (int) k});
373 auto devLabels =
374 toDevice<faiss::Index::idx_t, 2>(resources_,
375 device_,
376 labels,
377 resources_->getDefaultStream(device_),
378 {(int) n, (int) k});
379
380 index_->query(devX,
381 nprobe_,
382 (int) k,
383 devDistances,
384 devLabels);
385
386 // Copy back if necessary
387 fromDevice<float, 2>(
388 devDistances, distances, resources_->getDefaultStream(device_));
389 fromDevice<faiss::Index::idx_t, 2>(
390 devLabels, labels, resources_->getDefaultStream(device_));
391 }
392
393 int
394 GpuIndexIVFPQ::getListLength(int listId) const {
395 FAISS_ASSERT(index_);
396 return index_->getListLength(listId);
397 }
398
399 std::vector<unsigned char>
400 GpuIndexIVFPQ::getListCodes(int listId) const {
401 FAISS_ASSERT(index_);
402 DeviceScope scope(device_);
403
404 return index_->getListCodes(listId);
405 }
406
407 std::vector<long>
408 GpuIndexIVFPQ::getListIndices(int listId) const {
409 FAISS_ASSERT(index_);
410 DeviceScope scope(device_);
411
412 return index_->getListIndices(listId);
413 }
414
415 void
416 GpuIndexIVFPQ::verifySettings_() const {
417 // Our implementation has these restrictions:
418
419 // Must have some number of lists
420 FAISS_THROW_IF_NOT_MSG(nlist_ > 0, "nlist must be >0");
421
422 // up to a single byte per code
423 FAISS_THROW_IF_NOT_FMT(bitsPerCode_ <= 8,
424 "Bits per code must be <= 8 (passed %d)", bitsPerCode_);
425
426 // Sub-quantizers must evenly divide dimensions available
427 FAISS_THROW_IF_NOT_FMT(this->d % subQuantizers_ == 0,
428 "Number of sub-quantizers (%d) must be an "
429 "even divisor of the number of dimensions (%d)",
430 subQuantizers_, this->d);
431
432 // The number of bytes per encoded vector must be one we support
433 FAISS_THROW_IF_NOT_FMT(IVFPQ::isSupportedPQCodeLength(subQuantizers_),
434 "Number of bytes per encoded vector / sub-quantizers (%d) "
435 "is not supported",
436 subQuantizers_);
437
438 // We must have enough shared memory on the current device to store
439 // our lookup distances
440 int lookupTableSize = sizeof(float);
441 #ifdef FAISS_USE_FLOAT16
442 if (ivfpqConfig_.useFloat16LookupTables) {
443 lookupTableSize = sizeof(half);
444 }
445 #endif
446
447 // 64 bytes per code is only supported with usage of float16, at 2^8
448 // codes per subquantizer
449 size_t requiredSmemSize =
450 lookupTableSize * subQuantizers_ * utils::pow2(bitsPerCode_);
451 size_t smemPerBlock = getMaxSharedMemPerBlock(device_);
452
453 FAISS_THROW_IF_NOT_FMT(requiredSmemSize
454 <= getMaxSharedMemPerBlock(device_),
455 "Device %d has %zu bytes of shared memory, while "
456 "%d bits per code and %d sub-quantizers requires %zu "
457 "bytes. Consider useFloat16LookupTables and/or "
458 "reduce parameters",
459 device_, smemPerBlock, bitsPerCode_, subQuantizers_,
460 requiredSmemSize);
461
462 // If precomputed codes are disabled, we have an extra limitation in
463 // terms of the number of dimensions per subquantizer
464 FAISS_THROW_IF_NOT_FMT(ivfpqConfig_.usePrecomputedTables ||
465 IVFPQ::isSupportedNoPrecomputedSubDimSize(
466 this->d / subQuantizers_),
467 "Number of dimensions per sub-quantizer (%d) "
468 "is not currently supported without precomputed codes. "
469 "Only 1, 2, 3, 4, 6, 8, 10, 12, 16, 20, 24, 28, 32 dims "
470 "per sub-quantizer are currently supported with no "
471 "precomputed codes. "
472 "Precomputed codes supports any number of dimensions, but "
473 "will involve memory overheads.",
474 this->d / subQuantizers_);
475
476 // TODO: fully implement METRIC_INNER_PRODUCT
477 FAISS_THROW_IF_NOT_MSG(this->metric_type == faiss::METRIC_L2,
478 "METRIC_INNER_PRODUCT is currently unsupported");
479 }
480
481 } } // namespace
faiss::gpu::GpuIndexIVFPQ::getListIndices
std::vector< long > getListIndices(int listId) const
Definition: GpuIndexIVFPQ.cu:408
faiss::gpu::GpuIndexIVFPQ::searchImpl_
void searchImpl_(faiss::Index::idx_t n, const float *x, faiss::Index::idx_t k, float *distances, faiss::Index::idx_t *labels) const override
Called from GpuIndex for search.
Definition: GpuIndexIVFPQ.cu:349
faiss::IndexIVFPQ::precompute_table
void precompute_table()
build precomputed table
Definition: IndexIVFPQ.cpp:391
faiss::gpu::GpuIndexIVFPQ::reset
void reset() override
Definition: GpuIndexIVFPQ.cu:245
faiss::ProductQuantizer::nbits
size_t nbits
number of bits per quantization index
Definition: ProductQuantizer.h:29
faiss::gpu::GpuResources::getDefaultStreamCurrentDevice
cudaStream_t getDefaultStreamCurrentDevice()
Calls getDefaultStream with the current device.
Definition: GpuResources.cpp:25
faiss::gpu::GpuIndexIVFPQConfig::usePrecomputedTables
bool usePrecomputedTables
Definition: GpuIndexIVFPQ.h:36
faiss::IndexIVFPQ::polysemous_training
PolysemousTraining * polysemous_training
if NULL, use default
Definition: IndexIVFPQ.h:36
faiss::ProductQuantizer::byte_per_idx
size_t byte_per_idx
nb bytes per code component (1 or 2)
Definition: ProductQuantizer.h:33
faiss::gpu::GpuIndexIVFPQ::GpuIndexIVFPQ
GpuIndexIVFPQ(GpuResources *resources, const faiss::IndexIVFPQ *index, GpuIndexIVFPQConfig config=GpuIndexIVFPQConfig())
Definition: GpuIndexIVFPQ.cu:25
faiss::gpu::IVFBase::getDim
int getDim() const
Return the number of dimensions we are indexing.
Definition: IVFBase.cu:100
faiss::gpu::IVFBase::getListLength
int getListLength(int listId) const
Definition: IVFBase.cu:200
faiss::gpu::GpuIndexFlat::getGpuData
FlatIndex * getGpuData()
For internal access.
Definition: GpuIndexFlat.h:120
faiss::Index::assign
void assign(idx_t n, const float *x, idx_t *labels, idx_t k=1)
Definition: Index.cpp:23
faiss::gpu::IVFBase::reserveMemory
void reserveMemory(size_t numVecs)
Reserve GPU memory in our inverted lists for this number of vectors.
Definition: IVFBase.cu:45
faiss::gpu::GpuIndexIVFPQ::getListLength
int getListLength(int listId) const
Definition: GpuIndexIVFPQ.cu:394
faiss::IndexIVFPQ::do_polysemous_training
bool do_polysemous_training
reorder PQ centroids after training?
Definition: IndexIVFPQ.h:35
faiss::IndexIVFPQ::scan_table_threshold
size_t scan_table_threshold
use table computation or on-the-fly?
Definition: IndexIVFPQ.h:39
faiss::IndexIVFPQ::precomputed_table
std::vector< float > precomputed_table
Definition: IndexIVFPQ.h:47
faiss::IndexIVFPQ::polysemous_ht
int polysemous_ht
Hamming thresh for polysemous filtering.
Definition: IndexIVFPQ.h:41
faiss::gpu::GpuResources
Definition: GpuResources.h:23
faiss::gpu::GpuIndexIVFPQ::getBitsPerCode
int getBitsPerCode() const
Return the number of bits per PQ code.
Definition: GpuIndexIVFPQ.cu:225
faiss::gpu::GpuIndexIVFPQConfig::useFloat16LookupTables
bool useFloat16LookupTables
Definition: GpuIndexIVFPQ.h:32
faiss::gpu::GpuResources::getDefaultStream
virtual cudaStream_t getDefaultStream(int device)=0
faiss::IndexIVF::ids
std::vector< std::vector< long > > ids
Inverted lists for indexes.
Definition: IndexIVF.h:55
faiss::gpu::GpuIndexIVF
Definition: GpuIndexIVF.h:37
faiss::Index::d
int d
vector dimension
Definition: Index.h:64
faiss::gpu::GpuIndexIVFPQ::train
void train(Index::idx_t n, const float *x) override
Definition: GpuIndexIVFPQ.cu:301
faiss::IndexIVFPQ::max_codes
size_t max_codes
max nb of codes to visit to do a query
Definition: IndexIVFPQ.h:40
faiss::gpu::IVFPQ::isSupportedPQCodeLength
static bool isSupportedPQCodeLength(int size)
Returns true if we support PQ in this size.
Definition: IVFPQ.cu:72
faiss::gpu::GpuIndexIVFPQ::reclaimMemory
size_t reclaimMemory()
Definition: GpuIndexIVFPQ.cu:235
faiss::gpu::GpuIndexIVFPQConfig
Definition: GpuIndexIVFPQ.h:23
faiss::IndexIVFPQ
Definition: IndexIVFPQ.h:29
faiss::gpu::GpuIndexIVF::nprobe_
int nprobe_
Number of inverted list probes per query.
Definition: GpuIndexIVF.h:91
faiss::gpu::GpuIndexIVFPQ::reserveMemory
void reserveMemory(size_t numVecs)
Reserve GPU memory in our inverted lists for this number of vectors.
Definition: GpuIndexIVFPQ.cu:195
faiss::gpu::IVFPQ::classifyAndAddVectors
int classifyAndAddVectors(Tensor< float, 2, true > &vecs, Tensor< long, 1, true > &indices)
Definition: IVFPQ.cu:120
faiss::gpu::IVFPQ::query
void query(Tensor< float, 2, true > &queries, int nprobe, int k, Tensor< float, 2, true > &outDistances, Tensor< long, 2, true > &outIndices)
Definition: IVFPQ.cu:519
faiss::gpu::GpuIndex::device_
const int device_
The GPU device we are resident on.
Definition: GpuIndex.h:94
faiss::gpu::GpuIndexIVFPQ::copyFrom
void copyFrom(const faiss::IndexIVFPQ *index)
Definition: GpuIndexIVFPQ.cu:80
faiss::gpu::IVFPQ::getPQCentroids
Tensor< float, 3, true > getPQCentroids()
Definition: IVFPQ.cu:594
faiss::gpu::GpuIndex::resources_
GpuResources * resources_
Manages streans, cuBLAS handles and scratch memory for devices.
Definition: GpuIndex.h:91
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:88
faiss::gpu::GpuIndexIVFPQ::addImpl_
void addImpl_(faiss::Index::idx_t n, const float *x, const faiss::Index::idx_t *ids) override
Called from GpuIndex for add/add_with_ids.
Definition: GpuIndexIVFPQ.cu:320
faiss::Index::ntotal
idx_t ntotal
total nb of indexed vectors
Definition: Index.h:65
faiss::Index::verbose
bool verbose
verbosity level
Definition: Index.h:66
faiss::gpu::IVFPQ::setPrecomputedCodes
void setPrecomputedCodes(bool enable)
Enable or disable pre-computed codes.
Definition: IVFPQ.cu:102
faiss::gpu::IVFPQ::getListCodes
std::vector< unsigned char > getListCodes(int listId) const
Return the list codes of a particular list back to the CPU.
Definition: IVFPQ.cu:586
faiss::gpu::GpuIndexIVFPQ::copyTo
void copyTo(faiss::IndexIVFPQ *index) const
Definition: GpuIndexIVFPQ.cu:145
faiss::gpu::IVFBase::reset
void reset()
Definition: IVFBase.cu:75
faiss::gpu::DeviceScope
Definition: DeviceUtils.h:62
faiss::gpu::GpuIndex::memorySpace_
const MemorySpace memorySpace_
The memory space of our primary storage on the GPU.
Definition: GpuIndex.h:97
faiss::IndexIVFPQ::by_residual
bool by_residual
Encode residual or plain vector?
Definition: IndexIVFPQ.h:30
faiss::gpu::GpuIndexIVF::quantizer_
GpuIndexFlat * quantizer_
Quantizer for inverted lists.
Definition: GpuIndexIVF.h:94
faiss::Index::metric_type
MetricType metric_type
type of metric this index uses for search
Definition: Index.h:72
faiss::IndexIVFPQ::pq
ProductQuantizer pq
produces the codes
Definition: IndexIVFPQ.h:33
faiss::ProductQuantizer::M
size_t M
number of subquantizers
Definition: ProductQuantizer.h:28
faiss::gpu::GpuIndexIVFPQ::getNumSubQuantizers
int getNumSubQuantizers() const
Return the number of sub-quantizers we are using.
Definition: GpuIndexIVFPQ.cu:220
faiss::gpu::IVFBase::getListIndices
std::vector< long > getListIndices(int listId) const
Return the list indices of a particular list back to the CPU.
Definition: IVFBase.cu:207
faiss::gpu::GpuIndexIVFPQ::getCentroidsPerSubQuantizer
int getCentroidsPerSubQuantizer() const
Return the number of centroids per PQ code (2^bits per code)
Definition: GpuIndexIVFPQ.cu:230
faiss::IndexIVFPQ::code_size
size_t code_size
code size per vector in bytes
Definition: IndexIVFPQ.h:32
faiss::gpu::GpuIndexIVFPQ::setPrecomputedCodes
void setPrecomputedCodes(bool enable)
Enable or disable pre-computed codes.
Definition: GpuIndexIVFPQ.cu:204
faiss::ProductQuantizer
Definition: ProductQuantizer.h:25
faiss::gpu::GpuIndexIVF::copyFrom
void copyFrom(const faiss::IndexIVF *index)
Copy what we need from the CPU equivalent.
Definition: GpuIndexIVF.cu:80
faiss::Index::is_trained
bool is_trained
set if the Index does not require training, or if training is done already
Definition: Index.h:69
faiss::Index::compute_residual
void compute_residual(const float *x, float *residual, idx_t key) const
Definition: Index.cpp:57
faiss::gpu::GpuIndexIVFPQ::getPrecomputedCodes
bool getPrecomputedCodes() const
Are pre-computed codes enabled?
Definition: GpuIndexIVFPQ.cu:215
faiss::gpu::GpuIndexIVFConfig::indicesOptions
IndicesOptions indicesOptions
Index storage options for the GPU.
Definition: GpuIndexIVF.h:31
faiss::gpu::IVFBase::reclaimMemory
size_t reclaimMemory()
Definition: IVFBase.cu:105
faiss::gpu::IVFPQ
Implementing class for IVFPQ on the GPU.
Definition: IVFPQ.cuh:19
faiss::MetricType
MetricType
Some algorithms support both an inner product vetsion and a L2 search version.
Definition: Index.h:43
faiss::IndexIVFPQ::use_precomputed_table
int use_precomputed_table
if by_residual, build precompute tables
Definition: IndexIVFPQ.h:31
faiss::gpu::GpuIndexIVFPQ::getListCodes
std::vector< unsigned char > getListCodes(int listId) const
Definition: GpuIndexIVFPQ.cu:400
faiss::ProductQuantizer::centroids
std::vector< float > centroids
Centroid table, size M * ksub * dsub.
Definition: ProductQuantizer.h:52
faiss::gpu::IVFPQ::isSupportedNoPrecomputedSubDimSize
static bool isSupportedNoPrecomputedSubDimSize(int dims)
Definition: IVFPQ.cu:97