Reputation: 1
I could not find an example of application of cuFFT with CUDA in which the transformation of a matrix is realized as 1D transformations of rows and columns.
I have a 2048x2048
array (set as 1D of cuComplex
data). With 2D transform - no problem. But now what I need is to do the transform along x
, do some work on it, take inverse fft, then do the transform along y
, and do another work on it, then take its inverse transform.
How exactly would the sequence of commands look like if I want to use parallel processing? Should I use cuFFTPlanMany
? How? Or, perhaps, is there an example somewhere that I was not able to find?
Upvotes: 0
Views: 1510
Reputation: 21455
In the cuFFT Library User's guide, on page 3, there is an example on how computing a number BATCH
of one-dimensional DFTs of size NX
. Using cufftPlan1d(&plan, NX, CUFFT_C2C, BATCH);
, then cufftExecC2C
will perform a number BATCH
1D FFTs of size NX
. To achieve that, you have to arrange your data in a complex array of length BATCH*NX
. In your case, for the transform along x
, it would be BATCH=2048
and NX=2048
. For the transforms along y
, you have to transpose the matrix arising from previous calculations.
Your code will look like the following
#define NX 2048
#define NY 2048
int main() {
cufftHandle plan;
cufftComplex *data;
...
cudaMalloc((void**)&data, sizeof(cufftComplex)*NX*NY);
cufftPlan1d(&plan, NX, CUFFT_C2C, NY);
...
cufftExecC2C(plan, data, data, CUFFT_FORWARD);
...
// do some work
...
// make a transposition
...
cufftPlan1d(&plan, NY, CUFFT_C2C, NX);
...
cufftExecC2C(plan, data, data, CUFFT_FORWARD);
...
}
Upvotes: 3