Faiss

- Main Page
- Namespaces
- Classes
- Files

- File List

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
Comparators.cuh
1 /**
2 * Copyright (c) Facebook, Inc. and its affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8
9 #pragma once
10
11 #include <cuda.h>
12 #include "Float16.cuh"
13
14 namespace faiss { namespace gpu {
15
16 template <typename T>
17 struct Comparator {
18 __device__ static inline bool lt(T a, T b) {
19 return a < b;
20 }
21
22 __device__ static inline bool gt(T a, T b) {
23 return a > b;
24 }
25 };
26
27 #ifdef FAISS_USE_FLOAT16
28
29 template <>
30 struct Comparator<half> {
31 __device__ static inline bool lt(half a, half b) {
32 #if FAISS_USE_FULL_FLOAT16
33 return __hlt(a, b);
34 #else
35 return __half2float(a) < __half2float(b);
36 #endif // FAISS_USE_FULL_FLOAT16
37 }
38
39 __device__ static inline bool gt(half a, half b) {
40 #if FAISS_USE_FULL_FLOAT16
41 return __hgt(a, b);
42 #else
43 return __half2float(a) > __half2float(b);
44 #endif // FAISS_USE_FULL_FLOAT16
45 }
46 };
47
48 #endif // FAISS_USE_FLOAT16
49
50 } } // namespace
faiss::gpu::Comparator
Definition: Comparators.cuh:17