Faiss
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
Limits.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 "Float16.cuh"
15 #include "Pair.cuh"
16 #include <limits>
17 
18 namespace faiss { namespace gpu {
19 
20 template <typename T>
21 struct Limits {
22 };
23 
24 // Unfortunately we can't use constexpr because there is no
25 // constexpr constructor for half
26 // FIXME: faiss CPU uses +/-FLT_MAX instead of +/-infinity
27 constexpr float kFloatMax = std::numeric_limits<float>::max();
28 
29 template <>
30 struct Limits<float> {
31  static __device__ __host__ inline float getMin() {
32  return -kFloatMax;
33  }
34  static __device__ __host__ inline float getMax() {
35  return kFloatMax;
36  }
37 };
38 
39 #ifdef FAISS_USE_FLOAT16
40 
41 inline __device__ __host__ half kGetHalf(unsigned short v) {
42  half h;
43  h.x = v;
44  return h;
45 }
46 
47 template <>
48 struct Limits<half> {
49  static __device__ __host__ inline half getMin() {
50  return kGetHalf(0xfbffU);
51  }
52  static __device__ __host__ inline half getMax() {
53  return kGetHalf(0x7bffU);
54  }
55 };
56 
57 #endif // FAISS_USE_FLOAT16
58 
59 constexpr int kIntMin = std::numeric_limits<int>::min();
60 constexpr int kIntMax = std::numeric_limits<int>::max();
61 
62 template <>
63 struct Limits<int> {
64  static __device__ __host__ inline int getMin() {
65  return kIntMin;
66  }
67  static __device__ __host__ inline int getMax() {
68  return kIntMax;
69  }
70 };
71 
72 template<typename K, typename V>
73 struct Limits<Pair<K, V>> {
74  static __device__ __host__ inline Pair<K, V> getMin() {
76  }
77 
78  static __device__ __host__ inline Pair<K, V> getMax() {
80  }
81 };
82 
83 } } // namespace
A simple pair type for CUDA device usage.
Definition: Pair.cuh:22