Skip to content

[XPU] bugfix for contiguous in 0-size #73004

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions paddle/phi/kernels/xpu/contiguous_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ template <typename T, typename Context>
void ContiguousKernel(const Context& dev_ctx,
const DenseTensor& input,
DenseTensor* out) {
if (out->numel() == 0) {
dev_ctx.template Alloc<T>(out);
return;
}
phi::DenseTensorMeta meta = input.meta();
meta.strides = meta.calc_strides(meta.dims);
meta.offset = 0;
out->set_meta(meta);

if (out->numel() == 0) {
dev_ctx.template Alloc<T>(out);
return;
}

// use XPUCopyTypeTrait to deal with double and int16_t copy instead of
// XPUTypeTrait
using XPUType = typename XPUCopyTypeTrait<T>::Type;
Expand All @@ -59,15 +60,17 @@ template <>
void ContiguousKernel<phi::dtype::complex<float>, XPUContext>(
const XPUContext& dev_ctx, const DenseTensor& input, DenseTensor* out) {
using T = phi::dtype::complex<float>;
if (out->numel() == 0) {
dev_ctx.template Alloc<T>(out);
return;
}

phi::DenseTensorMeta meta = input.meta();
meta.strides = meta.calc_strides(meta.dims);
meta.offset = 0;
out->set_meta(meta);

if (out->numel() == 0) {
dev_ctx.template Alloc<T>(out);
return;
}

// The current complex number implementation uses separate real/imaginary
// parts,resulting in redundant operations and performance
// penalties.Optimization should address this in future iterations.
Expand Down