【问题标题】:Cufft error in file文件中的袖带错误
【发布时间】:2014-03-25 22:04:48
【问题描述】:

我收到错误消息:

文件中的袖带错误

我正在使用这个文件来加载 FFT 并将它们传递给另一个文件。

//----function to check for errors-------------------------------------------------
#define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); }
inline void gpuAssert(cudaError_t code, char *file, int line, bool abort=true)
{
   if (code != cudaSuccess) 
   {
      fprintf(stderr,"\nGPUassert: %s %s %d\n", cudaGetErrorString(code), file, line);
      if (abort) exit(code);
   }
}
//function to check for cuFFT errors --------------------------------------------------
#define CUFFT_SAFE_CALL( call) do { \
cufftResult err = call; \
if (err != CUFFT_SUCCESS) { \
fprintf(stderr, "Cufft error in file '%s' in line %i : %s.\n", \
__FILE__, __LINE__, "error" ); \
exit(EXIT_FAILURE); \
} \
} while (0)



#define NX 128*128      
#define NY 16       
#define BATCH 16    
#define NRANK 2     



void FFT_transform(cufftDoubleComplex** B_in)
{
    int n[NRANK] = {NX, NY};

    //size of B
    int Bsize=NX*NY*BATCH;

    //allocate host memory 
    *B_in=(cufftDoubleComplex*)malloc(Bsize*sizeof(cufftDoubleComplex));

    for (int i=0;i<NX*NY;i++){
        for (int j=0;j<BATCH;j++){
            (*B_in)[i*BATCH+j].x=(i*BATCH+j)*2;
            (*B_in)[i*BATCH+j].y=(i*BATCH+j)*2+1;

        }
    }

    //allocate device memory
    cufftDoubleComplex* B_dev;
    gpuErrchk(cudaMalloc((void**) &B_dev,Bsize* sizeof(cufftDoubleComplex)));

    if (cudaGetLastError() != cudaSuccess){
        fprintf(stderr, "Cuda error: Failed to allocate\n");
        return; 
    }

    // copy arrays from host to device
    gpuErrchk(cudaMemcpy(B_dev, *B_in,Bsize* sizeof(cufftDoubleComplex), cudaMemcpyHostToDevice));


    // Create a 2D FFT plan
    cufftHandle plan;
        CUFFT_SAFE_CALL(cufftPlan2d(&plan,NX,NY,CUFFT_Z2Z));

    if (cufftPlanMany(&plan, NRANK, n,NULL, 1, 0,NULL, 1, 0,CUFFT_Z2Z,BATCH) != CUFFT_SUCCESS){
        fprintf(stderr, "CUFFT Error: Unable to create plan\n");
        return; 
    }

    if (cufftSetCompatibilityMode(plan, CUFFT_COMPATIBILITY_NATIVE)!= CUFFT_SUCCESS){
        fprintf(stderr, "CUFFT Error: Unable to set compatibility mode to native\n");
        return;     
    }


    // perform transform
    CUFFT_SAFE_CALL(cufftExecZ2Z(plan,(cufftDoubleComplex *)(*B_in), (cufftDoubleComplex *)B_dev, CUFFT_FORWARD));

    if (cufftExecZ2Z(plan,*B_in,B_dev,CUFFT_FORWARD) != CUFFT_SUCCESS){
        fprintf(stderr, "CUFFT Error: Unable to execute plan\n");
        return;     
    }

    if (cudaThreadSynchronize() != cudaSuccess){
        fprintf(stderr, "Cuda error: Failed to synchronize\n");
        return;
    }

        // copy result from device to host
        gpuErrchk(cudaMemcpy(*B_in, B_dev,Bsize*sizeof(cufftDoubleComplex), cudaMemcpyDeviceToHost));




    //Destroy CUFFT context
    CUFFT_SAFE_CALL(cufftDestroy(plan));

        //clean up device memory
        gpuErrchk(cudaFree(B_dev));


}

我在以下行收到错误:

CUFFT_SAFE_CALL(cufftExecZ2Z(plan,(cufftDoubleComplex *)(*B_in), (cufftDoubleComplex *)B_dev, CUFFT_FORWARD));

【问题讨论】:

    标签: cuda fft cufft


    【解决方案1】:

    您收到错误是因为B_in 是指向主机内存而不是指向设备内存的指针,这是非法的。在 CUFFT 中,输入总是在设备内存中。您需要使用cudaMemcpyB_in 的内容传输到B_dev执行转换之前,然后提供B_dev 作为输入和输出,这将导致地方变换。这在 CUFFT API 文档here 中有明确描述。

    【讨论】:

    • :我正在从 B-in 转移到 B_dev。我错过了具有相同输入和输出的东西。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-21
    • 2016-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多