Faiss

- Main Page
- Namespaces
- Classes
- Files

- File List

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
ConversionOperators.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 //
20 // Conversion utilities
21 //
22
23 template <typename T>
24 struct ConvertTo {
25 };
26
27 template <>
28 struct ConvertTo<float> {
29 static inline __device__ float to(float v) { return v; }
30 #ifdef FAISS_USE_FLOAT16
31 static inline __device__ float to(half v) { return __half2float(v); }
32 #endif
33 };
34
35 template <>
36 struct ConvertTo<float2> {
37 static inline __device__ float2 to(float2 v) { return v; }
38 #ifdef FAISS_USE_FLOAT16
39 static inline __device__ float2 to(half2 v) { return __half22float2(v); }
40 #endif
41 };
42
43 template <>
44 struct ConvertTo<float4> {
45 static inline __device__ float4 to(float4 v) { return v; }
46 #ifdef FAISS_USE_FLOAT16
47 static inline __device__ float4 to(Half4 v) { return half4ToFloat4(v); }
48 #endif
49 };
50
51 #ifdef FAISS_USE_FLOAT16
52 template <>
53 struct ConvertTo<half> {
54 static inline __device__ half to(float v) { return __float2half(v); }
55 static inline __device__ half to(half v) { return v; }
56 };
57
58 template <>
59 struct ConvertTo<half2> {
60 static inline __device__ half2 to(float2 v) { return __float22half2_rn(v); }
61 static inline __device__ half2 to(half2 v) { return v; }
62 };
63
64 template <>
65 struct ConvertTo<Half4> {
66 static inline __device__ Half4 to(float4 v) { return float4ToHalf4(v); }
67 static inline __device__ Half4 to(Half4 v) { return v; }
68 };
69 #endif
70
71
72 } } // namespace
faiss::gpu::ConvertTo
Definition: ConversionOperators.cuh:24