This guide will walk you through the process of setting up NVIDIA drivers, CUDA, cuDNN, and some popular data science libraries on Ubuntu 22.04.
- Ensure you have administrative privileges on your computer.
- Make sure you are connected to the internet.
Execute these commands to remove any existing NVIDIA drivers.
sudo apt-get purge nvidia*
sudo apt-get autoremove
sudo apt-get autoclean
To install the NVIDIA driver, run:
sudo apt install nvidia-driver-535
Fetch and set up the CUDA repository with these commands.
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-ubuntu2204.pin
sudo mv cuda-ubuntu2204.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/12.2.2/local_installers/cuda-repo-ubuntu2204-12-2-local_12.2.2-535.104.05-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu2204-12-2-local_12.2.2-535.104.05-1_amd64.deb
sudo cp /var/cuda-repo-ubuntu2204-12-2-local/cuda-*-keyring.gpg /usr/share/keyrings/
sudo apt-get update
sudo apt-get -y install cuda
Adjust your system's PATH and library directories.
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
First, download the cuDNN package for CUDA 12. Look for a file named cudnn-linux-x86_64-8.9.4.25_cuda12-archive.tar.xz
. Then, run:
tar -xvf cudnn-linux-x86_64-8.9.4.25_cuda12-archive.tar.xz
cp -P cudnn-linux-x86_64-8.9.4.25_cuda12-archive/include/cudnn* /usr/local/cuda-12.2/include/
cp -P cudnn-linux-x86_64-8.9.4.25_cuda12-archive/lib/libcudnn* /usr/local/cuda-12.2/lib64/
chmod a+r /usr/local/cuda-12.2/lib64/libcudnn*
- For CuPy:
pip3 install cupy-cuda12x
- For PyTorch:
pip3 install torch torchvision torchaudio
- For General Data Science:
pip3 install numpy pandas matplotlib seaborn
After setup, ensure everything works. Check the NVIDIA driver version, test CUDA samples, and try importing your new Python libraries.
If you run into problems, consult NVIDIA's official documentation or tap into the vast knowledge of online tech communities.
Friendly Reminder: Double-check the compatibility of your system with the software versions outlined in this guide. The NVIDIA site offers comprehensive compatibility data and system requirements.
For Test
run.sh
#!/bin/bash nvcc matrix_mul.cu -o matrix_mul -lcublas ./matrix_mul
matrix_mul.cu