float* src;
cudaError_t err = cudaMalloc((void**)&src, totalsize*sizeof(float));
// totalsize 是 512*512*354
// 这里总是分配不成功,err = cudaErrorMemoryAllocation,是太大了么
查了下API,确实是这个原因
cudaErrorMemoryAllocation = 2 The API call failed because it was
unable to allocate enough memory to perform the requested operation.Read more at:
http://docs.nvidia.com/cuda/cuda-runtime-api/index.html#ixzz3ullrrFke
Follow us: @GPUComputing on Twitter | NVIDIA on Facebook
如果数据过大,是一个三维的数据,有什么办法可以解决么
当然,可分配的空间受显存的限制,具体来说应该是受全局内存的大小限制。如果是三维的数据建议使用
cudaMalloc3D()。对于数据过大以致于无法分配的问题,我觉得除了换一个好点的显卡之外很难解决。当然,如果楼主找到了其他好的解决方案,希望可以在这里分享。