Skip to content

Linking errors when trying to use pre built executorch binaries for running lowered resnet50 in executorch runtime. #8196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
sidharthkumar10500 opened this issue Feb 4, 2025 · 4 comments
Assignees
Labels
module: build/install Issues related to the cmake and buck2 builds, and to installing ExecuTorch module: user experience Issues related to reducing friction for users need-user-input The issue needs more information from the reporter before moving forward triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@sidharthkumar10500
Copy link

sidharthkumar10500 commented Feb 4, 2025

🚀 The feature, motivation and pitch

I am trying to use executorch without building it everytime I build my project.
Everything works when I compile executorch by adding
add_subdirectory(/home/sidharth/executorch /home/sidharth/executorch_build)
This line to my cmakelists.txt.
However when I try to install the required targets and files to another folder, I keep getting the following error.

/usr/bin/ld: /home/sidharth/executorch_examples/tota/lib/libextension_tensor.a(tensor_impl_ptr.cpp.o): in function executorch::extension::make_tensor_impl_ptr(std::vector<int, std::allocator >, void*, std::vector<unsigned char, std::allocator >, std::vector<int, std::allocator >, executorch::runtime::etensor::ScalarType, executorch::runtime::TensorShapeDynamism, std::function<void (void*)>)':
/home/sidharth/executorch/extension/tensor/tensor_impl_ptr.cpp:65: undefined reference to executorch::runtime::internal::get_log_timestamp()' /usr/bin/ld: /home/sidharth/executorch/extension/tensor/tensor_impl_ptr.cpp:65: undefined reference to executorch::runtime::runtime_abort()'
/usr/bin/ld: /home/sidharth/executorch/extension/tensor/tensor_impl_ptr.cpp:68: undefined reference to executorch::runtime::internal::get_log_timestamp()' /usr/bin/ld: /home/sidharth/executorch/extension/tensor/tensor_impl_ptr.cpp:68: undefined reference to executorch::runtime::runtime_abort()'
/usr/bin/ld: /home/sidharth/executorch/extension/tensor/tensor_impl_ptr.cpp:84: undefined reference to executorch::runtime::internal::get_log_timestamp()' /usr/bin/ld: /home/sidharth/executorch/extension/tensor/tensor_impl_ptr.cpp:84: undefined reference to executorch::runtime::runtime_abort()'
/usr/bin/ld: /home/sidharth/executorch/extension/tensor/tensor_impl_ptr.cpp:87: undefined reference to executorch::runtime::internal::get_log_timestamp()' /usr/bin/ld: /home/sidharth/executorch/extension/tensor/tensor_impl_ptr.cpp:87: undefined reference to executorch::runtime::runtime_abort()'
/usr/bin/ld: /home/sidharth/executorch_examples/tota/lib/libextension_tensor.a(tensor_impl_ptr.cpp.o): in function executorch::extension::make_tensor_impl_ptr(std::vector<int, std::allocator<int> >, std::vector<unsigned char, std::allocator<unsigned char> >, std::vector<unsigned char, std::allocator<unsigned char> >, std::vector<int, std::allocator<int> >, executorch::runtime::etensor::ScalarType, executorch::runtime::TensorShapeDynamism)': /home/sidharth/executorch/extension/tensor/tensor_impl_ptr.cpp:138: undefined reference to executorch::runtime::etensor::compute_numel(int const*, long)'
/usr/bin/ld: /home/sidharth/executorch/extension/tensor/tensor_impl_ptr.cpp:138: undefined reference to executorch::runtime::internal::get_log_timestamp()' /usr/bin/ld: /home/sidharth/executorch/extension/tensor/tensor_impl_ptr.cpp:138: undefined reference to executorch::runtime::runtime_abort()'
/usr/bin/ld: /home/sidharth/executorch_examples/tota/lib/libextension_tensor.a(tensor_impl_ptr.cpp.o): in function executorch::runtime::internal::logf(executorch::runtime::LogLevel, unsigned long, char const*, char const*, unsigned long, char const*, ...)': /home/sidharth/executorch/extension/tensor/../../../executorch/runtime/platform/log.h:131: undefined reference to executorch::runtime::internal::vlogf(executorch::runtime::LogLevel, unsigned long, char const*, char const*, unsigned long, char const*, __va_list_tag*)'
/usr/bin/ld: /home/sidharth/executorch_examples/tota/lib/libextension_tensor.a(tensor_impl_ptr.cpp.o): in function executorch::runtime::elementSize(executorch::runtime::etensor::ScalarType)': /home/sidharth/executorch/extension/tensor/../../../executorch/runtime/core/exec_aten/util/scalar_type_util.h:402: undefined reference to executorch::runtime::internal::get_log_timestamp()'
/usr/bin/ld: /home/sidharth/executorch/extension/tensor/../../../executorch/runtime/core/exec_aten/util/scalar_type_util.h:402: undefined reference to executorch::runtime::runtime_abort()' /usr/bin/ld: /home/sidharth/executorch_examples/tota/lib/libextension_tensor.a(tensor_impl_ptr.cpp.o): in function executorch::runtime::Error executorch::runtime::dim_order_to_stride<int, unsigned char, int>(int const*, unsigned char const*, unsigned long, int*)':
/home/sidharth/executorch/extension/tensor/../../../executorch/runtime/core/exec_aten/util/dim_order_util.h:146: undefined reference to executorch::runtime::internal::get_log_timestamp()' /usr/bin/ld: /home/sidharth/executorch_examples/tota/lib/libextension_tensor.a(tensor_impl_ptr.cpp.o): in function std::__detail::_MakeUniqexecutorch::runtime::etensor::TensorImpl::__single_object std::make_unique<executorch::runtime::etensor::TensorImpl, executorch::runtime::etensor::ScalarType&, unsigned long const&, int*, void*&, unsigned char*, int*, executorch::runtime::TensorShapeDynamism>(executorch::runtime::etensor::ScalarType&, unsigned long const&, int*&&, void*&, unsigned char*&&, int*&&, executorch::runtime::TensorShapeDynamism&&)':
/usr/include/c++/12/bits/unique_ptr.h:1065: undefined reference to executorch::runtime::etensor::TensorImpl::TensorImpl(executorch::runtime::etensor::ScalarType, long, int*, void*, unsigned char*, int*, executorch::runtime::TensorShapeDynamism)' collect2: error: ld returned 1 exit status gmake[2]: *** [CMakeFiles/executorch_demo.dir/build.make:115: executorch_demo] Error 1 gmake[1]: *** [CMakeFiles/Makefile2:87: CMakeFiles/executorch_demo.dir/all] Error 2 gmake: *** [Makefile:91: all] Error 2

I have added the include and lib folders in the cmakelists.txt as required but still getting this linking error.
`
target_include_directories(executorch_demo PUBLIC /home/sidharth/executorch_examples/tota/include/)
target_link_directories(executorch_demo PUBLIC /home/sidharth/executorch_examples/tota/lib/)

target_link_libraries(
executorch_demo
PRIVATE executorch
extension_module_static # Provides the Module class
extension_tensor # Provides the TensorPtr class
optimized_native_cpu_ops_lib # Provides baseline cross-platform
xnnpack_backend
PUBLIC ${OpenCV_LIBS}
)`

Can you please help me in sorting this issue?

Alternatives

No response

Additional context

No response

RFC (Optional)

No response

cc @larryliu0820 @mergennachin @byjlw

@digantdesai
Copy link
Contributor

digantdesai commented Feb 5, 2025

Everything works when I compile executorch by adding
add_subdirectory(/home/sidharth/executorch /home/sidharth/executorch_build)
This line to my cmakelists.txt.
However when I try to install the required targets and files to another folder, I keep getting the following error.

Not sure what's going on. Assuming the installed ExecuTorch has everything, i.e. executorch_core is linked in here.

Can you try find_package(executorch REQUIRED) in your CMake as suggested here? See example here

@digantdesai digantdesai added module: build/install Issues related to the cmake and buck2 builds, and to installing ExecuTorch triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module need-user-input The issue needs more information from the reporter before moving forward labels Feb 5, 2025
@sidharthkumar10500
Copy link
Author

Thanks for getting back on this.
I updated to the v0.5 of the executorch github and can see the updated executorch-config.cmake file.
When I try to install the project, only the .a files get copied and the header files are still missing. The install command did not automatically copy those. So to overcome this, I added the following to my cmakelists.txt file.
set(EXECUTORCH_ROOT /home/sidharth/) set(_common_include_directories ${EXECUTORCH_ROOT}) target_include_directories(${PROJECT_NAME} PUBLIC ${_common_include_directories})
this basically searches for the header files in the executorch root folder. Now the following works
find_package(executorch CONFIG REQUIRED)
I have access to the following variables EXECUTORCH_FOUND, EXECUTORCH_INCLUDE_DIRS, and EXECUTORCH_LIBRARIES. EXECUTORCH_INCLUDE_DIRS does not have the required header files that I overcame with the method I described earlier.
Now with this I am able to build my project to do some classification task with the resnet 50 model. When I run the infernce I get the following error.
E 00:00:00.044839 executorch:method.cpp:65] Backend XnnpackBackend is not registered.
If I dont use the xnnpack, then I get the following error.
E 00:00:00.202999 executorch:method.cpp:554] Missing operator: [7] aten::permute_copy.out E 00:00:00.203007 executorch:operator_registry.cpp:185] kernel 'aten::addmm.out' not found. E 00:00:00.203011 executorch:operator_registry.cpp:186] dtype: 6 | dim order: [ E 00:00:00.203015 executorch:operator_registry.cpp:186] 0, E 00:00:00.203020 executorch:operator_registry.cpp:186] ] E 00:00:00.203023 executorch:operator_registry.cpp:186] dtype: 6 | dim order: [ E 00:00:00.203027 executorch:operator_registry.cpp:186] 0, E 00:00:00.203031 executorch:operator_registry.cpp:186] 1, E 00:00:00.203034 executorch:operator_registry.cpp:186] ] E 00:00:00.203040 executorch:operator_registry.cpp:186] dtype: 6 | dim order: [ E 00:00:00.203042 executorch:operator_registry.cpp:186] 0, E 00:00:00.203047 executorch:operator_registry.cpp:186] 1, E 00:00:00.203050 executorch:operator_registry.cpp:186] ] E 00:00:00.203053 executorch:operator_registry.cpp:186] dtype: 6 | dim order: [ E 00:00:00.203056 executorch:operator_registry.cpp:186] 0, E 00:00:00.203060 executorch:operator_registry.cpp:186] 1, E 00:00:00.203063 executorch:operator_registry.cpp:186] ] E 00:00:00.203068 executorch:operator_registry.cpp:186] dtype: 6 | dim order: [ E 00:00:00.203073 executorch:operator_registry.cpp:186] 0, E 00:00:00.203076 executorch:operator_registry.cpp:186] 1, E 00:00:00.203080 executorch:operator_registry.cpp:186] ] E 00:00:00.203083 executorch:method.cpp:554] Missing operator: [8] aten::addmm.out E 00:00:00.203087 executorch:method.cpp:763] There are 175 instructions don't have corresponding operator registered. See logs for details
Basically it looks like none of the operators are getting registered.

However if build the executorch with my current project using # add_subdirectory(/home/sidharth/executorch /home/sidharth/executorch_build) then everything works properly. With all this I have following questions:-

  1. Do I have always include the executorch root folder to take care of including the header files or they will be automatically installed in a later version.
  2. Am I missing some steps that is throwing me the xnnbackend and the operator register errors. To install executorch, I followed the steps from this [link](https://pytorch.org/executorch/stable/getting-started-setup.html#clone-and-install-executorch-requirements).
  3. Is there an example CMakeLists.txt for building test projects without rebuilding executorch eachtime?

Thanks for all your help!

@larryliu0820
Copy link
Contributor

@sidharthkumar10500 the headers live inside <site-packages>/executorch/include:

[site-packages/executorch/include]$ tree
.
└── executorch
    ├── extension
    │   ├── kernel_util
    │   │   ├── make_boxed_from_unboxed_functor.h
    │   │   ├── meta_programming.h
    │   │   └── type_list.h
    │   ├── tensor
    │   │   ├── tensor_accessor.h
    │   │   ├── tensor.h
    │   │   ├── tensor_ptr.h
    │   │   └── tensor_ptr_maker.h
...

@larryliu0820
Copy link
Contributor

@sidharthkumar10500 for your build error

Now with this I am able to build my project to do some classification task with the resnet 50 model. When I run the infernce I get the following error.
E 00:00:00.044839 executorch:method.cpp:65] Backend XnnpackBackend is not registered.
If I dont use the xnnpack, then I get the following error.
E 00:00:00.202999 executorch:method.cpp:554] Missing operator: [7] aten::permute_copy.out E 00:00:00.203007 executorch:operator_registry.cpp:185] kernel 'aten::addmm.out' not found. E 00:00:00.203011

I think you want to link against _portable_lib which should contain XNNPack and portable kernels.

Check your ExecuTorch installation and see if this can be found: <site-packages>/executorch/extension/pybinidngs/_portable_lib.cpython-311-x86_64-linux-gnu.so

If so I think you should be able to use the following:

find_package(executorch CONFIG REQUIRED)
target_link_libraries(<binary> PUBLIC _portable_lib)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: build/install Issues related to the cmake and buck2 builds, and to installing ExecuTorch module: user experience Issues related to reducing friction for users need-user-input The issue needs more information from the reporter before moving forward triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
Status: In progress
Status: In progress
Development

No branches or pull requests

4 participants