Install CUDA & cuDNN on Ubuntu

Posted by hnqiu on November 7, 2021

Introduction

This post presents the steps to install CUDA 11.4 and cuDNN v8.2 on Ubuntu 18.04.

CUDA How-to

  • Install the NVIDIA GPU driver in the Ubuntu Software & Updates panel and reboot the system to allow the driver to take effect
    image
  • Check if the GPU is CUDA-capable and if the system meets the CUDA requirements (e.g., Ubuntu version, gcc, kernel) following Step 1 and Step 2 in the installation guide
  • Download the CUDA Toolkit from https://developer.nvidia.com/cuda-toolkit-archive and install following the instructions. Reboot the system to load the CUDA driver
  • Set up the development environment
    Add the following into ~/.bashrc and source it
    export PATH=/usr/local/cuda-11.4/bin${PATH:+:${PATH}}
    export LD_LIBRARY_PATH=/usr/local/cuda-11.4/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
    
  • Run sample tests
    cd ~/Desktop
    cuda-install-samples-11.4.sh .
    cd NVIDIA_CUDA-11.4_Samples/5_Simulations/nbody
    make
    ./nbody
    

Useful commands

  • Check NVIDIA driver
    nvidia-smi
    
  • Check CUDA info
    nvcc --version
    

Install cuDNN

  • Go to cuDNN home page and click Download cuDNN. Log in and download the following archive:
    cuDNN Library for Linux (x86_64)
    
  • Extract archive
    tar -xvf cudnn-linux-x64...tgz
    
  • Install files
    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*