Faiss

- Main Page
- Namespaces
- Classes
- Files

- File List

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
IVFFlat.cuh
1
2 /**
3 * Copyright (c) 2015-present, Facebook, Inc.
4 * All rights reserved.
5 *
6 * This source code is licensed under the CC-by-NC license found in the
7 * LICENSE file in the root directory of this source tree.
8 */
9
10 // Copyright 2004-present Facebook. All Rights Reserved.
11
12 #pragma once
13
14 #include "IVFBase.cuh"
15
16 namespace faiss { namespace gpu {
17
18 class IVFFlat : public IVFBase {
19 public:
20 /// Construct from a quantizer that has elemen
21 IVFFlat(GpuResources* resources,
22 /// We do not own this reference
23 FlatIndex* quantizer,
24 bool l2Distance,
25 bool useFloat16,
26 IndicesOptions indicesOptions);
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.
41 int classifyAndAddVectors(Tensor<float, 2, true>& vecs,
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
faiss::gpu::IVFFlat
Definition: IVFFlat.cuh:18
faiss::gpu::FlatIndex
Holder of GPU resources for a particular flat index.
Definition: FlatIndex.cuh:23
faiss::gpu::IVFBase
Base inverted list functionality for IVFFlat and IVFPQ.
Definition: IVFBase.cuh:27
faiss::gpu::GpuResources
Definition: GpuResources.h:24
faiss::gpu::IVFFlat::IVFFlat
IVFFlat(GpuResources *resources, FlatIndex *quantizer, bool l2Distance, bool useFloat16, IndicesOptions indicesOptions)
Construct from a quantizer that has elemen.
Definition: IVFFlat.cu:30
faiss::gpu::IVFFlat::classifyAndAddVectors
int classifyAndAddVectors(Tensor< float, 2, true > &vecs, Tensor< long, 1, true > &indices)
Definition: IVFFlat.cu:129
faiss::gpu::Tensor
Our tensor type.
Definition: Tensor.cuh:31
faiss::gpu::IVFFlat::addCodeVectorsFromCpu
void addCodeVectorsFromCpu(int listId, const float *vecs, const long *indices, size_t numVecs)
Definition: IVFFlat.cu:57
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:287
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:353