Search code examples
cudafftwcufft

Debugging CUFFTW interface plan creation


I am begining to port an existing fftw3 application to make use of the cuda fftw libraries. The initial stage is to simply replace the fftw3.h header with the cufft.h header and link the cufft libraries instead of the fftw3 libraries.

That is simple enough, and the code compiles with nvcc. However when I execute the code the application is unable to create a plan using the fftw_plan_guru_dft command (it just returns 0 instead of a valid plan).

Since there are no errors reported I am at a loss as to how I might debug this issue. cuda-gdb and gdb do not provide any further insight. They simply report

Error: Internal error reported by CUDA debugger API (error=7). The application cannot be further debugged.

UPDATE: So here is the minimum working example. As mentioned in my comment to Talonmies, this code is autogenerated by a scientific differential equation solver. So please excuse the function names etc.

#define real Re
#define imag Im

#include <complex>

#undef real
#undef imag

#include <cufftw.h>

#include <stdio.h>

int main(void) {
     int _transform_sizes_index = 1, _loop_sizes_index = 0;
     fftw_iodim _transform_sizes[1], _loop_sizes[2];
     _transform_sizes[0].n = 128;
     _transform_sizes[0].is = 0;
     _transform_sizes[0].os = 0;

    fftw_complex _data_in[128] = {0.};

    static fftw_plan _fftw_forward_plan = NULL;
    _fftw_forward_plan = fftw_plan_guru_dft(
          _transform_sizes_index, _transform_sizes,
          _loop_sizes_index, _loop_sizes,
          reinterpret_cast<fftw_complex*>(_data_in),
          reinterpret_cast<fftw_complex*>(_data_in),
          FFTW_FORWARD, FFTW_PATIENT);
    if (!_fftw_forward_plan)
       printf("Error: Unable to create forward plan\n");

    return 0;
}

Unless anyone else knows what I am doing wrong, it looks like this particular functionality of fftw3 may not be supported by cufftw.


Solution

  • As talonmies pointed out, the fftw_plan_guru_dft only has partial support in the cufftw library. The above example will run if you instead make use of the basic level fftw_plan_dft. More concretely

    #define real Re
    #define imag Im
    
    #include <complex>
    
    #undef real
    #undef imag
    
    #include <cufftw.h>
    
    #include <stdio.h>
    
    int main(void) {
        int _transform_sizes_index = 1, _loop_sizes_index = 0;
        int _transform_sizes[1] = {128};
    
        fftw_complex _data_in[128] = {0.};
    
        static fftw_plan _fftw_forward_plan = NULL;
        _fftw_forward_plan = fftw_plan_dft(
              _transform_sizes_index, _transform_sizes,
              reinterpret_cast<fftw_complex*>(_data_in),
              reinterpret_cast<fftw_complex*>(_data_in),
              FFTW_FORWARD, FFTW_PATIENT);
        if (!_fftw_forward_plan)
           printf("Error: Unable to create forward plan\n");
    
        return 0;
    }