@@ -95,7 +95,7 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
95
95
public:
96
96
void Compute (const paddle::framework::ExecutionContext& ctx) const override {
97
97
PADDLE_ENFORCE (paddle::platform::is_cpu_place (ctx.GetPlace ()),
98
- " It must use CPUPlace." );
98
+ platform::errors::InvalidArgument ( " It must use CPUPlace." ) );
99
99
bool is_INT8 =
100
100
std::is_same<T, int8_t >::value || std::is_same<T, uint8_t >::value;
101
101
if (!is_INT8) {
@@ -130,37 +130,59 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
130
130
auto * output = ctx.Output <Tensor>(" Output" );
131
131
132
132
PADDLE_ENFORCE_EQ (input->layout (), DataLayout::kMKLDNN ,
133
- " Wrong layout set for Input tensor" );
134
- PADDLE_ENFORCE_NE (input->format (), MKLDNNMemoryFormat::undef,
135
- " Wrong format set for Input tensor" );
133
+ platform::errors::InvalidArgument (
134
+ " The input tensor's layout should be %d, but got %d." ,
135
+ DataLayout::kMKLDNN , input->layout ()));
136
+ PADDLE_ENFORCE_NE (
137
+ input->format (), MKLDNNMemoryFormat::undef,
138
+ platform::errors::InvalidArgument (" Wrong format set for Input tensor" ));
136
139
137
- PADDLE_ENFORCE_EQ (filter->layout (), DataLayout::kMKLDNN ,
138
- " Wrong layout set for Filter tensor" );
140
+ PADDLE_ENFORCE_EQ (
141
+ filter->layout (), DataLayout::kMKLDNN ,
142
+ platform::errors::InvalidArgument (
143
+ " The Filter tensor's layout should be %d, but got %d." ,
144
+ DataLayout::kMKLDNN , filter->layout ()));
139
145
PADDLE_ENFORCE_NE (filter->format (), MKLDNNMemoryFormat::undef,
140
- " Wrong format set for Filter tensor" );
141
-
142
- PADDLE_ENFORCE_GE (
143
- input->dims ().size (), 4 ,
144
- " Input must be with 4 or 5 dimensions, i.e. NCHW or NCDHW" );
145
- PADDLE_ENFORCE_LE (
146
- input->dims ().size (), 5 ,
147
- " Input must be with 4 or 5 dimensions, i.e. NCHW or NCDHW" );
148
-
149
- PADDLE_ENFORCE_GE (
150
- filter->dims ().size (), 4 ,
151
- " Filter must be with 4 or 5 dimensions, i.e. OIHW or OIDHW" );
152
- PADDLE_ENFORCE_LE (
153
- filter->dims ().size (), 5 ,
154
- " Filter must be with 4 or 5 dimensions, i.e. OIHW or OIDHW" );
146
+ platform::errors::InvalidArgument (
147
+ " Wrong format set for Filter tensor" ));
148
+
149
+ PADDLE_ENFORCE_GE (input->dims ().size (), 4 ,
150
+ platform::errors::InvalidArgument (
151
+ " Input must be with 4 or 5 dimensions, i.e. NCHW or "
152
+ " NCDHW, but got dimension = %d ." ,
153
+ input->dims ().size ()));
154
+ PADDLE_ENFORCE_LE (input->dims ().size (), 5 ,
155
+ platform::errors::InvalidArgument (
156
+ " Input must be with 4 or 5 dimensions, i.e. NCHW or "
157
+ " NCDHW, but got dimension = %d ." ,
158
+ input->dims ().size ()));
159
+
160
+ PADDLE_ENFORCE_GE (filter->dims ().size (), 4 ,
161
+ platform::errors::InvalidArgument (
162
+ " Filter must be with 4 or 5 dimensions, i.e. OIHW or "
163
+ " OIDHW, but got dimension = %d ." ,
164
+ filter->dims ().size ()));
165
+ PADDLE_ENFORCE_LE (filter->dims ().size (), 5 ,
166
+ platform::errors::InvalidArgument (
167
+ " Filter must be with 4 or 5 dimensions, i.e. OIHW or "
168
+ " OIDHW, but got dimension = %d ." ,
169
+ filter->dims ().size ()));
155
170
156
171
if (bias) {
157
- PADDLE_ENFORCE_EQ (bias->layout (), DataLayout::kMKLDNN ,
158
- " Wrong layout set for Bias tensor" );
172
+ PADDLE_ENFORCE_EQ (
173
+ bias->layout (), DataLayout::kMKLDNN ,
174
+ platform::errors::InvalidArgument (
175
+ " The Bias tensor's layout should be %d, but got %d." ,
176
+ DataLayout::kMKLDNN , bias->layout ()));
159
177
PADDLE_ENFORCE_NE (bias->format (), MKLDNNMemoryFormat::undef,
160
- " Wrong format set for Bias tensor" );
178
+ platform::errors::InvalidArgument (
179
+ " Got wrong format for Bias tensor." ));
161
180
162
- PADDLE_ENFORCE_EQ (bias->dims ().size (), 1 ,
163
- " Bias must only have 1 dimension, i.e. X" );
181
+ PADDLE_ENFORCE_EQ (
182
+ bias->dims ().size (), 1 ,
183
+ platform::errors::InvalidArgument (" Bias must only have 1 dimension, "
184
+ " i.e. X, but got dimension = %d ." ,
185
+ bias->dims ().size ()));
164
186
}
165
187
166
188
std::vector<int > strides_temp = ctx.Attr <std::vector<int >>(" strides" );
@@ -295,10 +317,16 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
295
317
296
318
PADDLE_ENFORCE_NE (
297
319
residual_param_data, nullptr ,
298
- " Provide data if you want MKLDNN conv+elementwise_add fusion" );
299
- PADDLE_ENFORCE_EQ (output->dims (), residual_param->dims (),
300
- " Output and elementwise parameter need to have the "
301
- " same dimension sizes" );
320
+ platform::errors::InvalidArgument (
321
+ " Provide data if you want MKLDNN conv+elementwise_add fusion" ));
322
+ PADDLE_ENFORCE_EQ (
323
+ output->dims (), residual_param->dims (),
324
+ platform::errors::InvalidArgument (
325
+ " Output and elementwise parameter need to have the "
326
+ " same dimension sizes, "
327
+ " but got output's dimension = %d and residual param's dimension "
328
+ " = %d ." ,
329
+ output->dims ().size (), residual_param->dims ().size ()));
302
330
303
331
if (residual_param->format () != handler.GetDstFormat ()) {
304
332
auto output_data =
@@ -371,16 +399,23 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
371
399
auto * output = ctx.Output <Tensor>(" Output" );
372
400
373
401
PADDLE_ENFORCE_EQ (input->layout (), DataLayout::kMKLDNN ,
374
- " Wrong layout set for Input tensor" );
402
+ platform::errors::InvalidArgument (
403
+ " The input tensor's layout should be %d, but got %d." ,
404
+ DataLayout::kMKLDNN , input->layout ()));
375
405
PADDLE_ENFORCE_NE (input->format (), MKLDNNMemoryFormat::undef,
376
- " Wrong format set for Input tensor" );
377
-
378
- PADDLE_ENFORCE_GE (
379
- input->dims ().size (), 4 ,
380
- " Input must be with 4 or 5 dimensions, i.e. NCHW or NCDHW" );
381
- PADDLE_ENFORCE_LE (
382
- input->dims ().size (), 5 ,
383
- " Input must be with 4 or 5 dimensions, i.e. NCHW or NCDHW" );
406
+ platform::errors::InvalidArgument (
407
+ " Got wrong format for Input tensor." ));
408
+
409
+ PADDLE_ENFORCE_GE (input->dims ().size (), 4 ,
410
+ platform::errors::InvalidArgument (
411
+ " Input must be with 4 or 5 dimensions, i.e. NCHW or "
412
+ " NCDHW, but got dimension = %d ." ,
413
+ input->dims ().size ()));
414
+ PADDLE_ENFORCE_LE (input->dims ().size (), 5 ,
415
+ platform::errors::InvalidArgument (
416
+ " Input must be with 4 or 5 dimensions, i.e. NCHW or "
417
+ " NCDHW, but got dimension = %d ." ,
418
+ input->dims ().size ()));
384
419
385
420
std::string fuse_activation = ctx.Attr <std::string>(" fuse_activation" );
386
421
bool fuse_residual_conn = ctx.Attr <bool >(" fuse_residual_connection" );
@@ -438,17 +473,25 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
438
473
439
474
auto * filter = ctx.Input <Tensor>(" Filter" );
440
475
441
- PADDLE_ENFORCE_EQ (filter->layout (), DataLayout::kMKLDNN ,
442
- " Wrong layout set for Filter tensor" );
476
+ PADDLE_ENFORCE_EQ (
477
+ filter->layout (), DataLayout::kMKLDNN ,
478
+ platform::errors::InvalidArgument (
479
+ " The filter tensor's layout should be %d, but got %d." ,
480
+ DataLayout::kMKLDNN , filter->layout ()));
443
481
PADDLE_ENFORCE_NE (filter->format (), MKLDNNMemoryFormat::undef,
444
- " Wrong format set for Filter tensor" );
445
-
446
- PADDLE_ENFORCE_GE (
447
- filter->dims ().size (), 4 ,
448
- " Filter must be with 4 or 5 dimensions, i.e. OIHW or OIDHW" );
449
- PADDLE_ENFORCE_LE (
450
- filter->dims ().size (), 5 ,
451
- " Filter must be with 4 or 5 dimensions, i.e. OIHW or OIDHW" );
482
+ platform::errors::InvalidArgument (
483
+ " Got wrong format for Filter tensor." ));
484
+
485
+ PADDLE_ENFORCE_GE (filter->dims ().size (), 4 ,
486
+ platform::errors::InvalidArgument (
487
+ " Filter must be with 4 or 5 dimensions, i.e. OIHW "
488
+ " or OIDHW, but got dimensions = %d ." ,
489
+ filter->dims ().size ()));
490
+ PADDLE_ENFORCE_LE (filter->dims ().size (), 5 ,
491
+ platform::errors::InvalidArgument (
492
+ " Filter must be with 4 or 5 dimensions, i.e. OIHW "
493
+ " or OIDHW, but got dimensions = %d ." ,
494
+ filter->dims ().size ()));
452
495
453
496
PADDLE_ENFORCE_EQ (
454
497
!fuse_residual_conn || !force_fp32_output, true ,
@@ -457,13 +500,20 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
457
500
auto * bias = ctx.HasInput (" Bias" ) ? ctx.Input <Tensor>(" Bias" ) : nullptr ;
458
501
459
502
if (bias) {
460
- PADDLE_ENFORCE_EQ (bias->layout (), DataLayout::kMKLDNN ,
461
- " Wrong layout set for Bias tensor" );
503
+ PADDLE_ENFORCE_EQ (
504
+ bias->layout (), DataLayout::kMKLDNN ,
505
+ platform::errors::InvalidArgument (
506
+ " The bias tensor's layout should be %d, but got %d." ,
507
+ DataLayout::kMKLDNN , bias->layout ()));
462
508
PADDLE_ENFORCE_NE (bias->format (), MKLDNNMemoryFormat::undef,
463
- " Wrong format set for Bias tensor" );
509
+ platform::errors::InvalidArgument (
510
+ " Got wrong format for Bias tensor." ));
464
511
465
512
PADDLE_ENFORCE_EQ (bias->dims ().size (), 1 ,
466
- " Bias must only have 1 dimension, i.e. X" );
513
+ platform::errors::InvalidArgument (
514
+ " Bias must only have 1 dimension, i.e. X, but "
515
+ " got dimension = %d ." ,
516
+ bias->dims ().size ()));
467
517
}
468
518
469
519
std::vector<int > strides_temp = ctx.Attr <std::vector<int >>(" strides" );
@@ -482,7 +532,9 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
482
532
bool is_conv3d = strides.size () == 3U ;
483
533
484
534
PADDLE_ENFORCE_NE (is_conv3d, true ,
485
- " int8 does not support conv3d currently" );
535
+ platform::errors::InvalidArgument (
536
+ " int8 does not support conv3d currently, should "
537
+ " set param is_conv3d as False" ));
486
538
487
539
auto input_dims = input->dims ();
488
540
auto data_dims = framework::slice_ddim (input_dims, 2 , input_dims.size ());
@@ -599,9 +651,13 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
599
651
600
652
if (fuse_residual_conn) {
601
653
auto residual_param = ctx.Input <Tensor>(" ResidualData" );
602
- PADDLE_ENFORCE_EQ (output->dims (), residual_param->dims (),
603
- " Output and elementwise parameter need to have the "
604
- " same dimension sizes" );
654
+ PADDLE_ENFORCE_EQ (
655
+ output->dims (), residual_param->dims (),
656
+ platform::errors::InvalidArgument (
657
+ " Output and elementwise parameter need to have the "
658
+ " same dimension sizes, but got output's dimension = %d"
659
+ " and residual param's dimension =%d ." ,
660
+ output->dims ().size (), residual_param->dims ().size ()));
605
661
auto residual_dt =
606
662
paddle::framework::ToMKLDNNDataType (residual_param->type ());
607
663
if (residual_param->format () != handler->GetDstFormat ()) {
@@ -729,7 +785,7 @@ class ConvMKLDNNGradOpKernel : public paddle::framework::OpKernel<T> {
729
785
public:
730
786
void Compute (const paddle::framework::ExecutionContext& ctx) const override {
731
787
PADDLE_ENFORCE (paddle::platform::is_cpu_place (ctx.GetPlace ()),
732
- " It must use CPUPlace." );
788
+ platform::errors::InvalidArgument ( " It must use CPUPlace." ) );
733
789
734
790
auto & dev_ctx =
735
791
ctx.template device_context <platform::MKLDNNDeviceContext>();
@@ -743,23 +799,34 @@ class ConvMKLDNNGradOpKernel : public paddle::framework::OpKernel<T> {
743
799
Tensor* filter_grad = ctx.Output <Tensor>(framework::GradVarName (" Filter" ));
744
800
745
801
PADDLE_ENFORCE_EQ (input->layout (), DataLayout::kMKLDNN ,
746
- " Wrong layout set for Input tensor" );
802
+ platform::errors::InvalidArgument (
803
+ " The input tensor's layout should be %d, but got %d." ,
804
+ DataLayout::kMKLDNN , input->layout ()));
747
805
PADDLE_ENFORCE_NE (input->format (), MKLDNNMemoryFormat::undef,
748
- " Wrong format set for Input tensor" );
806
+ platform::errors::InvalidArgument (
807
+ " Got wrong format for Input tensor." ));
749
808
750
- PADDLE_ENFORCE_EQ (filter->layout (), DataLayout::kMKLDNN ,
751
- " Wrong layout set for Filter tensor" );
809
+ PADDLE_ENFORCE_EQ (
810
+ filter->layout (), DataLayout::kMKLDNN ,
811
+ platform::errors::InvalidArgument (
812
+ " The filter tensor's layout should be %d, but got %d." ,
813
+ DataLayout::kMKLDNN , filter->layout ()));
752
814
PADDLE_ENFORCE_NE (filter->format (), MKLDNNMemoryFormat::undef,
753
- " Wrong format set for Filter tensor" );
815
+ platform::errors::InvalidArgument (
816
+ " Got wrong format for Filter tensor." ));
754
817
755
- PADDLE_ENFORCE_EQ (output_grad->layout (), DataLayout::kMKLDNN ,
756
- " Wrong layout set for output_grad tensor" );
818
+ PADDLE_ENFORCE_EQ (
819
+ output_grad->layout (), DataLayout::kMKLDNN ,
820
+ platform::errors::InvalidArgument (
821
+ " The output_grad tensor's layout should be %d, but got %d." ,
822
+ DataLayout::kMKLDNN , output_grad->layout ()));
757
823
PADDLE_ENFORCE_NE (output_grad->format (), MKLDNNMemoryFormat::undef,
758
824
" Wrong format set for output_grad tensor" );
759
825
760
826
PADDLE_ENFORCE_EQ (
761
827
ctx.Attr <bool >(" is_test" ), false ,
762
- " is_test attribute should be set to False in training phase." );
828
+ platform::errors::InvalidArgument (
829
+ " is_test attribute should be set to False in training phase." ));
763
830
764
831
if (!input_grad && !filter_grad) return ;
765
832
@@ -859,7 +926,8 @@ class ConvMKLDNNGradOpKernel : public paddle::framework::OpKernel<T> {
859
926
std::static_pointer_cast<mkldnn::convolution_forward::primitive_desc>(
860
927
dev_ctx.GetBlob (key_conv_pd));
861
928
PADDLE_ENFORCE_NE (conv_pd, nullptr ,
862
- " Fail to find conv_pd in device context" );
929
+ platform::errors::InvalidArgument (
930
+ " Fail to find conv_pd in device context" ));
863
931
864
932
auto mkldnn_paddings = platform::ToMkldnnPadding (paddings);
865
933
0 commit comments