pytorch查看GPU信息

import torch

torch.cuda.is_available()
#cuda是否可用;

torch.cuda.device_count()
#返回gpu数量;

torch.cuda.get_device_name(0)
#返回gpu名字,设备索引默认从0开始;

torch.cuda.current_device()

tensorflow查看GPU信息:

import tensorflow as tf

from tensorflow.python.client import device_lib

gpu_device_name = tf.test.gpu_device_name()
print(gpu_device_name)



# 列出所有的本地机器设备
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']


 

Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐