• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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                   const bool include_batch_in_index);
44 };
45 
46 struct MaxPoolForwardNoMask_NCHW_VECT_C {
47   bool operator()(const int32* bottom_data, const int batch, const int height,
48                   const int width, int channels, const int pooled_height,
49                   const int pooled_width, const int kernel_h,
50                   const int kernel_w, const int stride_h, const int stride_w,
51                   const int pad_t, const int pad_l, int32* top_data,
52                   const Eigen::GpuDevice& d);
53 };
54 
55 template <typename T>
56 struct MaxPoolBackwardWithArgmax {
57   bool operator()(const int output_size, const int input_size,
58                   const T* top_diff, const int64* mask, const int top_offset,
59                   const int bottom_offset, T* bottom_diff,
60                   const Eigen::GpuDevice& d, const bool include_batch_in_index);
61 };
62 
63 template <typename T>
64 struct MaxPoolBackwardNoMask {
65   bool operator()(const T* bottom_data, const int batch, const int height,
66                   const int width, const int channels, const int pooled_height,
67                   const int pooled_width, const int kernel_h,
68                   const int kernel_w, const int stride_h, const int stride_w,
69                   const int pad_t, const int pad_l, const T* top_diff,
70                   T* bottom_diff, const Eigen::GpuDevice& d);
71 };
72 
73 template <typename T>
74 struct MaxPoolGradBackwardWithArgmax {
75   bool operator()(const int output_size, const int input_size,
76                   const T* top_diff, const int64* mask, const int top_offset,
77                   const int bottom_offset, T* bottom_diff,
78                   const Eigen::GpuDevice& d, const bool include_batch_in_index);
79 };
80 
81 template <typename T>
82 struct MaxPoolGradBackwardNoMask {
83   bool operator()(TensorFormat data_format, const T* bottom_data,
84                   const T* output_data, const int batch,
85                   const int pooled_height, const int pooled_width,
86                   const int channels, const int height, const int width,
87                   const int kernel_h, const int kernel_w, const int stride_h,
88                   const int stride_w, const int pad_t, const int pad_l,
89                   const T* top_diff, T* bottom_diff, const Eigen::GpuDevice& d);
90 };
91 
92 }  // namespace functor
93 
94 }  // namespace tensorflow
95 
96 #endif  // TENSORFLOW_CORE_KERNELS_MAXPOOLING_OP_GPU_H_
97