如何在WSL2环境下使用--gpus选项运行nvidia/cuda容器?
WSL2 Docker容器添加
--gpus参数后卡死问题 环境信息
- Windows 11系统
- WSL 2版本:1.1.3.0
- Ubuntu发行版:22.04.1 LTS(通过
lsb_release -a验证)user@desktop:~$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 22.04.1 LTS Release: 22.04 Codename: jammy - Docker Desktop版本:4.17.1
- 测试镜像:
nvidia/cuda:12.0.1-cudnn8-runtime-ubuntu22.04(同时验证过nvidia/cuda:11.6.0-devel-ubuntu20.04、nvidia/cuda:12.1.0-ubuntu22.04等镜像)
已完成配置
- Docker Desktop配置:
- 勾选Settings -> General:Use the WSL 2 based engine
- 勾选Settings -> Resources -> WSL integration:
- Enable integration with my default WSL distro
- 开启Ubuntu-22.04的Enable integration with additional distros选项
- WSL Ubuntu终端执行
nvidia-smi可正常输出GPU信息:user@desktop:~$ nvidia-smi Tue Mar 21 22:43:15 2023 +-----------------------------------------------------------------------------+ | NVIDIA-SMI 525.89.02 Driver Version: 528.49 CUDA Version: 12.0 | |-------------------------------+----------------------+----------------------+ | 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 RTX A200... On | 00000000:F3:00.0 Off | N/A | | N/A 61C P8 4W / 17W | 40MiB / 4096MiB | 0% Default | | | | N/A | +-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+ | Processes: | | GPU GI CI PID Type Process name GPU Memory | | ID ID Usage | |=============================================================================| | 0 N/A N/A 32 G /Xwayland N/A | | 0 N/A N/A 34 G /Xwayland N/A | | 0 N/A N/A 13020 G /Xwayland N/A | +-----------------------------------------------------------------------------+ - Windows PowerShell执行
nvidia-smi.exe可正常输出GPU信息,驱动版本528.49
问题现象
- 不添加
--gpus参数时,容器可正常启动,但无GPU功能 - 添加
--gpus 0、--gpus 1或--gpus all参数启动容器时,进程长时间无输出,且无法通过CTRL+C终止 - 更换Ubuntu 20.04发行版、其他CUDA镜像测试,问题依旧
- 拆分
docker create和docker start步骤启动容器,问题仍然存在
内容的提问来源于stack exchange,提问作者prsm
相关产品推荐
相关产品推荐

