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