This gist contains all the steps required to manage multiple cuda environments on ubuntu. For the steps walkthrough, For the walkthrough, I will install CUDA 11.8
and CUDA 11.3
on my system and manage them using environment modules
.
- Add PPA GPU Drivers Repository to the System
sudo add-apt-repository ppa:graphics-drivers/ppa
- Check GPU and available drives
ubuntu-devices drivers
- Install the compatible driver
sudo apt install nvidia-driver-530
- Check the installed nvidia driver
nvidia-detector
- Note:
- you can also autoinstall the compatible using
sudo ubuntu-drivers autoinstall
- Additionally, you can also install nvidia-drivers using Software & Updates ubuntu app. Just go to additional drivers tab, choose a driver and click apply changes
sudo apt-get update
sudo apt-get install environment-modules
- Create a directory
/etc/modulefiles/cuda
to hold modulefiles for cuda distributions
mkdir /etc/modulefiles/cuda
- Create a modulefile /etc/modulefiles/cuda/11.8 for
CUDA 11.3
and following lines to the file:
vim /etc/modulefiles/cuda/11.3
lorem epsum
- Create a modulefile /etc/modulefiles/cuda/11.3 for
CUDA 11.8
and following lines to the file:
vim /etc/modulefiles/cuda/11.8
lorem epsum
- Create a file
/etc/modulefiles/cuda/.version
to make python/cuda/11.8 the default cuda module:
lorem epsum
## check the path to nvcc (cuda distribution)
which nvcc
echo $CUDA_HOME
echo $PATH
echo $LD_LIBRARY_PATH
# check the available modules
module avail
# list the loaded modules
module list
# load CUDA 11.3
module load cuda/11.3
# check loaded cuda distribution (should show CUDA 11.3 paths)
which nvcc
echo $CUDA
echo $PATH
echo $LD_LIBRARY_PATH