Hi guys,
I am new to PyTorch or any other neural network package. I was running the example program of printing out a torch tensor in the installation page. I am able to successfully build it. But, while running the ‘make’ command, I am getting error. The details are given below.
I have installed (copied and unzipped) Pytorch C++ frontend in Centos 6.9. It has GNU C++ compiler 4.4.7, and I use a separately installed CMake of version 3.15.0.
Then, I wrote the code ‘first_example.cpp’
#include <torch/torch.h>
#includeint main() {
torch::Tensor tensor = torch::rand({2, 3});
std::cout << tensor << std::endl;
}
I compiled it using the CMakeLists.txt:
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(example-app)find_package(Torch REQUIRED)
add_executable(first_example first_example.cpp)
target_link_libraries(example-app “${TORCH_LIBRARIES}”)
set_property(TARGET example-app PROPERTY CXX_STANDARD 11)
with command:
/full/path/to/cmake -DCMAKE_PREFIX_PATH=full/path/to/libtorch …
This compiled OK.
– The C compiler identification is GNU 4.4.7
– The CXX compiler identification is GNU 4.4.7
– Check for working C compiler: /usr/bin/cc
– Check for working C compiler: /usr/bin/cc – works
– Detecting C compiler ABI info
– Detecting C compiler ABI info - done
– Detecting C compile features
– Detecting C compile features - done
– Check for working CXX compiler: /usr/bin/c++
– Check for working CXX compiler: /usr/bin/c++ – works
– Detecting CXX compiler ABI info
– Detecting CXX compiler ABI info - done
– Detecting CXX compile features
– Detecting CXX compile features - done
– Looking for pthread.h
– Looking for pthread.h - found
– Performing Test CMAKE_HAVE_LIBC_PTHREAD
– Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
– Looking for pthread_create in pthreads
– Looking for pthread_create in pthreads - not found
– Looking for pthread_create in pthread
– Looking for pthread_create in pthread - found
– Found Threads: TRUE
– Found torch: /export/apps/pytorch/libtorch/lib/libtorch.so
– Configuring done
– Generating done
– Build files have been written to: /export/apps/pytorch/libtorch/examples_dir/build
Now, when I run the ‘make’ command, I get the following error.
In file included from /export/apps/pytorch/libtorch/include/c10/core/Backend.h:5,
from /export/apps/pytorch/libtorch/include/c10/core/Layout.h:3,
from /export/apps/pytorch/libtorch/include/ATen/core/Tensor.h:4,
from /export/apps/pytorch/libtorch/include/ATen/Tensor.h:2,
from /export/apps/pytorch/libtorch/include/ATen/Context.h:4,
from /export/apps/pytorch/libtorch/include/ATen/ATen.h:5,
from /export/apps/pytorch/libtorch/include/torch/csrc/api/include/torch/types.h:3,
from /export/apps/pytorch/libtorch/include/torch/csrc/api/include/torch/data/dataloader_options.h:4,
from /export/apps/pytorch/libtorch/include/torch/csrc/api/include/torch/data/dataloader/base.h:3,
from /export/apps/pytorch/libtorch/include/torch/csrc/api/include/torch/data/dataloader/stateful.h:3,
from /export/apps/pytorch/libtorch/include/torch/csrc/api/include/torch/data/dataloader.h:3,
from /export/apps/pytorch/libtorch/include/torch/csrc/api/include/torch/data.h:3,
from /export/apps/pytorch/libtorch/include/torch/csrc/api/include/torch/all.h:4,
from /export/apps/pytorch/libtorch/include/torch/csrc/api/include/torch/torch.h:3,
from /export/apps/pytorch/libtorch/examples_dir/first_example.cpp:1:
/export/apps/pytorch/libtorch/include/c10/core/TensorTypeIdRegistration.h:16:18: error: atomic: No such file or directory
In file included from /export/apps/pytorch/libtorch/include/c10/core/Device.h:3,
from /export/apps/pytorch/libtorch/include/c10/core/Allocator.h:6,
from /export/apps/pytorch/libtorch/include/ATen/ATen.h:3,
from /export/apps/pytorch/libtorch/include/torch/csrc/api/include/torch/types.h:3,
from /export/apps/pytorch/libtorch/include/torch/csrc/api/include/torch/data/dataloader_options.h:4,
from /export/apps/pytorch/libtorch/include/torch/csrc/api/include/torch/data/dataloader/base.h:3,
from /export/apps/pytorch/libtorch/include/torch/csrc/api/include/torch/data/dataloader/stateful.h:3,
from /export/apps/pytorch/libtorch/include/torch/csrc/api/include/torch/data/dataloader.h:3,
from /export/apps/pytorch/libtorch/include/torch/csrc/api/include/torch/data.h:3,
from /export/apps/pytorch/libtorch/include/torch/csrc/api/include/torch/all.h:4,
from /export/apps/pytorch/libtorch/include/torch/csrc/api/include/torch/torch.h:3,
from /export/apps/pytorch/libtorch/examples_dir/first_example.cpp:1:
/export/apps/pytorch/libtorch/include/c10/core/DeviceType.h:34: error: ‘constexpr’ does not name a type
/export/apps/pytorch/libtorch/include/c10/core/DeviceType.h:35: error: ‘constexpr’ does not name a type
/export/apps/pytorch/libtorch/include/c10/core/DeviceType.h:36: error: ‘constexpr’ does not name a type
/export/apps/pytorch/libtorch/include/c10/core/DeviceType.h:37: error: ‘constexpr’ does not name a type
/export/apps/pytorch/libtorch/include/c10/core/DeviceType.h:38: error: ‘constexpr’ does not name a type
/export/apps/pytorch/libtorch/include/c10/core/DeviceType.h:41: error: expected constructor, destructor, or type conversion before ‘int’
/export/apps/pytorch/libtorch/include/c10/core/DeviceType.h:44: error: ‘COMPILE_TIME_MAX_DEVICE_TYPES’ was not declared in this scope
In file included from /export/apps/pytorch/libtorch/include/c10/core/Device.h:5,
from /export/apps/pytorch/libtorch/include/c10/core/Allocator.h:6,
from /export/apps/pytorch/libtorch/include/ATen/ATen.h:3,
from /export/apps/pytorch/libtorch/include/torch/csrc/api/include/torch/types.h:3,
from /export/apps/pytorch/libtorch/include/torch/csrc/api/include/torch/data/dataloader_options.h:4,
from /export/apps/pytorch/libtorch/include/torch/csrc/api/include/torch/data/dataloader/base.h:3,
from /export/apps/pytorch/libtorch/include/torch/csrc/api/include/torch/data/dataloader/stateful.h:3,
from /export/apps/pytorch/libtorch/include/torch/csrc/api/include/torch/data/dataloader.h:3,
from /export/apps/pytorch/libtorch/include/torch/csrc/api/include/torch/data.h:3,
from /export/apps/pytorch/libtorch/include/torch/csrc/api/include/torch/all.h:4,
from /export/apps/pytorch/libtorch/include/torch/csrc/api/include/torch/torch.h:3,
from /export/apps/pytorch/libtorch/examples_dir/first_example.cpp:1:
/export/apps/pytorch/libtorch/include/c10/util/Exception.h:71: error: expected ‘;’ before ‘noexcept’
/export/apps/pytorch/libtorch/include/c10/util/Exception.h:75: error: expected ‘;’ before ‘const’
/export/apps/pytorch/libtorch/include/c10/util/Exception.h:75: error: expected ‘;’ before ‘noexcept’
/export/apps/pytorch/libtorch/include/c10/util/Exception.h:80: error: expected ‘;’ before ‘const’
/export/apps/pytorch/libtorch/include/c10/util/Exception.h:80: error: expected ‘;’ before ‘noexcept’
/export/apps/pytorch/libtorch/include/c10/util/Exception.h:83: error: expected ‘;’ before ‘}’ token
/export/apps/pytorch/libtorch/include/c10/util/Exception.h:28: error: looser throw specifier for ‘virtual c10::Error::~Error()’
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/…/…/…/…/include/c++/4.4.7/exception:63: error: overriding ‘virtual std::exception::~exception() throw ()’
/export/apps/pytorch/libtorch/include/c10/util/Exception.h:49: error: ‘nullptr’ was not declared in this scope
/export/apps/pytorch/libtorch/include/c10/util/Exception.h:57: error: ‘nullptr’ was not declared in this scope
/export/apps/pytorch/libtorch/include/c10/util/Exception.h:86: error: expected nested-name-specifier before ‘handler_t’
/export/apps/pytorch/libtorch/include/c10/util/Exception.h:86: error: using-declaration for non-member at class scope
/export/apps/pytorch/libtorch/include/c10/util/Exception.h:86: error: expected ‘;’ before ‘=’ token
/export/apps/pytorch/libtorch/include/c10/util/Exception.h:86: error: expected unqualified-id before ‘=’ token
/export/apps/pytorch/libtorch/include/c10/util/Exception.h:95: error: ‘handler_t’ has not been declared
/export/apps/pytorch/libtorch/include/c10/util/Exception.h:102: error: ‘handler_t’ does not name a type
/export/apps/pytorch/libtorch/include/c10/util/Exception.h:109: error: ‘c10::Error::Error’ names constructor
In file included from /export/apps/pytorch/libtorch/include/c10/core/Allocator.h:6,
from /export/apps/pytorch/libtorch/include/ATen/ATen.h:3,
from /export/apps/pytorch/libtorch/include/torch/csrc/api/include/torch/types.h:3,
from /export/apps/pytorch/libtorch/include/torch/csrc/api/include/torch/data/dataloader_options.h:4,
from /export/apps/pytorch/libtorch/include/torch/csrc/api/include/torch/data/dataloader/base.h:3,
from /export/apps/pytorch/libtorch/include/torch/csrc/api/include/torch/data/dataloader/stateful.h:3,
from /export/apps/pytorch/libtorch/include/torch/csrc/api/include/torch/data/dataloader.h:3,
from /export/apps/pytorch/libtorch/include/torch/csrc/api/include/torch/data.h:3,
from /export/apps/pytorch/libtorch/include/torch/csrc/api/include/torch/all.h:4,
from /export/apps/pytorch/libtorch/include/torch/csrc/api/include/torch/torch.h:3,
from /export/apps/pytorch/libtorch/examples_dir/first_example.cpp:1:
/export/apps/pytorch/libtorch/include/c10/core/Device.h:18: error: expected nested-name-specifier before ‘DeviceIndex’
/export/apps/pytorch/libtorch/include/c10/core/Device.h:18: error: ‘DeviceIndex’ has not been declared
/export/apps/pytorch/libtorch/include/c10/core/Device.h:18: error: expected ‘;’ before ‘=’ token
/export/apps/pytorch/libtorch/include/c10/core/Device.h:18: error: expected unqualified-id before ‘=’ token
/export/apps/pytorch/libtorch/include/c10/core/Device.h:30: error: variable ‘c10::Device c10::final’ has initializer but incomplete type
/export/apps/pytorch/libtorch/include/c10/core/Device.h:31: error: expected primary-expression before ‘using’
/export/apps/pytorch/libtorch/include/c10/core/Device.h:31: error: expected ‘}’ before ‘using’
/export/apps/pytorch/libtorch/include/c10/core/Device.h:31: error: expected ‘,’ or ‘;’ before ‘using’
/export/apps/pytorch/libtorch/include/c10/core/Device.h:35: error: expected ‘)’ before ‘type’
/export/apps/pytorch/libtorch/include/c10/core/Device.h:45: error: expected unqualified-id before ‘const’
/export/apps/pytorch/libtorch/include/c10/core/Device.h:45: error: expected ‘)’ before ‘const’
/export/apps/pytorch/libtorch/include/c10/core/Device.h:49: error: expected initializer before ‘noexcept’
/export/apps/pytorch/libtorch/include/c10/core/Device.h:55: error: expected initializer before ‘noexcept’
/export/apps/pytorch/libtorch/include/c10/core/Device.h:60: error: variable or field ‘set_index’ declared void
/export/apps/pytorch/libtorch/include/c10/core/Device.h:60: error: ‘DeviceIndex’ was not declared in this scope
/export/apps/pytorch/libtorch/include/c10/core/Device.h:65: error: expected initializer before ‘noexcept’
/export/apps/pytorch/libtorch/include/c10/core/Device.h:70: error: ‘DeviceIndex’ does not name a type
/export/apps/pytorch/libtorch/include/c10/core/Device.h:75: error: expected initializer before ‘noexcept’
/export/apps/pytorch/libtorch/include/c10/core/Device.h:80: error: expected initializer before ‘noexcept’
/export/apps/pytorch/libtorch/include/c10/core/Device.h:85: error: expected initializer before ‘noexcept’
/export/apps/pytorch/libtorch/include/c10/core/Device.h:89: error: expected unqualified-id before ‘private’
/export/apps/pytorch/libtorch/include/c10/core/Device.h:91: error: ‘DeviceIndex’ does not name a type
/export/apps/pytorch/libtorch/include/c10/core/Device.h: In function ‘void c10::validate()’:
/export/apps/pytorch/libtorch/include/c10/core/Device.h:93: error: ‘index_’ was not declared in this scope
/export/apps/pytorch/libtorch/include/c10/core/Device.h:95: error: ‘is_cpu’ was not declared in this scope
/export/apps/pytorch/libtorch/include/c10/core/Device.h:95: error: ‘index_’ was not declared in this scope
/export/apps/pytorch/libtorch/include/c10/core/Device.h: At global scope:
/export/apps/pytorch/libtorch/include/c10/core/Device.h:102: error: expected ‘,’ or ‘…’ before ‘&’ token
/export/apps/pytorch/libtorch/include/c10/core/Device.h:104: error: expected declaration before ‘}’ token
make[2]: *** [CMakeFiles/first_example.dir/first_example.cpp.o] Error 1
make[1]: *** [CMakeFiles/first_example.dir/all] Error 2
make: *** [all] Error 2
I also compiled with the g++ command as follows:
g++ -std=c++0x -I /export/apps/pytorch/libtorch/include/torch/csrc/api/include/ first_example.cpp
I get the same error as above.
I am not sure what the issue is. Can anyone help?