# 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;

out=(cufftComplex*)malloc(sizeof(cufftComplex)*matrix->col*matrix->row);

cmatrix->row = matrix->row;

cmatrix->col = matrix->col;

pprComplexMatrixMem(cmatrix);

in[0]=1;

in[1]=2;

in[2]=3;

in[3]=4;

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);

cudaFree(outd);

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

{

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

{

cmatrix->data.real[i*2+j]=out[i*2+j].x;

cmatrix->data.imag[i*2+j]=out[i*2+j].y;

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;

matrix.row=2;

matrix.col=2;

pprMatrixMem(&matrix);

matrix.data[0]=1;

matrix.data[1]=2;

matrix.data[2]=3;

matrix.data[3]=4;

pprFFT(&matrix,&cmatrix);

printf("%f \n",cmatrix.data.real[0]);

printf("%f \n",cmatrix.data.real[1]);

printf("%f \n",cmatrix.data.real[2]);

printf("%f \n",cmatrix.data.real[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.

Cheers

Henrik

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)

Cheers,

Federico

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->
row
matrix->col];

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.