Skip to content

[XPU] add complex,real,imag,conj op for xpu #72649

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 4 commits into from
May 15, 2025

Conversation

fangfangssj
Copy link
Contributor

@fangfangssj fangfangssj commented May 9, 2025

PR Category

Operator Mechanism

PR Types

New features

Description

XPU新增complex,real,imag,conj四个算子和对应单测

  • 未添加complex128是因为xfft的底层不支持双精度浮点数
  • 使用const_cast是因为xfft库中函数未使用const来声明参数
  • 打开WITH_XPU_FFT才编译新增加的fft相关的算子,未打开的情况下不编译进去,这样的话不需要报not implemented或者precondition not met,当未编译时使用到相关的算子时,框架会自动fallback回cpu上执行,这样不会报错,使用体验更好一些

Pcard-75624

Copy link

paddle-bot bot commented May 9, 2025

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@fangfangssj fangfangssj changed the title [xpu] add complex,real,imag op for xpu [XPU] add complex,real,imag op for xpu May 9, 2025
Copy link
Contributor

@dynamicheart dynamicheart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

dev_ctx.template Alloc<T>(dx, static_cast<size_t>(numel * sizeof(T)));
DenseTensor real = Fill<phi::dtype::Real<T>, Context>(
dev_ctx, common::vectorize<int>(dout.dims()), phi::dtype::Real<T>(0.0));
int r = xfft_internal::xpu::combine_as_complex(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xpufftPR:#72477


#include "paddle/phi/kernels/complex_grad_kernel.h"

#include "fft/cuComplex.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里是不是需要开启WITH_XPU_XFT才能编译?那就要考虑以下几件事:
1、现在这个配置,默认是OFF,所以默认情况下就编不过?
2、是否需要像其它宏定义一样,加个判断?比如,如果没定义这个,就走到另外的分支上,报not implemented或者precondition not met。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是的,已修改为打开WITH_XPU_FFT才编译新增加的fft相关的算子,未打开的情况上不编译进去
这样的话不需要报not implemented或者precondition not met,当未编译时使用到相关的算子时,框架会自动fallback回cpu上执行,这样不会报错,使用体验更好一些

reinterpret_cast<cuFloatComplex*>(const_cast<T*>(x.data<T>())),
reinterpret_cast<cuFloatComplex*>(out->data<T>()));
PADDLE_ENFORCE_XDNN_SUCCESS(r, "conj");
if (std::is_same<T, phi::dtype::complex<float>>::value) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以尝试把is_same::value换成is_same_v

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在下个PR中修改,同时conj在xpu3_op_list.cc中少添加的类型也在下个PR中添加

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fangfangssj fangfangssj changed the title [XPU] add complex,real,imag op for xpu [XPU] add complex,real,imag,conj op for xpu May 15, 2025
@fangfangssj
Copy link
Contributor Author

/re-run approval

@HydrogenSulfate HydrogenSulfate merged commit ce0a5f5 into PaddlePaddle:develop May 15, 2025
54 of 56 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants