torch_test.py
import torch
print("torch_version:",torch.__version__)
print("cuda_version:",torch.version.cuda)
print("cudnn_version:",torch.backends.cudnn.version())
print("----------------------------------")
flag = torch.cuda.is_available()
print(flag)
# 查看显卡个数
print("device_count:",torch.cuda.device_count())
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("device_name:",torch.cuda.get_device_name(0))
print(torch.rand(3,3).cuda())
正确输出为:
错误情况:
(1)cuda版本和nvcc -V的版本不同
(2)输出False
(3)tensor无法计算,一直没有结果显示
问题解决:
1>可能是下载的torch版本不对,下载和cuda版本对应的torch(系统cuda为10.0,但是torch可能是cuda9.0编译的,要看清)(cuda_version并不是目前使用的cuda版本,而是torch适配的cuda版本)
2>各种可能问题,建议百度
3>可能是30系显卡使用小于cuda11.1的cuda版本,不适配,无法计算tensor(30系显卡只能用cuda11.1或更高版本)