Faiss

- Main Page
- Namespaces
- Classes
- Files

- File List

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