1 /* Copyright 2015 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #if GOOGLE_CUDA 17 18 #define EIGEN_USE_GPU 19 20 #include "tensorflow/core/framework/bfloat16.h" 21 #include "tensorflow/core/kernels/cast_op.h" 22 23 namespace tensorflow { 24 namespace functor { 25 26 typedef Eigen::GpuDevice GPUDevice; 27 28 template <typename O, typename I> 29 struct CastFunctor<GPUDevice, O, I> { 30 void operator()(const GPUDevice& d, typename TTypes<O>::Flat o, 31 typename TTypes<I>::ConstFlat i) { 32 Cast<GPUDevice, O, I>(d, o, i); 33 } 34 }; 35 36 #define DEFINE(O, I) template struct CastFunctor<GPUDevice, O, I> 37 #define DEFINE_ALL_FROM(in_type) \ 38 DEFINE(in_type, bool); \ 39 DEFINE(in_type, uint8); \ 40 DEFINE(in_type, int8); \ 41 DEFINE(in_type, uint16); \ 42 DEFINE(in_type, int16); \ 43 DEFINE(in_type, int32); \ 44 DEFINE(in_type, int64); \ 45 DEFINE(in_type, Eigen::half); \ 46 DEFINE(in_type, float); \ 47 DEFINE(in_type, double); \ 48 DEFINE(in_type, std::complex<float>); \ 49 DEFINE(in_type, std::complex<double>) 50 51 DEFINE_ALL_FROM(bool); 52 DEFINE_ALL_FROM(uint8); 53 DEFINE_ALL_FROM(int8); 54 DEFINE_ALL_FROM(uint16); 55 DEFINE_ALL_FROM(int16); 56 DEFINE_ALL_FROM(int32); 57 DEFINE_ALL_FROM(int64); 58 DEFINE_ALL_FROM(Eigen::half); 59 DEFINE_ALL_FROM(float); 60 DEFINE_ALL_FROM(double); 61 DEFINE_ALL_FROM(std::complex<float>); 62 DEFINE_ALL_FROM(std::complex<double>); 63 DEFINE(bfloat16, float); 64 DEFINE(float, bfloat16); 65 66 #undef DEFINE_ALL_FROM 67 #undef DEFINE 68 69 } // end namespace functor 70 } // end namespace tensorflow 71 72 #endif // GOOGLE_CUDA 73