After reading your message a second time, I’m not sure if the question is specific for a 2D FFT, or if it refers to the general question about passing “2D arrays” to CUDA.

I wrote a few words about the general issue of “2D array” in this post. Does this already answer your question?

In any case, the data that is passed to CUFFT (and to JCufft) has to be a 1D array, regardless of whether it is for a 1D, 2D or 3D transform. The example that you posted also shows that a 1D array of size NX*NY is allocated:

cudaMalloc((void**)&data1, sizeof(cufftComplex)*NX*NY);

Basically, the execution of a 2D FFT is rather straightforward, for example, a 2D complex forward transform:

```
cufftHandle plan = new cufftHandle();
cufftPlan2d(plan, N, N, CUFFT_C2C);
cufftExecC2C(plan, data, data, CUFFT_FORWARD);
cufftDestroy(plan);
```

Here another example, which prints (parts of) the results of a C2C transform executed with JCufft and with JTransforms:

```
import static jcuda.jcufft.JCufft.*;
import static jcuda.jcufft.cufftType.CUFFT_C2C;
import java.util.*;
import jcuda.jcufft.cufftHandle;
import edu.emory.mathcs.jtransforms.fft.FloatFFT_2D;
public class SimpleJCufft2D
{
private static final Random random = new Random(0);
public static void main(String args[])
{
int N = (1<<4);
float data[] = createRandomFloatData(N * N * 2);
float resultJCufft[] = testJCufft(N, data);
float resultJTransforms[] = testJTransforms(N, data);
System.out.println("JCufft : "+
Arrays.toString(Arrays.copyOfRange(resultJCufft, 0, 10))+"...");
System.out.println("JTransforms: "+
Arrays.toString(Arrays.copyOfRange(resultJTransforms, 0, 10))+"...");
}
private static float[] testJCufft(int N, float input[])
{
float data[] = input.clone();
cufftHandle plan = new cufftHandle();
cufftPlan2d(plan, N, N, CUFFT_C2C);
cufftExecC2C(plan, data, data, CUFFT_FORWARD);
cufftDestroy(plan);
return data;
}
private static float[] testJTransforms(int N, float input[])
{
float data[][] = make2D(input, N, N*2);
FloatFFT_2D fft = new FloatFFT_2D(N,N);
fft.complexForward(data);
return linearize(data);
}
public static float[] createRandomFloatData(int x)
{
float a[] = new float[x];
for (int i=0; i<x; i++)
{
a** = random.nextFloat();
}
return a;
}
public static float[][] make2D(float input[], int x, int y)
{
float result[][] = new float[x][y];
int index = 0;
for (int i=0; i<x; i++)
{
for (int j=0; j<y; j++)
{
result**[j] = input[index++];
}
}
return result;
}
public static float[] linearize(float a[][])
{
List<Float> list = new ArrayList<Float>();
for (int x=0; x<a.length; x++)
{
for (int y=0; y<a[x].length; y++)
{
list.add(a[x][y]);
}
}
float result[] = new float[list.size()];
for (int i=0; i<list.size(); i++)
{
result** = list.get(i);
}
return result;
}
}
```

Note that JTransforms needs “real” Java “2D arrays”, so there are some 1D <-> 2D conversion methods, which might be omitted once the library and the corresponding data layout has been chosen.

bye