Skip to content

Commit a4018b5

Browse files
committed
fix bug
1 parent b34bd59 commit a4018b5

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

paddle/phi/kernels/gpu/elementwise_grad.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -340,15 +340,15 @@ void ElementwiseDivGrad(const GPUContext &dev_ctx,
340340
DenseTensor *dy,
341341
int axis = -1) {
342342
const auto place = dev_ctx.GetPlace();
343-
if (dx->numel() == 0) {
343+
if (dx != nullptr && dx->numel() == 0) {
344344
dev_ctx.Alloc<T>(dx);
345345
}
346346

347-
if (dy->numel() == 0) {
347+
if (dy != nullptr && dy->numel() == 0) {
348348
dev_ctx.Alloc<T>(dy);
349349
}
350350

351-
bool need_dx = (dx != nullptr) && (dy->numel() != 0);
351+
bool need_dx = (dx != nullptr) && (dx->numel() != 0);
352352
bool need_dy = (dy != nullptr) && (dy->numel() != 0);
353353
if (need_dx && need_dy) {
354354
std::vector<const DenseTensor *> ins = {&dout, &out, &y};
@@ -387,15 +387,15 @@ void ElementwiseMulGrad(const GPUContext &dev_ctx,
387387
int axis) {
388388
const auto place = dev_ctx.GetPlace();
389389

390-
if (dx->numel() == 0) {
390+
if (dx != nullptr && dx->numel() == 0) {
391391
dev_ctx.Alloc<T>(dx);
392392
}
393393

394-
if (dy->numel() == 0) {
394+
if (dy != nullptr && dy->numel() == 0) {
395395
dev_ctx.Alloc<T>(dy);
396396
}
397397

398-
bool need_dx = (dx != nullptr) && (dy->numel() != 0);
398+
bool need_dx = (dx != nullptr) && (dx->numel() != 0);
399399
bool need_dy = (dy != nullptr) && (dy->numel() != 0);
400400
if (need_dy && need_dy) {
401401
std::vector<const DenseTensor *> ins = {&dout, &y, &x};

0 commit comments

Comments
 (0)