Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Green-li/8267b50bb801bf64a98a38e73cf39ace to your computer and use it in GitHub Desktop.
Save Green-li/8267b50bb801bf64a98a38e73cf39ace to your computer and use it in GitHub Desktop.
Managing multiple CUDA versions using environment modules in Ubuntu

Steps to manage multiple CUDA environments

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.

1. Install the compatible nvidia drivers (if required)

  • 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

2. Install CUDA 11.3 and CUDA 11.8

3. Install cuDNN library

4. Manage multipe cuda version using environment modules

a) Install the environment modules utility

sudo apt-get update
sudo apt-get install environment-modules

b) Create modulefiles for cuda distributions

  • 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

c) Make CUDA 11.8 the default cuda version

  • Create a file /etc/modulefiles/cuda/.version to make python/cuda/11.8 the default cuda module:
lorem epsum

Quick examples to switch cuda versions

## 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment