From 95c343d3c74ff3b2c0733d4f935d9995281d019b Mon Sep 17 00:00:00 2001 From: huangxu96 <46740794+huangxu96@users.noreply.github.com> Date: Wed, 9 Mar 2022 17:37:01 +0800 Subject: [PATCH] Fix a bug which might occur OOM problem (#40226) * Add wait after Copy * fix wrong place delete --- .../gpu/sigmoid_cross_entropy_with_logits_grad_kernel.cu | 2 ++ .../phi/kernels/gpu/sigmoid_cross_entropy_with_logits_kernel.cu | 1 + 2 files changed, 3 insertions(+) diff --git a/paddle/phi/kernels/gpu/sigmoid_cross_entropy_with_logits_grad_kernel.cu b/paddle/phi/kernels/gpu/sigmoid_cross_entropy_with_logits_grad_kernel.cu index 6fc65006ae2..f61cd2c3967 100644 --- a/paddle/phi/kernels/gpu/sigmoid_cross_entropy_with_logits_grad_kernel.cu +++ b/paddle/phi/kernels/gpu/sigmoid_cross_entropy_with_logits_grad_kernel.cu @@ -95,6 +95,7 @@ void SigmoidCrossEntropyWithLogitsGradKernel(const Context &dev_ctx, norm, sizeof(T), dev_ctx.stream()); + dev_ctx.Wait(); auto eps = static_cast(1e-5); *norm_cpu_ptr = *norm_cpu_ptr > eps ? *norm_cpu_ptr : eps; @@ -102,6 +103,7 @@ void SigmoidCrossEntropyWithLogitsGradKernel(const Context &dev_ctx, std::vector div_outs = {in_grad}; auto div_functor = DivFunctor(*norm_cpu_ptr); phi::funcs::ElementwiseKernel(dev_ctx, div_ins, &div_outs, div_functor); + delete norm_tensor; } delete counts_tensor; diff --git a/paddle/phi/kernels/gpu/sigmoid_cross_entropy_with_logits_kernel.cu b/paddle/phi/kernels/gpu/sigmoid_cross_entropy_with_logits_kernel.cu index 4b6e5628c72..b0e9efe5bba 100644 --- a/paddle/phi/kernels/gpu/sigmoid_cross_entropy_with_logits_kernel.cu +++ b/paddle/phi/kernels/gpu/sigmoid_cross_entropy_with_logits_kernel.cu @@ -95,6 +95,7 @@ void SigmoidCrossEntropyWithLogitsKernel(const Context &dev_ctx, norm, sizeof(T), dev_ctx.stream()); + dev_ctx.Wait(); auto eps = static_cast(1e-5); *norm_cpu_ptr = *norm_cpu_ptr > eps ? *norm_cpu_ptr : eps; -- GitLab