how to know cuda version

How to Know CUDA Version

If you are working with CUDA, it is crucial to know the version installed on your system. Here are a few methods to determine the CUDA version.

Method 1: nvcc Compiler

  1. Open a terminal or command prompt.
  2. Run the following command: nvcc --version.

Example output:
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Sun_Jul_11_22:07:18_PDT_2021
Cuda compilation tools, release 11.4, V11.4.100
Build cuda_11.4.r11.4/compiler.30274561_0

In this example, the CUDA version is 11.4.

Method 2: NVIDIA-SMI Tool

  1. Open a terminal or command prompt.
  2. Run the following command: nvidia-smi.

Example output (partially shown):
Fri Nov 19 10:21:31 2021
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 465.19.01 Driver Version: 465.19.01 CUDA Version: 11.3 |
|-------------------------------+----------------------+----------------------+

In this example, the CUDA version is 11.3.

Method 3: CUDA Runtime API

  1. Create a C++ source file, e.g., cuda_version.cpp, using a text editor.
  2. Paste the following code into the file:

“`cpp
#include
#include

int main() {
int cudaVersion;
cudaRuntimeGetVersion(&cudaVersion);
std::cout << “CUDA Version: ” << cudaVersion / 1000 << “.” << cudaVersion % 1000 << std::endl;
return 0;
}
“`

  1. Save the file and exit the text editor.
  2. Compile the source file using the CUDA toolkit.

Example command: nvcc cuda_version.cpp -o cuda_version

  1. Run the compiled program: ./cuda_version.

Example output:
CUDA Version: 11.4

In this example, the CUDA version is 11.4.

By following these methods, you can easily determine the CUDA version installed on your system.