Sometimes, it may be necessary programmatically to retrieve the latest version of CUDA supported by the installed GPU driver for troubleshooting, compatibility checks, or other purposes. This tutorial demonstrates how to get CUDA driver version using C++.
The cudaDriverGetVersion
function can be used to get the latest version of CUDA supported by the GPU driver. The version is returned as an integer. For example, CUDA 12.1.0 would be represented by integer 12010.
Using arithmetic operations, the major, minor, and patch version numbers are extracted from the driverVersion
variable, and printed to the console.
#include <iostream>
#include <cuda_runtime.h>
int main()
{
int driverVersion;
cudaDriverGetVersion(&driverVersion);
int major = driverVersion / 1000;
int minor = driverVersion % 1000 / 10;
int patch = driverVersion % 10;
std::cout << major << "." << minor << "." << patch << std::endl;
return 0;
}
Here's an example of the console output you might see when running the provided code:
12.1.0
Leave a Comment
Cancel reply