错误信息输出代码
cudaError_t cudaStatus = cudaMemcpy(GpuData.G_Gra, CPU_Data, sizeof(float), cudaMemcpyHostToDevice);
if (cudaStatus != cudaSuccess)
{
printf("CUDA Error:\n");
printf("File:%s Line:%d\n", __FILE__, __LINE__);
printf("Error code: %d Error text: %s\n", cudaStatus, cudaGetErrorString(cudaStatus));
}
Error code: 2 Error text: out of memory
(1)GPU显存不足; (2)显卡被其他程序占用,可用显存变小;
Error code: 77 Error text: an illegal memory access was encountered
(1)大概率发生内存践踏,报错位置并不是问题所在。我是在cudamalloc了结构体内存后,在设备上malloc结构体内部指针内存时,堆内存容量不足了,未开辟内存成功,导致后续cudamemcpy时发生内存践踏,导致程序报错。