Windows+WSL2+GPU CUDA+Docker

参考:

  1. CUDA on WSL User Guide
  2. NVIDIA CUDA Installation Guide for Linux
  3. WSL 2 GPU Support for Docker Desktop on NVIDIA GPUs - Docker

更新2022-04-24

不需要任何特殊的操作,就可以在Docker Desktop中使用GPU了

  • 操作系统
    Windows+WSL2+GPU CUDA+Docker_第1张图片

  • Docker Desktop
    Windows+WSL2+GPU CUDA+Docker_第2张图片

    • GPU驱动
      Windows+WSL2+GPU CUDA+Docker_第3张图片
  • 满足上面的要求后,执行命令:docker run -it --gpus=all --rm nvidia/cuda:11.4.2-base-ubuntu20.04 nvidia-smi
    Windows+WSL2+GPU CUDA+Docker_第4张图片

1.操作系统

  • 我采用的版本是windows10 教育版 2004(20262)。Ensure that you install Build version 20145 or higher.

  • 系统必须安装有nvidia的卡,同时安装对应wsl2的驱动

2.安装WSL2

参考:将WSL2作为生产力工具

3.安装Docker

在wsl2中:
curl https://get.docker.com | sh
关于Docker Desktop:
截止到2020.11.27,不支持Docker Desktop
参考:https://docs.nvidia.com/cuda/wsl-user-guide/index.html#known-limitations

4.安装cuda

从https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=WSL-Ubuntu&target_version=2.0下载相应的安装程序

  • 在WSL2中:
    注意:我使用的是Ubuntu18.04的镜像,如果是其他版本,请修改命令中的版本号
cd
apt-get install -y gcc g++ make
./cuda_11.1.0_455.23.05_linux.run

Windows+WSL2+GPU CUDA+Docker_第5张图片

Windows+WSL2+GPU CUDA+Docker_第6张图片

Windows+WSL2+GPU CUDA+Docker_第7张图片

cd ./NVIDIA_CUDA-11.1_Samples/1_Utilities/deviceQuery
make
./deviceQuery

Windows+WSL2+GPU CUDA+Docker_第8张图片

5.nvidia-docker toolkit

distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
# To get access to experimental features such as CUDA on WSL or the new MIG capability on A100, you may want to add the experimental branch to the repository listing
curl -s -L https://nvidia.github.io/libnvidia-container/experimental/$distribution/libnvidia-container-experimental.list | sudo tee /etc/apt/sources.list.d/libnvidia-container-experimental.list

apt-get update
apt-get install -y nvidia-docker2
service docker stop
service docker start

6.验证

docker run --rm --gpus all nvcr.io/nvidia/k8s/cuda-sample:nbody nbody -gpu -benchmark

报错:

docker: Error response from daemon: cgroups: cannot find cgroup mount destination: unknown.

参考:https://blog.csdn.net/ren7wei/article/details/80855779

mkdir /sys/fs/cgroup/systemd
mount -t cgroup -o none,name=systemd cgroup /sys/fs/cgroup/systemd

再次运行验证命令,通过
Windows+WSL2+GPU CUDA+Docker_第9张图片

安装脚本可以参考:https://blog.csdn.net/fleaxin/article/details/110310874

你可能感兴趣的:(wsl2,docker,nvidia,cuda,GPU)