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.
*/
// Copyright 2004-present Facebook. All Rights Reserved.
#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:166
faiss::gpu::GpuIndexIVF::getNumProbes
int getNumProbes() const
Returns our current number of list probes per query.
Definition: GpuIndexIVF.cu:209
faiss::gpu::GpuIndexIVF::setNumProbes
void setNumProbes(int nprobe)
Sets the number of list probes per query.
Definition: GpuIndexIVF.cu:201
faiss::gpu::GpuIndexIVF::getNumLists
int getNumLists() const
Returns the number of inverted lists we&#39;re managing.
Definition: GpuIndexIVF.cu:196
faiss::gpu::GpuIndexIVFConfig
Definition: GpuIndexIVF.h:25
faiss::gpu::GpuResources
Definition: GpuResources.h:23
faiss::gpu::GpuIndex
Definition: GpuIndex.h:35
faiss::gpu::GpuIndexIVF
Definition: GpuIndexIVF.h:37
faiss::gpu::GpuIndexFlatConfig
Definition: GpuIndexFlat.h:27
faiss::gpu::GpuIndexIVFConfig::flatConfig
GpuIndexFlatConfig flatConfig
Configuration for the coarse quantizer object.
Definition: GpuIndexIVF.h:34
faiss::gpu::GpuIndexIVF::getQuantizer
GpuIndexFlat * getQuantizer()
Return the quantizer we&#39;re using.
Definition: GpuIndexIVF.cu:76
faiss::gpu::GpuIndexIVF::nprobe_
int nprobe_
Number of inverted list probes per query.
Definition: GpuIndexIVF.h:91
faiss::gpu::GpuIndexIVF::copyTo
void copyTo(faiss::IndexIVF *index) const
Copy what we have to the CPU equivalent.
Definition: GpuIndexIVF.cu:149
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::GpuIndexIVF::quantizer_
GpuIndexFlat * quantizer_
Quantizer for inverted lists.
Definition: GpuIndexIVF.h:94
faiss::ClusteringParameters
Definition: Clustering.h:24
faiss::gpu::GpuIndexConfig
Definition: GpuIndex.h:20
faiss::gpu::GpuIndexFlat
Definition: GpuIndexFlat.h:54
faiss::gpu::GpuIndexIVF::copyFrom
void copyFrom(const faiss::IndexIVF *index)
Copy what we need from the CPU equivalent.
Definition: GpuIndexIVF.cu:81
faiss::gpu::GpuIndexIVF::add
void add(Index::idx_t n, const float *x) override
Definition: GpuIndexIVF.cu:214
faiss::gpu::GpuIndexIVF::cp
ClusteringParameters cp
Definition: GpuIndexIVF.h:82
faiss::gpu::GpuIndexIVFConfig::indicesOptions
IndicesOptions indicesOptions
Index storage options for the GPU.
Definition: GpuIndexIVF.h:31
faiss::MetricType
MetricType
Some algorithms support both an inner product version and a L2 search version.
Definition: Index.h:43