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/kernels/xent_op.h" 21 22 #include "tensorflow/core/framework/tensor_types.h" 23 #include "tensorflow/core/platform/types.h" 24 25 namespace tensorflow { 26 27 typedef Eigen::GpuDevice GPUDevice; 28 29 // Partial specialization for a GPUDevice, that uses the Eigen implementation 30 // from XentEigenImpl. 31 namespace functor { 32 template <typename T> 33 struct XentFunctor<GPUDevice, T> { 34 void operator()(const GPUDevice& d, typename TTypes<T>::ConstMatrix logits, 35 typename TTypes<T>::ConstMatrix labels, 36 typename TTypes<T>::Matrix scratch, 37 typename TTypes<T>::Vec loss, 38 typename TTypes<T>::Matrix backprop) { 39 XentEigenImpl<GPUDevice, T>::Compute(d, logits, labels, scratch, loss, 40 backprop); 41 } 42 }; 43 } // end namespace functor 44 45 // Instantiate the GPU implementation for half, float and double. 46 template struct functor::XentFunctor<GPUDevice, Eigen::half>; 47 template struct functor::XentFunctor<GPUDevice, float>; 48 template struct functor::XentFunctor<GPUDevice, double>; 49 50 } // end namespace tensorflow 51 52 #endif // GOOGLE_CUDA 53