pytorch / tvm

TVM integration into PyTorch
454 stars 64 forks source link

Can't Build the Project on MacOs #121

Open serhaty opened 5 years ago

serhaty commented 5 years ago

I am trying to build the project but it is failing errors on llvm-project directory. Here are steps I am following to build the project on my mac laptop:

# Follow steps to install pytorch on: https://github.com/pytorch/pytorch#from-source
# in torch/tvm folder running command to build
python setup.py develop

And this is my environment setup of the tools:

(pytorch) [11:23:56 AM] /Users/serhaty/local/tvm
 $ cmake --version
cmake version 3.14.0

CMake suite maintained and supported by Kitware (kitware.com/cmake).
(pytorch) [11:24:07 AM] /Users/serhaty/local/tvm
 $ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 11.0.0 (clang-1100.0.33.8)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
(pytorch) [11:24:12 AM] /Users/serhaty/local/tvm
 $ llvm-config --version
10.0.0svn
(pytorch) [11:24:20 AM] /Users/serhaty/local/tvm
 $ clang --version
clang version 10.0.0 (https://github.com/llvm/llvm-project.git 77297f0761d2009e25d5d709cdcb041229f3493c)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Users/serhaty/local/llvm-project/build/bin
(pytorch) [11:24:24 AM] /Users/serhaty/local/tvm
 $ python --version
Python 3.7.4

Here is the output from the above command:

$ python setup.py develop
running develop
running build_ext
running cmake_build
[  8%] Built target tvm_runtime
[  8%] Building CXX object tvm/CMakeFiles/tvm.dir/src/codegen/llvm/codegen_amdgpu.cc.o
[  8%] Building CXX object tvm/CMakeFiles/tvm.dir/src/codegen/llvm/codegen_arm.cc.o
[  9%] Building CXX object tvm/CMakeFiles/tvm.dir/src/codegen/llvm/codegen_llvm.cc.o
[  9%] Building CXX object tvm/CMakeFiles/tvm.dir/src/codegen/llvm/codegen_cpu.cc.o
[ 10%] Building CXX object tvm/CMakeFiles/tvm.dir/src/codegen/llvm/codegen_x86_64.cc.o
[ 10%] Building CXX object tvm/CMakeFiles/tvm.dir/src/codegen/llvm/codegen_nvptx.cc.o
[ 11%] Building CXX object tvm/CMakeFiles/tvm.dir/src/codegen/llvm/llvm_module.cc.o
[ 11%] Building CXX object tvm/CMakeFiles/tvm.dir/src/codegen/llvm/intrin_rule_rocm.cc.o
[ 11%] Building CXX object tvm/CMakeFiles/tvm.dir/src/codegen/llvm/llvm_common.cc.o
[ 11%] Building CXX object tvm/CMakeFiles/tvm.dir/src/codegen/llvm/intrin_rule_llvm.cc.o
[ 11%] Building CXX object tvm/CMakeFiles/tvm.dir/src/runtime/c_dsl_api.cc.o
[ 11%] Building CXX object tvm/CMakeFiles/tvm.dir/src/contrib/hybrid/codegen_hybrid.cc.o
[ 12%] Building CXX object tvm/CMakeFiles/tvm.dir/src/runtime/c_runtime_api.cc.o
[ 12%] Building CXX object tvm/CMakeFiles/tvm.dir/src/runtime/builtin_fp16.cc.o
[ 13%] Building CXX object tvm/CMakeFiles/tvm.dir/src/runtime/cpu_device_api.cc.o
[ 13%] Building CXX object tvm/CMakeFiles/tvm.dir/src/runtime/dso_module.cc.o
[ 13%] Building CXX object tvm/CMakeFiles/tvm.dir/src/runtime/file_util.cc.o
In file included from /Users/serhaty/local/tvm/tvm/src/codegen/llvm/llvm_common.cc:30:
In file included from /Users/serhaty/local/tvm/tvm/src/codegen/llvm/llvm_common.h:29:
In file included from /Users/serhaty/local/llvm-project/llvm/include/llvm/ExecutionEngine/MCJIT.h:17:
In file included from /Users/serhaty/local/llvm-project/llvm/include/llvm/ExecutionEngine/ExecutionEngine.h:18:
In file included from /Users/serhaty/local/llvm-project/llvm/include/llvm/ADT/ArrayRef.h:12:
In file included from /Users/serhaty/local/llvm-project/llvm/include/llvm/ADT/Hashing.h:48:
In file included from /Users/serhaty/local/llvm-project/llvm/include/llvm/Support/Host.h:16:
In file included from /Users/serhaty/local/llvm-project/llvm/include/llvm/ADT/StringMap.h:16:
In file included from /Users/serhaty/local/llvm-project/llvm/include/llvm/ADT/StringRef.h:12:
/Users/serhaty/local/llvm-project/llvm/include/llvm/ADT/STLExtras.h:555:49: error: no template named 'index_sequence' in namespace 'std'
  template <size_t... Ns> value_type deref(std::index_sequence<Ns...>) const {
                                           ~~~~~^
/Users/serhaty/local/llvm-project/llvm/include/llvm/ADT/STLExtras.h:560:36: error: no template named 'index_sequence' in namespace 'std'
  decltype(iterators) tup_inc(std::index_sequence<Ns...>) const {
                              ~~~~~^
/Users/serhaty/local/llvm-project/llvm/include/llvm/ADT/STLExtras.h:565:36: error: no template named 'index_sequence' in namespace 'std'
  decltype(iterators) tup_dec(std::index_sequence<Ns...>) const {
                              ~~~~~^
/Users/serhaty/local/llvm-project/llvm/include/llvm/ADT/STLExtras.h:572:46: error: no member named 'index_sequence_for' in namespace 'std'
  value_type operator*() { return deref(std::index_sequence_for<Iters...>{}); }
                                        ~~~~~^
/Users/serhaty/local/llvm-project/llvm/include/llvm/ADT/STLExtras.h:572:65: error: 'Iters' does not refer to a value
  value_type operator*() { return deref(std::index_sequence_for<Iters...>{}); }
                                                                ^
/Users/serhaty/local/llvm-project/llvm/include/llvm/ADT/STLExtras.h:547:41: note: declared here
template <typename ZipType, typename... Iters>
                                        ^
/Users/serhaty/local/llvm-project/llvm/include/llvm/ADT/STLExtras.h:575:23: error: no member named 'index_sequence_for' in namespace 'std'
    return deref(std::index_sequence_for<Iters...>{});
                 ~~~~~^
/Users/serhaty/local/llvm-project/llvm/include/llvm/ADT/STLExtras.h:575:42: error: 'Iters' does not refer to a value
    return deref(std::index_sequence_for<Iters...>{});
                                         ^
/Users/serhaty/local/llvm-project/llvm/include/llvm/ADT/STLExtras.h:547:41: note: declared here
template <typename ZipType, typename... Iters>
                                        ^
/Users/serhaty/local/llvm-project/llvm/include/llvm/ADT/STLExtras.h:579:30: error: no member named 'index_sequence_for' in namespace 'std'
    iterators = tup_inc(std::index_sequence_for<Iters...>{});
                        ~~~~~^
/Users/serhaty/local/llvm-project/llvm/include/llvm/ADT/STLExtras.h:579:49: error: 'Iters' does not refer to a value
    iterators = tup_inc(std::index_sequence_for<Iters...>{});
                                                ^
/Users/serhaty/local/llvm-project/llvm/include/llvm/ADT/STLExtras.h:547:41: note: declared here
template <typename ZipType, typename... Iters>
...
serhaty commented 5 years ago

I downgraded my llvm version to 8.0.1 using brew but now getting some build failure, when building torch_tvm itself. here is the log from first error:

In file included from /Users/serhaty/local/tvm/torch_tvm/operators.cpp:6:
In file included from /Users/serhaty/local/pytorch/torch/include/torch/csrc/autograd/record_function.h:3:
In file included from /Users/serhaty/local/pytorch/torch/include/ATen/core/ivalue.h:5:
In file included from /Users/serhaty/local/pytorch/torch/include/ATen/core/TensorBody.h:11:
In file included from /Users/serhaty/local/pytorch/torch/include/c10/core/TensorImpl.h:17:
In file included from /Users/serhaty/local/pytorch/torch/include/c10/util/Logging.h:28:
/Users/serhaty/local/pytorch/torch/include/c10/util/logging_is_not_google_glog.h:169:9: warning: 'CHECK_NOTNULL' macro redefined [-Wmacro-redefined]
#define CHECK_NOTNULL(val) \
        ^
/Users/serhaty/local/tvm/tvm/3rdparty/dmlc-core/include/dmlc/logging.h:215:9: note: previous definition is here
#define CHECK_NOTNULL(x) \
        ^
In file included from /Users/serhaty/local/tvm/torch_tvm/compiler.cpp:1:
In file included from /Users/serhaty/local/tvm/torch_tvm/compiler.h:3:
In file included from /Users/serhaty/local/pytorch/torch/include/torch/csrc/jit/argument_spec.h:3:
In file included from /Users/serhaty/local/pytorch/torch/include/ATen/core/jit_type.h:3:
In file included from /Users/serhaty/local/pytorch/torch/include/ATen/core/TensorBody.h:3:
In file included from /Users/serhaty/local/pytorch/torch/include/c10/core/Device.h:3:
In file included from /Users/serhaty/local/pytorch/torch/include/c10/core/DeviceType.h:8:
In file included from /Users/serhaty/local/pytorch/torch/include/c10/macros/Macros.h:146:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/sstream:174:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/ostream:138:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/ios:216:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__locale:15:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:505:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string_view:176:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__string:57:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/algorithm:641:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/type_traits:3161:38: error: implicit instantiation of undefined
      template 'std::__1::hash<c10::ScalarType>'
    : public integral_constant<bool, __is_constructible(_Tp, _Args...)>
                                     ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/type_traits:3420:14: note: in instantiation of template class
      'std::__1::is_constructible<std::__1::hash<c10::ScalarType>, const std::__1::hash<c10::ScalarType> &>' requested here
    : public is_constructible<_Tp,
             ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/utility:1597:5: note: in instantiation of template class
      'std::__1::is_copy_constructible<std::__1::hash<c10::ScalarType> >' requested here
    is_copy_constructible<_Hash>::value &&
    ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__hash_table:868:19: note: in instantiation of template type alias
      '__check_hash_requirements' requested here
    static_assert(__check_hash_requirements<_Key, _Hash>::value,
                  ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__hash_table:883:1: note: in instantiation of template class
      'std::__1::__enforce_unordered_container_requirements<c10::ScalarType, std::__1::hash<c10::ScalarType>, std::__1::equal_to<c10::ScalarType> >' requested here
typename __enforce_unordered_container_requirements<_Key, _Hash, _Equal>::type
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/unordered_map:856:26: note: while substituting explicitly-specified
      template arguments into function template '__diagnose_unordered_container_requirements'
    static_assert(sizeof(__diagnose_unordered_container_requirements<_Key, _Hash, _Pred>(0)), "");
                         ^
/Users/serhaty/local/tvm/torch_tvm/compiler.cpp:92:73: note: in instantiation of template class 'std::__1::unordered_map<c10::ScalarType, tvm::DataType,
      std::__1::hash<c10::ScalarType>, std::__1::equal_to<c10::ScalarType>, std::__1::allocator<std::__1::pair<const c10::ScalarType, tvm::DataType> > >' requested here
  static const std::unordered_map<at::ScalarType, tvm::relay::DataType> type_mapping = {
                                                                        ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/type_traits:417:50: note: template is declared here
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS hash;
                                                 ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/type_traits:3161:38: error: implicit instantiation of undefined
      template 'std::__1::hash<c10::ScalarType>'
    : public integral_constant<bool, __is_constructible(_Tp, _Args...)>
                                     ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/type_traits:3434:14: note: in instantiation of template class
      'std::__1::is_constructible<std::__1::hash<c10::ScalarType>, std::__1::hash<c10::ScalarType> &&>' requested here
    : public is_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
             ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/utility:1598:5: note: in instantiation of template class
      'std::__1::is_move_constructible<std::__1::hash<c10::ScalarType> >' requested here
    is_move_constructible<_Hash>::value &&
    ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__hash_table:868:19: note: in instantiation of template type alias
      '__check_hash_requirements' requested here
    static_assert(__check_hash_requirements<_Key, _Hash>::value,
                  ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__hash_table:883:1: note: in instantiation of template class
      'std::__1::__enforce_unordered_container_requirements<c10::ScalarType, std::__1::hash<c10::ScalarType>, std::__1::equal_to<c10::ScalarType> >' requested here
typename __enforce_unordered_container_requirements<_Key, _Hash, _Equal>::type
serhaty commented 5 years ago

@bwasti here is the version of clang++

 $ clang++ --version
clang version 8.0.1 (tags/RELEASE_801/final)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm/bin
bwasti commented 5 years ago

the last error seems related to pytorch -- can you try a different version of PT?

serhaty commented 5 years ago

I did rebuild both pytorch and tvm with clang++ which cleared recent errors but looks like there is one more error remaining:

In file included from /Users/serhaty/local/tvm/torch_tvm/compiler.h:5:
In file included from /Users/serhaty/local/tvm/tvm/include/tvm/relay/expr.h:27:                                                                                                 In file included from /Users/serhaty/local/tvm/tvm/include/tvm/attrs.h:48:
In file included from /Users/serhaty/local/tvm/tvm/3rdparty/dmlc-core/include/dmlc/common.h:14:                                                                                 /Users/serhaty/local/tvm/tvm/3rdparty/dmlc-core/include/dmlc/./logging.h:257:9: warning: 'LOG' macro redefined [-Wmacro-redefined]
#define LOG(severity) LOG_##severity.stream()                                                                                                                                           ^
/Users/serhaty/local/pytorch/torch/include/c10/util/logging_is_not_google_glog.h:96:9: note: previous definition is here                                                        #define LOG(n)                   \                                                                                                                                                      ^
In file included from /Users/serhaty/local/tvm/torch_tvm/register.cpp:8:                                                                                                        In file included from /Users/serhaty/local/tvm/torch_tvm/compiler.h:5:                                                                                                          In file included from /Users/serhaty/local/tvm/tvm/include/tvm/relay/expr.h:27:
In file included from /Users/serhaty/local/tvm/tvm/include/tvm/attrs.h:48:                                                                                                      In file included from /Users/serhaty/local/tvm/tvm/3rdparty/dmlc-core/include/dmlc/common.h:14:
/Users/serhaty/local/tvm/tvm/3rdparty/dmlc-core/include/dmlc/./logging.h:259:9: warning: 'LOG_IF' macro redefined [-Wmacro-redefined]
#define LOG_IF(severity, condition) \                                                                                                                                                   ^
/Users/serhaty/local/pytorch/torch/include/c10/util/logging_is_not_google_glog.h:101:9: note: previous definition is here                                                       #define LOG_IF(n, condition)                    \                                                                                                                                       ^
18 warnings and 1 error generated.
make[2]: *** [CMakeFiles/_torch_tvm.dir/torch_tvm/memory_utils.cpp.o] Error 1                                                                                                   make[2]: *** Waiting for unfinished jobs....
/Users/serhaty/local/tvm/torch_tvm/register.cpp:124:14: error: conversion from 'tvm::runtime::TVMArgValue' to 'size_t' (aka 'unsigned long') is ambiguous
      size_t id = args[0];                                                                                                                                                                   ^    ~~~~~~~
/Users/serhaty/local/tvm/tvm/include/tvm/runtime/packed_func.h:441:3: note: candidate function
  operator double() const {                                                                                                                                                       ^
/Users/serhaty/local/tvm/tvm/include/tvm/runtime/packed_func.h:451:3: note: candidate function                                                                                    operator int64_t() const {
  ^
/Users/serhaty/local/tvm/tvm/include/tvm/runtime/packed_func.h:455:3: note: candidate function                                                                                    operator uint64_t() const {                                                                                                                                                     ^
/Users/serhaty/local/tvm/tvm/include/tvm/runtime/packed_func.h:459:3: note: candidate function
  operator int() const {                                                                                                                                                          ^
/Users/serhaty/local/tvm/tvm/include/tvm/runtime/packed_func.h:465:3: note: candidate function
  operator bool() const {                                                                                                                                                         ^
18 warnings and 1 error generated.                                                                                                                                              make[2]: *** [CMakeFiles/_torch_tvm.dir/torch_tvm/register.cpp.o] Error 1
make[1]: *** [CMakeFiles/_torch_tvm.dir/all] Error 2
make: *** [all] Error 2
Traceback (most recent call last):
  File "setup.py", line 273, in <module>                                                                                                                                            url='https://github.com/pytorch/tvm',
  File "//anaconda3/envs/pytorch/lib/python3.7/site-packages/setuptools/__init__.py", line 145, in setup
    return distutils.core.setup(**attrs)
  File "//anaconda3/envs/pytorch/lib/python3.7/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "//anaconda3/envs/pytorch/lib/python3.7/distutils/dist.py", line 966, in run_commands
    self.run_command(cmd)                                                                                                                                                         File "//anaconda3/envs/pytorch/lib/python3.7/distutils/dist.py", line 985, in run_command
    cmd_obj.run()                                                                                                                                                                 File "setup.py", line 181, in run
    self.run_command('build_ext')
  File "//anaconda3/envs/pytorch/lib/python3.7/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "//anaconda3/envs/pytorch/lib/python3.7/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "setup.py", line 187, in run                                                                                                                                                 self.run_command('cmake_build')                                                                                                                                               File "//anaconda3/envs/pytorch/lib/python3.7/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)                                                                                                                                        File "//anaconda3/envs/pytorch/lib/python3.7/distutils/dist.py", line 985, in run_command                                                                                         cmd_obj.run()
  File "setup.py", line 176, in run                                                                                                                                                 self._run_build()                                                                                                                                                             File "setup.py", line 165, in _run_build
    subprocess.check_call(build_args)                                                                                                                                             File "//anaconda3/envs/pytorch/lib/python3.7/subprocess.py", line 347, in check_call                                                                                              raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['//anaconda3/envs/pytorch/bin/cmake', '--build', '.', '--', '-j', '16']' returned non-zero exit status 2.
yinghai commented 5 years ago
/Users/serhaty/local/tvm/torch_tvm/register.cpp:124:14: error: conversion from 'tvm::runtime::TVMArgValue' to 'size_t' (aka 'unsigned long') is ambiguous
      size_t id = args[0];                                                                                                                                                                   

seems legit