When developing CUDA applications, the CUDA runtime version is an important piece of information. It can be used to determine the compatibility of CUDA code. You may need to retrieve the CUDA runtime version programmatically for various purposes, such as logging information, handling version-dependent features, verifying the version at runtime, etc. This tutorial explains how to get CUDA runtime version using C++.
The cudaRuntimeGetVersion
function can be used to get the CUDA runtime version. This function returns an integer representing the version of the current CUDA runtime that is currently loaded and active on the system. For example, CUDA 11.8.0 would be represented by integer 11080.
We then extract the major, minor, and patch version numbers from the runtimeVersion
variable using simple arithmetic operations, and print them to the console.
#include <iostream>
#include <cuda_runtime.h>
int main()
{
int runtimeVersion;
cudaRuntimeGetVersion(&runtimeVersion);
int major = runtimeVersion / 1000;
int minor = runtimeVersion % 1000 / 10;
int patch = runtimeVersion % 10;
std::cout << major << "." << minor << "." << patch << std::endl;
return 0;
}
Here's an example of the expected output when running the provided code:
11.8.0
Leave a Comment
Cancel reply