How do you install CUDA 11 on Ubuntu 20.10 and verify the installation

49,877

Install the NVIDIA driver

This might be an optional step, but it is always good to first remove potential previously installed NVIDIA drivers:

sudo apt-get purge *nvidia*
sudo apt autoremove

Next, let's install the latest driver:

sudo apt install nvidia-driver-455

After this, we need to restart the computer to finalize the driver installation. Next we can verify whether the drive was succesfully installed:

nvidia-smi

This should contain the following or similar:

NVIDIA-SMI 455.28 Driver Version: 455.28

Install CUDA Toolkit

Next we can install the CUDA toolkit:

sudo apt install nvidia-cuda-toolkit

We also need to set the CUDA_PATH. Add this

export CUDA_PATH=/usr

at the end of your .bashrc and run

source ~/.bashrc

Now your CUDA installation should be complete, and

nvidia-smi

should indicate that you have CUDA 11.1 installed.

Test the CUDA toolkit installation /configuration

One of the best way to verify whether CUDA is properly installed is using the official "CUDA-sample". Ubuntu does not package them as part of "nvidia-cuda-toolkit" but we can download them directly from NVIDIA's github page:

wget https://github.com/NVIDIA/cuda-samples/archive/v11.1.tar.gz
tar xvf v11.1.tar.gz 
cd cuda-samples-11.1

For whatever reason, NVIDIA did not chose to include a modern build system (e.g. cmake), but ships a plain old Makefile instead. If just running "make" does not work for you, carefully read the error messages and see whether e.g. some required dependencies are not installed.

In order to help the build process a little, it might be advisable to specify the compute architecture of your GPU.

  1. You can find out your GPU by running nvidia-smi. Mine is a Quadro RTX 3000.
  2. Next google your GPU to find out the corresponding compute architecture. For the Quadro RTX 3000, it is "turing", version 7.5.
  3. Specify the architecture version when running make, e.g.
make SMS="75"

If the compilation was succesful, you can try out one of the samples. For instance:

./bin/x86_64/linux/release/immaTensorCoreGemm 

You should see the following or similar output:

M: 4096 (16 x 256)
N: 4096 (16 x 256)
K: 4096 (16 x 256)
Preparing data for GPU...
Required shared memory size: 64 Kb
Computing... using high performance kernel compute_gemm_imma 
Time: 6.030176 ms
TOPS: 22.79
Share:
49,877

Related videos on Youtube

Carlos Peña
Author by

Carlos Peña

Updated on September 18, 2022

Comments

  • Carlos Peña
    Carlos Peña 8 months

    There seem be be several options to install CUDA on Ubuntu 20.10: It is pre-bundled with 20.10, there are various installers at the official NVIDIA page, etc.

    Question: What is a recommended way to install CUDA 11.X on Ubuntu 20.10, and how do I verify the installation?

  • N0rbert
    N0rbert over 2 years
    This all is great, but the first command (sudo apt purge *nvidia*) will fail. Use apt-get instead.
  • Carlos Peña
    Carlos Peña over 2 years
    Thanks, corrected.
  • ubfan1
    ubfan1 over 2 years
    You might want to quote the "*nvidia*" so any files in your current working directory with "nvidia" in their names do not mess up the command.
  • Sephethus
    Sephethus over 2 years
    libcuda is not installed errors on make SMS="61"
  • Giorgos Sfikas
    Giorgos Sfikas over 2 years
    This installs nvcc of a lower version than the rest of the installation. This is not without problems, e.g. github.com/NVIDIA/cuda-samples/issues/57 where the older nvcc can't compile the newer (v11.2) code.
  • Neal Fultz
    Neal Fultz about 2 years
    I hit the same issue as @GiorgosSfikas - it looks like cuda v11.0 is in the ubuntu repos for 20.10, so I just downloaded the matching sample code to make it work. People should also check nvcc -V for the appropriate version.
  • plr
    plr about 2 years
    How do you check the architecture version? My GPU is a GeForce GTX 980, Maxwell architecture, but I seem to be unable to find the version to call make SMS="XX"
  • rob
    rob about 2 years
    sudo apt install nvidia-cuda-toolkit installs cuda 10.1 on Ubuntu 20.04. Not Cuda 11