-
Notifications
You must be signed in to change notification settings - Fork 74k
/
cast_op_gpu.cu.cc
159 lines (135 loc) · 4.89 KB
/
cast_op_gpu.cu.cc
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#if (defined(GOOGLE_CUDA) && GOOGLE_CUDA) || \
(defined(TENSORFLOW_USE_ROCM) && TENSORFLOW_USE_ROCM)
#define EIGEN_USE_GPU
#include "tensorflow/core/framework/bfloat16.h"
#define SPECIALIZE_FOR_GPUS
#include "tensorflow/core/kernels/cast_op.h"
#undef SPECIALIZE_FOR_GPUS
namespace tensorflow {
namespace functor {
typedef Eigen::GpuDevice GPUDevice;
#if defined(MLIR_GENERATED_GPU_KERNELS_ENABLED)
CAST_FUNCTORS_SUBSET(GPUDevice);
#else
CAST_FUNCTORS(GPUDevice);
#endif
#define DEFINE(O, I) template struct CastFunctor<GPUDevice, O, I>
#define DEFINE_ALL_FROM(in_type) \
DEFINE(in_type, bool); \
DEFINE(in_type, uint8); \
DEFINE(in_type, uint16); \
DEFINE(in_type, uint32); \
DEFINE(in_type, uint64); \
DEFINE(in_type, int8); \
DEFINE(in_type, int16); \
DEFINE(in_type, int32); \
DEFINE(in_type, int64); \
DEFINE(in_type, Eigen::half); \
DEFINE(in_type, float); \
DEFINE(in_type, double); \
DEFINE(in_type, std::complex<float>); \
DEFINE(in_type, std::complex<double>)
// Required functors not previously specialized for truncation.
DEFINE(double, float8_e5m2);
DEFINE(float, float8_e5m2);
DEFINE(bfloat16, float8_e5m2);
DEFINE(Eigen::half, float8_e5m2);
DEFINE(float8_e5m2, float8_e5m2);
DEFINE(float8_e4m3fn, float8_e5m2);
DEFINE(double, float8_e4m3fn);
DEFINE(float, float8_e4m3fn);
DEFINE(bfloat16, float8_e4m3fn);
DEFINE(Eigen::half, float8_e4m3fn);
DEFINE(float8_e4m3fn, float8_e4m3fn);
#if defined(MLIR_GENERATED_GPU_KERNELS_ENABLED)
// The cast from float to double is still needed for resize_bilinear_op.cc
DEFINE(double, float);
#else
DEFINE_ALL_FROM(bool);
DEFINE_ALL_FROM(uint8);
DEFINE_ALL_FROM(uint16);
DEFINE_ALL_FROM(uint32);
DEFINE_ALL_FROM(uint64);
DEFINE_ALL_FROM(int8);
DEFINE_ALL_FROM(int16);
DEFINE_ALL_FROM(int32);
DEFINE_ALL_FROM(int64);
DEFINE_ALL_FROM(double);
DEFINE_ALL_FROM(std::complex<double>);
#endif
#define DEFINE_ALL_TO_FLOAT(out_type) \
DEFINE(out_type, bool); \
DEFINE(out_type, uint8); \
DEFINE(out_type, uint16); \
DEFINE(out_type, uint32); \
DEFINE(out_type, uint64); \
DEFINE(out_type, int8); \
DEFINE(out_type, int16); \
DEFINE(out_type, int32); \
DEFINE(out_type, int64); \
DEFINE(out_type, Eigen::half); \
DEFINE(out_type, bfloat16); \
DEFINE(out_type, float); \
DEFINE(out_type, std::complex<float>)
#define DEFINE_ALL_TO_HALF(out_type) \
DEFINE(out_type, bool); \
DEFINE(out_type, uint8); \
DEFINE(out_type, uint16); \
DEFINE(out_type, uint32); \
DEFINE(out_type, uint64); \
DEFINE(out_type, int8); \
DEFINE(out_type, int16); \
DEFINE(out_type, int32); \
DEFINE(out_type, int64); \
DEFINE(out_type, Eigen::half); \
DEFINE(out_type, bfloat16)
DEFINE_ALL_TO_HALF(bfloat16);
DEFINE(bool, bfloat16);
DEFINE(uint8, bfloat16);
DEFINE(uint16, bfloat16);
DEFINE(uint32, bfloat16);
DEFINE(uint64, bfloat16);
DEFINE(int8, bfloat16);
DEFINE(int16, bfloat16);
DEFINE(int32, bfloat16);
DEFINE(int64, bfloat16);
DEFINE(std::complex<double>, bfloat16);
DEFINE(double, bfloat16);
DEFINE(bfloat16, std::complex<float>);
DEFINE(bfloat16, std::complex<double>);
DEFINE(bfloat16, double);
#if defined(MLIR_GENERATED_GPU_KERNELS_ENABLED)
// The cast from Eigen::half is still needed for depthwise_conv_grad_op.cc.
DEFINE(float, Eigen::half);
// The cast from float to float is still needed for resize_bilinear_op.cc.
DEFINE(float, float);
// The casts from complex to the complex element type is still needed for
// self_adjoint_eig_v2_op_gpu.cc
DEFINE(std::complex<float>, float);
DEFINE(std::complex<double>, double);
DEFINE(float, bfloat16);
DEFINE(Eigen::half, bfloat16);
DEFINE(std::complex<float>, bfloat16);
#else
DEFINE_ALL_TO_HALF(Eigen::half);
DEFINE_ALL_TO_FLOAT(float);
DEFINE_ALL_TO_FLOAT(std::complex<float>);
#endif
#undef DEFINE_ALL_TO_FLOAT
#undef DEFINE_ALL_TO_HALF
#undef DEFINE_ALL_FROM
#undef DEFINE
} // end namespace functor
} // end namespace tensorflow
#endif // GOOGLE_CUDA || TENSORFLOW_USE_ROCM