Faiss

- Main Page
- Namespaces
- Classes
- Files

- File List

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
Distance.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 "../utils/DeviceTensor.cuh"
12 #include "../utils/Float16.cuh"
13
14 namespace faiss { namespace gpu {
15
16 class GpuResources;
17
18 /// Calculates brute-force L2 distance between `vectors` and
19 /// `queries`, returning the k closest results seen
20 void runL2Distance(GpuResources* resources,
21 Tensor<float, 2, true>& vectors,
22 bool vectorsRowMajor,
23 // can be optionally pre-computed; nullptr if we
24 // have to compute it upon the call
25 Tensor<float, 1, true>* vectorNorms,
26 Tensor<float, 2, true>& queries,
27 bool queriesRowMajor,
28 int k,
29 Tensor<float, 2, true>& outDistances,
30 Tensor<int, 2, true>& outIndices,
31 // Do we care about `outDistances`? If not, we can
32 // take shortcuts.
33 bool ignoreOutDistances = false);
34
35 /// Calculates brute-force inner product distance between `vectors`
36 /// and `queries`, returning the k closest results seen
37 void runIPDistance(GpuResources* resources,
38 Tensor<float, 2, true>& vectors,
39 bool vectorsRowMajor,
40 Tensor<float, 2, true>& queries,
41 bool queriesRowMajor,
42 int k,
43 Tensor<float, 2, true>& outDistances,
44 Tensor<int, 2, true>& outIndices);
45
46 #ifdef FAISS_USE_FLOAT16
47 void runIPDistance(GpuResources* resources,
48 Tensor<half, 2, true>& vectors,
49 bool vectorsRowMajor,
50 Tensor<half, 2, true>& queries,
51 bool queriesRowMajor,
52 int k,
53 Tensor<half, 2, true>& outDistances,
54 Tensor<int, 2, true>& outIndices,
55 bool useHgemm);
56
57 void runL2Distance(GpuResources* resources,
58 Tensor<half, 2, true>& vectors,
59 bool vectorsRowMajor,
60 Tensor<half, 1, true>* vectorNorms,
61 Tensor<half, 2, true>& queries,
62 bool queriesRowMajor,
63 int k,
64 Tensor<half, 2, true>& outDistances,
65 Tensor<int, 2, true>& outIndices,
66 bool useHgemm,
67 bool ignoreOutDistances = false);
68 #endif
69
70 } } // namespace