diff mbox series

[v2,8/8] package/tensorflow-lite: new package

Message ID 20221128175851.1913859-8-james.hilliard1@gmail.com
State Superseded, archived
Headers show
Series [v2,1/8] package/flatbuffers: build position independent code | expand

Commit Message

James Hilliard Nov. 28, 2022, 5:58 p.m. UTC
From: Stefan Hager <stefan.hager@ginzinger.com>

This package adds the tensorflow lite runtime to buildroot.

Signed-off-by: Stefan Hager <stefan.hager@ginzinger.com>
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
Changes v1 -> v2:
  - fix label_image build
  - more explicit cmake config
---
 package/Config.in                             |  1 +
 .../0001-lite-Update-CMakeLists.txt.patch     | 49 +++++++++++++++++++
 .../0002-Fix-FindFlatBuffers-cmake-file.patch | 37 ++++++++++++++
 ...ink-tensorflow-lite-against-gemmlowp.patch | 32 ++++++++++++
 package/tensorflow-lite/Config.in             | 32 ++++++++++++
 package/tensorflow-lite/tensorflow-lite.hash  |  4 ++
 package/tensorflow-lite/tensorflow-lite.mk    | 49 +++++++++++++++++++
 7 files changed, 204 insertions(+)
 create mode 100644 package/tensorflow-lite/0001-lite-Update-CMakeLists.txt.patch
 create mode 100644 package/tensorflow-lite/0002-Fix-FindFlatBuffers-cmake-file.patch
 create mode 100644 package/tensorflow-lite/0003-Don-t-link-tensorflow-lite-against-gemmlowp.patch
 create mode 100644 package/tensorflow-lite/Config.in
 create mode 100644 package/tensorflow-lite/tensorflow-lite.hash
 create mode 100644 package/tensorflow-lite/tensorflow-lite.mk

Comments

Hager Stefan Dec. 16, 2022, 5:18 p.m. UTC | #1
Tested-by: Stefan Hager <stefan.hager@ginzinger.com>
Acked-by: Stefan Hager <stefan.hager@ginzinger.com>


From: James Hilliard <james.hilliard1@gmail.com>
Sent: Monday, November 28, 2022 18:58
To: buildroot@buildroot.org <buildroot@buildroot.org>
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>; Fabrice Fontaine <fontaine.fabrice@gmail.com>; Samuel Martin <s.martin49@gmail.com>; Hager Stefan <Stefan.Hager@ginzinger.com>; James Hilliard <james.hilliard1@gmail.com>
Subject: [PATCH v2 8/8] package/tensorflow-lite: new package 
 
From: Stefan Hager <stefan.hager@ginzinger.com>

This package adds the tensorflow lite runtime to buildroot.

Signed-off-by: Stefan Hager <stefan.hager@ginzinger.com>
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
Changes v1 -> v2:
  - fix label_image build
  - more explicit cmake config
---
 package/Config.in                             |  1 +
 .../0001-lite-Update-CMakeLists.txt.patch     | 49 +++++++++++++++++++
 .../0002-Fix-FindFlatBuffers-cmake-file.patch | 37 ++++++++++++++
 ...ink-tensorflow-lite-against-gemmlowp.patch | 32 ++++++++++++
 package/tensorflow-lite/Config.in             | 32 ++++++++++++
 package/tensorflow-lite/tensorflow-lite.hash  |  4 ++
 package/tensorflow-lite/tensorflow-lite.mk    | 49 +++++++++++++++++++
 7 files changed, 204 insertions(+)
 create mode 100644 package/tensorflow-lite/0001-lite-Update-CMakeLists.txt.patch
 create mode 100644 package/tensorflow-lite/0002-Fix-FindFlatBuffers-cmake-file.patch
 create mode 100644 package/tensorflow-lite/0003-Don-t-link-tensorflow-lite-against-gemmlowp.patch
 create mode 100644 package/tensorflow-lite/Config.in
 create mode 100644 package/tensorflow-lite/tensorflow-lite.hash
 create mode 100644 package/tensorflow-lite/tensorflow-lite.mk

diff --git a/package/Config.in b/package/Config.in
index a59d074430..c979710f32 100644
--- a/package/Config.in
+++ b/package/Config.in
@@ -2105,6 +2105,7 @@ endif
         source "package/sphinxbase/Config.in"
         source "package/startup-notification/Config.in"
         source "package/tbb/Config.in"
+       source "package/tensorflow-lite/Config.in"
         source "package/tinycbor/Config.in"
         source "package/tz/Config.in"
         source "package/tzdata/Config.in"
diff --git a/package/tensorflow-lite/0001-lite-Update-CMakeLists.txt.patch b/package/tensorflow-lite/0001-lite-Update-CMakeLists.txt.patch
new file mode 100644
index 0000000000..53b5170681
--- /dev/null
+++ b/package/tensorflow-lite/0001-lite-Update-CMakeLists.txt.patch
@@ -0,0 +1,49 @@
+From 081c2e4e3cf021efb2853a485a18b563e88f6117 Mon Sep 17 00:00:00 2001
+From: Terry Heo <terryheo@google.com>
+Date: Tue, 1 Nov 2022 15:55:30 -0700
+Subject: [PATCH] lite: Update CMakeLists.txt
+
+This changes are needed to build kernel tests.
+
+PiperOrigin-RevId: 485439972
+
+Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
+[james.hilliard1@gmail.com: backport from upstream commit
+081c2e4e3cf021efb2853a485a18b563e88f6117]
+---
+ tensorflow/lite/CMakeLists.txt | 7 ++++++-
+ 1 file changed, 6 insertions(+), 1 deletion(-)
+
+diff --git a/tensorflow/lite/CMakeLists.txt b/tensorflow/lite/CMakeLists.txt
+index 9dfbb4b72f3..fd8b3faf1e2 100644
+--- a/tensorflow/lite/CMakeLists.txt
++++ b/tensorflow/lite/CMakeLists.txt
+@@ -209,6 +209,9 @@ list(FILTER TFLITE_SRCS EXCLUDE REGEX ".*tflite_with_xnnpack\\.cc$")
+ # Exclude Flex related files.
+ list(FILTER TFLITE_SRCS EXCLUDE REGEX ".*with_selected_ops\\.cc$")
+ 
++# Exclude tensorflow_profiler_logger files.
++list(FILTER TFLITE_SRCS EXCLUDE REGEX ".*tensorflow_profiler_logger\\.cc$")
++
+ if(_TFLITE_ENABLE_MMAP)
+   list(FILTER TFLITE_SRCS EXCLUDE REGEX ".*mmap_allocation_disabled\\.cc$")
+ else()
+@@ -222,6 +225,7 @@ if(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "iOS")
+ endif()
+ populate_tflite_source_vars("core" TFLITE_CORE_SRCS)
+ populate_tflite_source_vars("core/api" TFLITE_CORE_API_SRCS)
++populate_tflite_source_vars("core/c" TFLITE_CORE_C_SRCS)
+ populate_tflite_source_vars("c" TFLITE_C_SRCS)
+ populate_tflite_source_vars("delegates" TFLITE_DELEGATES_SRCS)
+ if(TFLITE_ENABLE_GPU)
+@@ -483,6 +487,7 @@ endif()
+ # TFLite library
+ set(_ALL_TFLITE_SRCS
+   ${TFLITE_CORE_API_SRCS}
++  ${TFLITE_CORE_C_SRCS}
+   ${TFLITE_CORE_SRCS}
+   ${TFLITE_C_SRCS}
+   ${TFLITE_DELEGATES_FLEX_SRCS}
+-- 
+2.34.1
+
diff --git a/package/tensorflow-lite/0002-Fix-FindFlatBuffers-cmake-file.patch b/package/tensorflow-lite/0002-Fix-FindFlatBuffers-cmake-file.patch
new file mode 100644
index 0000000000..e97bb3e52f
--- /dev/null
+++ b/package/tensorflow-lite/0002-Fix-FindFlatBuffers-cmake-file.patch
@@ -0,0 +1,37 @@
+From a4ff4b5e952a22906ac0ed01e73f84f42926c325 Mon Sep 17 00:00:00 2001
+From: James Hilliard <james.hilliard1@gmail.com>
+Date: Thu, 24 Nov 2022 14:29:06 -0700
+Subject: [PATCH] Fix FindFlatBuffers cmake file
+
+Capitalization needs to match for system cmake override to work:
+https://github.com/google/flatbuffers/blob/v22.11.23/CMake/FindFlatBuffers.cmake
+
+Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
+[Upstream status:
+https://github.com/tensorflow/tensorflow/pull/58677]
+---
+ tensorflow/lite/CMakeLists.txt                                  | 2 +-
+ .../modules/{FindFlatbuffers.cmake => FindFlatBuffers.cmake}    | 0
+ 2 files changed, 1 insertion(+), 1 deletion(-)
+ rename tensorflow/lite/tools/cmake/modules/{FindFlatbuffers.cmake => FindFlatBuffers.cmake} (100%)
+
+diff --git a/tensorflow/lite/CMakeLists.txt b/tensorflow/lite/CMakeLists.txt
+index f9c30d6a046..c2ee9edfb61 100644
+--- a/tensorflow/lite/CMakeLists.txt
++++ b/tensorflow/lite/CMakeLists.txt
+@@ -143,7 +143,7 @@ find_package(absl REQUIRED)
+ find_package(Eigen3 REQUIRED)
+ find_package(farmhash REQUIRED)
+ find_package(fft2d REQUIRED)
+-find_package(Flatbuffers REQUIRED)
++find_package(FlatBuffers REQUIRED)
+ find_package(gemmlowp REQUIRED)
+ find_package(NEON_2_SSE REQUIRED)
+ find_package(cpuinfo REQUIRED)  #CPUINFO is used by XNNPACK and RUY library
+diff --git a/tensorflow/lite/tools/cmake/modules/FindFlatbuffers.cmake b/tensorflow/lite/tools/cmake/modules/FindFlatBuffers.cmake
+similarity index 100%
+rename from tensorflow/lite/tools/cmake/modules/FindFlatbuffers.cmake
+rename to tensorflow/lite/tools/cmake/modules/FindFlatBuffers.cmake
+-- 
+2.34.1
+
diff --git a/package/tensorflow-lite/0003-Don-t-link-tensorflow-lite-against-gemmlowp.patch b/package/tensorflow-lite/0003-Don-t-link-tensorflow-lite-against-gemmlowp.patch
new file mode 100644
index 0000000000..dbee9942b3
--- /dev/null
+++ b/package/tensorflow-lite/0003-Don-t-link-tensorflow-lite-against-gemmlowp.patch
@@ -0,0 +1,32 @@
+From fb584589f707853d85a081c99b1b82598c2631c1 Mon Sep 17 00:00:00 2001
+From: James Hilliard <james.hilliard1@gmail.com>
+Date: Thu, 24 Nov 2022 15:10:27 -0700
+Subject: [PATCH] Don't link tensorflow-lite against gemmlowp
+
+We can't link against gemmlowp as it is a header only library.
+
+Fixes:
+/bin/ld: cannot find -lgemmlowp: No such file or directory
+
+Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
+[Upstream status:
+https://github.com/tensorflow/tensorflow/pull/58678]
+---
+ tensorflow/lite/CMakeLists.txt | 1 -
+ 1 file changed, 1 deletion(-)
+
+diff --git a/tensorflow/lite/CMakeLists.txt b/tensorflow/lite/CMakeLists.txt
+index f9c30d6a046..3fe5ed15605 100644
+--- a/tensorflow/lite/CMakeLists.txt
++++ b/tensorflow/lite/CMakeLists.txt
+@@ -560,7 +560,6 @@ target_link_libraries(tensorflow-lite
+     farmhash
+     fft2d_fftsg2d
+     flatbuffers::flatbuffers
+-    gemmlowp
+     ruy::ruy
+     pthreadpool
+     ${CMAKE_DL_LIBS}
+-- 
+2.34.1
+
diff --git a/package/tensorflow-lite/Config.in b/package/tensorflow-lite/Config.in
new file mode 100644
index 0000000000..9231d674bd
--- /dev/null
+++ b/package/tensorflow-lite/Config.in
@@ -0,0 +1,32 @@
+config BR2_PACKAGE_TENSORFLOW_LITE
+       bool "tensorflow-lite"
+       depends on BR2_TOOLCHAIN_GCC_AT_LEAST_9
+       depends on BR2_TOOLCHAIN_USES_GLIBC
+       depends on BR2_INSTALL_LIBSTDCPP
+       depends on BR2_TOOLCHAIN_HAS_THREADS
+       depends on BR2_SHARED_LIBS
+       depends on ( BR2_arm && BR2_ARM_CPU_ARMV7A ) || ( BR2_aarch64 && BR2_ARM_CPU_ARMV8A )
+       select BR2_PACKAGE_CPUINFO
+       select BR2_PACKAGE_EIGEN
+       select BR2_PACKAGE_FARMHASH
+       select BR2_PACKAGE_FFT2D
+       select BR2_PACKAGE_FLATBUFFERS
+       select BR2_PACKAGE_GEMMLOWP
+       select BR2_PACKAGE_LIBABSEIL_CPP
+       select BR2_PACKAGE_NEON_2_SSE
+       select BR2_PACKAGE_RUY
+       help
+         Tensorflow Lite dynamic library and headers: Inference engine to run previously trained machine learning models.
+
+comment "tensorflow-lite needs needs a toolchain w/ gcc >= 9"
+       depends on !BR2_TOOLCHAIN_GCC_AT_LEAST_9
+
+comment "tensorflow-lite needs a toolchain w/ glibc, C++, threads"
+       depends on !BR2_TOOLCHAIN_USES_GLIBC || !BR2_INSTALL_LIBSTDCPP || \
+                       !BR2_TOOLCHAIN_HAS_THREADS
+
+comment "tensorflow-lite needs a toolchain w/ shared libraries"
+       depends on !BR2_SHARED_LIBS
+
+comment "tensorflow-lite in buildroot currently only supports arm + armv7a cpu or arm64 + armv8a cpu targets"
+       depends on ( BR2_arm && !BR2_ARM_CPU_ARMV7A ) || ( BR2_aarch64 && !BR2_ARM_CPU_ARMV8A) || (!BR2_arm && !BR2_aarch64)
diff --git a/package/tensorflow-lite/tensorflow-lite.hash b/package/tensorflow-lite/tensorflow-lite.hash
new file mode 100644
index 0000000000..7d9035707b
--- /dev/null
+++ b/package/tensorflow-lite/tensorflow-lite.hash
@@ -0,0 +1,4 @@
+# Locally calculated
+sha256  99c732b92b1b37fc243a559e02f9aef5671771e272758aa4aec7f34dc92dac48  tensorflow-lite-2.11.0.tar.gz
+# License files, locally calculated
+sha256  71c6915d04265772a0339bed47276942c678b45cc01534210ebe6984fd1aec65  LICENSE
diff --git a/package/tensorflow-lite/tensorflow-lite.mk b/package/tensorflow-lite/tensorflow-lite.mk
new file mode 100644
index 0000000000..1f75f3813c
--- /dev/null
+++ b/package/tensorflow-lite/tensorflow-lite.mk
@@ -0,0 +1,49 @@
+################################################################################
+#
+# tensorflow-lite
+#
+################################################################################
+
+TENSORFLOW_LITE_VERSION = 2.11.0
+TENSORFLOW_LITE_SITE =  $(call github,tensorflow,tensorflow,v$(TENSORFLOW_LITE_VERSION))
+TENSORFLOW_LITE_INSTALL_STAGING = YES
+TENSORFLOW_LITE_LICENSE = Apache-2.0
+TENSORFLOW_LITE_LICENSE_FILES = LICENSE
+TENSORFLOW_LITE_SUBDIR = tensorflow/lite
+TENSORFLOW_LITE_SUPPORTS_IN_SOURCE_BUILD = NO
+TENSORFLOW_LITE_DEPENDENCIES += \
+       host-pkgconf \
+       host-flatbuffers \
+       cpuinfo \
+       eigen \
+       farmhash \
+       fft2d \
+       flatbuffers \
+       gemmlowp \
+       libabseil-cpp \
+       neon-2-sse \
+       ruy
+
+TENSORFLOW_LITE_CONF_OPTS = \
+       -Dabsl_DIR=$(STAGING_DIR)/usr/lib/cmake/absl \
+       -DBUILD_SHARED_LIBS=ON \
+       -DCMAKE_CXX_FLAGS="$(TARGET_CXXFLAGS) -I$(STAGING_DIR)/usr/include/gemmlowp" \
+       -DCMAKE_FIND_PACKAGE_PREFER_CONFIG=ON \
+       -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
+       -DEigen3_DIR=$(STAGING_DIR)/usr/share/eigen3/cmake \
+       -DFARMHASH_SOURCE_DIR=$(FARMHASH_DIR) \
+       -Dfarmhash_DIR=$(STAGING_DIR)/usr/lib \
+       -DFETCHCONTENT_FULLY_DISCONNECTED=ON \
+       -DFETCHCONTENT_QUIET=OFF \
+       -DFFT2D_SOURCE_DIR=$(STAGING_DIR)/usr/include/fft2d \
+       -DFlatBuffers_DIR=$(STAGING_DIR)/usr/lib/cmake/flatbuffers \
+       -DNEON_2_SSE_DIR=$(STAGING_DIR)/usr/lib/cmake/NEON_2_SSE \
+       -DTFLITE_ENABLE_EXTERNAL_DELEGATE=ON \
+       -DTFLITE_ENABLE_GPU=OFF \
+       -DTFLITE_ENABLE_INSTALL=ON \
+       -DTFLITE_ENABLE_MMAP=ON \
+       -DTFLITE_ENABLE_NNAPI=ON \
+       -DTFLITE_ENABLE_RUY=ON \
+       -DTFLITE_ENABLE_XNNPACK=OFF
+
+$(eval $(cmake-package))
Gilles Talis Jan. 10, 2023, 12:48 p.m. UTC | #2
Hi James, Hi Stefan,

fyi, I could build and successfully test tensorflow lite on an aarch64
platform with Cortex A53 cores.
a few comments though.

Le lun. 28 nov. 2022 à 19:00, James Hilliard
<james.hilliard1@gmail.com> a écrit :
>
> From: Stefan Hager <stefan.hager@ginzinger.com>
>
> This package adds the tensorflow lite runtime to buildroot.
>
> Signed-off-by: Stefan Hager <stefan.hager@ginzinger.com>
> Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> ---
> Changes v1 -> v2:
>   - fix label_image build
>   - more explicit cmake config
> ---
>  package/Config.in                             |  1 +
If you want to be maintainers for this package, do not forget to
update the DEVELOPERS file.

>  .../0001-lite-Update-CMakeLists.txt.patch     | 49 +++++++++++++++++++
>  .../0002-Fix-FindFlatBuffers-cmake-file.patch | 37 ++++++++++++++
>  ...ink-tensorflow-lite-against-gemmlowp.patch | 32 ++++++++++++
>  package/tensorflow-lite/Config.in             | 32 ++++++++++++
>  package/tensorflow-lite/tensorflow-lite.hash  |  4 ++
>  package/tensorflow-lite/tensorflow-lite.mk    | 49 +++++++++++++++++++
>  7 files changed, 204 insertions(+)
>  create mode 100644 package/tensorflow-lite/0001-lite-Update-CMakeLists.txt.patch
>  create mode 100644 package/tensorflow-lite/0002-Fix-FindFlatBuffers-cmake-file.patch
>  create mode 100644 package/tensorflow-lite/0003-Don-t-link-tensorflow-lite-against-gemmlowp.patch
>  create mode 100644 package/tensorflow-lite/Config.in
>  create mode 100644 package/tensorflow-lite/tensorflow-lite.hash
>  create mode 100644 package/tensorflow-lite/tensorflow-lite.mk
>
> diff --git a/package/Config.in b/package/Config.in
> index a59d074430..c979710f32 100644
> --- a/package/Config.in
> +++ b/package/Config.in
> @@ -2105,6 +2105,7 @@ endif
>         source "package/sphinxbase/Config.in"
>         source "package/startup-notification/Config.in"
>         source "package/tbb/Config.in"
> +       source "package/tensorflow-lite/Config.in"
>         source "package/tinycbor/Config.in"
>         source "package/tz/Config.in"
>         source "package/tzdata/Config.in"
> diff --git a/package/tensorflow-lite/0001-lite-Update-CMakeLists.txt.patch b/package/tensorflow-lite/0001-lite-Update-CMakeLists.txt.patch
> new file mode 100644
> index 0000000000..53b5170681
> --- /dev/null
> +++ b/package/tensorflow-lite/0001-lite-Update-CMakeLists.txt.patch
> @@ -0,0 +1,49 @@
> +From 081c2e4e3cf021efb2853a485a18b563e88f6117 Mon Sep 17 00:00:00 2001
> +From: Terry Heo <terryheo@google.com>
> +Date: Tue, 1 Nov 2022 15:55:30 -0700
> +Subject: [PATCH] lite: Update CMakeLists.txt
> +
> +This changes are needed to build kernel tests.
> +
> +PiperOrigin-RevId: 485439972
> +
> +Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> +[james.hilliard1@gmail.com: backport from upstream commit
> +081c2e4e3cf021efb2853a485a18b563e88f6117]
> +---
> + tensorflow/lite/CMakeLists.txt | 7 ++++++-
> + 1 file changed, 6 insertions(+), 1 deletion(-)
> +
> +diff --git a/tensorflow/lite/CMakeLists.txt b/tensorflow/lite/CMakeLists.txt
> +index 9dfbb4b72f3..fd8b3faf1e2 100644
> +--- a/tensorflow/lite/CMakeLists.txt
> ++++ b/tensorflow/lite/CMakeLists.txt
> +@@ -209,6 +209,9 @@ list(FILTER TFLITE_SRCS EXCLUDE REGEX ".*tflite_with_xnnpack\\.cc$")
> + # Exclude Flex related files.
> + list(FILTER TFLITE_SRCS EXCLUDE REGEX ".*with_selected_ops\\.cc$")
> +
> ++# Exclude tensorflow_profiler_logger files.
> ++list(FILTER TFLITE_SRCS EXCLUDE REGEX ".*tensorflow_profiler_logger\\.cc$")
> ++
> + if(_TFLITE_ENABLE_MMAP)
> +   list(FILTER TFLITE_SRCS EXCLUDE REGEX ".*mmap_allocation_disabled\\.cc$")
> + else()
> +@@ -222,6 +225,7 @@ if(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "iOS")
> + endif()
> + populate_tflite_source_vars("core" TFLITE_CORE_SRCS)
> + populate_tflite_source_vars("core/api" TFLITE_CORE_API_SRCS)
> ++populate_tflite_source_vars("core/c" TFLITE_CORE_C_SRCS)
> + populate_tflite_source_vars("c" TFLITE_C_SRCS)
> + populate_tflite_source_vars("delegates" TFLITE_DELEGATES_SRCS)
> + if(TFLITE_ENABLE_GPU)
> +@@ -483,6 +487,7 @@ endif()
> + # TFLite library
> + set(_ALL_TFLITE_SRCS
> +   ${TFLITE_CORE_API_SRCS}
> ++  ${TFLITE_CORE_C_SRCS}
> +   ${TFLITE_CORE_SRCS}
> +   ${TFLITE_C_SRCS}
> +   ${TFLITE_DELEGATES_FLEX_SRCS}
> +--
> +2.34.1
> +
> diff --git a/package/tensorflow-lite/0002-Fix-FindFlatBuffers-cmake-file.patch b/package/tensorflow-lite/0002-Fix-FindFlatBuffers-cmake-file.patch
> new file mode 100644
> index 0000000000..e97bb3e52f
> --- /dev/null
> +++ b/package/tensorflow-lite/0002-Fix-FindFlatBuffers-cmake-file.patch
> @@ -0,0 +1,37 @@
> +From a4ff4b5e952a22906ac0ed01e73f84f42926c325 Mon Sep 17 00:00:00 2001
> +From: James Hilliard <james.hilliard1@gmail.com>
> +Date: Thu, 24 Nov 2022 14:29:06 -0700
> +Subject: [PATCH] Fix FindFlatBuffers cmake file
> +
> +Capitalization needs to match for system cmake override to work:
> +https://github.com/google/flatbuffers/blob/v22.11.23/CMake/FindFlatBuffers.cmake
> +
> +Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> +[Upstream status:
> +https://github.com/tensorflow/tensorflow/pull/58677]
> +---
> + tensorflow/lite/CMakeLists.txt                                  | 2 +-
> + .../modules/{FindFlatbuffers.cmake => FindFlatBuffers.cmake}    | 0
> + 2 files changed, 1 insertion(+), 1 deletion(-)
> + rename tensorflow/lite/tools/cmake/modules/{FindFlatbuffers.cmake => FindFlatBuffers.cmake} (100%)
> +
> +diff --git a/tensorflow/lite/CMakeLists.txt b/tensorflow/lite/CMakeLists.txt
> +index f9c30d6a046..c2ee9edfb61 100644
> +--- a/tensorflow/lite/CMakeLists.txt
> ++++ b/tensorflow/lite/CMakeLists.txt
> +@@ -143,7 +143,7 @@ find_package(absl REQUIRED)
> + find_package(Eigen3 REQUIRED)
> + find_package(farmhash REQUIRED)
> + find_package(fft2d REQUIRED)
> +-find_package(Flatbuffers REQUIRED)
> ++find_package(FlatBuffers REQUIRED)
> + find_package(gemmlowp REQUIRED)
> + find_package(NEON_2_SSE REQUIRED)
> + find_package(cpuinfo REQUIRED)  #CPUINFO is used by XNNPACK and RUY library
> +diff --git a/tensorflow/lite/tools/cmake/modules/FindFlatbuffers.cmake b/tensorflow/lite/tools/cmake/modules/FindFlatBuffers.cmake
> +similarity index 100%
> +rename from tensorflow/lite/tools/cmake/modules/FindFlatbuffers.cmake
> +rename to tensorflow/lite/tools/cmake/modules/FindFlatBuffers.cmake
> +--
> +2.34.1
> +
> diff --git a/package/tensorflow-lite/0003-Don-t-link-tensorflow-lite-against-gemmlowp.patch b/package/tensorflow-lite/0003-Don-t-link-tensorflow-lite-against-gemmlowp.patch
> new file mode 100644
> index 0000000000..dbee9942b3
> --- /dev/null
> +++ b/package/tensorflow-lite/0003-Don-t-link-tensorflow-lite-against-gemmlowp.patch
> @@ -0,0 +1,32 @@
> +From fb584589f707853d85a081c99b1b82598c2631c1 Mon Sep 17 00:00:00 2001
> +From: James Hilliard <james.hilliard1@gmail.com>
> +Date: Thu, 24 Nov 2022 15:10:27 -0700
> +Subject: [PATCH] Don't link tensorflow-lite against gemmlowp
> +
> +We can't link against gemmlowp as it is a header only library.
> +
> +Fixes:
> +/bin/ld: cannot find -lgemmlowp: No such file or directory
> +
> +Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> +[Upstream status:
> +https://github.com/tensorflow/tensorflow/pull/58678]
> +---
> + tensorflow/lite/CMakeLists.txt | 1 -
> + 1 file changed, 1 deletion(-)
> +
> +diff --git a/tensorflow/lite/CMakeLists.txt b/tensorflow/lite/CMakeLists.txt
> +index f9c30d6a046..3fe5ed15605 100644
> +--- a/tensorflow/lite/CMakeLists.txt
> ++++ b/tensorflow/lite/CMakeLists.txt
> +@@ -560,7 +560,6 @@ target_link_libraries(tensorflow-lite
> +     farmhash
> +     fft2d_fftsg2d
> +     flatbuffers::flatbuffers
> +-    gemmlowp
> +     ruy::ruy
> +     pthreadpool
> +     ${CMAKE_DL_LIBS}
> +--
> +2.34.1
> +
> diff --git a/package/tensorflow-lite/Config.in b/package/tensorflow-lite/Config.in
> new file mode 100644
> index 0000000000..9231d674bd
> --- /dev/null
> +++ b/package/tensorflow-lite/Config.in
> @@ -0,0 +1,32 @@
> +config BR2_PACKAGE_TENSORFLOW_LITE
> +       bool "tensorflow-lite"
> +       depends on BR2_TOOLCHAIN_GCC_AT_LEAST_9
Can you please add to comment that explains why this version of GCC is needed?

> +       depends on BR2_TOOLCHAIN_USES_GLIBC
> +       depends on BR2_INSTALL_LIBSTDCPP
> +       depends on BR2_TOOLCHAIN_HAS_THREADS
> +       depends on BR2_SHARED_LIBS
> +       depends on ( BR2_arm && BR2_ARM_CPU_ARMV7A ) || ( BR2_aarch64 && BR2_ARM_CPU_ARMV8A )
> +       select BR2_PACKAGE_CPUINFO
> +       select BR2_PACKAGE_EIGEN
> +       select BR2_PACKAGE_FARMHASH
> +       select BR2_PACKAGE_FFT2D
> +       select BR2_PACKAGE_FLATBUFFERS
> +       select BR2_PACKAGE_GEMMLOWP
> +       select BR2_PACKAGE_LIBABSEIL_CPP
> +       select BR2_PACKAGE_NEON_2_SSE
> +       select BR2_PACKAGE_RUY
> +       help
> +         Tensorflow Lite dynamic library and headers: Inference engine to run previously trained machine learning models.
The text is too long. Please run "utils/check-package" to see the
warning that it generates.

A couple of suggestions:
1) would it be possible to add an option to build and install the
label_image example? It is always handy to be able to test this
package once it is built.
2) would it be possible to add an option to build and install the
benchmark_model tool? This tool provides useful performance
information.

> +
> +comment "tensorflow-lite needs needs a toolchain w/ gcc >= 9"
> +       depends on !BR2_TOOLCHAIN_GCC_AT_LEAST_9
> +
> +comment "tensorflow-lite needs a toolchain w/ glibc, C++, threads"
> +       depends on !BR2_TOOLCHAIN_USES_GLIBC || !BR2_INSTALL_LIBSTDCPP || \
> +                       !BR2_TOOLCHAIN_HAS_THREADS
> +
> +comment "tensorflow-lite needs a toolchain w/ shared libraries"
> +       depends on !BR2_SHARED_LIBS
> +
> +comment "tensorflow-lite in buildroot currently only supports arm + armv7a cpu or arm64 + armv8a cpu targets"
> +       depends on ( BR2_arm && !BR2_ARM_CPU_ARMV7A ) || ( BR2_aarch64 && !BR2_ARM_CPU_ARMV8A) || (!BR2_arm && !BR2_aarch64)
> diff --git a/package/tensorflow-lite/tensorflow-lite.hash b/package/tensorflow-lite/tensorflow-lite.hash
> new file mode 100644
> index 0000000000..7d9035707b
> --- /dev/null
> +++ b/package/tensorflow-lite/tensorflow-lite.hash
> @@ -0,0 +1,4 @@
> +# Locally calculated
> +sha256  99c732b92b1b37fc243a559e02f9aef5671771e272758aa4aec7f34dc92dac48  tensorflow-lite-2.11.0.tar.gz
> +# License files, locally calculated
> +sha256  71c6915d04265772a0339bed47276942c678b45cc01534210ebe6984fd1aec65  LICENSE
> diff --git a/package/tensorflow-lite/tensorflow-lite.mk b/package/tensorflow-lite/tensorflow-lite.mk
> new file mode 100644
> index 0000000000..1f75f3813c
> --- /dev/null
> +++ b/package/tensorflow-lite/tensorflow-lite.mk
> @@ -0,0 +1,49 @@
> +################################################################################
> +#
> +# tensorflow-lite
> +#
> +################################################################################
> +
> +TENSORFLOW_LITE_VERSION = 2.11.0
> +TENSORFLOW_LITE_SITE =  $(call github,tensorflow,tensorflow,v$(TENSORFLOW_LITE_VERSION))
> +TENSORFLOW_LITE_INSTALL_STAGING = YES
> +TENSORFLOW_LITE_LICENSE = Apache-2.0
> +TENSORFLOW_LITE_LICENSE_FILES = LICENSE
> +TENSORFLOW_LITE_SUBDIR = tensorflow/lite
> +TENSORFLOW_LITE_SUPPORTS_IN_SOURCE_BUILD = NO
> +TENSORFLOW_LITE_DEPENDENCIES += \
> +       host-pkgconf \
> +       host-flatbuffers \
> +       cpuinfo \
> +       eigen \
> +       farmhash \
> +       fft2d \
> +       flatbuffers \
> +       gemmlowp \
> +       libabseil-cpp \
> +       neon-2-sse \
> +       ruy
> +
> +TENSORFLOW_LITE_CONF_OPTS = \
> +       -Dabsl_DIR=$(STAGING_DIR)/usr/lib/cmake/absl \
> +       -DBUILD_SHARED_LIBS=ON \
> +       -DCMAKE_CXX_FLAGS="$(TARGET_CXXFLAGS) -I$(STAGING_DIR)/usr/include/gemmlowp" \
> +       -DCMAKE_FIND_PACKAGE_PREFER_CONFIG=ON \
> +       -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
> +       -DEigen3_DIR=$(STAGING_DIR)/usr/share/eigen3/cmake \
> +       -DFARMHASH_SOURCE_DIR=$(FARMHASH_DIR) \
> +       -Dfarmhash_DIR=$(STAGING_DIR)/usr/lib \
> +       -DFETCHCONTENT_FULLY_DISCONNECTED=ON \
> +       -DFETCHCONTENT_QUIET=OFF \
> +       -DFFT2D_SOURCE_DIR=$(STAGING_DIR)/usr/include/fft2d \
> +       -DFlatBuffers_DIR=$(STAGING_DIR)/usr/lib/cmake/flatbuffers \
> +       -DNEON_2_SSE_DIR=$(STAGING_DIR)/usr/lib/cmake/NEON_2_SSE \
> +       -DTFLITE_ENABLE_EXTERNAL_DELEGATE=ON \
> +       -DTFLITE_ENABLE_GPU=OFF \
> +       -DTFLITE_ENABLE_INSTALL=ON \
> +       -DTFLITE_ENABLE_MMAP=ON \
> +       -DTFLITE_ENABLE_NNAPI=ON \
I thought NNAPI was used in Android. Can you explain why it is required here?

> +       -DTFLITE_ENABLE_RUY=ON \
> +       -DTFLITE_ENABLE_XNNPACK=OFF
any reason why xnnpack is not enabled? It would be great to enable it
as an option.

> +
> +$(eval $(cmake-package))
> --
> 2.34.1
>
> _______________________________________________
> buildroot mailing list
> buildroot@buildroot.org
> https://lists.buildroot.org/mailman/listinfo/buildroot
thanks
Gilles.
James Hilliard Jan. 24, 2023, 9:27 a.m. UTC | #3
On Tue, Jan 10, 2023 at 5:49 AM Gilles Talis <gilles.talis@gmail.com> wrote:
>
> Hi James, Hi Stefan,
>
> fyi, I could build and successfully test tensorflow lite on an aarch64
> platform with Cortex A53 cores.
> a few comments though.
>
> Le lun. 28 nov. 2022 à 19:00, James Hilliard
> <james.hilliard1@gmail.com> a écrit :
> >
> > From: Stefan Hager <stefan.hager@ginzinger.com>
> >
> > This package adds the tensorflow lite runtime to buildroot.
> >
> > Signed-off-by: Stefan Hager <stefan.hager@ginzinger.com>
> > Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> > ---
> > Changes v1 -> v2:
> >   - fix label_image build
> >   - more explicit cmake config
> > ---
> >  package/Config.in                             |  1 +
> If you want to be maintainers for this package, do not forget to
> update the DEVELOPERS file.
>
> >  .../0001-lite-Update-CMakeLists.txt.patch     | 49 +++++++++++++++++++
> >  .../0002-Fix-FindFlatBuffers-cmake-file.patch | 37 ++++++++++++++
> >  ...ink-tensorflow-lite-against-gemmlowp.patch | 32 ++++++++++++
> >  package/tensorflow-lite/Config.in             | 32 ++++++++++++
> >  package/tensorflow-lite/tensorflow-lite.hash  |  4 ++
> >  package/tensorflow-lite/tensorflow-lite.mk    | 49 +++++++++++++++++++
> >  7 files changed, 204 insertions(+)
> >  create mode 100644 package/tensorflow-lite/0001-lite-Update-CMakeLists.txt.patch
> >  create mode 100644 package/tensorflow-lite/0002-Fix-FindFlatBuffers-cmake-file.patch
> >  create mode 100644 package/tensorflow-lite/0003-Don-t-link-tensorflow-lite-against-gemmlowp.patch
> >  create mode 100644 package/tensorflow-lite/Config.in
> >  create mode 100644 package/tensorflow-lite/tensorflow-lite.hash
> >  create mode 100644 package/tensorflow-lite/tensorflow-lite.mk
> >
> > diff --git a/package/Config.in b/package/Config.in
> > index a59d074430..c979710f32 100644
> > --- a/package/Config.in
> > +++ b/package/Config.in
> > @@ -2105,6 +2105,7 @@ endif
> >         source "package/sphinxbase/Config.in"
> >         source "package/startup-notification/Config.in"
> >         source "package/tbb/Config.in"
> > +       source "package/tensorflow-lite/Config.in"
> >         source "package/tinycbor/Config.in"
> >         source "package/tz/Config.in"
> >         source "package/tzdata/Config.in"
> > diff --git a/package/tensorflow-lite/0001-lite-Update-CMakeLists.txt.patch b/package/tensorflow-lite/0001-lite-Update-CMakeLists.txt.patch
> > new file mode 100644
> > index 0000000000..53b5170681
> > --- /dev/null
> > +++ b/package/tensorflow-lite/0001-lite-Update-CMakeLists.txt.patch
> > @@ -0,0 +1,49 @@
> > +From 081c2e4e3cf021efb2853a485a18b563e88f6117 Mon Sep 17 00:00:00 2001
> > +From: Terry Heo <terryheo@google.com>
> > +Date: Tue, 1 Nov 2022 15:55:30 -0700
> > +Subject: [PATCH] lite: Update CMakeLists.txt
> > +
> > +This changes are needed to build kernel tests.
> > +
> > +PiperOrigin-RevId: 485439972
> > +
> > +Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> > +[james.hilliard1@gmail.com: backport from upstream commit
> > +081c2e4e3cf021efb2853a485a18b563e88f6117]
> > +---
> > + tensorflow/lite/CMakeLists.txt | 7 ++++++-
> > + 1 file changed, 6 insertions(+), 1 deletion(-)
> > +
> > +diff --git a/tensorflow/lite/CMakeLists.txt b/tensorflow/lite/CMakeLists.txt
> > +index 9dfbb4b72f3..fd8b3faf1e2 100644
> > +--- a/tensorflow/lite/CMakeLists.txt
> > ++++ b/tensorflow/lite/CMakeLists.txt
> > +@@ -209,6 +209,9 @@ list(FILTER TFLITE_SRCS EXCLUDE REGEX ".*tflite_with_xnnpack\\.cc$")
> > + # Exclude Flex related files.
> > + list(FILTER TFLITE_SRCS EXCLUDE REGEX ".*with_selected_ops\\.cc$")
> > +
> > ++# Exclude tensorflow_profiler_logger files.
> > ++list(FILTER TFLITE_SRCS EXCLUDE REGEX ".*tensorflow_profiler_logger\\.cc$")
> > ++
> > + if(_TFLITE_ENABLE_MMAP)
> > +   list(FILTER TFLITE_SRCS EXCLUDE REGEX ".*mmap_allocation_disabled\\.cc$")
> > + else()
> > +@@ -222,6 +225,7 @@ if(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "iOS")
> > + endif()
> > + populate_tflite_source_vars("core" TFLITE_CORE_SRCS)
> > + populate_tflite_source_vars("core/api" TFLITE_CORE_API_SRCS)
> > ++populate_tflite_source_vars("core/c" TFLITE_CORE_C_SRCS)
> > + populate_tflite_source_vars("c" TFLITE_C_SRCS)
> > + populate_tflite_source_vars("delegates" TFLITE_DELEGATES_SRCS)
> > + if(TFLITE_ENABLE_GPU)
> > +@@ -483,6 +487,7 @@ endif()
> > + # TFLite library
> > + set(_ALL_TFLITE_SRCS
> > +   ${TFLITE_CORE_API_SRCS}
> > ++  ${TFLITE_CORE_C_SRCS}
> > +   ${TFLITE_CORE_SRCS}
> > +   ${TFLITE_C_SRCS}
> > +   ${TFLITE_DELEGATES_FLEX_SRCS}
> > +--
> > +2.34.1
> > +
> > diff --git a/package/tensorflow-lite/0002-Fix-FindFlatBuffers-cmake-file.patch b/package/tensorflow-lite/0002-Fix-FindFlatBuffers-cmake-file.patch
> > new file mode 100644
> > index 0000000000..e97bb3e52f
> > --- /dev/null
> > +++ b/package/tensorflow-lite/0002-Fix-FindFlatBuffers-cmake-file.patch
> > @@ -0,0 +1,37 @@
> > +From a4ff4b5e952a22906ac0ed01e73f84f42926c325 Mon Sep 17 00:00:00 2001
> > +From: James Hilliard <james.hilliard1@gmail.com>
> > +Date: Thu, 24 Nov 2022 14:29:06 -0700
> > +Subject: [PATCH] Fix FindFlatBuffers cmake file
> > +
> > +Capitalization needs to match for system cmake override to work:
> > +https://github.com/google/flatbuffers/blob/v22.11.23/CMake/FindFlatBuffers.cmake
> > +
> > +Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> > +[Upstream status:
> > +https://github.com/tensorflow/tensorflow/pull/58677]
> > +---
> > + tensorflow/lite/CMakeLists.txt                                  | 2 +-
> > + .../modules/{FindFlatbuffers.cmake => FindFlatBuffers.cmake}    | 0
> > + 2 files changed, 1 insertion(+), 1 deletion(-)
> > + rename tensorflow/lite/tools/cmake/modules/{FindFlatbuffers.cmake => FindFlatBuffers.cmake} (100%)
> > +
> > +diff --git a/tensorflow/lite/CMakeLists.txt b/tensorflow/lite/CMakeLists.txt
> > +index f9c30d6a046..c2ee9edfb61 100644
> > +--- a/tensorflow/lite/CMakeLists.txt
> > ++++ b/tensorflow/lite/CMakeLists.txt
> > +@@ -143,7 +143,7 @@ find_package(absl REQUIRED)
> > + find_package(Eigen3 REQUIRED)
> > + find_package(farmhash REQUIRED)
> > + find_package(fft2d REQUIRED)
> > +-find_package(Flatbuffers REQUIRED)
> > ++find_package(FlatBuffers REQUIRED)
> > + find_package(gemmlowp REQUIRED)
> > + find_package(NEON_2_SSE REQUIRED)
> > + find_package(cpuinfo REQUIRED)  #CPUINFO is used by XNNPACK and RUY library
> > +diff --git a/tensorflow/lite/tools/cmake/modules/FindFlatbuffers.cmake b/tensorflow/lite/tools/cmake/modules/FindFlatBuffers.cmake
> > +similarity index 100%
> > +rename from tensorflow/lite/tools/cmake/modules/FindFlatbuffers.cmake
> > +rename to tensorflow/lite/tools/cmake/modules/FindFlatBuffers.cmake
> > +--
> > +2.34.1
> > +
> > diff --git a/package/tensorflow-lite/0003-Don-t-link-tensorflow-lite-against-gemmlowp.patch b/package/tensorflow-lite/0003-Don-t-link-tensorflow-lite-against-gemmlowp.patch
> > new file mode 100644
> > index 0000000000..dbee9942b3
> > --- /dev/null
> > +++ b/package/tensorflow-lite/0003-Don-t-link-tensorflow-lite-against-gemmlowp.patch
> > @@ -0,0 +1,32 @@
> > +From fb584589f707853d85a081c99b1b82598c2631c1 Mon Sep 17 00:00:00 2001
> > +From: James Hilliard <james.hilliard1@gmail.com>
> > +Date: Thu, 24 Nov 2022 15:10:27 -0700
> > +Subject: [PATCH] Don't link tensorflow-lite against gemmlowp
> > +
> > +We can't link against gemmlowp as it is a header only library.
> > +
> > +Fixes:
> > +/bin/ld: cannot find -lgemmlowp: No such file or directory
> > +
> > +Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> > +[Upstream status:
> > +https://github.com/tensorflow/tensorflow/pull/58678]
> > +---
> > + tensorflow/lite/CMakeLists.txt | 1 -
> > + 1 file changed, 1 deletion(-)
> > +
> > +diff --git a/tensorflow/lite/CMakeLists.txt b/tensorflow/lite/CMakeLists.txt
> > +index f9c30d6a046..3fe5ed15605 100644
> > +--- a/tensorflow/lite/CMakeLists.txt
> > ++++ b/tensorflow/lite/CMakeLists.txt
> > +@@ -560,7 +560,6 @@ target_link_libraries(tensorflow-lite
> > +     farmhash
> > +     fft2d_fftsg2d
> > +     flatbuffers::flatbuffers
> > +-    gemmlowp
> > +     ruy::ruy
> > +     pthreadpool
> > +     ${CMAKE_DL_LIBS}
> > +--
> > +2.34.1
> > +
> > diff --git a/package/tensorflow-lite/Config.in b/package/tensorflow-lite/Config.in
> > new file mode 100644
> > index 0000000000..9231d674bd
> > --- /dev/null
> > +++ b/package/tensorflow-lite/Config.in
> > @@ -0,0 +1,32 @@
> > +config BR2_PACKAGE_TENSORFLOW_LITE
> > +       bool "tensorflow-lite"
> > +       depends on BR2_TOOLCHAIN_GCC_AT_LEAST_9
> Can you please add to comment that explains why this version of GCC is needed?

I'm not sure why this is, maybe Stephan Hager can clarify.

>
> > +       depends on BR2_TOOLCHAIN_USES_GLIBC
> > +       depends on BR2_INSTALL_LIBSTDCPP
> > +       depends on BR2_TOOLCHAIN_HAS_THREADS
> > +       depends on BR2_SHARED_LIBS
> > +       depends on ( BR2_arm && BR2_ARM_CPU_ARMV7A ) || ( BR2_aarch64 && BR2_ARM_CPU_ARMV8A )
> > +       select BR2_PACKAGE_CPUINFO
> > +       select BR2_PACKAGE_EIGEN
> > +       select BR2_PACKAGE_FARMHASH
> > +       select BR2_PACKAGE_FFT2D
> > +       select BR2_PACKAGE_FLATBUFFERS
> > +       select BR2_PACKAGE_GEMMLOWP
> > +       select BR2_PACKAGE_LIBABSEIL_CPP
> > +       select BR2_PACKAGE_NEON_2_SSE
> > +       select BR2_PACKAGE_RUY
> > +       help
> > +         Tensorflow Lite dynamic library and headers: Inference engine to run previously trained machine learning models.
> The text is too long. Please run "utils/check-package" to see the
> warning that it generates.

Fixed in v3:
https://patchwork.ozlabs.org/project/buildroot/patch/20230124092235.806969-8-james.hilliard1@gmail.com/

>
> A couple of suggestions:
> 1) would it be possible to add an option to build and install the
> label_image example? It is always handy to be able to test this
> package once it is built.
> 2) would it be possible to add an option to build and install the
> benchmark_model tool? This tool provides useful performance
> information.

Not sure there's really a good way to do this without adding a config
flag upstream.

>
> > +
> > +comment "tensorflow-lite needs needs a toolchain w/ gcc >= 9"
> > +       depends on !BR2_TOOLCHAIN_GCC_AT_LEAST_9
> > +
> > +comment "tensorflow-lite needs a toolchain w/ glibc, C++, threads"
> > +       depends on !BR2_TOOLCHAIN_USES_GLIBC || !BR2_INSTALL_LIBSTDCPP || \
> > +                       !BR2_TOOLCHAIN_HAS_THREADS
> > +
> > +comment "tensorflow-lite needs a toolchain w/ shared libraries"
> > +       depends on !BR2_SHARED_LIBS
> > +
> > +comment "tensorflow-lite in buildroot currently only supports arm + armv7a cpu or arm64 + armv8a cpu targets"
> > +       depends on ( BR2_arm && !BR2_ARM_CPU_ARMV7A ) || ( BR2_aarch64 && !BR2_ARM_CPU_ARMV8A) || (!BR2_arm && !BR2_aarch64)
> > diff --git a/package/tensorflow-lite/tensorflow-lite.hash b/package/tensorflow-lite/tensorflow-lite.hash
> > new file mode 100644
> > index 0000000000..7d9035707b
> > --- /dev/null
> > +++ b/package/tensorflow-lite/tensorflow-lite.hash
> > @@ -0,0 +1,4 @@
> > +# Locally calculated
> > +sha256  99c732b92b1b37fc243a559e02f9aef5671771e272758aa4aec7f34dc92dac48  tensorflow-lite-2.11.0.tar.gz
> > +# License files, locally calculated
> > +sha256  71c6915d04265772a0339bed47276942c678b45cc01534210ebe6984fd1aec65  LICENSE
> > diff --git a/package/tensorflow-lite/tensorflow-lite.mk b/package/tensorflow-lite/tensorflow-lite.mk
> > new file mode 100644
> > index 0000000000..1f75f3813c
> > --- /dev/null
> > +++ b/package/tensorflow-lite/tensorflow-lite.mk
> > @@ -0,0 +1,49 @@
> > +################################################################################
> > +#
> > +# tensorflow-lite
> > +#
> > +################################################################################
> > +
> > +TENSORFLOW_LITE_VERSION = 2.11.0
> > +TENSORFLOW_LITE_SITE =  $(call github,tensorflow,tensorflow,v$(TENSORFLOW_LITE_VERSION))
> > +TENSORFLOW_LITE_INSTALL_STAGING = YES
> > +TENSORFLOW_LITE_LICENSE = Apache-2.0
> > +TENSORFLOW_LITE_LICENSE_FILES = LICENSE
> > +TENSORFLOW_LITE_SUBDIR = tensorflow/lite
> > +TENSORFLOW_LITE_SUPPORTS_IN_SOURCE_BUILD = NO
> > +TENSORFLOW_LITE_DEPENDENCIES += \
> > +       host-pkgconf \
> > +       host-flatbuffers \
> > +       cpuinfo \
> > +       eigen \
> > +       farmhash \
> > +       fft2d \
> > +       flatbuffers \
> > +       gemmlowp \
> > +       libabseil-cpp \
> > +       neon-2-sse \
> > +       ruy
> > +
> > +TENSORFLOW_LITE_CONF_OPTS = \
> > +       -Dabsl_DIR=$(STAGING_DIR)/usr/lib/cmake/absl \
> > +       -DBUILD_SHARED_LIBS=ON \
> > +       -DCMAKE_CXX_FLAGS="$(TARGET_CXXFLAGS) -I$(STAGING_DIR)/usr/include/gemmlowp" \
> > +       -DCMAKE_FIND_PACKAGE_PREFER_CONFIG=ON \
> > +       -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
> > +       -DEigen3_DIR=$(STAGING_DIR)/usr/share/eigen3/cmake \
> > +       -DFARMHASH_SOURCE_DIR=$(FARMHASH_DIR) \
> > +       -Dfarmhash_DIR=$(STAGING_DIR)/usr/lib \
> > +       -DFETCHCONTENT_FULLY_DISCONNECTED=ON \
> > +       -DFETCHCONTENT_QUIET=OFF \
> > +       -DFFT2D_SOURCE_DIR=$(STAGING_DIR)/usr/include/fft2d \
> > +       -DFlatBuffers_DIR=$(STAGING_DIR)/usr/lib/cmake/flatbuffers \
> > +       -DNEON_2_SSE_DIR=$(STAGING_DIR)/usr/lib/cmake/NEON_2_SSE \
> > +       -DTFLITE_ENABLE_EXTERNAL_DELEGATE=ON \
> > +       -DTFLITE_ENABLE_GPU=OFF \
> > +       -DTFLITE_ENABLE_INSTALL=ON \
> > +       -DTFLITE_ENABLE_MMAP=ON \
> > +       -DTFLITE_ENABLE_NNAPI=ON \
> I thought NNAPI was used in Android. Can you explain why it is required here?

Disabled in v3:
https://patchwork.ozlabs.org/project/buildroot/patch/20230124092235.806969-8-james.hilliard1@gmail.com/

>
> > +       -DTFLITE_ENABLE_RUY=ON \
> > +       -DTFLITE_ENABLE_XNNPACK=OFF
> any reason why xnnpack is not enabled? It would be great to enable it
> as an option.

Mostly since it's not a required dependency and haven't added the
dependency yet. Will look into adding that as a followup once this is
merged.

>
> > +
> > +$(eval $(cmake-package))
> > --
> > 2.34.1
> >
> > _______________________________________________
> > buildroot mailing list
> > buildroot@buildroot.org
> > https://lists.buildroot.org/mailman/listinfo/buildroot
> thanks
> Gilles.
Hager Stefan Jan. 26, 2023, 4:36 p.m. UTC | #4
> From: James Hilliard <james.hilliard1@gmail.com>
> Sent: Tuesday, January 24, 2023 10:27
> To: Gilles Talis <gilles.talis@gmail.com>
> Cc: buildroot@buildroot.org <buildroot@buildroot.org>; Hager Stefan <Stefan.Hager@ginzinger.com>; Samuel Martin <s.martin49@gmail.com>; Fabrice Fontaine <fontaine.fabrice@gmail.com>; Thomas Petazzoni <thomas.petazzoni@bootlin.com>
> Subject: Re: [Buildroot] [PATCH v2 8/8] package/tensorflow-lite: new package
> 
> On Tue, Jan 10, 2023 at 5:49 AM Gilles Talis <gilles.talis@gmail.com> wrote:
> >
> > Hi James, Hi Stefan,
> >
> > fyi, I could build and successfully test tensorflow lite on an aarch64
> > platform with Cortex A53 cores.
> > a few comments though.
> >
> > Le lun. 28 nov. 2022 à 19:00, James Hilliard
> > <james.hilliard1@gmail.com> a écrit :
> > >
> > > From: Stefan Hager <stefan.hager@ginzinger.com>
> > >
> > > This package adds the tensorflow lite runtime to buildroot.
> > >
> > > Signed-off-by: Stefan Hager <stefan.hager@ginzinger.com>
> > > Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> > > ---
> > > Changes v1 -> v2:
> > >   - fix label_image build
> > >   - more explicit cmake config
> > > ---
> > >  package/Config.in                             |  1 +
> > If you want to be maintainers for this package, do not forget to
> > update the DEVELOPERS file.
> >
> > >  .../0001-lite-Update-CMakeLists.txt.patch     | 49 +++++++++++++++++++
> > >  .../0002-Fix-FindFlatBuffers-cmake-file.patch | 37 ++++++++++++++
> > >  ...ink-tensorflow-lite-against-gemmlowp.patch | 32 ++++++++++++
> > >  package/tensorflow-lite/Config.in             | 32 ++++++++++++
> > >  package/tensorflow-lite/tensorflow-lite.hash  |  4 ++
> > >  package/tensorflow-lite/tensorflow-lite.mk    | 49 +++++++++++++++++++
> > >  7 files changed, 204 insertions(+)
> > >  create mode 100644 package/tensorflow-lite/0001-lite-Update-CMakeLists.txt.patch
> > >  create mode 100644 package/tensorflow-lite/0002-Fix-FindFlatBuffers-cmake-file.patch
> > >  create mode 100644 package/tensorflow-lite/0003-Don-t-link-tensorflow-lite-against-gemmlowp.patch
> > >  create mode 100644 package/tensorflow-lite/Config.in
> > >  create mode 100644 package/tensorflow-lite/tensorflow-lite.hash
> > >  create mode 100644 package/tensorflow-lite/tensorflow-lite.mk
> > >
> > > diff --git a/package/Config.in b/package/Config.in
> > > index a59d074430..c979710f32 100644
> > > --- a/package/Config.in
> > > +++ b/package/Config.in
> > > @@ -2105,6 +2105,7 @@ endif
> > >         source "package/sphinxbase/Config.in"
> > >         source "package/startup-notification/Config.in"
> > >         source "package/tbb/Config.in"
> > > +       source "package/tensorflow-lite/Config.in"
> > >         source "package/tinycbor/Config.in"
> > >         source "package/tz/Config.in"
> > >         source "package/tzdata/Config.in"
> > > diff --git a/package/tensorflow-lite/0001-lite-Update-CMakeLists.txt.patch b/package/tensorflow-lite/0001-lite-Update-CMakeLists.txt.patch
> > > new file mode 100644
> > > index 0000000000..53b5170681
> > > --- /dev/null
> > > +++ b/package/tensorflow-lite/0001-lite-Update-CMakeLists.txt.patch
> > > @@ -0,0 +1,49 @@
> > > +From 081c2e4e3cf021efb2853a485a18b563e88f6117 Mon Sep 17 00:00:00 2001
> > > +From: Terry Heo <terryheo@google.com>
> > > +Date: Tue, 1 Nov 2022 15:55:30 -0700
> > > +Subject: [PATCH] lite: Update CMakeLists.txt
> > > +
> > > +This changes are needed to build kernel tests.
> > > +
> > > +PiperOrigin-RevId: 485439972
> > > +
> > > +Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> > > +[james.hilliard1@gmail.com: backport from upstream commit
> > > +081c2e4e3cf021efb2853a485a18b563e88f6117]
> > > +---
> > > + tensorflow/lite/CMakeLists.txt | 7 ++++++-
> > > + 1 file changed, 6 insertions(+), 1 deletion(-)
> > > +
> > > +diff --git a/tensorflow/lite/CMakeLists.txt b/tensorflow/lite/CMakeLists.txt
> > > +index 9dfbb4b72f3..fd8b3faf1e2 100644
> > > +--- a/tensorflow/lite/CMakeLists.txt
> > > ++++ b/tensorflow/lite/CMakeLists.txt
> > > +@@ -209,6 +209,9 @@ list(FILTER TFLITE_SRCS EXCLUDE REGEX ".*tflite_with_xnnpack\\.cc$")
> > > + # Exclude Flex related files.
> > > + list(FILTER TFLITE_SRCS EXCLUDE REGEX ".*with_selected_ops\\.cc$")
> > > +
> > > ++# Exclude tensorflow_profiler_logger files.
> > > ++list(FILTER TFLITE_SRCS EXCLUDE REGEX ".*tensorflow_profiler_logger\\.cc$")
> > > ++
> > > + if(_TFLITE_ENABLE_MMAP)
> > > +   list(FILTER TFLITE_SRCS EXCLUDE REGEX ".*mmap_allocation_disabled\\.cc$")
> > > + else()
> > > +@@ -222,6 +225,7 @@ if(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "iOS")
> > > + endif()
> > > + populate_tflite_source_vars("core" TFLITE_CORE_SRCS)
> > > + populate_tflite_source_vars("core/api" TFLITE_CORE_API_SRCS)
> > > ++populate_tflite_source_vars("core/c" TFLITE_CORE_C_SRCS)
> > > + populate_tflite_source_vars("c" TFLITE_C_SRCS)
> > > + populate_tflite_source_vars("delegates" TFLITE_DELEGATES_SRCS)
> > > + if(TFLITE_ENABLE_GPU)
> > > +@@ -483,6 +487,7 @@ endif()
> > > + # TFLite library
> > > + set(_ALL_TFLITE_SRCS
> > > +   ${TFLITE_CORE_API_SRCS}
> > > ++  ${TFLITE_CORE_C_SRCS}
> > > +   ${TFLITE_CORE_SRCS}
> > > +   ${TFLITE_C_SRCS}
> > > +   ${TFLITE_DELEGATES_FLEX_SRCS}
> > > +--
> > > +2.34.1
> > > +
> > > diff --git a/package/tensorflow-lite/0002-Fix-FindFlatBuffers-cmake-file.patch b/package/tensorflow-lite/0002-Fix-FindFlatBuffers-cmake-file.patch
> > > new file mode 100644
> > > index 0000000000..e97bb3e52f
> > > --- /dev/null
> > > +++ b/package/tensorflow-lite/0002-Fix-FindFlatBuffers-cmake-file.patch
> > > @@ -0,0 +1,37 @@
> > > +From a4ff4b5e952a22906ac0ed01e73f84f42926c325 Mon Sep 17 00:00:00 2001
> > > +From: James Hilliard <james.hilliard1@gmail.com>
> > > +Date: Thu, 24 Nov 2022 14:29:06 -0700
> > > +Subject: [PATCH] Fix FindFlatBuffers cmake file
> > > +
> > > +Capitalization needs to match for system cmake override to work:
> > > +https://github.com/google/flatbuffers/blob/v22.11.23/CMake/FindFlatBuffers.cmake
> > > +
> > > +Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> > > +[Upstream status:
> > > +https://github.com/tensorflow/tensorflow/pull/58677]
> > > +---
> > > + tensorflow/lite/CMakeLists.txt                                  | 2 +-
> > > + .../modules/{FindFlatbuffers.cmake => FindFlatBuffers.cmake}    | 0
> > > + 2 files changed, 1 insertion(+), 1 deletion(-)
> > > + rename tensorflow/lite/tools/cmake/modules/{FindFlatbuffers.cmake => FindFlatBuffers.cmake} (100%)
> > > +
> > > +diff --git a/tensorflow/lite/CMakeLists.txt b/tensorflow/lite/CMakeLists.txt
> > > +index f9c30d6a046..c2ee9edfb61 100644
> > > +--- a/tensorflow/lite/CMakeLists.txt
> > > ++++ b/tensorflow/lite/CMakeLists.txt
> > > +@@ -143,7 +143,7 @@ find_package(absl REQUIRED)
> > > + find_package(Eigen3 REQUIRED)
> > > + find_package(farmhash REQUIRED)
> > > + find_package(fft2d REQUIRED)
> > > +-find_package(Flatbuffers REQUIRED)
> > > ++find_package(FlatBuffers REQUIRED)
> > > + find_package(gemmlowp REQUIRED)
> > > + find_package(NEON_2_SSE REQUIRED)
> > > + find_package(cpuinfo REQUIRED)  #CPUINFO is used by XNNPACK and RUY library
> > > +diff --git a/tensorflow/lite/tools/cmake/modules/FindFlatbuffers.cmake b/tensorflow/lite/tools/cmake/modules/FindFlatBuffers.cmake
> > > +similarity index 100%
> > > +rename from tensorflow/lite/tools/cmake/modules/FindFlatbuffers.cmake
> > > +rename to tensorflow/lite/tools/cmake/modules/FindFlatBuffers.cmake
> > > +--
> > > +2.34.1
> > > +
> > > diff --git a/package/tensorflow-lite/0003-Don-t-link-tensorflow-lite-against-gemmlowp.patch b/package/tensorflow-lite/0003-Don-t-link-tensorflow-lite-against-gemmlowp.patch
> > > new file mode 100644
> > > index 0000000000..dbee9942b3
> > > --- /dev/null
> > > +++ b/package/tensorflow-lite/0003-Don-t-link-tensorflow-lite-against-gemmlowp.patch
> > > @@ -0,0 +1,32 @@
> > > +From fb584589f707853d85a081c99b1b82598c2631c1 Mon Sep 17 00:00:00 2001
> > > +From: James Hilliard <james.hilliard1@gmail.com>
> > > +Date: Thu, 24 Nov 2022 15:10:27 -0700
> > > +Subject: [PATCH] Don't link tensorflow-lite against gemmlowp
> > > +
> > > +We can't link against gemmlowp as it is a header only library.
> > > +
> > > +Fixes:
> > > +/bin/ld: cannot find -lgemmlowp: No such file or directory
> > > +
> > > +Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> > > +[Upstream status:
> > > +https://github.com/tensorflow/tensorflow/pull/58678]
> > > +---
> > > + tensorflow/lite/CMakeLists.txt | 1 -
> > > + 1 file changed, 1 deletion(-)
> > > +
> > > +diff --git a/tensorflow/lite/CMakeLists.txt b/tensorflow/lite/CMakeLists.txt
> > > +index f9c30d6a046..3fe5ed15605 100644
> > > +--- a/tensorflow/lite/CMakeLists.txt
> > > ++++ b/tensorflow/lite/CMakeLists.txt
> > > +@@ -560,7 +560,6 @@ target_link_libraries(tensorflow-lite
> > > +     farmhash
> > > +     fft2d_fftsg2d
> > > +     flatbuffers::flatbuffers
> > > +-    gemmlowp
> > > +     ruy::ruy
> > > +     pthreadpool
> > > +     ${CMAKE_DL_LIBS}
> > > +--
> > > +2.34.1
> > > +
> > > diff --git a/package/tensorflow-lite/Config.in b/package/tensorflow-lite/Config.in
> > > new file mode 100644
> > > index 0000000000..9231d674bd
> > > --- /dev/null
> > > +++ b/package/tensorflow-lite/Config.in
> > > @@ -0,0 +1,32 @@
> > > +config BR2_PACKAGE_TENSORFLOW_LITE
> > > +       bool "tensorflow-lite"
> > > +       depends on BR2_TOOLCHAIN_GCC_AT_LEAST_9
> > Can you please add to comment that explains why this version of GCC is needed?
> 
> I'm not sure why this is, maybe Stephan Hager can clarify.

The Tensorflow-lite build documentation for cmake on ARM uses gcc.arm.8.3 in their example. 
BR offers the GCC Variables BR2_TOOLCHAIN_GCC_AT_LEAST_8, BR2_TOOLCHAIN_GCC_AT_LEAST_9 and ships with GCC 10/11/12.
So choosing BR2_TOOLCHAIN_GCC_AT_LEAST_9 seemed a good solution to me. 
Since i do not have prebuilt GCC8.0...GCC9.0 on hand selectiong 9 as minimum would be safe.

I tried setting to BR2_TOOLCHAIN_GCC_AT_LEAST_8 in the config and run the 'utils/./test-pkg -a'. 
Only 3 out of 44 possible toolchains were used for testing (the same as when using BR2_TOOLCHAIN_GCC_AT_LEAST_9), 
but none of them uses GCC 8.

Maybe someone can test and proof that it also works with GCC Versions < 9?

> 
> >
> > > +       depends on BR2_TOOLCHAIN_USES_GLIBC
> > > +       depends on BR2_INSTALL_LIBSTDCPP
> > > +       depends on BR2_TOOLCHAIN_HAS_THREADS
> > > +       depends on BR2_SHARED_LIBS
> > > +       depends on ( BR2_arm && BR2_ARM_CPU_ARMV7A ) || ( BR2_aarch64 && BR2_ARM_CPU_ARMV8A )
> > > +       select BR2_PACKAGE_CPUINFO
> > > +       select BR2_PACKAGE_EIGEN
> > > +       select BR2_PACKAGE_FARMHASH
> > > +       select BR2_PACKAGE_FFT2D
> > > +       select BR2_PACKAGE_FLATBUFFERS
> > > +       select BR2_PACKAGE_GEMMLOWP
> > > +       select BR2_PACKAGE_LIBABSEIL_CPP
> > > +       select BR2_PACKAGE_NEON_2_SSE
> > > +       select BR2_PACKAGE_RUY
> > > +       help
> > > +         Tensorflow Lite dynamic library and headers: Inference engine to run previously trained machine learning models.
> > The text is too long. Please run "utils/check-package" to see the
> > warning that it generates.
> 
> Fixed in v3:
> https://patchwork.ozlabs.org/project/buildroot/patch/20230124092235.806969-8-james.hilliard1@gmail.com/
> 
> >
> > A couple of suggestions:
> > 1) would it be possible to add an option to build and install the
> > label_image example? It is always handy to be able to test this
> > package once it is built.
> > 2) would it be possible to add an option to build and install the
> > benchmark_model tool? This tool provides useful performance
> > information.
> 
> Not sure there's really a good way to do this without adding a config
> flag upstream.
> 
> >
> > > +
> > > +comment "tensorflow-lite needs needs a toolchain w/ gcc >= 9"
> > > +       depends on !BR2_TOOLCHAIN_GCC_AT_LEAST_9
> > > +
> > > +comment "tensorflow-lite needs a toolchain w/ glibc, C++, threads"
> > > +       depends on !BR2_TOOLCHAIN_USES_GLIBC || !BR2_INSTALL_LIBSTDCPP || \
> > > +                       !BR2_TOOLCHAIN_HAS_THREADS
> > > +
> > > +comment "tensorflow-lite needs a toolchain w/ shared libraries"
> > > +       depends on !BR2_SHARED_LIBS
> > > +
> > > +comment "tensorflow-lite in buildroot currently only supports arm + armv7a cpu or arm64 + armv8a cpu targets"
> > > +       depends on ( BR2_arm && !BR2_ARM_CPU_ARMV7A ) || ( BR2_aarch64 && !BR2_ARM_CPU_ARMV8A) || (!BR2_arm && !BR2_aarch64)
> > > diff --git a/package/tensorflow-lite/tensorflow-lite.hash b/package/tensorflow-lite/tensorflow-lite.hash
> > > new file mode 100644
> > > index 0000000000..7d9035707b
> > > --- /dev/null
> > > +++ b/package/tensorflow-lite/tensorflow-lite.hash
> > > @@ -0,0 +1,4 @@
> > > +# Locally calculated
> > > +sha256  99c732b92b1b37fc243a559e02f9aef5671771e272758aa4aec7f34dc92dac48  tensorflow-lite-2.11.0.tar.gz
> > > +# License files, locally calculated
> > > +sha256  71c6915d04265772a0339bed47276942c678b45cc01534210ebe6984fd1aec65  LICENSE
> > > diff --git a/package/tensorflow-lite/tensorflow-lite.mk b/package/tensorflow-lite/tensorflow-lite.mk
> > > new file mode 100644
> > > index 0000000000..1f75f3813c
> > > --- /dev/null
> > > +++ b/package/tensorflow-lite/tensorflow-lite.mk
> > > @@ -0,0 +1,49 @@
> > > +################################################################################
> > > +#
> > > +# tensorflow-lite
> > > +#
> > > +################################################################################
> > > +
> > > +TENSORFLOW_LITE_VERSION = 2.11.0
> > > +TENSORFLOW_LITE_SITE =  $(call github,tensorflow,tensorflow,v$(TENSORFLOW_LITE_VERSION))
> > > +TENSORFLOW_LITE_INSTALL_STAGING = YES
> > > +TENSORFLOW_LITE_LICENSE = Apache-2.0
> > > +TENSORFLOW_LITE_LICENSE_FILES = LICENSE
> > > +TENSORFLOW_LITE_SUBDIR = tensorflow/lite
> > > +TENSORFLOW_LITE_SUPPORTS_IN_SOURCE_BUILD = NO
> > > +TENSORFLOW_LITE_DEPENDENCIES += \
> > > +       host-pkgconf \
> > > +       host-flatbuffers \
> > > +       cpuinfo \
> > > +       eigen \
> > > +       farmhash \
> > > +       fft2d \
> > > +       flatbuffers \
> > > +       gemmlowp \
> > > +       libabseil-cpp \
> > > +       neon-2-sse \
> > > +       ruy
> > > +
> > > +TENSORFLOW_LITE_CONF_OPTS = \
> > > +       -Dabsl_DIR=$(STAGING_DIR)/usr/lib/cmake/absl \
> > > +       -DBUILD_SHARED_LIBS=ON \
> > > +       -DCMAKE_CXX_FLAGS="$(TARGET_CXXFLAGS) -I$(STAGING_DIR)/usr/include/gemmlowp" \
> > > +       -DCMAKE_FIND_PACKAGE_PREFER_CONFIG=ON \
> > > +       -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
> > > +       -DEigen3_DIR=$(STAGING_DIR)/usr/share/eigen3/cmake \
> > > +       -DFARMHASH_SOURCE_DIR=$(FARMHASH_DIR) \
> > > +       -Dfarmhash_DIR=$(STAGING_DIR)/usr/lib \
> > > +       -DFETCHCONTENT_FULLY_DISCONNECTED=ON \
> > > +       -DFETCHCONTENT_QUIET=OFF \
> > > +       -DFFT2D_SOURCE_DIR=$(STAGING_DIR)/usr/include/fft2d \
> > > +       -DFlatBuffers_DIR=$(STAGING_DIR)/usr/lib/cmake/flatbuffers \
> > > +       -DNEON_2_SSE_DIR=$(STAGING_DIR)/usr/lib/cmake/NEON_2_SSE \
> > > +       -DTFLITE_ENABLE_EXTERNAL_DELEGATE=ON \
> > > +       -DTFLITE_ENABLE_GPU=OFF \
> > > +       -DTFLITE_ENABLE_INSTALL=ON \
> > > +       -DTFLITE_ENABLE_MMAP=ON \
> > > +       -DTFLITE_ENABLE_NNAPI=ON \
> > I thought NNAPI was used in Android. Can you explain why it is required here?
> 
> Disabled in v3:
> https://patchwork.ozlabs.org/project/buildroot/patch/20230124092235.806969-8-james.hilliard1@gmail.com/
> 
> >
> > > +       -DTFLITE_ENABLE_RUY=ON \
> > > +       -DTFLITE_ENABLE_XNNPACK=OFF
> > any reason why xnnpack is not enabled? It would be great to enable it
> > as an option.
> 
> Mostly since it's not a required dependency and haven't added the
> dependency yet. Will look into adding that as a followup once this is
> merged.

I agree, it would be a nice addition, but not a necessity for the initial merge.

> 
> >
> > > +
> > > +$(eval $(cmake-package))
> > > --
> > > 2.34.1
> > >
> > > _______________________________________________
> > > buildroot mailing list
> > > buildroot@buildroot.org
> > > https://lists.buildroot.org/mailman/listinfo/buildroot
> > thanks
> > Gilles.

Regards,
Stefan
Lang Daniel Jan. 27, 2023, 8:35 a.m. UTC | #5
Hi all,

> > From: James Hilliard <james.hilliard1@gmail.com>
> > Sent: Tuesday, January 24, 2023 10:27
> > To: Gilles Talis <gilles.talis@gmail.com>
> > Cc: buildroot@buildroot.org <buildroot@buildroot.org>; Hager Stefan <Stefan.Hager@ginzinger.com>; Samuel Martin <s.martin49@gmail.com>; Fabrice Fontaine <fontaine.fabrice@gmail.com>; Thomas Petazzoni <thomas.petazzoni@bootlin.com>
> > Subject: Re: [Buildroot] [PATCH v2 8/8] package/tensorflow-lite: new package
> > 
> > On Tue, Jan 10, 2023 at 5:49 AM Gilles Talis <gilles.talis@gmail.com> wrote:
> > >
> > > Hi James, Hi Stefan,
> > >
> > > fyi, I could build and successfully test tensorflow lite on an aarch64
> > > platform with Cortex A53 cores.
> > > a few comments though.
> > >
> > > Le lun. 28 nov. 2022 à 19:00, James Hilliard
> > > <james.hilliard1@gmail.com> a écrit :
> > > >
> > > > From: Stefan Hager <stefan.hager@ginzinger.com>
> > > >
> > > > This package adds the tensorflow lite runtime to buildroot.
> > > >
> > > > Signed-off-by: Stefan Hager <stefan.hager@ginzinger.com>
> > > > Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> > > > ---
> > > > Changes v1 -> v2:
> > > >   - fix label_image build
> > > >   - more explicit cmake config
> > > > ---

[SNIP]

> > > > diff --git a/package/tensorflow-lite/Config.in b/package/tensorflow-lite/Config.in
> > > > new file mode 100644
> > > > index 0000000000..9231d674bd
> > > > --- /dev/null
> > > > +++ b/package/tensorflow-lite/Config.in
> > > > @@ -0,0 +1,32 @@
> > > > +config BR2_PACKAGE_TENSORFLOW_LITE
> > > > +       bool "tensorflow-lite"
> > > > +       depends on BR2_TOOLCHAIN_GCC_AT_LEAST_9
> > > Can you please add to comment that explains why this version of GCC is needed?
> > 
> > I'm not sure why this is, maybe Stephan Hager can clarify.
> 
> The Tensorflow-lite build documentation for cmake on ARM uses gcc.arm.8.3 in their example. 
> BR offers the GCC Variables BR2_TOOLCHAIN_GCC_AT_LEAST_8, BR2_TOOLCHAIN_GCC_AT_LEAST_9 and ships with GCC 10/11/12.
> So choosing BR2_TOOLCHAIN_GCC_AT_LEAST_9 seemed a good solution to me. 
> Since i do not have prebuilt GCC8.0...GCC9.0 on hand selectiong 9 as minimum would be safe.
> 
> I tried setting to BR2_TOOLCHAIN_GCC_AT_LEAST_8 in the config and run the 'utils/./test-pkg -a'. 
> Only 3 out of 44 possible toolchains were used for testing (the same as when using BR2_TOOLCHAIN_GCC_AT_LEAST_9), 
> but none of them uses GCC 8.
> 
> Maybe someone can test and proof that it also works with GCC Versions < 9?
> 

I successfully compiled and tested v3 of this patch series.
tensorflow-lite and the label_image example build for armv7
with GCC 8.4 and GCC 7.5.
So I guess BR2_TOOLCHAIN_GCC_AT_LEAST_7 should be enough.
The justification for GCC 7 being tensorflows need for C++17.

> > 
> > >
> > > > +       depends on BR2_TOOLCHAIN_USES_GLIBC
> > > > +       depends on BR2_INSTALL_LIBSTDCPP
> > > > +       depends on BR2_TOOLCHAIN_HAS_THREADS
> > > > +       depends on BR2_SHARED_LIBS
> > > > +       depends on ( BR2_arm && BR2_ARM_CPU_ARMV7A ) || ( BR2_aarch64 && BR2_ARM_CPU_ARMV8A )
> > > > +       select BR2_PACKAGE_CPUINFO
> > > > +       select BR2_PACKAGE_EIGEN
> > > > +       select BR2_PACKAGE_FARMHASH
> > > > +       select BR2_PACKAGE_FFT2D
> > > > +       select BR2_PACKAGE_FLATBUFFERS
> > > > +       select BR2_PACKAGE_GEMMLOWP
> > > > +       select BR2_PACKAGE_LIBABSEIL_CPP
> > > > +       select BR2_PACKAGE_NEON_2_SSE
> > > > +       select BR2_PACKAGE_RUY
> > > > +       help
> > > > +         Tensorflow Lite dynamic library and headers: Inference engine to run previously trained machine learning models.
> > > The text is too long. Please run "utils/check-package" to see the
> > > warning that it generates.
> > 
> > Fixed in v3:
> > https://patchwork.ozlabs.org/project/buildroot/patch/20230124092235.806969-8-james.hilliard1@gmail.com/
> > 
> > >
> > > A couple of suggestions:
> > > 1) would it be possible to add an option to build and install the
> > > label_image example? It is always handy to be able to test this
> > > package once it is built.
> > > 2) would it be possible to add an option to build and install the
> > > benchmark_model tool? This tool provides useful performance
> > > information.
> > 
> > Not sure there's really a good way to do this without adding a config
> > flag upstream.
> > 
> > >
> > > > +
> > > > +comment "tensorflow-lite needs needs a toolchain w/ gcc >= 9"
> > > > +       depends on !BR2_TOOLCHAIN_GCC_AT_LEAST_9
> > > > +
> > > > +comment "tensorflow-lite needs a toolchain w/ glibc, C++, threads"
> > > > +       depends on !BR2_TOOLCHAIN_USES_GLIBC || !BR2_INSTALL_LIBSTDCPP || \
> > > > +                       !BR2_TOOLCHAIN_HAS_THREADS
> > > > +
> > > > +comment "tensorflow-lite needs a toolchain w/ shared libraries"
> > > > +       depends on !BR2_SHARED_LIBS
> > > > +
> > > > +comment "tensorflow-lite in buildroot currently only supports arm + armv7a cpu or arm64 + armv8a cpu targets"
> > > > +       depends on ( BR2_arm && !BR2_ARM_CPU_ARMV7A ) || ( BR2_aarch64 && !BR2_ARM_CPU_ARMV8A) || (!BR2_arm && !BR2_aarch64)
> > > > diff --git a/package/tensorflow-lite/tensorflow-lite.hash b/package/tensorflow-lite/tensorflow-lite.hash
> > > > new file mode 100644
> > > > index 0000000000..7d9035707b
> > > > --- /dev/null
> > > > +++ b/package/tensorflow-lite/tensorflow-lite.hash
> > > > @@ -0,0 +1,4 @@
> > > > +# Locally calculated
> > > > +sha256  99c732b92b1b37fc243a559e02f9aef5671771e272758aa4aec7f34dc92dac48  tensorflow-lite-2.11.0.tar.gz
> > > > +# License files, locally calculated
> > > > +sha256  71c6915d04265772a0339bed47276942c678b45cc01534210ebe6984fd1aec65  LICENSE
> > > > diff --git a/package/tensorflow-lite/tensorflow-lite.mk b/package/tensorflow-lite/tensorflow-lite.mk
> > > > new file mode 100644
> > > > index 0000000000..1f75f3813c
> > > > --- /dev/null
> > > > +++ b/package/tensorflow-lite/tensorflow-lite.mk
> > > > @@ -0,0 +1,49 @@
> > > > +################################################################################
> > > > +#
> > > > +# tensorflow-lite
> > > > +#
> > > > +################################################################################
> > > > +
> > > > +TENSORFLOW_LITE_VERSION = 2.11.0
> > > > +TENSORFLOW_LITE_SITE =  $(call github,tensorflow,tensorflow,v$(TENSORFLOW_LITE_VERSION))
> > > > +TENSORFLOW_LITE_INSTALL_STAGING = YES
> > > > +TENSORFLOW_LITE_LICENSE = Apache-2.0
> > > > +TENSORFLOW_LITE_LICENSE_FILES = LICENSE
> > > > +TENSORFLOW_LITE_SUBDIR = tensorflow/lite
> > > > +TENSORFLOW_LITE_SUPPORTS_IN_SOURCE_BUILD = NO
> > > > +TENSORFLOW_LITE_DEPENDENCIES += \
> > > > +       host-pkgconf \
> > > > +       host-flatbuffers \
> > > > +       cpuinfo \
> > > > +       eigen \
> > > > +       farmhash \
> > > > +       fft2d \
> > > > +       flatbuffers \
> > > > +       gemmlowp \
> > > > +       libabseil-cpp \
> > > > +       neon-2-sse \
> > > > +       ruy
> > > > +
> > > > +TENSORFLOW_LITE_CONF_OPTS = \
> > > > +       -Dabsl_DIR=$(STAGING_DIR)/usr/lib/cmake/absl \
> > > > +       -DBUILD_SHARED_LIBS=ON \
> > > > +       -DCMAKE_CXX_FLAGS="$(TARGET_CXXFLAGS) -I$(STAGING_DIR)/usr/include/gemmlowp" \
> > > > +       -DCMAKE_FIND_PACKAGE_PREFER_CONFIG=ON \
> > > > +       -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
> > > > +       -DEigen3_DIR=$(STAGING_DIR)/usr/share/eigen3/cmake \
> > > > +       -DFARMHASH_SOURCE_DIR=$(FARMHASH_DIR) \
> > > > +       -Dfarmhash_DIR=$(STAGING_DIR)/usr/lib \
> > > > +       -DFETCHCONTENT_FULLY_DISCONNECTED=ON \
> > > > +       -DFETCHCONTENT_QUIET=OFF \
> > > > +       -DFFT2D_SOURCE_DIR=$(STAGING_DIR)/usr/include/fft2d \
> > > > +       -DFlatBuffers_DIR=$(STAGING_DIR)/usr/lib/cmake/flatbuffers \
> > > > +       -DNEON_2_SSE_DIR=$(STAGING_DIR)/usr/lib/cmake/NEON_2_SSE \
> > > > +       -DTFLITE_ENABLE_EXTERNAL_DELEGATE=ON \
> > > > +       -DTFLITE_ENABLE_GPU=OFF \
> > > > +       -DTFLITE_ENABLE_INSTALL=ON \
> > > > +       -DTFLITE_ENABLE_MMAP=ON \
> > > > +       -DTFLITE_ENABLE_NNAPI=ON \
> > > I thought NNAPI was used in Android. Can you explain why it is required here?
> > 
> > Disabled in v3:
> > https://patchwork.ozlabs.org/project/buildroot/patch/20230124092235.806969-8-james.hilliard1@gmail.com/
> > 
> > >
> > > > +       -DTFLITE_ENABLE_RUY=ON \
> > > > +       -DTFLITE_ENABLE_XNNPACK=OFF
> > > any reason why xnnpack is not enabled? It would be great to enable it
> > > as an option.
> > 
> > Mostly since it's not a required dependency and haven't added the
> > dependency yet. Will look into adding that as a followup once this is
> > merged.
> 
> I agree, it would be a nice addition, but not a necessity for the initial merge.
> 
> > 
> > >
> > > > +
> > > > +$(eval $(cmake-package))
> > > > --
> > > > 2.34.1
> > > >
> > > > _______________________________________________
> > > > buildroot mailing list
> > > > buildroot@buildroot.org
> > > > https://lists.buildroot.org/mailman/listinfo/buildroot
> > > thanks
> > > Gilles.
> 
> Regards,
> Stefan

Regards,
Daniel
diff mbox series

Patch

diff --git a/package/Config.in b/package/Config.in
index a59d074430..c979710f32 100644
--- a/package/Config.in
+++ b/package/Config.in
@@ -2105,6 +2105,7 @@  endif
 	source "package/sphinxbase/Config.in"
 	source "package/startup-notification/Config.in"
 	source "package/tbb/Config.in"
+	source "package/tensorflow-lite/Config.in"
 	source "package/tinycbor/Config.in"
 	source "package/tz/Config.in"
 	source "package/tzdata/Config.in"
diff --git a/package/tensorflow-lite/0001-lite-Update-CMakeLists.txt.patch b/package/tensorflow-lite/0001-lite-Update-CMakeLists.txt.patch
new file mode 100644
index 0000000000..53b5170681
--- /dev/null
+++ b/package/tensorflow-lite/0001-lite-Update-CMakeLists.txt.patch
@@ -0,0 +1,49 @@ 
+From 081c2e4e3cf021efb2853a485a18b563e88f6117 Mon Sep 17 00:00:00 2001
+From: Terry Heo <terryheo@google.com>
+Date: Tue, 1 Nov 2022 15:55:30 -0700
+Subject: [PATCH] lite: Update CMakeLists.txt
+
+This changes are needed to build kernel tests.
+
+PiperOrigin-RevId: 485439972
+
+Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
+[james.hilliard1@gmail.com: backport from upstream commit
+081c2e4e3cf021efb2853a485a18b563e88f6117]
+---
+ tensorflow/lite/CMakeLists.txt | 7 ++++++-
+ 1 file changed, 6 insertions(+), 1 deletion(-)
+
+diff --git a/tensorflow/lite/CMakeLists.txt b/tensorflow/lite/CMakeLists.txt
+index 9dfbb4b72f3..fd8b3faf1e2 100644
+--- a/tensorflow/lite/CMakeLists.txt
++++ b/tensorflow/lite/CMakeLists.txt
+@@ -209,6 +209,9 @@ list(FILTER TFLITE_SRCS EXCLUDE REGEX ".*tflite_with_xnnpack\\.cc$")
+ # Exclude Flex related files.
+ list(FILTER TFLITE_SRCS EXCLUDE REGEX ".*with_selected_ops\\.cc$")
+ 
++# Exclude tensorflow_profiler_logger files.
++list(FILTER TFLITE_SRCS EXCLUDE REGEX ".*tensorflow_profiler_logger\\.cc$")
++
+ if(_TFLITE_ENABLE_MMAP)
+   list(FILTER TFLITE_SRCS EXCLUDE REGEX ".*mmap_allocation_disabled\\.cc$")
+ else()
+@@ -222,6 +225,7 @@ if(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "iOS")
+ endif()
+ populate_tflite_source_vars("core" TFLITE_CORE_SRCS)
+ populate_tflite_source_vars("core/api" TFLITE_CORE_API_SRCS)
++populate_tflite_source_vars("core/c" TFLITE_CORE_C_SRCS)
+ populate_tflite_source_vars("c" TFLITE_C_SRCS)
+ populate_tflite_source_vars("delegates" TFLITE_DELEGATES_SRCS)
+ if(TFLITE_ENABLE_GPU)
+@@ -483,6 +487,7 @@ endif()
+ # TFLite library
+ set(_ALL_TFLITE_SRCS
+   ${TFLITE_CORE_API_SRCS}
++  ${TFLITE_CORE_C_SRCS}
+   ${TFLITE_CORE_SRCS}
+   ${TFLITE_C_SRCS}
+   ${TFLITE_DELEGATES_FLEX_SRCS}
+-- 
+2.34.1
+
diff --git a/package/tensorflow-lite/0002-Fix-FindFlatBuffers-cmake-file.patch b/package/tensorflow-lite/0002-Fix-FindFlatBuffers-cmake-file.patch
new file mode 100644
index 0000000000..e97bb3e52f
--- /dev/null
+++ b/package/tensorflow-lite/0002-Fix-FindFlatBuffers-cmake-file.patch
@@ -0,0 +1,37 @@ 
+From a4ff4b5e952a22906ac0ed01e73f84f42926c325 Mon Sep 17 00:00:00 2001
+From: James Hilliard <james.hilliard1@gmail.com>
+Date: Thu, 24 Nov 2022 14:29:06 -0700
+Subject: [PATCH] Fix FindFlatBuffers cmake file
+
+Capitalization needs to match for system cmake override to work:
+https://github.com/google/flatbuffers/blob/v22.11.23/CMake/FindFlatBuffers.cmake
+
+Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
+[Upstream status:
+https://github.com/tensorflow/tensorflow/pull/58677]
+---
+ tensorflow/lite/CMakeLists.txt                                  | 2 +-
+ .../modules/{FindFlatbuffers.cmake => FindFlatBuffers.cmake}    | 0
+ 2 files changed, 1 insertion(+), 1 deletion(-)
+ rename tensorflow/lite/tools/cmake/modules/{FindFlatbuffers.cmake => FindFlatBuffers.cmake} (100%)
+
+diff --git a/tensorflow/lite/CMakeLists.txt b/tensorflow/lite/CMakeLists.txt
+index f9c30d6a046..c2ee9edfb61 100644
+--- a/tensorflow/lite/CMakeLists.txt
++++ b/tensorflow/lite/CMakeLists.txt
+@@ -143,7 +143,7 @@ find_package(absl REQUIRED)
+ find_package(Eigen3 REQUIRED)
+ find_package(farmhash REQUIRED)
+ find_package(fft2d REQUIRED)
+-find_package(Flatbuffers REQUIRED)
++find_package(FlatBuffers REQUIRED)
+ find_package(gemmlowp REQUIRED)
+ find_package(NEON_2_SSE REQUIRED)
+ find_package(cpuinfo REQUIRED)  #CPUINFO is used by XNNPACK and RUY library
+diff --git a/tensorflow/lite/tools/cmake/modules/FindFlatbuffers.cmake b/tensorflow/lite/tools/cmake/modules/FindFlatBuffers.cmake
+similarity index 100%
+rename from tensorflow/lite/tools/cmake/modules/FindFlatbuffers.cmake
+rename to tensorflow/lite/tools/cmake/modules/FindFlatBuffers.cmake
+-- 
+2.34.1
+
diff --git a/package/tensorflow-lite/0003-Don-t-link-tensorflow-lite-against-gemmlowp.patch b/package/tensorflow-lite/0003-Don-t-link-tensorflow-lite-against-gemmlowp.patch
new file mode 100644
index 0000000000..dbee9942b3
--- /dev/null
+++ b/package/tensorflow-lite/0003-Don-t-link-tensorflow-lite-against-gemmlowp.patch
@@ -0,0 +1,32 @@ 
+From fb584589f707853d85a081c99b1b82598c2631c1 Mon Sep 17 00:00:00 2001
+From: James Hilliard <james.hilliard1@gmail.com>
+Date: Thu, 24 Nov 2022 15:10:27 -0700
+Subject: [PATCH] Don't link tensorflow-lite against gemmlowp
+
+We can't link against gemmlowp as it is a header only library.
+
+Fixes:
+/bin/ld: cannot find -lgemmlowp: No such file or directory
+
+Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
+[Upstream status:
+https://github.com/tensorflow/tensorflow/pull/58678]
+---
+ tensorflow/lite/CMakeLists.txt | 1 -
+ 1 file changed, 1 deletion(-)
+
+diff --git a/tensorflow/lite/CMakeLists.txt b/tensorflow/lite/CMakeLists.txt
+index f9c30d6a046..3fe5ed15605 100644
+--- a/tensorflow/lite/CMakeLists.txt
++++ b/tensorflow/lite/CMakeLists.txt
+@@ -560,7 +560,6 @@ target_link_libraries(tensorflow-lite
+     farmhash
+     fft2d_fftsg2d
+     flatbuffers::flatbuffers
+-    gemmlowp
+     ruy::ruy
+     pthreadpool
+     ${CMAKE_DL_LIBS}
+-- 
+2.34.1
+
diff --git a/package/tensorflow-lite/Config.in b/package/tensorflow-lite/Config.in
new file mode 100644
index 0000000000..9231d674bd
--- /dev/null
+++ b/package/tensorflow-lite/Config.in
@@ -0,0 +1,32 @@ 
+config BR2_PACKAGE_TENSORFLOW_LITE
+	bool "tensorflow-lite"
+	depends on BR2_TOOLCHAIN_GCC_AT_LEAST_9
+	depends on BR2_TOOLCHAIN_USES_GLIBC
+	depends on BR2_INSTALL_LIBSTDCPP
+	depends on BR2_TOOLCHAIN_HAS_THREADS
+	depends on BR2_SHARED_LIBS
+	depends on ( BR2_arm && BR2_ARM_CPU_ARMV7A ) || ( BR2_aarch64 && BR2_ARM_CPU_ARMV8A )
+	select BR2_PACKAGE_CPUINFO
+	select BR2_PACKAGE_EIGEN
+	select BR2_PACKAGE_FARMHASH
+	select BR2_PACKAGE_FFT2D
+	select BR2_PACKAGE_FLATBUFFERS
+	select BR2_PACKAGE_GEMMLOWP
+	select BR2_PACKAGE_LIBABSEIL_CPP
+	select BR2_PACKAGE_NEON_2_SSE
+	select BR2_PACKAGE_RUY
+	help
+	  Tensorflow Lite dynamic library and headers: Inference engine to run previously trained machine learning models.
+
+comment "tensorflow-lite needs needs a toolchain w/ gcc >= 9"
+	depends on !BR2_TOOLCHAIN_GCC_AT_LEAST_9
+
+comment "tensorflow-lite needs a toolchain w/ glibc, C++, threads"
+	depends on !BR2_TOOLCHAIN_USES_GLIBC || !BR2_INSTALL_LIBSTDCPP || \
+			!BR2_TOOLCHAIN_HAS_THREADS
+
+comment "tensorflow-lite needs a toolchain w/ shared libraries"
+	depends on !BR2_SHARED_LIBS
+
+comment "tensorflow-lite in buildroot currently only supports arm + armv7a cpu or arm64 + armv8a cpu targets"
+	depends on ( BR2_arm && !BR2_ARM_CPU_ARMV7A ) || ( BR2_aarch64 && !BR2_ARM_CPU_ARMV8A) || (!BR2_arm && !BR2_aarch64)
diff --git a/package/tensorflow-lite/tensorflow-lite.hash b/package/tensorflow-lite/tensorflow-lite.hash
new file mode 100644
index 0000000000..7d9035707b
--- /dev/null
+++ b/package/tensorflow-lite/tensorflow-lite.hash
@@ -0,0 +1,4 @@ 
+# Locally calculated
+sha256  99c732b92b1b37fc243a559e02f9aef5671771e272758aa4aec7f34dc92dac48  tensorflow-lite-2.11.0.tar.gz
+# License files, locally calculated
+sha256  71c6915d04265772a0339bed47276942c678b45cc01534210ebe6984fd1aec65  LICENSE
diff --git a/package/tensorflow-lite/tensorflow-lite.mk b/package/tensorflow-lite/tensorflow-lite.mk
new file mode 100644
index 0000000000..1f75f3813c
--- /dev/null
+++ b/package/tensorflow-lite/tensorflow-lite.mk
@@ -0,0 +1,49 @@ 
+################################################################################
+#
+# tensorflow-lite
+#
+################################################################################
+
+TENSORFLOW_LITE_VERSION = 2.11.0
+TENSORFLOW_LITE_SITE =  $(call github,tensorflow,tensorflow,v$(TENSORFLOW_LITE_VERSION))
+TENSORFLOW_LITE_INSTALL_STAGING = YES
+TENSORFLOW_LITE_LICENSE = Apache-2.0
+TENSORFLOW_LITE_LICENSE_FILES = LICENSE
+TENSORFLOW_LITE_SUBDIR = tensorflow/lite
+TENSORFLOW_LITE_SUPPORTS_IN_SOURCE_BUILD = NO
+TENSORFLOW_LITE_DEPENDENCIES += \
+	host-pkgconf \
+	host-flatbuffers \
+	cpuinfo \
+	eigen \
+	farmhash \
+	fft2d \
+	flatbuffers \
+	gemmlowp \
+	libabseil-cpp \
+	neon-2-sse \
+	ruy
+
+TENSORFLOW_LITE_CONF_OPTS = \
+	-Dabsl_DIR=$(STAGING_DIR)/usr/lib/cmake/absl \
+	-DBUILD_SHARED_LIBS=ON \
+	-DCMAKE_CXX_FLAGS="$(TARGET_CXXFLAGS) -I$(STAGING_DIR)/usr/include/gemmlowp" \
+	-DCMAKE_FIND_PACKAGE_PREFER_CONFIG=ON \
+	-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
+	-DEigen3_DIR=$(STAGING_DIR)/usr/share/eigen3/cmake \
+	-DFARMHASH_SOURCE_DIR=$(FARMHASH_DIR) \
+	-Dfarmhash_DIR=$(STAGING_DIR)/usr/lib \
+	-DFETCHCONTENT_FULLY_DISCONNECTED=ON \
+	-DFETCHCONTENT_QUIET=OFF \
+	-DFFT2D_SOURCE_DIR=$(STAGING_DIR)/usr/include/fft2d \
+	-DFlatBuffers_DIR=$(STAGING_DIR)/usr/lib/cmake/flatbuffers \
+	-DNEON_2_SSE_DIR=$(STAGING_DIR)/usr/lib/cmake/NEON_2_SSE \
+	-DTFLITE_ENABLE_EXTERNAL_DELEGATE=ON \
+	-DTFLITE_ENABLE_GPU=OFF \
+	-DTFLITE_ENABLE_INSTALL=ON \
+	-DTFLITE_ENABLE_MMAP=ON \
+	-DTFLITE_ENABLE_NNAPI=ON \
+	-DTFLITE_ENABLE_RUY=ON \
+	-DTFLITE_ENABLE_XNNPACK=OFF
+
+$(eval $(cmake-package))