0

I am trying to perform a 1D FFT of a 2D array in the row dimension using the cufft MakePlanMany() function. Unfortunately when I make the call to cufftMakePlanMany it is causing a segmentation fault. I am new to C programming and CUDA so I could be making a dumb mistake. I am trying to follow the code example in this StackOverflow answer. My data (phd) is stored in row-major contiguous memory. Below is my code:

void bpGPU (float *phd, float *complex_image, int Nfft, int NumSamples){
   cufftHandle plan;
   cufftComplex *d_in, *d_out;
   int ds = sizeof(cufftComplex);
   ds = Nfft * NumSamples;
   cuMemAlloc((void**)&d_in, ds);
   cuMemAlloc((void**)&d_out, ds);
   int rank=1;
   int n = { Nfft };
   int inembed[] = {0};
   int onembed[] = {0};
   int istride = 1, ostride = 1;
   int idist = NumSamples, odist = NumSamples;
   int batch = Nfft * NumSamples;
   cufftPlanMany(&plan, rank, n, inembed, istride, idist, onembed, ostride, odist, CUFFT_C2C, batch);
   ...
}

I placed print statements before and after the cufftPlanMany so I know that is where the segmentation fault is occurring. Any help will be appreciated.

DLH
  • 199
  • 11
  • 1
    This doesn't look right: `int n = { Nfft };` You are supposed to provide a [mcve]. I believe the compiler should be warning or actually throwing an error about that, where you have used it in the call to `cufftPlanMany`. There are several other typos and omissions in the code you have shown, so I'm not really sure that is the issue. – Robert Crovella Jun 27 '18 at 22:16
  • @RobertCrovella: That statement was the problem now it is working. Thanks for pointing that out I feel stupid now. My inexperience with C is really showing. – DLH Jun 27 '18 at 22:21
  • when I try to compile that combination with `cufftPlanMany` the compiler throws an error and won't compile the code. Not sure what compiler you are using, or why it allows you to pass a bare integer as an integer pointer to a function expecting an integer pointer parameter. Something doesn't add up about what you have presented. Do you not even get a warning about the use of `n` in the call to `cufftPlanMany` ? – Robert Crovella Jun 27 '18 at 22:34
  • @RobertCrovella: I am using the gcc compiler. It had actually produced a warning message but it got lost in the many other warnings that I am getting. gcc seems to be fairly forgiving which is probably not a good thing for a beginner like me. – DLH Jun 27 '18 at 22:39

1 Answers1

1

The value n should be an array and I didn't declare it as such. Instead I set n equal to the size of the FFT which of course is not a valid pointer. CufftPlanMany tried to access the invalid pointer and returned a segmentation fault.

DLH
  • 199
  • 11