From ba6e8dca04b123991f13a41b4eec86af91b68700 Mon Sep 17 00:00:00 2001 From: Tushar Darote Date: Fri, 6 Feb 2026 12:09:36 +0530 Subject: [PATCH 1/4] flatbuffers: Import recipe from meta-openembedded rev d302ffa547 Copied flatbuffers.bb from meta-oe to meta-qcom-distro to customize and maintain local modifications needed for tflite v2.20.0 build. Signed-off-by: Tushar Darote --- recipes-support/flatbuffers/flatbuffers.bb | 32 +++++++++++++++++++++ recipes-support/flatbuffers/flatbuffers.inc | 3 ++ 2 files changed, 35 insertions(+) create mode 100644 recipes-support/flatbuffers/flatbuffers.bb create mode 100644 recipes-support/flatbuffers/flatbuffers.inc diff --git a/recipes-support/flatbuffers/flatbuffers.bb b/recipes-support/flatbuffers/flatbuffers.bb new file mode 100644 index 00000000..c51a49ba --- /dev/null +++ b/recipes-support/flatbuffers/flatbuffers.bb @@ -0,0 +1,32 @@ +SUMMARY = "Memory Efficient Serialization Library" +HOMEPAGE = "https://github.com/google/flatbuffers" +SECTION = "console/tools" +LICENSE = "Apache-2.0" +LIC_FILES_CHKSUM = "file://LICENSE;md5=3b83ef96387f14655fc854ddc3c6bd57" + +require flatbuffers.inc + +PACKAGE_BEFORE_PN = "${PN}-compiler" + +DEPENDS = "flatbuffers-native" + +RDEPENDS:${PN}-compiler = "${PN}" +RDEPENDS:${PN}-dev += "${PN}-compiler" + + +EXTRA_OECMAKE += " \ + -DFLATBUFFERS_BUILD_TESTS=OFF \ + -DFLATBUFFERS_BUILD_SHAREDLIB=ON \ +" +EXTRA_OECMAKE:append:class-target = " -DFLATBUFFERS_FLATC_EXECUTABLE=${STAGING_BINDIR_NATIVE}/flatc" + +inherit cmake python3native + +rm_flatc_cmaketarget_for_target() { + rm -f "${SYSROOT_DESTDIR}/${libdir}/cmake/flatbuffers/FlatcTargets.cmake" +} +SYSROOT_PREPROCESS_FUNCS:class-target += "rm_flatc_cmaketarget_for_target" + +FILES:${PN}-compiler = "${bindir}" + +BBCLASSEXTEND = "native nativesdk" diff --git a/recipes-support/flatbuffers/flatbuffers.inc b/recipes-support/flatbuffers/flatbuffers.inc new file mode 100644 index 00000000..1168369f --- /dev/null +++ b/recipes-support/flatbuffers/flatbuffers.inc @@ -0,0 +1,3 @@ +PV = "25.12.19" +SRCREV = "7e163021e59cca4f8e1e35a7c828b5c6b7915953" +SRC_URI = "git://github.com/google/flatbuffers.git;branch=master;protocol=https;tag=v${PV}" From c1ba1a67de760d534e6cdf841b5c62d0911c741e Mon Sep 17 00:00:00 2001 From: Tushar Darote Date: Fri, 6 Feb 2026 12:22:47 +0530 Subject: [PATCH 2/4] flatbuffers: Downgrade PV and SRCREV to 24.3.25 for TFLite v2.20.0 compatibility Downgraded flatbuffers from 25.12.19 to 24.3.25 as required by the TensorFlow Lite v2.20.0 build. Updated PV and SRCREV accordingly. Signed-off-by: Tushar Darote --- recipes-support/flatbuffers/flatbuffers.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/recipes-support/flatbuffers/flatbuffers.inc b/recipes-support/flatbuffers/flatbuffers.inc index 1168369f..bc7ab77c 100644 --- a/recipes-support/flatbuffers/flatbuffers.inc +++ b/recipes-support/flatbuffers/flatbuffers.inc @@ -1,3 +1,3 @@ -PV = "25.12.19" -SRCREV = "7e163021e59cca4f8e1e35a7c828b5c6b7915953" +PV = "24.3.25" +SRCREV = "595bf0007ab1929570c7671f091313c8fc20644e" SRC_URI = "git://github.com/google/flatbuffers.git;branch=master;protocol=https;tag=v${PV}" From d32b3b9605147272be31d6aba86b43b113c2f937 Mon Sep 17 00:00:00 2001 From: Tushar Darote Date: Fri, 30 Jan 2026 15:15:45 +0530 Subject: [PATCH 3/4] meta-qcom-distro: Add flatbuffers-tflite recipe for TFLite schema handling Add a dedicated flatbuffers-tflite recipe to address version compatibility issues with TensorFlow Lite 2.20.0.qcom. Problem: When using the flatbuffers version from meta-oe (25.12.19), TensorFlow Lite compilation fails with: static_assert(FLATBUFFERS_VERSION_MAJOR == 24 && FLATBUFFERS_VERSION_MINOR == 3 && FLATBUFFERS_VERSION_REVISION == 25) Error: static assertion failed: Non-compatible flatbuffers version included The comparison reduces to '(25 == 24)' Solution: Create a separate flatbuffers-tflite recipe that builds exactly version 24.3.25 as required by TFLite's schema generation code. This ensures proper schema handling and successful compilation of TensorFlow Lite 2.20.0.qcom. Why meta-oe's flatbuffers isn't sufficient: - TFLite 2.20.0.qcom requires flatbuffers version 24.3.25 exactly - meta-oe provides flatbuffers version 25.12.19 - Version mismatch causes static assertion failure in schema_generated.h - TFLite's schema generation code has strict version requirements Signed-off-by: Tushar Darote --- ...ffers.bb => flatbuffers-tflite_24.3.25.bb} | 25 +++++++++++-------- recipes-support/flatbuffers/flatbuffers.inc | 3 --- 2 files changed, 15 insertions(+), 13 deletions(-) rename recipes-support/flatbuffers/{flatbuffers.bb => flatbuffers-tflite_24.3.25.bb} (53%) delete mode 100644 recipes-support/flatbuffers/flatbuffers.inc diff --git a/recipes-support/flatbuffers/flatbuffers.bb b/recipes-support/flatbuffers/flatbuffers-tflite_24.3.25.bb similarity index 53% rename from recipes-support/flatbuffers/flatbuffers.bb rename to recipes-support/flatbuffers/flatbuffers-tflite_24.3.25.bb index c51a49ba..d0b04a95 100644 --- a/recipes-support/flatbuffers/flatbuffers.bb +++ b/recipes-support/flatbuffers/flatbuffers-tflite_24.3.25.bb @@ -1,30 +1,35 @@ -SUMMARY = "Memory Efficient Serialization Library" +SUMMARY = "Memory Efficient Serialization Library (TFLite Compatible)" +DESCRIPTION = "FlatBuffers is a cross-platform serialization library used for efficient data serialization and deserialization." +# "This recipe provides version 24.3.25 specifically for TensorFlow Lite 2.20.0.qcom compatibility, which requires an exact match of flatbuffers version 24.3.25 due to strict static assertions in its schema files." + HOMEPAGE = "https://github.com/google/flatbuffers" SECTION = "console/tools" LICENSE = "Apache-2.0" LIC_FILES_CHKSUM = "file://LICENSE;md5=3b83ef96387f14655fc854ddc3c6bd57" -require flatbuffers.inc - -PACKAGE_BEFORE_PN = "${PN}-compiler" +PV = "24.3.25" +SRCREV = "595bf0007ab1929570c7671f091313c8fc20644e" +SRC_URI = "git://github.com/google/flatbuffers.git;branch=master;protocol=https;tag=v${PV}" -DEPENDS = "flatbuffers-native" - -RDEPENDS:${PN}-compiler = "${PN}" -RDEPENDS:${PN}-dev += "${PN}-compiler" +DEPENDS = "flatbuffers-tflite-native" +inherit cmake python3native EXTRA_OECMAKE += " \ - -DFLATBUFFERS_BUILD_TESTS=OFF \ + -DFLATBUFFERS_BUILD_TESTS=OFF \ -DFLATBUFFERS_BUILD_SHAREDLIB=ON \ " EXTRA_OECMAKE:append:class-target = " -DFLATBUFFERS_FLATC_EXECUTABLE=${STAGING_BINDIR_NATIVE}/flatc" -inherit cmake python3native +RDEPENDS:${PN}-compiler = "${PN}" +RDEPENDS:${PN}-dev += "${PN}-compiler" + +PACKAGE_BEFORE_PN = "${PN}-compiler" rm_flatc_cmaketarget_for_target() { rm -f "${SYSROOT_DESTDIR}/${libdir}/cmake/flatbuffers/FlatcTargets.cmake" } + SYSROOT_PREPROCESS_FUNCS:class-target += "rm_flatc_cmaketarget_for_target" FILES:${PN}-compiler = "${bindir}" diff --git a/recipes-support/flatbuffers/flatbuffers.inc b/recipes-support/flatbuffers/flatbuffers.inc deleted file mode 100644 index bc7ab77c..00000000 --- a/recipes-support/flatbuffers/flatbuffers.inc +++ /dev/null @@ -1,3 +0,0 @@ -PV = "24.3.25" -SRCREV = "595bf0007ab1929570c7671f091313c8fc20644e" -SRC_URI = "git://github.com/google/flatbuffers.git;branch=master;protocol=https;tag=v${PV}" From 360967f5da6f876c20f90f31cef17b028f1f7e31 Mon Sep 17 00:00:00 2001 From: Tushar Darote Date: Thu, 29 Jan 2026 19:20:59 +0530 Subject: [PATCH 4/4] tflite: Add recipe and comprehensive patches for benchmark, OpenCL, and C API Apply multiple patches to enhance TensorFlow Lite functionality: - Add benchmark_model config option - Fix protobuf dependency in benchmark tools - Add dynamic OpenCL library loading support - Exclude subdirectories from all builds - Force delegate symbols from shared library - Add version support to C API - Fix label_image dependencies - Add install rule for C interface shared library Signed-off-by: Tushar Darote --- ...fig-option-to-enable-benchmark_model.patch | 53 ++++ ...-benchmark-require-protobuf-through-.patch | 31 ++ ...dynamic-OpenCL-library-loading-suppo.patch | 59 ++++ ...clude-subdirectories-from-all-builds.patch | 117 ++++++++ ...delegate-symbols-from-shared-library.patch | 76 +++++ .../0006-c-Add-version-support-to-C-API.patch | 58 ++++ ...7-cmake-Fix-label-image-dependencies.patch | 39 +++ ...l-rule-for-c-interface-shared-librar.patch | 74 +++++ ...log-dependency-for-enhanced-logging-.patch | 29 ++ .../extract_tflite_srcrevs_from_github.py | 276 ++++++++++++++++++ recipes-ml/tflite/tensorflow-lite_2.20.0.bb | 170 +++++++++++ 11 files changed, 982 insertions(+) create mode 100644 recipes-ml/tflite/files/0001-lite-Add-config-option-to-enable-benchmark_model.patch create mode 100644 recipes-ml/tflite/files/0002-cmake-lite-tools-benchmark-require-protobuf-through-.patch create mode 100644 recipes-ml/tflite/files/0003-feat-tflite-Add-dynamic-OpenCL-library-loading-suppo.patch create mode 100644 recipes-ml/tflite/files/0004-cmake-Exclude-subdirectories-from-all-builds.patch create mode 100644 recipes-ml/tflite/files/0005-c-Force-delegate-symbols-from-shared-library.patch create mode 100644 recipes-ml/tflite/files/0006-c-Add-version-support-to-C-API.patch create mode 100644 recipes-ml/tflite/files/0007-cmake-Fix-label-image-dependencies.patch create mode 100644 recipes-ml/tflite/files/0008-cmake-Add-install-rule-for-c-interface-shared-librar.patch create mode 100644 recipes-ml/tflite/files/0009-tflite-Add-absl-log-dependency-for-enhanced-logging-.patch create mode 100644 recipes-ml/tflite/files/extract_tflite_srcrevs_from_github.py create mode 100644 recipes-ml/tflite/tensorflow-lite_2.20.0.bb diff --git a/recipes-ml/tflite/files/0001-lite-Add-config-option-to-enable-benchmark_model.patch b/recipes-ml/tflite/files/0001-lite-Add-config-option-to-enable-benchmark_model.patch new file mode 100644 index 00000000..614b31c8 --- /dev/null +++ b/recipes-ml/tflite/files/0001-lite-Add-config-option-to-enable-benchmark_model.patch @@ -0,0 +1,53 @@ +From 832cc4fb50fd8ba8ddb15c02258d6a58efb72eec Mon Sep 17 00:00:00 2001 +From: James Hilliard +Date: Mon, 18 Sep 2023 10:34:56 -0600 +Subject: [PATCH 1/9] lite: Add config option to enable benchmark_model + +It's handy to have an option to enable the benchmark_model tool +so that it can be built and installed using the all target which +is preferable in some cases when packaging tensorflow-lite. + +Upstream-Status: Backport [c9a1cecffceb96bc1a116c62039cb893f65120d4] +Signed-off-by: James Hilliard +--- + tensorflow/lite/CMakeLists.txt | 1 + + tensorflow/lite/tools/benchmark/CMakeLists.txt | 9 ++++++++- + 2 files changed, 9 insertions(+), 1 deletion(-) + +diff --git a/tensorflow/lite/CMakeLists.txt b/tensorflow/lite/CMakeLists.txt +index 3198ec61e0b..cdd38ff2086 100644 +--- a/tensorflow/lite/CMakeLists.txt ++++ b/tensorflow/lite/CMakeLists.txt +@@ -64,6 +64,7 @@ include(GNUInstallDirs) + include(CMakeDependentOption) + option(TFLITE_ENABLE_INSTALL "Enable install rule" OFF) + option(TFLITE_ENABLE_LABEL_IMAGE "Enable label_image example" OFF) ++option(TFLITE_ENABLE_BENCHMARK_MODEL "Enable the benchmark_model tool" OFF) + option(TFLITE_ENABLE_RUY "Enable experimental RUY integration" OFF) + option(TFLITE_ENABLE_RESOURCE "Enable experimental support for resources" ON) + option(TFLITE_ENABLE_NNAPI "Enable NNAPI (Android only)." ON) +diff --git a/tensorflow/lite/tools/benchmark/CMakeLists.txt b/tensorflow/lite/tools/benchmark/CMakeLists.txt +index 79986f6c0ec..2b639475481 100644 +--- a/tensorflow/lite/tools/benchmark/CMakeLists.txt ++++ b/tensorflow/lite/tools/benchmark/CMakeLists.txt +@@ -95,9 +95,16 @@ if(TFLITE_ENABLE_GPU) + endif() # TFLITE_ENABLE_GPU + + add_executable(benchmark_model +- EXCLUDE_FROM_ALL + ${TFLITE_BENCHMARK_SRCS} + ) ++if(TFLITE_ENABLE_BENCHMARK_MODEL) ++ set_target_properties(benchmark_model PROPERTIES EXCLUDE_FROM_ALL FALSE) ++ if(TFLITE_ENABLE_INSTALL) ++ install(TARGETS benchmark_model) ++ endif() # TFLITE_ENABLE_INSTALL ++else() ++ set_target_properties(benchmark_model PROPERTIES EXCLUDE_FROM_ALL TRUE) ++endif() # TFLITE_ENABLE_BENCHMARK_MODEL + target_compile_options(benchmark_model + PRIVATE + ${TFLITE_BENCHMARK_CC_OPTIONS} +-- +2.34.1 + diff --git a/recipes-ml/tflite/files/0002-cmake-lite-tools-benchmark-require-protobuf-through-.patch b/recipes-ml/tflite/files/0002-cmake-lite-tools-benchmark-require-protobuf-through-.patch new file mode 100644 index 00000000..e79dfbd7 --- /dev/null +++ b/recipes-ml/tflite/files/0002-cmake-lite-tools-benchmark-require-protobuf-through-.patch @@ -0,0 +1,31 @@ +From e4bef15bb049dc38bdb670aab732750b3ce1a69f Mon Sep 17 00:00:00 2001 +From: Koen Kooi +Date: Thu, 9 Oct 2025 18:11:16 +0200 +Subject: [PATCH 2/9] cmake: lite/tools/benchmark: require protobuf through + find-package + +The tools needs headers for building and the library for linking, so +have cmake find the things it needs. + +Upstream-Status: Submitted [https://github.com/tensorflow/tensorflow/pull/109375] +Signed-off-by: Koen Kooi +--- + tensorflow/lite/tools/benchmark/CMakeLists.txt | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/tensorflow/lite/tools/benchmark/CMakeLists.txt b/tensorflow/lite/tools/benchmark/CMakeLists.txt +index 2b639475481..4eb63985922 100644 +--- a/tensorflow/lite/tools/benchmark/CMakeLists.txt ++++ b/tensorflow/lite/tools/benchmark/CMakeLists.txt +@@ -16,6 +16,8 @@ + + # The benchmark tool for Tensorflow Lite. + ++find_package(Protobuf REQUIRED) ++ + populate_source_vars("${TFLITE_SOURCE_DIR}/tools/benchmark" + TFLITE_BENCHMARK_SRCS + FILTER "(_test|_plus_flex_main|_performance_options.*)\\.cc$" +-- +2.34.1 + diff --git a/recipes-ml/tflite/files/0003-feat-tflite-Add-dynamic-OpenCL-library-loading-suppo.patch b/recipes-ml/tflite/files/0003-feat-tflite-Add-dynamic-OpenCL-library-loading-suppo.patch new file mode 100644 index 00000000..28baf69e --- /dev/null +++ b/recipes-ml/tflite/files/0003-feat-tflite-Add-dynamic-OpenCL-library-loading-suppo.patch @@ -0,0 +1,59 @@ +From 89f926065d911296213c39b71820ecc212e77f18 Mon Sep 17 00:00:00 2001 +From: Tushar Darote +Date: Thu, 9 Oct 2025 22:42:17 +0200 +Subject: [PATCH 3/9] feat(tflite): Add dynamic OpenCL library loading support + +Use pkg-config to detect OpenCL installation and set library name based on +OpenCL version. Pass library name as compile-time definition to OpenCL wrapper +and modify wrapper to use configured name instead of hardcoded defaults. +This fixes OpenCL library loading issues on systems with non-standard +installations and various Linux distributions. + +Upstream-Status: Submitted [https://github.com/tensorflow/tensorflow/pull/109377] +Signed-off-by: Tushar Darote +--- + tensorflow/lite/CMakeLists.txt | 14 ++++++++++++++ + tensorflow/lite/delegates/gpu/cl/opencl_wrapper.cc | 2 +- + 2 files changed, 15 insertions(+), 1 deletion(-) + +diff --git a/tensorflow/lite/CMakeLists.txt b/tensorflow/lite/CMakeLists.txt +index cdd38ff2086..2971047b3fc 100644 +--- a/tensorflow/lite/CMakeLists.txt ++++ b/tensorflow/lite/CMakeLists.txt +@@ -746,6 +746,20 @@ if (NOT BUILD_SHARED_LIBS) + list(APPEND TFLITE_TARGET_PUBLIC_OPTIONS "-DTFL_STATIC_LIBRARY_BUILD") + endif() + ++find_package(PkgConfig) ++pkg_check_modules(OPENCL opencl) ++ ++if(OPENCL_FOUND) ++ string(REGEX MATCH "^[0-9]+" OPENCL_VERSION_MAJOR ${OPENCL_VERSION}) ++ set(CL_LIB_NAME "libOpenCL.so.${OPENCL_VERSION_MAJOR}") ++else() ++ set(CL_LIB_NAME "libOpenCL.so") ++endif() ++ ++target_compile_definitions(tensorflow-lite ++ PRIVATE CL_LIB_NAME=\"${CL_LIB_NAME}\" ++) ++ + target_compile_options(tensorflow-lite + PUBLIC ${TFLITE_TARGET_PUBLIC_OPTIONS} + PRIVATE ${TFLITE_TARGET_PRIVATE_OPTIONS} +diff --git a/tensorflow/lite/delegates/gpu/cl/opencl_wrapper.cc b/tensorflow/lite/delegates/gpu/cl/opencl_wrapper.cc +index 2eb95df35ae..b8229ec1f96 100644 +--- a/tensorflow/lite/delegates/gpu/cl/opencl_wrapper.cc ++++ b/tensorflow/lite/delegates/gpu/cl/opencl_wrapper.cc +@@ -119,7 +119,7 @@ absl::Status LoadOpenCLOnce() { + static const char* kClLibName = + "/System/Library/Frameworks/OpenCL.framework/OpenCL"; + #else +- static const char* kClLibName = "libOpenCL.so"; ++ static const char* kClLibName = CL_LIB_NAME; + #endif + #ifdef __ANDROID__ + libopencl = AndroidDlopenSphalLibrary(kClLibName, RTLD_NOW | RTLD_LOCAL); +-- +2.34.1 + diff --git a/recipes-ml/tflite/files/0004-cmake-Exclude-subdirectories-from-all-builds.patch b/recipes-ml/tflite/files/0004-cmake-Exclude-subdirectories-from-all-builds.patch new file mode 100644 index 00000000..1ef6f7eb --- /dev/null +++ b/recipes-ml/tflite/files/0004-cmake-Exclude-subdirectories-from-all-builds.patch @@ -0,0 +1,117 @@ +From de587e5f42b09ec416f5ee2d7f9a884232354c03 Mon Sep 17 00:00:00 2001 +From: Tushar Darote +Date: Thu, 29 Jan 2026 18:18:00 +0530 +Subject: [PATCH 4/9] cmake: Exclude subdirectories from all builds + +Add EXCLUDE_FROM_ALL to add_subdirectory() calls in multiple CMake +modules to prevent unnecessary compilation of third-party dependencies +during default builds. This reduces build time and resource usage. + +- eigen.cmake +- farmhash.cmake +- fft2d.cmake +- flatbuffers.cmake +- gemmlowp.cmake +- neon2sse.cmake +- ruy.cmake + +Upstream-Status: Submitted [https://github.com/tensorflow/tensorflow/pull/109378] +Signed-off-by: Tushar Darote +--- + tensorflow/lite/tools/cmake/modules/cpuinfo.cmake | 1 + + tensorflow/lite/tools/cmake/modules/eigen.cmake | 2 +- + tensorflow/lite/tools/cmake/modules/farmhash.cmake | 1 + + tensorflow/lite/tools/cmake/modules/fft2d.cmake | 1 + + tensorflow/lite/tools/cmake/modules/flatbuffers.cmake | 1 + + tensorflow/lite/tools/cmake/modules/gemmlowp.cmake | 1 + + tensorflow/lite/tools/cmake/modules/neon2sse.cmake | 1 + + tensorflow/lite/tools/cmake/modules/ruy.cmake | 1 + + 8 files changed, 8 insertions(+), 1 deletion(-) + +diff --git a/tensorflow/lite/tools/cmake/modules/cpuinfo.cmake b/tensorflow/lite/tools/cmake/modules/cpuinfo.cmake +index 5556bec6448..8d1124ff261 100644 +--- a/tensorflow/lite/tools/cmake/modules/cpuinfo.cmake ++++ b/tensorflow/lite/tools/cmake/modules/cpuinfo.cmake +@@ -41,4 +41,5 @@ set(CPUINFO_BUILD_BENCHMARKS OFF CACHE BOOL "Disable cpuinfo micro-benchmarks") + add_subdirectory( + "${cpuinfo_SOURCE_DIR}" + "${cpuinfo_BINARY_DIR}" ++ EXCLUDE_FROM_ALL + ) +diff --git a/tensorflow/lite/tools/cmake/modules/eigen.cmake b/tensorflow/lite/tools/cmake/modules/eigen.cmake +index cf73d72fb32..c2ffd3f3d78 100644 +--- a/tensorflow/lite/tools/cmake/modules/eigen.cmake ++++ b/tensorflow/lite/tools/cmake/modules/eigen.cmake +@@ -99,4 +99,4 @@ set(EIGEN_TEST_SYCL OFF CACHE BOOL "Disable Sycl test") + set(EIGEN_SYCL_TRISYCL OFF CACHE BOOL "Disable triSYCL test") + # Make sure only MPL2.0 or more permissively licensed code is included. + add_compile_definitions(EIGEN_MPL2_ONLY) +-add_subdirectory("${eigen_SOURCE_DIR}" "${eigen_BINARY_DIR}") ++add_subdirectory("${eigen_SOURCE_DIR}" "${eigen_BINARY_DIR}" EXCLUDE_FROM_ALL) +diff --git a/tensorflow/lite/tools/cmake/modules/farmhash.cmake b/tensorflow/lite/tools/cmake/modules/farmhash.cmake +index 9c8e039e6fe..7a5160fa7eb 100644 +--- a/tensorflow/lite/tools/cmake/modules/farmhash.cmake ++++ b/tensorflow/lite/tools/cmake/modules/farmhash.cmake +@@ -44,4 +44,5 @@ set(FARMHASH_SOURCE_DIR "${farmhash_SOURCE_DIR}" CACHE PATH + add_subdirectory( + "${CMAKE_CURRENT_LIST_DIR}/farmhash" + "${farmhash_BINARY_DIR}" ++ EXCLUDE_FROM_ALL + ) +diff --git a/tensorflow/lite/tools/cmake/modules/fft2d.cmake b/tensorflow/lite/tools/cmake/modules/fft2d.cmake +index b4169104fae..9d44a2c6865 100644 +--- a/tensorflow/lite/tools/cmake/modules/fft2d.cmake ++++ b/tensorflow/lite/tools/cmake/modules/fft2d.cmake +@@ -37,4 +37,5 @@ set(FFT2D_SOURCE_DIR "${fft2d_SOURCE_DIR}" CACHE PATH "fft2d source") + add_subdirectory( + "${CMAKE_CURRENT_LIST_DIR}/fft2d" + "${fft2d_BINARY_DIR}" ++ EXCLUDE_FROM_ALL + ) +diff --git a/tensorflow/lite/tools/cmake/modules/flatbuffers.cmake b/tensorflow/lite/tools/cmake/modules/flatbuffers.cmake +index 8febb1fbd1c..267031de68f 100644 +--- a/tensorflow/lite/tools/cmake/modules/flatbuffers.cmake ++++ b/tensorflow/lite/tools/cmake/modules/flatbuffers.cmake +@@ -42,6 +42,7 @@ add_definitions(-DNOMINMAX=1) + add_subdirectory( + "${flatbuffers_SOURCE_DIR}" + "${flatbuffers_BINARY_DIR}" ++ EXCLUDE_FROM_ALL + ) + remove_definitions(-DNOMINMAX) + +diff --git a/tensorflow/lite/tools/cmake/modules/gemmlowp.cmake b/tensorflow/lite/tools/cmake/modules/gemmlowp.cmake +index 76d9705475b..9c8e2c90c7c 100644 +--- a/tensorflow/lite/tools/cmake/modules/gemmlowp.cmake ++++ b/tensorflow/lite/tools/cmake/modules/gemmlowp.cmake +@@ -48,6 +48,7 @@ set(GEMMLOWP_SOURCE_DIR "${gemmlowp_SOURCE_DIR}" CACHE PATH "Source directory") + add_subdirectory( + "${gemmlowp_SOURCE_DIR}/contrib" + "${gemmlowp_BINARY_DIR}" ++ EXCLUDE_FROM_ALL + ) + + set(BUILD_TESTING ${BUILD_TESTING_TMP}) +diff --git a/tensorflow/lite/tools/cmake/modules/neon2sse.cmake b/tensorflow/lite/tools/cmake/modules/neon2sse.cmake +index c2612e34bd2..77bcf1acba3 100644 +--- a/tensorflow/lite/tools/cmake/modules/neon2sse.cmake ++++ b/tensorflow/lite/tools/cmake/modules/neon2sse.cmake +@@ -40,4 +40,5 @@ endif() + add_subdirectory( + "${neon2sse_SOURCE_DIR}" + "${neon2sse_BINARY_DIR}" ++ EXCLUDE_FROM_ALL + ) +diff --git a/tensorflow/lite/tools/cmake/modules/ruy.cmake b/tensorflow/lite/tools/cmake/modules/ruy.cmake +index 1c5965f94f5..a6632d3247f 100644 +--- a/tensorflow/lite/tools/cmake/modules/ruy.cmake ++++ b/tensorflow/lite/tools/cmake/modules/ruy.cmake +@@ -37,4 +37,5 @@ set(RUY_SOURCE_DIR "${ruy_SOURCE_DIR}" CACHE PATH "RUY source directory") + add_subdirectory( + "${ruy_SOURCE_DIR}" + "${ruy_BINARY_DIR}" ++ EXCLUDE_FROM_ALL + ) +-- +2.34.1 + diff --git a/recipes-ml/tflite/files/0005-c-Force-delegate-symbols-from-shared-library.patch b/recipes-ml/tflite/files/0005-c-Force-delegate-symbols-from-shared-library.patch new file mode 100644 index 00000000..9ae71e95 --- /dev/null +++ b/recipes-ml/tflite/files/0005-c-Force-delegate-symbols-from-shared-library.patch @@ -0,0 +1,76 @@ +From 12fe5695802d3852c7e67fffcc74f8b3c46698cc Mon Sep 17 00:00:00 2001 +From: Tushar Darote +Date: Thu, 29 Jan 2026 18:25:22 +0530 +Subject: [PATCH 5/9] c: Force delegate symbols from shared library + +Add linker options to ensure delegate create/delete functions are resolved +from shared libraries rather than statically linked. Handles XNNPACK, external +delegate, and GPU delegates with platform-specific flags for Windows, macOS, +and Linux. + +Upstream-Status: Submitted [https://github.com/tensorflow/tensorflow/pull/109379] +Signed-off-by: Tushar Darote +--- + tensorflow/lite/c/CMakeLists.txt | 42 ++++++++++++++++++++++++++++++++ + 1 file changed, 42 insertions(+) + +diff --git a/tensorflow/lite/c/CMakeLists.txt b/tensorflow/lite/c/CMakeLists.txt +index 931f4372c5f..9fcafb14495 100644 +--- a/tensorflow/lite/c/CMakeLists.txt ++++ b/tensorflow/lite/c/CMakeLists.txt +@@ -80,10 +80,52 @@ if (TFLITE_C_BUILD_SHARED_LIBS) + if (WIN32) + target_compile_definitions(tensorflowlite_c PRIVATE TFL_COMPILE_LIBRARY) + target_compile_definitions(tensorflow-lite PRIVATE TFL_COMPILE_LIBRARY) ++ # Force the linker to treat delegate create and delete as undefined ++ # to pull them from static to shared library ++ if (TFLITE_ENABLE_XNNPACK) ++ target_link_options(tensorflowlite_c PRIVATE "/INCLUDE:TfLiteXNNPackDelegateCreate") ++ target_link_options(tensorflowlite_c PRIVATE "/INCLUDE:TfLiteXNNPackDelegateDelete") ++ endif() ++ if (TFLITE_ENABLE_EXTERNAL_DELEGATE) ++ target_link_options(tensorflowlite_c PRIVATE "/INCLUDE:TfLiteExternalDelegateCreate") ++ target_link_options(tensorflowlite_c PRIVATE "/INCLUDE:TfLiteExternalDelegateDelete") ++ endif() ++ if (CMAKE_SYSTEM_NAME MATCHES "Android" OR TFLITE_ENABLE_GPU) ++ target_link_options(tensorflowlite_c PRIVATE "/INCLUDE:TfLiteGpuDelegateV2Create") ++ target_link_options(tensorflowlite_c PRIVATE "/INCLUDE:TfLiteGpuDelegateV2Delete") ++ endif() + elseif (APPLE) + target_link_options(tensorflowlite_c PRIVATE "-Wl,-exported_symbols_list,${TFLITE_SOURCE_DIR}/c/exported_symbols.lds") ++ # Force the linker to treat delegate create and delete as undefined ++ # to pull them from static to shared library ++ if (TFLITE_ENABLE_XNNPACK) ++ target_link_options(tensorflowlite_c PRIVATE "-Wl,-u,_TfLiteXNNPackDelegateCreate") ++ target_link_options(tensorflowlite_c PRIVATE "-Wl,-u,_TfLiteXNNPackDelegateDelete") ++ endif() ++ if (TFLITE_ENABLE_EXTERNAL_DELEGATE) ++ target_link_options(tensorflowlite_c PRIVATE "-Wl,-u,_TfLiteExternalDelegateCreate") ++ target_link_options(tensorflowlite_c PRIVATE "-Wl,-u,_TfLiteExternalDelegateDelete") ++ endif() ++ if (CMAKE_SYSTEM_NAME MATCHES "Android" OR TFLITE_ENABLE_GPU) ++ target_link_options(tensorflowlite_c PRIVATE "-Wl,-u,_TfLiteGpuDelegateV2Create") ++ target_link_options(tensorflowlite_c PRIVATE "-Wl,-u,_TfLiteGpuDelegateV2Delete") ++ endif() + else () + target_link_options(tensorflowlite_c PRIVATE "-Wl,--version-script,${TFLITE_SOURCE_DIR}/c/version_script.lds") ++ # Force the linker to treat delegate create and delete as undefined ++ # to pull them from static to shared library ++ if (TFLITE_ENABLE_XNNPACK) ++ target_link_options(tensorflowlite_c PRIVATE "-Wl,-u,TfLiteXNNPackDelegateCreate") ++ target_link_options(tensorflowlite_c PRIVATE "-Wl,-u,TfLiteXNNPackDelegateDelete") ++ endif() ++ if (TFLITE_ENABLE_EXTERNAL_DELEGATE) ++ target_link_options(tensorflowlite_c PRIVATE "-Wl,-u,TfLiteExternalDelegateCreate") ++ target_link_options(tensorflowlite_c PRIVATE "-Wl,-u,TfLiteExternalDelegateDelete") ++ endif() ++ if (CMAKE_SYSTEM_NAME MATCHES "Android" OR TFLITE_ENABLE_GPU) ++ target_link_options(tensorflowlite_c PRIVATE "-Wl,-u,TfLiteGpuDelegateV2Create") ++ target_link_options(tensorflowlite_c PRIVATE "-Wl,-u,TfLiteGpuDelegateV2Delete") ++ endif() + endif() + endif() + +-- +2.34.1 + diff --git a/recipes-ml/tflite/files/0006-c-Add-version-support-to-C-API.patch b/recipes-ml/tflite/files/0006-c-Add-version-support-to-C-API.patch new file mode 100644 index 00000000..7eaeac67 --- /dev/null +++ b/recipes-ml/tflite/files/0006-c-Add-version-support-to-C-API.patch @@ -0,0 +1,58 @@ +From 42e520631efdb34a1b5093d2d72bc6e4043b923d Mon Sep 17 00:00:00 2001 +From: Tushar Darote +Date: Thu, 29 Jan 2026 18:54:32 +0530 +Subject: [PATCH 6/9] c: Add version support to C API + +Set up version handling with compile definitions for major, minor, and patch +versions. Configure shared library properties with version and soversion +for proper C API versioning. + +Upstream-Status: Submitted [https://github.com/tensorflow/tensorflow/pull/109380] +Signed-off-by: Tushar Darote +--- + tensorflow/lite/c/CMakeLists.txt | 22 +++++++++++++++++++++- + 1 file changed, 21 insertions(+), 1 deletion(-) + +diff --git a/tensorflow/lite/c/CMakeLists.txt b/tensorflow/lite/c/CMakeLists.txt +index 9fcafb14495..7d9a5942cab 100644 +--- a/tensorflow/lite/c/CMakeLists.txt ++++ b/tensorflow/lite/c/CMakeLists.txt +@@ -14,7 +14,22 @@ + # limitations under the License. + + cmake_minimum_required(VERSION 3.16) +-project(tensorflow-lite-c C CXX) ++ ++set(TF_MAJOR_VERSION "" CACHE STRING "TensorFlow Lite major version") ++set(TF_MINOR_VERSION "" CACHE STRING "TensorFlow Lite minor version") ++set(TF_PATCH_VERSION "" CACHE STRING "TensorFlow Lite patch version") ++set(TF_VERSION_SUFFIX "" CACHE STRING "TensorFlow Lite version suffix") ++ ++project(tensorflow-lite-c ++ VERSION "${TF_MAJOR_VERSION}.${TF_MINOR_VERSION}.${TF_PATCH_VERSION}${TF_VERSION_SUFFIX}" ++ LANGUAGES C CXX) ++ ++add_compile_definitions( ++ TF_MAJOR_VERSION=${TF_MAJOR_VERSION} ++ TF_MINOR_VERSION=${TF_MINOR_VERSION} ++ TF_PATCH_VERSION=${TF_PATCH_VERSION} ++ TF_VERSION_SUFFIX="${TF_VERSION_SUFFIX}" ++) + + option(TFLITE_C_BUILD_SHARED_LIBS "Build shared libraries" ON) + +@@ -129,6 +144,11 @@ if (TFLITE_C_BUILD_SHARED_LIBS) + endif() + endif() + ++set_target_properties(tensorflowlite_c PROPERTIES ++ VERSION "${TF_MAJOR_VERSION}.${TF_MINOR_VERSION}.${TF_PATCH_VERSION}${TF_VERSION_SUFFIX}" ++ SOVERSION ${TF_MAJOR_VERSION} ++) ++ + target_link_libraries(tensorflowlite_c + tensorflow-lite + ) +-- +2.34.1 + diff --git a/recipes-ml/tflite/files/0007-cmake-Fix-label-image-dependencies.patch b/recipes-ml/tflite/files/0007-cmake-Fix-label-image-dependencies.patch new file mode 100644 index 00000000..cc4cbd2f --- /dev/null +++ b/recipes-ml/tflite/files/0007-cmake-Fix-label-image-dependencies.patch @@ -0,0 +1,39 @@ +From 0676f58864633579a6e4702dc47868a2f98e9708 Mon Sep 17 00:00:00 2001 +From: Ivan Evlogiev +Date: Thu, 22 Jan 2026 16:32:46 +0000 +Subject: [PATCH 7/9] cmake: Fix label image dependencies + +- Properly find Protobuf package +- Link with protobuf library from protobuf package +- Link with abseil dependency of protobuf + +Upstream-Status: Submitted [https://github.com/tensorflow/tensorflow/pull/109381] +Signed-off-by: Ivan Evlogiev +--- + tensorflow/lite/examples/label_image/CMakeLists.txt | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +diff --git a/tensorflow/lite/examples/label_image/CMakeLists.txt b/tensorflow/lite/examples/label_image/CMakeLists.txt +index 07ab2343ae5..31d31661ca3 100644 +--- a/tensorflow/lite/examples/label_image/CMakeLists.txt ++++ b/tensorflow/lite/examples/label_image/CMakeLists.txt +@@ -16,6 +16,8 @@ + + # The label_image example for Tensorflow Lite. + ++find_package(Protobuf REQUIRED) ++ + populate_source_vars("${TFLITE_SOURCE_DIR}/examples/label_image" + TFLITE_LABEL_IMAGE_SRCS + FILTER "_test\\.cc$" +@@ -84,5 +86,6 @@ target_compile_options(label_image + target_link_libraries(label_image + tensorflow-lite + profiling_info_proto +- libprotobuf ++ protobuf::libprotobuf ++ absl::log + ) +-- +2.34.1 + diff --git a/recipes-ml/tflite/files/0008-cmake-Add-install-rule-for-c-interface-shared-librar.patch b/recipes-ml/tflite/files/0008-cmake-Add-install-rule-for-c-interface-shared-librar.patch new file mode 100644 index 00000000..5717b282 --- /dev/null +++ b/recipes-ml/tflite/files/0008-cmake-Add-install-rule-for-c-interface-shared-librar.patch @@ -0,0 +1,74 @@ +From fc53cdac176fbbd8e283da96c275057caf4e2eae Mon Sep 17 00:00:00 2001 +From: Ivan Evlogiev +Date: Thu, 22 Jan 2026 16:37:21 +0000 +Subject: [PATCH 8/9] cmake: Add install rule for c interface shared library + +- Install c interface library when shared library is enabled +- Do not install cpp static library when shared library is used +- Add package config file for shared library + +Upstream-Status: Submitted [https://github.com/tensorflow/tensorflow/pull/109382] +Signed-off-by: Ivan Evlogiev +--- + tensorflow/lite/CMakeLists.txt | 4 ++-- + tensorflow/lite/c/CMakeLists.txt | 14 ++++++++++++++ + tensorflow/lite/c/tensorflowlite_c.pc.in | 10 ++++++++++ + 3 files changed, 26 insertions(+), 2 deletions(-) + create mode 100644 tensorflow/lite/c/tensorflowlite_c.pc.in + +diff --git a/tensorflow/lite/CMakeLists.txt b/tensorflow/lite/CMakeLists.txt +index 2971047b3fc..76dc0637645 100644 +--- a/tensorflow/lite/CMakeLists.txt ++++ b/tensorflow/lite/CMakeLists.txt +@@ -766,8 +766,8 @@ target_compile_options(tensorflow-lite + ) + add_library(${PROJECT_NAME}::tensorflowlite ALIAS tensorflow-lite) + +-# The install targets. +-if(TFLITE_ENABLE_INSTALL) ++# The install targets for static lib. ++if(TFLITE_ENABLE_INSTALL AND NOT TFLITE_C_BUILD_SHARED_LIBS) + install( + TARGETS tensorflow-lite + EXPORT ${PROJECT_NAME}Targets +diff --git a/tensorflow/lite/c/CMakeLists.txt b/tensorflow/lite/c/CMakeLists.txt +index 7d9a5942cab..9b7fe9bfe7e 100644 +--- a/tensorflow/lite/c/CMakeLists.txt ++++ b/tensorflow/lite/c/CMakeLists.txt +@@ -152,3 +152,17 @@ set_target_properties(tensorflowlite_c PROPERTIES + target_link_libraries(tensorflowlite_c + tensorflow-lite + ) ++if(TFLITE_ENABLE_INSTALL) ++ install(TARGETS tensorflowlite_c) ++ ++ configure_file( ++ tensorflowlite_c.pc.in ++ ${CMAKE_CURRENT_BINARY_DIR}/tensorflowlite_c.pc ++ @ONLY ++ ) ++ ++ install( ++ FILES ${CMAKE_CURRENT_BINARY_DIR}/tensorflowlite_c.pc ++ DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig ++ ) ++endif() +diff --git a/tensorflow/lite/c/tensorflowlite_c.pc.in b/tensorflow/lite/c/tensorflowlite_c.pc.in +new file mode 100644 +index 00000000000..42c5f02a8ad +--- /dev/null ++++ b/tensorflow/lite/c/tensorflowlite_c.pc.in +@@ -0,0 +1,10 @@ ++prefix=@CMAKE_INSTALL_PREFIX@ ++libdir=${prefix}/lib ++includedir=${prefix}/include ++ ++Name: tensorflow lite ++Description: tensorflow lite shared library ++Version: @PROJECT_VERSION@ ++Requires: ++Libs: -L${libdir} -ltensorflowlite_c ++Cflags: -I${includedir} +-- +2.34.1 + diff --git a/recipes-ml/tflite/files/0009-tflite-Add-absl-log-dependency-for-enhanced-logging-.patch b/recipes-ml/tflite/files/0009-tflite-Add-absl-log-dependency-for-enhanced-logging-.patch new file mode 100644 index 00000000..ea70b360 --- /dev/null +++ b/recipes-ml/tflite/files/0009-tflite-Add-absl-log-dependency-for-enhanced-logging-.patch @@ -0,0 +1,29 @@ +From 30ab372896886efbc295603310c31a9d2e851e79 Mon Sep 17 00:00:00 2001 +From: Tushar Darote +Date: Fri, 20 Feb 2026 21:56:20 +0530 +Subject: [PATCH 9/9] tflite: Add absl::log dependency for enhanced logging + support + +This change adds the absl::log library + +Upstream-Status: Submitted [https://github.com/tensorflow/tensorflow/pull/110784] +Signed-off-by: Tushar Darote +--- + tensorflow/lite/CMakeLists.txt | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/tensorflow/lite/CMakeLists.txt b/tensorflow/lite/CMakeLists.txt +index 76dc0637645..bea6e4eb78b 100644 +--- a/tensorflow/lite/CMakeLists.txt ++++ b/tensorflow/lite/CMakeLists.txt +@@ -728,6 +728,7 @@ target_link_libraries(tensorflow-lite + Eigen3::Eigen + absl::flags + absl::hash ++ absl::log + absl::status + absl::strings + absl::synchronization +-- +2.34.1 + diff --git a/recipes-ml/tflite/files/extract_tflite_srcrevs_from_github.py b/recipes-ml/tflite/files/extract_tflite_srcrevs_from_github.py new file mode 100644 index 00000000..9d03724f --- /dev/null +++ b/recipes-ml/tflite/files/extract_tflite_srcrevs_from_github.py @@ -0,0 +1,276 @@ +#!/usr/bin/env python3 + +################################################################################ +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. +# SPDX-License-Identifier: BSD-3-Clause-Clear +################################################################################ + +import requests +import re +import sys +from urllib.parse import quote +import json + +def get_github_content(owner, repo, ref, filepath): + """Fetch content from GitHub""" + url = f"https://api.github.com/repos/{owner}/{repo}/contents/{filepath}?ref={ref}" + response = requests.get(url) + if response.status_code == 200: + content = response.json() + # Decode base64 content + import base64 + return base64.b64decode(content['content']).decode('utf-8') + return None + +def get_android_git_commit(repo_url, branch="main"): + """Fetch latest commit from Android external repository""" + try: + # Direct API call to get latest commit + api_url = f"{repo_url}/+/refs/heads/{branch}" + response = requests.get(api_url) + if response.status_code == 200: + content = response.text + # Look for commit hash pattern + match = re.search(r'([a-f0-9]{40})', content) + if match: + return match.group(1) + except: + pass + return None + +def extract_from_workspace_bzl(content, pattern): + """Extract commit from workspace.bzl content""" + match = re.search(pattern, content) + if match: + return match.group(1) if match.group(1) else match.group(2) + return None + +def extract_from_cmake(content, pattern): + """Extract commit from cmake content""" + match = re.search(pattern, content) + if match: + return match.group(1) if match.group(1) else match.group(2) + return None + +def main(): + if len(sys.argv) != 2: + print("Usage: python3 extract_tflite_srcrevs_from_github.py ") + print("Example: python3 extract_tflite_srcrevs_from_github.py v2.20.0") + sys.exit(1) + + tensorflow_version = sys.argv[1] + owner = "tensorflow" + repo = "tensorflow" + + print(f"Extracting SRCREV values for TensorFlow {tensorflow_version} from GitHub...") + + # Dictionary mapping component names to their extraction methods + components = { + 'farmhash': { + 'files': [ + 'third_party/xla/third_party/farmhash/workspace.bzl', + 'tensorflow/lite/tools/cmake/modules/farmhash.cmake' + ], + 'patterns': [ + r'FARMHASH_COMMIT\s*=\s*"([^"]+)"', + r'GIT_TAG\s+([a-f0-9]+)' + ] + }, + 'gemmlowp': { + 'files': [ + 'third_party/xla/third_party/gemmlowp/workspace.bzl', + 'tensorflow/lite/tools/cmake/modules/gemmlowp.cmake' + ], + 'patterns': [ + r'GEMMLOWP_COMMIT\s*=\s*"([^"]+)"', + r'GIT_TAG\s+([a-f0-9]+)' + ] + }, + 'cpuinfo': { + 'files': [ + 'third_party/xla/workspace2.bzl', + 'tensorflow/workspace2.bzl', + 'tensorflow/lite/tools/cmake/modules/cpuinfo.cmake' + ], + 'patterns': [ + r'cpuinfo-([a-f0-9]+)', + r'GIT_TAG\s+([a-f0-9]+)' + ] + }, + 'mlDtypes': { + 'files': [ + 'third_party/xla/third_party/py/ml_dtypes/workspace.bzl', + 'tensorflow/lite/tools/cmake/modules/ml_dtypes.cmake' + ], + 'patterns': [ + r'ML_DTYPES_COMMIT\s*=\s*"([^"]+)"', + r'GIT_TAG\s+([a-f0-9]+)' + ] + }, + 'ruy': { + 'files': [ + 'third_party/ruy/workspace.bzl', + 'tensorflow/lite/tools/cmake/modules/ruy.cmake' + ], + 'patterns': [ + r'ruy-([a-f0-9]+)', + r'GIT_TAG\s+([a-f0-9]+)' + ] + }, + 'openclHeaders': { + 'files': [ + 'third_party/opencl_headers/workspace.bzl', + 'tensorflow/lite/tools/cmake/modules/opencl_headers.cmake' + ], + 'patterns': [ + r'OpenCL-Headers-([a-f0-9]+)', + r'GIT_TAG\s+([a-f0-9]+)' + ] + }, + 'vulkanHeaders': { + 'files': [ + 'third_party/vulkan_headers/workspace.bzl', + 'tensorflow/lite/tools/cmake/modules/vulkan_headers.cmake' + ], + 'patterns': [ + r'Vulkan-Headers-([a-f0-9]+)', + r'GIT_TAG\s+([a-f0-9]+)' + ] + }, + 'xnnpack': { + 'files': [ + 'third_party/xla/workspace2.bzl', + 'tensorflow/workspace2.bzl', + 'tensorflow/lite/tools/cmake/modules/xnnpack.cmake' + ], + 'patterns': [ + r'XNNPACK-([a-f0-9]+)', + r'GIT_TAG\s+([a-f0-9]+)' + ] + }, + 'fp16': { + 'files': [ + 'third_party/xla/third_party/FP16/workspace.bzl' + ], + 'patterns': [ + r'FP16-([a-f0-9]+)', + r'GIT_TAG\s+([a-f0-9]+)' + ] + }, + 'kleidiai': { + 'files': [ + 'third_party/xla/workspace2.bzl', + 'tensorflow/workspace2.bzl' + ], + 'patterns': [ + r'kleidiai-([a-f0-9]+)', + r'GIT_TAG\s+([a-f0-9]+)' + ] + }, + 'pthreadpool': { + 'files': [ + 'third_party/xla/workspace2.bzl', + 'tensorflow/workspace2.bzl', + 'tensorflow/lite/cmake/DownloadPThreadPool.cmake' + ], + 'patterns': [ + r'pthreadpool-([a-f0-9]+)', + r'GIT_TAG\s+([a-f0-9]+)' + ] + }, + 'fxdiv': { + 'files': [ + 'third_party/xla/workspace2.bzl', + 'tensorflow/workspace2.bzl' + ], + 'patterns': [ + r'FXdiv-([a-f0-9]+)', + r'GIT_TAG\s+([a-f0-9]+)' + ] + }, + 'fft2d': { + 'special_handling': True, + 'repo_url': 'https://android.googlesource.com/platform/external/fft2d', + 'branch': 'main' + } + } + + # Extract commits + srcrevs = {} + + # Handle special cases first + if 'fft2d' in components and components['fft2d'].get('special_handling'): + # Fetch fft2d from Android source + try: + # Direct API call to get latest commit + api_url = "https://android.googlesource.com/platform/external/fft2d/+refs/heads/main" + response = requests.get(api_url) + if response.status_code == 200: + content = response.text + # Look for commit hash in the response + match = re.search(r'([a-f0-9]{40})', content) + if match: + commit = match.group(1) + srcrevs['fft2d'] = commit + print(f"Found fft2d commit: {commit}") + else: + # Alternative method - try to get from a specific API endpoint + api_url = "https://android.googlesource.com/platform/external/fft2d/+log" + response = requests.get(api_url) + if response.status_code == 200: + lines = response.text.split('\n') + if len(lines) > 1: + # First line should contain the latest commit + first_line = lines[0] + match = re.search(r'^([a-f0-9]{40})', first_line) + if match: + commit = match.group(1) + srcrevs['fft2d'] = commit + print(f"Found fft2d commit: {commit}") + except Exception as e: + print(f"Error fetching fft2d: {e}") + print("⚠️ Could not fetch fft2d commit, skipping...") + + # Handle regular components + for component, info in components.items(): + if component == 'fft2d' or 'special_handling' in info: + continue # Already handled + + commit = None + for file_path in info['files']: + if commit: + break + + content = get_github_content(owner, repo, tensorflow_version, file_path) + if content: + # Try each pattern + for pattern in info['patterns']: + match = re.search(pattern, content) + if match: + # Handle capturing groups properly + if len(match.groups()) >= 1: + commit = match.group(1) if match.group(1) else match.group(2) if len(match.groups()) > 1 and match.group(2) else None + else: + commit = match.group(0) + if commit: + break + + if commit: + srcrevs[component] = commit + else: + print(f"⚠️ Could not find commit for {component} in {tensorflow_version}") + + # Sort the SRCREV values alphabetically by component name + sorted_srcrevs = dict(sorted(srcrevs.items())) + + # Print the results in sorted order + print("\nGenerated SRCREV entries (sorted):") + print("# Generated from TensorFlow GitHub repository") + print(f"# TensorFlow version: {tensorflow_version}") + for component, commit in sorted_srcrevs.items(): + print(f'SRCREV_{component} = "{commit}"') + + return sorted_srcrevs + +if __name__ == "__main__": + main() diff --git a/recipes-ml/tflite/tensorflow-lite_2.20.0.bb b/recipes-ml/tflite/tensorflow-lite_2.20.0.bb new file mode 100644 index 00000000..a0625d5a --- /dev/null +++ b/recipes-ml/tflite/tensorflow-lite_2.20.0.bb @@ -0,0 +1,170 @@ +SUMMARY = "TensorFlow Lite C API Library" +DESCRIPTION = "TensorFlow Lite C API Library for embedded systems" +LICENSE = "Apache-2.0" +LIC_FILES_CHKSUM = "file://LICENSE;md5=4158a261ca7f2525513e31ba9c50ae98" + +REQUIRED_DISTRO_FEATURES += "opengl" + +DEPENDS += " \ + flatbuffers-tflite \ + flatbuffers-tflite-native \ + jpeg \ + libeigen \ + opencl-headers \ + protobuf \ + protobuf-native \ + virtual/egl \ +" + +PACKAGECONFIG ?= "gpu" +PACKAGECONFIG[gpu] = " -DTFLITE_ENABLE_GPU=ON, -DTFLITE_ENABLE_GPU=OFF, virtual/libopencl1 vulkan-headers," + +# TensorFlow Lite version and branch +TF_LITE_VERSION = "${PV}" +TF_LITE_MAJOR = "${@d.getVar('PV').split('.')[0]}" +TF_LITE_MINOR = "${@d.getVar('PV').split('.')[1]}" +TF_LITE_PATCH = "0" +TF_LITE_BRANCH = "r${TF_LITE_MAJOR}.${TF_LITE_MINOR}" + +SRCREV_FORMAT = "tensorflow_cpuinfo_farmhash_fft2d_fp16_fxdiv_gemmlowp_kleidiai_mlDtypes_openclHeaders_pthreadpool_ruy_vulkanHeaders_xnnpack" + +# Main TensorFlow repository revision +SRCREV_tensorflow = "72fbba3d20f4616d7312b5e2b7f79daf6e82f2fa" + +# Third‑party dependency revisions used by TensorFlow Lite +# +# How to update these SRCREV_* values: +# +# 1) Use the automated script 'extract_tflite_srcrevs_from_github.py' to generate +# the latest SRCREV values for all dependencies. +# +# 2) Run the script with the target TensorFlow version: +# python3 extract_tflite_srcrevs_from_github.py v2.20.0 +# +# 3) Replace the SRCREV_* values below with the output from the script. +# +# 4) For fft2d specifically, the script automatically fetches from: +# https://android.googlesource.com/platform/external/fft2d.git +# +# 5) Rebuild and validate. +# +# IMPORTANT: Always use the automated script to ensure SRCREV values match +# the exact pinned versions in the TensorFlow repository. +# Pinned third‑party revisions (automatically generated) +SRCREV_cpuinfo = "de0ce7c7251372892e53ce9bc891750d2c9a4fd8" +SRCREV_farmhash = "0d859a811870d10f53a594927d0d0b97573ad06d" +SRCREV_fft2d = "fa0ad63f8b666836f56a823de546390a6e4ff4b6" +SRCREV_fp16 = "4dfe081cf6bcd15db339cf2680b9281b8451eeb3" +SRCREV_fxdiv = "63058eff77e11aa15bf531df5dd34395ec3017c8" +SRCREV_gemmlowp = "16e8662c34917be0065110bfcd9cc27d30f52fdf" +SRCREV_kleidiai = "dc69e899945c412a8ce39ccafd25139f743c60b1" +SRCREV_mlDtypes = "00d98cd92ade342fef589c0470379abb27baebe9" +SRCREV_openclHeaders = "dcd5bede6859d26833cd85f0d6bbcee7382dc9b3" +SRCREV_pthreadpool = "c2ba5c50bb58d1397b693740cf75fad836a0d1bf" +SRCREV_ruy = "3286a34cc8de6149ac6844107dfdffac91531e72" +SRCREV_vulkanHeaders = "32c07c0c5334aea069e518206d75e002ccd85389" +SRCREV_xnnpack = "585e73e63cb35c8a416c83a48ca9ab79f7f7d45e" + +SRC_URI = " \ + git://github.com/tensorflow/tensorflow.git;name=tensorflow;branch=${TF_LITE_BRANCH};protocol=https;tag=v${TF_LITE_VERSION} \ + file://0001-lite-Add-config-option-to-enable-benchmark_model.patch \ + file://0002-cmake-lite-tools-benchmark-require-protobuf-through-.patch \ + file://0003-feat-tflite-Add-dynamic-OpenCL-library-loading-suppo.patch \ + file://0004-cmake-Exclude-subdirectories-from-all-builds.patch \ + file://0005-c-Force-delegate-symbols-from-shared-library.patch \ + file://0006-c-Add-version-support-to-C-API.patch \ + file://0007-cmake-Fix-label-image-dependencies.patch \ + file://0008-cmake-Add-install-rule-for-c-interface-shared-librar.patch \ + file://0009-tflite-Add-absl-log-dependency-for-enhanced-logging-.patch \ + git://github.com/google/farmhash;name=farmhash;destsuffix=tensorflow-lite-${TF_LITE_VERSION}/third_party/farmhash/;branch=master;protocol=https \ + git://github.com/google/gemmlowp.git;name=gemmlowp;destsuffix=tensorflow-lite-${TF_LITE_VERSION}/third_party/gemmlowp/;branch=master;protocol=https \ + git://github.com/pytorch/cpuinfo.git;name=cpuinfo;destsuffix=tensorflow-lite-${TF_LITE_VERSION}/third_party/cpuinfo/;branch=main;protocol=https \ + git://github.com/jax-ml/ml_dtypes.git;name=mlDtypes;destsuffix=tensorflow-lite-${TF_LITE_VERSION}/third_party/ml_dtypes/;branch=main;protocol=https \ + git://github.com/google/ruy.git;name=ruy;destsuffix=tensorflow-lite-${TF_LITE_VERSION}/third_party/ruy/;branch=master;protocol=https \ + git://github.com/KhronosGroup/OpenCL-Headers.git;name=openclHeaders;destsuffix=tensorflow-lite-${TF_LITE_VERSION}/third_party/opencl_headers/;branch=main;protocol=https \ + git://github.com/KhronosGroup/Vulkan-Headers.git;name=vulkanHeaders;destsuffix=tensorflow-lite-${TF_LITE_VERSION}/third_party/vulkan_headers/;branch=main;protocol=https \ + git://github.com/google/XNNPACK.git;name=xnnpack;destsuffix=tensorflow-lite-${TF_LITE_VERSION}/third_party/xnnpack/;branch=master;protocol=https \ + git://android.googlesource.com/platform/external/fft2d.git;name=fft2d;destsuffix=tensorflow-lite-${TF_LITE_VERSION}/fft2d;branch=main;protocol=https \ + git://github.com/Maratyszcza/FP16.git;protocol=https;branch=master;name=fp16;destsuffix=${S}/FP16 \ + git://github.com/ARM-software/kleidiai.git;protocol=https;branch=main;name=kleidiai;destsuffix=${S}/kleidiai \ + git://github.com/google/pthreadpool.git;protocol=https;branch=main;name=pthreadpool;destsuffix=${S}/pthreadpool \ + git://github.com/Maratyszcza/FXdiv.git;protocol=https;branch=master;name=fxdiv;destsuffix=${S}/FXdiv \ +" + +inherit cmake features_check pkgconfig + +OECMAKE_SOURCEPATH = "${S}/tensorflow/lite/c" +OECMAKE_TARGET_COMPILE += "benchmark_model label_image" + +EXTRA_OECMAKE += " \ + -DCMAKE_FIND_PACKAGE_PREFER_CONFIG=ON \ + -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \ + -DCMAKE_SYSTEM_NAME=Linux \ + -DCPUINFO_BUILD_UNIT_TESTS=OFF \ + -DCPUINFO_SUPPORTED_PLATFORM=ON \ + -DFP16_SOURCE_DIR=${S}/FP16 \ + -DFXDIV_SOURCE_DIR=${S}/FXdiv \ + -DKLEIDIAI_SOURCE_DIR=${S}/kleidiai \ + -DProtobuf_PROTOC_EXECUTABLE=${STAGING_BINDIR_NATIVE}/protoc \ + -DTFLITE_ENABLE_BENCHMARK_MODEL=ON \ + -DTFLITE_ENABLE_INSTALL=ON \ + -DTFLITE_ENABLE_LABEL_IMAGE=ON \ + -DTFLITE_ENABLE_NNAPI=OFF \ + -DTFLITE_ENABLE_RUY=ON \ + -DTFLITE_ENABLE_XNNPACK=ON \ + -DTFLITE_HOST_TOOLS_DIR=${STAGING_BINDIR_NATIVE} \ + -DTF_MAJOR_VERSION=${TF_LITE_MAJOR} \ + -DTF_MINOR_VERSION=${TF_LITE_MINOR} \ + -DTF_PATCH_VERSION=${TF_LITE_PATCH} \ + -DTF_VERSION_SUFFIX= \ + -DPTHREADPOOL_SOURCE_DIR=${S}/pthreadpool \ +" + +# Disable ARM BF16 support for clang toolchain builds +EXTRA_OECMAKE:append:toolchain-clang = " -DXNNPACK_ENABLE_ARM_BF16=OFF" + +# Symlink third-party directories +do_configure:prepend() { + mkdir -p ${WORKDIR}/build + cd ${WORKDIR}/build + + # Create symbolic links for third-party dependencies + ln -sf ${S}/third_party/cpuinfo cpuinfo + ln -sf ${S}/third_party/farmhash farmhash + ln -sf ${S}/third_party/gemmlowp gemmlowp + ln -sf ${S}/third_party/ml_dtypes ml_dtypes + ln -sf ${S}/third_party/opencl_headers opencl_headers + ln -sf ${S}/third_party/ruy ruy + ln -sf ${S}/third_party/vulkan_headers vulkan_headers + ln -sf ${S}/third_party/xnnpack xnnpack + ln -sf ${S}/fft2d/src/fft2d/fft2d fft2d + + mkdir -p opengl_headers + cp ${COMMON_LICENSE_DIR}/Apache-2.0 opengl_headers/opengl_headers_LICENSE.txt + + mkdir -p egl_headers + cp ${COMMON_LICENSE_DIR}/Apache-2.0 egl_headers/egl_headers_LICENSE.txt +} + +# Header files to install +TFLITE_HEADERS = " \ + tensorflow/compiler/mlir/lite \ + tensorflow/core/lib \ + tensorflow/core/platform \ + tensorflow/core/public \ + tensorflow/lite \ +" + +do_install:append() { + for HPATH in ${TFLITE_HEADERS}; do + install -d ${D}${includedir}/$(dirname ${HPATH}) + cd ${S} + find ${HPATH} \( ! -name "*hexagon*" -name "*.h*" \) -type f | while read header; do + install -D -m 0644 ${S}/$header ${D}${includedir}/$header + done + done + + install -d ${D}${bindir} + install -m 0755 ${B}/tensorflow-lite/examples/label_image/label_image ${D}${bindir} + install -m 0755 ${B}/tensorflow-lite/tools/benchmark/benchmark_model ${D}${bindir} +}