[Complex] Fix wrong reciprocal result when meets complex dtype#74290
Merged
luotao1 merged 2 commits intoPaddlePaddle:developfrom Jul 31, 2025
Merged
[Complex] Fix wrong reciprocal result when meets complex dtype#74290luotao1 merged 2 commits intoPaddlePaddle:developfrom
luotao1 merged 2 commits intoPaddlePaddle:developfrom
Conversation
|
你的PR提交成功,感谢你对开源项目的贡献! |
Contributor
Author
|
/re-run all-failed |
Malone-AI
reviewed
Jul 30, 2025
Malone-AI
left a comment
There was a problem hiding this comment.
What about extracting shared CPU/GPU code?
Like this one
template <typename T>
__host__ __device__ __forceinline__ ComplexType<T> reciprocal_complex_kernel(
const ComplexType<T>& val) {
auto both_inf = [](T real, T imag) {
return (isinf(real) && isinf(imag));
};
auto either_inf = [](T real, T imag) {
return isinf(real) || isinf(imag);
};
auto either_nan = [](T real, T imag) {
return isnan(real) || isnan(imag);
};
if (either_nan(val.real, val.imag) || both_inf(val.real, val.imag)) {
T quiet_nan = std::numeric_limits<T>::quiet_NaN();
return ComplexType<T>(quiet_nan, quiet_nan);
} else if (either_inf(val.real, val.imag)) {
return ComplexType<T>{static_cast<T>(0), static_cast<T>(0)};
}
return static_cast<ComplexType<T>>(1.0) / val;
}
template <typename T>
struct Reciprocal {
HOSTDEVICE ComplexType<T> operator()(const ComplexType<T>& val) const {
return reciprocal_complex_kernel(val);
}
};
template <typename T>
struct CudaReciprocalFunctor<ComplexType<T>>
: public BaseActivationFunctor<ComplexType<T>> {
__device__ __forceinline__ ComplexType<T> operator()(
const ComplexType<T> x) const {
return reciprocal_complex_kernel(x);
}
};
Contributor
@Malone-AI, you can create a new PR to extract shared CPU/GPU code. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Category
Operator Mechanism
PR Types
Bug fixes
Description
#73714
Fix wrong reciprocal result when meets complex dtype