Windows 10 mmcv-full 1.3.13 安装记录

2022-08-06 10:53:40 浏览数 (1)

之前记录过mmcv-full 1.2.7 在Win 10 下的安装记录,Windows 10 mmcv-full 1.3.6 安装记录 和 Windows 11 mmcv-full 1.3.9 安装记录,近来mmcv-full 升级到了1.3.13,本文记录安装过程。

环境记录

  • Win 10 专业版
  • Python 3.8.5 (Anaconda3-2020.11)
  • 显卡型号 960M
  • 显卡驱动 471.41
  • CUDA 11.1
  • cuDNN 8.2.1
  • PyTorch 1.9.1 cu11.1
  • torchvision 0.10.1 cu11.1
  • VS 2019 Community
  • MMCV 1.3.13

环境配置

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

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

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

显卡驱动

可以参考之前的链接

  • 我们的目标是安装CUDA 11.1
  • 根据官网CUDA版本与驱动版本的关系表

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 以上版本的显卡驱动
  • 在官网搜索自己的显卡,选择合适的版本下载安装即可
  • 我下载的是 471.41 版本的显卡驱动
代码语言:javascript复制
$ nvidia-smi
Sat Sep 25 22:50:39 2021
 ----------------------------------------------------------------------------- 
| NVIDIA-SMI 471.41       Driver Version: 471.41       CUDA Version: 11.4     |
|------------------------------- ---------------------- ---------------------- 
| 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:02:00.0 Off |                  N/A |
| N/A    0C    P8    N/A /  N/A |     40MiB /  4096MiB |      0%      Default |
|                               |                      |                  N/A |
 ------------------------------- ---------------------- ---------------------- 

 ----------------------------------------------------------------------------- 
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|  No running processes found                                                 |
 ----------------------------------------------------------------------------- 

CUDA 11.1

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

  • 在官网下载即可

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

  • 具体流程可以参考之前的链接
  • 注意安装时勾掉 Visual Studio Intgration
  • 可能会报Nsight Visual Studio Edition 安装失败的错误
代码语言:txt复制
- [解决方案](https://www.zywvvd.com/notes/environment/cuda/cuda-install-error/cuda-install-error/)
代码语言:javascript复制
C:UsersAdministrator>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.9.1 cu11.1 / torchvision 0.10.1 cu11.1
  • 此处一定要安装 1.8 以上的torch
  • 因为 mmcv 在CUDA 11.1 下仅支持 1.8, 1.9版本的 torch

CUDA

torch 1.9

torch 1.8

torch 1.7

torch 1.6

torch 1.5

torch 1.4

torch 1.3

11.1

install

install

11.0

install

10.2

install

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

install

  • 可以使用官方命令安装
代码语言:txt复制
- conda
代码语言:javascript复制
conda install pytorch torchvision torchaudio cudatoolkit=11.1 -c pytorch -c conda-forge

代码语言:txt复制
- pip
代码语言:javascript复制
pip3 install torch==1.9.1 cu111 torchvision==0.10.1 cu111 torchaudio===0.9.1 -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 Studio2019CommunityVCToolsMSVC14.27.29110binHostx86x64 添加到环境变量 PATH, 这样 cl.exe 可以在控制台中所有路径中被调用。
代码语言:javascript复制
C:UsersAdministrator>cl
用于 x64 的 Microsoft (R) C/C   优化编译器 19.29.30037 版
版权所有(C) Microsoft Corporation。保留所有权利。

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

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

安装 MMCV 1.3.13

  • github 链接: https://github.com/open-mmlab/mmcv

可以重新构建 anaconda 环境

  • 下载代码,调整到指定tag,构建基础依赖环境
代码语言:javascript复制
git clone https://github.com/open-mmlab/mmcv.git
cd mmcv
git checkout v1.3.13
pip3 install -r requirements.txt

配置环境变量

变量名称

值(需要根据个人情况调整)

CUDA_HOME

C:Program FilesNVIDIA GPU Computing ToolkitCUDAv11.1

CUDA_PATH

C:Program FilesNVIDIA GPU Computing ToolkitCUDAv11.1

MMCV_WITH_OPS

1

MAX_JOBS

4

path

记得添加 cl.exe 所在文件夹

TORCH_CUDA_ARCH_LIST

5.0

  • 其中TORCH_CUDA_ARCH_LIST一项表示的是显卡算力,可以在官网查询,我的查不到,可以用CUDA工具查询:

执行: C:Program FilesNVIDIA GPU Computing ToolkitCUDAv11.1extrasdemo_suitedeviceQuery.exe

代码语言:javascript复制
>deviceQuery.exe
deviceQuery.exe Starting...

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

Detected 1 CUDA Capable device(s)

Device 0: "NVIDIA GeForce GTX 960M"
  CUDA Driver Version / Runtime Version          11.4 / 11.1
  CUDA Capability Major/Minor version number:    5.0
  Total amount of global memory:                 4096 MBytes (4294967296 bytes)
  ( 5) Multiprocessors, (128) CUDA Cores/MP:     640 CUDA Cores
  GPU Max Clock rate:                            1176 MHz (1.18 GHz)
  Memory Clock rate:                             2505 Mhz
  Memory Bus Width:                              128-bit
  L2 Cache Size:                                 2097152 bytes
  Maximum Texture Dimension Size (x,y,z)         1D=(65536), 2D=(65536, 65536), 3D=(4096, 4096, 4096)
  Maximum Layered 1D Texture Size, (num) layers  1D=(16384), 2048 layers
  Maximum Layered 2D Texture Size, (num) layers  2D=(16384, 16384), 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:  2048
  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 4 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:            No
  Supports Cooperative Kernel Launch:            No
  Supports MultiDevice Co-op Kernel Launch:      No
  Device PCI Domain ID / Bus ID / location ID:   0 / 2 / 0
  Compute Mode:
     < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 11.4, CUDA Runtime Version = 11.1, NumDevs = 1, Device0 = NVIDIA GeForce GTX 960M
Result = PASS

  • CUDA Capability Major/Minor version number: 5.0里的值填进TORCH_CUDA_ARCH_LIST
编译安装
代码语言:javascript复制
# build
python setup.py build_ext # if success, cl will be launched to compile ops
# install
python setup.py develop

检查安装情况
  • 查看pip包列表
代码语言:javascript复制
(base) H:testmmcv>pip show mmcv-full
Name: mmcv-full
Version: 1.3.13
Summary: OpenMMLab Computer Vision Foundation
Home-page: https://github.com/open-mmlab/mmcv
Author: MMCV Contributors
Author-email: openmmlab@gmail.com
License: UNKNOWN
Location: h:testmmcv
Requires: addict, numpy, packaging, Pillow, pyyaml, yapf, regex
Required-by:

  • 查看编译文件,35个
  • 在 mmcv 文件夹里会有一个 _ext.cp38-win_amd64.pyd文件生成

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

pyd文件

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

当python环境中没有安装pytorch时mmcv不会编译,可以顺利成功安装,这之后再放入pyd文件即可 编译时设置不同的算力值会生成不同算力的pyd文件 文件名:_ext.cp38-win_amd64.pyd

  • 由 960M 显卡编译(算力 5.0)
  • 由 960M 显卡编译(算力 6.1)
  • 由 960M 显卡编译(算力 7.5)
  • 由 960M 显卡编译(适用于算力 3.5 3.7 5.0 5.2 6.0 6.1 7.0 7.5)

前提是CUDA、python、torch、显卡算力等版本需要和我一致才能用。

参考资料

  • https://blog.csdn.net/lebusini/article/details/117525764
  • http://allophane.com/index.php/2021/05/26/win10_build_mmcv-full_from_source/
  • https://github.com/open-mmlab/mmcv

0 人点赞