foreword
This article mainly explains how to configure CUDA to enable GPU acceleration in WSL2 (Ubuntu20.04) under Widnows 11 environment (this article assumes that you have installed Nvidia CUDA on Windows)
configuration process
check drive
Open GeForce Experience to check the status of the driver, you need to update to the latest version, and finally restart GeForce Experience.
Install CUDA
command generation
generate install command
Select version: CUDA Toolkit Archive | NVIDIA Developer
Install tool: CUDA Toolkit 12.2 Update 1 Downloads | NVIDIA Developer
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/12.2.1/local_installers/cuda-repo-wsl-ubuntu-12-2-local_12.2.1-1_amd64.deb
sudo dpkg -i cuda-repo-wsl-ubuntu-12-2-local_12.2.1-1_amd64.deb
sudo cp /var/cuda-repo-wsl-ubuntu-12-2-local/cuda-*-keyring.gpg /usr/share/keyrings/
sudo apt-get update
sudo apt-get -y install cuda
问题:dpkg: unrecoverable fatal error, aborting: unknown system user ‘redis’ in statoverride file;
vim /var/lib/dpkg/statoverride
root crontab 2755 /usr/bin/crontab
root root 1733 /var/lib/php/sessions
root messagebus 4754 /usr/lib/dbus-1.0/dbus-daemon-launch-helper
redis redis 640 /etc/redis/redis.conf
Just delete the last line
Configuration Environment
vim ~/.zshrc
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PAT
source ~/.zshrc
If you are using other shells, please modify to other configuration files
verify
# 验证是否安装成功
nvcc -V
# 查看驱动
nvidia-smi
Install cuDNN
cuDNN (CUDA Deep Neural Network, CUDA Deep Neural Network Library) download address
wget https://developer.nvidia.com/downloads/compute/cudnn/secure/8.9.3/local_installers/12.x/cudnn-linux-x86_64-8.9.3.28_cuda12-archive.tar.xz/
tar -xvf cudnn-linux-x86_64-8.9.3.28_cuda12-archive.tar.xz
sudo cp cudnn-*-archive/include/cudnn*.h /usr/local/cuda/include
sudo cp -P cudnn-*-archive/lib/libcudnn* /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn*.h /usr/local/cuda/lib64/libcudnn*
Verify that GPU acceleration is possible
pip3 install torch torchvision torchaudio
import torch
print(torch.cuda.is_available())
If the output is True, it means that the CUDA GPU acceleration is successful
reference article
Configure CUDA in Windows11 WSL2 Ubuntu18.04 environment
Configure pytorch GPU acceleration environment on WSL2 side_wsl2 pytorch
tensorflow - WSL2- nvidia-smi command not running - Stack Overflow
This article is published by OpenWrite, a multi-post platform for blogging !