Compile error with "USE_HEXAGON_DEVICE sim"

Hi, I met a compile error like this:

tvm/src/runtime/hexagon/sim/hexagon_device_sim.cc:626:25: error: no template named 'istream_iterator' in namespace 'std'; did you mean 'istreambuf_iterator'?
  using iterator = std::istream_iterator<std::string>;
                   ~~~~~^~~~~~~~~~~~~~~~
                        istreambuf_iterator

It seems to need c++17 and I do modify it in the CMakeLists:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 87fa2e0..44aa53e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -439,12 +439,12 @@ include(cmake/modules/RustExt.cmake)
 
 include(CheckCXXCompilerFlag)
 if(NOT MSVC)
-  check_cxx_compiler_flag("-std=c++14" SUPPORT_CXX14)
-  set(CMAKE_CXX_FLAGS "-std=c++14 ${CMAKE_CXX_FLAGS}")
+  check_cxx_compiler_flag("-std=c++17" SUPPORT_CXX17)
+  set(CMAKE_CXX_FLAGS "-std=c++17 ${CMAKE_CXX_FLAGS}")
   set(CMAKE_CUDA_STANDARD 14)
 else()
-  check_cxx_compiler_flag("/std:c++14" SUPPORT_CXX14)
-  set(CMAKE_CXX_FLAGS "/std:c++14 ${CMAKE_CXX_FLAGS}")
+  check_cxx_compiler_flag("/std:c++17" SUPPORT_CXX17)
+  set(CMAKE_CXX_FLAGS "/std:c++17 ${CMAKE_CXX_FLAGS}")
   set(CMAKE_CUDA_STANDARD 14)
 endif()

Besides, this is my config.cmake file:

49c49
< set(USE_CUDA ON)
---
> set(USE_CUDA OFF)
125c125
< set(USE_LLVM /usr/bin/llvm-config-10)
---
> set(USE_LLVM OFF)
255c255
< set(USE_RELAY_DEBUG ON)
---
> set(USE_RELAY_DEBUG OFF)
276,277c276,277
< set(USE_HEXAGON_DEVICE sim)
< set(USE_HEXAGON_SDK /my home/Qualcomm/Hexagon_SDK/3.5.4)
---
> set(USE_HEXAGON_DEVICE OFF)
> set(USE_HEXAGON_SDK /path/to/sdk)
287c287
< set(USE_TARGET_ONNX ON)
---
> set(USE_TARGET_ONNX OFF)

I’ve tied both gcc-7.5.0 and clang-10 but got the same error.

Is there anything I missed? Thanks. @kparzysz

This shouldn’t require C++17, this class exists in C++11 too. Could you add

#include <iterator>

at the beginning of hexagon_device_sim.cc?

If that doesn’t help, could you paste your entire cmake command line?

1 Like

Sorry for the late reply.

Could you add

#include <iterator>

at the beginning of hexagon_device_sim.cc?

This worked. Thanks!

Then I met another problem:

hexagon_device_sim.cc:146:33: error: no matching function for call to ‘tvm::runtime::hexagon::detail::Optional<long int>::Optional()’

And I fixed it by modifying the struct Optional

@@ -89,6 +90,7 @@ template <typename T>
 struct Optional : public dmlc::optional<T> {
   using dmlc::optional<T>::optional;
   using dmlc::optional<T>::operator=;
+  Optional() {}
   Optional(const T& val) : dmlc::optional<T>(val) {}  // NOLINT(*)


After that, I ran the test_target_codegen_hexagon, but got segmentation fault:

python tests/python/unittest/test_target_codegen_hexagon.py
enabled targets: llvm; llvm -device=arm_cpu; cuda; hexagon
pytest marker: 
=============================================== test session starts ===============================================
platform linux -- Python 3.8.3, pytest-5.4.3, py-1.9.0, pluggy-0.13.1
rootdir: my home/Projects/Coder_tvm/tvm
collected 5 items                                                                                                 

tests/python/unittest/test_target_codegen_hexagon.py ....Fatal Python error: Segmentation fault

Current thread 0x00007fb3c6a31700 (most recent call first):
  File "my home//Projects/Coder_tvm/tvm/python/tvm/_ffi/_ctypes/packed_func.py", line 227 in __call__
  File "my home//Projects/Coder_tvm/tvm/python/tvm/relay/build_module.py", line 172 in build
  File "my home//Projects/Coder_tvm/tvm/python/tvm/relay/build_module.py", line 357 in build
  File "my home//Projects/Coder_tvm/tvm/tests/python/unittest/test_target_codegen_hexagon.py", line 136 in test_linked_params_codegen

By the way, I didn’t change any other codes except:

$ git diff

diff --git a/src/runtime/hexagon/sim/hexagon_device_sim.cc b/src/runtime/hexagon/sim/hexagon_device_sim.cc
index 14ab4c3..a1c9b8f 100644
--- a/src/runtime/hexagon/sim/hexagon_device_sim.cc
+++ b/src/runtime/hexagon/sim/hexagon_device_sim.cc
@@ -24,6 +24,7 @@
 
 #include <algorithm>
 #include <deque>
+#include <iterator>
 #include <iomanip>
 #include <locale>
 #include <memory>
@@ -89,6 +90,7 @@ template <typename T>
 struct Optional : public dmlc::optional<T> {
   using dmlc::optional<T>::optional;
   using dmlc::optional<T>::operator=;
+  Optional() {}
   Optional(const T& val) : dmlc::optional<T>(val) {}  // NOLINT(*)
 
   T* operator->() { return &this->operator*(); 

My config.cmake is:

$ diff cmake/config.cmake config.cmake 

49c49
< set(USE_CUDA OFF)
---
> set(USE_CUDA ON)
125c125
< set(USE_LLVM OFF)
---
> set(USE_LLVM /usr/bin/llvm-config-10)
255c255
< set(USE_RELAY_DEBUG OFF)
---
> set(USE_RELAY_DEBUG ON)
276,277c276,277
< set(USE_HEXAGON_DEVICE OFF)
< set(USE_HEXAGON_SDK /path/to/sdk)
---
> set(USE_HEXAGON_DEVICE sim)
> set(USE_HEXAGON_SDK /home/SENSETIME/mupei/Qualcomm/Hexagon_SDK/3.5.4)
287c287
< set(USE_TARGET_ONNX OFF)
---
> set(USE_TARGET_ONNX ON)


Have you met this error before? Or maybe I have the wrong config?

My cmake command line is:

cd build
cmake ..
make -j8

Thanks again @kparzysz

There are two things you can try:

  1. Make sure that the Hexagon target is present in the LLVM you’re using:
/usr/bin/llvm-config-10 --targets-built
  1. If Hexagon is supported, you could run this test from a debugger and print the stack trace when the segfault happens e.g.
lldb python tests/python/unittest/test_target_codegen_hexagon.py
(lldb) run
<segfault>
(lldb) bt

I have same problem with same sdk version in ubuntu 18.04:

tests/python/unittest/test_target_codegen_hexagon.py Process 23044 stopped and restarted: thread 1 received signal: SIGCHLD
Process 23044 stopped and restarted: thread 1 received signal: SIGCHLD
.Process 23044 stopped and restarted: thread 1 received signal: SIGCHLD
...Process 23044 stopped
* thread #1, name = 'python3', stop reason = signal SIGSEGV: invalid address (fault address: 0x34)
    frame #0: 0x00007fffcedcb4fb libLLVM-10.so.1`___lldb_unnamed_symbol30093$$libLLVM-10.so.1 + 11
libLLVM-10.so.1`___lldb_unnamed_symbol30093$$libLLVM-10.so.1:
->  0x7fffcedcb4fb <+11>: movl   0x34(%rsi), %eax
    0x7fffcedcb4fe <+14>: addl   $-0x2, %eax
    0x7fffcedcb501 <+17>: cmpl   $0x1e, %eax
    0x7fffcedcb504 <+20>: ja     0x7fffcedcb523            ; <+51>
(lldb) bt
* thread #1, name = 'python3', stop reason = signal SIGSEGV: invalid address (fault address: 0x34)
  * frame #0: 0x00007fffcedcb4fb libLLVM-10.so.1`___lldb_unnamed_symbol30093$$libLLVM-10.so.1 + 11
    frame #1: 0x00007fffcd69254d libLLVM-10.so.1`llvm::LLVMTargetMachine::addAsmPrinter(llvm::legacy::PassManagerBase&, llvm::raw_pwrite_stream&, llvm::raw_pwrite_stream*, llvm::CodeGenFileType, llvm::MCContext&) + 557
    frame #2: 0x00007fffcd69299d libLLVM-10.so.1`llvm::LLVMTargetMachine::addPassesToEmitFile(llvm::legacy::PassManagerBase&, llvm::raw_pwrite_stream&, llvm::raw_pwrite_stream*, llvm::CodeGenFileType, bool, llvm::MachineModuleInfoWrapperPass*) + 221
    frame #3: 0x00007fffd4067179 libtvm.so`tvm::codegen::BuildHexagon(tvm::IRModule, tvm::Target)::'lambda0'(llvm::Module const&, tvm::codegen::BuildHexagon(tvm::IRModule, tvm::Target)::CodeGenFileType)::operator()(llvm::Module const&, tvm::codegen::BuildHexagon(tvm::IRModule, tvm::Target)::CodeGenFileType) const + 281
    frame #4: 0x00007fffd40686b7 libtvm.so`tvm::codegen::BuildHexagon(tvm::IRModule, tvm::Target) + 4695
    frame #5: 0x00007fffd393946d libtvm.so`void tvm::runtime::TypedPackedFunc<tvm::runtime::Module (tvm::IRModule, tvm::Target)>::AssignTypedLambda<tvm::runtime::Module (*)(tvm::IRModule, tvm::Target)>(tvm::runtime::Module (*)(tvm::IRModule, tvm::Target), std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)::'lambda'(tvm::runtime::TVMArgs const&, tvm::runtime::TVMRetValue*)::operator()(tvm::runtime::TVMArgs const&, tvm::runtime::TVMRetValue*) const + 301
    frame #6: 0x00007fffd393302c libtvm.so`tvm::codegen::Build(tvm::IRModule, tvm::Target) + 1228
    frame #7: 0x00007fffd327ec37 libtvm.so`tvm::build(tvm::runtime::Map<tvm::Target, tvm::IRModule, void, void> const&, tvm::Target const&) + 1863
    frame #8: 0x00007fffd3eaf6a7 libtvm.so`tvm::relay::backend::RelayBuildModule::BuildRelay(tvm::IRModule, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, tvm::runtime::NDArray, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, tvm::runtime::NDArray> > > const&, tvm::runtime::String) + 6999
    frame #9: 0x00007fffd3eb0b31 libtvm.so`tvm::relay::backend::RelayBuildModule::GetFunction(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, tvm::runtime::ObjectPtr<tvm::runtime::Object> const&)::'lambda1'(tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*)::operator()(tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*) const + 833
    frame #10: 0x00007fffd3eb0de7 libtvm.so`std::_Function_handler<void (tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*), tvm::relay::backend::RelayBuildModule::GetFunction(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, tvm::runtime::ObjectPtr<tvm::runtime::Object> const&)::'lambda1'(tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*)>::_M_invoke(std::_Any_data const&, tvm::runtime::TVMArgs&&, tvm::runtime::TVMRetValue*&&) + 23
    frame #11: 0x00007fffd40cc81b libtvm.so`TVMFuncCall + 91
    frame #12: 0x00007fffe90ebbb3 core.cpython-36m-x86_64-linux-gnu.so`::__pyx_f_3tvm_4_ffi_4_cy3_4core_FuncCall(__pyx_v_chandle=0x000000002589af20, __pyx_v_args=0x00007fff5c0c6048, __pyx_v_ret_val=0x00007fffffff7730, __pyx_v_ret_tcode=0x00007fffffff7728) at core.cpp:7603
    frame #13: 0x00007fffe90ebf53 core.cpython-36m-x86_64-linux-gnu.so`::__pyx_pw_3tvm_4_ffi_4_cy3_4core_14PackedFuncBase_5__call__(PyObject *, PyObject *, PyObject *) at core.cpp:8387
    frame #14: 0x00007fffe90ebf3d core.cpython-36m-x86_64-linux-gnu.so`::__pyx_pw_3tvm_4_ffi_4_cy3_4core_14PackedFuncBase_5__call__(__pyx_v_self=0x00007fff5c0cac78, __pyx_args=0x00007fff5c0c6048, __pyx_kwds=<unavailable>) at core.cpp:8351