-
Notifications
You must be signed in to change notification settings - Fork 555
Expand file tree
/
Copy pathbinary.hpp
More file actions
133 lines (114 loc) · 3.98 KB
/
Copy pathbinary.hpp
File metadata and controls
133 lines (114 loc) · 3.98 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*******************************************************
* Copyright (c) 2022, 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 <optypes.hpp>
#include <common/half.hpp>
using arrayfire::common::half;
namespace arrayfire {
namespace oneapi {
template<typename To, typename Ti, af_op_t op>
struct BinOp;
#define BINARY_TYPE_1(fn) \
template<typename To, typename Ti> \
struct BinOp<To, Ti, af_##fn##_t> { \
const char *name() { return "__" #fn; } \
}; \
\
template<typename To> \
struct BinOp<To, cfloat, af_##fn##_t> { \
const char *name() { return "__c" #fn "f"; } \
}; \
\
template<typename To> \
struct BinOp<To, cdouble, af_##fn##_t> { \
const char *name() { return "__c" #fn; } \
};
BINARY_TYPE_1(eq)
BINARY_TYPE_1(neq)
BINARY_TYPE_1(lt)
BINARY_TYPE_1(le)
BINARY_TYPE_1(gt)
BINARY_TYPE_1(ge)
BINARY_TYPE_1(add)
BINARY_TYPE_1(sub)
BINARY_TYPE_1(mul)
BINARY_TYPE_1(div)
BINARY_TYPE_1(and)
BINARY_TYPE_1(or)
BINARY_TYPE_1(bitand)
BINARY_TYPE_1(bitor)
BINARY_TYPE_1(bitxor)
BINARY_TYPE_1(bitshiftl)
BINARY_TYPE_1(bitshiftr)
#undef BINARY_TYPE_1
#define BINARY_TYPE_2(fn) \
template<typename To, typename Ti> \
struct BinOp<To, Ti, af_##fn##_t> { \
const char *name() { return "__" #fn; } \
}; \
template<typename To> \
struct BinOp<To, float, af_##fn##_t> { \
const char *name() { return "f" #fn; } \
}; \
template<typename To> \
struct BinOp<To, double, af_##fn##_t> { \
const char *name() { return "f" #fn; } \
}; \
template<typename To> \
struct BinOp<To, cfloat, af_##fn##_t> { \
const char *name() { return "__c" #fn "f"; } \
}; \
\
template<typename To> \
struct BinOp<To, cdouble, af_##fn##_t> { \
const char *name() { return "__c" #fn; } \
};
BINARY_TYPE_2(min)
BINARY_TYPE_2(max)
BINARY_TYPE_2(rem)
BINARY_TYPE_2(mod)
template<typename To, typename Ti>
struct BinOp<To, Ti, af_pow_t> {
const char *name() { return "__pow"; }
};
#define POW_BINARY_OP(INTYPE, OPNAME) \
template<typename To> \
struct BinOp<To, INTYPE, af_pow_t> { \
const char *name() { return OPNAME; } \
};
POW_BINARY_OP(double, "pow")
POW_BINARY_OP(float, "pow")
POW_BINARY_OP(half, "pow")
POW_BINARY_OP(intl, "__powll")
POW_BINARY_OP(uintl, "__powul")
POW_BINARY_OP(uint, "__powui")
POW_BINARY_OP(int, "__powsi")
#undef POW_BINARY_OP
template<typename Ti>
struct BinOp<cfloat, Ti, af_cplx2_t> {
const char *name() { return "__cplx2f"; }
};
template<typename Ti>
struct BinOp<cdouble, Ti, af_cplx2_t> {
const char *name() { return "__cplx2"; }
};
template<typename To, typename Ti>
struct BinOp<To, Ti, af_cplx2_t> {
const char *name() { return "noop"; }
};
template<typename To, typename Ti>
struct BinOp<To, Ti, af_atan2_t> {
const char *name() { return "atan2"; }
};
template<typename To, typename Ti>
struct BinOp<To, Ti, af_hypot_t> {
const char *name() { return "hypot"; }
};
} // namespace oneapi
} // namespace arrayfire