Faiss
 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 
20 };
21 
22 /// A GPU version of IndexBinaryFlat for brute-force comparison of bit vectors
23 /// via Hamming distance
25  public:
26  /// Construct from a pre-existing faiss::IndexBinaryFlat instance, copying
27  /// data over to the given GPU
29  const faiss::IndexBinaryFlat* index,
32 
33  /// Construct an empty instance that can be added to
35  int dims,
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 
50  const uint8_t* x) override;
51 
52  void reset() override;
53 
55  const uint8_t* x,
57  int32_t* distances,
58  faiss::IndexBinary::idx_t* labels) const override;
59 
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
81 
82  /// Configuration options
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
88 };
89 
90 } } // 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
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
long idx_t
all indices are this type
Definition: IndexBinary.h:38
void copyFrom(const faiss::IndexBinaryFlat *index)
GpuIndexBinaryFlat(GpuResources *resources, const faiss::IndexBinaryFlat *index, GpuIndexBinaryFlatConfig config=GpuIndexBinaryFlatConfig())