对应多个cuda版本的PytorchGPU版本共存

参考链接:
1.win10 pytorch安装(cuda + cudnn、anaconda、pytorch
2.Win10安装CUDA10和cuDNN
3.win10下pytorch-gpu安装以及CUDA详细安装过程
4.TensorFlow-gpu安装(100%成功)

cmd下检查cuda安装:

Microsoft Windows [版本 10.0.18363.1139]
(c) 2019 Microsoft Corporation。保留所有权利。

C:\Users\chenxuqi>nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Sep__1_21:08:32_Central_Daylight_Time_2017
Cuda compilation tools, release 9.0, V9.0.176

C:\Users\chenxuqi>

在这里插入图片描述

在这里插入图片描述
测试代码:

import time
import torch 

print(torch.__version__)
print(torch.cuda.is_available())

##################################################
print('----'*10)
for i in range(1,10):
    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)

在这里插入图片描述

版权所有 (C) Microsoft Corporation。保留所有权利。

尝试新的跨平台 PowerShell https://aka.ms/pscore6

PS C:\Users\chenxuqi\Desktop\新建文件夹>  & 'D:\Anaconda3\envs\pytorch_1.5.1_cu101\python.exe' 'c:\Users\chenxuqi\.vscode\extensions\ms-python.python-2020.10.332292344\pythonFiles\lib\python\debugpy\launcher' '50169' '--' 'c:\Users\chenxuqi\Desktop\新建文件夹\testGPU.py'       
1.5.1+cu101
----------------------------------------
3.116953134536743
0.5529775619506836
PS C:\Users\chenxuqi\Desktop\新建文件夹> conda activate pytorch_1.5.1_cu101
PS C:\Users\chenxuqi\Desktop\新建文件夹>  cd 'c:\Users\chenxuqi\Desktop\新建文件夹'; & 'D:\Anaconda3\envs\pytorch_1.5.1_cu102\python.exe' 'c:\Users\chenxuqi\.vscode\extensions\ms-python.python-2020.10.332292344\pythonFiles\lib\python\debugpy\launcher' '50184' '--' 'c:\Users\che1.5.1
True
----------------------------------------
3.254598617553711
0.5271706581115723
0.9557905197143555
PS C:\Users\chenxuqi\Desktop\新建文件夹>  cd 'c:\Users\chenxuqi\Desktop\新建文件夹'; & 'D:\Anaconda3\envs\pytorch_1.6.0_cu102\python.exe' 'c:\Users\chenxuqi\.vscode\extensions\ms-python.python-2020.10.332292344\pythonFiles\lib\python\debugpy\launcher' '50196' '--' 'c:\Users\chenxuqi\Desktop\新建文件夹\testGPU.py'
1.6.0
True
----------------------------------------
3.835683822631836
0.5949108600616455
PS C:\Users\chenxuqi\Desktop\新建文件夹>  cd 'c:\Users\chenxuqi\Desktop\新建文件夹'; & 'D:\Anaconda3\envs\pytorch_1.6.0_cu101\python.exe' 'c:\Users\chenxuqi\.vscode\extensions\ms-python.python-2020.10.332292344\pythonFiles\lib\python\debugpy\launcher' '50205' '--' 'c:\Users\chenxuqi\Desktop\新建文件夹\testGPU.py'
1.6.0+cu101
True
0.9557905197143555
PS C:\Users\chenxuqi\Desktop\新建文件夹>  cd 'c:\Users\chenxuqi\Desktop\新建文件夹'; & 'D:\Anaconda3\envs\pytorch_1.6.0_cu102\python.exe' 'c:\Users\chenxuqi\.vscode\extensions\ms-python.python-2020.10.332292344\pythonFiles\lib\python\debugpy\launcher' '50196' '--' 'c:\Users\chenxuqi\Desktop\新建文件夹\testGPU.py'
1.6.0
True
----------------------------------------
3.835683822631836
0.5949108600616455
PS C:\Users\chenxuqi\Desktop\新建文件夹>  cd 'c:\Users\chenxuqi\Desktop\新建文件夹'; & 'D:\Anaconda3\envs\pytorch_1.6.0_cu101\python.exe' 'c:\Users\chenxuqi\.vscode\extensions\ms-python.python-2020.10.332292344\pythonFiles\lib\python\debugpy\launcher' '50205' '--' 'c:\Users\chenxuqi\Desktop\新建文件夹\testGPU.py'
1.6.0+cu101
True
----------------------------------------
3.68234920501709
0.5653483867645264
0.9160294532775879
PS C:\Users\chenxuqi\Desktop\新建文件夹>  cd 'c:\Users\chenxuqi\Desktop\新建文件夹'; & 'D:\Anaconda3\envs\pytorch_1.5.1_cu92\python.exe' 'c:\Users\chenxuqi\.vscode\extensions\ms-python.python-2020.10.332292344\pythonFiles\lib\python\debugpy\launcher' '50217' '--' 'c:\Users\chenxuqi\Desktop\新建文件夹\testGPU.py'
1.5.1+cu92
True
----------------------------------------
3.1128926277160645
0.5216362476348877
PS C:\Users\chenxuqi\Desktop\新建文件夹>

注意:安装多个不同cuda版本的PyTorch需要更新显卡驱动
如果显卡驱动版本过低则会导致错误如下:

AssertionError: 
The NVIDIA driver on your system is too old (found version 9000).
Please update your GPU driver by downloading and installing a new
version from the URL: http://www.nvidia.com/Download/index.aspx
Alternatively, go to: https://pytorch.org to install
a PyTorch version that has been compiled with your version
of the CUDA driver.

因此需要去更新显卡驱动,笔者笔记本上显卡驱动版本是456.71,其发布日期是10/20/2020.
在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值