Complex Numbers on CUDA

Hello Everyone,

After searching for a long time and not getting relevant answer, i am here to ask from you all guys. Its a simple question but i didn’t get any clue to this. I have to transfer complex number from Host to Device and after searching about this i came to know that cuComplex header file is used for this purpose. On host i am using complex and on device side cuComplex. but i am getting error that they are not compatible with each other. So can anybody help me to figure out how i can solve this problem. i have to transfer these complex numbers and on device on multiplication will be carried out.
so the question is how i can transfer complex number and is there any library to use exp, sin or cos functions in CUDA??

Waiting for a favorable response.

Thanks
Regards

Hello,

You should use the same type on both host and device, or use the converter (cuComplex *) Array when you submit it in the kernel.

Dear Pasoleatis,

Thanks for the reply but truely speaking i am not getting the point. I am pasting a simple code of complex numbers can you just write the GPU part for me? it will be very helpful for me. On CPU side i am using complex…

global void kernelFunc(complex *ad,complex *bd,complex *cd,int N)
{
int i = blockDim.x * blockIdx.x + threadIdx.x;

	cd[i]=ad[i] + bd[i];

}

int main(int argc, char *argv)
{
int i;
complex a[3];
complex b[3];
complex c[3];

complex *ad,*bd,*cd;

int size = 3*sizeof(complex);

cudaMalloc((void**)&ad,size);
cudaMalloc((void**)&bd,size);
cudaMalloc((void**)&cd,size);
memset(c,0,sizeof(c));

cudaMemcpy(ad,a,size,cudaMemcpyHostToDevice);
cudaMemcpy(bd,b,size,cudaMemcpyHostToDevice);

dim3 dimGrid(1,1,1);
dim3 dimBlock(3,1,1);

kernelFunc <<< dimGrid,dimBlock >>> (ad,bd,cd,3);
cudaDeviceSynchronize();
cudaMemcpy(c,cd,size,cudaMemcpyDeviceToHost);

}

i am taking an array of size 3.
also i am suing complex for both but getting an error.

Please look at it.

Thanks

Hello,

Sorry it is called cufftComplex and it comes with the cufft library If you have a complex float you can use the type cufftComplex on both host and device. To my knowledge there is no structure for complex int. One way to do it is do define int2 variable and make the additions each component, something like

int2 a,b,c;

a.x=b.x+c.x;

a.y=b.y+c.y;

The other possibility is to define ourself complex structure and define the addition operation.

Of course you always use the cufftComplex and work with floats.

Pleas eput your code between the lines [ code ] and [ / code ] (without the spaces) it makes a nice formatting and makes it easier to read it.

Dear Pasoleatis,

Thanks a lot for your guidance, the technique works. Actually i was familiar with cufftComplex but thought may be complex will work for it. Anyway thanks again and if ever you will visit South Korea…just remember you have one friend here…cheers…Hopefully in future again i will disturb you…

Thanks