From 9f80d52c2c00d907b9f3ea6589ca17dcc880ff88 Mon Sep 17 00:00:00 2001 From: Andy Tai Date: Sun, 23 Nov 2025 00:49:56 -0800 Subject: [PATCH] gnu: Add tflite-micro. * gnu/packages/machine-learning.scm (tflite-micro): New variable. * gnu/packages/patches/tflite-micro_disable_download.patch: New file. * gnu/local.mk: (dist_patch_DATA): Reference new patch file. Change-Id: I43470f3101a48cf3570e31c00796d16e7257673c Signed-off-by: Andreas Enge --- gnu/local.mk | 1 + gnu/packages/machine-learning.scm | 84 +++++++++++++++++++ .../tflite-micro_disable_download.patch | 62 ++++++++++++++ 3 files changed, 147 insertions(+) create mode 100644 gnu/packages/patches/tflite-micro_disable_download.patch diff --git a/gnu/local.mk b/gnu/local.mk index 42146d8ec4664f8a52e4324463321f689df8b54d..afc9b1fa1de59cb574b04c7f523ab2f769260d2c 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -2366,6 +2366,7 @@ dist_patch_DATA = \ %D%/packages/patches/texi2html-document-encoding.patch \ %D%/packages/patches/texi2html-i18n.patch \ %D%/packages/patches/texmacs-wayland-hidpi.patch \ + %D%/packages/patches/tflite-micro_disable_download.patch \ %D%/packages/patches/thefuck-test-environ.patch \ %D%/packages/patches/thefuck-remove-broken-tests.patch \ %D%/packages/patches/tidy-CVE-2015-5522+5523.patch \ diff --git a/gnu/packages/machine-learning.scm b/gnu/packages/machine-learning.scm index c53187220df75288da2da664fa0ea60590fc440f..66861c67b4f2d56f8313c724ba82bc087292f8d0 100644 --- a/gnu/packages/machine-learning.scm +++ b/gnu/packages/machine-learning.scm @@ -3521,6 +3521,90 @@ devices.") (string-append #$output "/lib"))))) (native-inputs '()))) +(define-public tflite-micro + (let ((commit "a94423c6b6ee1f30c82d60952d70f749296a5581") + (version "0") + (revision "0")) + (package + (name "tflite-micro") + (version (git-version version revision commit)) + (source + (origin + (method git-fetch) + (uri (git-reference + (url "https://github.com/tensorflow/tflite-micro") + (commit commit))) + (file-name (git-file-name name version)) + (sha256 + (base32 "0q1l4chj4p7vwclcysjmzl017l08kpqh498wpghq1cph641mdp5n")) + (patches (search-patches "tflite-micro_disable_download.patch")))) + (build-system gnu-build-system) + (arguments + (list + #:tests? #f ;there are no tests + #:phases + #~(modify-phases %standard-phases + (add-after 'unpack 'patch-makefile + (lambda _ + (let ((makefile "tensorflow/lite/micro/tools/make/Makefile")) + (substitute* makefile + (("BASE_GENDIR := gen") + "BASE_GENDIR := $(BUILD_DIR)"))))) + (delete 'configure) + + (replace 'build + (lambda _ + (let ((makefile "tensorflow/lite/micro/tools/make/Makefile")) + (mkdir-p "../build") + (invoke "make" + "-j" + (number->string (parallel-job-count)) + "-f" + makefile + (string-append "BASE_GENDIR=" "../build") + (string-append "PRE_INCLUDES=-I" + #$(this-package-input "gemmlowp") + "/include/gemmlowp" + " -I" + #$(this-package-input + "kissfft-for-tflite-micro") + "/include/kissfft" + " -I" + #$(package-source + kissfft-for-tflite-micro)))))) + (replace 'install + (lambda _ + (for-each (lambda (f) + (install-file f + (string-append #$output "/lib"))) + (find-files "../build" "\\.a$")) + (for-each (lambda (f) + (install-file f + (string-append #$output + "/include/lite/micro"))) + (find-files "tensorflow/lite/micro" "\\.h$")) + (for-each (lambda (f) + (install-file f + (string-append #$output + "/include/lite/micro"))) + (find-files "signal/micro/kernels" "\\.h$")) + (for-each (lambda (f) + (install-file f + (string-append #$output + "/include/lite/micro"))) + (find-files "signal/src" "\\.h$"))))))) + (inputs (list flatbuffers-23.5 gemmlowp kissfft-for-tflite-micro ruy)) + (native-inputs (list python python-pillow python-numpy)) + (home-page "https://ai.google.dev/edge/litert/microcontrollers/overview") + (synopsis + "Infrastructure to enable deployment of ML models to embedded targets ") + (description + "TensorFlow Lite for Microcontrollers is a port of TensorFlow Lite designed +to run machine learning models on DSPs, microcontrollers and other devices with +limited memory.") + (license license:asl2.0)))) + + (define-public dmlc-core (package (name "dmlc-core") diff --git a/gnu/packages/patches/tflite-micro_disable_download.patch b/gnu/packages/patches/tflite-micro_disable_download.patch new file mode 100644 index 0000000000000000000000000000000000000000..6b3ff1977426c094e87ef5e0538822bfff5a51c1 --- /dev/null +++ b/gnu/packages/patches/tflite-micro_disable_download.patch @@ -0,0 +1,62 @@ +diff --git a/tensorflow/lite/micro/tools/make/Makefile b/tensorflow/lite/micro/tools/make/Makefile +index a21765b3..e8cf2bd6 100644 +--- a/tensorflow/lite/micro/tools/make/Makefile ++++ b/tensorflow/lite/micro/tools/make/Makefile +@@ -90,7 +90,7 @@ EXTERNAL_DIR := + # This is the downloads directory inside the makefiles directory + DOWNLOADS_DIR := $(MAKEFILE_DIR)/downloads + +-INCLUDES := \ ++INCLUDES := $(PRE_INCLUDES) \ + -I. \ + -I$(DOWNLOADS_DIR) \ + -I$(DOWNLOADS_DIR)/gemmlowp \ +@@ -620,27 +620,27 @@ MICROLITE_CC_SRCS := $(filter-out $(MICROLITE_BENCHMARK_SRCS), $(MICROLITE_CC_SR + # improved error checking. To accomodate that, we first create a downloads + # directory. + $(shell mkdir -p ${DOWNLOADS_DIR}) +- +-# Directly download the flatbuffers library. +-DOWNLOAD_RESULT := $(shell $(MAKEFILE_DIR)/flatbuffers_download.sh ${DOWNLOADS_DIR} $(TENSORFLOW_ROOT)) +-ifneq ($(DOWNLOAD_RESULT), SUCCESS) +- $(error Something went wrong with the flatbuffers download: $(DOWNLOAD_RESULT)) +-endif +- +-DOWNLOAD_RESULT := $(shell $(MAKEFILE_DIR)/kissfft_download.sh ${DOWNLOADS_DIR} $(TENSORFLOW_ROOT)) +-ifneq ($(DOWNLOAD_RESULT), SUCCESS) +- $(error Something went wrong with the kissfft download: $(DOWNLOAD_RESULT)) +-endif +- +-DOWNLOAD_RESULT := $(shell $(MAKEFILE_DIR)/pigweed_download.sh ${DOWNLOADS_DIR} $(TENSORFLOW_ROOT)) +-ifneq ($(DOWNLOAD_RESULT), SUCCESS) +- $(error Something went wrong with the pigweed download: $(DOWNLOAD_RESULT)) +-endif +- +-include $(MAKEFILE_DIR)/third_party_downloads.inc +-THIRD_PARTY_DOWNLOADS := +-$(eval $(call add_third_party_download,$(GEMMLOWP_URL),$(GEMMLOWP_MD5),gemmlowp,)) +-$(eval $(call add_third_party_download,$(RUY_URL),$(RUY_MD5),ruy,)) ++# ++## Directly download the flatbuffers library. ++#DOWNLOAD_RESULT := $(shell $(MAKEFILE_DIR)/flatbuffers_download.sh ${DOWNLOADS_DIR} $(TENSORFLOW_ROOT)) ++#ifneq ($(DOWNLOAD_RESULT), SUCCESS) ++# $(error Something went wrong with the flatbuffers download: $(DOWNLOAD_RESULT)) ++#endif ++# ++#DOWNLOAD_RESULT := $(shell $(MAKEFILE_DIR)/kissfft_download.sh ${DOWNLOADS_DIR} $(TENSORFLOW_ROOT)) ++#ifneq ($(DOWNLOAD_RESULT), SUCCESS) ++# $(error Something went wrong with the kissfft download: $(DOWNLOAD_RESULT)) ++#endif ++# ++#DOWNLOAD_RESULT := $(shell $(MAKEFILE_DIR)/pigweed_download.sh ${DOWNLOADS_DIR} $(TENSORFLOW_ROOT)) ++#ifneq ($(DOWNLOAD_RESULT), SUCCESS) ++# $(error Something went wrong with the pigweed download: $(DOWNLOAD_RESULT)) ++#endif ++# ++#include $(MAKEFILE_DIR)/third_party_downloads.inc ++#THIRD_PARTY_DOWNLOADS := ++#$(eval $(call add_third_party_download,$(GEMMLOWP_URL),$(GEMMLOWP_MD5),gemmlowp,)) ++#$(eval $(call add_third_party_download,$(RUY_URL),$(RUY_MD5),ruy,)) + + # The target-specific makefile must have a name that is exactly + # TARGET_makefile.inc and is only needed for cross-compilation (i.e. when TARGET