直接上测试代码:
import tensorflow as tf
from tensorflow.python.client import device_lib
gpu_device_name = tf.test.gpu_device_name()
print(gpu_device_name)
print(tf.config.list_physical_devices('GPU'))
# 列出所有的本地机器设备
local_device_protos = device_lib.list_local_devices()
# 打印
# print(local_device_protos)
# 只打印GPU设备
[print(x) for x in local_device_protos if x.device_type == 'GPU']
使用上机环境地址:http://www.codeforest.cn/book/14/detail?preview=1
测试结果如下
/device:GPU:0 [PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')] name: "/device:GPU:0" device_type: "GPU" memory_limit: 14369834944 locality { bus_id: 2 numa_node: 1 links { } } incarnation: 9177932156359785129 physical_device_desc: "device: 0, name: Tesla T4, pci bus id: 0000:da:00.0, compute capability: 7.5"