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())
# True
# cuda:0
# GeForce GTX 1060
# tensor([[0.5772, 0.5287, 0.0946],
# [0.9525, 0.7855, 0.1391],
# [0.6858, 0.5143, 0.8188]], device='cuda:0')
————————————————
版權聲明:本文爲CSDN博主「明月幾時有.」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/weixin_35576881/article/details/89709116