CUDA and CuDNN version for libtorch

Hi @ptrblck

I want to know what libtorch API that we can use to get the CUDA and CuDNN version?
Ps:
Right now I have a project that using both opencv DNN and Libtorch, but I keep getting warning because unmatch cudnn version. I use pre-built libtorch library.

best regards,
Albert Christianto

For cuDNN:

long cudnn_version = at::detail::getCUDAHooks().versionCuDNN();

for CUDA runtime:

int runtimeVersion;
AT_CUDA_CHECK(cudaRuntimeGetVersion(&runtimeVersion));

for the driver version:

int version;
AT_CUDA_CHECK(cudaDriverGetVersion(&version));

In case you want to use checks in the code you could also use e.g.:

#if defined(CUDA_VERSION) && CUDA_VERSION >= 11200
1 Like

@ptrblck what are your include headers and namespace declarations?

#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 << 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";
}