很多时候,我让CUDA库完全失败并返回错误46(“所有支持CUDA的设备都忙或不可用”),即使对于像cudaMalloc这样的简单调用也是如此。如果我重新启动计算机,代码会成功运行,但这远非理想。这个问题显然是quite common。
我的设置如下:
我尝试了很多来自Nvidia论坛的解决方案,但它没有用。我不想每次都重启。我还尝试使用我认为正确的程序卸载并重新加载驱动程序(可能不是)
kextunload -b com.nvidia.CUDA
kextload -b com.nvidia.CUDA
但它仍然不起作用。我怎样才能将GPU(或CUDA)恢复到理智状态?
这是设备查询结果
CUDA Device Query (Runtime API) version (CUDART static linking)
Found 1 CUDA Capable device(s)
Device 0: "GeForce 9400M"
CUDA Driver Version / Runtime Version 4.0 / 4.0
CUDA Capability Major/Minor version number: 1.1
Total amount of global memory: 254 MBytes (265945088 bytes)
( 2) Multiprocessors x ( 8) CUDA Cores/MP: 16 CUDA Cores
GPU Clock Speed: 1.10 GHz
Memory Clock rate: 1075.00 Mhz
Memory Bus Width: 128-bit
Max Texture Dimension Size (x,y,z) 1D=(8192), 2D=(65536,32768), 3D=(2048,2048,2048)
Max Layered Texture Size (dim) x layers 1D=(8192) x 512, 2D=(8192,8192) x 512
Total amount of constant memory: 65536 bytes
Total amount of shared memory per block: 16384 bytes
Total number of registers available per block: 8192
Warp size: 32
Maximum number of threads per block: 512
Maximum sizes of each dimension of a block: 512 x 512 x 64
Maximum sizes of each dimension of a grid: 65535 x 65535 x 1
Maximum memory pitch: 2147483647 bytes
Texture alignment: 256 bytes
Concurrent copy and execution: No with 0 copy engine(s)
Run time limit on kernels: Yes
Integrated GPU sharing Host Memory: Yes
Support host page-locked memory mapping: Yes
Concurrent kernel execution: No
Alignment requirement for Surfaces: Yes
Device has ECC support enabled: No
Device is using TCC driver mode: No
Device supports Unified Addressing (UVA): No
Device PCI Bus ID / PCI location ID: 2 / 0
Compute Mode:
< Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >
deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 4.0, CUDA Runtime Version = 4.0, NumDevs = 1, Device = GeForce 9400M
[deviceQuery] test results...
PASSED
这是可能失败的代码示例(尽管在正常情况下它不会失败)
#include <stdio.h>
__global__ void add(int a, int b, int *c) {
*c = a + b;
}
int main(void) {
int c;
int *dev_c;
cudaMalloc( (void **) &dev_c, sizeof(int)); // fails here, returning 46
add<<<1,1>>>(2,7,dev_c);
cudaMemcpy(&c, dev_c, sizeof(int), cudaMemcpyDeviceToHost);
printf("hello world, %d\n",c);
cudaFree( dev_c);
return 0;
}
我还发现,偶尔我会恢复到没有重启的理智行为。我仍然不知道触发它的原因。
答案 0 :(得分:7)
我确认评论者对我的帖子所作的陈述。如果其他应用程序正在控制它,GPU可能无法工作。就我而言,firefox中的flash播放器显然占用了卡上的所有可用资源。我杀了flash的firefox插件,卡片立即重新开始工作。
答案 1 :(得分:3)
重启计算机对我来说很成功。
答案 2 :(得分:0)
您可以这样做来保存您的一天:
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
对我有用。
答案 3 :(得分:0)
为 ubuntu (Nvidia 450) 更改 Nvidia 驱动程序版本