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 CC-by-NC 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 "../utils/DeviceTensor.cuh"
14 #include "../utils/Float16.cuh"
15
16 namespace faiss { namespace gpu {
17
18 class GpuResources;
19
20 /// Calculates brute-force L2 distance between `vectors` and
21 /// `queries`, returning the k closest results seen
22 void runL2Distance(GpuResources* resources,
23 Tensor<float, 2, true>& vectors,
24 Tensor<float, 2, true>* vectorsTransposed,
25 // can be optionally pre-computed; nullptr if we
26 // have to compute it upon the call
27 Tensor<float, 1, true>* vectorNorms,
28 Tensor<float, 2, true>& queries,
29 int k,
30 Tensor<float, 2, true>& outDistances,
31 Tensor<int, 2, true>& outIndices,
32 // Do we care about `outDistances`? If not, we can
33 // take shortcuts.
34 bool ignoreOutDistances = false,
35 // Hint to use a different sized tile for
36 // multi-streaming the queries. If <= 0, we use the
37 // default
38 int tileSizeOverride = -1);
39
40 /// Calculates brute-force inner product distance between `vectors`
41 /// and `queries`, returning the k closest results seen
42 void runIPDistance(GpuResources* resources,
43 Tensor<float, 2, true>& vectors,
44 Tensor<float, 2, true>* vectorsTransposed,
45 Tensor<float, 2, true>& queries,
46 int k,
47 Tensor<float, 2, true>& outDistances,
48 Tensor<int, 2, true>& outIndices,
49 // Hint to use a different sized tile for
50 // multi-streaming the queries. If <= 0, we use the
51 // default
52 int tileSizeOverride = -1);
53
54 #ifdef FAISS_USE_FLOAT16
55 void runIPDistance(GpuResources* resources,
56 Tensor<half, 2, true>& vectors,
57 Tensor<half, 2, true>* vectorsTransposed,
58 Tensor<half, 2, true>& queries,
59 int k,
60 Tensor<half, 2, true>& outDistances,
61 Tensor<int, 2, true>& outIndices,
62 bool useHgemm,
63 int tileSizeOverride = -1);
64
65 void runL2Distance(GpuResources* resources,
66 Tensor<half, 2, true>& vectors,
67 Tensor<half, 2, true>* vectorsTransposed,
68 Tensor<half, 1, true>* vectorNorms,
69 Tensor<half, 2, true>& queries,
70 int k,
71 Tensor<half, 2, true>& outDistances,
72 Tensor<int, 2, true>& outIndices,
73 bool useHgemm,
74 bool ignoreOutDistances = false,
75 int tileSizeOverride = -1);
76 #endif
77
78 } } // namespace