本文最后更新于:2024年1月14日 晚上

之前记录过mmcv-full 1.2.7 在Win 10 下的安装记录,和 Windows 10 mmcv-full 1.3.6 安装记录,本以为可以安享一段时间宁静,突然发现1.3.6训练有问题,重新安装了mmcv-full 1.3.9,本文记录安装过程。

环境记录

  • Win 11 专业版
  • Python 3.8.5 (Anaconda3-2020.11)
  • 显卡型号 GTX 1660
  • 显卡驱动 470.14
  • CUDA 11.1
  • cuDNN 8.2.1
  • PyTorch 1.8.1 + cu11.1
  • torchvision 0.9.1 + cu11.1
  • VS 2019 Community
  • MMCV 1.3.9

环境配置

按照记录的环境逐步搭建,这是我安装mmcv时的环境,可以根据个人情况酌情调整,注意各个环境之间的版本依赖

Python 3.8.5

  • 安装 Anaconda3-2020.11 可以得到配套的 python 3.8.5

其他版本也可以,建议 3.7 以上 python

显卡驱动

可以参考之前的链接

Toolkit Driver Version Minimum Required Driver Version*
CUDA Toolkit Linux x86_64 Driver Version Windows x86_64 Driver Version Linux x86_64 Driver Version Windows x86_64 Driver Version
CUDA 11.3.0 GA >=465.19.01 >=465.89 >= 450.80.02 >= 456.38
CUDA 11.2.2 Update 2 >=460.32.03 >=461.33 >= 450.80.02 >= 456.38
CUDA 11.2.1 Update 1 >=460.32.03 >=461.09 >= 450.80.02 >= 456.38
CUDA 11.2.0 GA >=460.27.03 >=460.82 >= 450.80.02 >= 456.38
CUDA 11.1.1 Update 1 >=455.32 >=456.81 >= 450.80.02 >= 456.38
CUDA 11.1 GA >=455.23 >=456.38 >= 450.80.02 >= 456.38
CUDA 11.0.3 Update 1 >= 450.51.06 >= 451.82 >= 450.51.06 >= 451.82
CUDA 11.0.2 GA >= 450.51.05 >= 451.48 >= 450.51.06 >= 451.48
CUDA 11.0.1 RC >= 450.36.06 >= 451.22 >= 450.51.06 >= 451.22
CUDA 10.2.89 >= 440.33 >= 441.22 >= 440.33 >= 441.22
CUDA 10.1 (10.1.105 general release, and updates) >= 418.39 >= 418.96 >= 418.39 >= 418.96
CUDA 10.0.130 >= 410.48 >= 411.31 >= 410.48 >= 411.31
CUDA 9.2 (9.2.148 Update 1) >= 396.37 >= 398.26 >= 396.37 >= 398.26
CUDA 9.2 (9.2.88) >= 396.26 >= 397.44 >= 396.26 >= 397.44
CUDA 9.1 (9.1.85) >= 390.46 >= 391.29 >= 390.46 >= 391.29
CUDA 9.0 (9.0.76) >= 384.81 >= 385.54 >= 384.81 >= 385.54
CUDA 8.0 (8.0.61 GA2) >= 375.26 >= 376.51 >= 375.26 >= 376.51
CUDA 8.0 (8.0.44) >= 367.48 >= 369.30 >= 367.48 >= 369.30
CUDA 7.5 (7.5.16) >= 352.31 >= 353.66 >= 352.31 >= 353.66
CUDA 7.0 (7.0.28) >= 346.46 >= 347.62 >= 346.46 >= 347.62
  • 我们需要在Win 10 安装 456.81 以上版本的显卡驱动
  • 官网搜索自己的显卡,选择合适的版本下载安装即可
  • 我下载的是 470.14 版本的显卡驱动
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

C:\Users\Administrator>nvidia-smi
Fri Jul 16 18:41:46 2021
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 470.14 Driver Version: 470.14 CUDA Version: 11.3 |
|-------------------------------+----------------------+----------------------+
| GPU Name TCC/WDDM | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|===============================+======================+======================|
| 0 NVIDIA GeForce ... WDDM | 00000000:01:00.0 On | N/A |
| 0% 50C P8 15W / 135W | 427MiB / 6144MiB | 2% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| 0 N/A N/A 1148 C+G Insufficient Permissions N/A |
| 0 N/A N/A 1860 C+G C:\Windows\explorer.exe N/A |
| 0 N/A N/A 4176 C+G ...lPanel\SystemSettings.exe N/A |
| 0 N/A N/A 5072 C+G ...b3d8bbwe\WinStore.App.exe N/A |
| 0 N/A N/A 6916 C+G ...n1h2txyewy\SearchHost.exe N/A |
| 0 N/A N/A 7740 C+G ...y\ShellExperienceHost.exe N/A |
| 0 N/A N/A 11232 C+G ...2txyewy\TextInputHost.exe N/A |
+-----------------------------------------------------------------------------+


CUDA 11.1

当前 (2021.06.16)最新 cuda 版本 11.3,pytorch 和 mmcv 还不支持,因此建议当前最高cuda版本11.1

  • 在官网下载即可

https://developer.nvidia.com/cuda-downloads

  • 具体流程可以参考之前的链接

  • 注意安装时勾掉 Visual Studio Intgration

  • 可能会报Nsight Visual Studio Edition 安装失败的错误

1
2
3
4
5
6
C:\Users\Administrator>nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2020 NVIDIA Corporation
Built on Tue_Sep_15_19:12:04_Pacific_Daylight_Time_2020
Cuda compilation tools, release 11.1, V11.1.74
Build cuda_11.1.relgpu_drvr455TC455_06.29069683_0

cuDNN 8.2.1

  • 针对CUDA 11.1, cuDnn 可选择的版本其实有好几个
    • 8.0.4 支持 11.1
    • 8.1.1 支持11.0、11.1、11.2
    • 8.2.1 支持 11.X
  • 以上几个版本应该都可以用,我选择了 8.2.1
  • 具体步骤参考之前的链接
  • 官网链接(有时比较慢):https://developer.nvidia.com/zh-cn/cudnn
  • 下载后直接粘贴到CUDA文件夹即可

PyTorch 1.8.1 + cu11.1 / torchvision 0.9.1 + cu11.1

  • 此处一定要安装 1.8 以上的torch
  • 因为 mmcv 在CUDA 11.1 下仅支持 1.8 版本的 torch
CUDA torch 1.8 torch 1.7 torch 1.6 torch 1.5 torch 1.4 torch 1.3
11.1 install
11.0 install
10.2 install install install install
10.1 install install install install install install
9.2 install install install install install
cpu install install install install install install
  • 可以使用官方命令安装

    • conda
    1
    conda install pytorch torchvision torchaudio cudatoolkit=11.1 -c pytorch -c conda-forge
    • pip
    1
    pip3 install torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio===0.9.0 -f https://download.pytorch.org/whl/torch_stable.html
  • 也可以直接去下载目录选择自己需要的版本:

https://download.pytorch.org/whl/torch_stable.html

VS 2019 Community

  • 可以参考之前的链接
  • 当时下载的专业版,事实证明社区版就足够了
  • 安装C++桌面开发功能即可
  • C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\bin\Hostx86\x64 添加到环境变量 PATH, 这样 cl.exe 可以在控制台中所有路径中被调用。
1
2
3
4
5
C:\Users\Administrator>cl
用于 x64 的 Microsoft (R) C/C++ 优化编译器 19.29.30037 版
版权所有(C) Microsoft Corporation。保留所有权利。

用法: cl [ 选项... ] 文件名... [ /link 链接选项... ]

网上有说仅安装VS C++ build tools 也可以,我尝试的时候没有成功

安装 MMCV 1.3.9

可以重新构建 anaconda 环境

  • 下载代码,调整到指定tag,构建基础依赖环境
1
2
3
4
git clone https://github.com/open-mmlab/mmcv.git
cd mmcv
git checkout v1.3.9
pip3 install -r requirements.txt

配置环境变量

变量名称 值(需要根据个人情况调整)
CUDA_HOME C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1
CUDA_PATH C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1
MMCV_WITH_OPS 1
MAX_JOBS 4
path 记得添加 cl.exe 所在文件夹
TORCH_CUDA_ARCH_LIST 7.5
  • 其中TORCH_CUDA_ARCH_LIST一项表示的是显卡算力,可以在官网查询,我的查不到,可以用CUDA工具查询:

执行: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\extras\demo_suite\deviceQuery.exe

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
C:\>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\extras\demo_suite\deviceQuery.exe"
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\extras\demo_suite\deviceQuery.exe Starting...

CUDA Device Query (Runtime API) version (CUDART static linking)

Detected 1 CUDA Capable device(s)

Device 0: "GeForce GTX 1660"
CUDA Driver Version / Runtime Version 11.2 / 11.1
CUDA Capability Major/Minor version number: 7.5
Total amount of global memory: 6144 MBytes (6442450944 bytes)
(22) Multiprocessors, ( 64) CUDA Cores/MP: 1408 CUDA Cores
GPU Max Clock rate: 1815 MHz (1.81 GHz)
Memory Clock rate: 4001 Mhz
Memory Bus Width: 192-bit
L2 Cache Size: 1572864 bytes
Maximum Texture Dimension Size (x,y,z) 1D=(131072), 2D=(131072, 65536), 3D=(16384, 16384, 16384)
Maximum Layered 1D Texture Size, (num) layers 1D=(32768), 2048 layers
Maximum Layered 2D Texture Size, (num) layers 2D=(32768, 32768), 2048 layers
Total amount of constant memory: zu bytes
Total amount of shared memory per block: zu bytes
Total number of registers available per block: 65536
Warp size: 32
Maximum number of threads per multiprocessor: 1024
Maximum number of threads per block: 1024
Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
Max dimension size of a grid size (x,y,z): (2147483647, 65535, 65535)
Maximum memory pitch: zu bytes
Texture alignment: zu bytes
Concurrent copy and kernel execution: Yes with 6 copy engine(s)
Run time limit on kernels: Yes
Integrated GPU sharing Host Memory: No
Support host page-locked memory mapping: Yes
Alignment requirement for Surfaces: Yes
Device has ECC support: Disabled
CUDA Device Driver Mode (TCC or WDDM): WDDM (Windows Display Driver Model)
Device supports Unified Addressing (UVA): Yes
Device supports Compute Preemption: Yes
Supports Cooperative Kernel Launch: Yes
Supports MultiDevice Co-op Kernel Launch: No
Device PCI Domain ID / Bus ID / location ID: 0 / 1 / 0
Compute Mode:
< Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 11.2, CUDA Runtime Version = 11.1, NumDevs = 1, Device0 = GeForce GTX 1660
Result = PASS
  • CUDA Capability Major/Minor version number: 7.5里的值填进TORCH_CUDA_ARCH_LIST

编译安装

1
2
3
4
# build
python setup.py build_ext # if success, cl will be launched to compile ops
# install
python setup.py develop
检查安装情况
  • 查看pip包列表
1
2
3
4
5
6
7
8
9
10
11
C:\Users\Administrator>pip show mmcv-full
Name: mmcv-full
Version: 1.3.9
Summary: OpenMMLab Computer Vision Foundation
Home-page: https://github.com/open-mmlab/mmcv
Author: MMCV Authors
Author-email: openmmlab@gmail.com
License: UNKNOWN
Location: e:\programdata\python_external_lib\mmcv
Requires: addict, numpy, Pillow, pyyaml, yapf, regex
Required-by:
  • 查看编译文件,55个
  • 查看 _ext.cp38-win_amd64.pyd文件是否生成
  • 上述文件生成正常说明安装成功

正常情况下整个过程纵享丝滑,不需要改任何源码

pyd文件

  • 分享我编译的_ext.cp38-win_amd64.pyd文件,可以安装mmcv-full之后直接放在安装目录中,不需要编译直接可用

当python环境中没有安装pytorch时mmcv不会编译,可以顺利成功安装,这之后再放入pyd文件即可

文件名:_ext.cp38-win_amd64.pyd

前提是CUDA、python、torch、显卡算力等版本需要和我一致才能用https://uipv4.zywvvd.com:33030/HexoFiles/vvd-dell-2021-win-10/1.3.9-7.5-960M-win10_ext.cp38-win_amd64.pyd

参考资料



文章链接:
https://www.zywvvd.com/notes/environment/cuda/windows-mmcv-1-3-9-install/windows-mmcv-1-3-9-install/


“觉得不错的话,给点打赏吧 ୧(๑•̀⌄•́๑)૭”

微信二维码

微信支付

支付宝二维码

支付宝支付

Windows 11 mmcv-full 1.3.9 安装记录
https://www.zywvvd.com/notes/environment/cuda/windows-mmcv-1-3-9-install/windows-mmcv-1-3-9-install/
作者
Yiwei Zhang
发布于
2021年7月16日
许可协议