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