I am trying to figure out how to use complex numbers in both my host and device code. I came across cuComplex (but can’t find any documentation!) and float2 which at least gets a mention in the CUDA programming guide.
What should I use? In the header file for cuComplex, it looks like the functions are declared with __host__ __device__ so I am assuming that means that it would be ok to use them in either place.
My original data is being read in from a file into a std::complex<float> so I dont really want to mess with that. I guess in order to use the complex values on the GPU though, I will have to copy from the original complex<float> to the cuComplex?
cuComplexis defined in/usr/local/cuda/include/cuComplex.h(modulo your install dir). The relevant snippets:There are also handy functions in there for working with complex numbers — multiplying them, building them, etc.
As for whether to use
float2orcuComplex, you should use whichever is semantically appropriate — is it a vector or a complex number? Also, if it is a complex number, you may want to consider usingcuFloatComplexorcuDoubleComplexjust to be fully explicit.