All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
GpuIndexBinaryFlat.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 "../IndexBinaryFlat.h"
#include "GpuIndex.h"
namespace faiss { namespace gpu {
class BinaryFlatIndex;
class GpuResources;
struct GpuIndexBinaryFlatConfig : public GpuIndexConfig {
};
/// A GPU version of IndexBinaryFlat for brute-force comparison of bit vectors
/// via Hamming distance
class GpuIndexBinaryFlat : public IndexBinary {
public:
/// Construct from a pre-existing faiss::IndexBinaryFlat instance, copying
/// data over to the given GPU
GpuIndexBinaryFlat(GpuResources* resources,
const faiss::IndexBinaryFlat* index,
GpuIndexBinaryFlatConfig config =
GpuIndexBinaryFlatConfig());
/// Construct an empty instance that can be added to
GpuIndexBinaryFlat(GpuResources* resources,
int dims,
GpuIndexBinaryFlatConfig config =
GpuIndexBinaryFlatConfig());
~GpuIndexBinaryFlat() override;
/// Initialize ourselves from the given CPU index; will overwrite
/// all data in ourselves
void copyFrom(const faiss::IndexBinaryFlat* index);
/// Copy ourselves to the given CPU index; will overwrite all data
/// in the index instance
void copyTo(faiss::IndexBinaryFlat* index) const;
void add(faiss::IndexBinary::idx_t n,
const uint8_t* x) override;
void reset() override;
void search(faiss::IndexBinary::idx_t n,
const uint8_t* x,
faiss::IndexBinary::idx_t k,
int32_t* distances,
faiss::IndexBinary::idx_t* labels) const override;
void reconstruct(faiss::IndexBinary::idx_t key,
uint8_t* recons) const override;
protected:
/// Called from search when the input data is on the CPU;
/// potentially allows for pinned memory usage
void searchFromCpuPaged_(int n,
const uint8_t* x,
int k,
int32_t* outDistancesData,
int* outIndicesData) const;
void searchNonPaged_(int n,
const uint8_t* x,
int k,
int32_t* outDistancesData,
int* outIndicesData) const;
protected:
/// Manages streans, cuBLAS handles and scratch memory for devices
GpuResources* resources_;
/// Configuration options
GpuIndexBinaryFlatConfig config_;
/// Holds our GPU data containing the list of vectors; is managed via raw
/// pointer so as to allow non-CUDA compilers to see this header
BinaryFlatIndex* data_;
};
} } // namespace gpu
faiss::IndexBinaryFlat
Definition: IndexBinaryFlat.h:22
faiss::gpu::GpuIndexBinaryFlat::reset
void reset() override
Removes all elements from the database.
Definition: GpuIndexBinaryFlat.cu:139
faiss::gpu::BinaryFlatIndex
Holder of GPU resources for a particular flat index.
Definition: BinaryFlatIndex.cuh:21
faiss::gpu::GpuIndexBinaryFlatConfig
Definition: GpuIndexBinaryFlat.h:19
faiss::gpu::GpuIndexBinaryFlat::copyTo
void copyTo(faiss::IndexBinaryFlat *index) const
Definition: GpuIndexBinaryFlat.cu:99
faiss::gpu::GpuResources
Definition: GpuResources.h:22
faiss::gpu::GpuIndexBinaryFlat::add
void add(faiss::IndexBinary::idx_t n, const uint8_t *x) override
Definition: GpuIndexBinaryFlat.cu:117
faiss::gpu::GpuIndexBinaryFlat::config_
GpuIndexBinaryFlatConfig config_
Configuration options.
Definition: GpuIndexBinaryFlat.h:83
faiss::gpu::GpuIndexBinaryFlat::search
void search(faiss::IndexBinary::idx_t n, const uint8_t *x, faiss::IndexBinary::idx_t k, int32_t *distances, faiss::IndexBinary::idx_t *labels) const override
Definition: GpuIndexBinaryFlat.cu:148
faiss::gpu::GpuIndexBinaryFlat::resources_
GpuResources * resources_
Manages streans, cuBLAS handles and scratch memory for devices.
Definition: GpuIndexBinaryFlat.h:80
faiss::gpu::GpuIndexBinaryFlat::searchFromCpuPaged_
void searchFromCpuPaged_(int n, const uint8_t *x, int k, int32_t *outDistancesData, int *outIndicesData) const
Definition: GpuIndexBinaryFlat.cu:253
faiss::gpu::GpuIndexBinaryFlat::reconstruct
void reconstruct(faiss::IndexBinary::idx_t key, uint8_t *recons) const override
Definition: GpuIndexBinaryFlat.cu:282
faiss::IndexBinary
Definition: IndexBinary.h:37
faiss::gpu::GpuIndexConfig
Definition: GpuIndex.h:19
faiss::IndexBinary::idx_t
long idx_t
all indices are this type
Definition: IndexBinary.h:38
faiss::gpu::GpuIndexBinaryFlat::copyFrom
void copyFrom(const faiss::IndexBinaryFlat *index)
Definition: GpuIndexBinaryFlat.cu:71
faiss::gpu::GpuIndexBinaryFlat::GpuIndexBinaryFlat
GpuIndexBinaryFlat(GpuResources *resources, const faiss::IndexBinaryFlat *index, GpuIndexBinaryFlatConfig config=GpuIndexBinaryFlatConfig())
Definition: GpuIndexBinaryFlat.cu:25
faiss::gpu::GpuIndexBinaryFlat
Definition: GpuIndexBinaryFlat.h:24
faiss::gpu::GpuIndexBinaryFlat::data_
BinaryFlatIndex * data_
Definition: GpuIndexBinaryFlat.h:87