Skip to content

Instantly share code, notes, and snippets.

@johndpope
Forked from khansun/LinuxCUDAtoolkits.md
Last active July 4, 2021 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johndpope/f8feb553c6959f0000318f730f3d181f to your computer and use it in GitHub Desktop.
Save johndpope/f8feb553c6959f0000318f730f3d181f to your computer and use it in GitHub Desktop.
Multiple versions of CUDA toolkit and CUDNN installation guide for Linux

Remove previous NVIDIA drivers if needed:

sudo dpkg -P $(dpkg -l | grep nvidia-driver | awk '{print $2}')

sudo apt autoremove

sudo lshw -C display

NVIDIA Apmere cards including 3070, 3080 and 3090 dos not work with CUDA 10.
You have to use CUDA 11.0 or higher.
Right now, the only way to do so is by installing tf-nightly or building yourself.
Works with TensorFlow version 2.5

##Install proper NVIDIA driver:

sudo ubuntu-drivers devices

sudo ubuntu-drivers autoinstall

Install CUDA toolkit: 11.4



wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin

sudo mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600

sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub

sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/ /"

sudo apt-get update
sudo apt-get -y install cuda-11.4

Install CUDNN dynamic libraries:

 

 tar -xzvf cudnn-10.1-linux-x64-v7.6.5.32.tgz

 sudo cp cuda/include/cudnn*.h /usr/local/cuda/include
 
 sudo cp -P cuda/lib64/libcudnn* /usr/local/cuda/lib64
 
 sudo chmod a+r /usr/local/cuda/include/cudnn*.h /usr/local/cuda/lib64/libcudnn*

OR use Anaconda:

  • Create virtual environment 'cuda': conda create -n cuda -c nvidia -c conda-forge \ -c defaults python=3.8 codatoolkit=10.1

  • Install compatible version of CUDNN: conda install -c anaconda cudnn=7.6.5

Update environment variable

vim ~/.bashrc

  • Append the following lines:

# CUDA related exports
export PATH=/usr/local/cuda-10.1/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-10.1/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

export PATH=/usr/local/cuda-11.2/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-11.2/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

# cubalas

export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/usr/local/cuda-10.2/targets/x86_64-linux/include/
export PATH=/usr/local/cuda-10.2/targets/x86_64-linux/include/${PATH:+:${PATH}}

export LD_LIBRARY_PATH="/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64:${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}"
export PATH="/usr/local/cuda/bin:${PATH:+:${PATH}}"
export LIBRARY_PATH="/usr/local/cuda-10.1/lib64:${LIBRARY_PATH:+:${LIBRARY_PATH}}


export PATH=/usr/local/cuda-11.1/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-11.1/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
"
  • Create CUDA library Path file and append the following text:

    sudo touch /etc/profile.d/cuda.sh

CUDAVER=cuda-11.4

export CUDA_HOME=/usr/local/cuda
export PATH=/usr/local/$CUDAVER/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/$CUDAVER/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/usr/local/$CUDAVER/lib64:$LD_LIBRARY_PATH
export CUDA_PATH=/usr/local/$CUDAVER
export CUDA_ROOT=/usr/local/$CUDAVER
export CUDA_HOME=/usr/local/$CUDAVER
export CUDA_HOST_COMPILER=/usr/bin/gcc-9
  • Update changes to ENV valiable:

    source ~/.bashrc

    source /etc/profile.d/cuda.sh

The NVCC should have the following config:

nvcc --version

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Wed_Jun__2_19:15:15_PDT_2021
Cuda compilation tools, release 11.4, V11.4.48
Build cuda_11.4.r11.4/compiler.30033411_0

@johndpope
Copy link
Author

johndpope commented Jul 2, 2021

can cudatoolkit 11.4 + driver 470 + tf-nightly peacefully coexist?
There's also these later cuda / cudnn files.
conda search -c nvidia cudnn
cudnn 8.0.4 cuda11.0_0 nvidia
cudnn 8.0.4 cuda11.1_0 nvidia

conda search -c nvidia cudatoolkit
cudatoolkit 11.0.3 h15472ef_8 nvidia
cudatoolkit 11.0.221 h6bb024c_0 nvidia
cudatoolkit 11.0.221 h6bb024c_0 pkgs/main
cudatoolkit 11.1.1 h6406543_8 nvidia
cudatoolkit 11.1.74 h6bb024c_0 nvidia
cudatoolkit 11.2.0 h73cb219_8 nvidia
cudatoolkit 11.2.1 h8204236_8 nvidia
cudatoolkit 11.2.2 he111cf0_8 nvidia
cudatoolkit 11.2.72 h2bc3f7f_0 nvidia

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment