wsl2 + cuda + nvgpu
基本环境
- wsl安装:https://docs.nvidia.com/cuda/wsl-user-guide/index.html#installing-wsl2
- wsl手册https://docs.microsoft.com/zh-cn/windows/wsl/reference
- (桌面显卡驱动)需要先安装支持wsl的显卡 https://developer.nvidia.com/cuda/wsl
进入ubuntu以后
查看内核版本
cat /etc/lsb-release
- 阿里源 https://www.cnblogs.com/07yml/p/11701139.html
- 工具 https://tecadmin.net/install-development-tools-on-ubuntu/
- (alternative)systemctl https://blog.csdn.net/w851685279/article/details/108825893
- cuda
- repo更新(较慢) https://blog.csdn.net/gzroy/article/details/111190131 -> repo版本最好改为wsl-ubuntu
- runfile安装 https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&target_distro=WSLUbuntu&target_version=20&target_type=runfilelocal 选择wsl2
-
查看显卡(wsl2的cudatool包不带ns工具,可以根据系统提示安装)
nvidia-smi
- (可选)anaconda https://blog.csdn.net/a475952074/article/details/79521567
- (可选)pytorch https://pytorch.org/get-started/locally/ 使用docker则无需配置本地python
docker
安装 https://www.cnblogs.com/jimchen1218/p/14186262.html
(此处猜测安装desktop的docker以后wsl内可以不用再安装)
运行 https://docs.nvidia.com/cuda/wsl-user-guide/index.html#running-containers
1算力检测
$ docker run --gpus all nvcr.io/nvidia/k8s/cuda-sample:nbody nbody -gpu -benchmark
2矩阵模板
$ docker run --gpus all --shm-size=1g --ulimit memlock=-1 --ulimit stack=67108864 -v "${PWD}:/mnt/c" nvcr.io/nvidia/tensorflow:20.03-tf2-py3 python /mnt/c/matmul.py gpu 20000
其中1可以显示当前桌面环境中的显卡,2可以看到调用gpu和cpu有明显时间区别
问题
在wsl内运行python文件可能无法正确识别显卡,同时nvcr.io/nvidia/tensorflow:20.03-tf2-py3也无法正确调用显卡
wsl2内的systemd有冲突,导致systemctl与docker可能无法正常使用
wsl-user-guide末注明了现阶段cuda on wsl2的部分已知问题