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<float> 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 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<float> 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

#1
Posted 05/04/2012 07:45 AM   
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.
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.

#2
Posted 05/04/2012 08:47 AM   
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<float>...

__global__ void kernelFunc(complex<int> *ad,complex<int> *bd,complex<int> *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<int> a[3];
complex<int> b[3];
complex<int> c[3];

complex<int> *ad,*bd,*cd;

int size = 3*sizeof(complex<int>);

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<int> for both but getting an error.

Please look at it.

Thanks
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<float>...



__global__ void kernelFunc(complex<int> *ad,complex<int> *bd,complex<int> *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<int> a[3];

complex<int> b[3];

complex<int> c[3];



complex<int> *ad,*bd,*cd;



int size = 3*sizeof(complex<int>);



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<int> for both but getting an error.



Please look at it.



Thanks

#3
Posted 05/04/2012 09:07 AM   
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

[code]
int2 a,b,c;
a.x=b.x+c.x;
a.y=b.y+c.y;
[/code]

The other possibility is to define ourself complex<int> 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.
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<int> 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.

#4
Posted 05/04/2012 09:36 AM   
Dear Pasoleatis,

Thanks a lot for your guidance, the technique works. Actually i was familiar with cufftComplex but thought may be complex<float> 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
Dear Pasoleatis,



Thanks a lot for your guidance, the technique works. Actually i was familiar with cufftComplex but thought may be complex<float> 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

#5
Posted 05/04/2012 01:39 PM   
Scroll To Top