Skip to content

Commit 19c156f

Browse files
authored
[XPU] bugfix for contiguous in 0-size (#73004)
1 parent 71ee897 commit 19c156f

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

paddle/phi/kernels/xpu/contiguous_kernel.cc

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,16 @@ template <typename T, typename Context>
2424
void ContiguousKernel(const Context& dev_ctx,
2525
const DenseTensor& input,
2626
DenseTensor* out) {
27-
if (out->numel() == 0) {
28-
dev_ctx.template Alloc<T>(out);
29-
return;
30-
}
3127
phi::DenseTensorMeta meta = input.meta();
3228
meta.strides = meta.calc_strides(meta.dims);
3329
meta.offset = 0;
3430
out->set_meta(meta);
3531

32+
if (out->numel() == 0) {
33+
dev_ctx.template Alloc<T>(out);
34+
return;
35+
}
36+
3637
// use XPUCopyTypeTrait to deal with double and int16_t copy instead of
3738
// XPUTypeTrait
3839
using XPUType = typename XPUCopyTypeTrait<T>::Type;
@@ -59,15 +60,17 @@ template <>
5960
void ContiguousKernel<phi::dtype::complex<float>, XPUContext>(
6061
const XPUContext& dev_ctx, const DenseTensor& input, DenseTensor* out) {
6162
using T = phi::dtype::complex<float>;
62-
if (out->numel() == 0) {
63-
dev_ctx.template Alloc<T>(out);
64-
return;
65-
}
63+
6664
phi::DenseTensorMeta meta = input.meta();
6765
meta.strides = meta.calc_strides(meta.dims);
6866
meta.offset = 0;
6967
out->set_meta(meta);
7068

69+
if (out->numel() == 0) {
70+
dev_ctx.template Alloc<T>(out);
71+
return;
72+
}
73+
7174
// The current complex number implementation uses separate real/imaginary
7275
// parts,resulting in redundant operations and performance
7376
// penalties.Optimization should address this in future iterations.

0 commit comments

Comments
 (0)