Faiss

- Main Page
- Namespaces
- Classes
- Files

- File List

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