Faiss
 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 
19 };
20 
21 /// A GPU version of IndexBinaryFlat for brute-force comparison of bit vectors
22 /// via Hamming distance
24  public:
25  /// Construct from a pre-existing faiss::IndexBinaryFlat instance, copying
26  /// data over to the given GPU
28  const faiss::IndexBinaryFlat* index,
31 
32  /// Construct an empty instance that can be added to
34  int dims,
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 
49  const uint8_t* x) override;
50 
51  void reset() override;
52 
54  const uint8_t* x,
56  int32_t* distances,
57  faiss::IndexBinary::idx_t* labels) const override;
58 
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
80 
81  /// Configuration options
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
87 };
88 
89 } } // namespace gpu
void reset() override
Removes all elements from the database.
Holder of GPU resources for a particular flat index.
void copyTo(faiss::IndexBinaryFlat *index) const
Index::idx_t idx_t
all indices are this type
Definition: IndexBinary.h:37
void add(faiss::IndexBinary::idx_t n, const uint8_t *x) override
GpuIndexBinaryFlatConfig config_
Configuration options.
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
GpuResources * resources_
Manages streans, cuBLAS handles and scratch memory for devices.
void searchFromCpuPaged_(int n, const uint8_t *x, int k, int32_t *outDistancesData, int *outIndicesData) const
void reconstruct(faiss::IndexBinary::idx_t key, uint8_t *recons) const override
void copyFrom(const faiss::IndexBinaryFlat *index)
GpuIndexBinaryFlat(GpuResources *resources, const faiss::IndexBinaryFlat *index, GpuIndexBinaryFlatConfig config=GpuIndexBinaryFlatConfig())