Memory 当我知道有足够的内存空间时,为什么Cudamaloc会给我一个错误?

Memory 当我知道有足够的内存空间时,为什么Cudamaloc会给我一个错误?,memory,cuda,Memory,Cuda,我有一个特斯拉C2070,应该有5636554752字节的内存 但是,这给了我一个错误: int *buf_d = NULL; err = cudaMalloc((void **)&buf_d, 1000000000*sizeof(int)); if( err != cudaSuccess) { printf("CUDA error: %s\n", cudaGetErrorString(err)); return EXIT_ERROR; } 这怎么可能?这与最大

我有一个特斯拉C2070,应该有5636554752字节的内存

但是,这给了我一个错误:

int *buf_d = NULL;

err = cudaMalloc((void **)&buf_d, 1000000000*sizeof(int));

if( err != cudaSuccess)
{
     printf("CUDA error: %s\n", cudaGetErrorString(err));
     return EXIT_ERROR;
}
这怎么可能?这与最大内存间距有关吗?以下是GPU的规格:

Device 0: "Tesla C2070" 
CUDA Driver Version:    3.20 
CUDA Runtime Version:   3.20 
CUDA Capability Major/Minor version number: 2.0 
Total amount of global memory:  5636554752 bytes 
Multiprocessors x Cores/MP = Cores: 14 (MP) x 32 (Cores/MP) = 448 (Cores) 
Total amount of constant memory:    65536 bytes Total amount of shared memory per block:    49152 bytes Total number of registers available per block: 32768 Warp size: 32 
Maximum number of threads per block:    1024 
Maximum sizes of each dimension of a block: 1024 x 1024 x 64 
Maximum sizes of each dimension of a grid:  65535 x 65535 x 1
Maximum memory pitch: 2147483647 bytes
至于我运行的机器,它有24个Intel®Xeon®处理器X565,Linux发行版为Rocks 5.4(Maverick)


有什么想法吗?谢谢

基本问题在于你的题目——你实际上并不知道你有足够的记忆力,你只是假设你有足够的记忆力。运行时API包括
cudaMemGetInfo
函数,该函数将返回设备上的可用内存量。在设备上建立上下文时,驱动程序必须为设备代码预留空间,为每个线程预留本地内存,为
printf
支持预留fifo缓冲区,为每个线程预留堆栈,并为内核
malloc
/
新调用预留堆(有关更多详细信息,请参阅)。所有这些都会消耗相当多的内存,使您在ECC保留后的最大可用内存大大低于您假设的代码可用内存。该API还包括
cudaDeviceGetLimit
,可用于查询设备运行时支持消耗的内存量。还有一个附带调用
cudaDeviceSetLimit
,它允许您更改运行时支持的每个组件将保留的内存量

即使您根据自己的喜好调整了运行时内存占用,并从驱动程序获得了实际的可用内存值,仍然需要考虑页面大小粒度和碎片问题。很少有可能将API报告的内容的每个字节都分配为免费的。通常,当目标是尝试分配卡上的每个可用字节时,我会这样做:

const size_t Mb = 1<<20; // Assuming a 1Mb page size here

size_t available, total;
cudaMemGetInfo(&available, &total);

int *buf_d = 0; 
size_t nwords = total / sizeof(int);
size_t words_per_Mb = Mb / sizeof(int);

while(cudaMalloc((void**)&buf_d,  nwords * sizeof(int)) == cudaErrorMemoryAllocation)
{
    nwords -= words_per_Mb;
    if( nwords  < words_per_Mb)
    {
        // signal no free memory
        break;
    }
}

// leaves int buf_d[nwords] on the device or signals no free memory

const size\u t Mb=1您在哪个平台上?您会得到什么错误代码?使用“cudaGetErrorString”打印错误代码总是很有帮助的。你能不能指定你得到的错误字符串,并看看你在什么时候通过减小大小停止得到错误。我在更新中添加了更多信息。错误是“内存不足”,谢谢。我使用
cudaMemGetInfo
获取我的gpu内存信息,2147483648中只有13614248是空闲的,即0.6%,为什么空闲内存这么小?我肯定没有使用任何其他与GPU。。。