Print the CUDA version and CuDNN version in LibTorch

Is it possible to print the version of CUDA and cuDNN that a given build of LibTorch was compiled against in C++?

This post shows the corresponding calls.

1 Like
#include <torch/torch.h>
#include <ATen/cuda/CUDAContext.h>
using namespace std;

void print_LibtorchVersion() {
    cout << "PyTorch version: "
        << TORCH_VERSION_MAJOR << "."
        << TORCH_VERSION_MINOR << "."
        << TORCH_VERSION_PATCH << std::endl;
}

void print_CUDA_cuDNN_info() {
    long cudnn_version = at::detail::getCUDAHooks().versionCuDNN();
    cout << "The cuDNN version is " << cudnn_version <<"\n";
    int runtimeVersion;
    AT_CUDA_CHECK(cudaRuntimeGetVersion(&runtimeVersion));
    cout << "The CUDA runtime version is " << runtimeVersion << "\n";
    int version;
    AT_CUDA_CHECK(cudaDriverGetVersion(&version));
    cout << "The driver version is " << version << "\n";
}