Categories
Linux

How to Check CUDA Version on Ubuntu 18.04

Here you will learn how to check CUDA version on Ubuntu 18.04. The 3 methods are NVIDIA driver’s nvidia-smi, CUDA toolkit’s nvcc, and simply checking a file.

Prerequisite

Before we start, you should have installed NVIDIA driver on your system as well as Nvidia CUDA toolkit.

Method 1 — Use nvidia-smi from Nvidia Linux driver

The first way to check CUDA version is to run nvidia-smi that comes from your Ubuntu 18.04’s NVIDIA driver, specifically the NVIDIA-utils package. You can install either Nvidia driver from the official repository of Ubuntu, or from the NVIDIA website.

$ which nvidia-smi
/usr/bin/nvidia-smi
nvidia smi command from nvidia util package ubuntu 18 04

To use nvidia-smi to check your CUDA version on Ubuntu 18.04, directly run from command line

nvidia-smi

You will see similar output to the screenshot below. The details about the CUDA version is to the top right of the output. My version is 10.2 here. Whether you have 10.0, 10.1 or even the older 9.0 installed, it will differ.

Use nvidia smi to check cuda version on Ubuntu 18 04

Surprisingly, except for the CUDA version, you can also find more detail from nvidia-smi, such as driver version (440.64), GPU name, GPU fan ratio, power consumption / capacity, memory usage. Also you can find the processes that actually use the GPU.

Here is the full text output:

vh@varhowto-com:~$ nvidia-smi
Fri Aug 21 22:14:58 2020
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 440.64 Driver Version: 440.64 CUDA Version: 10.2 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 GeForce GTX 1070 Off | 00000000:01:00.0 On | N/A |
| 32% 49C P0 35W / 151W | 4422MiB / 8116MiB | 1% Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 2071 G /usr/lib/xorg/Xorg 73MiB |
| 0 2251 G /usr/bin/gnome-shell 51MiB |
| 0 7168 G /usr/lib/xorg/Xorg 2616MiB |
| 0 7284 G /usr/bin/gnome-shell 523MiB |
| 0 14958 G /usr/lib/rstudio/bin/rstudio 319MiB |
| 0 15193 G /usr/lib/rstudio/bin/rstudio 307MiB |
| 0 19471 G …AAAAAAAAAAAACAAAAAAAAAA= --shared-files 524MiB |
+-----------------------------------------------------------------------------+
vh@varhowto-com:~$

What is nvidia-smi?

nvidia-smi (NVSMI) is NVIDIA System Management Interface program. It is also known as NVSMI. nvidia-smi provides tracking and maintenance features for all of the Tesla, Quadro, GRID and GeForce NVIDIA GPUs and higher architectural families in Fermi. For most functions, GeForce Titan Series products are supported with only a limited amount of detail provided for the rest of the Geforce range.

NVSMI is also a cross-platform program which supports all common NVIDIA driver-supported Linux distros and 64-bit versions of Windows starting with Windows Server 2008 R2. Metrics can be used by users directly via stdout, or saved in CSV and XML formats for scripting purposes.

For more information, check out nvidia-smi‘s manpage.

Method 2 — Use nvcc to check CUDA version on Ubuntu 18.04

If you have installed the cuda-toolkit package either from Ubuntu 18.04’s or NVIDIA’s official Ubuntu 18.04 repository through sudo apt install nvidia-cuda-toolkit, or by downloading from NVIDIA’s official website and install it manually, you will have nvcc in your path ($PATH) and its location would be /usr/bin/nvcc (by running which nvcc).

nvcc command from the cuda toolkit package 1

To check the CUDA version with nvcc on Ubuntu 18.04, execute

nvcc --version

Different output can be seen in the screenshot below. The last line reveals a version of your CUDA version. This version here is 10.1. Yours may vary, and may be 10.0 or 10.2. You will see the full text output after the screenshot too.

Use nvcc version to check cuda version
vh@varhowto-com:~$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Sun_Jul_28_19:07:16_PDT_2019
Cuda compilation tools, release 10.1, V10.1.243

What is nvcc?

nvcc is the NVIDIA CUDA Compiler, thus the name. It is the main wrapper for the CUDA compiler suite. For the other use of nvcc, you can use it to compile and link both host and GPU code.

Check out the manpage of nvcc for more information.

Method 3 — cat /usr/local/cuda/version.txt

cat /usr/local/cuda/version.txt

Note that this method might not work on Ubuntu 18.04 if you install Nvidia driver and CUDA from Ubuntu 18.04’s own official repository.

cat usr local cuda version.txt ubuntu 20 04

3 ways to check CUDA version on Ubuntu 18.04

Time Needed : 5 minutes

There are three ways to identify the CUDA version on Ubuntu 18.04.

  1. The best way is by the NVIDIA driver's nvidia-smi command you may have installed.

    Simply run nvidia-smiUse nvidia smi to check cuda version on Ubuntu 18 04

  2. A simpler way is possibly to test a file, but this may not work on Ubuntu 18.04

    Run cat /usr/local/cuda/version.txt
    cat usr local cuda version.txt for TensorFlow

  3. Another approach is through the cuda-toolkit command nvcc.

    nvcc –versionUse nvcc version to check cuda version

Tools
  • nvcc
  • nvidia-smi
Materials
  • Ubuntu
  • PyTorch

+10

By VarHowto Editor

Welcome to VarHowto!

2 replies on “How to Check CUDA Version on Ubuntu 18.04”

What is nvidia-smi shows cuda version
but other 2 methods dont show anything ?
This is so confusing. how can one method say i have CUDA and other 2 says I dont have cuda.

+1

Method 1 is not completely right, nvidia-smi doesn’t show you the cuda version that you have installed, it shows you the latest cuda version that is compatible with your nvidia driver.

+4

Comments are closed.