cuFFT return zeros

Hi I have the following test code for the CUFFT in 2D

void pprFFT(pprMatrix *matrix, pprComplexMatrix *cmatrix)


	cufftHandle plan;

	cufftReal in[matrix->row*matrix->col],indev[matrix->row*matrix->col]; 

	cufftComplex *out,*outd;

	int i,j;



	cmatrix->row = matrix->row;

	cmatrix->col = matrix->col;









	cudaMalloc((void**)&outd, sizeof(cufftComplex)*4);

	cudaMalloc((void**)&indev, sizeof(cufftReal)*4);


	 cudaMemcpy(indev, in, sizeof(cufftReal)*4, cudaMemcpyHostToDevice);


	cufftResult err1 = cufftPlan2d(&plan, 2, 2, CUFFT_R2C);

	printf("%d\n", err1);

	cufftResult err2 =cufftExecR2C(&plan, indev, outd);

	printf("%d\n", err2);


	cudaMemcpy(out, outd, sizeof(cufftComplex)*4, cudaMemcpyDeviceToHost);






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


		for(j =0 ; j < 2 ; j++)




			printf("data[%d] %f %f\n", i, out[i*2+j].x, out[i*2+j].y);





int main(int argc, char *argv[])


	pprMatrix matrix;

	pprComplexMatrix cmatrix;


	int i,j;






	printf("%f \n",[0]);

	printf("%f \n",[1]);

	printf("%f \n",[2]);

	printf("%f \n",[3]);



But the result is all zeros. The error is in ExecR2C (CUFTT_EXEC_FAILED) but don’t know how to solve it, any ideas?

I have a vector with all the info of the image but I want to perform a 2D FFT with those values.

Hi Brabbit

From your code it seems like your plan is very small. Are you trying to do a 2D FFT of a 2-by-2 matrix?

Also, you do not specify a direction. It might have a default, but you should anyway.

My suggestion would be to make a test case of a 32 by 32 amount of data, and specifying a forward FFT.



Thanks !

Yes, I’m working on images so I want to do a 2D FFT, I used a 2-by-2 matrix but even with that small number doesn’t work, in fact, my images are from 60 thousand pixels to 70 MP,

but I wanted to try it first on a small data set.

I’ll explain my problem:

My data is thought as a 2D matrix, let’s say:

1 2 3 4

6 7 8 9

1 8 3 4

And i want to perform a 2D FFT, but in memory I have the following:

1 2 3 4 6 7 8 9 1 8 3 4

But as I said I need a 2D FFT. I checked with the examples on the site of nvidia but couldn’t make it work. The direction of the CUFFT is implicit (at least that’s what it says on the CUFFT library pdf)



It is correct you do not need to specify the direction. Have you tried to allocate memory using malloc() instead of doing it “the C++ way?” I have done some 2D FFTs lately, but I did all of my own memory allocation. I would also ensure your data being sent to the GPU before th FFT is what you expect it to be. The rest of the code seems ok to me.

You said some of your data is large data sets - 70M pixels…how do you plan on doing images that large that will not fit on the GPU? I am trying to accomplish this same goal, and just recently got my code working, but it will crash if I try to create FFT plans too large for my device.

By “the C++ way” you mean using new? I use malloc since I’m basically using C (although there’s no much problem writing that on C++)

Yes I checked if my pointers (on the host) to the data have the right info and they do.

Well I haven’t tried with 70 MP images, I think there’s a limit on the size of the matrix in CUFFT…but first I need to make the CUFFT work desperately :S

I’ll keep trying any advise is very welcome :=)

What i meant was - cufftReal in[matrix->rowmatrix->col],indev[matrix->

Fix those lines to use malloc and try it

Ok thanks, I’ll try it right now…

Can anyone give a piece of code that you are completely sure it works … I really basic test code performing a FFT on a 2D matrix.