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_MAXPOOLING_OP_GPU_H_
     21 #define TENSORFLOW_CORE_KERNELS_MAXPOOLING_OP_GPU_H_
     22 
     23 #define EIGEN_USE_GPU
     24 
     25 #include "tensorflow/core/framework/tensor_types.h"
     26 #include "tensorflow/core/platform/types.h"
     27 #include "tensorflow/core/util/tensor_format.h"
     28 
     29 namespace tensorflow {
     30 
     31 namespace functor {
     32 // Run the forward pass of max pooling, optionally writing the argmax indices to
     33 // the mask array, if it is not nullptr. If mask is passed in as nullptr, the
     34 // argmax indices are not written.
     35 template <typename T>
     36 struct MaxPoolForwardWithOptionalArgmax {
     37   bool operator()(const T* bottom_data, const int batch, const int height,
     38                   const int width, const int channels, const int pooled_height,
     39                   const int pooled_width, const int kernel_h,
     40                   const int kernel_w, const int stride_h, const int stride_w,
     41                   const int pad_t, const int pad_l, T* top_data, int64* mask,
     42                   const Eigen::GpuDevice& d, bool propagate_nans);
     43 };
     44 
     45 struct MaxPoolForwardNoMask_NCHW_VECT_C {
     46   bool operator()(const int32* bottom_data, const int batch, const int height,
     47                   const int width, int channels, const int pooled_height,
     48                   const int pooled_width, const int kernel_h,
     49                   const int kernel_w, const int stride_h, const int stride_w,
     50                   const int pad_t, const int pad_l, int32* top_data,
     51                   const Eigen::GpuDevice& d);
     52 };
     53 
     54 template <typename T>
     55 struct MaxPoolBackwardWithArgmax {
     56   bool operator()(const int output_size, const int input_size,
     57                   const T* top_diff, const int64* mask, const int top_offset,
     58                   const int bottom_offset, T* bottom_diff,
     59                   const Eigen::GpuDevice& d);
     60 };
     61 
     62 template <typename T>
     63 struct MaxPoolBackwardNoMask {
     64   bool operator()(const T* bottom_data, const int batch, const int height,
     65                   const int width, const int channels, const int pooled_height,
     66                   const int pooled_width, const int kernel_h,
     67                   const int kernel_w, const int stride_h, const int stride_w,
     68                   const int pad_t, const int pad_l, const T* top_diff,
     69                   T* bottom_diff, const Eigen::GpuDevice& d);
     70 };
     71 
     72 template <typename T>
     73 struct MaxPoolGradBackwardWithArgmax {
     74   bool operator()(const int output_size, const int input_size,
     75                   const T* top_diff, const int64* mask, const int top_offset,
     76                   const int bottom_offset, T* bottom_diff,
     77                   const Eigen::GpuDevice& d);
     78 };
     79 
     80 template <typename T>
     81 struct MaxPoolGradBackwardNoMask {
     82   bool operator()(TensorFormat data_format, const T* bottom_data,
     83                   const T* output_data, const int batch,
     84                   const int pooled_height, const int pooled_width,
     85                   const int channels, const int height, const int width,
     86                   const int kernel_h, const int kernel_w, const int stride_h,
     87                   const int stride_w, const int pad_t, const int pad_l,
     88                   const T* top_diff, T* bottom_diff, const Eigen::GpuDevice& d);
     89 };
     90 
     91 }  // namespace functor
     92 
     93 }  // namespace tensorflow
     94 
     95 #endif  // TENSORFLOW_CORE_KERNELS_MAXPOOLING_OP_GPU_H_
     96