@@ -43,12 +43,14 @@ class PoolXPUKernel : public framework::OpKernel<T> {
4343 bool exclusive = context.Attr <bool >(" exclusive" );
4444 bool is_test = context.Attr <bool >(" is_test" );
4545 bool adaptive = context.Attr <bool >(" adaptive" );
46- PADDLE_ENFORCE_EQ (!adaptive, true ,
47- platform::errors::InvalidArgument (
48- " XPU does not support adaptive == true!" ));
49- PADDLE_ENFORCE_EQ (ksize.size (), 2 ,
50- platform::errors::InvalidArgument (
51- " XPU only support 2 dimension pooling!" ));
46+ PADDLE_ENFORCE_EQ (
47+ !adaptive, true ,
48+ platform::errors::InvalidArgument (
49+ " The Pool2d XPU OP does not support adaptive == true!" ));
50+ PADDLE_ENFORCE_EQ (
51+ ksize.size (), 2 ,
52+ platform::errors::InvalidArgument (
53+ " The Pool2d XPU OP only support 2 dimension pooling!" ));
5254 int * index_data = nullptr ;
5355 if (context.Attr <bool >(" global_pooling" )) {
5456 for (size_t i = 0 ; i < ksize.size (); ++i) {
@@ -80,7 +82,10 @@ class PoolXPUKernel : public framework::OpKernel<T> {
8082 stride_w, out_h, out_w);
8183 PADDLE_ENFORCE_EQ (
8284 r, xpu::Error_t::SUCCESS,
83- platform::errors::InvalidArgument (" pool2d XPU kernel error!" ));
85+ platform::errors::External (
86+ " The pool2d XPU API return wrong value[%d], please check "
87+ " where Baidu Kunlun Card is properly installed." ,
88+ r));
8489 }
8590};
8691template <typename DeviceContext, typename T>
@@ -99,12 +104,15 @@ class PoolGradXPUKernel : public framework::OpKernel<T> {
99104 bool exclusive = context.Attr <bool >(" exclusive" );
100105 bool adaptive = context.Attr <bool >(" adaptive" );
101106 const int * index_data = nullptr ;
102- PADDLE_ENFORCE_EQ (!adaptive, true ,
103- platform::errors::InvalidArgument (
104- " XPU does not support adaptive == true!" ));
105- PADDLE_ENFORCE_EQ (ksize.size (), 2 ,
106- platform::errors::InvalidArgument (
107- " XPU only support 2 dimension pooling!" ));
107+ PADDLE_ENFORCE_EQ (
108+ !adaptive, true ,
109+ platform::errors::InvalidArgument (
110+ " The Pool2d XPU OP does not support adaptive == true!" ));
111+ PADDLE_ENFORCE_EQ (ksize.size (), 2 , platform::errors::InvalidArgument (
112+ " The Pool2d XPU OP only support 2 "
113+ " dimension pooling!, but received "
114+ " %d-dimension pool kernel size" ,
115+ ksize.size ()));
108116 if (context.Attr <bool >(" global_pooling" )) {
109117 for (size_t i = 0 ; i < ksize.size (); ++i) {
110118 paddings[i] = 0 ;
@@ -139,16 +147,22 @@ class PoolGradXPUKernel : public framework::OpKernel<T> {
139147 int r =
140148 xpu::memset (dev_ctx.x_context (), reinterpret_cast <void **>(input_grad),
141149 zero, in_x_grad->numel () * sizeof (float ));
142- PADDLE_ENFORCE_EQ (r, xpu::Error_t::SUCCESS,
143- platform::errors::InvalidArgument (
144- " There are pool2d grad XPU kernel error raised!" ));
150+ PADDLE_ENFORCE_EQ (
151+ r, xpu::Error_t::SUCCESS,
152+ platform::errors::External (
153+ " The Pool2d XPU OP return wrong value[%d], please check "
154+ " where Baidu Kunlun Card is properly installed." ,
155+ r));
145156 r = xpu::pooling_backward (dev_ctx.x_context (), input, output, index_data,
146157 output_grad, input_grad, pool_type, c, in_h, in_w,
147158 pad_left, pad_right, pad_up, pad_down, win_h,
148159 win_w, stride_h, stride_w, out_h, out_w);
149- PADDLE_ENFORCE_EQ (r, xpu::Error_t::SUCCESS,
150- platform::errors::InvalidArgument (
151- " There are pool2d grad XPU kernel error raised!" ));
160+ PADDLE_ENFORCE_EQ (
161+ r, xpu::Error_t::SUCCESS,
162+ platform::errors::External (
163+ " The Pool2d XPU OP return wrong value[%d], please check "
164+ " where Baidu Kunlun Card is properly installed." ,
165+ r));
152166 }
153167};
154168
0 commit comments