Faiss
 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 // 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 
36 /// Calculates brute-force inner product distance between `vectors`
37 /// and `queries`, returning the k closest results seen
38 void runIPDistance(GpuResources* resources,
39  Tensor<float, 2, true>& vectors,
40  Tensor<float, 2, true>* vectorsTransposed,
41  Tensor<float, 2, true>& queries,
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  Tensor<half, 2, true>* vectorsTransposed,
50  Tensor<half, 2, true>& queries,
51  int k,
52  Tensor<half, 2, true>& outDistances,
53  Tensor<int, 2, true>& outIndices,
54  bool useHgemm);
55 
56 void runL2Distance(GpuResources* resources,
57  Tensor<half, 2, true>& vectors,
58  Tensor<half, 2, true>* vectorsTransposed,
59  Tensor<half, 1, true>* vectorNorms,
60  Tensor<half, 2, true>& queries,
61  int k,
62  Tensor<half, 2, true>& outDistances,
63  Tensor<int, 2, true>& outIndices,
64  bool useHgemm,
65  bool ignoreOutDistances = false);
66 #endif
67 
68 } } // namespace