gnu: tensorflow-lite: Update to 2.12.1.

* gnu/packages/algebra.scm (eigen-for-tensorflow-lite): Remove variable.
* gnu/packages/machine-learning.scm (tensorflow-lite): Update to 2.12.1
[arguments]<configure-flags>: Turn on GPU and RUY use; Use cmake to
find packages already in Guix as dependencies for absl-cpp, eigen,
flatbuffer, neon2ssl, cpuinfo, ruy.
[arguments]<phases>: Remove operations setting up absl-cpp, eigen, ruy,
and neon2ssl as native inouts as now we use Guix's packages of these
as dependencies. Do default build phase.
Add steps to install C shared library and benchmark_model tool.
[inputs]: Add cpuinfo, eigen, fp16, mesa-header, opencl,
pthreadpool, ruy, vulkan and xnnpack as explicit inputs.
[native-inputs]: Remove local setup of neon2ssl and ruy
as we now use Guix's packages of these as explicit dependencies.
* gnu/packages/serialization.scm (flatbuffers-next-shared): New variable,
flatbuffers-next built with -fPIC as needed by tensorflow-lite.

Signed-off-by: Ricardo Wurmus <rekado@elephly.net>
This commit is contained in:
Andy Tai 2023-09-02 21:55:18 -07:00 committed by Ricardo Wurmus
parent 2d366e309b
commit 3eb77954f9
No known key found for this signature in database
GPG key ID: 197A5888235FACAC
3 changed files with 140 additions and 135 deletions

View file

@ -1154,38 +1154,6 @@ (define-public eigen-for-tensorflow
(substitute* "test/CMakeLists.txt" (substitute* "test/CMakeLists.txt"
(("ei_add_test\\(stddeque") "#"))))))))))) (("ei_add_test\\(stddeque") "#")))))))))))
(define-public eigen-for-tensorflow-lite
;; This commit was taken from
;; tensorflow/lite/tools/cmake/modules/eigen.cmake
(let ((commit "d10b27fe37736d2944630ecd7557cefa95cf87c9")
(revision "1"))
(package (inherit eigen)
(name "eigen-for-tensorflow-lite")
(version (git-version "3.3.7" revision commit))
(source (origin
(method git-fetch)
(uri (git-reference
(url "https://gitlab.com/libeigen/eigen")
(commit commit)))
(sha256
(base32
"0v8a20cwvwmp3hw4275b37frw33v92z0mr8f4dn6y8k0rz92hrrf"))
(file-name (git-file-name name version))
(modules '((guix build utils)))
(snippet
;; Ther are test failures in the "unsupported" directory, but
;; maintainers say it's unsupported anyway, so just skip
;; them.
'(begin
(substitute* "unsupported/CMakeLists.txt"
(("add_subdirectory\\(test.*")
"# Do not build the tests for unsupported features.\n"))))))
(arguments
(substitute-keyword-arguments (package-arguments eigen)
((#:phases phases)
`(modify-phases ,phases
(delete 'disable-some-tests))))))))
(define-public xtensor (define-public xtensor
(package (package
(name "xtensor") (name "xtensor")

View file

@ -55,12 +55,14 @@ (define-module (gnu packages machine-learning)
#:use-module (gnu packages) #:use-module (gnu packages)
#:use-module (gnu packages adns) #:use-module (gnu packages adns)
#:use-module (gnu packages algebra) #:use-module (gnu packages algebra)
#:use-module (gnu packages assembly)
#:use-module (gnu packages audio) #:use-module (gnu packages audio)
#:use-module (gnu packages autotools) #:use-module (gnu packages autotools)
#:use-module (gnu packages base) #:use-module (gnu packages base)
#:use-module (gnu packages bash) #:use-module (gnu packages bash)
#:use-module (gnu packages boost) #:use-module (gnu packages boost)
#:use-module (gnu packages bdw-gc) #:use-module (gnu packages bdw-gc)
#:use-module (gnu packages c)
#:use-module (gnu packages check) #:use-module (gnu packages check)
#:use-module (gnu packages compression) #:use-module (gnu packages compression)
#:use-module (gnu packages cmake) #:use-module (gnu packages cmake)
@ -89,6 +91,7 @@ (define-module (gnu packages machine-learning)
#:use-module (gnu packages ninja) #:use-module (gnu packages ninja)
#:use-module (gnu packages ocaml) #:use-module (gnu packages ocaml)
#:use-module (gnu packages onc-rpc) #:use-module (gnu packages onc-rpc)
#:use-module (gnu packages opencl)
#:use-module (gnu packages parallel) #:use-module (gnu packages parallel)
#:use-module (gnu packages perl) #:use-module (gnu packages perl)
#:use-module (gnu packages pkg-config) #:use-module (gnu packages pkg-config)
@ -100,6 +103,7 @@ (define-module (gnu packages machine-learning)
#:use-module (gnu packages python-science) #:use-module (gnu packages python-science)
#:use-module (gnu packages python-web) #:use-module (gnu packages python-web)
#:use-module (gnu packages python-xyz) #:use-module (gnu packages python-xyz)
#:use-module (gnu packages regex)
#:use-module (gnu packages rpc) #:use-module (gnu packages rpc)
#:use-module (gnu packages serialization) #:use-module (gnu packages serialization)
#:use-module (gnu packages sphinx) #:use-module (gnu packages sphinx)
@ -108,6 +112,7 @@ (define-module (gnu packages machine-learning)
#:use-module (gnu packages swig) #:use-module (gnu packages swig)
#:use-module (gnu packages time) #:use-module (gnu packages time)
#:use-module (gnu packages tls) #:use-module (gnu packages tls)
#:use-module (gnu packages vulkan)
#:use-module (gnu packages video) #:use-module (gnu packages video)
#:use-module (gnu packages web) #:use-module (gnu packages web)
#:use-module (gnu packages xml) #:use-module (gnu packages xml)
@ -2967,7 +2972,7 @@ (define-public tensorflow
(define-public tensorflow-lite (define-public tensorflow-lite
(package (package
(name "tensorflow-lite") (name "tensorflow-lite")
(version "2.5.0") (version "2.12.1")
(source (source
(origin (origin
(method git-fetch) (method git-fetch)
@ -2977,97 +2982,141 @@ (define-public tensorflow-lite
(file-name (git-file-name name version)) (file-name (git-file-name name version))
(sha256 (sha256
(base32 (base32
"1jdw2i1rq06zqd6aabh7bbm0avsg4pygnfmd7gviv0blhih9054l")))) "0jkgljdagdqllnxygl35r5bh3f9qmbczymfj357gm9krh59g2kmd"))))
(build-system cmake-build-system) (build-system cmake-build-system)
(arguments (arguments
`(#:tests? #false ; no "check" target (list
#:build-type "Release" #:tests? #false ;tests are not building now
#:configure-flags #:build-type "Release"
(list #:modules '((ice-9 match)
"-DTFLITE_ENABLE_GPU=OFF" (guix build utils)
"-DTFLITE_ENABLE_RUY=OFF" (guix build cmake-build-system))
#:configure-flags
#~(list
;; "-DTFLITE_KERNEL_TEST=ON" ; TODO: build tests
;; so cmake can be used to find this from other packages
"-DTFLITE_ENABLE_INSTALL=ON"
;; TODO: The build system attempts to build xnnpack from source. We ;; Use Guix's own packages as dependencies.
;; would like to use our xnnpack package here, but this requires more "-DCMAKE_FIND_PACKAGE_PREFER_CONFIG=ON"
;; work.
"-DTFLITE_ENABLE_XNNPACK=OFF"
;; Pretend we've already fetched abseil. We won't actually build it "-DTFLITE_ENABLE_GPU=ON"
;; but use the existing package. "-DTFLITE_ENABLE_RUY=ON"
"-Dabseil-cpp_POPULATED=TRUE"
;; Don't fetch the sources. We have already built flatbuffers. ;; TODO: turn on Farmhash
"-Dflatbuffers_POPULATED=TRUE" ;;"-DSYSTEM_FARMHASH=ON"
(string-append "-Dabsl_DIR=" #$(this-package-input "abseil-cpp")
"/lib/cmake/absl")
(string-append "-DEigen3_DIR=" #$(this-package-input "eigen")
"/share/eigen3/cmake")
(string-append "-DFlatBuffers_DIR="
#$(this-package-input "flatbuffers-shared")
"/lib/cmake/flatbuffers")
(string-append "-DNEON_2_SSE_DIR=" #$(this-package-input "neon2sse")
"/lib/cmake/NEON_2_SSE")
(string-append "-Dcpuinfo_DIR=" #$(this-package-input "cpuinfo")
"/share/cpuinfo")
(string-append "-Druy_DIR=" #$(this-package-input "ruy")
"/lib/cmake/ruy")
"-DFFT2D_SOURCE_DIR=/tmp/fft2d" ;; TODO: The build system attempts to build xnnpack from source. We
"-Dneon2sse_SOURCE_DIR=/tmp/neon2sse" ;; would like to use our xnnpack package here, but this requires more
"-Dneon2sse_BINARY_DIR=/tmp/neon2sse-bin" ;; work.
"-DFARMHASH_SOURCE_DIR=/tmp/farmhash" "-DTFLITE_ENABLE_XNNPACK=OFF"
"-Dgemmlowp_SOURCE_DIR=/tmp/gemmlowp"
(string-append "-DRUY_SOURCE_DIR="
(assoc-ref %build-inputs "ruy-src")))
#:phases
(modify-phases %standard-phases
(add-after 'unpack 'chdir
(lambda _ (chdir "tensorflow/lite")))
(add-after 'chdir 'copy-sources
(lambda* (#:key inputs #:allow-other-keys)
;; Use external cmake finders instead of these stubs that won't
;; find anything but the bundled sources.
(delete-file "tools/cmake/modules/Findabsl.cmake")
(delete-file "tools/cmake/modules/Findeigen.cmake")
(substitute* "CMakeLists.txt" ;; Don't fetch the sources. We have these already
(("find_package\\(eigen REQUIRED") "-Degl_headers_POPULATED=TRUE"
"find_package(eigen REQUIRED NAMES Eigen3")) "-Dfp16_headers_POPULATED=TRUE"
(substitute* "tools/cmake/modules/Findflatbuffers.cmake" "-Dopencl_headers_POPULATED=TRUE"
(("get_target_property.*") "-Dopengl_headers_POPULATED=TRUE"
(format #false "set(FLATBUFFERS_INCLUDE_DIRS ~a/include)\n" "-Dvulkan_headers_POPULATED=TRUE"
(assoc-ref inputs "flatbuffers")))) "-Dgoogletest_POPULATED=TRUE"
"-Dgoogle_benchmark_POPULATED=TRUE"
"-Dnsync_POPULATED=TRUE"
"-Dre2_POPULATED=TRUE"
;; Don't fetch source code; we already have everything we need. "-DFFT2D_SOURCE_DIR=/tmp/fft2d"
(substitute* '("tools/cmake/modules/fft2d.cmake" "-DFARMHASH_SOURCE_DIR=/tmp/farmhash"
"tools/cmake/modules/ruy.cmake" "-Dgemmlowp_SOURCE_DIR=/tmp/gemmlowp")
"tools/cmake/modules/farmhash.cmake" #:phases
"tools/cmake/modules/neon2sse.cmake" #~(modify-phases %standard-phases
"tools/cmake/modules/gemmlowp.cmake") (add-after 'unpack 'chdir
(("OverridableFetchContent_Populate.*") "")) (lambda _ (chdir "tensorflow/lite")))
(add-after 'chdir 'copy-sources
(lambda* (#:key inputs #:allow-other-keys)
;; TODO: properly use Guix's pthreaqdpool. We are not using
;; pthreadpool because we are not enabling xnnpack
(substitute* "CMakeLists.txt"
(("if\\(NOT DEFINED PTHREADPOOL_SOURCE_DIR\\)")
"if(false)"))
(substitute* "CMakeLists.txt"
(("if\\(NOT TARGET pthreadpool\\)")
"if(false)"))
(mkdir-p "/tmp/farmhash") ;; Don't fetch source code; we already have everything we need.
(with-directory-excursion "/tmp/farmhash" (substitute* '("tools/cmake/modules/fft2d.cmake"
(invoke "tar" "--strip-components=1" "tools/cmake/modules/farmhash.cmake"
"-xf" (assoc-ref inputs "farmhash-src"))) "tools/cmake/modules/gemmlowp.cmake")
(("OverridableFetchContent_Populate.*") ""))
(mkdir-p "/tmp/fft2d") (mkdir-p "/tmp/farmhash")
(with-directory-excursion "/tmp/fft2d" (with-directory-excursion "/tmp/farmhash"
(invoke "tar" "--strip-components=1" (invoke "tar" "--strip-components=1"
"-xf" (assoc-ref inputs "fft2d-src"))) "-xf" (assoc-ref inputs "farmhash-src")))
(copy-recursively (assoc-ref inputs "neon2sse-src") (mkdir-p "/tmp/fft2d")
"/tmp/neon2sse/") (with-directory-excursion "/tmp/fft2d"
(copy-recursively (assoc-ref inputs "gemmlowp-src") (invoke "tar" "--strip-components=1"
"/tmp/gemmlowp/"))) "-xf" (assoc-ref inputs "fft2d-src")))
(add-after 'copy-sources 'prepare-shared-library-build
(lambda _ (chdir "c"))) (copy-recursively (assoc-ref inputs "gemmlowp-src")
(replace 'install "/tmp/gemmlowp/")))
(lambda* (#:key outputs #:allow-other-keys)
(let* ((out (assoc-ref outputs "out")) (add-after 'build 'build-shared-library
(lib (string-append out "/lib")) (lambda* (#:key configure-flags #:allow-other-keys)
(headers (string-append out "/include/tensorflow/lite"))) (mkdir-p "c")
(install-file "../build/libtensorflowlite_c.so" lib) (with-directory-excursion "c"
(with-directory-excursion ".." (apply invoke "cmake" (append configure-flags (list "../../lite/c")))
(for-each (invoke "cmake" "--build" "." "-j" (number->string
(lambda (file) (parallel-job-count))))))
(let ((target-dir (string-append headers "/" (dirname file)))) (add-after 'build-shared-library 'build-benchmark-model
(install-file file target-dir))) (lambda _
(find-files "." "\\.h$"))))))))) (invoke "cmake" "--build" "." "--target" "benchmark_model"
"-j" (number->string (parallel-job-count)))))
(add-after 'install 'install-extra
(lambda* (#:key outputs #:allow-other-keys)
(let* ((out (assoc-ref outputs "out"))
(lib (string-append out "/lib"))
(bin (string-append out "/bin")))
(install-file "../build/c/libtensorflowlite_c.so" lib)
(install-file "../build/tools/benchmark/benchmark_model" bin))))
(replace 'check
(lambda* (#:key tests? #:allow-other-keys)
(when tests?
(invoke "ctest" "-L" "plain")))))))
(inputs (inputs
`(("abseil-cpp" ,abseil-cpp-20200923.3) `(("abseil-cpp" ,abseil-cpp-20200923.3)
("eigen" ,eigen-for-tensorflow-lite) ("cpuinfo" ,cpuinfo)
("flatbuffers" ,flatbuffers) ("eigen" ,eigen)
("python" ,python))) ("fp16" ,fp16)
("flatbuffers-shared" ,flatbuffers-next-shared)
;;("gemmlowp" ,gemmlowp) ; TODO
("mesa-headers" ,mesa-headers)
("neon2sse" ,neon2sse)
("nsync" ,nsync)
("opencl-clhpp" ,opencl-clhpp)
("opencl-headers" ,opencl-headers)
("opencl-icd-loader" ,opencl-icd-loader)
("pthreadpool" ,pthreadpool)
("python" ,python)
("ruy" ,ruy)
("re2" ,re2)
;;("xnnpack" ,xnnpack) ; TODO: use Guix's copy of xnnpack
("vulkan-headers" ,vulkan-headers)))
(native-inputs (native-inputs
`(("pkg-config" ,pkg-config) `(("pkg-config" ,pkg-config)
("googletest" ,googletest)
("gemmlowp-src" ("gemmlowp-src"
;; The commit hash is taken from ;; The commit hash is taken from
;; "tensorflow/lite/tools/cmake/modules/gemmlowp.cmake". ;; "tensorflow/lite/tools/cmake/modules/gemmlowp.cmake".
@ -3081,17 +3130,6 @@ (define-public tensorflow-lite
(sha256 (sha256
(base32 (base32
"1sbp8kmr2azwlvfbzryy1frxi99jhsh1nc93bdbxdf8zdgpv0kxl"))))) "1sbp8kmr2azwlvfbzryy1frxi99jhsh1nc93bdbxdf8zdgpv0kxl")))))
("neon2sse-src"
,(let ((commit "a1652fd5253afbf3e39357b012974f93511f6108"))
(origin
(method git-fetch)
(uri (git-reference
(url "https://github.com/intel/ARM_NEON_2_x86_SSE")
(commit commit)))
(file-name (git-file-name "neon2sse" (string-take commit 8)))
(sha256
(base32
"1q8gkxag9wlnwdwad2pclsrkwzrdjy94hyrkayrsvxyj7szb5y8i")))))
("farmhash-src" ("farmhash-src"
,(let ((commit "816a4ae622e964763ca0862d9dbd19324a1eaf45")) ,(let ((commit "816a4ae622e964763ca0862d9dbd19324a1eaf45"))
(origin (origin
@ -3107,24 +3145,12 @@ (define-public tensorflow-lite
,(origin ,(origin
(method url-fetch) (method url-fetch)
(uri (string-append "https://storage.googleapis.com/" (uri (string-append "https://storage.googleapis.com/"
"mirror.tensorflow.org/" "mirror.tensorflow.org/github.com/petewarden/"
"www.kurims.kyoto-u.ac.jp/~ooura/fft2d.tgz")) "OouraFFT/archive/v1.0.tar.gz"))
(file-name "fft2d.tar.gz") (file-name "fft2d.tar.gz")
(sha256 (sha256
(base32 (base32
"1jfflzi74fag9z4qmgwvp90aif4dpbr1657izmxlgvf4hy8fk9xd")))) "1jfflzi74fag9z4qmgwvp90aif4dpbr1657izmxlgvf4hy8fk9xd"))))))
("ruy-src"
,(let ((commit "9c56af3fce210a8a103eda19bd6f47c08a9e3d90"))
(origin
(method git-fetch)
(uri (git-reference
(url "https://github.com/google/ruy")
(commit commit)
(recursive? #true)))
(file-name (git-file-name "ruy" (string-take commit 8)))
(sha256
(base32
"1cfd5gk6kaj8kbl3h98gx1ap8czd59y6p8qq8nr28fklpyzf5cis")))))))
(home-page "https://tensorflow.org") (home-page "https://tensorflow.org")
(synopsis "Machine learning framework") (synopsis "Machine learning framework")
(description (description

View file

@ -811,6 +811,17 @@ (define-public flatbuffers-next
(base32 (base32
"1z3a6l8g2y53i5xzraswfs2i0i3kk52zv7nzc2q3fgisbyiri3pz")))))) "1z3a6l8g2y53i5xzraswfs2i0i3kk52zv7nzc2q3fgisbyiri3pz"))))))
(define-public flatbuffers-next-shared
(package
(inherit flatbuffers-next)
(name "flatbuffers-shared")
(version "23.1.21")
(arguments
(substitute-keyword-arguments (package-arguments flatbuffers-next)
((#:configure-flags flags)
;; Compile with -fPIC, needed for shared lib.
#~(cons "-DFLATBUFFERS_CXX_FLAGS=-fPIC" #$flags))))))
(define-public python-feather-format (define-public python-feather-format
(package (package
(name "python-feather-format") (name "python-feather-format")