Closed desmoteo closed 3 years ago
Hi @desmoteo,
Can you link the diff of your CMake? The backends (e.g. armnn/src/backends/neon/CMakeLists.txt) are normally statically linked to libarmnn.so, so I'd be interested to see how you included them as part of libarmnn.a.
Thanks, Francis.
Thanks for the quick answer! A few changes were sufficient to get some libarmnn.a and libarmnnDelegate.a.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2b0c95254..99dda4c69 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -512,7 +512,7 @@ foreach(lib ${armnnLibraries})
list(APPEND armnn_sources $<TARGET_OBJECTS:${lib}>)
endforeach()
-add_library_ex(armnn SHARED ${armnn_sources})
+add_library_ex(armnn STATIC ${armnn_sources})
target_compile_definitions(armnn PRIVATE "ARMNN_COMPILING_DLL")
diff --git a/delegate/CMakeLists.txt b/delegate/CMakeLists.txt
index b43feb7f9..c8e711b6e 100644
--- a/delegate/CMakeLists.txt
+++ b/delegate/CMakeLists.txt
@@ -50,7 +50,7 @@ list(APPEND armnnDelegate_sources
src/Unpack.hpp
src/Transpose.hpp)
-add_library(armnnDelegate SHARED ${armnnDelegate_sources})
+add_library(armnnDelegate STATIC ${armnnDelegate_sources})
target_include_directories(armnnDelegate
PUBLIC
diff --git a/delegate/cmake/Modules/FindTfLite.cmake b/delegate/cmake/Modules/FindTfLite.cmake
index 41f55e3e8..a99344739 100644
--- a/delegate/cmake/Modules/FindTfLite.cmake
+++ b/delegate/cmake/Modules/FindTfLite.cmake
@@ -17,6 +17,7 @@ find_library(TfLite_LIB
NAMES
"libtensorflow_lite_all.so"
"libtensorflowlite.so"
+ "libtensorflow-lite.a"
HINTS
${TFLITE_LIB_ROOT}
${TFLITE_LIB_ROOT}/tensorflow/lite)
@@ -24,7 +25,8 @@ find_library(TfLite_LIB
find_path(TfLite_Schema_INCLUDE_PATH
schema_generated.h
HINTS
- ${TFLITE_LIB_ROOT}/tensorflow/lite/schema)
+ ${TFLITE_LIB_ROOT}/tensorflow/lite/schema
+ ${TFLITE_LIB_ROOT}/../tensorflow/lite/schema)
## Set TFLITE_FOUND
Hi @desmoteo,
Ah OK, I'm thinking you need to append the backend sources e.g the _${armnnNeonBackendsources} from armnn/src/backends/neon/CMakeLists.txt to the _armnnsources in armnn/CMakeLists.txt for each of the backends.
My assumption is you can't link a static library to a static library so you need to roll all the objects into one.
Can you use nm to check if the libarmnn.a contains any Neon specific functions?
nm -C libarmnn.a | grep NeonLayerSupport
Hope that's of some help, Francis.
Thanks @FrancisMurtagh-arm
This is interesting. The command
nm -C libarmnn.a | grep NeonLayerSupport
produces a lot of output. But when I run the same on the target executable, no reference to "Neon" is found. I'll try to dig in, can it be related to the BackendRegistry inner workings?
Matteo
OK I managed to include all missing symbols by using the following linker option:
-Wl,-whole-archive -larmnn -Wl,-no-whole-archive
The statically linked executable is now sensibly smaller than the previous ex + shared libs bundle. ArmNN with CpuAcc backend seems more than 2x faster than XNNPack delegate.
Thanks again for the suggestions, @FrancisMurtagh-arm !
Hi @desmoteo,
I wasn't aware of that option but it does make sense; thanks and nicely done.
Do you plan to publish these results anywhere? I'm sure others would be interested. @jimfly01
Thanks, Francis.
Hi @FrancisMurtagh-arm
Yes, I will write it down and post a link here.
Closing this
I have been trying to build static libarmnn.a and libarmnnDelegate.a to use on aarch64 devices (cortex-A53) in order to limit storage usage. I managed to compile the libraries and link the target executable, anyway when running on the target I get the following error:
I built the libraries following the cross compilation documentation and modified the cmake command for armnn build as follows:
I create the delegate as follows:
I don't understand what I am doing wrong. Any help is welcome.