All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
GpuIndexIVF.h
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the CC-by-NC license found in the
* LICENSE file in the root directory of this source tree.
*/
// Copyright 2004-present Facebook. All Rights Reserved.
#pragma once
#include "GpuIndex.h"
#include "GpuIndicesOptions.h"
#include "../Clustering.h"
namespace faiss { struct IndexIVF; }
namespace faiss { namespace gpu {
class GpuIndexFlat;
class GpuResources;
class GpuIndexIVF : public GpuIndex {
public:
GpuIndexIVF(GpuResources* resources,
int device,
IndicesOptions indicesOptions,
bool useFloat16CoarseQuantizer,
int dims,
faiss::MetricType metric,
int nlist);
GpuIndexIVF(GpuResources* resources,
int device,
IndicesOptions indicesOptions,
int dims,
faiss::MetricType metric,
int nlist,
GpuIndexFlat* quantizer);
~GpuIndexIVF() override;
private:
/// Shared initialization functions
void init_();
public:
/// What indices storage options are we using?
IndicesOptions getIndicesOptions() const;
/// Is our coarse quantizer storing and performing math in float16?
bool getUseFloat16CoarseQuantizer() const;
/// Copy what we need from the CPU equivalent
void copyFrom(const faiss::IndexIVF* index);
/// Copy what we have to the CPU equivalent
void copyTo(faiss::IndexIVF* index) const;
/// Returns the number of inverted lists we're managing
int getNumLists() const;
/// Sets the number of list probes per query
void setNumProbes(int nprobe);
/// Returns our current number of list probes per query
int getNumProbes() const;
/// `x` can be resident on the CPU or any GPU; the proper copies are
/// performed
/// Forwards to add_with_ids; assigns IDs as needed
/// FIXME: remove override for C++03 compatibility
void add(Index::idx_t n, const float* x) override;
protected:
void trainQuantizer_(faiss::Index::idx_t n, const float* x);
protected:
/// How should indices be stored on the GPU?
const IndicesOptions indicesOptions_;
/// Do we want to use float16 storage and math in our coarse
/// quantizer?
const bool useFloat16CoarseQuantizer_;
/// Number of inverted lists that we manage
int nlist_;
/// Number of inverted list probes per query
int nprobe_;
/// Ability to override default clustering parameters
ClusteringParameters cp_;
/// Quantizer for inverted lists
GpuIndexFlat* quantizer_;
/// Do we own the above quantizer instance?
bool ownsQuantizer_;
};
} } // 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