|
|
|
|
@ -27,6 +27,11 @@
|
|
|
|
|
#include <thrust/complex.h>
|
|
|
|
|
#endif // PADDLE_WITH_CUDA
|
|
|
|
|
|
|
|
|
|
#ifdef PADDLE_WITH_HIP
|
|
|
|
|
#include <hip/hip_complex.h>
|
|
|
|
|
#include <thrust/complex.h> // NOLINT
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
|
|
#include "paddle/fluid/platform/complex128.h"
|
|
|
|
|
@ -54,7 +59,7 @@ struct PADDLE_ALIGN(8) complex64 {
|
|
|
|
|
~complex64() = default;
|
|
|
|
|
|
|
|
|
|
HOSTDEVICE complex64(float real, float imag) : real(real), imag(imag) {}
|
|
|
|
|
#if defined(PADDLE_WITH_CUDA)
|
|
|
|
|
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
|
|
|
|
|
|
|
|
|
|
HOSTDEVICE inline explicit complex64(const thrust::complex<float>& c) {
|
|
|
|
|
real = c.real();
|
|
|
|
|
@ -65,9 +70,15 @@ struct PADDLE_ALIGN(8) complex64 {
|
|
|
|
|
return thrust::complex<float>(real, imag);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef PADDLE_WITH_HIP
|
|
|
|
|
HOSTDEVICE inline explicit operator hipFloatComplex() const {
|
|
|
|
|
return make_hipFloatComplex(real, imag);
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
HOSTDEVICE inline explicit operator cuFloatComplex() const {
|
|
|
|
|
return make_cuFloatComplex(real, imag);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
HOSTDEVICE complex64(const float& val) : real(val), imag(0) {}
|
|
|
|
|
@ -207,7 +218,7 @@ struct PADDLE_ALIGN(8) complex64 {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
HOSTDEVICE inline complex64 operator+(const complex64& a, const complex64& b) {
|
|
|
|
|
#if defined(__CUDA_ARCH__)
|
|
|
|
|
#if defined(__CUDA_ARCH__) || defined(__HIPCC__)
|
|
|
|
|
return complex64(thrust::complex<float>(a.real, a.imag) +
|
|
|
|
|
thrust::complex<float>(b.real, b.imag));
|
|
|
|
|
#else
|
|
|
|
|
@ -216,7 +227,7 @@ HOSTDEVICE inline complex64 operator+(const complex64& a, const complex64& b) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HOSTDEVICE inline complex64 operator-(const complex64& a, const complex64& b) {
|
|
|
|
|
#if defined(__CUDA_ARCH__)
|
|
|
|
|
#if defined(__CUDA_ARCH__) || defined(__HIPCC__)
|
|
|
|
|
return complex64(thrust::complex<float>(a.real, a.imag) -
|
|
|
|
|
thrust::complex<float>(b.real, b.imag));
|
|
|
|
|
#else
|
|
|
|
|
@ -225,7 +236,7 @@ HOSTDEVICE inline complex64 operator-(const complex64& a, const complex64& b) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HOSTDEVICE inline complex64 operator*(const complex64& a, const complex64& b) {
|
|
|
|
|
#if defined(__CUDA_ARCH__)
|
|
|
|
|
#if defined(__CUDA_ARCH__) || defined(__HIPCC__)
|
|
|
|
|
return complex64(thrust::complex<float>(a.real, a.imag) *
|
|
|
|
|
thrust::complex<float>(b.real, b.imag));
|
|
|
|
|
#else
|
|
|
|
|
@ -235,7 +246,7 @@ HOSTDEVICE inline complex64 operator*(const complex64& a, const complex64& b) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HOSTDEVICE inline complex64 operator/(const complex64& a, const complex64& b) {
|
|
|
|
|
#if defined(__CUDA_ARCH__)
|
|
|
|
|
#if defined(__CUDA_ARCH__) || defined(__HIPCC__)
|
|
|
|
|
return complex64(thrust::complex<float>(a.real, a.imag) /
|
|
|
|
|
thrust::complex<float>(b.real, b.imag));
|
|
|
|
|
#else
|
|
|
|
|
@ -246,7 +257,7 @@ HOSTDEVICE inline complex64 operator/(const complex64& a, const complex64& b) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HOSTDEVICE inline complex64 operator-(const complex64& a) {
|
|
|
|
|
#if defined(__CUDA_ARCH__)
|
|
|
|
|
#if defined(__CUDA_ARCH__) || defined(__HIPCC__)
|
|
|
|
|
return complex64(-thrust::complex<float>(a.real, a.imag));
|
|
|
|
|
#else
|
|
|
|
|
complex64 res;
|
|
|
|
|
@ -258,7 +269,7 @@ HOSTDEVICE inline complex64 operator-(const complex64& a) {
|
|
|
|
|
|
|
|
|
|
HOSTDEVICE inline complex64& operator+=(complex64& a, // NOLINT
|
|
|
|
|
const complex64& b) {
|
|
|
|
|
#if defined(__CUDA_ARCH__)
|
|
|
|
|
#if defined(__CUDA_ARCH__) || defined(__HIPCC__)
|
|
|
|
|
a = complex64(thrust::complex<float>(a.real, a.imag) +=
|
|
|
|
|
thrust::complex<float>(b.real, b.imag));
|
|
|
|
|
return a;
|
|
|
|
|
@ -271,7 +282,7 @@ HOSTDEVICE inline complex64& operator+=(complex64& a, // NOLINT
|
|
|
|
|
|
|
|
|
|
HOSTDEVICE inline complex64& operator-=(complex64& a, // NOLINT
|
|
|
|
|
const complex64& b) {
|
|
|
|
|
#if defined(__CUDA_ARCH__)
|
|
|
|
|
#if defined(__CUDA_ARCH__) || defined(__HIPCC__)
|
|
|
|
|
a = complex64(thrust::complex<float>(a.real, a.imag) -=
|
|
|
|
|
thrust::complex<float>(b.real, b.imag));
|
|
|
|
|
return a;
|
|
|
|
|
@ -284,7 +295,7 @@ HOSTDEVICE inline complex64& operator-=(complex64& a, // NOLINT
|
|
|
|
|
|
|
|
|
|
HOSTDEVICE inline complex64& operator*=(complex64& a, // NOLINT
|
|
|
|
|
const complex64& b) {
|
|
|
|
|
#if defined(__CUDA_ARCH__)
|
|
|
|
|
#if defined(__CUDA_ARCH__) || defined(__HIPCC__)
|
|
|
|
|
a = complex64(thrust::complex<float>(a.real, a.imag) *=
|
|
|
|
|
thrust::complex<float>(b.real, b.imag));
|
|
|
|
|
return a;
|
|
|
|
|
@ -297,7 +308,7 @@ HOSTDEVICE inline complex64& operator*=(complex64& a, // NOLINT
|
|
|
|
|
|
|
|
|
|
HOSTDEVICE inline complex64& operator/=(complex64& a, // NOLINT
|
|
|
|
|
const complex64& b) {
|
|
|
|
|
#if defined(__CUDA_ARCH__)
|
|
|
|
|
#if defined(__CUDA_ARCH__) || defined(__HIPCC__)
|
|
|
|
|
a = complex64(thrust::complex<float>(a.real, a.imag) /=
|
|
|
|
|
thrust::complex<float>(b.real, b.imag));
|
|
|
|
|
return a;
|
|
|
|
|
@ -341,6 +352,7 @@ HOSTDEVICE inline bool operator>=(const complex64& a, const complex64& b) {
|
|
|
|
|
|
|
|
|
|
HOSTDEVICE inline bool(isnan)(const complex64& a) {
|
|
|
|
|
#if defined(__CUDA_ARCH__)
|
|
|
|
|
// __isnanf not supported on HIP platform
|
|
|
|
|
return __isnanf(a.real) || __isnanf(a.imag);
|
|
|
|
|
#else
|
|
|
|
|
return std::isnan(a.real) || std::isnan(a.imag);
|
|
|
|
|
@ -349,6 +361,7 @@ HOSTDEVICE inline bool(isnan)(const complex64& a) {
|
|
|
|
|
|
|
|
|
|
HOSTDEVICE inline bool(isinf)(const complex64& a) {
|
|
|
|
|
#if defined(__CUDA_ARCH__)
|
|
|
|
|
// __isinff not supported on HIP platform
|
|
|
|
|
return __isinff(a.real) || __isinff(a.imag);
|
|
|
|
|
#else
|
|
|
|
|
return std::isinf(a.real) || std::isinf(a.imag);
|
|
|
|
|
@ -360,7 +373,7 @@ HOSTDEVICE inline bool(isfinite)(const complex64& a) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HOSTDEVICE inline float(abs)(const complex64& a) {
|
|
|
|
|
#if defined(__CUDA_ARCH__)
|
|
|
|
|
#if defined(__CUDA_ARCH__) || defined(__HIPCC__)
|
|
|
|
|
return complex64(thrust::abs(thrust::complex<float>(a.real, a.imag)));
|
|
|
|
|
#else
|
|
|
|
|
return std::abs(std::complex<float>(a.real, a.imag));
|
|
|
|
|
@ -368,7 +381,7 @@ HOSTDEVICE inline float(abs)(const complex64& a) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HOSTDEVICE inline complex64(pow)(const complex64& a, const complex64& b) {
|
|
|
|
|
#if defined(__CUDA_ARCH__)
|
|
|
|
|
#if defined(__CUDA_ARCH__) || defined(__HIPCC__)
|
|
|
|
|
return complex64(thrust::pow(thrust::complex<float>(a.real, a.imag),
|
|
|
|
|
thrust::complex<float>(b.real, b.imag)));
|
|
|
|
|
#else
|
|
|
|
|
@ -377,7 +390,7 @@ HOSTDEVICE inline complex64(pow)(const complex64& a, const complex64& b) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HOSTDEVICE inline complex64(sqrt)(const complex64& a) {
|
|
|
|
|
#if defined(__CUDA_ARCH__)
|
|
|
|
|
#if defined(__CUDA_ARCH__) || defined(__HIPCC__)
|
|
|
|
|
return complex64(thrust::sqrt(thrust::complex<float>(a.real, a.imag)));
|
|
|
|
|
#else
|
|
|
|
|
return std::sqrt(std::complex<float>(a));
|
|
|
|
|
@ -385,7 +398,7 @@ HOSTDEVICE inline complex64(sqrt)(const complex64& a) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HOSTDEVICE inline complex64(tanh)(const complex64& a) {
|
|
|
|
|
#if defined(__CUDA_ARCH__)
|
|
|
|
|
#if defined(__CUDA_ARCH__) || defined(__HIPCC__)
|
|
|
|
|
return complex64(thrust::tanh(thrust::complex<float>(a.real, a.imag)));
|
|
|
|
|
#else
|
|
|
|
|
return std::tanh(std::complex<float>(a));
|
|
|
|
|
@ -393,7 +406,7 @@ HOSTDEVICE inline complex64(tanh)(const complex64& a) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HOSTDEVICE inline complex64(log)(const complex64& a) {
|
|
|
|
|
#if defined(__CUDA_ARCH__)
|
|
|
|
|
#if defined(__CUDA_ARCH__) || defined(__HIPCC__)
|
|
|
|
|
return complex64(thrust::log(thrust::complex<float>(a.real, a.imag)));
|
|
|
|
|
#else
|
|
|
|
|
return std::log(std::complex<float>(a));
|
|
|
|
|
|