1、在windows11上安装cuda11.1 使用 nvidia-smi和nvcc --version查看是否安装成功以及版本
2、使用wsl新建Ubuntu-20.04系统
3、检查/usr/lib/wsl/lib 是否存在nvidia-smi以及若干cuda.co
cd /usr/lib/wsl/lib
ls
libcuda.so libd3d12.so libnvcuvid.so libnvidia-encode.so libnvidia-opticalflow.so nvidia-smi
libcuda.so.1 libd3d12core.so libnvcuvid.so.1 libnvidia-encode.so.1 libnvidia-opticalflow.so.1
libcuda.so.1.1 libdxcore.so libnvdxdlkernels.so libnvidia-ml.so.1 libnvwgf2umx.so
这一步非常重要,如果没有这些so文件,那么后面pytorch就没法检测到cuda存在。
(openmmlab) root@DESKTOP-7505DGE:/usr/lib/wsl/lib
Mon Sep 12 14:28:30 2022
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 515.65.01 Driver Version: 516.94 CUDA Version: 11.7 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|===============================+======================+======================|
| 0 NVIDIA GeForce ... On | 00000000:0A:00.0 On | N/A |
| 0% 38C P8 14W / 250W | 989MiB / 11264MiB | 3% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| No running processes found |
+-----------------------------------------------------------------------------+
4、根据CUDA Support for WSL 2 为wsl准备环境
sudo apt-key del 7fa2af80
wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-wsl-ubuntu.pin
sudo mv cuda-wsl-ubuntu.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/11.1.0/local_installers/cuda-repo-wsl-ubuntu-11-1-local_11.1.0-1_amd64.deb
sudo dpkg -i cuda-repo-wsl-ubuntu-11-1-local_11.1.0-1_amd64.deb
sudo apt-key add /var/cuda-repo-wsl-ubuntu-11-1-local/7fa2af80.pub
sudo apt-get update
sudo apt-get -y install cuda
5、安装好后去更新环境变量
vim ~/.bashrc
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
source ~/.bashrc
nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2020 NVIDIA Corporation
Built on Tue_Sep_15_19:10:02_PDT_2020
Cuda compilation tools, release 11.1, V11.1.74
Build cuda_11.1.TC455_06.29069683_0
6、安装anaconda
bash Anaconda.sh
source ~/.bashrc
7、创建conda环境
conda create --name openmmlab python=3.7 -y
conda activate openmmlab
conda install pytorch==1.8.1 torchvision==0.9.1 torchaudio==0.8.1 cudatoolkit=11.1 -c pytorch -c conda-forge
8、检查cuda是否可用
>>> import torch
>>> torch.cuda.is_available()
True
9、如果c盘空间不足,可以参考Move WSL to Another Drive将wsl2移动到D盘
D:
mkdir WSL
cd WSL
wsl --export Ubuntu-20.04 ubuntu-20.04.tar
wsl --unregister Ubuntu-20.04
mkdir Ubuntu-20.04
wsl --import Ubuntu-20.04 Ubuntu-20.04 ubuntu-20.04.tar
参考资料: https://docs.nvidia.com/cuda/wsl-user-guide/index.html https://docs.microsoft.com/en-us/windows/wsl/tutorials/gpu-compute
|