【问题标题】:CUFFT_ALLOC_FAILED Error in nsight eclipsensight eclipse 中的 CUFFT_ALLOC_FAILED 错误
【发布时间】:2014-01-06 19:53:22
【问题描述】:

我写了一个简单的 cuda 文件,在 Visual Studio 2010 和 nsight eclipse 中成功构建

代码在这里

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>

#include <cufft.h>
#include <cutil_inline.h>

typedef float2 Complex; 

int main(int argc, char** argv) 
{
     const int NX = 1024;

 const int BATCH = 90000;

     const int SIGNAL_SIZE = NX * BATCH;

     Complex* h_signal = (Complex*)malloc(sizeof(Complex) * SIGNAL_SIZE);

     for (unsigned int i = 0; i < SIGNAL_SIZE; ++i) {
    h_signal[i].x = rand() / (float)RAND_MAX;
    h_signal[i].y = 0;
}

Complex* d_signal;
cutilSafeCall(cudaMalloc((void**)&d_signal, sizeof(Complex)*SIGNAL_SIZE));


cutilSafeCall(cudaMemcpy(d_signal, h_signal, sizeof(Complex)*SIGNAL_SIZE,
                          cudaMemcpyHostToDevice));

cufftHandle plan;
cufftSafeCall(cufftPlan1d(&plan, NX, CUFFT_C2C, BATCH));


cufftSafeCall(cufftExecC2C(plan, (cufftComplex *)d_signal, (cufftComplex *)d_signal,   CUFFT_FORWARD));

cutilSafeCall(cudaMemcpy(h_signal, d_signal, SIGNAL_SIZE*sizeof(Complex),
                          cudaMemcpyDeviceToHost));

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

// cleanup memory
free(h_signal);
cutilSafeCall(cudaFree(d_signal));

cudaThreadExit();

 cutilExit(argc, argv);
}

例如,我将 NX 和 BATCH 更改了四次

const int NX = 1024;

const int BATCH = 90000;

const int SIGNAL_SIZE = NX * BATCH;

cufftHandle plan;
cufftPlan1d(&plan, NX, CUFFT_C2C, BATCH);

我在 Visual Studio 2010 和 2012(Windows 7 64 位)但在 ubuntu 中成功运行了 Sample 12.04(32位)nsight eclipse给出这个错误

CUFFT_ALLOC_FAILED

用于 cufftPlan1d 功能

我将 BATCH 更改为 80000 (NX = 1024) & 这个错误发生在 ubuntu 但在 Visual Studio 2010 中,我运行时没有任何错误!

我使用具有此功能的 Cuda 工具包 5.5:

以单精度转换多达 1.28 亿个元素的大小

和 80000 * 1024 = 81920000 个元素

我将 BATCH 更改为 8000 (NX = 1024),并且在 ubuntu 中没有发生该错误

请帮帮我

谢谢

【问题讨论】:

  • 错误发生的时间和地点?
  • 请注意,cudaThreadExit() 已被弃用,取而代之的是 cudaDeviceReset(),请参阅 this document
  • 我有一个具有 2 GB RAM 的 GTX 650 Ti boost。当我设置 Nx = 1024 和 Batch = 90000 nsight eclipse 有一个 CUFFT_ALLOC_FAILED 错误但在 Visual Studio 中,我运行它没有任何错误!

标签: c++ eclipse cuda gpu


【解决方案1】:

您可以使用cufftEstimate1d 估算您的 cuFFT 调用所需的内存量。

#include <conio.h>

#include <cufft.h>

#define cufftSafeCall(err)      __cufftSafeCall(err, __FILE__, __LINE__)
inline void __cufftSafeCall(cufftResult err, const char *file, const int line)
{
    if( CUFFT_SUCCESS != err) {
    fprintf(stderr, "cufftSafeCall() CUFFT error in file <%s>, line %i.\n",
        file, line);
    getch(); exit(-1);
    }
}


int main() {

    const int NX = 1024;

    const int BATCH = 100000;

    size_t workSize;

    cufftSafeCall(cufftEstimate1d(NX, CUFFT_C2C, BATCH, &workSize));

    printf("%i\n",workSize);

    getchar();

} 

【讨论】:

    【解决方案2】:

    CUFFT 文档:http://docs.nvidia.com/cuda/cufft/#function-cufftplan1d

    CUFFT_ALLOC_FAILED : The allocation of GPU resources for the plan failed.

    意思是cufftPlan1d() 无法在 GPU 上分配内存,可能是因为没有足够的可用内存。可用的 VRAM 在操作系统之间不会发生变化,因此要么您没有适合您的卡的驱动程序,要么您在具有有限 VRAM 的 GPU 的单独机器上运行 Ubuntu。你可以通过cudaGetDeviceProperties()查看可用的全局内存

    【讨论】:

    • 我用的是同一台机器。我认为驱动程序没有问题,因为所有 cuda 示例都成功构建并运行!
    • 我认为 32 位和 64 位的 gpu 分配不同,这是真的吗?
    猜你喜欢
    • 2014-12-12
    • 2012-08-24
    • 2012-08-07
    • 2013-08-11
    • 2012-11-05
    • 2015-01-30
    • 2012-11-27
    • 2013-12-15
    相关资源
    最近更新 更多