之前记录过mmcv-full 1.2.7 在Win 10 下的安装记录,当时的环境版本太低,现在需要升级,重新安装了mmcv-full 1.3.6,本文记录安装过程。
环境记录
- Win 10 专业版
- Python 3.8.5 (Anaconda3-2020.11)
- 显卡型号 GTX 1660
- 显卡驱动 461.92
- CUDA 11.1
- cuDNN 8.0.4
- PyTorch 1.8.1 cu11.1
- torchvision 0.9.1 cu11.1
- VS 2019 Community
- MMCV 1.3.6
环境配置
按照记录的环境逐步搭建,这是我安装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 |
|
|
|
|
CUDA 11.2.2 Update 2 |
|
|
|
|
CUDA 11.2.1 Update 1 |
|
|
|
|
CUDA 11.2.0 GA |
|
|
|
|
CUDA 11.1.1 Update 1 |
|
|
|
|
CUDA 11.1 GA |
|
|
|
|
CUDA 11.0.3 Update 1 |
|
|
|
|
CUDA 11.0.2 GA |
|
|
|
|
CUDA 11.0.1 RC |
|
|
|
|
CUDA 10.2.89 |
|
|
|
|
CUDA 10.1 (10.1.105 general release, and updates) |
|
|
|
|
CUDA 10.0.130 |
|
|
|
|
CUDA 9.2 (9.2.148 Update 1) |
|
|
|
|
CUDA 9.2 (9.2.88) |
|
|
|
|
CUDA 9.1 (9.1.85) |
|
|
|
|
CUDA 9.0 (9.0.76) |
|
|
|
|
CUDA 8.0 (8.0.61 GA2) |
|
|
|
|
CUDA 8.0 (8.0.44) |
|
|
|
|
CUDA 7.5 (7.5.16) |
|
|
|
|
CUDA 7.0 (7.0.28) |
|
|
|
|
- 我们需要在Win 10 安装 456.81 以上版本的显卡驱动
- 在官网搜索自己的显卡,选择合适的版本下载安装即可
- 我下载的是 461.92 版本的显卡驱动
C:UsersAdministrator>nvidia-smi
Wed Jun 16 09:46:55 2021
-----------------------------------------------------------------------------
| NVIDIA-SMI 461.92 Driver Version: 461.92 CUDA Version: 11.2 |
|------------------------------- ---------------------- ----------------------
| 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 GeForce GTX 1660 WDDM | 00000000:01:00.0 On | N/A |
| 27% 38C P8 4W / 120W | 288MiB / 6144MiB | 12% Default |
| | | N/A |
------------------------------- ---------------------- ----------------------
-----------------------------------------------------------------------------
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| 0 N/A N/A 1236 C G Insufficient Permissions 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 安装失败
的错误
- [解决方案](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.0.4
- 针对CUDA 11.1, cuDnn 可选择的版本其实有好几个
- 8.0.4 支持 11.1
- 8.1.1 支持11.0、11.1、11.2
- 8.2.1 支持 11.X
- 以上几个版本应该都可以用,稳妥起见我选择了 8.0.4,其他的没有亲测过
- 具体步骤参考之前的链接
- 官网链接(有时比较慢):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
代码语言:javascript复制conda install pytorch torchvision torchaudio cudatoolkit=11.1 -c pytorch -c conda-forge
代码语言:txt复制- pip
代码语言:javascript复制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 Studio2019CommunityVCToolsMSVC14.27.29110binHostx86x64
添加到环境变量 PATH, 这样 cl.exe 可以在控制台中所有路径中被调用。
C:UsersAdministrator>cl
用于 x64 的 Microsoft (R) C/C 优化编译器 19.29.30037 版
版权所有(C) Microsoft Corporation。保留所有权利。
用法: cl [ 选项... ] 文件名... [ /link 链接选项... ]
网上有说仅安装VS C build tools 也可以,我尝试的时候没有成功
安装 MMCV 1.3.6
- github 链接: https://github.com/open-mmlab/mmcv
可以重新构建 anaconda 环境
- 下载代码,调整到指定tag,构建基础依赖环境
git clone https://github.com/open-mmlab/mmcv.git
cd mmcv
git checkout v1.3.6
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 | 7.5 |
- 其中
TORCH_CUDA_ARCH_LIST
一项表示的是显卡算力,可以在官网查询,我的查不到,可以用CUDA工具查询:
代码语言:javascript复制执行:
C:Program FilesNVIDIA GPU Computing ToolkitCUDAv11.1extrasdemo_suitedeviceQuery.exe
C:>"C:Program FilesNVIDIA GPU Computing ToolkitCUDAv11.1extrasdemo_suitedeviceQuery.exe"
C:Program FilesNVIDIA GPU Computing ToolkitCUDAv11.1extrasdemo_suitedeviceQuery.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
中
编译安装
代码语言:javascript复制# build
python setup.py build_ext # if success, cl will be launched to compile ops
# install
python setup.py develop
检查安装情况
- 查看pip包列表
C:>pip show mmcv-full
Name: mmcv-full
Version: 1.3.6
Summary: OpenMMLab Computer Vision Foundation
Home-page: https://github.com/open-mmlab/mmcv
Author: MMCV Authors
Author-email: openmmlab@gmail.com
License: UNKNOWN
Location: f:mmcv
Requires: addict, numpy, Pillow, pyyaml, yapf, regex
Required-by:
- 查看编译文件,55个
- 查看
_ext.cp38-win_amd64.pyd
文件是否生成
- 上述文件生成正常说明安装成功
正常情况下整个过程纵享丝滑,不需要改任何源码
未解决的问题
- 其实上述步骤我重复了很多遍,一直提示
error: Microsoft Visual C 14.0 is required
尝试各种办法,装了啥都不行 - 最终重装系统解决的问题
- 最后分享我编译的
_ext.cp38-win_amd64.pyd
文件,可以安装mmcv-full之后直接放在安装目录中,不需要编译直接可用
前提是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