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 BSD+Patents license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include "GpuIndex.h"
#include "GpuIndexFlat.h"
#include "GpuIndicesOptions.h"
#include "../Clustering.h"
namespace faiss { struct IndexIVF; }
namespace faiss { namespace gpu {
class GpuIndexFlat;
class GpuResources;
struct GpuIndexIVFConfig : public GpuIndexConfig {
inline GpuIndexIVFConfig()
: indicesOptions(INDICES_64_BIT) {
}
/// Index storage options for the GPU
IndicesOptions indicesOptions;
/// Configuration for the coarse quantizer object
GpuIndexFlatConfig flatConfig;
};
class GpuIndexIVF : public GpuIndex {
public:
GpuIndexIVF(GpuResources* resources,
int dims,
faiss::MetricType metric,
int nlist,
GpuIndexIVFConfig config = GpuIndexIVFConfig());
~GpuIndexIVF() override;
private:
/// Shared initialization functions
void init_();
public:
/// 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;
/// Return the quantizer we're using
GpuIndexFlat* getQuantizer();
/// 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);
public:
/// Exposed as IndexIVF does to allow overriding clustering
/// parameters
ClusteringParameters cp;
protected:
GpuIndexIVFConfig ivfConfig_;
/// Number of inverted lists that we manage
int nlist_;
/// Number of inverted list probes per query
int nprobe_;
/// Quantizer for inverted lists
GpuIndexFlat* quantizer_;
};
} } // namespace
faiss::IndexIVF
Definition: IndexIVF.h:91
faiss::gpu::GpuIndexIVF::getNumProbes
int getNumProbes() const
Returns our current number of list probes per query.
Definition: GpuIndexIVF.cu:208
faiss::gpu::GpuIndexIVF::setNumProbes
void setNumProbes(int nprobe)
Sets the number of list probes per query.
Definition: GpuIndexIVF.cu:200
faiss::gpu::GpuIndexIVF::getNumLists
int getNumLists() const
Returns the number of inverted lists we&#39;re managing.
Definition: GpuIndexIVF.cu:195
faiss::gpu::GpuIndexIVFConfig
Definition: GpuIndexIVF.h:24
faiss::gpu::GpuResources
Definition: GpuResources.h:22
faiss::gpu::GpuIndex
Definition: GpuIndex.h:34
faiss::gpu::GpuIndexIVF
Definition: GpuIndexIVF.h:36
faiss::gpu::GpuIndexFlatConfig
Definition: GpuIndexFlat.h:26
faiss::gpu::GpuIndexIVFConfig::flatConfig
GpuIndexFlatConfig flatConfig
Configuration for the coarse quantizer object.
Definition: GpuIndexIVF.h:33
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:90
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:64
faiss::gpu::GpuIndexIVF::nlist_
int nlist_
Number of inverted lists that we manage.
Definition: GpuIndexIVF.h:87
faiss::gpu::GpuIndexIVF::quantizer_
GpuIndexFlat * quantizer_
Quantizer for inverted lists.
Definition: GpuIndexIVF.h:93
faiss::ClusteringParameters
Definition: Clustering.h:23
faiss::gpu::GpuIndexConfig
Definition: GpuIndex.h:19
faiss::gpu::GpuIndexFlat
Definition: GpuIndexFlat.h:53
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:213
faiss::gpu::GpuIndexIVF::cp
ClusteringParameters cp
Definition: GpuIndexIVF.h:81
faiss::gpu::GpuIndexIVFConfig::indicesOptions
IndicesOptions indicesOptions
Index storage options for the GPU.
Definition: GpuIndexIVF.h:30
faiss::MetricType
MetricType
Some algorithms support both an inner product version and a L2 search version.
Definition: Index.h:45