vicki
(Vicki Anand)
March 28, 2019, 9:49pm
1
I am trying out the c++ frontend with a simple program.
Compilation of this code block is failing -
torch::DeviceType device_type;
if (torch::cuda::is_available())
{
std::cout << "CUDA is available!" << std::endl;
device_type = torch::kCUDA;
}
And throws this error -
error: ‘is_available’ is not a member of ‘at::cuda’
if (torch::cuda::is_available())
Any idea what might be wrong here?
1 Like
mhubii
(Martin Huber)
April 1, 2019, 9:42am
2
hm that is strange. Can you please provide your CMakeLists.txt
and the command with which you are trying to build your code? Where did you get your libtorch from?
vicki
(Vicki Anand)
April 1, 2019, 1:23pm
3
CMakeList is a minimal:
project(custom_op)
find_package(Torch REQUIRED)
add_executable(jit_minimal jit_minimal.cpp)
target_link_libraries(jit_minimal "${TORCH_LIBRARIES}")
set_property(TARGET jit_minimal PROPERTY CXX_STANDARD 11)
Command used for build -
mkdir -p build/
cd build/
# cmake -DCMAKE_PREFIX_PATH=~/libs/libtorch/ ..
cmake -DCMAKE_PREFIX_PATH=~/libs/nightly/libtorch/ ..
make
And I got the libtorch using the download url on pytorch website.
mhubii
(Martin Huber)
April 1, 2019, 2:03pm
4
that should work, please provide your full jit_minimal.cpp
what version of CUDA do you have?
I met this error too, any idea?
pratyush911
(Pratyush Maini)
November 8, 2019, 12:37pm
6
Including the following should solve it.
#include <torch/torch.h>
You are possibly only including #include <torch/script.h>
3 Likes
Martin_JH
(Martin JH)
April 1, 2021, 8:50am
7
Thanks @pratyush911 . That was the solution.
Schuyler
(Schuyler)
April 12, 2021, 4:00am
8
Thanks for the information. It is really helpful for us. Please keep suggesting such a content.
www.myaarpmedicare.com