How to manage multiple versions of Cuda and cuDNN ?

How to manage multiple versions of Cuda and cuDNN ?

I am writing this blog to give some insights on managing multiple versions of Cuda and some links.

  • this unordered seed list will be replaced by toc as unordered list

References

First of all, I must thank two blog posts, which made my life easier.

  • https://blog.kovalevskyi.com/multiple-version-of-cuda-libraries-on-the-same-machine-b9502d50ae77
  • https://www.pugetsystems.com/labs/hpc/How-to-install-CUDA-9-2-on-Ubuntu-18-04-1184/

Get Started

Why we are doing this ?

  • Suppose you want to run some old projects from GitHub.
  • Experiment with new versions of CUDA, and experiment new features of it.

CUDA installation

Before starting, we need to download CUDA and follow steps from NVIDIA for right version.

The most important steps to follow during CUDA installation.

  1. Do not install CUDA drivers from CUDA-toolkit. Manually install the latest drivers for your graphics card.
  2. Do not create the symbolic link during installation process, since we need multiple versions.

Automation Script

The blogs that I mentioned earlier help a lot, and then I added the below script to make my life even more accessible.

touch ~/.bashrc add below contents to bottom of the file

# add below to your env bash file.

function _switch_cuda {
   v=$1
   export PATH=$PATH:/usr/local/cuda-$v/bin
   export CUDADIR=/usr/local/cuda-$v
   export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-$v/lib64
   nvcc --version
}
_switch_cuda 10.1 # change the version of your like to load bash.

cuDNN installation on all CUDA versions.

Finally, Installing cuDNN is just like copying the source header files into the respective CUDA toolkit path. Download and extract the cuDNN tar file, then run below script to copy lib into right CUDA Dirs.

After extraction of cudnn zip, create cudnn_install.sh file and place it like below.
ajayramesh @ ubox-r9-1804 ~/tmp/cudnn-10.2-linux-x64-v7.6.5.32
└─ $ ▶ tree -L 2
.
├── cuda
│   ├── include
│   ├── lib64
│   └── NVIDIA_SLA_cuDNN_Support.txt
└── cudnn_install.sh

3 directories, 2 files

Script to move cuDNN to right folders

Add below content to new cudnn_install.sh and run this command chmod +x cudnn_install.sh & sudo ./cudnn_install.sh on extracted cuDNN zip folder

read -p "CUDA-version: " ver
cp cuda/include/cudnn.h /usr/local/cuda-"${ver}"/include
cp cuda/lib64/libcudnn* /usr/local/cuda-"${ver}"/lib64
chmod a+r /usr/local/cuda*/include/cudnn.h /usr/local/cuda*/lib64/libcudnn*

Final Results

My current system now got CUDA 9.0 to 10.2 versions.

ajayramesh @ ubox-r9-1804 /usr/local
└─ $ ▶ tree -L 1
.
├── bin
├── cuda-10.0
├── cuda-10.1
├── cuda-10.2
├── cuda-9.0
├── cuda-9.1
├── cuda-9.2
├── etc
├── games
├── include
├── lib
├── man -> share/man
├── sbin
├── share
├── src
└── texlive

16 directories, 0 files

© 2021. All rights reserved.