gpucomplex

This header is in the RTS, and contains useful CUDA operators. All credit to the original author, R. G. Edgar. I’ve added in double definitions, as well as my gpuUserComplex` def, which allows float or double to be selected during compilation using the flag --DDOUBLE_PRECISION (so even though in the below it says typedef gpuFloatComplex gupuUserComplex, this depends on compilation). This code has also been updated with GPU macros, so it can be used for both CUDA and HIP code in conjunction with the gpu_macros.h header.

CUDA operators for complex numbers. For some reason, these aren’t defined in the CUDA headers form NVIDIA

Author

R. G. Edgar; modified with macros by M. Sokolowski

Typedefs

typedef gpuFloatComplex gpuUserComplex

If -DDOUBLE_PRECISION flag is NOT added at compilation, then cuUserComplex is set to cuFloatComplex

Functions

__device__ inline gpuFloatComplex operator-(gpuFloatComplex a)

Unary negative.

__device__ inline void operator+=(gpuFloatComplex &a, const gpuFloatComplex b)

Self addition.

__device__ inline gpuFloatComplex operator+(const gpuFloatComplex a, const gpuFloatComplex b)

Addition of two complex numbers.

__device__ inline gpuFloatComplex operator+(const gpuFloatComplex a, const float r)

Addition of float to complex.

__device__ inline gpuFloatComplex operator+(const float r, const gpuFloatComplex z)

Addition of complex to float.

__device__ inline void operator-=(gpuFloatComplex &a, const gpuFloatComplex b)

Self subtraction.

__device__ inline gpuFloatComplex operator-(const gpuFloatComplex a, const gpuFloatComplex b)

Subtraction.

__device__ inline void operator*=(gpuFloatComplex &a, const gpuFloatComplex b)

Self multiplication.

__device__ inline gpuFloatComplex operator*(const gpuFloatComplex a, const gpuFloatComplex b)

Multiplication of two complex numbers.

__device__ inline void operator*=(gpuFloatComplex &z, const float r)

Self multiplication by real number.

__device__ inline gpuFloatComplex operator*(const gpuFloatComplex z, const float r)

Multiplication by a real number.

__device__ inline gpuFloatComplex operator*(const float r, const gpuFloatComplex z)

Multiplication of a real number.

__device__ inline gpuFloatComplex operator/(const gpuFloatComplex a, const gpuFloatComplex b)

Division of two complex numbers.

__device__ inline gpuFloatComplex operator/(const float r, const gpuFloatComplex b)

Division of a real number.

__device__ inline gpuFloatComplex operator/(const gpuFloatComplex a, const float r)

Division by a real number.

__device__ inline gpuFloatComplex gpuComplexExp(const gpuFloatComplex z)

Exponentiation Computes e^z == e^x ( cos y + i sin y )

__device__ inline gpuFloatComplex U1polar(const float theta)

Calculate real and imaginary parts of U(1) variable e^(i*theta)

__device__ inline gpuDoubleComplex operator-(gpuDoubleComplex a)

Unary negative.

__device__ inline void operator+=(gpuDoubleComplex &a, const gpuDoubleComplex b)

Self addition.

__device__ inline gpuDoubleComplex operator+(const gpuDoubleComplex a, const gpuDoubleComplex b)

Addition of two complex numbers.

__device__ inline gpuDoubleComplex operator+(const gpuDoubleComplex a, const double r)

Addition of double to complex.

__device__ inline gpuDoubleComplex operator+(const double r, const gpuDoubleComplex z)

Addition of complex to double.

__device__ inline void operator-=(gpuDoubleComplex &a, const gpuDoubleComplex b)

Self subtraction.

__device__ inline gpuDoubleComplex operator-(const gpuDoubleComplex a, const gpuDoubleComplex b)

Subtraction.

__device__ inline void operator*=(gpuDoubleComplex &a, const gpuDoubleComplex b)

Self multiplication.

__device__ inline gpuDoubleComplex operator*(const gpuDoubleComplex a, const gpuDoubleComplex b)

Multiplication of two complex numbers.

__device__ inline void operator*=(gpuDoubleComplex &z, const double r)

Self multiplication by real number.

__device__ inline gpuDoubleComplex operator*(const gpuDoubleComplex z, const double r)

Multiplication by a real number.

__device__ inline gpuDoubleComplex operator*(const double r, const gpuDoubleComplex z)

Multiplication of a real number.

__device__ inline gpuDoubleComplex operator/(const gpuDoubleComplex a, const gpuDoubleComplex b)

Division of two complex numbers.

__device__ inline gpuDoubleComplex operator/(const double r, const gpuDoubleComplex b)

Division of a real number.

__device__ inline gpuDoubleComplex operator/(const gpuDoubleComplex a, const double r)

Division by a real number.

__device__ inline gpuDoubleComplex gpuComplexExp(const gpuDoubleComplex z)

Exponentiation Computes e^z == e^x ( cos y + i sin y )

__device__ inline gpuDoubleComplex U1polar(const double theta)

Calculate real and imaginary parts of U(1) variable e^(i*theta)

__device__ inline gpuUserComplex make_gpuUserComplex(user_precision_t real, user_precision_t imag)

Make a CUDA complex to the precision set during compilation.