Home | History | Annotate | Download | only in kernels
      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 #error This file must only be included when building with Cuda support
     18 #endif
     19 
     20 #ifndef TENSORFLOW_KERNELS_CWISE_OPS_GPU_GRADIENTS_CU_H_
     21 #define TENSORFLOW_KERNELS_CWISE_OPS_GPU_GRADIENTS_CU_H_
     22 
     23 #define EIGEN_USE_GPU
     24 
     25 #include <complex>
     26 
     27 #include "tensorflow/core/framework/tensor_types.h"
     28 #include "tensorflow/core/kernels/cwise_ops.h"
     29 #include "tensorflow/core/kernels/cwise_ops_gradients.h"
     30 #include "tensorflow/core/platform/types.h"
     31 
     32 #include "tensorflow/core/platform/logging.h"
     33 namespace tensorflow {
     34 namespace functor {
     35 
     36 typedef Eigen::GpuDevice GPUDevice;
     37 typedef std::complex<float> complex64;
     38 typedef std::complex<double> complex128;
     39 
     40 // Partial specialization of SimpleBinaryFunctor<Device=GPUDevice, Functor>.
     41 template <typename Functor>
     42 struct SimpleBinaryFunctor<GPUDevice, Functor> {
     43   void operator()(const GPUDevice& d, typename Functor::tout_type out,
     44                   typename Functor::tin_type in1,
     45                   typename Functor::tin_type in2) {
     46     To32Bit(out).device(d) =
     47         To32Bit(in1).binaryExpr(in2, typename Functor::func());
     48   }
     49 };
     50 
     51 // Macros to explicitly instantiate kernels on GPU for multiple types
     52 // (T0, T1, etc.) for SimpleBiaryFunctor (e.g., functor::tanh_grad).
     53 #define DEFINE_SIMPLE_BINARY1(F, T) \
     54   template struct SimpleBinaryFunctor<GPUDevice, F<T> >
     55 #define DEFINE_SIMPLE_BINARY2(F, T0, T1) \
     56   DEFINE_SIMPLE_BINARY1(F, T0);          \
     57   DEFINE_SIMPLE_BINARY1(F, T1)
     58 #define DEFINE_SIMPLE_BINARY3(F, T0, T1, T2) \
     59   DEFINE_SIMPLE_BINARY2(F, T0, T1);          \
     60   DEFINE_SIMPLE_BINARY1(F, T2)
     61 #define DEFINE_SIMPLE_BINARY4(F, T0, T1, T2, T3) \
     62   DEFINE_SIMPLE_BINARY2(F, T0, T1);              \
     63   DEFINE_SIMPLE_BINARY2(F, T2, T3)
     64 #define DEFINE_SIMPLE_BINARY5(F, T0, T1, T2, T3, T4) \
     65   DEFINE_SIMPLE_BINARY2(F, T0, T1);                  \
     66   DEFINE_SIMPLE_BINARY3(F, T2, T3, T4)
     67 
     68 }  // end namespace functor
     69 }  // end namespace tensorflow
     70 
     71 #endif  // TENSORFLOW_KERNELS_CWISE_OPS_GPU_GRADIENTS_CU_H_
     72