Skip to content

Commit feaf1e2

Browse files
author
chengduo
authored
Merge pull request #5608 from chengduoZH/fix_pooling_function_parameter_order
fix pooling functor parameter order
2 parents d7319c2 + 2160497 commit feaf1e2

File tree

5 files changed

+278
-272
lines changed

5 files changed

+278
-272
lines changed

paddle/operators/math/pooling.cc

Lines changed: 61 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ template <typename PoolProcess, typename T>
2727
class Pool2dFunctor<platform::CPUPlace, PoolProcess, T> {
2828
public:
2929
void operator()(const platform::DeviceContext& context,
30-
const framework::Tensor& input, framework::Tensor& output,
31-
std::vector<int>& ksize, std::vector<int>& strides,
32-
std::vector<int>& paddings, PoolProcess pool_process) {
30+
const framework::Tensor& input, std::vector<int>& ksize,
31+
std::vector<int>& strides, std::vector<int>& paddings,
32+
PoolProcess pool_process, framework::Tensor* output) {
3333
const int batch_size = input.dims()[0];
3434
const int input_height = input.dims()[2];
3535
const int input_width = input.dims()[3];
36-
const int output_channels = output.dims()[1];
37-
const int output_height = output.dims()[2];
38-
const int output_width = output.dims()[3];
36+
const int output_channels = output->dims()[1];
37+
const int output_height = output->dims()[2];
38+
const int output_width = output->dims()[3];
3939
const int ksize_height = ksize[0];
4040
const int ksize_width = ksize[1];
4141
const int stride_height = strides[0];
@@ -47,7 +47,7 @@ class Pool2dFunctor<platform::CPUPlace, PoolProcess, T> {
4747
const int output_stride = output_height * output_width;
4848

4949
const T* input_data = input.data<T>();
50-
T* output_data = output.mutable_data<T>(context.GetPlace());
50+
T* output_data = output->mutable_data<T>(context.GetPlace());
5151

5252
for (int i = 0; i < batch_size; i++) {
5353
for (int c = 0; c < output_channels; ++c) {
@@ -87,11 +87,12 @@ template <typename PoolProcess, class T>
8787
class Pool2dGradFunctor<platform::CPUPlace, PoolProcess, T> {
8888
public:
8989
void operator()(const platform::DeviceContext& context,
90-
const framework::Tensor& input, framework::Tensor& input_grad,
90+
const framework::Tensor& input,
9191
const framework::Tensor& output,
9292
const framework::Tensor& output_grad, std::vector<int>& ksize,
9393
std::vector<int>& strides, std::vector<int>& paddings,
94-
PoolProcess pool_grad_process) {
94+
PoolProcess pool_grad_process,
95+
framework::Tensor* input_grad) {
9596
const int batch_size = input.dims()[0];
9697
const int input_height = input.dims()[2];
9798
const int input_width = input.dims()[3];
@@ -110,7 +111,7 @@ class Pool2dGradFunctor<platform::CPUPlace, PoolProcess, T> {
110111
const T* input_data = input.data<T>();
111112
const T* output_data = output.data<T>();
112113
const T* output_grad_data = output_grad.data<T>();
113-
T* input_grad_data = input_grad.mutable_data<T>(context.GetPlace());
114+
T* input_grad_data = input_grad->mutable_data<T>(context.GetPlace());
114115

115116
for (int i = 0; i < batch_size; i++) {
116117
for (int c = 0; c < output_channels; ++c) {
@@ -154,10 +155,11 @@ template <class T>
154155
class MaxPool2dGradFunctor<platform::CPUPlace, T> {
155156
public:
156157
void operator()(const platform::DeviceContext& context,
157-
const framework::Tensor& input, framework::Tensor& input_grad,
158+
const framework::Tensor& input,
158159
const framework::Tensor& output,
159160
const framework::Tensor& output_grad, std::vector<int>& ksize,
160-
std::vector<int>& strides, std::vector<int>& paddings) {
161+
std::vector<int>& strides, std::vector<int>& paddings,
162+
framework::Tensor* input_grad) {
161163
const int batch_size = input.dims()[0];
162164
const int input_height = input.dims()[2];
163165
const int input_width = input.dims()[3];
@@ -176,7 +178,7 @@ class MaxPool2dGradFunctor<platform::CPUPlace, T> {
176178
const T* input_data = input.data<T>();
177179
const T* output_data = output.data<T>();
178180
const T* output_grad_data = output_grad.data<T>();
179-
T* input_grad_data = input_grad.mutable_data<T>(context.GetPlace());
181+
T* input_grad_data = input_grad->mutable_data<T>(context.GetPlace());
180182

181183
for (int i = 0; i < batch_size; i++) {
182184
for (int c = 0; c < output_channels; ++c) {
@@ -240,17 +242,17 @@ template <typename PoolProcess, class T>
240242
class Pool3dFunctor<platform::CPUPlace, PoolProcess, T> {
241243
public:
242244
void operator()(const platform::DeviceContext& context,
243-
const framework::Tensor& input, framework::Tensor& output,
244-
std::vector<int>& ksize, std::vector<int>& strides,
245-
std::vector<int>& paddings, PoolProcess pool_process) {
245+
const framework::Tensor& input, std::vector<int>& ksize,
246+
std::vector<int>& strides, std::vector<int>& paddings,
247+
PoolProcess pool_process, framework::Tensor* output) {
246248
const int batch_size = input.dims()[0];
247249
const int input_depth = input.dims()[2];
248250
const int input_height = input.dims()[3];
249251
const int input_width = input.dims()[4];
250-
const int output_channels = output.dims()[1];
251-
const int output_depth = output.dims()[2];
252-
const int output_height = output.dims()[3];
253-
const int output_width = output.dims()[4];
252+
const int output_channels = output->dims()[1];
253+
const int output_depth = output->dims()[2];
254+
const int output_height = output->dims()[3];
255+
const int output_width = output->dims()[4];
254256
const int ksize_depth = ksize[0];
255257
const int ksize_height = ksize[1];
256258
const int ksize_width = ksize[2];
@@ -265,7 +267,7 @@ class Pool3dFunctor<platform::CPUPlace, PoolProcess, T> {
265267
const int output_stride = output_depth * output_height * output_width;
266268

267269
const T* input_data = input.data<T>();
268-
T* output_data = output.mutable_data<T>(context.GetPlace());
270+
T* output_data = output->mutable_data<T>(context.GetPlace());
269271

270272
for (int i = 0; i < batch_size; i++) {
271273
for (int c = 0; c < output_channels; ++c) {
@@ -315,11 +317,12 @@ template <typename PoolProcess, class T>
315317
class Pool3dGradFunctor<platform::CPUPlace, PoolProcess, T> {
316318
public:
317319
void operator()(const platform::DeviceContext& context,
318-
const framework::Tensor& input, framework::Tensor& input_grad,
320+
const framework::Tensor& input,
319321
const framework::Tensor& output,
320322
const framework::Tensor& output_grad, std::vector<int>& ksize,
321323
std::vector<int>& strides, std::vector<int>& paddings,
322-
PoolProcess pool_grad_process) {
324+
PoolProcess pool_grad_process,
325+
framework::Tensor* input_grad) {
323326
const int batch_size = input.dims()[0];
324327
const int input_depth = input.dims()[2];
325328
const int input_height = input.dims()[3];
@@ -343,7 +346,7 @@ class Pool3dGradFunctor<platform::CPUPlace, PoolProcess, T> {
343346
const T* input_data = input.data<T>();
344347
const T* output_data = output.data<T>();
345348
const T* output_grad_data = output_grad.data<T>();
346-
T* input_grad_data = input_grad.mutable_data<T>(context.GetPlace());
349+
T* input_grad_data = input_grad->mutable_data<T>(context.GetPlace());
347350

348351
for (int i = 0; i < batch_size; i++) {
349352
for (int c = 0; c < output_channels; ++c) {
@@ -398,10 +401,11 @@ template <class T>
398401
class MaxPool3dGradFunctor<platform::CPUPlace, T> {
399402
public:
400403
void operator()(const platform::DeviceContext& context,
401-
const framework::Tensor& input, framework::Tensor& input_grad,
404+
const framework::Tensor& input,
402405
const framework::Tensor& output,
403406
const framework::Tensor& output_grad, std::vector<int>& ksize,
404-
std::vector<int>& strides, std::vector<int>& paddings) {
407+
std::vector<int>& strides, std::vector<int>& paddings,
408+
framework::Tensor* input_grad) {
405409
const int batch_size = input.dims()[0];
406410
const int input_depth = input.dims()[2];
407411
const int input_height = input.dims()[3];
@@ -425,7 +429,7 @@ class MaxPool3dGradFunctor<platform::CPUPlace, T> {
425429
const T* input_data = input.data<T>();
426430
const T* output_data = output.data<T>();
427431
const T* output_grad_data = output_grad.data<T>();
428-
T* input_grad_data = input_grad.mutable_data<T>(context.GetPlace());
432+
T* input_grad_data = input_grad->mutable_data<T>(context.GetPlace());
429433

430434
for (int i = 0; i < batch_size; i++) {
431435
for (int c = 0; c < output_channels; ++c) {
@@ -498,15 +502,15 @@ template <typename T>
498502
class MaxPool2dWithIndexFunctor<platform::CPUPlace, T> {
499503
public:
500504
void operator()(const platform::DeviceContext& context,
501-
const framework::Tensor& input, framework::Tensor& output,
502-
framework::Tensor& mask, std::vector<int>& ksize,
503-
std::vector<int>& strides, std::vector<int>& paddings) {
505+
const framework::Tensor& input, std::vector<int>& ksize,
506+
std::vector<int>& strides, std::vector<int>& paddings,
507+
framework::Tensor* output, framework::Tensor* mask) {
504508
const int batch_size = input.dims()[0];
505509
const int input_height = input.dims()[2];
506510
const int input_width = input.dims()[3];
507-
const int output_channels = output.dims()[1];
508-
const int output_height = output.dims()[2];
509-
const int output_width = output.dims()[3];
511+
const int output_channels = output->dims()[1];
512+
const int output_height = output->dims()[2];
513+
const int output_width = output->dims()[3];
510514
const int ksize_height = ksize[0];
511515
const int ksize_width = ksize[1];
512516
const int stride_height = strides[0];
@@ -517,8 +521,8 @@ class MaxPool2dWithIndexFunctor<platform::CPUPlace, T> {
517521
const int output_stride = output_height * output_width;
518522

519523
const T* input_data = input.data<T>();
520-
T* output_data = output.mutable_data<T>(context.GetPlace());
521-
T* mask_data = mask.mutable_data<T>(context.GetPlace());
524+
T* output_data = output->mutable_data<T>(context.GetPlace());
525+
T* mask_data = mask->mutable_data<T>(context.GetPlace());
522526

523527
for (int i = 0; i < batch_size; i++) {
524528
for (int c = 0; c < output_channels; ++c) {
@@ -563,13 +567,13 @@ template <typename T>
563567
class MaxPool2dWithIndexGradFunctor<platform::CPUPlace, T> {
564568
public:
565569
void operator()(const platform::DeviceContext& context,
566-
framework::Tensor& input_grad,
567570
const framework::Tensor& output_grad,
568571
const framework::Tensor& mask, std::vector<int>& ksize,
569-
std::vector<int>& strides, std::vector<int>& paddings) {
570-
const int batch_size = input_grad.dims()[0];
571-
const int input_height = input_grad.dims()[2];
572-
const int input_width = input_grad.dims()[3];
572+
std::vector<int>& strides, std::vector<int>& paddings,
573+
framework::Tensor* input_grad) {
574+
const int batch_size = input_grad->dims()[0];
575+
const int input_height = input_grad->dims()[2];
576+
const int input_width = input_grad->dims()[3];
573577
const int output_channels = output_grad.dims()[1];
574578
const int output_height = output_grad.dims()[2];
575579
const int output_width = output_grad.dims()[3];
@@ -578,7 +582,7 @@ class MaxPool2dWithIndexGradFunctor<platform::CPUPlace, T> {
578582

579583
const T* mask_data = mask.data<T>();
580584
const T* output_grad_data = output_grad.data<T>();
581-
T* input_grad_data = input_grad.mutable_data<T>(context.GetPlace());
585+
T* input_grad_data = input_grad->mutable_data<T>(context.GetPlace());
582586

583587
for (int n = 0; n < batch_size; ++n) {
584588
for (int c = 0; c < output_channels; ++c) {
@@ -612,17 +616,17 @@ template <typename T>
612616
class MaxPool3dWithIndexFunctor<platform::CPUPlace, T> {
613617
public:
614618
void operator()(const platform::DeviceContext& context,
615-
const framework::Tensor& input, framework::Tensor& output,
616-
framework::Tensor& mask, std::vector<int>& ksize,
617-
std::vector<int>& strides, std::vector<int>& paddings) {
619+
const framework::Tensor& input, std::vector<int>& ksize,
620+
std::vector<int>& strides, std::vector<int>& paddings,
621+
framework::Tensor* output, framework::Tensor* mask) {
618622
const int batch_size = input.dims()[0];
619623
const int input_depth = input.dims()[2];
620624
const int input_height = input.dims()[3];
621625
const int input_width = input.dims()[4];
622-
const int output_channels = output.dims()[1];
623-
const int output_depth = output.dims()[2];
624-
const int output_height = output.dims()[3];
625-
const int output_width = output.dims()[4];
626+
const int output_channels = output->dims()[1];
627+
const int output_depth = output->dims()[2];
628+
const int output_height = output->dims()[3];
629+
const int output_width = output->dims()[4];
626630
const int ksize_depth = ksize[0];
627631
const int ksize_height = ksize[1];
628632
const int ksize_width = ksize[2];
@@ -636,8 +640,8 @@ class MaxPool3dWithIndexFunctor<platform::CPUPlace, T> {
636640
const int output_stride = output_depth * output_height * output_width;
637641

638642
const T* input_data = input.data<T>();
639-
T* output_data = output.mutable_data<T>(context.GetPlace());
640-
T* mask_data = mask.mutable_data<T>(context.GetPlace());
643+
T* output_data = output->mutable_data<T>(context.GetPlace());
644+
T* mask_data = mask->mutable_data<T>(context.GetPlace());
641645

642646
for (int i = 0; i < batch_size; i++) {
643647
for (int c = 0; c < output_channels; ++c) {
@@ -691,14 +695,14 @@ template <typename T>
691695
class MaxPool3dWithIndexGradFunctor<platform::CPUPlace, T> {
692696
public:
693697
void operator()(const platform::DeviceContext& context,
694-
framework::Tensor& input_grad,
695698
const framework::Tensor& output_grad,
696699
const framework::Tensor& mask, std::vector<int>& ksize,
697-
std::vector<int>& strides, std::vector<int>& paddings) {
698-
const int batch_size = input_grad.dims()[0];
699-
const int input_depth = input_grad.dims()[2];
700-
const int input_height = input_grad.dims()[3];
701-
const int input_width = input_grad.dims()[4];
700+
std::vector<int>& strides, std::vector<int>& paddings,
701+
framework::Tensor* input_grad) {
702+
const int batch_size = input_grad->dims()[0];
703+
const int input_depth = input_grad->dims()[2];
704+
const int input_height = input_grad->dims()[3];
705+
const int input_width = input_grad->dims()[4];
702706
const int output_channels = output_grad.dims()[1];
703707
const int output_depth = output_grad.dims()[2];
704708
const int output_height = output_grad.dims()[3];
@@ -708,7 +712,7 @@ class MaxPool3dWithIndexGradFunctor<platform::CPUPlace, T> {
708712

709713
const T* mask_data = mask.data<T>();
710714
const T* output_grad_data = output_grad.data<T>();
711-
T* input_grad_data = input_grad.mutable_data<T>(context.GetPlace());
715+
T* input_grad_data = input_grad->mutable_data<T>(context.GetPlace());
712716

713717
for (int n = 0; n < batch_size; ++n) {
714718
for (int c = 0; c < output_channels; ++c) {

0 commit comments

Comments
 (0)