文章目录
1. 查看CUDA的版本
CUDA有两个主要API,即运行时API和驱动程序API。两者都有对应的版本。
- 对驱动程序API的必要支持由GPU驱动程序安装程序安装。
- 对运行时API的必要支持是由CUDA工具包安装程序安装的,它也可能有一个GPU驱动程序安装程序捆绑在里面。
在一些情况下,已安装驱动程序API版本可能并不总是与已安装运行时API版本匹配,特别是当你安装一个独立于安装CUDA(即CUDA工具包)的GPU驱动程序时。
1.1 CUDA runtime version
the CUDA compiler-driver tool that is installed with the CUDA toolkit.
nvcc
是与CUDA工具包一起安装的CUDA编译驱动工具,它总是报告CUDA运行时的版本,而CUDA运行时的版本是它构建时要识别的。它不知道安装了什么驱动版本,甚至不知道是否安装了GPU驱动。
- 方式一
命令行输入:nvcc --version
- 方式二
查找安装目录的版本说明,一般安装目录都在C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA
下。
1.2 CUDA driver version
nvidia-smi工具由GPU驱动程序的安装程序安装,并且通常在视图中有GPU驱动程序。
- 方式一
从NVIDIA的控制面板中查看版本信息。
- 方式二
命令行:nvidia-smi
因此,从设计上来说,这两个数字不一定是匹配的,因为它们反映了两种不同的东西。
在大多数情况下,如果nvidia-smi
报告的CUDA版本在数值上等于或高于nvcc -V
查询的CUDA版本,则无需担心。这是CUDA(较新的驱动程序/驱动程序API支持较旧的CUDA工具包/运行时API)中定义的兼容性路径。
例如,如果nvidia-smi报告CUDA 10.2,并nvcc -V报告CUDA 10.1,则通常不必担心。它应该可以正常工作,并不一定意味着您“当您打算安装CUDA 10.1时实际上已经安装了CUDA 10.2”
如果nvcc命令根本不报告任何内容(例如Command 'nvcc' not found...
),则也可能是由于CUDA安装不正确。
2. 安装PyTorch
2.1 去pytorch官网下载指定版本的pytorch
到官网选择安装的环境:【 PyTorch】
根据自己的本机配置(cudatoolkit=9.0
)生成anaconda安装pytorch的命令:
conda install pytorch==1.1.0 torchvision==0.3.0 cudatoolkit=9.0 -c pytorch
2.2 添加清华通道
在conda的配置文件中,添加Pytorch的清华源:
channels:
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
ssl_verify: true
show_channel_urls: true
2.3 安装
需要注意的是,最后这个指令是从官网的指令去掉-c pytorch
。
conda install pytorch==1.1.0 torchvision==0.3.0 cudatoolkit=9.0
(CCNet) C:\Users\86571>conda install pytorch==1.1.0 torchvision==0.3.0 cudatoolkit=9.0
Collecting package metadata (repodata.json): done
Solving environment: |
Warning: >10 possible package resolutions (only showing differing packages):
- https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/noarch::pip-20.2.4-py_0, https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/noarch::wheel-0.35.1-pyh9f0ad1d_0, https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/win-64::vc-14.1-h869be7e_1, https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/win-64::vs2015_runtime-14.16.27012-h30e32a0_2
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/noarch::wheel-0.35.1-pyh9f0ad1d_0, https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/noarch::pip-20.2.4-py_0, https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/win-64::vc-14.1-h869be7e_1, https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/win-64::vs2015_runtime-14.16.27012-h30e32a0_2
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/noarch::pip-20.2.4-py_0, https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/noarch::wheel-0.35.1-pyh9f0ad1d_0, https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/win-64::vc-14.1-h869be7e_1, https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/win-64::vs2015_runtime-14.16.27012-h30e32a0_2
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/noarch::pip-20.2.4-py_0, http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/noarch::wheel-0.35.1-pyh9f0ad1d_0, https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/win-64::vc-14.1-h869be7e_1, https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/win-64::vs2015_runtime-14.16.27012-h30e32a0_2
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/noarch::pip-20.2.4-py_0, http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/win-64::vc-14.1-h869be7e_1, https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/noarch::wheel-0.35.1-pyh9f0ad1d_0, https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/win-64::vs2015_runtime-14.16.27012-h30e32a0_2
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/noarch::pip-20.2.4-py_0, http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/noarch::wheel-0.35.1-pyh9f0ad1d_0, http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/win-64::vc-14.1-h869be7e_1, https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/win-64::vs2015_runtime-14.16.27012-h30e32a0_2
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/win-64::vc-14.1-h869be7e_1, https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/noarch::pip-20.2.4-py_0, https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/noarch::wheel-0.35.1-pyh9f0ad1d_0, https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/win-64::vs2015_runtime-14.16.27012-h30e32a0_2
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/noarch::wheel-0.35.1-pyh9f0ad1d_0, http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/win-64::vc-14.1-h869be7e_1, https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/noarch::pip-20.2.4-py_0, https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/win-64::vs2015_runtime-14.16.27012-h30e32a0_2
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/win-64::vc-14.1-h869be7e_1, http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/win-64::vs2015_runtime-14.16.27012-h30e32a0_2, https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/noarch::pip-20.2.4-py_0, https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/noarch::wheel-0.35.1-pyh9f0ad1d_0
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/win-64::vs2015_runtime-14.16.27012-h30e32a0_2, https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/noarch::pip-20.2.4-py_0, https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/noarch::wheel-0.35.1-pyh9f0ad1d_0, https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/win-64::vc-14.1-h869be7e_1
... and othedone
==> WARNING: A newer version of conda exists. <==
current version: 4.8.5
latest version: 4.9.2
Please update conda by running
$ conda update -n base conda
WARNING conda.gateways.disk.delete:unlink_or_rename_to_trash(140): Could not remove or rename D:\CodingSoftware\Anaconda3\pkgs\pytorch-1.1.0-py3.7_cuda90_cudnn7_1.tar.bz2. Please remove this file manually (you may need to reboot to free file handles)
WARNING conda.gateways.disk.delete:unlink_or_rename_to_trash(140): Could not remove or rename D:\CodingSoftware\Anaconda3\pkgs\pytorch-1.1.0-py3.7_cuda90_cudnn7_1\Lib\site-packages\torch\include\pybind11\chrono.h. Please remove this file manually (you may need to reboot to free file handles)
WARNING conda.gateways.disk.delete:unlink_or_rename_to_trash(140): Could not remove or rename D:\CodingSoftware\Anaconda3\pkgs\pytorch-1.7.0-py3.7_cuda110_cudnn8_0.tar.bz2. Please remove this file manually (you may need to reboot to free file handles)
WARNING conda.gateways.disk.delete:unlink_or_rename_to_trash(140): Could not remove or rename D:\CodingSoftware\Anaconda3\pkgs\pytorch-1.7.0-py3.7_cuda110_cudnn8_0\info\paths.json. Please remove this file manually (you may need to reboot to free file handles)
## Package Plan ##
environment location: D:\CodingSoftware\Anaconda3\envs\CCNet
added / updated specs:
- cudatoolkit=9.0
- pytorch==1.1.0
- torchvision==0.3.0
The following packages will be downloaded:
package | build
---------------------------|-----------------
blas-1.0 | mkl 6 KB http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
ca-certificates-2020.10.14 | 0 159 KB http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
certifi-2020.6.20 | pyhd3eb1b0_3 159 KB http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
cffi-1.14.3 | py37h7a1dbc1_0 226 KB http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
cudatoolkit-9.0 | 1 339.8 MB http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
freetype-2.10.4 | hd328e21_0 490 KB http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
intel-openmp-2020.2 | 254 2.0 MB http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
jpeg-9b | hb83a4c4_2 313 KB http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
libpng-1.6.37 | h2a8f88b_0 598 KB http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
libtiff-4.1.0 | h56a325e_1 1.1 MB http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
lz4-c-1.9.2 | hf4a77e7_3 121 KB http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
mkl-2020.2 | 256 170.7 MB http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
mkl-service-2.3.0 | py37hb782905_0 200 KB http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
mkl_fft-1.2.0 | py37h45dec08_0 135 KB http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
mkl_random-1.1.1 | py37h47e9c7a_0 272 KB http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
ninja-1.10.1 | py37h7ef1ec2_0 275 KB http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
numpy-1.19.2 | py37hadc3359_0 21 KB http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
numpy-base-1.19.2 | py37ha3acd2a_0 4.8 MB http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
olefile-0.46 | py37_0 49 KB http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
openssl-1.1.1h | he774522_0 5.8 MB http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
pillow-8.0.1 | py37h4fa10fc_0 736 KB http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
pycparser-2.20 | py_2 94 KB http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
pytorch-1.1.0 |py3.7_cuda90_cudnn7_1 427.2 MB http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch
six-1.15.0 | py37haa95532_0 50 KB http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
tk-8.6.10 | he774522_0 3.2 MB http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
torchvision-0.3.0 | py37_cu90_1 2.3 MB http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch
xz-5.2.5 | h62dcd97_0 333 KB http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
zlib-1.2.11 | h62dcd97_4 132 KB http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
zstd-1.4.5 | h04227a9_0 837 KB http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
------------------------------------------------------------
Total: 961.9 MB
The following NEW packages will be INSTALLED:
blas anaconda/pkgs/main/win-64::blas-1.0-mkl
cffi anaconda/pkgs/main/win-64::cffi-1.14.3-py37h7a1dbc1_0
cudatoolkit anaconda/pkgs/main/win-64::cudatoolkit-9.0-1
freetype anaconda/pkgs/main/win-64::freetype-2.10.4-hd328e21_0
intel-openmp anaconda/pkgs/main/win-64::intel-openmp-2020.2-254
jpeg anaconda/pkgs/main/win-64::jpeg-9b-hb83a4c4_2
libpng anaconda/pkgs/main/win-64::libpng-1.6.37-h2a8f88b_0
libtiff anaconda/pkgs/main/win-64::libtiff-4.1.0-h56a325e_1
lz4-c anaconda/pkgs/main/win-64::lz4-c-1.9.2-hf4a77e7_3
mkl anaconda/pkgs/main/win-64::mkl-2020.2-256
mkl-service anaconda/pkgs/main/win-64::mkl-service-2.3.0-py37hb782905_0
mkl_fft anaconda/pkgs/main/win-64::mkl_fft-1.2.0-py37h45dec08_0
mkl_random anaconda/pkgs/main/win-64::mkl_random-1.1.1-py37h47e9c7a_0
ninja anaconda/pkgs/main/win-64::ninja-1.10.1-py37h7ef1ec2_0
numpy anaconda/pkgs/main/win-64::numpy-1.19.2-py37hadc3359_0
numpy-base anaconda/pkgs/main/win-64::numpy-base-1.19.2-py37ha3acd2a_0
olefile anaconda/pkgs/main/win-64::olefile-0.46-py37_0
pillow anaconda/pkgs/main/win-64::pillow-8.0.1-py37h4fa10fc_0
pycparser anaconda/pkgs/main/noarch::pycparser-2.20-py_2
pytorch anaconda/cloud/pytorch/win-64::pytorch-1.1.0-py3.7_cuda90_cudnn7_1
six anaconda/pkgs/main/win-64::six-1.15.0-py37haa95532_0
tk anaconda/pkgs/main/win-64::tk-8.6.10-he774522_0
torchvision anaconda/cloud/pytorch/win-64::torchvision-0.3.0-py37_cu90_1
xz anaconda/pkgs/main/win-64::xz-5.2.5-h62dcd97_0
zlib anaconda/pkgs/main/win-64::zlib-1.2.11-h62dcd97_4
zstd anaconda/pkgs/main/win-64::zstd-1.4.5-h04227a9_0
The following packages will be SUPERSEDED by a higher-priority channel:
ca-certificates anaconda/cloud/conda-forge::ca-certif~ --> anaconda/pkgs/main::ca-certificates-2020.10.14-0
certifi anaconda/cloud/conda-forge/win-64::ce~ --> anaconda/pkgs/main/noarch::certifi-2020.6.20-pyhd3eb1b0_3
openssl anaconda/cloud/conda-forge --> anaconda/pkgs/main
Proceed ([y]/n)? y
Downloading and Extracting Packages
six-1.15.0 | 50 KB | ############################################################################ | 100%
certifi-2020.6.20 | 159 KB | ############################################################################ | 100%
blas-1.0 | 6 KB | ############################################################################ | 100%
libtiff-4.1.0 | 1.1 MB | ############################################################################ | 100%
ninja-1.10.1 | 275 KB | ############################################################################ | 100%
numpy-base-1.19.2 | 4.8 MB | ############################################################################ | 100%
mkl_fft-1.2.0 | 135 KB | ############################################################################ | 100%
mkl-service-2.3.0 | 200 KB | ############################################################################ | 100%
numpy-1.19.2 | 21 KB | ############################################################################ | 100%
tk-8.6.10 | 3.2 MB | ############################################################################ | 100%
libpng-1.6.37 | 598 KB | ############################################################################ | 100%
mkl-2020.2 | 170.7 MB | ############################################################################ | 100%
zstd-1.4.5 | 837 KB | ############################################################################ | 100%
mkl_random-1.1.1 | 272 KB | ############################################################################ | 100%
ca-certificates-2020 | 159 KB | ############################################################################ | 100%
lz4-c-1.9.2 | 121 KB | ############################################################################ | 100%
intel-openmp-2020.2 | 2.0 MB | ############################################################################ | 100%
cffi-1.14.3 | 226 KB | ############################################################################ | 100%
olefile-0.46 | 49 KB | ############################################################################ | 100%
jpeg-9b | 313 KB | ############################################################################ | 100%
pycparser-2.20 | 94 KB | ############################################################################ | 100%
openssl-1.1.1h | 5.8 MB | ############################################################################ | 100%
freetype-2.10.4 | 490 KB | ############################################################################ | 100%
pillow-8.0.1 | 736 KB | ############################################################################ | 100%
pytorch-1.1.0 | 427.2 MB | ###########################################################################8 | 100% WARNING conda.gateways.disk.delete:unlink_or_rename_to_trash(140): Could not remove or rename D:\CodingSoftware\Anaconda3\pkgs\pytorch-1.1.0-py3.7_cuda90_cudnn7_1\Lib\site-packages\torch\include\pybind11\chrono.h. Please remove this file manually (you may need to reboot to free file handles)
WARNING conda.gateways.disk.delete:unlink_or_rename_to_trash(140): Could not remove or rename D:\CodingSoftware\Anaconda3\pkgs\pytorch-1.1.0-py3.7_cuda90_cudnn7_1\Lib\site-packages\torch\include\pybind11\chrono.h. Please remove this file manually (you may need to reboot to free file handles)
pytorch-1.1.0 | 427.2 MB | ############################################################################ | 100%
torchvision-0.3.0 | 2.3 MB | ############################################################################ | 100%
cudatoolkit-9.0 | 339.8 MB | ############################################################################ | 100%
xz-5.2.5 | 333 KB | ############################################################################ | 100%
zlib-1.2.11 | 132 KB | ############################################################################ | 100%
InvalidArchiveError('Error with archive D:\\CodingSoftware\\Anaconda3\\pkgs\\pytorch-1.1.0-py3.7_cuda90_cudnn7_1.tar.bz2. You probably need to delete and re-download or re-create this file. Message from libarchive was:\n\nCould not unlink')
仔细看一下出错信息:
InvalidArchiveError('Error with archive D:\\CodingSoftware\\Anaconda3\\pkgs\\pytorch-1.1.0-py3.7_cuda90_cudnn7_1.tar.bz2. You probably need to delete and re-download or re-create this file. Message from libarchive was:\n\nCould not unlink')
将指定的文件删除后,再次安装。成功。