Faiss

- Main Page
- Namespaces
- Classes
- Files

- File List

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