PGI with OpenACC and cuFFT in c++

I’m trying PGI to do FFT with cuFFT, but there’s an error message :
Segmentation fault (core dumped)

Here is my code:

#include <cufft.h>

// Declared extern "C" to disable C++ name mangling
extern "C" void for_CUFFT(float *d_data, int n, void *stream)
{
    cufftHandle plan;
    cufftPlan1d(&plan, n, CUFFT_C2C, 1);
    cufftSetStream(plan, (cudaStream_t)stream);
    cufftExecC2C(plan, (cufftComplex*)d_data,   (cufftComplex*)d_data,CUFFT_FORWARD);
    cufftDestroy(plan);
}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "openacc.h"

// Forward declaration of wrapper function that will call CUFFT
extern void for_CUFFT(float *d_data, int n, void *stream);

int main(int argc, char *argv[])
{
    int n = 256;
    float *data = (float* )malloc(2*n*sizeof(float));
    int i;

    // Initialize interleaved input data on host
    for(i=0; i<2*n; i+=2)  {
        data[i] = i/2.0;
        data[i+1] = 0.0;
    }

    // Copy data to device at start of region and back to host and end of region
    #pragma acc data copy(data[0:2*n])
    {
        // Inside this region the device data pointer will be used
        #pragma acc host_data use_device(data)
        {
           void *stream = acc_get_cuda_stream(acc_async_sync);
           for_CUFFT(data, n, stream);
        }
    }

    for(i=0; i<n; i+=2) {
        printf("data[%d] = %f  \n", i, data[i]);
    }

    return 0;
}

And my compiler command :
pgc++ -acc -ta=nvidia -Minfo -Mcudalib=cufft filename.cpp

I have stocked a week, do any one knows how to fix it?

Hi Yan-Chi,

For good or bad, I’m not able to recreate this error. I’ve tried several different systems and compiler versions, but the code runs fine for me.

What device, compiler version, and OS are you using? Also, can you post an example of the error?

  • Mat
% pgc++ -acc -ta=nvidia -Minfo -Mcudalib=cufft cufft_11_30_15.cpp -V15.10
main:
     35, Generating copy(data[:n*2])
% a.out
data[0] = 32640.000000
data[2] = -127.999992
data[4] = -127.999908
data[6] = -128.000000
data[8] = -128.000000
data[10] = -127.999969
data[12] = -128.000031
data[14] = -128.000320
data[16] = -128.000000
data[18] = -127.999718
data[20] = -127.999985
data[22] = -128.000031
data[24] = -128.000000
data[26] = -128.000000
data[28] = -128.000031
data[30] = -127.999969
data[32] = -128.000000
data[34] = -127.999939
data[36] = -127.999962
data[38] = -128.000000
... cut ...
data[246] = -128.000000
data[248] = -128.000031
data[250] = -128.000000
data[252] = -128.000000
data[254] = -127.999992

Hi Mat,

Sorry, my bad.
My nvidia driver was broken at that moment.
Reboot it and compile it succeed.
Thanks for your reply.
It makes me trying the orther problems and find the way.