From 3e9ad093c67492288c03ee61cfe6edf93438488a Mon Sep 17 00:00:00 2001 From: FlyingQianMM <245467267@qq.com> Date: Mon, 4 Apr 2022 21:54:33 +0800 Subject: [PATCH] fix index_select kernel configuration error where input numel is 0 (#41383) --- paddle/phi/kernels/gpu/index_select_grad_kernel.cu | 3 +++ paddle/phi/kernels/gpu/index_select_kernel.cu | 3 +++ 2 files changed, 6 insertions(+) diff --git a/paddle/phi/kernels/gpu/index_select_grad_kernel.cu b/paddle/phi/kernels/gpu/index_select_grad_kernel.cu index 209ce1ccf5c..75ae1bbcd0a 100644 --- a/paddle/phi/kernels/gpu/index_select_grad_kernel.cu +++ b/paddle/phi/kernels/gpu/index_select_grad_kernel.cu @@ -85,6 +85,9 @@ void IndexSelectGradKernel(const Context& ctx, phi::DataType::INT64)); int64_t numel = x_grad->numel(); + if (numel == 0) { + return; + } int64_t index_nums = index.numel(); int64_t out_nums = out_grad.numel(); diff --git a/paddle/phi/kernels/gpu/index_select_kernel.cu b/paddle/phi/kernels/gpu/index_select_kernel.cu index 57a13a9aefc..38a6582d790 100644 --- a/paddle/phi/kernels/gpu/index_select_kernel.cu +++ b/paddle/phi/kernels/gpu/index_select_kernel.cu @@ -72,6 +72,9 @@ void IndexSelectKernel(const Context& ctx, T* out_data = ctx.template Alloc(output); int64_t numel = output->numel(); + if (numel == 0) { + return; + } auto stream = ctx.stream(); unsigned int block_dim = PADDLE_CUDA_NUM_THREADS; -- GitLab