Pytorch – 检测CUDA、cuDNN以及GPU版本的Pytorch是否安装成功、GPU显存测试
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调用。
本文作者:StubbornHuang
版权声明:本文为站长原创文章,如果转载请注明原文链接!
原文标题:Pytorch – 检测CUDA、cuDNN以及GPU版本的Pytorch是否安装成功、GPU显存测试
原文链接:https://www.stubbornhuang.com/1500/
发布于:2021年08月06日 10:33:26
修改于:2023年06月26日 21:23:06
当前分类随机文章推荐
- Pytorch - 模型微调时删除原有模型中的某一层的方法 阅读3223次,点赞0次
- 深度学习 - 我的深度学习项目代码文件组织结构 阅读1830次,点赞3次
- Pytorch - torch.nn.Conv2d参数详解与使用 阅读1203次,点赞0次
- Pytorch - 修改Pytoch中torchvision.models预置模型的方法 阅读379次,点赞0次
- Pytorch - Pytoch结合Tensorboard实现数据可视化 阅读439次,点赞0次
- Pytorch - RuntimeError: No rendezvous handler for env://错误 阅读1535次,点赞0次
- Pytorch – 使用torch.matmul()替换torch.einsum(‘nkctv,kvw->nctw’,(a,b))算子模式 阅读1380次,点赞0次
- Pytorch - 没有使用with torch.no_grad()造成测试网络时显存爆炸的问题 阅读812次,点赞0次
- Pytorch - torch.distributed.init_process_group函数详解 阅读999次,点赞0次
- Pytorch - 模型断点续训,optimizer.step()报错:RuntimeError Expected all tensors to be on the same device, but found cuda:0 阅读311次,点赞0次
全站随机文章推荐
- C++ - return this和return *this的含义和区别 阅读652次,点赞0次
- WordPress - get_header函数,加载主题头部header模板 阅读1127次,点赞0次
- UnrealEngine4 - C++层打印信息到屏幕 阅读2830次,点赞0次
- C++ - 在Visual Studio中使用OpenMP加速for循环 阅读501次,点赞0次
- Centos7 - frp内网穿透,访问内网web服务/访问内网websocket服务 阅读3299次,点赞1次
- 资源分享 - 3D数学基础:图形和游戏开发 第2版 , 3D Math Primer for Graphics and Game Development (Second Edition) 中文版 PDF下载 阅读6461次,点赞0次
- 资源分享 - Physically Based Rendering From Theory To Implementation (First Edition)英文高清PDF下载 阅读3327次,点赞0次
- FFmpge - Ubuntu编译FFmpeg出现WARNING: pkg-config not found, library detection may fail警告 阅读6087次,点赞0次
- ThreeJS - 使用Hdr环境贴图作为间接光照对模型进行渲染 阅读2539次,点赞3次
- Python - 获取当前时间字符串 阅读1424次,点赞0次
评论
169