torch验证是否在使用GPU

import torch
a = torch.cuda.is_available()
print(a)

ngpu= 1
# Decide which device we want to run on
device = torch.device("cuda:0" if (torch.cuda.is_available() and ngpu > 0) else "cpu")
print(device)
print(torch.cuda.get_device_name(0))
print(torch.rand(3,3).cuda()) 


猜你喜欢

转载自blog.csdn.net/qq_40199232/article/details/108684448
今日推荐