Windows 11 WSL2 CUDA (Windows 11 Home 22000.708, Nvidia Studio Driver 512.96)

Good afternoon. I apologize for the delay in response.

  1. Installing WSL2

wsl.exe --install
wsl.exe --update

  1. Update WSL Ubuntu

sudo apt-get update && sudo apt-get upgrade

  1. Installing CUDA in WSL

sudo apt-key del 7fa2af80

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/11.6.2/local_installers/cuda-repo-wsl-ubuntu-11-6-local_11.6.2-1_amd64.deb
sudo dpkg -i cuda-repo-wsl-ubuntu-11-6-local_11.6.2-1_amd64.deb
sudo apt-key add /var/cuda-repo-wsl-ubuntu-11-6-local/7fa2af80.pub
sudo apt-get update
sudo apt-get -y install cuda-toolkit-11-6

2.1) Check, if Nvidia CUDA see videocard

nvidia-smi

  1. Install Pip3

sudo apt install python3-pip
pip3 install --upgrade pip

  1. Install TensorFlow

pip install tensorflow

  1. Install CudNN

sudo apt-get install zlib1g
sudo dpkg -i ./cudnn-local-repo-ubuntu2004-8.4.1.50_1.0-1_amd64.deb
sudo cp /var/cudnn-local-repo-ubuntu2004-8.4.1.50/cudnn-local-E3EC4A60-keyring.gpg /usr/share/keyrings/
sudo apt-get update
sudo apt-get install libcudnn8 libcudnn8-dev

4.1) Check TensorFlow:
a) Check CPU:

python3 -c “import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))”

If tesor return, everything is working properly.

б) Check GPU:

python3 -c “import tensorflow as tf; print(tf.config.list_physical_devices(‘GPU’))”

If tesor return, everything is working properly.

3 Likes