after I see the install tutorial of libtorch PyTorch cppdocs, I can use libtorch in cpp file. However, I meet an error when include<torch/torch.h>
in .cu file.
Reference the step in PyTorch cppdocs. I write a demo like follow:
- CMakeLists.txt
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(torchcpp)
find_package(CUDA REQUIRED)
find_package(Torch REQUIRED)
enable_language(CUDA)
add_executable(torchcpp tmp.cu)
target_link_libraries(torchcpp "${TORCH_LIBRARIES}")
# set_property(TARGET torchcpp PROPERTY CXX_STANDARD 11)
set_property(TARGET torchcpp PROPERTY CUDA_STANDARD 11)
- tmp.cu(the demo code is silly, however, i just want to test)
#include <torch/torch.h>
#include <iostream>
using namespace std;
int main() {
at::Tensor tensor = torch::randn({5}).cuda();
cout << tensor << endl;
}
And follow the instruction to make:
mkdir build
cd build
cmake -DCMAKE_PREFIX_PATH=my_path_to_libtorch/libtorch ..
can compile without error.
make
there is an error:
xxx/libtorch/include/torch/csrc/jit/argument_spec.h(56): error: static assertion failed with "ArgumentInfo is to be a POD struct"
I hope get your help. thank you!
Addition: If I change the head file to
#include <ATen/ATen.h>
#include <ATen/cuda/CUDAContext.h>
#include <iostream>
using namespace std;
using namespace at;
int main() {
auto tensor = at::randn({5}).cuda();
cout << tensor << endl;
}
it can make correctly.