Problems converting cuda complex to C++ complex

Hello!

I’m trying to speed up some image reconstruction using CUDA, running on I’m running this on CUDA 2.2, Mac OS 10.5.7, on a G Force 8600 M GT.

Due to having to preserve as much of the original C++ code as possible, partly to be able to use the functions that come with it, I’m forced to keep using the complex type from the C++ standard library. However, for computations inside the kernels, I need my “own” complex type, which I borrowed from Chris Buchner on this forums (_cudacomplex). Initially, I will create a _cudacomplex array to pass to the kernel, but once it’s been run, I need those numbers back in C++ complex form.

However, I am in no way able to compile any code that lets me reconstruct a Complex array with the cudacomplex values. Here is the bit I used to fill the cudacomplex array in the first place:

for (int i=0;i<NO_FFT*2;i++){
float temp[2] = {(float)creal(PW[i]),(float)cimag(PW[i])};
h_PW[i]= temp;
}

And this is what I’m trying to use (and failing) once I have the results from the kernel back:

[b] for (int i=0;i<compsize;i++){

	double complex ctemp((double)h_PW[i].real,(double)h_PW[i].img);

	PW[i]= ctemp;
}

[/b]

The compiler is spitting these errors:

[b][i]forward_wrap.cu(150): error: a value of type “double” cannot be used to initialize an entity of type “double _Complex”

forward_wrap.cu(150): error: expected a “)”[/i][/b]

There is a lot of inefficiency in splitting those declarations, but at this point, after many hours stuck in this, I’m wiling to accept any performance hit.

I suspect that I might be doing something wrong when linking/importing, or something to do with C/C++ mixed instructions, but I don’t know enough of either language to figure it out.

Thanks a lot in advance, and I hope the problem was explained clearly.

Pablo

PD: Seems like the array index is doing some weird thing with italics… oh well