-
Notifications
You must be signed in to change notification settings - Fork 548
Expand file tree
/
Copy pathcast.hpp
More file actions
89 lines (74 loc) · 2.09 KB
/
cast.hpp
File metadata and controls
89 lines (74 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*******************************************************
* Copyright (c) 2014, ArrayFire
* All rights reserved.
*
* This file is distributed under 3-clause BSD license.
* The complete license agreement can be obtained at:
* http://arrayfire.com/licenses/BSD-3-Clause
********************************************************/
#pragma once
#include <Array.hpp>
#include <common/half.hpp>
#include <common/jit/UnaryNode.hpp>
#include <err_cuda.hpp>
#include <math.hpp>
#include <optypes.hpp>
#include <types.hpp>
#include <af/dim4.hpp>
namespace arrayfire {
namespace cuda {
template<typename To, typename Ti>
struct CastOp {
const char *name() { return ""; }
};
#define CAST_FN(TYPE) \
template<typename Ti> \
struct CastOp<TYPE, Ti> { \
const char *name() { return "(" #TYPE ")"; } \
};
CAST_FN(int)
CAST_FN(unsigned int)
CAST_FN(unsigned char)
CAST_FN(signed char)
CAST_FN(unsigned short)
CAST_FN(short)
CAST_FN(float)
CAST_FN(double)
template<typename Ti>
struct CastOp<common::half, Ti> {
const char *name() { return "(__half)"; }
};
#define CAST_CFN(TYPE) \
template<typename Ti> \
struct CastOp<TYPE, Ti> { \
const char *name() { return "__convert_" #TYPE; } \
};
CAST_CFN(cfloat)
CAST_CFN(cdouble)
CAST_CFN(char)
template<>
struct CastOp<cfloat, cdouble> {
const char *name() { return "__convert_z2c"; }
};
template<>
struct CastOp<cdouble, cfloat> {
const char *name() { return "__convert_c2z"; }
};
template<>
struct CastOp<cfloat, cfloat> {
const char *name() { return "__convert_c2c"; }
};
template<>
struct CastOp<cdouble, cdouble> {
const char *name() { return "__convert_z2z"; }
};
// Casting from half to unsigned char causes compilation issues. First convert
// to short then to half
template<>
struct CastOp<unsigned char, common::half> {
const char *name() { return "(short)"; }
};
#undef CAST_FN
#undef CAST_CFN
} // namespace cuda
} // namespace arrayfire