File indexing completed on 2026-03-30 07:48:32
0001
0002
0003
0004
0005
0006 from spack.package import *
0007 from spack_repo.builtin.build_systems.cmake import CMakePackage
0008 import os
0009
0010
0011 class TensorflowLite(CMakePackage):
0012 """TensorFlow Lite is TensorFlow's lightweight solution for mobile and
0013 embedded devices. It enables low-latency inference of on-device machine
0014 learning models with a small binary size and fast performance supporting
0015 hardware acceleration."""
0016
0017 homepage = "https://www.tensorflow.org/lite/"
0018 url = "https://github.com/tensorflow/tensorflow/archive/refs/tags/v2.8.0.tar.gz"
0019
0020 maintainers = ["wdconinc"]
0021
0022 version(
0023 "2.9.1",
0024 sha256="6eaf86ead73e23988fe192da1db68f4d3828bcdd0f3a9dc195935e339c95dbdc",
0025 )
0026 version(
0027 "2.9.0",
0028 sha256="8087cb0c529f04a4bfe480e49925cd64a904ad16d8ec66b98e2aacdfd53c80ff",
0029 )
0030 version(
0031 "2.8.2",
0032 sha256="b3f860c02c22a30e9787e2548ca252ab289a76b7778af6e9fa763d4aafd904c7",
0033 )
0034 version(
0035 "2.8.1",
0036 sha256="4b487a63d6f0c1ca46a2ac37ba4687eabdc3a260c222616fa414f6df73228cec",
0037 )
0038 version(
0039 "2.8.0",
0040 sha256="66b953ae7fba61fd78969a2e24e350b26ec116cf2e6a7eb93d02c63939c6f9f7",
0041 )
0042
0043 variant("gpu", default=False, description="Enable GPU support")
0044 variant("metal", default=False, description="Enable Metal support")
0045 variant("xnnpack", default=True, description="Enable XNNPACK support")
0046 variant("shared", default=False, description="Build shared libraries")
0047
0048 depends_on("cmake@3.16:", type="build")
0049
0050 depends_on("c", type="build")
0051 depends_on("cxx", type="build")
0052
0053
0054 depends_on("abseil-cpp")
0055 depends_on("eigen")
0056 depends_on("flatbuffers")
0057 depends_on("fp16")
0058 depends_on("gemmlowp")
0059 depends_on("psimd")
0060 depends_on("pthreadpool")
0061 depends_on("farmhash")
0062
0063
0064 depends_on("cpuinfo")
0065
0066
0067
0068 depends_on("opencl", when="gpu")
0069
0070
0071
0072
0073
0074
0075 depends_on("xnnpack", when="xnnpack")
0076
0077 root_cmakelists_dir = "tensorflow/lite"
0078
0079 def patch(self):
0080
0081 filter_file(
0082 "^add_subdirectory", "#add_subdirectory", "tensorflow/lite/CMakeLists.txt"
0083 )
0084
0085 def cmake_args(self):
0086 args = [
0087 self.define_from_variant("TFLITE_ENABLE_GPU", "gpu"),
0088 self.define_from_variant("TFLITE_ENABLE_METAL", "metal"),
0089 self.define_from_variant("TFLITE_ENABLE_XNNPACK", "xnnpack"),
0090 self.define_from_variant("BUILD_SHARED_LIBS", "shared"),
0091 self.define("TFLITE_KERNEL_TEST", self.run_tests),
0092 ]
0093 return args
0094
0095 def install(self, spec, prefix):
0096
0097 super().install(spec, prefix)
0098
0099
0100 mkdirp(self.prefix.lib)
0101 with working_dir(self.build_directory):
0102 for l in find(".", "libtensorflow-lite.*", recursive=False):
0103 install(l, self.prefix.lib)
0104
0105
0106 mkdirp(self.prefix.include)
0107 for h in find(
0108 join_path(self.stage.source_path, "tensorflow/lite"), "*.h", recursive=True
0109 ):
0110 relpath = os.path.relpath(h)
0111 dirname = os.path.dirname(relpath)
0112 installdir = join_path(self.prefix.include, dirname)
0113 mkdirp(installdir)
0114 install(h, installdir)
0115
0116
0117 for d in ["flatbuffers"]:
0118 install_tree(
0119 join_path(self.build_directory, d, "include"), self.prefix.include
0120 )