CUFFT how use it?

Greetings,

i have some problems to understand how correctly use the cufft library.

i must calculate the fourier transform of an array of 512 elements (floats).

this my code:

#define DIM 512

		....

	float f[DIM];

	FILE *img = fopen("Image0.bin","r");

	fread(f,sizeof(float),DIM,img);

	fclose(img);

	cufftComplex f2[DIM];

	int i;

	for(i = 0; i < DIM; i++)

		f2[i].x = f[i];

		 cufftComplex *df;

	cudaMalloc((void**)&df,sizeof(cufftComplex)*DIM);

	cudaMemcpy(df,f2,DIM,cudaMemcpyHostToDevice);

	cufftHandle plan;

	cufftPlan1d(&plan, DIM, CUFFT_C2C, 1);

	cufftExecC2C(plan, df, df,CUFFT_FORWARD);

	cudaMemcpy(f2,df,DIM,cudaMemcpyDeviceToHost);

the problem is that this code do nothing in sense that f and f2 are equal.

Reading the cufft manual in the examples i noted that it uses ‘BATCH’…what is the utility of batch?

why it is == 10 in the examples and not == 2 or == 100?

thanks a lot

Are you performing any error checking?

BATCH is for doing many FFTs of the same length in parallel. If you aren’t using this, you probably don’t want to use CUDA. In the example, they are performing 10 FFTs, not 2 nor 100 (the could be, but they chose 10).

ah…

ok suppose that i have 900 array of 512 elements…to calculate the DFT of everyone i can

do

....

 cudaMalloc((void**)&df,sizeof(cufftComplex)*DIM*NUM);

 cudaMemcpy(.....);

 cufftPlan1d(&plan, 512, CUFFT_C2C, 900);

 cufftExecC2C(plan, df, df,CUFFT_FORWARD);

 ....

thank you!

Yep, that code should do the trick. I urge you to look into adding some error handling though ;)