apache / tvm

Open deep learning compiler stack for cpu, gpu and specialized accelerators
https://tvm.apache.org/
Apache License 2.0
11.46k stars 3.41k forks source link

Undefined Reference Errors When Linking Against PyTorch in CMake #17008

Open OleeHu opened 2 months ago

OleeHu commented 2 months ago

I am encountering linker errors when trying to build my project using CMake with PyTorch. The build process fails with several undefined reference errors related to PyTorch symbols. Below are the details of the error messages:

/usr/bin/ld: ../../libtvm_runtime.a(libtorch_runtime.cc.o): in function `tvm::runtime::contrib::run_torch_module(torch::jit::Module*, tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*)':
libtorch_runtime.cc:(.text+0x10c3): undefined reference to `torch::jit::Method::operator()(std::vector<c10::IValue, std::allocator<c10::IValue> >, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, c10::IValue, 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, c10::IValue> > > const&) const'
/usr/bin/ld: ../../libtvm_runtime.a(libtorch_runtime.cc.o): in function `tvm::runtime::contrib::TorchModuleNode::GetSource(tvm::runtime::String const&)':
libtorch_runtime.cc:(.text._ZN3tvm7runtime7contrib15TorchModuleNode9GetSourceERKNS0_6StringE[_ZN3tvm7runtime7contrib15TorchModuleNode9GetSourceERKNS0_6StringE]+0x41): undefined reference to `torch::jit::Module::dump_to_str[abi:cxx11](bool, bool, bool) const'
/usr/bin/ld: ../../libtvm_runtime.a(libtorch_runtime.cc.o): in function `tvm::runtime::contrib::TorchModuleNode::SaveToBinary(dmlc::Stream*)':
libtorch_runtime.cc:(.text._ZN3tvm7runtime7contrib15TorchModuleNode12SaveToBinaryEPN4dmlc6StreamE[_ZN3tvm7runtime7contrib15TorchModuleNode12SaveToBinaryEPN4dmlc6StreamE]+0x2be): undefined reference to `torch::jit::Module::save(std::ostream&, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, 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, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > const&) const'
/usr/bin/ld: ../../libtvm_runtime.a(libtorch_runtime.cc.o): in function `torch::jit::Object::get_method(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const':
libtorch_runtime.cc:(.text._ZNK5torch3jit6Object10get_methodERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZNK5torch3jit6Object10get_methodERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x35): undefined reference to `torch::jit::Object::find_method(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
/usr/bin/ld: libtorch_runtime.cc:(.text._ZNK5torch3jit6Object10get_methodERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZNK5torch3jit6Object10get_methodERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x323): undefined reference to `c10::detail::torchCheckFail(char const*, char const*, unsigned int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
collect2: error: ld returned 1 exit status
make[2]: *** [apps/cpp_rtvm/CMakeFiles/rtvm.dir/build.make:142: rtvm] Error 1
make[1]: *** [CMakeFiles/Makefile2:1547: apps/cpp_rtvm/CMakeFiles/rtvm.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....

During the CMake configuration, the following warnings are displayed:

CMake Warning at tvm/lib/python3.9/site-packages/torch/share/cmake/Torch/TorchConfig.cmake:22 (message):
  static library kineto_LIBRARY-NOTFOUND not found.
Call Stack (most recent call first):
  tvm/lib/python3.9/site-packages/torch/share/cmake/Torch/TorchConfig.cmake:127 (append_torchlib_if_found)
  cmake/modules/contrib/LibTorch.cmake:19 (find_package)
  CMakeLists.txt:576 (include)

CMake Warning (dev) at cmake/modules/contrib/PT_TVMDSOOP.cmake:19 (find_package):
  Policy CMP0148 is not set: The FindPythonInterp and FindPythonLibs modules
  are removed.  Run "cmake --help-policy CMP0148" for policy details.  Use
  the cmake_policy command to set the policy and suppress this warning.

Call Stack (most recent call first):
  CMakeLists.txt:580 (include)
This warning is for project developers.  Use -Wno-dev to suppress it.

Here are my configuration options

--   ---------------- Summary ----------------
--   CMake version         : 3.28.3
--   CMake executable      : /usr/bin/cmake
--   Generator             : Unix Makefiles
--   System                : Linux
--   C++ compiler          : /usr/bin/c++
--   C++ compiler ID       : GNU
--   C++ compiler version  : 13.2.0
--   CXX flags             : -std=c++17 -faligned-new -O2 -Wall -fPIC 
--   CXX launcher          : 
--   Linker flags          : 
--   Build type            : 
--   Compile definitions   : TVM_INDEX_DEFAULT_I64=1;TVM_KALLOC_ALIGNMENT=64;TVM_THREADPOOL_USE_OPENMP=0;DMLC_USE_FOPEN64=0;NDEBUG=1;TVM_USE_CMSISNN;USE_MICRO_STANDALONE_RUNTIME=1
--   Options:
--    BACKTRACE_ON_SEGFAULT              : OFF
--    BUILD_DUMMY_LIBTVM                 : OFF
--    BUILD_STATIC_RUNTIME               : ON
--    COMPILER_RT_PATH                   : 3rdparty/compiler-rt
--    DLPACK_PATH                        : 3rdparty/dlpack/include
--    DMLC_PATH                          : 3rdparty/dmlc-core/include
--    HIDE_PRIVATE_SYMBOLS               : OFF
--    INDEX_DEFAULT_I64                  : ON
--    INSTALL_DEV                        : OFF
--    PICOJSON_PATH                      : 3rdparty/picojson
--    RANG_PATH                          : 3rdparty/rang/include
--    ROCM_PATH                          : /opt/rocm
--    SUMMARIZE                          : ON
--    TVM_DEBUG_WITH_ABI_CHANGE          : OFF
--    TVM_LOG_BEFORE_THROW               : OFF
--    USE_ALTERNATIVE_LINKER             : AUTO
--    USE_AMX                            : OFF
--    USE_AOT_EXECUTOR                   : ON
--    USE_ARM_COMPUTE_LIB                : OFF
--    USE_ARM_COMPUTE_LIB_GRAPH_EXECUTOR : OFF
--    USE_BLAS                           : none
--    USE_BNNS                           : OFF
--    USE_BYODT_POSIT                    : OFF
--    USE_CCACHE                         : AUTO
--    USE_CLML                           : OFF
--    USE_CLML_GRAPH_EXECUTOR            : OFF
--    USE_CMSISNN                        : ON
--    USE_COREML                         : OFF
--    USE_CPP_RPC                        : OFF
--    USE_CUBLAS                         : OFF
--    USE_CUDA                           : OFF
--    USE_CUDNN                          : OFF
--    USE_CURAND                         : OFF
--    USE_CUSTOM_LOGGING                 : OFF
--    USE_CUTLASS                        : OFF
--    USE_DNNL                           : OFF
--    USE_ETHOSN                         : OFF
--    USE_FALLBACK_STL_MAP               : OFF
--    USE_GRAPH_EXECUTOR                 : ON
--    USE_GRAPH_EXECUTOR_CUDA_GRAPH      : OFF
--    USE_GTEST                          : AUTO
--    USE_HEXAGON                        : OFF
--    USE_HEXAGON_EXTERNAL_LIBS          : OFF
--    USE_HEXAGON_GTEST                  : /path/to/hexagon/gtest
--    USE_HEXAGON_RPC                    : OFF
--    USE_HEXAGON_SDK                    : /path/to/sdk
--    USE_IOS_RPC                        : OFF
--    USE_KHRONOS_SPIRV                  : OFF
--    USE_LIBBACKTRACE                   : AUTO
--    USE_LIBTORCH                       : /home/oleehu/tvm/tvm/lib/python3.9/site-packages/torch
--    USE_LLVM                           : ON
--    USE_METAL                          : OFF
--    USE_MICRO                          : ON
--    USE_MICRO_STANDALONE_RUNTIME       : ON
--    USE_MIOPEN                         : OFF
--    USE_MKL                            : OFF
--    USE_MLIR                           : OFF
--    USE_MRVL                           : OFF
--    USE_MSC                            : OFF
--    USE_MSCCL                          : OFF
--    USE_MSVC_MT                        : OFF
--    USE_NCCL                           : OFF
--    USE_NNPACK                         : OFF
--    USE_NVTX                           : OFF
--    USE_OPENCL                         : OFF
--    USE_OPENCL_ENABLE_HOST_PTR         : OFF
--    USE_OPENCL_GTEST                   : /path/to/opencl/gtest
--    USE_OPENMP                         : none
--    USE_PAPI                           : OFF
--    USE_PROFILER                       : ON
--    USE_PT_TVMDSOOP                    : ON
--    USE_RANDOM                         : ON
--    USE_RCCL                           : OFF
--    USE_RELAY_DEBUG                    : ON
--    USE_ROCBLAS                        : OFF
--    USE_ROCM                           : OFF
--    USE_RPC                            : ON
--    USE_RTTI                           : ON
--    USE_RUST_EXT                       : OFF
--    USE_SORT                           : ON
--    USE_SPIRV_KHR_INTEGER_DOT_PRODUCT  : OFF
--    USE_STACKVM_RUNTIME                : ON
--    USE_TARGET_ONNX                    : ON
--    USE_TENSORFLOW_PATH                : /home/oleehu/tvm/tvm/lib/python3.9/site-packages/tensorflow
--    USE_TENSORRT_CODEGEN               : OFF
--    USE_TENSORRT_RUNTIME               : OFF
--    USE_TFLITE                         : OFF
--    USE_TF_TVMDSOOP                    : OFF
--    USE_THREADS                        : ON
--    USE_THRUST                         : OFF
--    USE_UMA                            : OFF
--    USE_VERILATOR                      : OFF
--    USE_VITIS_AI                       : OFF
--    USE_VULKAN                         : OFF
-- Build without FlashInfer

It seems that the "kineto" library is not available in the Linux version of Torch.

System Information OS: Ubuntu 22.04 CMake Version: 3.28.3 GCC Version: 13.2.0 PyTorch Version: 1.17 (installed via pip,also tried version 2.2.0) Python Version: 3.9.16 (within a virtual environment)

The linker errors indicate that certain PyTorch functions are not found. This typically happens when the necessary libraries are not linked correctly or there is a mismatch in the ABI (Application Binary Interface).

Any guidance or suggestions would be greatly appreciated. Thank you!