【发布时间】: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 中,我运行它没有任何错误!