【发布时间】:2018-06-17 13:44:05
【问题描述】:
我想知道pytorch 是否正在使用我的 GPU。可以使用nvidia-smi 检测在此过程中是否有来自 GPU 的任何活动,但我希望在python 脚本中编写一些内容。
有办法吗?
【问题讨论】:
-
有没有办法获取所有当前可用 gpus 的列表?类似
devices = torch.get_all_devices() # [0, 1, 2] or whatever their name is -
见stackoverflow.com/questions/64776822/…:
[torch.cuda.device(i) for i in range(torch.cuda.device_count())] -
有人告诉我这行得通
list(range(torch.cuda.device_count()))。不过谢谢! -
@CharlieParker,你会想要(假设你有
import torch):devices = [d for d in range(torch.cuda.device_count())]如果你想要名字:device_names = [torch.cuda.get_device_name(d) for d in devices]你可能像我一样,喜欢将这些映射为 dict跨机管理:device_to_name = dict( device_names, devices )
标签: python memory-management gpu nvidia pytorch