You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by ar...@apache.org on 2022/07/12 21:48:07 UTC

[tvm] 22/47: Split TFLite runtime deps away from python

This is an automated email from the ASF dual-hosted git repository.

areusch pushed a commit to branch areusch/freeze-dependencies
in repository https://gitbox.apache.org/repos/asf/tvm.git

commit 0b94e7a904566612227c1032fe161f3e35bd343b
Author: Andrew Reusch <ar...@gmail.com>
AuthorDate: Wed Jun 8 20:41:20 2022 -0700

    Split TFLite runtime deps away from python
---
 cmake/config.cmake                              |  6 ++--
 cmake/modules/contrib/TFLite.cmake              | 11 +++++--
 docker/Dockerfile.ci_cpu                        |  6 ++--
 docker/Dockerfile.ci_gpu                        |  5 ++--
 docker/Dockerfile.ci_qemu                       |  6 ++--
 docker/install/ubuntu_install_tflite_runtime.sh | 39 +++++++++++++++++++++++++
 6 files changed, 59 insertions(+), 14 deletions(-)

diff --git a/cmake/config.cmake b/cmake/config.cmake
index b9a3aaef7d..405b5c1bce 100644
--- a/cmake/config.cmake
+++ b/cmake/config.cmake
@@ -184,10 +184,10 @@ set(USE_RANDOM ON)
 set(USE_NNPACK OFF)
 
 # Possible values:
-# - ON: enable tflite with cmake's find search
-# - OFF: disable tflite
+# - ON: enable tflite runtime with cmake's find search
+# - OFF: disable tflite runtime
 # - /path/to/libtensorflow-lite.a: use specific path to tensorflow lite library
-set(USE_TFLITE OFF)
+set(USE_TFLITE_RUNTIME OFF)
 
 # /path/to/tensorflow: tensorflow root path when use tflite library
 set(USE_TENSORFLOW_PATH none)
diff --git a/cmake/modules/contrib/TFLite.cmake b/cmake/modules/contrib/TFLite.cmake
index 3159710909..7629fdfb74 100644
--- a/cmake/modules/contrib/TFLite.cmake
+++ b/cmake/modules/contrib/TFLite.cmake
@@ -15,8 +15,13 @@
 # specific language governing permissions and limitations
 # under the License.
 
-if(NOT USE_TFLITE STREQUAL "OFF")
-  message(STATUS "Build with contrib.tflite")
+if(DEFINED USE_TFLITE AND NOT DEFINED USE_TFLITE_RUNTIME)
+  message(WARNING "USE_TFLITE is renamed to USE_TFLITE_RUNTIME; please update your config.cmake")
+  set(USE_TFLITE_RUNTIME "${USE_TFLITE}")
+endif()
+
+if(NOT USE_TFLITE_RUNTIME STREQUAL "OFF")
+  message(STATUS "Build with contrib.tflite runtime")
   if (USE_TENSORFLOW_PATH STREQUAL "none")
     set(USE_TENSORFLOW_PATH ${CMAKE_CURRENT_SOURCE_DIR}/tensorflow)
   endif()
@@ -34,7 +39,7 @@ if(NOT USE_TFLITE STREQUAL "OFF")
     list(APPEND TVM_RUNTIME_LINKER_LIBS ${USE_EDGETPU}/libedgetpu/direct/aarch64/libedgetpu.so.1)
   endif()
 
-  if (USE_TFLITE STREQUAL "ON")
+  if (USE_TFLITE_RUNTIME STREQUAL "ON")
     set(USE_TFLITE ${USE_TENSORFLOW_PATH}/tensorflow/lite/tools/make/gen/*/lib)
   endif()
   find_library(TFLITE_CONTRIB_LIB libtensorflow-lite.a ${USE_TFLITE})
diff --git a/docker/Dockerfile.ci_cpu b/docker/Dockerfile.ci_cpu
index 2117b77e77..6aeb13ec9e 100644
--- a/docker/Dockerfile.ci_cpu
+++ b/docker/Dockerfile.ci_cpu
@@ -111,9 +111,9 @@ RUN bash /install/ubuntu_install_verilator.sh
 # COPY install/ubuntu_install_tensorflow.sh /install/ubuntu_install_tensorflow.sh
 # RUN bash /install/ubuntu_install_tensorflow.sh
 
-# TFLite deps
-# COPY install/ubuntu_install_tflite.sh /install/ubuntu_install_tflite.sh
-# RUN bash /install/ubuntu_install_tflite.sh
+# TFLite runtime deps
+COPY install/ubuntu_install_tflite_runtime.sh /install/ubuntu_install_tflite_runtime.sh
+RUN bash /install/ubuntu_install_tflite_runtime.sh
 
 # Compute Library
 COPY install/ubuntu_download_arm_compute_lib_binaries.sh /install/ubuntu_download_arm_compute_lib_binaries.sh
diff --git a/docker/Dockerfile.ci_gpu b/docker/Dockerfile.ci_gpu
index c845c215f9..471ecf9849 100644
--- a/docker/Dockerfile.ci_gpu
+++ b/docker/Dockerfile.ci_gpu
@@ -92,8 +92,9 @@ RUN bash /install/ubuntu_install_gluoncv.sh
 COPY install/ubuntu_install_libtorch.sh /install/ubuntu_install_libtorch.sh
 RUN bash /install/ubuntu_install_libtorch.sh
 
-# COPY install/ubuntu_install_tflite.sh /install/ubuntu_install_tflite.sh
-# RUN bash /install/ubuntu_install_tflite.sh
+# TFLite runtime deps
+COPY install/ubuntu_install_tflite_runtime.sh /install/ubuntu_install_tflite_runtime.sh
+RUN bash /install/ubuntu_install_tflite_runtime.sh
 
 COPY install/ubuntu_install_dgl.sh /install/ubuntu_install_dgl.sh
 RUN bash /install/ubuntu_install_dgl.sh
diff --git a/docker/Dockerfile.ci_qemu b/docker/Dockerfile.ci_qemu
index 86652f582a..ff8c2dcdd7 100644
--- a/docker/Dockerfile.ci_qemu
+++ b/docker/Dockerfile.ci_qemu
@@ -60,9 +60,9 @@ RUN bash /install/ubuntu_install_java.sh
 # COPY install/ubuntu_install_tensorflow.sh /install/ubuntu_install_tensorflow.sh
 # RUN bash /install/ubuntu_install_tensorflow.sh
 
-# TFLite deps
-# COPY install/ubuntu_install_tflite.sh /install/ubuntu_install_tflite.sh
-# RUN bash /install/ubuntu_install_tflite.sh
+# TFLite runtime deps
+COPY install/ubuntu_install_tflite_runtime.sh /install/ubuntu_install_tflite_runtime.sh
+RUN bash /install/ubuntu_install_tflite_runtime.sh
 
 # sccache
 COPY install/ubuntu_install_sccache.sh /install/ubuntu_install_sccache.sh
diff --git a/docker/install/ubuntu_install_tflite_runtime.sh b/docker/install/ubuntu_install_tflite_runtime.sh
new file mode 100755
index 0000000000..a7a61497df
--- /dev/null
+++ b/docker/install/ubuntu_install_tflite_runtime.sh
@@ -0,0 +1,39 @@
+#!/bin/bash
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+set -e
+set -u
+set -o pipefail
+
+# The tflite version should have matched versions to the tensorflow
+# version installed from pip in ubuntu_install_tensorflow.sh
+TENSORFLOW_VERSION=$(python3 -c "import tensorflow; print(tensorflow.__version__)" 2> /dev/null)
+
+# Download, build and install flatbuffers
+git clone --branch=v1.12.0 --depth=1 --recursive https://github.com/google/flatbuffers.git
+cd flatbuffers
+cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release
+make install -j8
+cd ..
+
+# Build the TFLite static library, necessary for building with TFLite ON.
+# The library is built at:
+# tensorflow/tensorflow/lite/tools/make/gen/*/lib/libtensorflow-lite.a.
+git clone https://github.com/tensorflow/tensorflow --branch=v${TENSORFLOW_VERSION} --depth 1
+./tensorflow/tensorflow/lite/tools/make/download_dependencies.sh
+./tensorflow/tensorflow/lite/tools/make/build_lib.sh