From fde47aae610c4319abdfeb245fb402ae6a668028 Mon Sep 17 00:00:00 2001 From: Tomasz Patejko Date: Tue, 22 May 2018 00:52:00 +0200 Subject: [PATCH] MKL elementwise add backward: grad inputs copied when they are not null --- paddle/fluid/operators/elementwise_add_op.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/paddle/fluid/operators/elementwise_add_op.h b/paddle/fluid/operators/elementwise_add_op.h index 0bf9600848..3286aa848d 100644 --- a/paddle/fluid/operators/elementwise_add_op.h +++ b/paddle/fluid/operators/elementwise_add_op.h @@ -102,13 +102,15 @@ class ElementwiseAddGradKernel : public framework::OpKernel { if (platform::is_cpu_place(ctx.GetPlace()) && (x->dims() == y->dims())) { auto blas = math::GetBlas(ctx); - if (dx) - dx->mutable_data(ctx.GetPlace()); - if (dy) - dy->mutable_data(ctx.GetPlace()); - - blas.VCOPY(dout->numel(), dout->data(), dx->data()); - blas.VCOPY(dout->numel(), dout->data(), dy->data()); + if (dx) { + blas.VCOPY(dout->numel(), dout->data(), + dx->mutable_data(ctx.GetPlace())); + } + + if (dy) { + blas.VCOPY(dout->numel(), dout->data(), + dy->mutable_data(ctx.GetPlace())); + } } else { ElemwiseGradCompute, IdentityGrad>( ctx, *x, *y, *out, *dout, axis, dx, dy, IdentityGrad(), -- GitLab