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_CORE_KERNELS_POOLING_OPS_COMMON_GPU_H_
     21 #define TENSORFLOW_CORE_KERNELS_POOLING_OPS_COMMON_GPU_H_
     22 
     23 #include <vector>
     24 #include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor"
     25 #include "tensorflow/core/framework/numeric_op.h"
     26 #include "tensorflow/core/framework/op_kernel.h"
     27 #include "tensorflow/core/framework/tensor_shape.h"
     28 #include "tensorflow/core/kernels/avgpooling_op.h"
     29 #include "tensorflow/core/kernels/maxpooling_op.h"
     30 #include "tensorflow/core/kernels/ops_util.h"
     31 #include "tensorflow/core/platform/stream_executor.h"
     32 #include "tensorflow/core/util/padding.h"
     33 #include "tensorflow/core/util/tensor_format.h"
     34 
     35 namespace tensorflow {
     36 
     37 // A helper class that launch the cudnn pooling forward operations.
     38 template <typename T>
     39 class DnnPoolingOp {
     40  public:
     41   typedef GPUDevice Device;
     42   static void Compute(OpKernelContext* context,
     43                       perftools::gputools::dnn::PoolingMode pooling_mode,
     44                       const std::vector<int32>& size,
     45                       const std::vector<int32>& stride, Padding padding,
     46                       TensorFormat data_format, const Tensor& tensor_in,
     47                       const TensorShape& tensor_out_shape, bool propagate_nans);
     48 };
     49 
     50 // A helper class that launch the cudnn pooling backward operations.
     51 // The original input and output tensors are optional for AvgPoolGrad, but
     52 // mandatory for MaxPoolGrad.
     53 template <typename T>
     54 class DnnPoolingGradOp {
     55  public:
     56   typedef GPUDevice Device;
     57   static void Compute(OpKernelContext* context,
     58                       perftools::gputools::dnn::PoolingMode pooling_mode,
     59                       const std::vector<int32>& size,
     60                       const std::vector<int32>& stride, Padding padding,
     61                       TensorFormat data_format, const Tensor* tensor_in,
     62                       const Tensor* tensor_out, const Tensor& out_backprop,
     63                       const TensorShape& tensor_in_shape, bool propagate_nans);
     64 };
     65 
     66 }  // namespace tensorflow
     67 
     68 #endif  // TENSORFLOW_CORE_KERNELS_POOLING_OPS_COMMON_GPU_H_
     69