Pytorch – 检测CUDA、cuDNN以及GPU版本的Pytorch是否安装成功、GPU显存测试
本文作者:StubbornHuang
版权声明:本文为站长原创文章,如果转载请注明原文链接!
原文标题:Pytorch – 检测CUDA、cuDNN以及GPU版本的Pytorch是否安装成功、GPU显存测试
原文链接:https://www.stubbornhuang.com/1500/
发布于:2021年08月06日 10:33:26
修改于:2021年08月06日 10:33:26

1 测试代码
import time
import torch
if __name__ == '__main__':
print('torch版本:'+torch.__version__)
print('cuda是否可用:'+str(torch.cuda.is_available()))
print('cuda版本:'+str(torch.version.cuda))
print('cuda数量:'+str(torch.cuda.device_count()))
print('GPU名称:'+str(torch.cuda.get_device_name()))
print('当前设备索引:'+str(torch.cuda.current_device()))
device = torch.device("cuda:0" if (torch.cuda.is_available()) else "cpu")
print(device)
print(torch.rand(3, 3).cuda())
for i in range(1,100000):
start = time.time()
a = torch.FloatTensor(i*100,1000,1000)
a = a.cuda() #a = a
a = torch.matmul(a,a)
end = time.time() - start
print(end)
结果:
torch版本:1.7.1
cuda是否可用:True
cuda版本:11.0
cuda数量:1
GPU名称:NVIDIA GeForce RTX 3090
当前设备索引:0
cuda:0
tensor([[0.3954, 0.7494, 0.8901],
[0.6576, 0.1618, 0.6446],
[0.1332, 0.2121, 0.8951]], device='cuda:0')
如果显示cuda可用,并且pytorch tensor可正常放到cuda上面去计算,那么就表明整个pytorch+cuda环境搭建成功,后面的for循环主要是为了测试GPU的显存是否能正常被pytorch调用。
当前分类随机文章推荐
- Pytorch - RuntimeError: No rendezvous handler for env://错误 阅读822次,点赞0次
- Pytorch - 创建随机Tensor的常用方法 阅读143次,点赞0次
- Pytorch - torch.topk参数详解与使用 阅读161次,点赞0次
- Pytorch – 使用torch.matmul()替换torch.einsum('bhxyd,md->bhxym',(a,b))算子模式 阅读933次,点赞0次
- Pytorch - 内置的CTC损失函数torch.nn.CTCLoss参数详解与使用示例 阅读990次,点赞1次
- Pytorch - torch.nn.Module的parameters()和named_parameters() 阅读455次,点赞0次
- Pytorch - torch.stack参数详解与使用 阅读577次,点赞0次
- Pytorch - torch.cat函数 阅读196次,点赞0次
- Pytorch - 使用Pyav解码视频文件并将视频帧转换为Pytorch tensor作为网络模型输入数据 阅读3692次,点赞0次
- Pytorch - 内置的LSTM网络torch.nn.LSTM参数详解与使用示例 阅读1523次,点赞0次
全站随机文章推荐
- 资源分享 - Speech and Language Processing - An Introduction to Natural Language Processing, Computational Linguistics, and Speech Recognition , Third Edition draft 英文高清PDF下载 阅读512次,点赞0次
- 深度学习 - 经典的卷积神经网络(CNN)模型结构 阅读407次,点赞0次
- Python - 安装onnxruntime-gpu出现ERROR: Could not install packages due to an OSError: [Errno 2] No such file or directory: '...\\numpy-1.23.1.dist-info\\METADATA' 阅读263次,点赞0次
- 资源分享 - Computational Geometry - Algorithms and Applications, First Edition 英文高清PDF下载 阅读1607次,点赞0次
- WordPress - 修改WP Editor.md markdown编辑器插件从剪切板粘贴图片上传的清晰度和质量 阅读934次,点赞0次
- ThreeJS - FBXLoader: TGA loader not found, creating placeholder texture for ... 阅读507次,点赞0次
- OpenCV - 静态图片人脸检测和摄像头人脸检测 阅读3003次,点赞0次
- 资源分享 - AI Game Programming Wisdom 4 英文高清PDF下载 阅读1238次,点赞0次
- Pytorch - 创建随机Tensor的常用方法 阅读143次,点赞0次
- CUDA 安装报错 could not create file "...\chrome_elf.dll" 阅读1643次,点赞0次
评论
168