diff --git a/paddle/phi/kernels/xpu/pool_grad_kernel.cc b/paddle/phi/kernels/xpu/pool_grad_kernel.cc index dfea57231560ad370b3c90e1198cfe698bbfc118..a94a757dc8bf013de858b52c9504613de0593f0e 100644 --- a/paddle/phi/kernels/xpu/pool_grad_kernel.cc +++ b/paddle/phi/kernels/xpu/pool_grad_kernel.cc @@ -157,6 +157,12 @@ void Pool2dGradKernel(const Context& ctx, PADDLE_ENFORCE_XDNN_SUCCESS(r, "adaptive_pool2d_grad"); } else { + if (kernel_size[0] > in_h) { + kernel_size[0] = in_h; + } + if (kernel_size[1] > in_w) { + kernel_size[1] = in_w; + } if (pooling_type == "max") { // TODO(zhanghuan05) to bind max_pool2d_grad_indices xpu api r = xpu::max_pool2d_grad( diff --git a/paddle/phi/kernels/xpu/pool_kernel.cc b/paddle/phi/kernels/xpu/pool_kernel.cc index ad09a5ed37188e19f23ec71ad276a7d3b10b389e..ff324746939ed5e3ff2cda6dcf920f4fec842da0 100644 --- a/paddle/phi/kernels/xpu/pool_kernel.cc +++ b/paddle/phi/kernels/xpu/pool_kernel.cc @@ -90,6 +90,12 @@ void Pool2dKernel(const Context& ctx, int* index_data = nullptr; int r = xpu::Error_t::SUCCESS; if (!adaptive) { + if (kernel_size[0] > in_h) { + kernel_size[0] = in_h; + } + if (kernel_size[1] > in_w) { + kernel_size[1] = in_w; + } if (pooling_type == "max") { r = xpu::max_pool2d( ctx.x_context(),