From: Chirag Shilwant <[email protected]>
- TensorFlow Lite is TensorFlow's lightweight solution for mobile
and embedded devices. It enables low-latency inference of on-device
machine learning models with a small binary size.
- The tensorflow-lite v2.16 recipe in meta-arago currently supports,
- CPU delegate (with RUY enabled), XNNPACK delegate & ArmNN
via external delegate for ARMv8 based Cortex-A platforms.
- CPU delegate (with RUY enabled) & ArmNN via external delegate
for ARMv7 based Cortex-A platforms.
Signed-off-by: Chirag Shilwant <[email protected]>
---
...eLists-for-building-_pywrap_tensorfl.patch | 37 ++++
...eLists-for-building-shared-object-li.patch | 55 +++++
...uild-issues-observed-in-TFlite-v2.16.patch | 36 ++++
.../tensorflow-lite/tensorflow-lite_2.16.bb | 203 ++++++++++++++++++
4 files changed, 331 insertions(+)
create mode 100644
meta-arago-extras/recipes-framework/tensorflow-lite/tensorflow-lite/0001-lite-Update-CMakeLists-for-building-_pywrap_tensorfl.patch
create mode 100644
meta-arago-extras/recipes-framework/tensorflow-lite/tensorflow-lite/0002-lite-Update-CMakeLists-for-building-shared-object-li.patch
create mode 100644
meta-arago-extras/recipes-framework/tensorflow-lite/tensorflow-lite/0003-CMakeLists-Fix-build-issues-observed-in-TFlite-v2.16.patch
create mode 100644
meta-arago-extras/recipes-framework/tensorflow-lite/tensorflow-lite_2.16.bb
diff --git
a/meta-arago-extras/recipes-framework/tensorflow-lite/tensorflow-lite/0001-lite-Update-CMakeLists-for-building-_pywrap_tensorfl.patch
b/meta-arago-extras/recipes-framework/tensorflow-lite/tensorflow-lite/0001-lite-Update-CMakeLists-for-building-_pywrap_tensorfl.patch
new file mode 100644
index 00000000..0eed77f9
--- /dev/null
+++
b/meta-arago-extras/recipes-framework/tensorflow-lite/tensorflow-lite/0001-lite-Update-CMakeLists-for-building-_pywrap_tensorfl.patch
@@ -0,0 +1,37 @@
+From 64b8e731309f1ee9ad41bd65d7661854d5c3106c Mon Sep 17 00:00:00 2001
+From: Chirag Shilwant <[email protected]>
+Date: Sun, 19 Jan 2025 14:54:25 +0530
+Subject: [PATCH 1/2] lite: Update CMakeLists for building
+ _pywrap_tensorflow_interpreter_wrapper
+
+- Update the CMakeLists.txt file for TensorFlow Lite to include the
paths for
+PYTHON, Numpy, and PYBIND11 headers.
+
+- This ensures that these headers are available during the build
process,
+which is necessary for building the
_pywrap_tensorflow_interpreter_wrapper
+target that relies on these dependencies.
+
+Upstream-Status: Inappropriate [configuration]
+
+Signed-off-by: Chirag Shilwant <[email protected]>
+---
+ tensorflow/lite/CMakeLists.txt | 3 +++
+ 1 file changed, 3 insertions(+)
+
+diff --git a/tensorflow/lite/CMakeLists.txt
b/tensorflow/lite/CMakeLists.txt
+index a61f537365a..f41e57d9155 100644
+--- a/tensorflow/lite/CMakeLists.txt
++++ b/tensorflow/lite/CMakeLists.txt
+@@ -727,6 +727,9 @@
set_target_properties(_pywrap_tensorflow_interpreter_wrapper
PROPERTIES PREFIX "
+ target_include_directories(_pywrap_tensorflow_interpreter_wrapper
+ PUBLIC
+ ${TENSORFLOW_SOURCE_DIR}
++ ${PYTHON_TARGET_INCLUDE}
++ ${NUMPY_TARGET_INCLUDE}
++ ${PYBIND11_TARGET_INCLUDE}
+ )
+
+ target_link_libraries(_pywrap_tensorflow_interpreter_wrapper
+--
+2.34.1
+
diff --git
a/meta-arago-extras/recipes-framework/tensorflow-lite/tensorflow-lite/0002-lite-Update-CMakeLists-for-building-shared-object-li.patch
b/meta-arago-extras/recipes-framework/tensorflow-lite/tensorflow-lite/0002-lite-Update-CMakeLists-for-building-shared-object-li.patch
new file mode 100644
index 00000000..a8c4f2ba
--- /dev/null
+++
b/meta-arago-extras/recipes-framework/tensorflow-lite/tensorflow-lite/0002-lite-Update-CMakeLists-for-building-shared-object-li.patch
@@ -0,0 +1,55 @@
+From 92adea5bb011ed36c9b63bd442bf147fad96a5bb Mon Sep 17 00:00:00 2001
+From: Chirag Shilwant <[email protected]>
+Date: Sun, 19 Jan 2025 15:08:59 +0530
+Subject: [PATCH 2/2] lite: Update CMakeLists for building shared object
+ library
+
+- When building TFLite with CMake, it builds static library
+(i.e. libtensorflow-lite.a) by default which isn't self-contained
+since all the transitive dependencies are not included [1]
+
+- As documented in [1], there's an update needed in CMake build steps
+inorder to generate a shared object library (i.e.
libtensorflow-lite.so)
+
+- This patch adds schema_conversion_utils.cc to TFLite source files
+& updates CMakeLists.txt to build TFLite as a shared library.
Additionally,
+it ensures that the properties are set correctly to manage the shared
+object version.
+
+[1]: https://ai.google.dev/edge/litert/build/cmake#step_5_build_litert
+
+Upstream-Status: Inappropriate [enable feature]
+
+Signed-off-by: Chirag Shilwant <[email protected]>
+---
+ tensorflow/lite/CMakeLists.txt | 6 +++++-
+ 1 file changed, 5 insertions(+), 1 deletion(-)
+
+diff --git a/tensorflow/lite/CMakeLists.txt
b/tensorflow/lite/CMakeLists.txt
+index f41e57d9155..923c673d623 100644
+--- a/tensorflow/lite/CMakeLists.txt
++++ b/tensorflow/lite/CMakeLists.txt
+@@ -622,8 +622,9 @@ set(_ALL_TFLITE_SRCS
+ ${TFLITE_SOURCE_DIR}/schema/conversion_metadata_generated.h
+ ${TFLITE_SOURCE_DIR}/schema/schema_utils.cc
+ ${TFLITE_SOURCE_DIR}/schema/schema_generated.h
++ ${TFLITE_SOURCE_DIR}/schema/schema_conversion_utils.cc
+ )
+-add_library(tensorflow-lite
++add_library(tensorflow-lite SHARED EXCLUDE_FROM_ALL
+ ${_ALL_TFLITE_SRCS}
+ )
+ set(_ALL_TFLITE_HDRS ${_ALL_TFLITE_SRCS})
+@@ -700,6 +701,9 @@ if(TFLITE_ENABLE_INSTALL)
+ )
+ endif()
+
++# Manage version for shared object (dynamic) library
++set_target_properties(tensorflow-lite PROPERTIES VERSION
"${TFLITE_VERSION_MAJOR}")
++
+ # The kernel tests.
+ if(TFLITE_KERNEL_TEST)
+ enable_testing()
+--
+2.34.1
+
diff --git
a/meta-arago-extras/recipes-framework/tensorflow-lite/tensorflow-lite/0003-CMakeLists-Fix-build-issues-observed-in-TFlite-v2.16.patch
b/meta-arago-extras/recipes-framework/tensorflow-lite/tensorflow-lite/0003-CMakeLists-Fix-build-issues-observed-in-TFlite-v2.16.patch
new file mode 100644
index 00000000..d38a3cdd
--- /dev/null
+++
b/meta-arago-extras/recipes-framework/tensorflow-lite/tensorflow-lite/0003-CMakeLists-Fix-build-issues-observed-in-TFlite-v2.16.patch
@@ -0,0 +1,36 @@
+From 1b93fb907b3436edf2b64db94f74b1db724943ae Mon Sep 17 00:00:00 2001
+From: Chirag Shilwant <[email protected]>
+Date: Mon, 20 Jan 2025 19:51:20 +0530
+Subject: [PATCH] CMakeLists: Fix build issues observed in TFlite v2.16
+
+- Improve regular expression for filtering neon and sse
+related sources. The improved expression avoids missing files
+in case the absolute path contains the terms neon or sse.
+
+- Fixes [1]
+
+[1]: https://github.com/tensorflow/tensorflow/issues/70730
+
+Upstream-Status: Backport from master
+
+Signed-off-by: Chirag Shilwant <[email protected]>
+---
+ tensorflow/lite/CMakeLists.txt | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/tensorflow/lite/CMakeLists.txt
b/tensorflow/lite/CMakeLists.txt
+index 923c673d623..3e2fb501bde 100644
+--- a/tensorflow/lite/CMakeLists.txt
++++ b/tensorflow/lite/CMakeLists.txt
+@@ -554,7 +554,7 @@
populate_tflite_source_vars("kernels/internal/reference/sparse_ops"
+ )
+ populate_tflite_source_vars("kernels/internal/optimized/4bit"
+ TFLITE_KERNEL_INTERNAL_OPT_4BIT_SRCS
+- FILTER "(.*neon.*|.*sse.*)\\.(cc|h)"
++ FILTER "(.*neon_.*|.*sse_.*)\\.(cc|h)"
+ )
+ set(TFLITE_PROFILER_SRCS
+ ${TFLITE_SOURCE_DIR}/profiling/platform_profiler.cc
+--
+2.34.1
+
diff --git
a/meta-arago-extras/recipes-framework/tensorflow-lite/tensorflow-lite_2.16.bb
b/meta-arago-extras/recipes-framework/tensorflow-lite/tensorflow-lite_2.16.bb
new file mode 100644
index 00000000..ca51d6dc
--- /dev/null
+++
b/meta-arago-extras/recipes-framework/tensorflow-lite/tensorflow-lite_2.16.bb
@@ -0,0 +1,203 @@
+DESCRIPTION = "TensorFlow Lite is an open source deep learning
framework for \
+on-device inference."
+AUTHOR = "Google Inc. and Yuan Tang"
+SUMMARY = "TensorFlow Lite C++ Library, Python interpreter &
Benchmark Model"
+HOMEPAGE = "https://www.tensorflow.org/lite"
+
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM =
"file://LICENSE;md5=4158a261ca7f2525513e31ba9c50ae98"
+
+PV = "2.16.2"
+
+# Get major of the PV variable
+MAJOR = "${@d.getVar('PV').split('.')[0]}"
+
+# Matches v${PV} tag
+SRCREV = "810f233968cec850915324948bbbc338c97cf57f"
+
+SRC_URI = " \
+ git://github.com/tensorflow/tensorflow;protocol=https;branch=r2.16 \
+
file://0001-lite-Update-CMakeLists-for-building-_pywrap_tensorfl.patch \
+
file://0002-lite-Update-CMakeLists-for-building-shared-object-li.patch \
+
file://0003-CMakeLists-Fix-build-issues-observed-in-TFlite-v2.16.patch \
+"
+
+S = "${WORKDIR}/git"
+
+inherit setuptools3 cmake
+
+DEPENDS = " \
+ zlib \
+ python3-numpy-native \
+ python3-pybind11-native \
+ python3-wheel-native \
+ python3-pybind11 \
+ python3-numpy \
+ swig-native \
+ python3 \
+ gzip-native \
+"
+
+# Set building environment variables
+TENSORFLOW_TARGET="linux"
+TENSORFLOW_TARGET_ARCH:aarch64="aarch64"
+
+OECMAKE_SOURCEPATH = "${S}/tensorflow/lite"
+
+# The -O3 flag enables high-level optimizations for performance
+# and the -DNDEBUG flag disables debugging code, such as assertions
+# to further optimize the build for production use.
+# Hence, activate -O3 optimization and disable debug symbols.
+OECMAKE_C_FLAGS_RELEASE = "-O3 -DNDEBUG"
+OECMAKE_CXX_FLAGS_RELEASE = "-O3 -DNDEBUG"
+
+OECMAKE_C_FLAGS_RELEASE:append:arm = " -march=armv7-a -mfpu=neon"
+OECMAKE_CXX_FLAGS_RELEASE:append:arm = " -march=armv7-a -mfpu=neon"
+
+# 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"
+
+do_generate_toolchain_file:append:arm() {
+ # XNNPACK does not recognize this when CMAKE_SYSTEM_PROCESSOR is
arm.
+ # Instead, you need to change it to armv7.
+ sed -i 's:CMAKE_SYSTEM_PROCESSOR arm:CMAKE_SYSTEM_PROCESSOR
armv7:g' ${WORKDIR}/toolchain.cmake
+}
+
+EXTRA_OECMAKE:append = " \
+ -DFETCHCONTENT_FULLY_DISCONNECTED=OFF \
+ -DTFLITE_ENABLE_RUY=ON \
+ -DPYTHON_TARGET_INCLUDE=${RECIPE_SYSROOT}${includedir}/${PYTHON_DIR} \
+
-DNUMPY_TARGET_INCLUDE=${RECIPE_SYSROOT}${PYTHON_SITEPACKAGES_DIR}/numpy/core/include
\
+
-DPYBIND11_TARGET_INCLUDE=${RECIPE_SYSROOT}${PYTHON_SITEPACKAGES_DIR}/pybind11/include
\
+ -DCMAKE_SYSTEM_NAME=${TENSORFLOW_TARGET} \
+ -DTFLITE_VERSION_MAJOR=${MAJOR} \
+"
+
+EXTRA_OECMAKE:append:aarch64 = " \
+ -DTFLITE_ENABLE_XNNPACK=ON \
+ -DCMAKE_SYSTEM_PROCESSOR=${TENSORFLOW_TARGET_ARCH} \
+"
+
+# XNNPACK is not supported in Linux armv7-a
[https://github.com/tensorflow/tensorflow/issues/64358]
+# Hence, turning it off
+EXTRA_OECMAKE:append:arm = " \
+ -DTFLITE_ENABLE_XNNPACK=OFF \
+"