How to Check Your CUDA Version on Ubuntu (Including cuDNN Compatibility Guide)

1. Introduction

CUDA (Compute Unified Device Architecture) is a parallel computing platform developed by NVIDIA that utilizes GPUs. It is widely used for machine learning, deep learning, 3D rendering, and many other computational workloads.

When using CUDA in an Ubuntu environment, it is important to check your CUDA version for the following reasons:

Driver Compatibility

CUDA supports only specific NVIDIA driver versions, and incompatibility can prevent CUDA from functioning correctly.

Library Compatibility

Libraries such as TensorFlow and PyTorch require specific versions of CUDA and cuDNN, so it is essential to verify that the correct versions are installed.

Avoiding Environment Conflicts

If multiple CUDA versions are installed on the system, you must know which version is currently active and switch between them as needed.

This guide clearly explains how to check the CUDA version on Ubuntu.

2. How to Check the CUDA Version on Ubuntu

In Ubuntu, you can check your CUDA version using the following methods.

Method 1: Check with nvidia-smi (Easiest Method)

The NVIDIA driver includes a tool called nvidia-smi (NVIDIA System Management Interface) that shows GPU information.

Command

nvidia-smi

Example Output

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 530.41.03    Driver Version: 530.41.03    CUDA Version: 12.1     |
+-----------------------------------------------------------------------------+

Key Points

  • The CUDA Version: 12.1 line shows the maximum CUDA version supported by the driver.
  • This may differ from the actual installed CUDA Toolkit version, so check the next methods as well.

Method 2: Check with nvcc -V (For Developers)

If CUDA is properly installed, you can check the version of nvcc, the CUDA compiler.

Command

nvcc -V

Example Output

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2023 NVIDIA Corporation
Built on Sun_Jul_30_19:09:40_PDT_2023
Cuda compilation tools, release 12.1, V12.1.105

Key Points

  • release 12.1, V12.1.105 → This indicates the installed CUDA Toolkit version.
  • It may not match the version shown by nvidia-smi.

Method 3: Check version.txt (Manual Check)

If CUDA is installed under /usr/local/cuda, the file version.txt contains version information.

Command

cat /usr/local/cuda/version.txt

Example Output

CUDA Version 12.1.105

Key Points

  • Useful when nvcc -V is unavailable.
  • You must ensure that /usr/local/cuda is correctly symlinked.

3. How to Check the cuDNN Version

cuDNN (CUDA Deep Neural Network) is a deep learning library used with CUDA.
It is important to check the cuDNN version along with CUDA.

Method 1: Check cudnn_version.h

The cuDNN version is stored in the header file cudnn_version.h.

Command

cat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR -A 2

Example Output

#define CUDNN_MAJOR 8
#define CUDNN_MINOR 9
#define CUDNN_PATCHLEVEL 1

Key Points

  • Indicates that cuDNN 8.9.1 is installed.
  • The grep command helps extract version info easily.
  • cuDNN and CUDA must be compatible; verify the correct pairing.

Method 2: Check with dpkg (Debian-Based Linux Only)

On Debian-based systems like Ubuntu, you can check installed cuDNN packages with dpkg.

Command

dpkg -l | grep libcudnn

Example Output

ii  libcudnn8    8.9.1-1+cuda12.1    amd64    NVIDIA cuDNN Library

Key Points

  • The cuDNN version (8.9.1) is shown in the package name.
  • cuda12.1 indicates the compatible CUDA version.

Use these methods to ensure your CUDA environment is configured correctly.

4. How to Handle Multiple Installed CUDA Versions

In Ubuntu, it is possible to install multiple versions of CUDA. However, this may cause confusion about which version is currently active.
In such cases, you must switch to the correct version manually.

Method 1: Switch Versions Using update-alternatives

Ubuntu allows you to switch between CUDA versions using the update-alternatives tool.

Check Current Settings

update-alternatives --query cuda

Switch Versions

sudo update-alternatives --config cuda

Example Output

There are 3 choices for the alternative cuda (providing /usr/local/cuda).

  Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /usr/local/cuda-11.8  100       auto mode
  1            /usr/local/cuda-10.2  50        manual mode
  2            /usr/local/cuda-11.8  100       manual mode
  3            /usr/local/cuda-12.1  110       manual mode

Press <enter> to keep the current choice[*], or type selection number:

Key Points

  • Running update-alternatives --config cuda displays all available CUDA versions.
  • You can select the version to use by entering the corresponding number.
  • auto mode and manual mode are available; choose manual mode for manual switching.

Method 2: Manually Configure Symbolic Links

You can also activate a specific CUDA version by manually adjusting symbolic links.

Check Existing Symlink

ls -l /usr/local/cuda

Example Output

lrwxrwxrwx 1 root root 20 Feb  1 12:34 /usr/local/cuda -> /usr/local/cuda-11.8

Change CUDA Version

sudo rm /usr/local/cuda
sudo ln -s /usr/local/cuda-12.1 /usr/local/cuda

Verify

ls -l /usr/local/cuda

Key Points

  • /usr/local/cuda is used as the default CUDA path, so updating this link switches the active version.
  • Using ln -s makes switching between versions easy.

By using these methods, you can manage multiple CUDA installations and ensure the correct version is active.

5. Frequently Asked Questions (FAQ)

This section summarizes common issues related to checking CUDA versions. Use it for troubleshooting.

Q1: nvcc -V is not found!

If the nvcc command is missing, the CUDA path may not be set.

Solution 1: Check if CUDA is installed

ls /usr/local/cuda/

Solution 2: Add nvcc to PATH

export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH

After this, run nvcc -V again to confirm it works.

Q2: Why is the CUDA version shown by nvidia-smi different?

The CUDA version shown by nvidia-smi represents the maximum CUDA version supported by the NVIDIA driver.

Check Example:

nvidia-smi

Example Output:

CUDA Version: 12.1

However, this does not indicate the installed CUDA Toolkit version. Use nvcc -V or version.txt to verify the actual installed version.

Q3: How do I check CUDA and cuDNN compatibility?

The most accurate way is to refer to NVIDIA’s official support matrix.

Official Site:

NVIDIA cuDNN Support Matrix

You should also confirm compatibility by checking the installed versions:

Check CUDA Version

nvcc -V

Check cuDNN Version

cat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR -A 2

By managing these versions appropriately, you can avoid issues related to CUDA and cuDNN.

6. Summary

This article explained how to check the CUDA version in an Ubuntu environment.
Let’s review the key points.

How to Check CUDA Versions

MethodCommandDescription
nvidia-sminvidia-smiShows the CUDA version supported by the driver
nvcc -Vnvcc -VShows the installed CUDA Toolkit version
version.txtcat /usr/local/cuda/version.txtManually check the installed CUDA version

How to Check cuDNN

MethodCommandDescription
cudnn_version.hcat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR -A 2Check version from the header file
dpkgdpkg -l | grep libcudnnCheck installed cuDNN packages

How to Switch CUDA Versions

MethodCommandDescription
update-alternativessudo update-alternatives --config cudaSwitch between multiple CUDA versions
Symbolic Linksudo ln -s /usr/local/cuda-XX.X /usr/local/cudaManually switch CUDA versions

Key Takeaways

  • Always verify your CUDA version before development
  • Check compatibility between CUDA and cuDNN
  • Understand how to switch versions when multiple CUDA installations exist

By properly managing your environment, you can maximize the performance and stability of CUDA.
We hope this guide helps you verify CUDA versions effectively on Ubuntu.

年収訴求