I’ve just started a project which i plan on porting to CUDA, most of the operations involve mixed math on complex and real numbers. I’ve never really used complex numbers before in any of my code so i’m not quite sure what’s the best way to start, especially since i will immediately be working with cuda and so don’t want to use a type which is not even cuda supported.
My options appear to be -> the c++ complex class template (which is pretty crap), using the gsl complex numbers which is a bit annoying as it’s all macro tastic but probably pretty solid, using the C99 complex.h specificiation which seems to be very good but i’m not sure how this will mix with nvcc or just knocking together my own typedef, basic fns etc.
Anyone else done much with complex numbers? Any thoughts or advice?
You will probably need to roll your complex struct to manipulate complex numbers from global and device functions. Other libraries are not going to work from the GPU, probably not even purely template libraries like STL.
nvcc does support operator overloading, so you can easily write stuff like this:
What support is there for complex arithmetic like that in math.h and complex.h ? I see that convolutionFFT2D in the SDK uses the Complex data type (float2) and I see cublasCgemm() in the CUBLAS documentation, but I was curious about the status of the math library.
I’m also using my own Complex struct. But here comes the point. I seperated my cuda code from my C code in my .cu file will be my kernel etc. I pass my struct to the kernel as an argument but I also want to use the struct inside my C code. How can I manage to do that?
Without make 2 typedefs with exactly the same name but without the hostdevice bla bla bla…