889

Is there any quick command or script to check for the version of CUDA installed?

I found the manual of 4.0 under the installation directory but I'm not sure whether it is of the actual installed version or not.

Alexander Abakumov
  • 13,617
  • 16
  • 88
  • 129
Hailiang Zhang
  • 17,604
  • 23
  • 71
  • 117
  • 3
    See also: [How to verify CuDNN installation?](http://stackoverflow.com/q/31326015/562769) – Martin Thoma Jan 02 '17 at 12:41
  • 6
    Which OS is this question targeting? – nbro Jan 11 '18 at 00:15
  • do you think about the installed and supported runtime or the installed SDK? – Alexander Stohr May 16 '19 at 15:18
  • 13
    @JaredHoberock `nvcc --version` produce `The program 'nvcc' is currently not installed. You can install it by typing: sudo apt install nvidia-cuda-toolkit` however `nvidia-smi` contain `CUDA Version: 10.1`. – mrgloom Aug 22 '19 at 13:27
  • 3
    But `cat /usr/local/cuda/version.txt` gives more precise version `CUDA Version 10.1.168` – mrgloom Aug 22 '19 at 13:29
  • Please search for conda if you need the question to be answered in that context. – questionto42 Jul 29 '20 at 22:45
  • If you are looking for the actual version digits as a string, in unix, you can use a mix of `nvidia-smi` to get the version, `grep` to identify the line, and `sed` to remove the unnecessary characters: `nvidia-smi | grep -o 'CUDA Version: [0-9].\.[0-9]' | sed 's/.*: //'` – Eduardo Pignatelli Feb 16 '21 at 20:33

31 Answers31

1141

As Jared mentions in a comment, from the command line:

nvcc --version

(or /usr/local/cuda/bin/nvcc --version) gives the CUDA compiler version (which matches the toolkit version).

From application code, you can query the runtime API version with

cudaRuntimeGetVersion()

or the driver API version with

cudaDriverGetVersion()

As Daniel points out, deviceQuery is an SDK sample app that queries the above, along with device capabilities.

As others note, you can also check the contents of the version.txt (.json in recent CUDA versions) using (e.g., on Mac or Linux)

cat /usr/local/cuda/version.txt

However, if there is another version of the CUDA toolkit installed other than the one symlinked from /usr/local/cuda, this may report an inaccurate version if another version is earlier in your PATH than the above, so use with caution.

paleonix
  • 2,293
  • 1
  • 13
  • 29
harrism
  • 26,505
  • 2
  • 57
  • 88
  • 10
    nvcc --version should work from the Windows command prompt assuming nvcc is in your path. – harrism Jan 14 '17 at 06:06
  • 22
    in Ubuntu you may need to install `nvidia-cuda-tools` to make this command to work. just type `sudo apt install nvidia-cuda-toolkit` – Oleg Kokorin Aug 24 '17 at 11:46
  • @OlegKokorin, if you're getting this advice from terminal, it seems you haven't CUDA installed. – VeLKerr Dec 24 '17 at 19:38
  • 20
    If you can't find `nvcc`, it should be in `/usr/local/cuda/bin/`. – Rush Mar 02 '18 at 19:17
  • 1
    Be aware that you might have two or more nvcc binaries installed on your system, so running `nvcc` may pick up an old version. This is actually a blessing in disguise, since you may find that you need to modify your PATH so it picks up the newer nvcc version. – Craig S. Anderson Feb 20 '19 at 20:06
  • 15
    Upvote for `cat /usr/local/cuda/version.txt`. Popular method with `nvcc --version` works if you have nvidia-toolkit installed, however, if you have only cuda runtime, nvcc might not exist. It might be the case @RutgerHofste pointed out. E.g. ([Tensorflow setup instructions](https://www.tensorflow.org/install/gpu#ubuntu_1804_cuda_10) do not install nvcc) – Kirill Pavlov Mar 24 '19 at 13:49
  • 5
    Both "/usr/local/cuda/bin/nvcc --version" and "nvcc --version" show different output. – kamran kausar Jun 11 '20 at 11:57
  • So your `PATH` probably includes a different `nvcc`. – harrism Jun 12 '20 at 01:22
  • nvcc --version tells you the version of the compiler. Moreover, installing `nvidia-cuda-tools` takes a major dump on your system that may end up with a version of nvcc that is different from your cuda drivers. Good grief is this answer poison! – user3673 Dec 03 '20 at 01:05
  • 1
    Also `/usr/lib/cuda/version.txt` – Memristor Mar 06 '21 at 16:40
  • 1
    nvcc --version was showing me different cuda version than the one on my machine. I had to update environment variables in .bashrc file for it show the correct version - PATH and LD_LIBRARY_PATH - https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#post-installation-actions – Gaurav Srivastava Jul 21 '21 at 17:47
  • Can you provide an example of how to run cudaRuntimeGetVersion() and cudaDriverGetVersion() from application code? – lightbox142 Aug 29 '23 at 16:55
275

[Edited answer. Thanks for everyone who corrected it]

If you run

nvidia-smi

You should find the CUDA Version *highest CUDA version the installed driver supports on the top right corner of the comand's output. At least I found that output for CUDA version 10.0 e.g., enter image description here

Note that this does not mean that CUDA 10.0 is installed. It may or may not be.

You can check via nvcc --version command if CUDA is really installed.

Note - Sometimes installing CUDA via some methods (.run file) by default also installs an NVIDIA driver or replaces the existing installed driver, and many people get confused regarding this. However, installing a driver via CUDA installation may not get you the most updated or suitable driver for your GPU. This is a more complex topic.

Alex Punnen
  • 5,287
  • 3
  • 59
  • 71
mostafa.elhoushi
  • 3,758
  • 1
  • 17
  • 10
  • 10
    Looks like `nvidia-smi` only outputs driver version for older versions. – mrgloom Jun 14 '19 at 12:55
  • 67
    That CUDA Version display only works for driver version after 410.72. And it will display CUDA Version even when no CUDA is installed. So this information not make any sense currently. Reference: https://devtalk.nvidia.com/default/topic/1045528/nvidia-smi-doesn-t-show-cuda-version-even-after-installation/ – Bruce Yo Sep 24 '19 at 02:48
  • 61
    This answer is incorrect, That only indicates the driver CUDA version support. It does not provide any information about which CUDA version is installed or even whether there is CUDA installed at all – talonmies Nov 10 '19 at 20:09
  • 5
    This cuda version only shows the gpu cuda capabilities and not the cuda version used for runtime api. – monti May 28 '20 at 10:33
  • 23
    `nvcc --version` and `nvidia-smi` did not give me the same CUDA version. And it turns out yours (`nvidia-smi`) was the wrong one. – scottlittle Sep 27 '20 at 01:16
  • 13
    nvidia-smi only displays the highest compatible cuda version for the installed driver. This is not necessarily the cuda version that is currently installed ! – Pidem Oct 29 '20 at 16:11
  • 3
    This answer is factually wrong. `nvidia-smi` displays the highest CUDA version the installed driver supports. Please edit. – bviktor Apr 11 '22 at 12:49
  • What's the difference between "the highest compatible cuda version for the installed driver" and the currently installed CUDA version? – HappyFace May 11 '23 at 10:31
  • @HappyFace my understanding is that the currently installed CUDA version is the version of CUDA that is actually installed on your machine. The driver on a machine can suport multiple versions of CUDA, so "the highest compatible cuda version for the installed driver" tells you to what CUDA version you can upgrade to. – mostafa.elhoushi May 17 '23 at 11:23
228

On Ubuntu Cuda V8:

$ cat /usr/local/cuda/version.txt
  

You can also get some insights into which CUDA versions are installed with:

$ ls -l /usr/local | grep cuda

which will give you something like this:

lrwxrwxrwx  1 root root    9 Mar  5  2020 cuda -> cuda-10.2
drwxr-xr-x 16 root root 4096 Mar  5  2020 cuda-10.2
drwxr-xr-x 16 root root 4096 Mar  5  2020 cuda-8.0.61

Given a sane PATH, the version cuda points to should be the active one (10.2 in this case).

NOTE: This only works if you are willing to assume CUDA is installed under /usr/local/cuda (which is true for the independent installer with the default location, but not true e.g. for distributions with CUDA integrated as a package). Ref: comment from @einpoklum.

drevicko
  • 14,382
  • 15
  • 75
  • 97
mwweb
  • 7,625
  • 4
  • 19
  • 24
  • 11
    this is more versatile than harrism's answer since it doesn't require installing `nvcc` (which requires admin privileges) – dinosaur Dec 13 '17 at 00:46
  • 1
    Works on AWS Linux Deep Learning AMI – Rutger Hofste Feb 01 '18 at 14:38
  • 21
    using this I get "CUDA Version 8.0.61" but nvcc --version gives me "Cuda compilation tools, release 7.5, V7.5.17" do you know the reason for the missmatch? – martinako Mar 21 '18 at 15:07
  • 1
    Upvoted for being the more correct answer, my CUDA version is 9.0.176 and was nowhere mentioned in nvcc -V – Kalpit May 24 '18 at 09:41
  • I get a file not found error, but nvcc reports version 8.0. /usr/local/cuda does not exist.. – Elias Jul 17 '18 at 14:35
  • This answer is not more correct. If `/usr/local/cuda/version.txt` does not match the output of `nvcc --version` then there is another version of the CUDA toolkit that appears in your `PATH` before the one symlinked from `/usr/local/cuda`. Check your `PATH` settings. I've updated my answer. – harrism Jul 26 '18 at 07:13
  • @dinosaur Why would you have a CUDA version.txt but not nvcc installed? I don't think this is possible unless `nvcc` was removed after it was installed. – harrism Jul 26 '18 at 07:14
  • found mine in `/usr/lib/cuda/version.txt` – CpILL Sep 10 '19 at 03:15
  • @martinako I guess you have updated cuda without installing an updated nvcc. Have a look at `ls -l /usr/local | grep cuda` to get an idea of which versions you have installed. The one /usr/local/cuda (which should be a symlink) points to should be the default version seen by the system. – drevicko Mar 11 '21 at 00:33
  • I agree, now it's `cat /usr/lib/cuda/version.json` – pg0xC May 31 '21 at 20:40
41

For CUDA version:

nvcc --version

Or use,

nvidia-smi

For cuDNN version:

For Linux:

Use following to find path for cuDNN:

$ whereis cuda
cuda: /usr/local/cuda

Then use this to get version from header file,

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

For Windows,

Use following to find path for cuDNN:

C:\>where cudnn*
C:\Program Files\cuDNN7\cuda\bin\cudnn64_7.dll

Then use this to dump version from header file,

type "%PROGRAMFILES%\cuDNN7\cuda\include\cudnn.h" | findstr CUDNN_MAJOR

If you're getting two different versions for CUDA on Windows - Different CUDA versions shown by nvcc and NVIDIA-smi

Shital Shah
  • 63,284
  • 17
  • 238
  • 185
  • 1
    you are talking about CUDA SDK. maybe the question was on CUDA runtime and drivers - then this wont fit. (or maybe the question is about compute capability - but not sure if that is the case.) – Alexander Stohr May 16 '19 at 15:23
  • nvcc is a binary and will report its version. you can have multiple versions side to side in serparate subdirs. /usr/local/cuda is an optional symlink and its probably only present if the CUDA SDK is installed. – Alexander Stohr May 16 '19 at 15:24
  • 1
    @Lorenz - in some instances I didn't had nvidia-smi installed. Also, when you are debugging it is good to know where things are. If you want to uninstall cuda on Linux, many times your only option is to manually find versions and delete them. Also, notice that answer contains CUDA as well as cuDNN, later is not shown by smi. I've updated answer to use nvidia-smi just in case if your only interest is the version number for CUDA. – Shital Shah Aug 02 '20 at 05:01
  • The aim was to get @Mircea's comment deleted, I did not mean your answer. It was not my intention to get nvidia-smi mentioned in your answer. It is already wrong to name nvidia-smi at all! It is not an answer to the question of this thread. If you desparately want to name it, you must make clear that it does not show the installed version, but only the supported version. Your answer, as it is now, does not make this clear, and is thus wrong in this point. – questionto42 Aug 03 '20 at 15:01
  • For Linux it was actually in `cat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR -A 2` and for a conda environment: `cat /opt/anaconda3/envs/tensorflow-gpu-2.6/include/cudnn_version.h | grep CUDNN_MAJOR -A 2` – Gabriel Cretin Nov 30 '21 at 10:45
  • 1
    `nvidia-smi` does NOT have anything to do with the installed CUDA version. It doesn't even come with the CUDA toolkit, it comes from the NV driver package. It displays the max supported CUDA version, that is all. – bviktor Apr 11 '22 at 12:52
34

Other respondents have already described which commands can be used to check the CUDA version. Here, I'll describe how to turn the output of those commands into an environment variable of the form "10.2", "11.0", etc.

To recap, you can use

nvcc --version

to find out the CUDA version. I think this should be your first port of call. If you have multiple versions of CUDA installed, this command should print out the version for the copy which is highest on your PATH.

The output looks like this:

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2020 NVIDIA Corporation
Built on Thu_Jun_11_22:26:38_PDT_2020
Cuda compilation tools, release 11.0, V11.0.194
Build cuda_11.0_bu.TC445_37.28540450_0

We can pass this output through sed to pick out just the MAJOR.MINOR release version number.

CUDA_VERSION=$(nvcc --version | sed -n 's/^.*release \([0-9]\+\.[0-9]\+\).*$/\1/p')

If nvcc isn't on your path, you should be able to run it by specifying the full path to the default location of nvcc instead.

/usr/local/cuda/bin/nvcc --version

The output of which is the same as above, and it can be parsed in the same way.

Alternatively, you can find the CUDA version from the version.txt file.

cat /usr/local/cuda/version.txt

The output of which

CUDA Version 10.1.243

can be parsed using sed to pick out just the MAJOR.MINOR release version number.

CUDA_VERSION=$(cat /usr/local/cuda/version.txt | sed 's/.* \([0-9]\+\.[0-9]\+\).*/\1/')

Note that sometimes the version.txt file refers to a different CUDA installation than the nvcc --version. In this scenario, the nvcc version should be the version you're actually using.

We can combine these three methods together in order to robustly get the CUDA version as follows:

if nvcc --version 2&> /dev/null; then
    # Determine CUDA version using default nvcc binary
    CUDA_VERSION=$(nvcc --version | sed -n 's/^.*release \([0-9]\+\.[0-9]\+\).*$/\1/p');

elif /usr/local/cuda/bin/nvcc --version 2&> /dev/null; then
    # Determine CUDA version using /usr/local/cuda/bin/nvcc binary
    CUDA_VERSION=$(/usr/local/cuda/bin/nvcc --version | sed -n 's/^.*release \([0-9]\+\.[0-9]\+\).*$/\1/p');

elif [ -f "/usr/local/cuda/version.txt" ]; then
    # Determine CUDA version using /usr/local/cuda/version.txt file
    CUDA_VERSION=$(cat /usr/local/cuda/version.txt | sed 's/.* \([0-9]\+\.[0-9]\+\).*/\1/')

else
    CUDA_VERSION=""

fi

This environment variable is useful for downstream installations, such as when pip installing a copy of pytorch that was compiled for the correct CUDA version.

python -m pip install \
    "torch==1.9.0+cu${CUDA_VERSION/./}" \
    "torchvision==0.10.0+cu${CUDA_VERSION/./}" \
    -f https://download.pytorch.org/whl/torch_stable.html

Similarly, you could install the CPU version of pytorch when CUDA is not installed.

if [ "$CUDA_VERSION" = "" ]; then
    MOD="+cpu";
    echo "Warning: Installing CPU-only version of pytorch"
else
    MOD="+cu${CUDA_VERSION/./}";
    echo "Installing pytorch with $MOD"
fi

python -m pip install \
    "torch==1.9.0${MOD}" \
    "torchvision==0.10.0${MOD}" \
    -f https://download.pytorch.org/whl/torch_stable.html

But be careful with this because you can accidentally install a CPU-only version when you meant to have GPU support. For example, if you run the install script on a server's login node which doesn't have GPUs and your jobs will be deployed onto nodes which do have GPUs. In this case, the login node will typically not have CUDA installed.

scottclowe
  • 2,015
  • 19
  • 20
  • Nice solution. I have an Ubuntu 18.04 installation that reports CUDA_VERSION 9.1 but can run PyTorch with cu10.1. Not sure how that works. – Jason Harrison Jun 03 '22 at 18:00
  • GPU vs CPU: this can be switched at run time so you can decide then. – Jason Harrison Jun 03 '22 at 18:01
  • @JasonHarrison If you have a GPU, you can install the GPU version and pick whether to run on GPU or CPU at runtime. If you don't have a GPU, you might want to save a lot of disk space by installing the CPU-only version of pytorch. I believe pytorch installations actually ship with a vendored copy of CUDA included, hence you can install and run pytorch with different versions CUDA to what you have installed on your system. – scottclowe Jun 13 '22 at 23:51
31

Use the following command to check CUDA installation by Conda:

conda list cudatoolkit

And the following command to check CUDNN version installed by conda:

conda list cudnn

If you want to install/update CUDA and CUDNN through CONDA, please use the following commands:

conda install -c anaconda cudatoolkit
conda install -c anaconda cudnn

Alternatively you can use following commands to check CUDA installation:

nvidia-smi

OR

nvcc --version

If you are using tensorflow-gpu through Anaconda package (You can verify this by simply opening Python in console and check if the default python shows Anaconda, Inc. when it starts, or you can run which python and check the location), then manually installing CUDA and CUDNN will most probably not work. You will have to update through conda instead.

If you want to install CUDA, CUDNN, or tensorflow-gpu manually, you can check out the instructions here https://www.tensorflow.org/install/gpu

SidK
  • 1,174
  • 1
  • 9
  • 9
  • 5
    `nvidia-smi` does not give you the installed version, just the supported one, which is of no use for the question, see the comments under the answer of @mostafa.elhoushi. – questionto42 Jul 29 '20 at 21:20
  • 2
    `nvcc --version` is not working in anaconda prompt if you have the cuda toolkit installed with conda, and it is a repetition of the accepted answer if you mean it outside of anaconda prompt for a non-conda installation. – questionto42 Jul 29 '20 at 21:22
  • Mind that in conda, you should not separately install cudatoolkit if you want to install it for pytorch. Have a look at https://stackoverflow.com/questions/53102436/pytorch-cuda-with-anaconda-not-available/63162492#63162492 for details. – questionto42 Jul 29 '20 at 21:25
  • 1
    Upvote for how to check if cuda is installed in anaconda. – questionto42 Jul 29 '20 at 21:27
24

On Ubuntu :

Try

$ cat /usr/local/cuda/version.txt or $ cat /usr/local/cuda-8.0/version.txt

Sometimes the folder is named "Cuda-version".

If none of above works, try going to $ /usr/local/ And find the correct name of your Cuda folder.

Output should be similar to: CUDA Version 8.0.61

Emir Husic
  • 717
  • 5
  • 16
12

If you have installed CUDA SDK, you can run "deviceQuery" to see the version of CUDA

Daniel
  • 137
  • 4
  • 7
    For those wondering: `deviceQuery` is a sample program to build (Linux: run `make` in `/usr/local/cuda/samples`, then `./bin/x86_64/linux/release/deviceQuery`). – Matthieu Sep 29 '17 at 14:18
  • Nowadays the samples are not included with the CUDA Toolkit anymore. You can find them on [Github](https://github.com/NVIDIA/cuda-samples) instead. This particular one is located under `Samples/1_Utilities`. – paleonix Apr 28 '23 at 13:58
9

If you have PyTorch installed, you can simply run the following code in your IDE:

import torch

print(torch.version.cuda)
HexNeural
  • 163
  • 2
  • 6
  • 4
    Warning: This will tell you the version of cuda that PyTorch was built against, but not necessarily the version of PyTorch that you could install. – Jason Harrison Jun 03 '22 at 17:35
5

You might find CUDA-Z useful, here is a quote from their Site:

"This program was born as a parody of another Z-utilities such as CPU-Z and GPU-Z. CUDA-Z shows some basic information about CUDA-enabled GPUs and GPGPUs. It works with nVIDIA Geforce, Quadro and Tesla cards, ION chipsets."

http://cuda-z.sourceforge.net/

On the Support Tab there is the URL for the Source Code: http://sourceforge.net/p/cuda-z/code/ and the download is not actually an Installer but the Executable itself (no installation, so this is "quick").

This Utility provides lots of information and if you need to know how it was derived there is the Source to look at. There are other Utilities similar to this that you might search for.

Rob
  • 1,487
  • 2
  • 25
  • 29
  • this is a program for the Windows platform. will it be useable from inside a script? – Alexander Stohr May 16 '19 at 15:22
  • Looking at the various tabs I couldn't find any useful information about CUDA. – Redoman Jun 19 '21 at 11:42
  • It's for Linux, Windows, and Mac: https://sourceforge.net/p/cuda-z/code/HEAD/tree/qt-s-mini/4.8.6/ - check the Trunk for the source: https://sourceforge.net/p/cuda-z/code/HEAD/tree/trunk/ – Rob Jun 19 '21 at 11:51
5

One can get the cuda version by typing the following in the terminal:

$ nvcc -V

# below is the result
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Nov__3_21:07:56_CDT_2017
Cuda compilation tools, release 9.1, V9.1.85

Alternatively, one can manually check for the version by first finding out the installation directory using:

$ whereis -b cuda         
cuda: /usr/local/cuda

And then cd into that directory and check for the CUDA version.

kmario23
  • 57,311
  • 13
  • 161
  • 150
5

On Windows 10, I found nvidia-smi.exe in 'C:\Program Files\NVIDIA Corporation\NVSMI'; after cd into that folder (was not in the PATH in my case) and '.\nvidia-smi.exe' it showed enter image description here

  • 3
    This does not show the currently installed CUDA version but only the highest compatible CUDA version available for your GPU. See comments to this other answer https://stackoverflow.com/a/55717476/988591. – Redoman Jun 19 '21 at 11:45
4

if nvcc --version is not working for you then use cat /usr/local/cuda/version.txt

James McGuigan
  • 7,542
  • 4
  • 26
  • 29
Nassima Noufail
  • 177
  • 1
  • 2
3

First you should find where Cuda installed.

If it's a default installation like here the location should be:

for ubuntu:

/usr/local/cuda

in this folder you should have a file

version.txt

open this file with any text editor or run:

cat version.txt

from the folder

OR

 cat /usr/local/cuda/version.txt 
ChaosPredictor
  • 3,777
  • 1
  • 36
  • 46
3

We have three ways to check Version: In my case below is the output:- Way 1:-

cat /usr/local/cuda/version.txt

Output:-

CUDA Version 10.1.243

Way2:-

nvcc --version

Output:-

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Nov__3_21:07:56_CDT_2017
Cuda compilation tools, release 9.1, V9.1.85

Way3:-

/usr/local/cuda/bin/nvcc --version

Output:-

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

Way4:-

nvidia-smi
NVIDIA-SMI 450.36.06    Driver Version: 450.36.06    CUDA Version: 11.0

Outputs are not same. Don't know why it's happening.

kamran kausar
  • 4,117
  • 1
  • 23
  • 17
3

If you have multiple CUDA installed, the one loaded in your system is CUDA associated with "nvcc". Therefore, "nvcc --version" shows what you want.

Y Tao
  • 47
  • 4
3

On Windows 11 with CUDA 11.6.1, this worked for me:

cat "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\version.json"
Neele22
  • 373
  • 2
  • 18
2

After installing CUDA one can check the versions by: nvcc -V

I have installed both 5.0 and 5.5 so it gives

Cuda Compilation Tools,release 5.5,V5.5,0

This command works for both Windows and Ubuntu.

2

Apart from the ones mentioned above, your CUDA installations path (if not changed during setup) typically contains the version number

doing a which nvcc should give the path and that will give you the version

PS: This is a quick and dirty way, the above answers are more elegant and will result in the right version with considerable effort

Sandeep Raju Prabhakar
  • 18,652
  • 8
  • 35
  • 44
2

If you are running on linux:

dpkg -l | grep cuda
Ali AzG
  • 1,861
  • 2
  • 18
  • 28
Pidem
  • 260
  • 2
  • 13
2

Using tensorflow:

import tensorflow as tf
from tensorflow.python.platform import build_info as build
print(f"tensorflow version: {tf.__version__}")
print(f"Cuda Version: {build.build_info['cuda_version']}")
print(f"Cudnn version: {build.build_info['cudnn_version']}")

tensorflow version: 2.4.0

Cuda Version: 11.0

Cudnn version: 8

Roushan
  • 4,074
  • 3
  • 21
  • 38
2

I wanted to know this info as well so that I could install PyTorch such that it could take advantage of my GPUs on my Window 10 system. I was able to find this information from my NVidia Control Panel. If you have a Windows system and don't have this installed, you can get it here:

https://nvidia.custhelp.com/app/answers/detail/a_id/4733/~/nvidia-control-panel-windows-store-app

Once this is installed, find and launch the NVIDIA Control Panel:

enter image description here

Once it's up, at the bottom left corner, click on the **onc sec, ** link:

enter image description here

From this page, click the Components tab. This is how I found out I had CUDA 11.7 installed.

enter image description here

Michael Szczepaniak
  • 1,970
  • 26
  • 35
0

i get /usr/local - no such file or directory. Though nvcc -V gives

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2016 NVIDIA Corporation
Built on Sun_Sep__4_22:14:01_CDT_2016
Cuda compilation tools, release 8.0, V8.0.44
0

Programmatically with the CUDA Runtime API C++ wrappers (caveat: I'm the author):

auto v1 = cuda::version::maximum_supported_by_driver();
auto v2 = cuda::version::runtime();

This gives you a cuda::version_t structure, which you can compare and also print/stream e.g.:

if (v2 < cuda::version_t{ 8, 0 } ) {
    std::cerr << "CUDA version " << v2 << " is insufficient." std::endl;
}
einpoklum
  • 118,144
  • 57
  • 340
  • 684
  • Can you suggest a way to do this without compiling C++ code? In a previous comment, you mention `cat /usr/local/cuda/version.txt` no longer works with CUDA 11... – drevicko Mar 11 '21 at 01:05
  • @drevicko: well, try [this](https://stackoverflow.com/a/66001811/1593077), or several other answers here on this page. – einpoklum Mar 11 '21 at 09:08
  • ok. I was hoping to avoid installing the CUDA SDK (needed for nvcc, as I understand). Using nvidia-smi is unreliable. The folder linked from /usr/local/cuda (which ought to be a symlink) seems a good option: does that fit with what you know and work for CUDA 11? – drevicko Mar 12 '21 at 00:31
  • 1
    @drevicko: Yes, if you are willing to assume CUDA is installed under `/usr/local/cuda` (which is true for the independent installer with the default location, but not true e.g. for distributions with CUDA integrated as a package) - then looking at the symlink is sufficient. – einpoklum Mar 12 '21 at 10:19
  • I found `/usr/local/cuda/version.json` which has cuda related package and versions. I am using Ubuntu 20.04 – panc Sep 17 '21 at 05:15
0

Found mine after:

whereis cuda

at

cuda: /usr/lib/cuda /usr/include/cuda.h

with

nvcc --version

CUDA Version 9.1.85

VM47
  • 89
  • 6
0

Open a terminal and run these commands:

cd /usr/local/cuda/samples/1_Utilities/deviceQuery
sudo make
./deviceQuery

You can get the information of CUDA Driver version, CUDA Runtime Version, and also detailed information for GPU(s). An image example of the output from my end is as below.

You can find the image here.

Xingang
  • 17
  • 1
0

On my cuda-11.6.0 installation, the information can be found in /usr/local/cuda/version.json. It contains the full version number (11.6.0 instead of 11.6 as shown by nvidia-smi.

The information can be retrieved as follows:

python -c 'import json; print(json.load(open("/usr/local/cuda/version.json"))["cuda"]["version"])'
ognum
  • 31
  • 2
0

Assuming CUDA was installed on Ubuntu (arguably the most common system for ML/DL), we can use apt to get both CUDA and cuDNN library versions installed in the current (container) system:

$ apt list --installed | grep cud

Sample output:

$ docker run -it --rm mirekphd/cuda-11.2-cudnn8-devel-ubuntu22.04:latest apt list --installed | grep cud

cuda-command-line-tools-11-2/now 11.2.2-1 amd64 [installed,local]
cuda-compat-11-2/now 460.106.00-1 amd64 [installed,local]
cuda-compiler-11-2/now 11.2.2-1 amd64 [installed,local]
cuda-cudart-11-2/now 11.2.152-1 amd64 [installed,local]
cuda-cudart-dev-11-2/now 11.2.152-1 amd64 [installed,local]
cuda-cuobjdump-11-2/now 11.2.152-1 amd64 [installed,local]
cuda-cupti-11-2/now 11.2.152-1 amd64 [installed,local]
cuda-cupti-dev-11-2/now 11.2.152-1 amd64 [installed,local]
cuda-cuxxfilt-11-2/now 11.2.152-1 amd64 [installed,local]
cuda-driver-dev-11-2/now 11.2.152-1 amd64 [installed,local]
cuda-gdb-11-2/now 11.2.152-1 amd64 [installed,local]
cuda-keyring/now 1.1-1 all [installed,local]
cuda-libraries-dev-11-2/now 11.2.2-1 amd64 [installed,local]
cuda-memcheck-11-2/now 11.2.152-1 amd64 [installed,local]
cuda-minimal-build-11-2/now 11.2.2-1 amd64 [installed,local]
cuda-nvcc-11-2/now 11.2.152-1 amd64 [installed,local]
cuda-nvdisasm-11-2/now 11.2.152-1 amd64 [installed,local]
cuda-nvml-dev-11-2/now 11.2.152-1 amd64 [installed,local]
cuda-nvprof-11-2/now 11.2.152-1 amd64 [installed,local]
cuda-nvprune-11-2/now 11.2.152-1 amd64 [installed,local]
cuda-nvrtc-11-2/now 11.2.152-1 amd64 [installed,local]
cuda-nvrtc-dev-11-2/now 11.2.152-1 amd64 [installed,local]
cuda-nvtx-11-2/now 11.2.152-1 amd64 [installed,local]
cuda-sanitizer-11-2/now 11.2.152-1 amd64 [installed,local]
libcudnn8-dev/now 8.1.1.33-1+cuda11.2 amd64 [installed,local]
libcudnn8/now 8.1.1.33-1+cuda11.2 amd64 [installed,local]
libnccl-dev/now 2.18.1-1+cuda12.1 amd64 [installed,local]
libnccl2/now 2.18.1-1+cuda12.1 amd64 [installed,local]
mirekphd
  • 4,799
  • 3
  • 38
  • 59
-1

You can check the version of CUDA using

nvcc -V

or you can use

nvcc --version

or You can check the location of where the CUDA is using

whereis cuda 

and then do

cat location/of/cuda/you/got/from/above/command
David Buck
  • 3,752
  • 35
  • 31
  • 35
-1

To verify the CUDA version installed on your machine, you can use the nvidia-smi command in the terminal.

The output should look something like this:

+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 535.54.03              Driver Version: 535.54.03    CUDA Version: 12.2     |
|-----------------------------------------+----------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |         Memory-Usage | GPU-Util  Compute M. |
|                                         |                      |               MIG M. |
|=========================================+======================+======================|
|   0  NVIDIA GeForce GT 1030         Off | 00000000:43:00.0 Off |                  N/A |
| 35%   28C    P8              N/A /  30W |    255MiB /  2048MiB |      0%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+

+---------------------------------------------------------------------------------------+
| Processes:                                                                            |
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
|        ID   ID                                                             Usage      |
|=======================================================================================|
|    0   N/A  N/A      4396      G   /usr/libexec/Xorg                            63MiB |
|    0   N/A  N/A      4521      G   /usr/bin/gnome-shell                        190MiB |
+---------------------------------------------------------------------------------------+
nikhil int
  • 181
  • 2
  • 14
-3

If there is a version mismatch between nvcc and nvidia-smi then different versions of cuda are used as driver and run time environemtn.

To ensure same version of CUDA drivers are used what you need to do is to get CUDA on system path.

First run whereis cuda and find the location of cuda driver.

Then go to .bashrc and modify the path variable and set the directory precedence order of search using variable 'LD_LIBRARY_PATH'.

for instance

$ whereis cuda
cuda: /usr/lib/cuda /usr/include/cuda.h /usr/local/cuda

CUDA is installed at /usr/local/cuda, now we need to to .bashrc and add the path variable as:

vim  ~/.bashrc
export PATH="/usr/local/cuda/bin:${PATH}"

and after this line set the directory search path as:

export LD_LIBRARY_PATH="/usr/local/cuda/lib64:${LD_LIBRARY_PATH}"

Then save the .bashrc file. And refresh it as:

$ source ~/.bashrc

This will ensure you have nvcc -V and nvidia-smi to use the same version of drivers.

Tanveer
  • 890
  • 12
  • 22