@@ -27,15 +27,15 @@ template <typename PoolProcess, typename T>
27
27
class Pool2dFunctor <platform::CPUPlace, PoolProcess, T> {
28
28
public:
29
29
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 ) {
33
33
const int batch_size = input.dims ()[0 ];
34
34
const int input_height = input.dims ()[2 ];
35
35
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 ];
39
39
const int ksize_height = ksize[0 ];
40
40
const int ksize_width = ksize[1 ];
41
41
const int stride_height = strides[0 ];
@@ -47,7 +47,7 @@ class Pool2dFunctor<platform::CPUPlace, PoolProcess, T> {
47
47
const int output_stride = output_height * output_width;
48
48
49
49
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 ());
51
51
52
52
for (int i = 0 ; i < batch_size; i++) {
53
53
for (int c = 0 ; c < output_channels; ++c) {
@@ -87,11 +87,12 @@ template <typename PoolProcess, class T>
87
87
class Pool2dGradFunctor <platform::CPUPlace, PoolProcess, T> {
88
88
public:
89
89
void operator ()(const platform::DeviceContext& context,
90
- const framework::Tensor& input, framework::Tensor& input_grad,
90
+ const framework::Tensor& input,
91
91
const framework::Tensor& output,
92
92
const framework::Tensor& output_grad, std::vector<int >& ksize,
93
93
std::vector<int >& strides, std::vector<int >& paddings,
94
- PoolProcess pool_grad_process) {
94
+ PoolProcess pool_grad_process,
95
+ framework::Tensor* input_grad) {
95
96
const int batch_size = input.dims ()[0 ];
96
97
const int input_height = input.dims ()[2 ];
97
98
const int input_width = input.dims ()[3 ];
@@ -110,7 +111,7 @@ class Pool2dGradFunctor<platform::CPUPlace, PoolProcess, T> {
110
111
const T* input_data = input.data <T>();
111
112
const T* output_data = output.data <T>();
112
113
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 ());
114
115
115
116
for (int i = 0 ; i < batch_size; i++) {
116
117
for (int c = 0 ; c < output_channels; ++c) {
@@ -154,10 +155,11 @@ template <class T>
154
155
class MaxPool2dGradFunctor <platform::CPUPlace, T> {
155
156
public:
156
157
void operator ()(const platform::DeviceContext& context,
157
- const framework::Tensor& input, framework::Tensor& input_grad,
158
+ const framework::Tensor& input,
158
159
const framework::Tensor& output,
159
160
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) {
161
163
const int batch_size = input.dims ()[0 ];
162
164
const int input_height = input.dims ()[2 ];
163
165
const int input_width = input.dims ()[3 ];
@@ -176,7 +178,7 @@ class MaxPool2dGradFunctor<platform::CPUPlace, T> {
176
178
const T* input_data = input.data <T>();
177
179
const T* output_data = output.data <T>();
178
180
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 ());
180
182
181
183
for (int i = 0 ; i < batch_size; i++) {
182
184
for (int c = 0 ; c < output_channels; ++c) {
@@ -240,17 +242,17 @@ template <typename PoolProcess, class T>
240
242
class Pool3dFunctor <platform::CPUPlace, PoolProcess, T> {
241
243
public:
242
244
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 ) {
246
248
const int batch_size = input.dims ()[0 ];
247
249
const int input_depth = input.dims ()[2 ];
248
250
const int input_height = input.dims ()[3 ];
249
251
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 ];
254
256
const int ksize_depth = ksize[0 ];
255
257
const int ksize_height = ksize[1 ];
256
258
const int ksize_width = ksize[2 ];
@@ -265,7 +267,7 @@ class Pool3dFunctor<platform::CPUPlace, PoolProcess, T> {
265
267
const int output_stride = output_depth * output_height * output_width;
266
268
267
269
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 ());
269
271
270
272
for (int i = 0 ; i < batch_size; i++) {
271
273
for (int c = 0 ; c < output_channels; ++c) {
@@ -315,11 +317,12 @@ template <typename PoolProcess, class T>
315
317
class Pool3dGradFunctor <platform::CPUPlace, PoolProcess, T> {
316
318
public:
317
319
void operator ()(const platform::DeviceContext& context,
318
- const framework::Tensor& input, framework::Tensor& input_grad,
320
+ const framework::Tensor& input,
319
321
const framework::Tensor& output,
320
322
const framework::Tensor& output_grad, std::vector<int >& ksize,
321
323
std::vector<int >& strides, std::vector<int >& paddings,
322
- PoolProcess pool_grad_process) {
324
+ PoolProcess pool_grad_process,
325
+ framework::Tensor* input_grad) {
323
326
const int batch_size = input.dims ()[0 ];
324
327
const int input_depth = input.dims ()[2 ];
325
328
const int input_height = input.dims ()[3 ];
@@ -343,7 +346,7 @@ class Pool3dGradFunctor<platform::CPUPlace, PoolProcess, T> {
343
346
const T* input_data = input.data <T>();
344
347
const T* output_data = output.data <T>();
345
348
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 ());
347
350
348
351
for (int i = 0 ; i < batch_size; i++) {
349
352
for (int c = 0 ; c < output_channels; ++c) {
@@ -398,10 +401,11 @@ template <class T>
398
401
class MaxPool3dGradFunctor <platform::CPUPlace, T> {
399
402
public:
400
403
void operator ()(const platform::DeviceContext& context,
401
- const framework::Tensor& input, framework::Tensor& input_grad,
404
+ const framework::Tensor& input,
402
405
const framework::Tensor& output,
403
406
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) {
405
409
const int batch_size = input.dims ()[0 ];
406
410
const int input_depth = input.dims ()[2 ];
407
411
const int input_height = input.dims ()[3 ];
@@ -425,7 +429,7 @@ class MaxPool3dGradFunctor<platform::CPUPlace, T> {
425
429
const T* input_data = input.data <T>();
426
430
const T* output_data = output.data <T>();
427
431
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 ());
429
433
430
434
for (int i = 0 ; i < batch_size; i++) {
431
435
for (int c = 0 ; c < output_channels; ++c) {
@@ -498,15 +502,15 @@ template <typename T>
498
502
class MaxPool2dWithIndexFunctor <platform::CPUPlace, T> {
499
503
public:
500
504
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 ) {
504
508
const int batch_size = input.dims ()[0 ];
505
509
const int input_height = input.dims ()[2 ];
506
510
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 ];
510
514
const int ksize_height = ksize[0 ];
511
515
const int ksize_width = ksize[1 ];
512
516
const int stride_height = strides[0 ];
@@ -517,8 +521,8 @@ class MaxPool2dWithIndexFunctor<platform::CPUPlace, T> {
517
521
const int output_stride = output_height * output_width;
518
522
519
523
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 ());
522
526
523
527
for (int i = 0 ; i < batch_size; i++) {
524
528
for (int c = 0 ; c < output_channels; ++c) {
@@ -563,13 +567,13 @@ template <typename T>
563
567
class MaxPool2dWithIndexGradFunctor <platform::CPUPlace, T> {
564
568
public:
565
569
void operator ()(const platform::DeviceContext& context,
566
- framework::Tensor& input_grad,
567
570
const framework::Tensor& output_grad,
568
571
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 ];
573
577
const int output_channels = output_grad.dims ()[1 ];
574
578
const int output_height = output_grad.dims ()[2 ];
575
579
const int output_width = output_grad.dims ()[3 ];
@@ -578,7 +582,7 @@ class MaxPool2dWithIndexGradFunctor<platform::CPUPlace, T> {
578
582
579
583
const T* mask_data = mask.data <T>();
580
584
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 ());
582
586
583
587
for (int n = 0 ; n < batch_size; ++n) {
584
588
for (int c = 0 ; c < output_channels; ++c) {
@@ -612,17 +616,17 @@ template <typename T>
612
616
class MaxPool3dWithIndexFunctor <platform::CPUPlace, T> {
613
617
public:
614
618
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 ) {
618
622
const int batch_size = input.dims ()[0 ];
619
623
const int input_depth = input.dims ()[2 ];
620
624
const int input_height = input.dims ()[3 ];
621
625
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 ];
626
630
const int ksize_depth = ksize[0 ];
627
631
const int ksize_height = ksize[1 ];
628
632
const int ksize_width = ksize[2 ];
@@ -636,8 +640,8 @@ class MaxPool3dWithIndexFunctor<platform::CPUPlace, T> {
636
640
const int output_stride = output_depth * output_height * output_width;
637
641
638
642
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 ());
641
645
642
646
for (int i = 0 ; i < batch_size; i++) {
643
647
for (int c = 0 ; c < output_channels; ++c) {
@@ -691,14 +695,14 @@ template <typename T>
691
695
class MaxPool3dWithIndexGradFunctor <platform::CPUPlace, T> {
692
696
public:
693
697
void operator ()(const platform::DeviceContext& context,
694
- framework::Tensor& input_grad,
695
698
const framework::Tensor& output_grad,
696
699
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 ];
702
706
const int output_channels = output_grad.dims ()[1 ];
703
707
const int output_depth = output_grad.dims ()[2 ];
704
708
const int output_height = output_grad.dims ()[3 ];
@@ -708,7 +712,7 @@ class MaxPool3dWithIndexGradFunctor<platform::CPUPlace, T> {
708
712
709
713
const T* mask_data = mask.data <T>();
710
714
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 ());
712
716
713
717
for (int n = 0 ; n < batch_size; ++n) {
714
718
for (int c = 0 ; c < output_channels; ++c) {
0 commit comments