Faiss

- Main Page
- Namespaces
- Classes
- Files

- File List

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