cuFFT. A way to read complex data produced by the procedure

Hello. Would you tell me a way to read the array of complex values produced by the procedure? Probably, it can be done on a lower level with pointers, but would like to know if could exist other way to do it.

I don’t have the faintest clue what might be meant by “other ways” of accessing the data. A 1-D array is the simplest of all data structures: One accesses it by supplying the index to the desired element.

Are you using CUFFT directly from a CUDA program, or are you interfacing to it from some other language, e.g. Python? If the latter, use whatever mechanism is appropriate in that language, but as far as I am familiar with languages outside the C/C++ family they all support the notion of an array.

I wonder whether you are looking at some sort of XY issue. In other words: What are you trying to accomplish that gave rise to this question?

I try to read the output of cuFFT from C++.

The input of the FFT is an array, the output is an array: Clearly you are already handling arrays in your C++ code. In addition, you mentioned in a different question that you previously used FFTW, whose interfaces are very similar to CUFFT. So I fail to see what the issue might be.

In FFTW there is an explicit array structure which holds real and imaginary values.

You might want to show some code that demonstrates what you are talking about. I have not used FFTW so will assume it just uses regular old C/C++ arrays. Consider the equivalency of the two code snippets below:

void my_func (float *arg, float *res);
#define N 1024

float arg1[N], res1[N];
/* Initialize content of arg1 */
my_func (arg1, res1);
printf ("%15.8e\n", res1[0]);  // <<<<<<<<<

float *arg2 = malloc (N * sizeof (float));
float *res2 = malloc (N * sizeof (float));
/* Initialize content of arg2 */
my_func (arg2, res2);
printf ("%15.8e\n", res2[0]);  // <<<<<<<<<

I looked at the FFTW API and it passes regular old pointers to complex data for input and output. Example:

FFTW_CDECL X(execute_r2r)(const X(plan) p, R *in, R *out);

A difference with CUFFT seems to be that the complex type R in CUFFT is a two-element array rather than a two-element struct as in CUFFT (but with a compatible layout: real part followed by imaginary part)

/* complex type for internal use */
typedef R C[2];

I wonder if values in cufftDoubleComplex structure go like real-imaginary, or if all real values are stored first, and then go imaginary numbers?

Use the source, Luke! If you look at the header files that come with CUDA, you’ll find:


typedef cuDoubleComplex cufftDoubleComplex;


typedef double2 cuDoubleComplex;
__host__ __device__ static __inline__ double cuCreal (cuDoubleComplex x) 
    return x.x; 
__host__ __device__ static __inline__ double cuCimag (cuDoubleComplex x) 
    return x.y; 


struct __device_builtin__ __builtin_align__(16) double2
    double x, y;

So each cuDoubleComplex is a suitably aligned struct of two elements, the .x of which stores the real part and the .y of which stores the imaginary part.

How does FFTW store its complex numbers? I may have misinterpreted the header file because I was to lazy to track down the definition of type ‘C’. Maybe it is a pointer type rather than an elementary numeric type. [Later:] It looks like my interpretation was correct, as the FFTW documentation says:

As far as I recall, MATLAB carries around complex numbers as separate arrays of real and imaginary components.

Thank you for detailed answer. The problem is solved now.