pytorch测试GPU是否安装成功

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

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_32146369/article/details/106574354
今日推荐