当我使用包含大量循环的for循环时,将发生错误"非特定启动失败" 我的代码如下:
//Kernel function
__global__ void Kernel(double *M_gpu, int size)
{
for (int i = 0; i < size; i++)
{
M_gpu[i] = i / 2 + 6;
}
}
int main()
{
cudaError_t cudaStatus;
//Allocating CPU space
int size = 10000000;
double *M = (double *)malloc(sizeof(double)*size);
//Allocating GPU space
double *M_gpu;
cudaStatus = cudaMalloc((void**)&M_gpu, sizeof(double)*size);
if (cudaStatus != cudaSuccess)
{
cout << "Allocating CPU space failed!" << cudaGetErrorString(cudaStatus) << endl; getchar(); exit(0);
}
//calling Kernel function
Kernel << <1, 1 >> > (M_gpu, size);
cudaDeviceSynchronize();
cudaStatus = cudaGetLastError();
if (cudaStatus != cudaSuccess)
{
cout << "Calling Kernel function failed!" << cudaGetErrorString(cudaStatus) << endl; getchar(); exit(0);
}
//copying data from GPU to CPU
cudaStatus = cudaMemcpy(M, M_gpu, sizeof(double)*size, cudaMemcpyDeviceToHost);
if (cudaStatus != cudaSuccess)
{
cout << "Copying data from GPU to CPU failed!" << cudaGetErrorString(cudaStatus) << endl; getchar(); exit(0);
}
//END
cout << "Success!" << endl;
getchar();
}
我的操作系统是Win10 64bit,我的GPU是GTX860M,内存为4GB,我的CUDA版本是8.0。我使用Visual Studio 2015社区。 我知道做这样的事并不好,因为它表现不好。但我只想知道上面的代码有什么问题,逻辑似乎很好,可以确定没有发生内存分配错误。内核函数有一些限制吗?