任何Cuda函数调用都返回cudaErrorMemoryAllocation

任何Cuda函数调用都返回cudaErrorMemoryAllocation,cuda,out-of-memory,runtime-error,Cuda,Out Of Memory,Runtime Error,我想知道为什么我在互联网上找到的所有简单的Cuda代码示例都不适用于我,我发现即使是最简单的代码也会导致错误: #include <stdio.h> int main(int argc, char ** argv) { size_t available, total; cudaError_t err = cudaMemGetInfo(&available, &total); if (err == cudaErrorMemoryAllocati

我想知道为什么我在互联网上找到的所有简单的Cuda代码示例都不适用于我,我发现即使是最简单的代码也会导致错误:

#include <stdio.h>

int main(int argc, char ** argv) {
    size_t available, total;
    cudaError_t err = cudaMemGetInfo(&available, &total);
    if (err == cudaErrorMemoryAllocation) {
        printf("cudaErrorMemoryAllocation");
    } else {
        printf("OK or not memory allocation error");
    }
    return 0;
}
平台Windows 8 64位

编译器Visual Studio 2008

计算能力1.1(GeForce 8800 GT)


CUDA版本5.5

创建CUDA上下文时,分配的内存可能不足以初始化。这可能解释了您得到的cudaerrormoryallocation错误

cudaMemGetInfo不会抛出该特定错误,因此它一定是其他错误:

请注意,此函数还可能返回以前的错误代码, 异步启动

堆栈跟踪中的cuD3D11CtxCreate也会创建一个CUDA上下文,因此可能就是它


另外:如果您有多个应用程序运行时与您的设备发生冲突,这可能也是原因。

问题已解决。我仍然不确定是什么原因导致了这一点,要么是旧的显卡驱动程序与Cuda安装程序中隐藏在“推荐”选项下安装的新显卡驱动程序之间存在冲突,要么是VS 2008的歪装。但是,我决定重新安装所有程序,并尝试使用VS 2012而不是VS 2008,现在一切正常。

我认为512 MB应该足以初始化Cuda环境,没有其他运行的程序会消耗整个内存。在此之前,您是否尝试过重置设备?我刚才试过了。cudaDeviceReset()返回cudaSuccess,但对程序的其余部分没有更改您是否能够正确运行CUDA SDK示例,特别是deviceQuery示例?是的,我能够运行deviceQuery,它会正确打印我的8800 GT的配置。但是,我尝试启动的其他一些示例失败,出现了“CUDA错误代码=2(cudaErrorMemoryAllocation)”,我希望我没有让您误入歧途,但我会调查可能的驱动程序问题。您的卡是否使用了正确的驱动程序?重新安装驱动程序怎么样?我的卡有更新,所以我已经安装了。不幸的是,它没有解决问题。您是否尝试过简单的系统重启?它解决了这类问题,而且,。
cudaErrorMemoryAllocation
========= CUDA-MEMCHECK
========= Program hit error 2 on CUDA API call to cudaMemGetInfo 
=========     Saved host backtrace up to driver entry point at error
=========     Host Frame:C:\Windows\SYSTEM32\nvcuda.dll (cuD3D11CtxCreate + 0x118a92) [0x137572]
=========     Host Frame:D:\Cuda\a.exe [0x1223]
=========     Host Frame:D:\Cuda\a.exe [0x101c]
=========     Host Frame:D:\Cuda\a.exe [0x901f]
=========     Host Frame:C:\Windows\system32\KERNEL32.DLL (BaseThreadInitThunk + 0x1a) [0x1832]
=========     Host Frame:C:\Windows\SYSTEM32\ntdll.dll (RtlUserThreadStart + 0x21) [0x5d609]
=========
========= ERROR SUMMARY: 1 error