cufftw.h and C99 complex types

I am trying to convert a code that uses the fftw libraries into a code that uses the CUDA fftw libraries. The first step in this conversion is to change the inclusion of the header fftw3.h to cufftw.h

However, it seems as though the definition of complex data types in these two headers is different. The cufftw.h header does not seem to use the standard C99 complex types if the complex.h header has been included.

Have others encountered this problem? Is there a work around? Or should I be changing all of my complex definitions to be double arrays?


The layout of the complex data types exported by cuComplex.h (which are used by CUBLAS and CUFFT, best I know) is identical to the layout specified for the complex data types in C, C++, and Fortran.

The problem I have is when trying to do something like this

fftw_complex a;

a = 0.0 + _Complex_I*0.0;

I will get the error

error: incompatible types when assigning to type ‘fftw_complex’ from type ‘complex double’

The above code works when compiling with gcc and fftw3.h. The workaround I have is

a[0] = 0.0;
a[1] = 0.0;

But I do not want to have to do this to my entire code. Shouldn’t the transition be seamless?

The single source code line above suggests you are trying to perform complex arithmetic. If this is device code, it will not work because CUDA does not support complex arithmetic in either C99 or C++ style. If this is host code, one would have to examine the typedef for fftw_complex to diagnose what exactly is going on.

I would guess (I did not check !) that cufftw.h maps this to one of the complex types defined by cuComplex.h. If so, operations would be limited to the few functions defined in cuComplex.h, for example make_cuDoubleComplex(0.0,0.0) for constructing a complex zero.

What I would suggest in order to minimize impact on your code base is to keep all host code that performs operations on complex data in separate C or C++ files that include fftw3.h, and use the file cufftw.h only in those files that represent the interface to CUFFT.

Yes, this is exactly the case. I have checked the definitions for both cufftw.h and fftw3.h and they are slightly different (which is the cause of problem).

I do like your suggestion and I will give it a try.

Thank you very much. I will let you know how it turns out.

It may not be clear enough from the documentation, but use of cufftw.h is optional. It should be the case that you can use the cufftw library in conjunction with the standard fftw3.h. We provided cufftw.h as a way of generating compile time errors for programs that call fftw functions we don’t support. I would be interested to know if you have had problems compiling using the standard fftw3.h.

njuffa, thanks your solution has worked well.

Paul, so you mean I can use the nvidia cufftw library with the fftw3.h header?

Thanks for closing the loop and good to hear you got things to work. I contacted the library team to explore what we could improve in terms of example code and documentation for this feature (that is new in CUDA 5.5)

Hey Paul,

Your suggestion worked too!

So all in needed to do was change over the linked library. That was easy ;-)