diff --git a/meta-digi-dey/dynamic-layers/stm32mpu-ai/recipes-frameworks/tensorflow-lite/files/0006-TFLite-cmake-add-XNNPACK-delegate-u8-and-i8-definition.patch b/meta-digi-dey/dynamic-layers/stm32mpu-ai/recipes-frameworks/tensorflow-lite/files/0006-TFLite-cmake-add-XNNPACK-delegate-u8-and-i8-definition.patch new file mode 100644 index 000000000..6aea05595 --- /dev/null +++ b/meta-digi-dey/dynamic-layers/stm32mpu-ai/recipes-frameworks/tensorflow-lite/files/0006-TFLite-cmake-add-XNNPACK-delegate-u8-and-i8-definition.patch @@ -0,0 +1,25 @@ +From c8af5997f3d9b851ff81ef1fb4045ec59f80d976 Mon Sep 17 00:00:00 2001 +From: Alexis BRISSON +Date: Wed, 10 May 2023 16:44:47 +0200 +Subject: [PATCH 1/1] TFLite add XNNPACK delegate u8 and i8 definition + +Signed-off-by: Alexis BRISSON +--- + tensorflow/lite/CMakeLists.txt | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/tensorflow/lite/CMakeLists.txt b/tensorflow/lite/CMakeLists.txt +index 073b29c4860..b3b89a4236c 100644 +--- a/tensorflow/lite/CMakeLists.txt ++++ b/tensorflow/lite/CMakeLists.txt +@@ -404,6 +404,8 @@ if(TFLITE_ENABLE_XNNPACK) + TFLITE_DELEGATES_XNNPACK_SRCS + FILTER ".*(_test|_tester)\\.(cc|h)" + ) ++ add_definitions( -DXNNPACK_DELEGATE_ENABLE_QS8=1 ) ++ add_definitions( -DXNNPACK_DELEGATE_ENABLE_QU8=1 ) + list(APPEND TFLITE_TARGET_DEPENDENCIES + XNNPACK + ) +-- +2.25.1 diff --git a/meta-digi-dey/dynamic-layers/stm32mpu-ai/recipes-frameworks/tensorflow-lite/files/0007-TFLite-fix-aarch64-support-for-XNNPACK.patch b/meta-digi-dey/dynamic-layers/stm32mpu-ai/recipes-frameworks/tensorflow-lite/files/0007-TFLite-fix-aarch64-support-for-XNNPACK.patch new file mode 100644 index 000000000..62519cb53 --- /dev/null +++ b/meta-digi-dey/dynamic-layers/stm32mpu-ai/recipes-frameworks/tensorflow-lite/files/0007-TFLite-fix-aarch64-support-for-XNNPACK.patch @@ -0,0 +1,44 @@ +From 78cbe3bb1970982adf32c9966b83789301d45cd8 Mon Sep 17 00:00:00 2001 +From: Maxence GUILHIN +Date: Mon, 10 Jul 2023 15:47:59 +0200 +Subject: [PATCH 1/1] tensorflow-lite : fix aarch64 support for XNNPACK + +The "-mcpu=" switch might be introduced externaly into CMake: either in _FLAGS or +as part of CC, CXX, ASM environmental variables (to be stored in CMAKE__COMPILER_ARG1). +This switch is not compatible with XNNPACK build mechanism and causes the XNNPACK compilation +break due to "unsupported instructions". This switch needs to be removed for XNNPACK +In order to isolate the changes only for XNNPACK and its depencencies, a subfolder is +introduced. + +Signed-off-by: Maxence GUILHIN +--- + tensorflow/lite/tools/cmake/modules/xnnpack.cmake | 14 ++++++++++++++ + 1 file changed, 14 insertions(+) + +diff --git a/tensorflow/lite/tools/cmake/modules/xnnpack.cmake b/tensorflow/lite/tools/cmake/modules/xnnpack.cmake +index 24f0674cf92..028fc3a76e2 100644 +--- a/tensorflow/lite/tools/cmake/modules/xnnpack.cmake ++++ b/tensorflow/lite/tools/cmake/modules/xnnpack.cmake +@@ -38,6 +38,20 @@ endif() + set(XNNPACK_BUILD_TESTS OFF CACHE BOOL "Disable XNNPACK test.") + set(XNNPACK_BUILD_BENCHMARKS OFF CACHE BOOL "Disable XNNPACK benchmarks.") + ++# The "-mcpu=" switch might be introduced externaly into CMake: either in _FLAGS or ++# as part of CC, CXX, ASM environmental variables (to be stored in CMAKE__COMPILER_ARG1). ++# This switch is not compatible with XNNPACK build mechanism and causes the XNNPACK compilation ++# break due to "unsupported instructions". This switch needs to be removed for XNNPACK ++# In order to isolate the changes only for XNNPACK and its depencencies, a subfolder is ++# introduced. ++ ++foreach(FLAG IN ITEMS CMAKE_ASM_FLAGS CMAKE_ASM_COMPILER_ARG1 CMAKE_C_FLAGS CMAKE_C_COMPILER_ARG1 CMAKE_CXX_FLAGS CMAKE_CXX_COMPILER_ARG1) ++ if(${FLAG}) ++ string(REGEX REPLACE "-mcpu=[-a-zA-Z0-9_.^$*+?]*" "" _tmp ${${FLAG}}) ++ set(${FLAG} ${_tmp}) ++ endif() ++endforeach() ++ + # The following line adds project of PTHREADPOOL, FP16 and XNNPACK which are + # needed to compile XNNPACK delegate of TFLite. + add_subdirectory( +-- +2.25.1 diff --git a/meta-digi-dey/dynamic-layers/stm32mpu-ai/recipes-frameworks/tensorflow-lite/files/0008-TFLite-cmake-change-visibility-compilation-options.patch b/meta-digi-dey/dynamic-layers/stm32mpu-ai/recipes-frameworks/tensorflow-lite/files/0008-TFLite-cmake-change-visibility-compilation-options.patch new file mode 100644 index 000000000..714f30fbe --- /dev/null +++ b/meta-digi-dey/dynamic-layers/stm32mpu-ai/recipes-frameworks/tensorflow-lite/files/0008-TFLite-cmake-change-visibility-compilation-options.patch @@ -0,0 +1,30 @@ +From 0675ef8a401c5f77aeb674b006594190c7f58810 Mon Sep 17 00:00:00 2001 +From: Othmane AHL ZOUAOUI +Date: Wed, 20 Mar 2024 15:05:40 +0100 +Subject: [PATCH 8/8] TFLite: cmake: change visibility compilation options + +Changing the compile options of the libtensorflow-lite shared lib +to export all the symbols of the lib and make them visible during +the runtime. + +Change-Id: I25a88a3ba29b00d1f40336e10acb898ab8b016a5 +Signed-off-by: Othmane AHL ZOUAOUI +--- + tensorflow/lite/CMakeLists.txt | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/tensorflow/lite/CMakeLists.txt b/tensorflow/lite/CMakeLists.txt +index 40812886306..f7bb65d894a 100644 +--- a/tensorflow/lite/CMakeLists.txt ++++ b/tensorflow/lite/CMakeLists.txt +@@ -517,6 +517,8 @@ set(_ALL_TFLITE_SRCS + add_library(tensorflow-lite SHARED EXCLUDE_FROM_ALL + ${_ALL_TFLITE_SRCS} + ) ++target_compile_options(tensorflow-lite PRIVATE -fvisibility=hidden) ++target_compile_options(tensorflow-lite PRIVATE -fvisibility=default) + set(_ALL_TFLITE_HDRS ${_ALL_TFLITE_SRCS}) + list(FILTER _ALL_TFLITE_HDRS INCLUDE REGEX ".*\\.h$") + target_include_directories(tensorflow-lite +-- +2.34.1 diff --git a/meta-digi-dey/dynamic-layers/stm32mpu-ai/recipes-frameworks/tensorflow-lite/tensorflow-lite_git.bbappend b/meta-digi-dey/dynamic-layers/stm32mpu-ai/recipes-frameworks/tensorflow-lite/tensorflow-lite_git.bbappend new file mode 100644 index 000000000..6eb361db0 --- /dev/null +++ b/meta-digi-dey/dynamic-layers/stm32mpu-ai/recipes-frameworks/tensorflow-lite/tensorflow-lite_git.bbappend @@ -0,0 +1,47 @@ +# Copyright (C) 2024, Digi International Inc. + +FILESEXTRAPATHS:prepend := "${THISDIR}/files:" + +SRC_URI += " file://0006-TFLite-cmake-add-XNNPACK-delegate-u8-and-i8-definition.patch " +SRC_URI += " file://0008-TFLite-cmake-change-visibility-compilation-options.patch " +SRC_URI:append:stm32mp2common = " file://0007-TFLite-fix-aarch64-support-for-XNNPACK.patch " + +# Set building environment variables +TENSORFLOW_TARGET:aarch64="linux" +TENSORFLOW_TARGET_ARCH:aarch64="aarch64" + +# Activate -O3 optimization and disable debug symbols +OECMAKE_C_FLAGS_RELEASE = "-O3 -DNDEBUG" +OECMAKE_CXX_FLAGS_RELEASE = "-O3 -DNDEBUG" +# Build tensorflow-lite.so library, _pywrap_tensorflow_interpreter_wrapper.so library and the benchmark_model application +OECMAKE_TARGET_COMPILE = "tensorflow-lite _pywrap_tensorflow_interpreter_wrapper benchmark_model" + +EXTRA_OECMAKE += " -DTFLITE_ENABLE_XNNPACK=OFF " + +do_compile() { + # Standard CMAKE build. + cmake_runcmake_build --target ${OECMAKE_TARGET_COMPILE} + # Build the python wheel (procedure extract form the build_pip_package_with_cmake.sh) + BUILD_DIR=${WORKDIR}/build + TENSORFLOW_DIR=${S} + TENSORFLOW_LITE_DIR="${TENSORFLOW_DIR}/tensorflow/lite" + TENSORFLOW_VERSION=$(grep "_VERSION = " "${TENSORFLOW_DIR}/tensorflow/tools/pip_package/setup.py" | cut -d= -f2 | sed "s/[ '-]//g") + mkdir -p "${BUILD_DIR}/tflite_runtime" + cp -r "${TENSORFLOW_LITE_DIR}/tools/pip_package/debian" \ + "${TENSORFLOW_LITE_DIR}/tools/pip_package/MANIFEST.in" \ + "${BUILD_DIR}" + cp -r "${TENSORFLOW_LITE_DIR}/python/interpreter_wrapper" "${BUILD_DIR}" + cp "${TENSORFLOW_LITE_DIR}/tools/pip_package/setup_with_binary.py" "${BUILD_DIR}/setup.py" + cp "${TENSORFLOW_LITE_DIR}/python/interpreter.py" \ + "${TENSORFLOW_LITE_DIR}/python/metrics/metrics_interface.py" \ + "${TENSORFLOW_LITE_DIR}/python/metrics/metrics_portable.py" \ + "${BUILD_DIR}/tflite_runtime" + echo "__version__ = '${TENSORFLOW_VERSION}'" >> "${BUILD_DIR}/tflite_runtime/__init__.py" + echo "__git_version__ = '$(git -C "${TENSORFLOW_DIR}" describe)'" >> "${BUILD_DIR}/tflite_runtime/__init__.py" + + export PACKAGE_VERSION="${TENSORFLOW_VERSION}" + export PROJECT_NAME="tflite_runtime" + cp "${BUILD_DIR}/_pywrap_tensorflow_interpreter_wrapper.so" "tflite_runtime" + + setuptools3_do_compile +}