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 // 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 (256)
38 int tileSize = -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>& queries,
45 int k,
46 Tensor<float, 2, true>& outDistances,
47 Tensor<int, 2, true>& outIndices,
48 // Hint to use a different sized tile for
49 // multi-streaming the queries. If <= 0, we use the
50 // default (256)
51 int tileSize = -1);
52
53 #ifdef FAISS_USE_FLOAT16
54 void runIPDistance(GpuResources* resources,
55 Tensor<half, 2, true>& vectors,
56 Tensor<half, 2, true>& queries,
57 int k,
58 Tensor<half, 2, true>& outDistances,
59 Tensor<int, 2, true>& outIndices,
60 int tileSize = -1);
61
62 void runL2Distance(GpuResources* resources,
63 Tensor<half, 2, true>& vectors,
64 Tensor<half, 1, true>* vectorNorms,
65 Tensor<half, 2, true>& queries,
66 int k,
67 Tensor<half, 2, true>& outDistances,
68 Tensor<int, 2, true>& outIndices,
69 bool ignoreOutDistances = false,
70 int tileSize = -1);
71 #endif
72
73 } } // namespace