如何验证GPU的使用情况?

时间:2017-01-12 12:45:27

标签: cntk

如何验证CNTK正在使用GPU?我在我的机器上安装了CNTK-2-0-beta7-0-Windows-64bit-GPU-1bit-SGD二进制文件。但是,当我尝试从Python运行它时:

from cntk.device import set_default_device, gpu
set_default_device(gpu(0))

我明白了:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-8-eca77b3090be> in <module>()
      1 from cntk.device import set_default_device, gpu
----> 2 set_default_device(gpu(0))

C:\local\Anaconda3-4.1.1-Windows-x86_64\envs\cntk-py34\lib\site-packages\cntk\device.py in gpu(device_id)
     74         :class:`~cntk.device.DeviceDescriptor`: GPU device descriptor
     75     '''
---> 76     return cntk_py.DeviceDescriptor.gpu_device(device_id)
     77 
     78 def use_default_device():

ValueError: Specified GPU device id (0) is invalid.

立即添加更多信息:

这是运行NVidia_smi.exe

的结果
C:\Program Files\NVIDIA Corporation\NVSMI>nvidia-smi.exe
Thu Jan 12 20:38:30 2017
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 369.61                 Driver Version: 369.61                    |
|-------------------------------+----------------------+----------------------+
| GPU  Name            TCC/WDDM | Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce GPU        WDDM  | 0000:01:00.0     Off |                  N/A |
| N/A   51C    P0     2W /  N/A |    864MiB /  1024MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID  Type  Process name                               Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+

在Jupyter笔记本中重启内核后,我得到:

import cntk as C
if C.device.default().type() == 0:
    print('running on CPU')
else:
    print('running on GPU')

running on CPU

然而今天我能够跑:

from cntk.device import set_default_device, gpu
set_default_device(gpu(0))

import cntk as C
if C.device.default().type() == 0:
    print('running on CPU')
else:
    print('running on GPU')

running on GPU

GPU应该是GPU机器上的默认设置,还是需要明确设置?

1 个答案:

答案 0 :(得分:2)

这听起来像是间歇性的失败。这种情况可能发生在某些笔记本电脑上,例如Surface Book,它有两个GPU,一个来自NVIDIA,另一个是集成的,笔记本电脑关闭了NVIDIA GPU以节省能源,例如:当它用电池运行时。

关于默认行为,默认情况下,CNTK将选择最佳可用设备,如果是GPU,则将其锁定,以便其他进程无法使用它。如果您明确使用set_default_device(gpu(0)),那么GPU将不会被锁定,其他进程可以使用它。