Faiss

- Main Page
- Namespaces
- Classes
- Files

- File List

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
GpuIndexBinaryFlat.h
1 /**
2 * Copyright (c) Facebook, Inc. and its affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 #pragma once
9
10 #include "../IndexBinaryFlat.h"
11 #include "GpuIndex.h"
12
13 namespace faiss { namespace gpu {
14
15 class BinaryFlatIndex;
16 class GpuResources;
17
18 struct GpuIndexBinaryFlatConfig : public GpuIndexConfig {
19 };
20
21 /// A GPU version of IndexBinaryFlat for brute-force comparison of bit vectors
22 /// via Hamming distance
23 class GpuIndexBinaryFlat : public IndexBinary {
24 public:
25 /// Construct from a pre-existing faiss::IndexBinaryFlat instance, copying
26 /// data over to the given GPU
27 GpuIndexBinaryFlat(GpuResources* resources,
28 const faiss::IndexBinaryFlat* index,
29 GpuIndexBinaryFlatConfig config =
30 GpuIndexBinaryFlatConfig());
31
32 /// Construct an empty instance that can be added to
33 GpuIndexBinaryFlat(GpuResources* resources,
34 int dims,
35 GpuIndexBinaryFlatConfig config =
36 GpuIndexBinaryFlatConfig());
37
38 ~GpuIndexBinaryFlat() override;
39
40 /// Initialize ourselves from the given CPU index; will overwrite
41 /// all data in ourselves
42 void copyFrom(const faiss::IndexBinaryFlat* index);
43
44 /// Copy ourselves to the given CPU index; will overwrite all data
45 /// in the index instance
46 void copyTo(faiss::IndexBinaryFlat* index) const;
47
48 void add(faiss::IndexBinary::idx_t n,
49 const uint8_t* x) override;
50
51 void reset() override;
52
53 void search(faiss::IndexBinary::idx_t n,
54 const uint8_t* x,
55 faiss::IndexBinary::idx_t k,
56 int32_t* distances,
57 faiss::IndexBinary::idx_t* labels) const override;
58
59 void reconstruct(faiss::IndexBinary::idx_t key,
60 uint8_t* recons) const override;
61
62 protected:
63 /// Called from search when the input data is on the CPU;
64 /// potentially allows for pinned memory usage
65 void searchFromCpuPaged_(int n,
66 const uint8_t* x,
67 int k,
68 int32_t* outDistancesData,
69 int* outIndicesData) const;
70
71 void searchNonPaged_(int n,
72 const uint8_t* x,
73 int k,
74 int32_t* outDistancesData,
75 int* outIndicesData) const;
76
77 protected:
78 /// Manages streans, cuBLAS handles and scratch memory for devices
79 GpuResources* resources_;
80
81 /// Configuration options
82 GpuIndexBinaryFlatConfig config_;
83
84 /// Holds our GPU data containing the list of vectors; is managed via raw
85 /// pointer so as to allow non-CUDA compilers to see this header
86 BinaryFlatIndex* data_;
87 };
88
89 } } // namespace gpu
faiss::IndexBinaryFlat
Definition: IndexBinaryFlat.h:21
faiss::gpu::GpuIndexBinaryFlat::reset
void reset() override
Removes all elements from the database.
Definition: GpuIndexBinaryFlat.cu:138
faiss::gpu::BinaryFlatIndex
Holder of GPU resources for a particular flat index.
Definition: BinaryFlatIndex.cuh:20
faiss::gpu::GpuIndexBinaryFlatConfig
Definition: GpuIndexBinaryFlat.h:18
faiss::gpu::GpuIndexBinaryFlat::copyTo
void copyTo(faiss::IndexBinaryFlat *index) const
Definition: GpuIndexBinaryFlat.cu:98
faiss::gpu::GpuResources
Definition: GpuResources.h:21
faiss::IndexBinary::idx_t
Index::idx_t idx_t
all indices are this type
Definition: IndexBinary.h:37
faiss::gpu::GpuIndexBinaryFlat::add
void add(faiss::IndexBinary::idx_t n, const uint8_t *x) override
Definition: GpuIndexBinaryFlat.cu:116
faiss::gpu::GpuIndexBinaryFlat::config_
GpuIndexBinaryFlatConfig config_
Configuration options.
Definition: GpuIndexBinaryFlat.h:82
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:147
faiss::gpu::GpuIndexBinaryFlat::resources_
GpuResources * resources_
Manages streans, cuBLAS handles and scratch memory for devices.
Definition: GpuIndexBinaryFlat.h:79
faiss::gpu::GpuIndexBinaryFlat::searchFromCpuPaged_
void searchFromCpuPaged_(int n, const uint8_t *x, int k, int32_t *outDistancesData, int *outIndicesData) const
Definition: GpuIndexBinaryFlat.cu:252
faiss::gpu::GpuIndexBinaryFlat::reconstruct
void reconstruct(faiss::IndexBinary::idx_t key, uint8_t *recons) const override
Definition: GpuIndexBinaryFlat.cu:281
faiss::IndexBinary
Definition: IndexBinary.h:36
faiss::gpu::GpuIndexConfig
Definition: GpuIndex.h:18
faiss::gpu::GpuIndexBinaryFlat::copyFrom
void copyFrom(const faiss::IndexBinaryFlat *index)
Definition: GpuIndexBinaryFlat.cu:70
faiss::gpu::GpuIndexBinaryFlat::GpuIndexBinaryFlat
GpuIndexBinaryFlat(GpuResources *resources, const faiss::IndexBinaryFlat *index, GpuIndexBinaryFlatConfig config=GpuIndexBinaryFlatConfig())
Definition: GpuIndexBinaryFlat.cu:24
faiss::gpu::GpuIndexBinaryFlat
Definition: GpuIndexBinaryFlat.h:23
faiss::gpu::GpuIndexBinaryFlat::data_
BinaryFlatIndex * data_
Definition: GpuIndexBinaryFlat.h:86