Message ID | 20250123172509.445473-2-c-shilwant@ti.com |
---|---|
State | Changes Requested |
Delegated to: | Ryan Eatmon |
Headers | show |
Series | Add TFLite Runtime | expand |
On 1/23/25 11:25 AM, Chirag wrote: > From: Chirag Shilwant <c-shilwant@ti.com> > > - 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 <c-shilwant@ti.com> > --- > ...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 <c-shilwant@ti.com> > +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 <c-shilwant@ti.com> > +--- > + 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 <c-shilwant@ti.com> > +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 <c-shilwant@ti.com> > +--- > + 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 <c-shilwant@ti.com> > +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 <c-shilwant@ti.com> > +--- > + 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" > + Is this not automatically set now from the file name version? > +# 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. If ARMv7 is not supported with XNNPACK, are these lines still needed? > + 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 \ > +" > + > +do_configure[network] = "1" > + > +do_configure:prepend() { > + if [ -n "${http_proxy}" ]; then > + export HTTP_PROXY=${http_proxy} > + export http_proxy=${http_proxy} > + fi > + > + if [ -n "${https_proxy}" ]; then > + export HTTPS_PROXY=${https_proxy} > + export https_proxy=${https_proxy} > + fi Are these checks needed? If it is unset then exporting doesn't hurt, could replace all this with: export http_proxy export https_proxy do_configure[network] = "1" > + > + # There is no Fortran compiler in the toolchain, but bitbake sets this variable anyway with unavailable > + # binary & it leads to "CMake Error: Could not find compiler set in environment variable FC:" > + unset FC > +} > + > +do_compile[network] = "1" > + > +do_compile:prepend() { > + # Used to download cmake dependencies when behind a proxy > + if [ -n "${http_proxy}" ]; then > + export HTTP_PROXY=${http_proxy} > + export http_proxy=${http_proxy} > + fi > + > + if [ -n "${https_proxy}" ]; then > + export HTTPS_PROXY=${https_proxy} > + export https_proxy=${https_proxy} > + fi Do you need network during compile? Seems to only be used in configure. Andrew > +} > + > +SETUPTOOLS_SETUP_PATH = "${B}" > + > +do_compile:append() { > + # Build the python wheel (procedure extract form the build_pip_package_with_cmake.sh) > + BUILD_DIR=${B} > + 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 "${B}/tflite_runtime" > + cp -r "${TENSORFLOW_LITE_DIR}/tools/pip_package/debian" \ > + "${TENSORFLOW_LITE_DIR}/tools/pip_package/MANIFEST.in" \ > + "${B}" > + cp -r "${TENSORFLOW_LITE_DIR}/python/interpreter_wrapper" "${B}" > + cp "${TENSORFLOW_LITE_DIR}/tools/pip_package/setup_with_binary.py" "${B}/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" \ > + "${B}/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 "${B}/_pywrap_tensorflow_interpreter_wrapper.so" "tflite_runtime" > + > + setuptools3_do_compile > +} > + > +do_install() { > + # Install tensorflow-lite dynamic library > + install -d ${D}${libdir} > + install -m 0644 ${B}/libtensorflow-lite.so.${MAJOR} ${D}${libdir}/libtensorflow-lite.so.${PV} > + > + ln -sf libtensorflow-lite.so.${PV} ${D}${libdir}/libtensorflow-lite.so.${MAJOR} > + ln -sf libtensorflow-lite.so.${PV} ${D}${libdir}/libtensorflow-lite.so > + > + # armnn expects the the dynamic library of tensorflow lite to be named as "libtensorflowlite.so" > + # Eg - https://github.com/ARM-software/armnn/blob/branches/armnn_24_11/delegate/cmake/Modules/FindTfLite.cmake#L19 > + # Hence, create a symbolic link to handle the same > + ln -snf libtensorflow-lite.so ${D}${libdir}/libtensorflowlite.so > + > + # Install benchmark_model > + install -d ${D}/opt/${PN}/tools/ > + install -m 0755 ${B}/tools/benchmark/benchmark_model ${D}/opt/${PN}/tools/ > + # chrpath -r '$ORIGIN' ${D}/opt/${PN}/tools/benchmark_model > + > + # Install header files > + install -d ${D}${includedir}/tensorflow/lite > + cd ${S}/tensorflow/lite > + cp --parents $(find . -name "*.h*" -not -path "*cmake_build/*") ${D}${includedir}/tensorflow/lite > + cd ${B} > + cp --parents $(find . -name "*.h*") ${D}${includedir}/tensorflow/lite > + > + # Install Tflite python3 interpreter > + install -d ${D}${PYTHON_SITEPACKAGES_DIR}/tflite_runtime > + install -d ${D}${PYTHON_SITEPACKAGES_DIR}/tflite_runtime.egg-info > + install -m 0755 ${B}/tflite_runtime/* ${D}${PYTHON_SITEPACKAGES_DIR}/tflite_runtime > + install -m 0755 ${B}/tflite_runtime.egg-info/* ${D}${PYTHON_SITEPACKAGES_DIR}/tflite_runtime.egg-info > + # chrpath -r '$ORIGIN' ${D}${PYTHON_SITEPACKAGES_DIR}/tflite_runtime/*.so > +} > + > +PACKAGES += "${PN}-tools python3-${PN}" > + > +RDEPENDS:${PN} += " \ > + ${PN}-tools \ > + python3-${PN} \ > +" > + > +FILES:${PN} = " \ > + ${libdir}/lib*.so* \ > +" > + > +FILES:${PN}-tools = " \ > + /opt/* \ > +" > + > +FILES:python3-${PN} = " \ > + ${PYTHON_SITEPACKAGES_DIR}/tflite_runtime \ > + ${PYTHON_SITEPACKAGES_DIR}/tflite_runtime.egg-info \ > +" > + > +RDEPENDS:python3-${PN} += " python3-ctypes python3-numpy " > + > +PROVIDES += "python3-${PN}"
> >+do_configure[network] = "1" > >+ > >+do_configure:prepend() { > >+ if [ -n "${http_proxy}" ]; then > >+ export HTTP_PROXY=${http_proxy} > >+ export http_proxy=${http_proxy} > >+ fi > >+ > >+ if [ -n "${https_proxy}" ]; then > >+ export HTTPS_PROXY=${https_proxy} > >+ export https_proxy=${https_proxy} > >+ fi > > > Are these checks needed? If it is unset then exporting doesn't hurt, > could replace all this with: > > export http_proxy > export https_proxy > do_configure[network] = "1" > > >+do_compile[network] = "1" > >+ > >+do_compile:prepend() { > >+ # Used to download cmake dependencies when behind a proxy > >+ if [ -n "${http_proxy}" ]; then > >+ export HTTP_PROXY=${http_proxy} > >+ export http_proxy=${http_proxy} > >+ fi > >+ > >+ if [ -n "${https_proxy}" ]; then > >+ export HTTPS_PROXY=${https_proxy} > >+ export https_proxy=${https_proxy} > >+ fi > > Do you need network during compile? Seems to only be used in configure. Both of the above will get you in trouble later on - these are considered a very bad antisocial behavior and an almost sure way to strip off of any Yocto Project Compatible status... I'd suggest spending some time trying to find a way to do any and all downloads inside the do_fetch() task, which is the only one allowed to have network access. In other words - do_configure() and do_compile() are definitely not the right places to do any network fetching...
Hi Andrew, On 24/01/25 03:44, Andrew Davis wrote: > On 1/23/25 11:25 AM, Chirag wrote: >> From: Chirag Shilwant <c-shilwant@ti.com> >> >> - 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 <c-shilwant@ti.com> >> --- >> ...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 <c-shilwant@ti.com> >> +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 <c-shilwant@ti.com> >> +--- >> + 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 <c-shilwant@ti.com> >> +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 <c-shilwant@ti.com> >> +--- >> + 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 <c-shilwant@ti.com> >> +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 <c-shilwant@ti.com> >> +--- >> + 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" >> + > > Is this not automatically set now from the file name version? Ahh, yes! Will rename the recipe name to 2.16.2 in my v2 patch > > >> +# 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. > > If ARMv7 is not supported with XNNPACK, are these lines still needed? Thanks for catching, will drop the irrelevant XNNPACK comment But yeah, the logic of setting CMAKE_SYSTEM_PROCESSOR to armv7 is still needed though! > > >> + 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 \ >> +" >> + >> +do_configure[network] = "1" >> + >> +do_configure:prepend() { >> + if [ -n "${http_proxy}" ]; then >> + export HTTP_PROXY=${http_proxy} >> + export http_proxy=${http_proxy} >> + fi >> + >> + if [ -n "${https_proxy}" ]; then >> + export HTTPS_PROXY=${https_proxy} >> + export https_proxy=${https_proxy} >> + fi > > > Are these checks needed? Yeah, I was just being more cautious. Will drop the "if checks" in v2 > If it is unset then exporting doesn't hurt, > could replace all this with: > > export http_proxy > export https_proxy > do_configure[network] = "1" > >> + >> + # There is no Fortran compiler in the toolchain, but bitbake >> sets this variable anyway with unavailable >> + # binary & it leads to "CMake Error: Could not find compiler set >> in environment variable FC:" >> + unset FC >> +} >> + >> +do_compile[network] = "1" >> + >> +do_compile:prepend() { >> + # Used to download cmake dependencies when behind a proxy >> + if [ -n "${http_proxy}" ]; then >> + export HTTP_PROXY=${http_proxy} >> + export http_proxy=${http_proxy} >> + fi >> + >> + if [ -n "${https_proxy}" ]; then >> + export HTTPS_PROXY=${https_proxy} >> + export https_proxy=${https_proxy} >> + fi > > Do you need network during compile? Seems to only be used in configure. yeah, thanks for catching! apparently it's not needed. So, it was needed earlier when I was trying to build the python wheel package directly using build_pip_package_with_cmake.sh provided by tensorflow But later I decided to revamp the logic & switched to setuptools3 after which we don't neednetwork access in do_compile & even the proxy setting stuff! So, it's only the do_configure stage where we need network access for tensorflow-lite Will handle this in v2 patch. -- Chirag > > > Andrew > >> +} >> + >> +SETUPTOOLS_SETUP_PATH = "${B}" >> + >> +do_compile:append() { >> + # Build the python wheel (procedure extract form the >> build_pip_package_with_cmake.sh) >> + BUILD_DIR=${B} >> + 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 "${B}/tflite_runtime" >> + cp -r "${TENSORFLOW_LITE_DIR}/tools/pip_package/debian" \ >> + "${TENSORFLOW_LITE_DIR}/tools/pip_package/MANIFEST.in" \ >> + "${B}" >> + cp -r "${TENSORFLOW_LITE_DIR}/python/interpreter_wrapper" "${B}" >> + cp >> "${TENSORFLOW_LITE_DIR}/tools/pip_package/setup_with_binary.py" >> "${B}/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" \ >> + "${B}/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 "${B}/_pywrap_tensorflow_interpreter_wrapper.so" >> "tflite_runtime" >> + >> + setuptools3_do_compile >> +} >> + >> +do_install() { >> + # Install tensorflow-lite dynamic library >> + install -d ${D}${libdir} >> + install -m 0644 ${B}/libtensorflow-lite.so.${MAJOR} >> ${D}${libdir}/libtensorflow-lite.so.${PV} >> + >> + ln -sf libtensorflow-lite.so.${PV} >> ${D}${libdir}/libtensorflow-lite.so.${MAJOR} >> + ln -sf libtensorflow-lite.so.${PV} >> ${D}${libdir}/libtensorflow-lite.so >> + >> + # armnn expects the the dynamic library of tensorflow lite to be >> named as "libtensorflowlite.so" >> + # Eg - >> https://github.com/ARM-software/armnn/blob/branches/armnn_24_11/delegate/cmake/Modules/FindTfLite.cmake#L19 >> + # Hence, create a symbolic link to handle the same >> + ln -snf libtensorflow-lite.so ${D}${libdir}/libtensorflowlite.so >> + >> + # Install benchmark_model >> + install -d ${D}/opt/${PN}/tools/ >> + install -m 0755 ${B}/tools/benchmark/benchmark_model >> ${D}/opt/${PN}/tools/ >> + # chrpath -r '$ORIGIN' ${D}/opt/${PN}/tools/benchmark_model >> + >> + # Install header files >> + install -d ${D}${includedir}/tensorflow/lite >> + cd ${S}/tensorflow/lite >> + cp --parents $(find . -name "*.h*" -not -path "*cmake_build/*") >> ${D}${includedir}/tensorflow/lite >> + cd ${B} >> + cp --parents $(find . -name "*.h*") >> ${D}${includedir}/tensorflow/lite >> + >> + # Install Tflite python3 interpreter >> + install -d ${D}${PYTHON_SITEPACKAGES_DIR}/tflite_runtime >> + install -d ${D}${PYTHON_SITEPACKAGES_DIR}/tflite_runtime.egg-info >> + install -m 0755 ${B}/tflite_runtime/* >> ${D}${PYTHON_SITEPACKAGES_DIR}/tflite_runtime >> + install -m 0755 ${B}/tflite_runtime.egg-info/* >> ${D}${PYTHON_SITEPACKAGES_DIR}/tflite_runtime.egg-info >> + # chrpath -r '$ORIGIN' >> ${D}${PYTHON_SITEPACKAGES_DIR}/tflite_runtime/*.so >> +} >> + >> +PACKAGES += "${PN}-tools python3-${PN}" >> + >> +RDEPENDS:${PN} += " \ >> + ${PN}-tools \ >> + python3-${PN} \ >> +" >> + >> +FILES:${PN} = " \ >> + ${libdir}/lib*.so* \ >> +" >> + >> +FILES:${PN}-tools = " \ >> + /opt/* \ >> +" >> + >> +FILES:python3-${PN} = " \ >> + ${PYTHON_SITEPACKAGES_DIR}/tflite_runtime \ >> + ${PYTHON_SITEPACKAGES_DIR}/tflite_runtime.egg-info \ >> +" >> + >> +RDEPENDS:python3-${PN} += " python3-ctypes python3-numpy " >> + >> +PROVIDES += "python3-${PN}"
Hi Denys, On 24/01/25 04:05, Denys Dmytriyenko wrote: > > >+do_configure[network] = "1" > >+ > >+do_configure: prepend() { > > >+ if [ -n "${http_proxy}" ]; then > >+ export > HTTP_PROXY=${http_proxy} > >+ export http_proxy=${http_proxy} > >+ fi > > >+ > > ZjQcmQRYFpfptBannerStart > This message was sent from outside of Texas Instruments. > Do not click links or open attachments unless you recognize the source > of this email and know the content is safe. > Report Suspicious > <https://us-phishalarm-ewt.proofpoint.com/EWT/v1/G3vK!uPdqXRfP1m07amYkfLMjnW_0WPoGAUc_xiEhDJ8PA6NpT0xA8jTf-KB9808zSr3fgbwdqDV_S4_t$> > > ZjQcmQRYFpfptBannerEnd > > >+do_configure[network] = "1" > > >+ > > >+do_configure:prepend() { > > >+ if [ -n "${http_proxy}" ]; then > > >+ export HTTP_PROXY=${http_proxy} > > >+ export http_proxy=${http_proxy} > > >+ fi > > >+ > > >+ if [ -n "${https_proxy}" ]; then > > >+ export HTTPS_PROXY=${https_proxy} > > >+ export https_proxy=${https_proxy} > > >+ fi > > > > > > Are these checks needed? If it is unset then exporting doesn't hurt, > > could replace all this with: > > > > export http_proxy > > export https_proxy > > do_configure[network] = "1" > > > > >+do_compile[network] = "1" > > >+ > > >+do_compile:prepend() { > > >+ # Used to download cmake dependencies when behind a proxy > > >+ if [ -n "${http_proxy}" ]; then > > >+ export HTTP_PROXY=${http_proxy} > > >+ export http_proxy=${http_proxy} > > >+ fi > > >+ > > >+ if [ -n "${https_proxy}" ]; then > > >+ export HTTPS_PROXY=${https_proxy} > > >+ export https_proxy=${https_proxy} > > >+ fi > > > > Do you need network during compile? Seems to only be used in configure. > > Both of the above will get you in trouble later on - these are considered a > very bad antisocial behavior and an almost sure way to strip off of any Yocto > Project Compatible status... I completely understand your concerns about following best practices in Yocto. I was aware that the Yocto documentation now recommends limiting network access to the do_fetch task. However, I'd like to point out that many official Yocto Project layers still enable network access after do_fetch. For example, in meta-openembedded, there are several recipes that enable network access during do_configure and do_compile. Following are few references, - meta-oe/recipes-support/crucible [1] - meta-oe/recipes-dbs/influxdb [2] - meta-oe/recipes-test/syzkaller [3] - meta-arago-extras/recipes-devtools/websocketd [4] These are few examples which I founded just my doing a grep on layers used in TI SDK but I'm sure there would be more such recipes in other layers which are under Yocto Project banner & still enabling network after do_fetch. It's interesting to note that the Yocto Project documentation itself provides example of how to enable network access outside of do_fetch [5]. This highlights the complexity of building certain packages, especially those with dynamic dependencies. Projects like Golang and TensorFlow have more traction towards x86-based systems, making it challenging to revamp their build workflows. As a result, many Yocto layers, including meta-imx-ml [6], meta-st-x-linux-ai [7], and even meta-tensorflow (the official Yocto Project layer for TensorFlow), builds TFLite by enabling network access during do_configure and do_compile [8] Furthermore, the TensorFlow CMake build system is not intelligent enough to detect the presence of existing dependencies. This makes it difficult to cleanly build TensorFlow Lite without network connectivity. I'd like to point out that meta-webosose:recipes-upstreamable which attempts to build TFLite without network connectivity [9], but it ends up with a recipe that uses dirty hacks to delete CMake files for certain delegates. This approach makes the recipe non-scalable and difficult to migrate to newer versions (I believe that's one of the reason they are still on TFLite v2.9 for past 2 years!) Similarly, Golang-based projects face similar challenges. That's why we're enabling network access at do_compile for websocketd in meta-arago [4] Btw, I'd like to mention that I've already addressed the do_compile network access issue by switching to setuptools3 [10]. Nevertheless, I still require network access at the do_configure stage to complete the build process. I hope this provides more context to the issue. Ideally, if we want to fix this problem, Yocto Project should educate projects like Golang, Tensorflow, etc. about the traction of these projects in non x86 based systems where majority of people end up using Yocto project which doesn't like fetching dependencies at runtime. Post which several folks can collaborate & ensure to add a build mechanism which is Yocto Project friendly! [1]: https://git.openembedded.org/meta-openembedded/plain/meta-oe/recipes-support/crucible/crucible_2023.11.02.bb?h=scarthgap [2]: https://git.openembedded.org/meta-openembedded/plain/meta-oe/recipes-dbs/influxdb/influxdb_1.8.10.bb?h=scarthgap [3]: https://git.openembedded.org/meta-openembedded/plain/meta-oe/recipes-test/syzkaller/syzkaller_git.bb?h=scarthgap [4]: https://git.ti.com/cgit/arago-project/meta-arago/commit/meta-arago-extras/recipes-devtools/websocketd/websocketd_0.4.1.bb?h=scarthgap&id=29ef988fae74cd26c418d0e728f757b3c26f23da [5]: https://docs.yoctoproject.org/5.0.6/migration-guides/migration-4.0.html#fetching-changes [6]: https://github.com/nxp-imx/meta-imx/blob/scarthgap-6.6.36-2.1.0/meta-imx-ml/recipes-libraries/tensorflow-lite/tensorflow-lite_2.16.2.bb#L46 [7]: https://github.com/STMicroelectronics/meta-st-x-linux-ai/blob/scarthgap/recipes-frameworks/tensorflow-lite/tensorflow-lite_git.bb#L75 [8]: https://git.yoctoproject.org/meta-tensorflow/tree/recipes-framework/tensorflow/tensorflow.inc#n64 [9]: https://github.com/webosose/meta-webosose/blob/master/meta-webos/recipes-upstreamable/tensorflow-lite/tensorflow-lite_2.9.3.inc#L140 [10]: https://lists.yoctoproject.org/g/meta-arago/message/15754 --- Chirag > > I'd suggest spending some time trying to find a way to do any and all > downloads inside the do_fetch() task, which is the only one allowed to have > network access. > > In other words - do_configure() and do_compile() are definitely not the right > places to do any network fetching... > > -- > Denys
On 1/23/25 11:25 AM, Chirag wrote: > From: Chirag Shilwant <c-shilwant@ti.com> > > - 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 <c-shilwant@ti.com> > --- > ...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 <c-shilwant@ti.com> > +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 <c-shilwant@ti.com> > +--- > + 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 <c-shilwant@ti.com> > +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 <c-shilwant@ti.com> > +--- > + 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 <c-shilwant@ti.com> > +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 <c-shilwant@ti.com> > +--- > + 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 \ > +" Should this be a config option? PACKAGECONFIG[xnnpack] = "-DTFLITE_ENABLE_XNNPACK=ON, -DTFLITE_ENABLE_XNNPACK=OFF" Then we could simply disable it for arm with PACKAGECONFIG:remove:arm = "xnnpack" > + > +do_configure[network] = "1" > + > +do_configure:prepend() { > + if [ -n "${http_proxy}" ]; then > + export HTTP_PROXY=${http_proxy} > + export http_proxy=${http_proxy} > + fi > + > + if [ -n "${https_proxy}" ]; then > + export HTTPS_PROXY=${https_proxy} > + export https_proxy=${https_proxy} > + fi > + > + # There is no Fortran compiler in the toolchain, but bitbake sets this variable anyway with unavailable > + # binary & it leads to "CMake Error: Could not find compiler set in environment variable FC:" > + unset FC > +} > + > +do_compile[network] = "1" > + > +do_compile:prepend() { > + # Used to download cmake dependencies when behind a proxy > + if [ -n "${http_proxy}" ]; then > + export HTTP_PROXY=${http_proxy} > + export http_proxy=${http_proxy} > + fi > + > + if [ -n "${https_proxy}" ]; then > + export HTTPS_PROXY=${https_proxy} > + export https_proxy=${https_proxy} > + fi > +} > + > +SETUPTOOLS_SETUP_PATH = "${B}" > + > +do_compile:append() { > + # Build the python wheel (procedure extract form the build_pip_package_with_cmake.sh) > + BUILD_DIR=${B} > + 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 "${B}/tflite_runtime" > + cp -r "${TENSORFLOW_LITE_DIR}/tools/pip_package/debian" \ > + "${TENSORFLOW_LITE_DIR}/tools/pip_package/MANIFEST.in" \ > + "${B}" > + cp -r "${TENSORFLOW_LITE_DIR}/python/interpreter_wrapper" "${B}" > + cp "${TENSORFLOW_LITE_DIR}/tools/pip_package/setup_with_binary.py" "${B}/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" \ > + "${B}/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 "${B}/_pywrap_tensorflow_interpreter_wrapper.so" "tflite_runtime" > + > + setuptools3_do_compile > +} > + > +do_install() { > + # Install tensorflow-lite dynamic library > + install -d ${D}${libdir} > + install -m 0644 ${B}/libtensorflow-lite.so.${MAJOR} ${D}${libdir}/libtensorflow-lite.so.${PV} > + > + ln -sf libtensorflow-lite.so.${PV} ${D}${libdir}/libtensorflow-lite.so.${MAJOR} > + ln -sf libtensorflow-lite.so.${PV} ${D}${libdir}/libtensorflow-lite.so > + > + # armnn expects the the dynamic library of tensorflow lite to be named as "libtensorflowlite.so" > + # Eg - https://github.com/ARM-software/armnn/blob/branches/armnn_24_11/delegate/cmake/Modules/FindTfLite.cmake#L19 > + # Hence, create a symbolic link to handle the same > + ln -snf libtensorflow-lite.so ${D}${libdir}/libtensorflowlite.so > + > + # Install benchmark_model > + install -d ${D}/opt/${PN}/tools/ > + install -m 0755 ${B}/tools/benchmark/benchmark_model ${D}/opt/${PN}/tools/ > + # chrpath -r '$ORIGIN' ${D}/opt/${PN}/tools/benchmark_model > + > + # Install header files > + install -d ${D}${includedir}/tensorflow/lite > + cd ${S}/tensorflow/lite > + cp --parents $(find . -name "*.h*" -not -path "*cmake_build/*") ${D}${includedir}/tensorflow/lite > + cd ${B} > + cp --parents $(find . -name "*.h*") ${D}${includedir}/tensorflow/lite > + > + # Install Tflite python3 interpreter > + install -d ${D}${PYTHON_SITEPACKAGES_DIR}/tflite_runtime > + install -d ${D}${PYTHON_SITEPACKAGES_DIR}/tflite_runtime.egg-info > + install -m 0755 ${B}/tflite_runtime/* ${D}${PYTHON_SITEPACKAGES_DIR}/tflite_runtime > + install -m 0755 ${B}/tflite_runtime.egg-info/* ${D}${PYTHON_SITEPACKAGES_DIR}/tflite_runtime.egg-info > + # chrpath -r '$ORIGIN' ${D}${PYTHON_SITEPACKAGES_DIR}/tflite_runtime/*.so > +} I'm not seeing any pkg-config nor cmake file deployed to allow other projects to find this package. I see some folks manually added a .pc file, might be an option here. Andrew > + > +PACKAGES += "${PN}-tools python3-${PN}" > + > +RDEPENDS:${PN} += " \ > + ${PN}-tools \ > + python3-${PN} \ > +" > + > +FILES:${PN} = " \ > + ${libdir}/lib*.so* \ > +" > + > +FILES:${PN}-tools = " \ > + /opt/* \ > +" > + > +FILES:python3-${PN} = " \ > + ${PYTHON_SITEPACKAGES_DIR}/tflite_runtime \ > + ${PYTHON_SITEPACKAGES_DIR}/tflite_runtime.egg-info \ > +" > + > +RDEPENDS:python3-${PN} += " python3-ctypes python3-numpy " > + > +PROVIDES += "python3-${PN}"
Hi Andrew, On 25/01/25 02:49, Andrew Davis wrote: > On 1/23/25 11:25 AM, Chirag wrote: >> From: Chirag Shilwant <c-shilwant@ti.com> >> >> - 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 <c-shilwant@ti.com> >> --- >> ...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 <c-shilwant@ti.com> >> +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 <c-shilwant@ti.com> >> +--- >> + 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 <c-shilwant@ti.com> >> +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 <c-shilwant@ti.com> >> +--- >> + 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 <c-shilwant@ti.com> >> +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 <c-shilwant@ti.com> >> +--- >> + 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 \ >> +" > > Should this be a config option? Yeah, we can go via PACKAGECONFIG route as well. Will handle that in v2 > > > PACKAGECONFIG[xnnpack] = "-DTFLITE_ENABLE_XNNPACK=ON, > -DTFLITE_ENABLE_XNNPACK=OFF" > > Then we could simply disable it for arm with > > PACKAGECONFIG:remove:arm = "xnnpack" > >> + >> +do_configure[network] = "1" >> + >> +do_configure:prepend() { >> + if [ -n "${http_proxy}" ]; then >> + export HTTP_PROXY=${http_proxy} >> + export http_proxy=${http_proxy} >> + fi >> + >> + if [ -n "${https_proxy}" ]; then >> + export HTTPS_PROXY=${https_proxy} >> + export https_proxy=${https_proxy} >> + fi >> + >> + # There is no Fortran compiler in the toolchain, but bitbake >> sets this variable anyway with unavailable >> + # binary & it leads to "CMake Error: Could not find compiler set >> in environment variable FC:" >> + unset FC >> +} >> + >> +do_compile[network] = "1" >> + >> +do_compile:prepend() { >> + # Used to download cmake dependencies when behind a proxy >> + if [ -n "${http_proxy}" ]; then >> + export HTTP_PROXY=${http_proxy} >> + export http_proxy=${http_proxy} >> + fi >> + >> + if [ -n "${https_proxy}" ]; then >> + export HTTPS_PROXY=${https_proxy} >> + export https_proxy=${https_proxy} >> + fi >> +} >> + >> +SETUPTOOLS_SETUP_PATH = "${B}" >> + >> +do_compile:append() { >> + # Build the python wheel (procedure extract form the >> build_pip_package_with_cmake.sh) >> + BUILD_DIR=${B} >> + 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 "${B}/tflite_runtime" >> + cp -r "${TENSORFLOW_LITE_DIR}/tools/pip_package/debian" \ >> + "${TENSORFLOW_LITE_DIR}/tools/pip_package/MANIFEST.in" \ >> + "${B}" >> + cp -r "${TENSORFLOW_LITE_DIR}/python/interpreter_wrapper" "${B}" >> + cp >> "${TENSORFLOW_LITE_DIR}/tools/pip_package/setup_with_binary.py" >> "${B}/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" \ >> + "${B}/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 "${B}/_pywrap_tensorflow_interpreter_wrapper.so" >> "tflite_runtime" >> + >> + setuptools3_do_compile >> +} >> + >> +do_install() { >> + # Install tensorflow-lite dynamic library >> + install -d ${D}${libdir} >> + install -m 0644 ${B}/libtensorflow-lite.so.${MAJOR} >> ${D}${libdir}/libtensorflow-lite.so.${PV} >> + >> + ln -sf libtensorflow-lite.so.${PV} >> ${D}${libdir}/libtensorflow-lite.so.${MAJOR} >> + ln -sf libtensorflow-lite.so.${PV} >> ${D}${libdir}/libtensorflow-lite.so >> + >> + # armnn expects the the dynamic library of tensorflow lite to be >> named as "libtensorflowlite.so" >> + # Eg - >> https://github.com/ARM-software/armnn/blob/branches/armnn_24_11/delegate/cmake/Modules/FindTfLite.cmake#L19 >> + # Hence, create a symbolic link to handle the same >> + ln -snf libtensorflow-lite.so ${D}${libdir}/libtensorflowlite.so >> + >> + # Install benchmark_model >> + install -d ${D}/opt/${PN}/tools/ >> + install -m 0755 ${B}/tools/benchmark/benchmark_model >> ${D}/opt/${PN}/tools/ >> + # chrpath -r '$ORIGIN' ${D}/opt/${PN}/tools/benchmark_model >> + >> + # Install header files >> + install -d ${D}${includedir}/tensorflow/lite >> + cd ${S}/tensorflow/lite >> + cp --parents $(find . -name "*.h*" -not -path "*cmake_build/*") >> ${D}${includedir}/tensorflow/lite >> + cd ${B} >> + cp --parents $(find . -name "*.h*") >> ${D}${includedir}/tensorflow/lite >> + >> + # Install Tflite python3 interpreter >> + install -d ${D}${PYTHON_SITEPACKAGES_DIR}/tflite_runtime >> + install -d ${D}${PYTHON_SITEPACKAGES_DIR}/tflite_runtime.egg-info >> + install -m 0755 ${B}/tflite_runtime/* >> ${D}${PYTHON_SITEPACKAGES_DIR}/tflite_runtime >> + install -m 0755 ${B}/tflite_runtime.egg-info/* >> ${D}${PYTHON_SITEPACKAGES_DIR}/tflite_runtime.egg-info >> + # chrpath -r '$ORIGIN' >> ${D}${PYTHON_SITEPACKAGES_DIR}/tflite_runtime/*.so >> +} > > I'm not seeing any pkg-config nor cmake file deployed to allow other > projects to find this package. I see some folks manually added a .pc > file, might be an option here. yeah, I was thinking to add it post NNstreamer gets integrated in arago (mentioning that NNstreamer needs this package-config file) But if everyone is fine, I can handle it in my v2 as well. Will use the .pc approach for the same -- Chirag > > > Andrew > >> + >> +PACKAGES += "${PN}-tools python3-${PN}" >> + >> +RDEPENDS:${PN} += " \ >> + ${PN}-tools \ >> + python3-${PN} \ >> +" >> + >> +FILES:${PN} = " \ >> + ${libdir}/lib*.so* \ >> +" >> + >> +FILES:${PN}-tools = " \ >> + /opt/* \ >> +" >> + >> +FILES:python3-${PN} = " \ >> + ${PYTHON_SITEPACKAGES_DIR}/tflite_runtime \ >> + ${PYTHON_SITEPACKAGES_DIR}/tflite_runtime.egg-info \ >> +" >> + >> +RDEPENDS:python3-${PN} += " python3-ctypes python3-numpy " >> + >> +PROVIDES += "python3-${PN}"
On Fri, Jan 24, 2025 at 08:01:03PM +0530, Chirag Shilwant wrote: > Hi Denys, > > On 24/01/25 04:05, Denys Dmytriyenko wrote: > >> >+do_configure[network] = "1" > >+ > >+do_configure: prepend() { > >> >+ if [ -n "${http_proxy}" ]; then > >+ export > >HTTP_PROXY=${http_proxy} > >+ export http_proxy=${http_proxy} > >+ > >fi > >+ > > >ZjQcmQRYFpfptBannerStart > >This message was sent from outside of Texas Instruments. > >Do not click links or open attachments unless you recognize the > >source of this email and know the content is safe. > >Report Suspicious > ><https://us-phishalarm-ewt.proofpoint.com/EWT/v1/G3vK!uPdqXRfP1m07amYkfLMjnW_0WPoGAUc_xiEhDJ8PA6NpT0xA8jTf-KB9808zSr3fgbwdqDV_S4_t$> > > > >ZjQcmQRYFpfptBannerEnd > >> >+do_configure[network] = "1" > >> >+ > >> >+do_configure:prepend() { > >> >+ if [ -n "${http_proxy}" ]; then > >> >+ export HTTP_PROXY=${http_proxy} > >> >+ export http_proxy=${http_proxy} > >> >+ fi > >> >+ > >> >+ if [ -n "${https_proxy}" ]; then > >> >+ export HTTPS_PROXY=${https_proxy} > >> >+ export https_proxy=${https_proxy} > >> >+ fi > >> > > Are these checks needed? If it is unset then exporting > >doesn't hurt, > >> could replace all this with: > >> > export http_proxy > >> export https_proxy > >> do_configure[network] = "1" > >> > >+do_compile[network] = "1" > >> >+ > >> >+do_compile:prepend() { > >> >+ # Used to download cmake dependencies when behind a proxy > >> >+ if [ -n "${http_proxy}" ]; then > >> >+ export HTTP_PROXY=${http_proxy} > >> >+ export http_proxy=${http_proxy} > >> >+ fi > >> >+ > >> >+ if [ -n "${https_proxy}" ]; then > >> >+ export HTTPS_PROXY=${https_proxy} > >> >+ export https_proxy=${https_proxy} > >> >+ fi > >> > Do you need network during compile? Seems to only be used in > >configure. > > > >Both of the above will get you in trouble later on - these are considered a > >very bad antisocial behavior and an almost sure way to strip off of any Yocto > >Project Compatible status... > > I completely understand your concerns about following best practices > in Yocto. > I was aware that the Yocto documentation now recommends limiting > network access > to the do_fetch task. However, I'd like to point out that many > official Yocto Project > layers still enable network access after do_fetch. You are missing my point... "Yocto Project Compatible" is not merely saying a layer works with the Yocto Project. It is a compliance and badging program that tests layers against a set of defined criterias, recognizing those that pass as "Yocto Project Compatible". For example, meta-ti layers are Yocto Project Compatible since very early days and we kept it that way - it's being checked nightly on the YP autobuilder. On the other hand, meta-arago layers never had Yocto Project Compatible designation. Moreover, except meta-oe, none of the other layers you linked to are Yocto Project Compatible! The "YP Compatible" program was "on hiatus" for quite some time, but is being revamped now to re-launch some time in the near future - the Yocto Project Technical Steering Committee has worked hard on the changes and I've been closely involved - check the Technical Leadership tab here: https://www.yoctoproject.org/about/leadership/ A wider range and more stricter criterias coming with this revamp are a direct result of misbehaving layers and all the pain they cause to the community. For example, most of the QA checks are becoming mandatory: https://git.openembedded.org/openembedded-core/commit/?id=ce2e42ace2d15fb6745437cf0a7f07d28398ca12 We'll be catching layers that try to skip those QA checks with INSANE_SKIP: https://git.openembedded.org/openembedded-core/commit/?id=9c3ba88628853b20fb4c98c99cf3fe8349024016 And catching layers that use network outside of do_fetch() is in the works: https://git.yoctoproject.org/poky-contrib/tree/meta/classes-global/yocto-check-layer.bbclass?h=ross/checknetwork All the corresponding documentation will be updated in due time... You can find a rather short list of the past Yocto Project Compatible layers that were recognzied and designated under the old program (new applications are currently closed until the revamped program is out): https://www.yoctoproject.org/development/yocto-project-compatible-layers/ For comparison, here's a much longer (but still not exhaustive) list of registered YP layers - note how few of them have a little "YP Compatible" badge next to their names: https://layers.openembedded.org/layerindex/branch/master/layers/ And last week I also talked here on this list about efforts led by Ryan to improve meta-arago layers quality to potentially seek YP Compatible status some time in the future: https://lists.yoctoproject.org/g/meta-arago/message/15738 That's why in my reply to you I pointed out problematic areas and suggested looking for better alternatives early on, before those become bigger issues: > >I'd suggest spending some time trying to find a way to do any and all > >downloads inside the do_fetch() task, which is the only one allowed to have > >network access. > > > >In other words - do_configure() and do_compile() are definitely not the right > >places to do any network fetching... But you are free to dismiss my recommendations...
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 <c-shilwant@ti.com> +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 <c-shilwant@ti.com> +--- + 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 <c-shilwant@ti.com> +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 <c-shilwant@ti.com> +--- + 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 <c-shilwant@ti.com> +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 <c-shilwant@ti.com> +--- + 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 \ +" + +do_configure[network] = "1" + +do_configure:prepend() { + if [ -n "${http_proxy}" ]; then + export HTTP_PROXY=${http_proxy} + export http_proxy=${http_proxy} + fi + + if [ -n "${https_proxy}" ]; then + export HTTPS_PROXY=${https_proxy} + export https_proxy=${https_proxy} + fi + + # There is no Fortran compiler in the toolchain, but bitbake sets this variable anyway with unavailable + # binary & it leads to "CMake Error: Could not find compiler set in environment variable FC:" + unset FC +} + +do_compile[network] = "1" + +do_compile:prepend() { + # Used to download cmake dependencies when behind a proxy + if [ -n "${http_proxy}" ]; then + export HTTP_PROXY=${http_proxy} + export http_proxy=${http_proxy} + fi + + if [ -n "${https_proxy}" ]; then + export HTTPS_PROXY=${https_proxy} + export https_proxy=${https_proxy} + fi +} + +SETUPTOOLS_SETUP_PATH = "${B}" + +do_compile:append() { + # Build the python wheel (procedure extract form the build_pip_package_with_cmake.sh) + BUILD_DIR=${B} + 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 "${B}/tflite_runtime" + cp -r "${TENSORFLOW_LITE_DIR}/tools/pip_package/debian" \ + "${TENSORFLOW_LITE_DIR}/tools/pip_package/MANIFEST.in" \ + "${B}" + cp -r "${TENSORFLOW_LITE_DIR}/python/interpreter_wrapper" "${B}" + cp "${TENSORFLOW_LITE_DIR}/tools/pip_package/setup_with_binary.py" "${B}/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" \ + "${B}/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 "${B}/_pywrap_tensorflow_interpreter_wrapper.so" "tflite_runtime" + + setuptools3_do_compile +} + +do_install() { + # Install tensorflow-lite dynamic library + install -d ${D}${libdir} + install -m 0644 ${B}/libtensorflow-lite.so.${MAJOR} ${D}${libdir}/libtensorflow-lite.so.${PV} + + ln -sf libtensorflow-lite.so.${PV} ${D}${libdir}/libtensorflow-lite.so.${MAJOR} + ln -sf libtensorflow-lite.so.${PV} ${D}${libdir}/libtensorflow-lite.so + + # armnn expects the the dynamic library of tensorflow lite to be named as "libtensorflowlite.so" + # Eg - https://github.com/ARM-software/armnn/blob/branches/armnn_24_11/delegate/cmake/Modules/FindTfLite.cmake#L19 + # Hence, create a symbolic link to handle the same + ln -snf libtensorflow-lite.so ${D}${libdir}/libtensorflowlite.so + + # Install benchmark_model + install -d ${D}/opt/${PN}/tools/ + install -m 0755 ${B}/tools/benchmark/benchmark_model ${D}/opt/${PN}/tools/ + # chrpath -r '$ORIGIN' ${D}/opt/${PN}/tools/benchmark_model + + # Install header files + install -d ${D}${includedir}/tensorflow/lite + cd ${S}/tensorflow/lite + cp --parents $(find . -name "*.h*" -not -path "*cmake_build/*") ${D}${includedir}/tensorflow/lite + cd ${B} + cp --parents $(find . -name "*.h*") ${D}${includedir}/tensorflow/lite + + # Install Tflite python3 interpreter + install -d ${D}${PYTHON_SITEPACKAGES_DIR}/tflite_runtime + install -d ${D}${PYTHON_SITEPACKAGES_DIR}/tflite_runtime.egg-info + install -m 0755 ${B}/tflite_runtime/* ${D}${PYTHON_SITEPACKAGES_DIR}/tflite_runtime + install -m 0755 ${B}/tflite_runtime.egg-info/* ${D}${PYTHON_SITEPACKAGES_DIR}/tflite_runtime.egg-info + # chrpath -r '$ORIGIN' ${D}${PYTHON_SITEPACKAGES_DIR}/tflite_runtime/*.so +} + +PACKAGES += "${PN}-tools python3-${PN}" + +RDEPENDS:${PN} += " \ + ${PN}-tools \ + python3-${PN} \ +" + +FILES:${PN} = " \ + ${libdir}/lib*.so* \ +" + +FILES:${PN}-tools = " \ + /opt/* \ +" + +FILES:python3-${PN} = " \ + ${PYTHON_SITEPACKAGES_DIR}/tflite_runtime \ + ${PYTHON_SITEPACKAGES_DIR}/tflite_runtime.egg-info \ +" + +RDEPENDS:python3-${PN} += " python3-ctypes python3-numpy " + +PROVIDES += "python3-${PN}"