Skip to content

Instantly share code, notes, and snippets.

@adwellj
Last active February 19, 2024 23:05
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save adwellj/2769957e7fc8c7e9372e5f4b06f72b80 to your computer and use it in GitHub Desktop.
Save adwellj/2769957e7fc8c7e9372e5f4b06f72b80 to your computer and use it in GitHub Desktop.
Instructions for installing CUDA for TensorFlow 2.8 in Ubuntu 20.04 in WSL2 (Win 10 - 02/2022)

Confirm GPU access in WSL

In an Ubuntu terminal, enter nvidia-smi. If that fails, make sure your Nvidia drivers are up-to-date (current version: 511.23). Win10 version also needs to be at least 21H2 (Winkey + R then winver in Windows to check version).

Current versions of TF use CUDA 11.2 and cuDNN 8.1. Tested build configurations Run the below commands in a terminal:

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

Install cuDNN

Download cuDNN v8.1.1 Run the below commands in a terminal (change .tgz filename as needed):

tar -xzvf cudnn-11.2-linux-x64-v8.1.1.33.tgz
sudo cp cuda/include/cudnn.h /usr/local/cuda/include
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*

Set CUPTI path

CUPTI ships with the CUDA Toolkit. Append its installation direction to the $LD_LIBRARY_PATH environment variable: export LD_LIBRARY_PATH=/usr/local/cuda/lib64:/usr/local/cuda-11.2/lib64

Install PIP

Run below in terminal: sudo apt update && sudo apt install python3-pip

Install TensorFlow

Run below in terminal: pip install tensorflow

Check Tensorflow for GPU

Run below in terminal: python3 -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"

Output should end with something like [PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]. If output ends with only [], the GPU is not detected.

Sources

Installing Tensorflow with GPU, CUDA and cuDNN in Ubuntu 20.04 - Medium GPU support | TensorFlow

@mujtabax18
Copy link

Thanks alot it worked,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment