현상
visual studio 2019에서 libtorch cuda 버전을 정상적으로 link했음에도 불구하고 CUDA 인식이 안되었음.
std::cout << torch::cuda::is_available() << std::endl;
0
해결방법
아래와 같이 Windows.h을 include해서 해결함.
#include <ATen/ATen.h>
#include <torch/torch.h>
#include <iostream>
#include <Windows.h>
int main() {
LoadLibraryA("torch_cuda.dll");
try {
std::cout << torch::cuda::is_available() << std::endl;
torch::Tensor tensor = at::tensor({ -1, 1 }, at::kCUDA);
}
catch (exception& ex) {
std::cout << ex.what() << std::endl;
}
}
참고