Faiss
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
IVFFlat.cuh
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 
10 #pragma once
11 
12 #include "IVFBase.cuh"
13 
14 namespace faiss { namespace gpu {
15 
16 class IVFFlat : public IVFBase {
17  public:
18  /// Construct from a quantizer that has elemen
19  IVFFlat(GpuResources* resources,
20  /// We do not own this reference
21  FlatIndex* quantizer,
22  bool l2Distance,
23  bool useFloat16,
24  IndicesOptions indicesOptions,
25  MemorySpace space);
26 
27  ~IVFFlat() override;
28 
29  /// Add vectors to a specific list; the input data can be on the
30  /// host or on our current device
31  void addCodeVectorsFromCpu(int listId,
32  const float* vecs,
33  const long* indices,
34  size_t numVecs);
35 
36  /// Adds the given vectors to this index.
37  /// The input data must be on our current device.
38  /// Returns the number of vectors successfully added. Vectors may
39  /// not be able to be added because they contain NaNs.
41  Tensor<long, 1, true>& indices);
42 
43  /// Find the approximate k nearest neigbors for `queries` against
44  /// our database
45  void query(Tensor<float, 2, true>& queries,
46  int nprobe,
47  int k,
48  Tensor<float, 2, true>& outDistances,
49  Tensor<long, 2, true>& outIndices);
50 
51  /// Return the vectors of a particular list back to the CPU
52  std::vector<float> getListVectors(int listId) const;
53 
54  private:
55  /// Returns the size of our stored vectors, in bytes
56  size_t getVectorMemorySize() const;
57 
58  private:
59  /// Calculating L2 distance or inner product?
60  const bool l2Distance_;
61 
62  /// Do we store data internally as float16 (versus float32)?
63  const bool useFloat16_;
64 };
65 
66 } } // namespace
Holder of GPU resources for a particular flat index.
Definition: FlatIndex.cuh:22
Base inverted list functionality for IVFFlat and IVFPQ.
Definition: IVFBase.cuh:26
IVFFlat(GpuResources *resources, FlatIndex *quantizer, bool l2Distance, bool useFloat16, IndicesOptions indicesOptions, MemorySpace space)
Construct from a quantizer that has elemen.
Definition: IVFFlat.cu:28
int classifyAndAddVectors(Tensor< float, 2, true > &vecs, Tensor< long, 1, true > &indices)
Definition: IVFFlat.cu:128
Our tensor type.
Definition: Tensor.cuh:29
void addCodeVectorsFromCpu(int listId, const float *vecs, const long *indices, size_t numVecs)
Definition: IVFFlat.cu:53
void query(Tensor< float, 2, true > &queries, int nprobe, int k, Tensor< float, 2, true > &outDistances, Tensor< long, 2, true > &outIndices)
Definition: IVFFlat.cu:286
std::vector< float > getListVectors(int listId) const
Return the vectors of a particular list back to the CPU.
Definition: IVFFlat.cu:352