能够检验是否成功安装pytorch, cuda, cudnn,并能输出GPU型号
import torch
a = torch.cuda.is_available()
print(a)
ngpu= 1
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())
输出样例:
True
cuda:0
GeForce GTX 1650
tensor([[0.0387, 0.8379, 0.6165],
[0.4231, 0.0060, 0.9049],
[0.7293, 0.1726, 0.9432]], device='cuda:0')