complex library in CUDA

Does CUDA have a complex library which support operation like sin, cos, exp? I can’t find those operation in cuComplex.h. :unsure:

Not that I know of. You can think of type complex as float[2]. Then if you want to calculate say sin(z), use elementary math formulas to do that.

The cuComplex class doesn’t even overload basic maths operators. It is certainly possible to add your own non-member overloads in a separate header file, but a cleaner way would be to write a wrapper class around this class.

I’ve tried something similar and came up with a cudaComplex class, which you can find here in the forums. It doesn’t yet implement any transcendentals (sin, cos, exp, etc), though.


Thx for your reply, I’ll try to use double[2] :)

Depending on what you want to do, double[2] might be good, but sometimes keeping parallel arrays of the real and imaginary part makes more sense. For example if you want to conjugate a large array that is set up with elements that are double[2] then you get a memory bandwidth penalty compared to two large arrays of doubles for the real and imaginary parts, for other operations it’s the other way around.