From b0a3638f0abeb07bb28bb9b7238262a4aa79aa3a Mon Sep 17 00:00:00 2001 From: LielinJiang <50691816+LielinJiang@users.noreply.github.com> Date: Tue, 6 Sep 2022 10:47:25 +0800 Subject: [PATCH] Fix grad error of groupnorm op when cuda version==11.7 (#45738) * fix grad error of grounorm op when cuda version==11.7 --- paddle/fluid/operators/group_norm_op.cu | 17 +++++++++++++++-- .../phi/kernels/gpu/group_norm_grad_kernel.cu | 17 +++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/paddle/fluid/operators/group_norm_op.cu b/paddle/fluid/operators/group_norm_op.cu index 668f69b4c75..105d4d6c75e 100644 --- a/paddle/fluid/operators/group_norm_op.cu +++ b/paddle/fluid/operators/group_norm_op.cu @@ -427,8 +427,21 @@ __global__ void GroupNormBackwardGetMeanAndVar(const T* x, } CudaAtomicAddWithWarp(&(d_mean[bid * groups + gid]), d_mean_data); CudaAtomicAddWithWarp(&(d_var[bid * groups + gid]), d_var_data); - if (flags & kHasScale) CudaAtomicAddWithWarp(&(d_scale[ccid]), d_scale_data); - if (flags & kHasBias) CudaAtomicAddWithWarp(&(d_bias[ccid]), d_bias_data); + + if (flags & kHasScale) { +#if CUDA_VERSION >= 11070 + platform::CudaAtomicAdd(&(d_scale[ccid]), d_scale_data); +#else + CudaAtomicAddWithWarp(&(d_scale[ccid]), d_scale_data); +#endif + } + if (flags & kHasBias) { +#if CUDA_VERSION >= 11070 + platform::CudaAtomicAdd(&(d_bias[ccid]), d_bias_data); +#else + CudaAtomicAddWithWarp(&(d_bias[ccid]), d_bias_data); +#endif + } } template diff --git a/paddle/phi/kernels/gpu/group_norm_grad_kernel.cu b/paddle/phi/kernels/gpu/group_norm_grad_kernel.cu index 359dc8a0095..c33fbfbd51f 100644 --- a/paddle/phi/kernels/gpu/group_norm_grad_kernel.cu +++ b/paddle/phi/kernels/gpu/group_norm_grad_kernel.cu @@ -68,8 +68,21 @@ __global__ void GroupNormBackwardGetMeanAndVar(const T* x, } CudaAtomicAddWithWarp(&(d_mean[bid * groups + gid]), d_mean_data); CudaAtomicAddWithWarp(&(d_var[bid * groups + gid]), d_var_data); - if (flags & kHasScale) CudaAtomicAddWithWarp(&(d_scale[ccid]), d_scale_data); - if (flags & kHasBias) CudaAtomicAddWithWarp(&(d_bias[ccid]), d_bias_data); + + if (flags & kHasScale) { +#if CUDA_VERSION >= 11070 + platform::CudaAtomicAdd(&(d_scale[ccid]), d_scale_data); +#else + CudaAtomicAddWithWarp(&(d_scale[ccid]), d_scale_data); +#endif + } + if (flags & kHasBias) { +#if CUDA_VERSION >= 11070 + platform::CudaAtomicAdd(&(d_bias[ccid]), d_bias_data); +#else + CudaAtomicAddWithWarp(&(d_bias[ccid]), d_bias_data); +#endif + } } template -- GitLab