@@ -86,6 +86,9 @@ inline void TensorCopy(const Context& dev_ctx,
86
86
C_Stream stream = static_cast <C_Stream>(dev_ctx.stream ());
87
87
88
88
auto size = src.numel () * paddle::experimental::SizeOf (src.dtype ());
89
+ if (UNLIKELY (size) == 0 ) {
90
+ return ;
91
+ }
89
92
90
93
if (src_place.GetType () == phi::AllocationType::CPU &&
91
94
dst_place_.GetType () == phi::AllocationType::CUSTOM) {
@@ -108,17 +111,16 @@ inline void TensorCopy(const Context& dev_ctx,
108
111
dev_ctx.Wait ();
109
112
}
110
113
} else {
111
- PADDLE_THROW (phi::errors::Unimplemented (
112
- " TensorCopy is not supported." ));
114
+ PADDLE_THROW (
115
+ phi::errors::Unimplemented ( " TensorCopy is not supported." ));
113
116
}
114
117
} else {
115
- PADDLE_THROW (phi::errors::Unimplemented (
116
- " TensorCopy is not supported." ));
118
+ PADDLE_THROW (phi::errors::Unimplemented (" TensorCopy is not supported." ));
117
119
}
118
120
} else if (src_place.GetType () == phi::AllocationType::CPU &&
119
- dst_place_.GetType () == phi::AllocationType::CPU) {
120
- std::memcpy (dst_ptr, src_ptr, size);
121
- }
121
+ dst_place_.GetType () == phi::AllocationType::CPU) {
122
+ std::memcpy (dst_ptr, src_ptr, size);
123
+ }
122
124
}
123
125
124
126
/* *
@@ -357,9 +359,9 @@ inline void NpuBroadcast(const Context& dev_ctx,
357
359
dev_ctx.template Alloc <T>(&tmp_tensor);
358
360
NpuOpRunner runner;
359
361
runner.SetType (" Expand" )
360
- .AddInput (tmp_src)
361
- .AddInput (dev_ctx, phi::vectorize<int64_t >(tmp_tensor_dims))
362
- .AddOutput (tmp_tensor);
362
+ .AddInput (tmp_src)
363
+ .AddInput (dev_ctx, phi::vectorize<int64_t >(tmp_tensor_dims))
364
+ .AddOutput (tmp_tensor);
363
365
auto stream = dev_ctx.stream ();
364
366
runner.Run (stream);
365
367
tmp_src = tmp_tensor;
@@ -421,12 +423,13 @@ inline void NpuElementWiseOpBroadcast(const Context& dev_ctx,
421
423
phi::errors::InvalidArgument (
422
424
" Axis should be great than or equal to 0, but received axis is %d." ,
423
425
axis));
424
- PADDLE_ENFORCE_LE (axis,
425
- max_dim,
426
- phi::errors::InvalidArgument (
427
- " Axis should be less than or equal to %d, but received axis is %d." ,
428
- max_dim,
429
- axis));
426
+ PADDLE_ENFORCE_LE (
427
+ axis,
428
+ max_dim,
429
+ phi::errors::InvalidArgument (
430
+ " Axis should be less than or equal to %d, but received axis is %d." ,
431
+ max_dim,
432
+ axis));
430
433
431
434
for (int i = 0 ; i < x_dims.size (); ++i) {
432
435
dst_dims_vec[i + x_axis] =
0 commit comments