注意:
以下过程无难度,故省略:
- 安装 Nvidia 驱动
- 启用 WSL
- 配置使用 WSL2 版本
- WSL 安装 Ubuntu
上述可参考:
- 如何使用 WSL 在 Windows 上安装 Linux
- Step by Step Procedure to Install WSL2 on Windows And Run Ubuntu on Windows Using WSL2
- How to install Linux WSL2 on Windows 10 and Windows 11
- How To Install Windows Subsystem For Linux (WSL2) On Windows 11
准备就绪后的表现为:
可以在 WSL 的 Ubuntu 中执行
which nvidia-smi
, 能得到如下输出/usr/lib/wsl/lib/nvidia-smi
- 可以在 WSL 的 Ubuntu 中执行
nvidia-smi
, 能正常输出
以下所有操作均在上述过程就绪之后
环境
- 系统:
Windows 11
+WSL2
+Ubuntu 22.04
GPU:
NVIDIA GeForce RTX 3070
- Driver Version: 555.99 (Windows 11 安装 Geforce Game Ready 驱动 555.99)
- NVIDIA-SMI: 555.99
- CUDA Version: 12.5
Docker CUDA 配置
参考: Installing Docker and The Docker Utility Engine for NVIDIA GPUs
Install Docker Engine on Ubuntu | Docker Documentation
Set up Docker's
apt
repository.# Add Docker's official GPG key: sudo apt-get update sudo apt-get install ca-certificates curl sudo install -m 0755 -d /etc/apt/keyrings sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc sudo chmod a+r /etc/apt/keyrings/docker.asc # Add the repository to Apt sources: echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \ $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ sudo tee /etc/apt/sources.list.d/docker.list > /dev/null sudo apt-get update
Install the Latest Docker packages.
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Verify that the Docker Engine installation is successful
sudo docker run -it --rm hello-world
Installing the NVIDIA Container Toolkit | NVIDIA Documentation
Configure the
apt
production repositorycurl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \ && curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \ sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \ sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
Install the NVIDIA Container Toolkit packages:
sudo apt-get update sudo apt-get install -y nvidia-container-toolkit
Configure the container runtime by using the nvidia-ctk command:
sudo nvidia-ctk runtime configure --runtime=docker sudo systemctl restart docker
Testing Docker and NVIDIA Container Runtime: Running a Sample Workload | NVIDIA Documentation
sudo docker run -it --rm --runtime=nvidia --gpus all ubuntu nvidia-smi
PyTorch-CUDA 测试
# 运行 pytorch-cuda 容器
sudo docker pull pytorch/pytorch:2.3.1-cuda12.1-cudnn8-runtime
sudo docker run -it --rm --runtime=nvidia --gpus all pytorch/pytorch:2.3.1-cuda12.1-cudnn8-runtime python
# python 测试代码
import torch
print(torch.cuda.is_available())
print(torch.cuda._is_compiled())
print(torch.__config__.show())
Docker 构建 ONNX Runtime CUDA 镜像
参考: https://github.com/microsoft/onnxruntime/blob/main/dockerfiles/README.md#cuda
# Build the docker image
git clone https://github.com/microsoft/onnxruntime
cd onnxruntime/dockerfiles/
sudo docker build -t onnxruntime-cuda -f Dockerfile.cuda ..
# Run the Docker image
sudo docker run -it --rm --runtime=nvidia --gpus all onnxruntime-cuda
# or
sudo nvidia-docker run -it --rm onnxruntime-cuda
评论 (0)