c++ - nsight eclipse 中的 CUFFT_ALLOC_FAILED 错误

标签 c++ eclipse cuda gpu

我写了一个简单的 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 个元素 < 1.28 亿个元素

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

请帮帮我

谢谢

最佳答案

您可以使用 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();

} 

关于c++ - nsight eclipse 中的 CUFFT_ALLOC_FAILED 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20870672/

相关文章:

cuda - NVIDIA Visual Profiler 可以显示并发内核执行情况吗?

c++ - FLAC.框架错误

c++ - 如何将关键点复制到另一个 vector

c++ - 嵌套类的不完整类型

java - Eclipse CoreException 位置

c++ - 如何在 Cuda 中从 2D 实数到复数 FFT 获取所有数据

c++ - QSerialPort readLine() 与 readAll() 相比非常慢

android - 无法解析 'adb version' 的输出?

eclipse - R CMD 安装后,R 帮助在 Eclipse 中未更新

python - 解释 3D 数组在内存中的间距、宽度、高度、深度