🛠 Prereqs:
- WSL2 enabled on Windows
- NVIDIA GPU driver (≥ v535) installed on Windows
- Ubuntu 22.04 installed via WSL
- Download cuDNN manually while logged in to NVIDIA Developer
🧱 1. Setup Python environment in Ubuntu (WSL2)
sudo apt update && sudo apt install python3.11 python3.11-venv gcc-11 g++-11 -y
python3.11 -m venv ~/tf-gpu-311
source ~/tf-gpu-311/bin/activate
pip install --upgrade pip
pip install tensorflow==2.15.0
⚙️ 2. Install CUDA 12.2 (runfile method)
wget https://developer.download.nvidia.com/compute/cuda/12.2.0/local_installers/cuda_12.2.0_535.54.03_linux.run
chmod +x cuda_12.2.0_535.54.03_linux.run
sudo ./cuda_12.2.0_535.54.03_linux.run
- ❌ Uncheck driver install (you're using Windows one)
- ✅ Install toolkit only
Then set up environment:
echo 'export PATH=/usr/local/cuda-12.2/bin:$PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda-12.2/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrc
📦 3. Install cuDNN 8.9.4 (for CUDA 12.x)
- Go to cuDNN Downloads
-
Login → Choose:
- Version: cuDNN 8.9.4
- OS: Linux
- Installer: Local Installer for Ubuntu22.04 x86_64 (.deb)
Download
.deb
file and move it into Ubuntu:
cp /mnt/c/Users//Downloads/cudnn-local-repo-ubuntu2204-8.9.4.25_1.0-1_amd64.deb ~/
cd ~
sudo dpkg -i cudnn-local-repo-ubuntu2204-8.9.4.25_1.0-1_amd64.deb
sudo cp /var/cudnn-local-repo-ubuntu2204-8.9.4.25/cudnn-*-keyring.gpg /usr/share/keyrings/
sudo apt update
sudo apt install libcudnn8 libcudnn8-dev -y
🔄 4. Restart WSL2
In PowerShell (Windows):
wsl --shutdown
Then open Ubuntu again:
source ~/tf-gpu-311/bin/activate
✅ 5. Test TensorFlow GPU
import tensorflow as tf
print("TensorFlow version:", tf.__version__)
print("GPUs available:", tf.config.list_physical_devices('GPU'))
print("CUDA enabled:", tf.test.is_built_with_cuda())
print("GPU name:", tf.test.gpu_device_name())
💚 Expected Output
GPUs available: [PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
CUDA enabled: True
GPU name: /device:GPU:0
Happy TensorFlowing, GPU wizard 🧙♂️⚡