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 
     18 #define EIGEN_USE_GPU
     19 
     20 #include "tensorflow/core/kernels/sparse_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, typename Index>
     33 struct SparseXentFunctor<GPUDevice, T, Index> {
     34   void operator()(const GPUDevice& d, typename TTypes<T>::ConstMatrix logits,
     35                   typename TTypes<Index>::ConstVec labels,
     36                   typename TTypes<T>::Vec scratch, typename TTypes<T>::Vec loss,
     37                   typename TTypes<T>::Matrix backprop) {
     38     SparseXentEigenImpl<GPUDevice, T, Index>::Compute(d, logits, labels,
     39                                                       scratch, loss, backprop);
     40   }
     41 };
     42 }  // end namespace functor
     43 
     44 // Instantiate the GPU implementation for float.
     45 #define REGISTER(Index)                                                      \
     46   template struct functor::SparseXentFunctor<GPUDevice, float, Index>;       \
     47   template class generator::SparseXentGradGenerator<float, Index>;           \
     48   template struct functor::SparseXentFunctor<GPUDevice, Eigen::half, Index>; \
     49   template class generator::SparseXentGradGenerator<Eigen::half, Index>;
     50 REGISTER(int32)
     51 REGISTER(int64)
     52 #undef REGISTER
     53 
     54 }  // end namespace tensorflow
     55 
     56 #endif  // GOOGLE_CUDA
     57