在python解释器中运行下面两句会打印出当前可用的设备,包括CPU&GPU。
from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())
结果
[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 10595931102430515727
, name: "/device:GPU:0"
device_type: "GPU"
memory_limit: 3187500646
locality {
bus_id: 1
links {
}
}
incarnation: 17411412352072525648
可见我的电脑上可用的设备有两个,一个是CPU,一个是GPU,但是我的电脑上的GPU有两个,如下图所示:
但是打印出来的却是GPU:0,需要注意的是,这个GPU:0指的是英伟达的显卡,也就是电脑上的GPU 1。