#include <cuda_runtime.h>
#include <torch/torch.h>
#include <iostream>
int main() {
std::cout << "CUDA device count: " << torch::cuda::device_count() << std::endl;
std::cout << "CUDA is available: " << (torch::cuda::is_available() ? "Yes" : "No") << std::endl;
std::cout << "cuDNN is available: " << (torch::cuda::cudnn_is_available() ? "Yes" : "No") << std::endl;
int deviceCount;
cudaGetDeviceCount(&deviceCount);
std::cout << "Number of CUDA devices: " << deviceCount << std::endl;
return 0;
}
Output:
CUDA device count: 0
CUDA is available: No
cuDNN is available: No
Number of CUDA devices: 1
runtime seems to work, torch won't show CUDA
I'm using MSVC 2022, windows 11. I installed latest pytorch with CUDA support
libtorch-win-shared-with-deps-2.4.0+cu124.zip
(I also tried release), my nvcc --version
shows:
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2024 NVIDIA Corporation
Built on Fri_Jun_14_16:44:19_Pacific_Daylight_Time_2024
Cuda compilation tools, release 12.6, V12.6.20
Build cuda_12.6.r12.6/compiler.34431801_0
I tried different versions of pytorch with no success. I can access CUDA from python code using pytorch with no problems, but i need to access it in C++