CUFFT gives wrong results? the results from MATLAB and CUFFT differ...

Hello Everybody,

I have been starting at this code for ages, and couldn’t figure out what is wrong with it.

Basically, I am trying to write a simple ifft function for to compare with the ifft function in MATLAB. The code works fine with 1D data (1x 1024) with and without padding. However, it spits out weird answers when I try a 2D data (as in 2x 1024 matrix). To clarify here, I want to use the batch capability to do 2 ifft in parallel.

I have written my code as follow:

[codebox] cufftPlan1d(&plan, N, CUFFT_C2C, M) ;

cufftExecC2C(plan, rhs_complex_d, rhs_complex_d, CUFFT_INVERSE) ;[/codebox]

where N = 1024, M = 2. But somehow I just couldn’t get the result to agree with the MATLAB result, which I know is correct.

I have attached a copy of my code, which is based on the ifft2_cuda.c example that came with the MATLAB plugin. Also, I have attached a picture showing the two results: the top being what it supposes to look like, and bottom being what I am getting with the above code.

Any suggestions or helps are much appreciated!!
ifft_cuda.txt (6.03 KB)

From what I know, the data has to be stored in a special way for batch computing of FFT.

Hi wanderine,

Thanks for your input. The data was prepared and stored in the interleaved format required by the CUDA FFT prior to the operation on the device. However, it is similar to what you have suspected. The errors were make at the file format and conversation of the results back from C to MATLAB. The example below will try to illustrate the problem with the previously attached code (and the solution is somewhat trivial after that).

Starting with 2 1024 elements array, which is stored in sort of a weird way like so:

1 3 5 7 … 1021 1023 1025 … 2045 2047

2 4 6 8 … 1022 1024 1026 … 2046 2048

The IFFT was performed on the 2 sets of data correctly and the results are stored back in the exact same format.

However, the unpack function reads row-wise, and grouped the top row as one data set and the bottom as the other. This resulted in what seemed like 2 IFFT’s in one row of data while the second half of the data are placed in the second row.

Thanks to those who took time to look at my problem and my codes, and special thanks to wanderine for posting suggestions.

Just a dumb guess (as I haven’t used CUFFT) but is it something as simple as single versus double precision?
You might compare with Volkov’s speedy CUDA FFT, too… not just because it’s faster, but as a quality double check.

If I’v got a penny for each time I messed up because Matlab’s saving column first I would be really rich…I thought of this first but did not think it could happen in 1D

I have resolved the issue, and I didn’t notice problems arising from single precision operations.