Faiss
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
Comparators.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 <cuda.h>
15 #include "Float16.cuh"
16 
17 namespace faiss { namespace gpu {
18 
19 template <typename T>
20 struct Comparator {
21  __device__ static inline bool lt(T a, T b) {
22  return a < b;
23  }
24 
25  __device__ static inline bool gt(T a, T b) {
26  return a > b;
27  }
28 };
29 
30 #ifdef FAISS_USE_FLOAT16
31 
32 template <>
33 struct Comparator<half> {
34  __device__ static inline bool lt(half a, half b) {
35 #if FAISS_USE_FULL_FLOAT16
36  return __hlt(a, b);
37 #else
38  return __half2float(a) < __half2float(b);
39 #endif // FAISS_USE_FULL_FLOAT16
40  }
41 
42  __device__ static inline bool gt(half a, half b) {
43 #if FAISS_USE_FULL_FLOAT16
44  return __hgt(a, b);
45 #else
46  return __half2float(a) > __half2float(b);
47 #endif // FAISS_USE_FULL_FLOAT16
48  }
49 };
50 
51 #endif // FAISS_USE_FLOAT16
52 
53 } } // namespace