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