This is an automated email from the ASF dual-hosted git repository.
gromero pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git
The following commit(s) were added to refs/heads/main by this push:
new d6f78b1acc [microTVM] Update Zephyr version and Zephyr SDK version
(#13818)
d6f78b1acc is described below
commit d6f78b1accfa481dc5473fe6c47c724bd1fe465e
Author: Mehrdad Hessar <[email protected]>
AuthorDate: Wed Feb 1 06:30:25 2023 -0800
[microTVM] Update Zephyr version and Zephyr SDK version (#13818)
This commit updates the microTVM code to use Zephyr 3.2 and SDK 0.15.2.
As a result of this change, there are a few other changes that are
included:
- A launch script was added for Zephyr and Arduino template project to
run the Project API server from a different Python ENV than TVM Python
ENV;
- For Zephyr, the launch script uses global python3.8 which is where
west is registered. However, for Arduino it uses a separate virtual ENV
with python3 version that exists in the host;
- tests/micro/project_api/test_arduino_microtvm_api_server.py was
removed since these tests were using Arduino microTVM API server by
importing it from TVM. We no longer support Arduino/Zephyr dependencies
in TVM testing python ENV;
- Disables a demo and test due to a CMSIS-NN bug:
[Bug] CMSIS-NN BYOC fails with Zephyr 3.2 #13856;
There will be a follow up work to move Zephyr to a completely separate
virtual ENV as it was done in this commit for Arduino in the launch
script.
---
.../template_project/launch_microtvm_api_server.sh | 37 ++--
.../template_project/microtvm_api_server.py | 13 +-
.../template_project/launch_microtvm_api_server.sh | 32 ++--
.../zephyr/template_project/microtvm_api_server.py | 41 +++--
.../src/aot_standalone_demo/main.c | 5 +-
.../src/aot_standalone_demo/zephyr_uart.c | 6 +-
.../zephyr/template_project/src/host_driven/main.c | 22 +--
.../src/mlperftiny/submitter_implemented.cc | 4 +-
.../template_project/src/mlperftiny/tvmruntime.cc | 4 +-
.../template_project/src/mlperftiny/zephyr_uart.cc | 6 +-
apps/microtvm/zephyr_cmsisnn/src/main.c | 4 +-
ci/jenkins/docker-images.ini | 2 +-
cmake/modules/Arduino.cmake | 2 +
cmake/modules/Zephyr.cmake | 2 +
.../how_to/work_with_microtvm/install_zephyr.rst | 14 +-
gallery/how_to/work_with_microtvm/micro_train.py | 5 +-
python/tvm/micro/project_api/client.py | 14 +-
.../test_arduino_microtvm_api_server.py | 200 ---------------------
tests/micro/project_api/test_project_api.py | 33 +++-
tests/micro/zephyr/test_zephyr.py | 1 +
tests/scripts/task_demo_microtvm.sh | 7 +-
21 files changed, 151 insertions(+), 303 deletions(-)
diff --git a/tests/scripts/task_demo_microtvm.sh
b/apps/microtvm/arduino/template_project/launch_microtvm_api_server.sh
similarity index 55%
copy from tests/scripts/task_demo_microtvm.sh
copy to apps/microtvm/arduino/template_project/launch_microtvm_api_server.sh
index 8a79373fba..80f3e5bd74 100755
--- a/tests/scripts/task_demo_microtvm.sh
+++ b/apps/microtvm/arduino/template_project/launch_microtvm_api_server.sh
@@ -1,4 +1,4 @@
-#!/usr/bin/env bash
+#!/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
@@ -16,23 +16,28 @@
# specific language governing permissions and limitations
# under the License.
-set -euxo pipefail
+function show_usage() {
+ cat <<EOF
+This script is for running microtvm_api_server with Arduino.
+Usage: launch_microtvm_api_server.sh <microtvm_api_server.py> --read-fd
<READ_FD_PATH> --write-fd <WRITE_FD_PATH>
+EOF
+}
-source tests/scripts/setup-pytest-env.sh
+if [ "$#" -lt 5 -o "$1" == "--help" ]; then
+ show_usage
+ exit -1
+fi
-pushd apps/microtvm/cmsisnn
- timeout 5m ./run_demo.sh
-popd
+ARDUINO_VENV_PATH=${HOME}/.tvm/micro_arduino
-pushd apps/microtvm/zephyr_cmsisnn
- timeout 5m ./run_demo.sh
-popd
+# Create virtual env
+mkdir -p ${HOME}/.tvm
+PYTHON_CMD=$(which python3)
+$PYTHON_CMD -m venv ${ARDUINO_VENV_PATH}
+ARDUINO_PYTHON_CMD="${ARDUINO_VENV_PATH}/bin/python3"
-pushd apps/microtvm/ethosu
-FVP_PATH="/opt/arm/FVP_Corstone_SSE-300_Ethos-U55"
-CMAKE_PATH="/opt/arm/cmake/bin/cmake"
-FREERTOS_PATH="/opt/freertos/FreeRTOSv202112.00"
+# Install dependencies
+$ARDUINO_PYTHON_CMD -m pip install pyusb packaging
- timeout 5m ./run_demo.sh --fvp_path $FVP_PATH --cmake_path $CMAKE_PATH
- timeout 5m ./run_demo.sh --fvp_path $FVP_PATH --cmake_path $CMAKE_PATH
--freertos_path $FREERTOS_PATH
-popd
+# Run server
+$ARDUINO_PYTHON_CMD $1 $2 $3 $4 $5
diff --git a/apps/microtvm/arduino/template_project/microtvm_api_server.py
b/apps/microtvm/arduino/template_project/microtvm_api_server.py
index 4e8ee32c37..05c17ee194 100644
--- a/apps/microtvm/arduino/template_project/microtvm_api_server.py
+++ b/apps/microtvm/arduino/template_project/microtvm_api_server.py
@@ -28,7 +28,7 @@ import time
from string import Template
from packaging import version
-from tvm.micro.project_api import server
+import server
_LOG = logging.getLogger(__name__)
@@ -387,7 +387,16 @@ class Handler(server.ProjectAPIHandler):
source_dir.mkdir()
# Copies files from the template folder to project_dir
- shutil.copy2(API_SERVER_DIR / "microtvm_api_server.py", project_dir)
+ for file in os.listdir(API_SERVER_DIR):
+ if file.endswith(".py"):
+ shutil.copy2(API_SERVER_DIR / file, project_dir / file)
+
+ # Copy launch script
+ shutil.copy2(
+ API_SERVER_DIR / "launch_microtvm_api_server.sh",
+ project_dir / "launch_microtvm_api_server.sh",
+ )
+
shutil.copy2(BOARDS, project_dir / BOARDS.name)
self._copy_project_files(API_SERVER_DIR, project_dir, project_type)
diff --git a/tests/scripts/task_demo_microtvm.sh
b/apps/microtvm/zephyr/template_project/launch_microtvm_api_server.sh
similarity index 58%
copy from tests/scripts/task_demo_microtvm.sh
copy to apps/microtvm/zephyr/template_project/launch_microtvm_api_server.sh
index 8a79373fba..1531c453dc 100755
--- a/tests/scripts/task_demo_microtvm.sh
+++ b/apps/microtvm/zephyr/template_project/launch_microtvm_api_server.sh
@@ -1,4 +1,4 @@
-#!/usr/bin/env bash
+#!/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
@@ -16,23 +16,19 @@
# specific language governing permissions and limitations
# under the License.
-set -euxo pipefail
+function show_usage() {
+ cat <<EOF
+This script is for running microtvm_api_server with Zephyr.
+Usage: launch_microtvm_api_server.sh <microtvm_api_server.py> --read-fd
<READ_FD_PATH> --write-fd <WRITE_FD_PATH>
+EOF
+}
-source tests/scripts/setup-pytest-env.sh
+if [ "$#" -lt 5 -o "$1" == "--help" ]; then
+ show_usage
+ exit -1
+fi
-pushd apps/microtvm/cmsisnn
- timeout 5m ./run_demo.sh
-popd
+PYTHON_CMD=$(sed 's/#!//; q' $(which west))
-pushd apps/microtvm/zephyr_cmsisnn
- timeout 5m ./run_demo.sh
-popd
-
-pushd apps/microtvm/ethosu
-FVP_PATH="/opt/arm/FVP_Corstone_SSE-300_Ethos-U55"
-CMAKE_PATH="/opt/arm/cmake/bin/cmake"
-FREERTOS_PATH="/opt/freertos/FreeRTOSv202112.00"
-
- timeout 5m ./run_demo.sh --fvp_path $FVP_PATH --cmake_path $CMAKE_PATH
- timeout 5m ./run_demo.sh --fvp_path $FVP_PATH --cmake_path $CMAKE_PATH
--freertos_path $FREERTOS_PATH
-popd
+# Run server
+$PYTHON_CMD $1 $2 $3 $4 $5
diff --git a/apps/microtvm/zephyr/template_project/microtvm_api_server.py
b/apps/microtvm/zephyr/template_project/microtvm_api_server.py
index 0bafd7066d..17dd991229 100644
--- a/apps/microtvm/zephyr/template_project/microtvm_api_server.py
+++ b/apps/microtvm/zephyr/template_project/microtvm_api_server.py
@@ -44,7 +44,7 @@ import serial
import serial.tools.list_ports
import yaml
-from tvm.micro.project_api import server
+import server
_LOG = logging.getLogger(__name__)
@@ -68,7 +68,7 @@ CMAKELIST_FILENAME = "CMakeLists.txt"
# Used to check Zephyr version installed on the host.
# We only check two levels of the version.
-ZEPHYR_VERSION = 2.7
+ZEPHYR_VERSION = 3.2
WEST_CMD = default = sys.executable + " -m west" if sys.executable else None
@@ -317,7 +317,10 @@ PROJECT_OPTIONS = server.default_project_options(
),
server.ProjectOption(
"west_cmd",
- optional=["generate_project"],
+ required=(
+ ["generate_project", "build", "flash", "open_transport"] if not
WEST_CMD else None
+ ),
+ optional=(["generate_project", "build", "flash", "open_transport"] if
WEST_CMD else None),
type="str",
default=WEST_CMD,
help=(
@@ -551,9 +554,18 @@ class Handler(server.ProjectAPIHandler):
# Make project directory.
project_dir.mkdir()
- # Copy ourselves to the generated project. TVM may perform further
build steps on the generated project
+ # Copy ourselves and other python scripts to the generated project.
TVM may perform further build steps on the generated project
# by launching the copy.
- shutil.copy2(__file__, project_dir / os.path.basename(__file__))
+ current_dir = pathlib.Path(__file__).parent.absolute()
+ for file in os.listdir(current_dir):
+ if file.endswith(".py"):
+ shutil.copy2(current_dir / file, project_dir / file)
+
+ # Copy launch script
+ shutil.copy2(
+ current_dir / "launch_microtvm_api_server.sh",
+ project_dir / "launch_microtvm_api_server.sh",
+ )
# Copy boards.json file to generated project.
shutil.copy2(BOARDS, project_dir / BOARDS.name)
@@ -660,8 +672,6 @@ class Handler(server.ProjectAPIHandler):
tf.extractall(project_dir)
def build(self, options):
- verbose = options.get("verbose")
-
if BUILD_DIR.exists():
shutil.rmtree(BUILD_DIR)
BUILD_DIR.mkdir()
@@ -680,12 +690,7 @@ class Handler(server.ProjectAPIHandler):
st.st_mode | stat.S_IEXEC,
)
- check_call(["cmake", "-GNinja", ".."], cwd=BUILD_DIR, env=env)
-
- args = ["ninja"]
- if verbose:
- args.append("-v")
- check_call(args, cwd=BUILD_DIR, env=env)
+ check_call(options["west_cmd"].split(" ") + ["build"],
cwd=API_SERVER_DIR, env=env)
# A list of all zephyr_board values which are known to launch using QEMU.
Many platforms which
# launch through QEMU by default include "qemu" in their name. However,
not all do. This list
@@ -748,15 +753,16 @@ class Handler(server.ProjectAPIHandler):
)
def open_transport(self, options):
+ west_cmd = options["west_cmd"]
zephyr_board = _find_board_from_cmake_file(API_SERVER_DIR /
CMAKELIST_FILENAME)
emu_platform = _find_platform_from_cmake_file(API_SERVER_DIR /
CMAKELIST_FILENAME)
if self._is_fvp(zephyr_board, emu_platform == "armfvp"):
arm_fvp_path = options["arm_fvp_path"]
verbose = options.get("verbose")
- transport = ZephyrFvpTransport(arm_fvp_path, verbose)
+ transport = ZephyrFvpTransport(west_cmd, arm_fvp_path, verbose)
elif self._is_qemu(zephyr_board):
gdbserver_port = options.get("gdbserver_port")
- transport = ZephyrQemuTransport(gdbserver_port)
+ transport = ZephyrQemuTransport(west_cmd, gdbserver_port)
else:
zephyr_base = options["zephyr_base"]
serial_number = options.get("serial_number")
@@ -921,13 +927,14 @@ class ZephyrQemuMakeResult(enum.Enum):
class ZephyrQemuTransport:
"""The user-facing Zephyr QEMU transport class."""
- def __init__(self, gdbserver_port: int = None):
+ def __init__(self, west_cmd: str, gdbserver_port: int = None):
self._gdbserver_port = gdbserver_port
self.proc = None
self.pipe_dir = None
self.read_fd = None
self.write_fd = None
self._queue = queue.Queue()
+ self._west_cmd = west_cmd
def open(self):
with open(BUILD_DIR / "CMakeCache.txt", "r") as cmake_cache_f:
@@ -947,7 +954,7 @@ class ZephyrQemuTransport:
env["TVM_QEMU_GDBSERVER_PORT"] = self._gdbserver_port
self.proc = subprocess.Popen(
- ["ninja", "run"],
+ self._west_cmd.split(" ") + ["build", "-t", "run"],
cwd=BUILD_DIR,
env=env,
stdout=subprocess.PIPE,
diff --git
a/apps/microtvm/zephyr/template_project/src/aot_standalone_demo/main.c
b/apps/microtvm/zephyr/template_project/src/aot_standalone_demo/main.c
index f7405e94e0..9ba521ae17 100644
--- a/apps/microtvm/zephyr/template_project/src/aot_standalone_demo/main.c
+++ b/apps/microtvm/zephyr/template_project/src/aot_standalone_demo/main.c
@@ -19,15 +19,14 @@
#include <assert.h>
#include <float.h>
-#include <kernel.h>
#include <stdio.h>
#include <string.h>
-#include <sys/reboot.h>
#include <tvm/runtime/c_runtime_api.h>
#include <tvm/runtime/crt/logging.h>
#include <tvm/runtime/crt/stack_allocator.h>
#include <unistd.h>
-#include <zephyr.h>
+#include <zephyr/kernel.h>
+#include <zephyr/sys/reboot.h>
#include "input_data.h"
#include "output_data.h"
diff --git
a/apps/microtvm/zephyr/template_project/src/aot_standalone_demo/zephyr_uart.c
b/apps/microtvm/zephyr/template_project/src/aot_standalone_demo/zephyr_uart.c
index 02401584f6..8d5f912081 100644
---
a/apps/microtvm/zephyr/template_project/src/aot_standalone_demo/zephyr_uart.c
+++
b/apps/microtvm/zephyr/template_project/src/aot_standalone_demo/zephyr_uart.c
@@ -18,8 +18,8 @@
*/
#include "zephyr_uart.h"
-#include <drivers/uart.h>
-#include <sys/ring_buffer.h>
+#include <zephyr/drivers/uart.h>
+#include <zephyr/sys/ring_buffer.h>
#include "crt_config.h"
@@ -76,7 +76,7 @@ uint32_t TVMPlatformWriteSerial(const char* data, uint32_t
size) {
// Initialize UART
void TVMPlatformUARTInit() {
// Claim console device.
- g_microtvm_uart = device_get_binding(DT_LABEL(DT_CHOSEN(zephyr_console)));
+ g_microtvm_uart = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
const struct uart_config config = {.baudrate = 115200,
.parity = UART_CFG_PARITY_NONE,
.stop_bits = UART_CFG_STOP_BITS_1,
diff --git a/apps/microtvm/zephyr/template_project/src/host_driven/main.c
b/apps/microtvm/zephyr/template_project/src/host_driven/main.c
index 7dd082e2e5..c01daab6d0 100644
--- a/apps/microtvm/zephyr/template_project/src/host_driven/main.c
+++ b/apps/microtvm/zephyr/template_project/src/host_driven/main.c
@@ -28,20 +28,20 @@
* intended to be a demonstration, since typically you will want to incorporate
* this logic into your own application.
*/
-#include <drivers/gpio.h>
-#include <drivers/uart.h>
-#include <fatal.h>
-#include <kernel.h>
-#include <random/rand32.h>
#include <stdio.h>
-#include <sys/printk.h>
-#include <sys/reboot.h>
-#include <sys/ring_buffer.h>
-#include <timing/timing.h>
+#include <string.h>
#include <tvm/runtime/crt/logging.h>
#include <tvm/runtime/crt/microtvm_rpc_server.h>
#include <unistd.h>
-#include <zephyr.h>
+#include <zephyr/drivers/gpio.h>
+#include <zephyr/drivers/uart.h>
+#include <zephyr/fatal.h>
+#include <zephyr/kernel.h>
+#include <zephyr/random/rand32.h>
+#include <zephyr/sys/printk.h>
+#include <zephyr/sys/reboot.h>
+#include <zephyr/sys/ring_buffer.h>
+#include <zephyr/timing/timing.h>
#ifdef FVP
#include "fvp/semihost.h"
@@ -253,7 +253,7 @@ void main(void) {
#endif
// Claim console device.
- tvm_uart = device_get_binding(DT_LABEL(DT_CHOSEN(zephyr_console)));
+ tvm_uart = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
uart_rx_init(&uart_rx_rbuf, tvm_uart);
// Initialize system timing. We could stop and start it every time, but we'll
diff --git
a/apps/microtvm/zephyr/template_project/src/mlperftiny/submitter_implemented.cc
b/apps/microtvm/zephyr/template_project/src/mlperftiny/submitter_implemented.cc
index 84baee3072..91ae0c025c 100644
---
a/apps/microtvm/zephyr/template_project/src/mlperftiny/submitter_implemented.cc
+++
b/apps/microtvm/zephyr/template_project/src/mlperftiny/submitter_implemented.cc
@@ -19,10 +19,10 @@
#include "api/submitter_implemented.h"
-#include <drivers/gpio.h>
-#include <kernel.h>
#include <tvm/runtime/crt/platform.h>
#include <unistd.h>
+#include <zephyr/drivers/gpio.h>
+#include <zephyr/kernel.h>
#include "api/internally_implemented.h"
#include "tvmruntime.h"
diff --git a/apps/microtvm/zephyr/template_project/src/mlperftiny/tvmruntime.cc
b/apps/microtvm/zephyr/template_project/src/mlperftiny/tvmruntime.cc
index b16a1e711f..3fb7ccf8eb 100644
--- a/apps/microtvm/zephyr/template_project/src/mlperftiny/tvmruntime.cc
+++ b/apps/microtvm/zephyr/template_project/src/mlperftiny/tvmruntime.cc
@@ -21,15 +21,15 @@
#include <assert.h>
#include <float.h>
-#include <kernel.h>
#include <math.h>
-#include <power/reboot.h>
#include <stdint.h>
#include <stdio.h>
#include <tvm/runtime/c_runtime_api.h>
#include <tvm/runtime/crt/logging.h>
#include <tvm/runtime/crt/platform.h>
#include <tvm/runtime/crt/stack_allocator.h>
+#include <zephyr/kernel.h>
+#include <zephyr/sys/reboot.h>
#include "output_data.h"
#include "tvmgen_default.h"
diff --git
a/apps/microtvm/zephyr/template_project/src/mlperftiny/zephyr_uart.cc
b/apps/microtvm/zephyr/template_project/src/mlperftiny/zephyr_uart.cc
index 9880eadd4d..0922c32133 100644
--- a/apps/microtvm/zephyr/template_project/src/mlperftiny/zephyr_uart.cc
+++ b/apps/microtvm/zephyr/template_project/src/mlperftiny/zephyr_uart.cc
@@ -19,9 +19,9 @@
#include "zephyr_uart.h"
-#include <drivers/uart.h>
-#include <sys/ring_buffer.h>
#include <tvm/runtime/crt/error_codes.h>
+#include <zephyr/drivers/uart.h>
+#include <zephyr/sys/ring_buffer.h>
#include "crt_config.h"
@@ -79,7 +79,7 @@ uint32_t TVMPlatformWriteSerial(const char* data, uint32_t
size) {
// Initialize UART.
void TVMPlatformUARTInit(uint32_t baudrate /* = TVM_UART_DEFAULT_BAUDRATE */) {
// Claim console device.
- g_microtvm_uart = device_get_binding(DT_LABEL(DT_CHOSEN(zephyr_console)));
+ g_microtvm_uart = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
const struct uart_config config = {.baudrate = baudrate,
.parity = UART_CFG_PARITY_NONE,
.stop_bits = UART_CFG_STOP_BITS_1,
diff --git a/apps/microtvm/zephyr_cmsisnn/src/main.c
b/apps/microtvm/zephyr_cmsisnn/src/main.c
index 466c25e71e..55c09a7f42 100644
--- a/apps/microtvm/zephyr_cmsisnn/src/main.c
+++ b/apps/microtvm/zephyr_cmsisnn/src/main.c
@@ -21,10 +21,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/printk.h>
#include <tvm/runtime/c_runtime_api.h>
#include <tvm/runtime/crt/stack_allocator.h>
-#include <zephyr.h>
+#include <zephyr/kernel.h>
+#include <zephyr/sys/printk.h>
#include "tvmgen_default.h"
diff --git a/ci/jenkins/docker-images.ini b/ci/jenkins/docker-images.ini
index 149ea7b76b..ff84b97be3 100644
--- a/ci/jenkins/docker-images.ini
+++ b/ci/jenkins/docker-images.ini
@@ -18,7 +18,7 @@
# This data file is read during when Jenkins runs job to determine docker
images.
[jenkins]
ci_arm: tlcpack/ci-arm:20221013-060115-61c9742ea
-ci_cortexm: tlcpack/ci-cortexm:20230116-133924-dad13d1c1
+ci_cortexm: tlcpackstaging/ci_cortexm:20230124-233207-fd3f8035c
ci_cpu: tlcpack/ci-cpu:20230110-070003-d00168ffb
ci_gpu: tlcpack/ci-gpu:20221128-070141-ae4fd7df7
ci_hexagon: tlcpack/ci_hexagon:20230127-185848-95fa22308
diff --git a/cmake/modules/Arduino.cmake b/cmake/modules/Arduino.cmake
index bc06fab7a4..4d9962689d 100644
--- a/cmake/modules/Arduino.cmake
+++ b/cmake/modules/Arduino.cmake
@@ -21,6 +21,8 @@ if(USE_MICRO)
APPEND
ARDUINO_FILE_COPY_JOBS
"apps/microtvm/arduino/template_project microtvm_api_server.py ->
arduino"
+ "python/tvm/micro/project_api server.py -> arduino"
+ "apps/microtvm/arduino/template_project launch_microtvm_api_server.sh ->
arduino"
"apps/microtvm/arduino/template_project boards.json -> arduino"
"apps/microtvm/arduino/template_project/src/example_project *.c ->
arduino/src/example_project"
"apps/microtvm/arduino/template_project/src/example_project *.h ->
arduino/src/example_project"
diff --git a/cmake/modules/Zephyr.cmake b/cmake/modules/Zephyr.cmake
index 1f506f5132..a13aef3319 100644
--- a/cmake/modules/Zephyr.cmake
+++ b/cmake/modules/Zephyr.cmake
@@ -21,6 +21,8 @@ if(USE_MICRO)
APPEND
ZEPHYR_FILE_COPY_JOBS
"apps/microtvm/zephyr/template_project microtvm_api_server.py -> zephyr"
+ "python/tvm/micro/project_api server.py -> zephyr"
+ "apps/microtvm/zephyr/template_project launch_microtvm_api_server.sh ->
zephyr"
"apps/microtvm/zephyr/template_project boards.json -> zephyr"
"apps/microtvm/zephyr/template_project CMakeLists.txt.template -> zephyr"
"apps/microtvm/zephyr/template_project/src/aot_standalone_demo *.c ->
zephyr/src/aot_standalone_demo"
diff --git a/gallery/how_to/work_with_microtvm/install_zephyr.rst
b/gallery/how_to/work_with_microtvm/install_zephyr.rst
index a4c412f0f7..49bc20c425 100644
--- a/gallery/how_to/work_with_microtvm/install_zephyr.rst
+++ b/gallery/how_to/work_with_microtvm/install_zephyr.rst
@@ -34,19 +34,19 @@ Install Zephyr
export ZEPHYR_BASE=${ZEPHYR_PROJECT_PATH}/zephyr
west init ${ZEPHYR_PROJECT_PATH}
cd ${ZEPHYR_BASE}
- git checkout v2.7-branch
+ git checkout v3.2-branch
cd ..
west update
west zephyr-export
chmod -R o+w ${ZEPHYR_PROJECT_PATH}
# Install Zephyr SDK
- ZEPHYR_SDK_VERSION=0.13.2
- ZEPHYR_SDK_FILE="/content/zephyr-sdk-linux-setup.run"
- wget --no-verbose -O $ZEPHYR_SDK_FILE \
-
https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${ZEPHYR_SDK_VERSION}/zephyr-sdk-${ZEPHYR_SDK_VERSION}-linux-x86_64-setup.run
- chmod +x $ZEPHYR_SDK_FILE
- "$ZEPHYR_SDK_FILE" -- -d /content/zephyr-sdk --quiet
+ cd /content
+ ZEPHYR_SDK_VERSION="0.15.2"
+ wget
"https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${ZEPHYR_SDK_VERSION}/zephyr-sdk-${ZEPHYR_SDK_VERSION}_linux-x86_64.tar.gz"
+ tar xvf "zephyr-sdk-${ZEPHYR_SDK_VERSION}_linux-x86_64.tar.gz"
+ mv "zephyr-sdk-${ZEPHYR_SDK_VERSION}" zephyr-sdk
+ rm "zephyr-sdk-${ZEPHYR_SDK_VERSION}_linux-x86_64.tar.gz"
# Install python dependencies
python3 -m pip install -r "${ZEPHYR_BASE}/scripts/requirements.txt"
diff --git a/gallery/how_to/work_with_microtvm/micro_train.py
b/gallery/how_to/work_with_microtvm/micro_train.py
index 56ff54616f..bbb265420c 100644
--- a/gallery/how_to/work_with_microtvm/micro_train.py
+++ b/gallery/how_to/work_with_microtvm/micro_train.py
@@ -439,14 +439,17 @@ with open(QUANTIZED_MODEL_PATH, "wb") as f:
# ``tvm.micro.generate_project`` and pass in the Arduino template project to
finish compilation.
import shutil
-import tflite
import tvm
import tvm.micro.testing
# Method to load model is different in TFLite 1 vs 2
try: # TFLite 2.1 and above
+ import tflite
+
tflite_model = tflite.Model.GetRootAsModel(quantized_model, 0)
except AttributeError: # Fall back to TFLite 1.14 method
+ import tflite.Model
+
tflite_model = tflite.Model.Model.GetRootAsModel(quantized_model, 0)
# Convert to the Relay intermediate representation
diff --git a/python/tvm/micro/project_api/client.py
b/python/tvm/micro/project_api/client.py
index c9f889e9b6..75c870b771 100644
--- a/python/tvm/micro/project_api/client.py
+++ b/python/tvm/micro/project_api/client.py
@@ -204,18 +204,18 @@ SERVER_PYTHON_FILENAME = "microtvm_api_server.py"
def instantiate_from_dir(project_dir: typing.Union[pathlib.Path, str], debug:
bool = False):
"""Launch server located in project_dir, and instantiate a Project API
Client
connected to it."""
- args = None
+ proc_args = None
project_dir = pathlib.Path(project_dir)
python_script = project_dir / SERVER_PYTHON_FILENAME
if python_script.is_file():
- args = [sys.executable, str(python_script)]
+ proc_args = [sys.executable, str(python_script)]
launch_script = project_dir / SERVER_LAUNCH_SCRIPT_FILENAME
if launch_script.is_file():
- args = [str(launch_script)]
+ proc_args = [str(launch_script), str(python_script)]
- if args is None:
+ if proc_args is None:
raise ProjectAPIServerNotFoundError(
f"No Project API server found in project directory: {project_dir}"
"\n"
@@ -225,12 +225,12 @@ def instantiate_from_dir(project_dir:
typing.Union[pathlib.Path, str], debug: bo
api_server_read_fd, tvm_write_fd = os.pipe()
tvm_read_fd, api_server_write_fd = os.pipe()
- args.extend(["--read-fd", str(api_server_read_fd), "--write-fd",
str(api_server_write_fd)])
+ proc_args.extend(["--read-fd", str(api_server_read_fd), "--write-fd",
str(api_server_write_fd)])
if debug:
- args.append("--debug")
+ proc_args.append("--debug")
api_server_proc = subprocess.Popen( # pylint: disable=unused-variable
- args, bufsize=0, pass_fds=(api_server_read_fd, api_server_write_fd),
cwd=project_dir
+ proc_args, bufsize=0, pass_fds=(api_server_read_fd,
api_server_write_fd), cwd=project_dir
)
os.close(api_server_read_fd)
os.close(api_server_write_fd)
diff --git a/tests/micro/project_api/test_arduino_microtvm_api_server.py
b/tests/micro/project_api/test_arduino_microtvm_api_server.py
deleted file mode 100644
index 39e5780af6..0000000000
--- a/tests/micro/project_api/test_arduino_microtvm_api_server.py
+++ /dev/null
@@ -1,200 +0,0 @@
-# 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.
-
-import subprocess
-import sys
-from pathlib import Path
-from unittest import mock
-
-from packaging import version
-import pytest
-
-import tvm
-from tvm.micro.project_api import server
-
-sys.path.insert(0, tvm.micro.get_microtvm_template_projects("arduino"))
-import microtvm_api_server
-
-sys.path.pop(0)
-
-
-class TestGenerateProject:
- DEFAULT_OPTIONS = {"arduino_cli_cmd": "arduino-cli", "board": "nano33ble"}
-
- def _set_pathlib_path_exists(self, value):
- with mock.patch.object(Path, "exists") as mock_exists:
- mock_exists.return_value = value
-
- @mock.patch("pathlib.Path")
- def test_find_modified_include_path(self, mock_pathlib_path):
- handler = microtvm_api_server.Handler()
-
- project_dir = mock_pathlib_path("/dummy/project")
- file_path = (
- project_dir
- / "src"
- / "standalone_crt"
- / "src"
- / "runtime"
- / "crt"
- / "graph_executor"
- / "load_json.c"
- )
-
- # Should return C standard libs unmodified
- clib_output = handler._find_modified_include_path(project_dir,
file_path, "math.h")
- assert clib_output == "math.h"
-
- # If import already works, should return unmodified
- valid_arduino_import = "../../../../include/tvm/runtime/crt/platform.h"
- self._set_pathlib_path_exists(True)
- valid_output = handler._find_modified_include_path(
- project_dir, file_path, valid_arduino_import
- )
- assert valid_output == valid_arduino_import
-
- # Format for arduino-cli v0.18.2
- BOARD_CONNECTED_V18 = (
- "Port Type Board Name FQBN
Core \n"
- "/dev/ttyACM0 Serial Port (USB) Arduino Nano 33 BLE
arduino:mbed_nano:nano33ble arduino:mbed_nano\n"
- "/dev/ttyACM1 Serial Port (USB) Arduino Nano 33
arduino:mbed_nano:nano33 arduino:mbed_nano\n"
- "/dev/ttyS4 Serial Port Unknown
\n"
- "\n"
- )
- # Format for arduino-cli v0.21.1 and above
- BOARD_CONNECTED_V21 = (
- "Port Protocol Type Board Name FQBN
Core \n"
- "/dev/ttyACM0 serial arduino:mbed_nano:nano33ble
arduino:mbed_nano\n"
- "\n"
- )
- BOARD_DISCONNECTED_V21 = (
- "Port Protocol Type Board Name FQBN Core\n"
- "/dev/ttyS4 serial Serial Port Unknown\n"
- "\n"
- )
-
- def test_parse_connected_boards(self):
- h = microtvm_api_server.Handler()
- boards = h._parse_connected_boards(self.BOARD_CONNECTED_V21)
- assert list(boards) == [
- {
- "port": "/dev/ttyACM0",
- "protocol": "serial",
- "type": "",
- "board name": "",
- "fqbn": "arduino:mbed_nano:nano33ble",
- "core": "arduino:mbed_nano",
- }
- ]
-
- @mock.patch("subprocess.run")
- def test_auto_detect_port(self, mock_run):
- process_mock = mock.Mock()
- handler = microtvm_api_server.Handler()
-
- # Test it returns the correct port when a board is connected
- mock_run.return_value.stdout = bytes(self.BOARD_CONNECTED_V18, "utf-8")
- assert handler._auto_detect_port(self.DEFAULT_OPTIONS) ==
"/dev/ttyACM0"
-
- # Should work with old or new arduino-cli version
- mock_run.return_value.stdout = bytes(self.BOARD_CONNECTED_V21, "utf-8")
- assert handler._auto_detect_port(self.DEFAULT_OPTIONS) ==
"/dev/ttyACM0"
-
- # Test it raises an exception when no board is connected
- mock_run.return_value.stdout = bytes(self.BOARD_DISCONNECTED_V21,
"utf-8")
- with pytest.raises(microtvm_api_server.BoardAutodetectFailed):
- handler._auto_detect_port(self.DEFAULT_OPTIONS)
-
- # Test that the FQBN needs to match EXACTLY
- handler._get_fqbn =
mock.MagicMock(return_value="arduino:mbed_nano:nano33")
- mock_run.return_value.stdout = bytes(self.BOARD_CONNECTED_V18, "utf-8")
- assert (
- handler._auto_detect_port({**self.DEFAULT_OPTIONS, "board":
"nano33"}) == "/dev/ttyACM1"
- )
-
- BAD_CLI_VERSION = "arduino-cli Version: 0.7.1 Commit: 7668c465 Date:
2019-12-31T18:24:32Z\n"
- GOOD_CLI_VERSION = "arduino-cli Version: 0.21.1 Commit: 9fcbb392 Date:
2022-02-24T15:41:45Z\n"
-
- @mock.patch("subprocess.run")
- def test_auto_detect_port(self, mock_run):
- handler = microtvm_api_server.Handler()
- mock_run.return_value.stdout = bytes(self.GOOD_CLI_VERSION, "utf-8")
- arduino_cli_cmd = self.DEFAULT_OPTIONS.get("arduino_cli_cmd")
- warning_as_error = self.DEFAULT_OPTIONS.get("warning_as_error")
-
- handler._check_platform_version(
- cli_command=arduino_cli_cmd, warning_as_error=warning_as_error
- )
- assert handler._version == version.parse("0.21.1")
-
- handler = microtvm_api_server.Handler()
- mock_run.return_value.stdout = bytes(self.BAD_CLI_VERSION, "utf-8")
- with pytest.raises(server.ServerError) as error:
- handler._check_platform_version(cli_command=arduino_cli_cmd,
warning_as_error=True)
- mock_run.reset_mock()
-
- @mock.patch("subprocess.run")
- def test_flash_retry(self, mock_run):
- mock_run.return_value.stdout = bytes(self.GOOD_CLI_VERSION, "utf-8")
-
- def side_effect(cmd, *args, **kwargs):
- if cmd[1] == "flash":
- raise subprocess.TimeoutExpired(cmd, kwargs["timeout"])
- return mock.DEFAULT
-
- mock_run.side_effect = side_effect
-
- handler = microtvm_api_server.Handler()
- handler._port = "/dev/ttyACM0"
-
- # handler.flash will try flashing `handler.FLASH_MAX_RETRIES` times,
- # after which it will raise a TimeoutExpired exception of its own
- with pytest.raises(RuntimeError):
- handler.flash(self.DEFAULT_OPTIONS)
-
- # Test we checked version then called upload once per retry attempt,
- # plus once to verify arduino-cli version.
- assert mock_run.call_count == handler.FLASH_MAX_RETRIES + 1
-
- @mock.patch("subprocess.run")
- def test_flash(self, mock_run):
- mock_run.return_value.stdout = bytes(self.GOOD_CLI_VERSION, "utf-8")
-
- handler = microtvm_api_server.Handler()
- handler._port = "/dev/ttyACM0"
-
- # Test no exception thrown when command works
- handler.flash(self.DEFAULT_OPTIONS)
-
- # Test we checked version then called upload
- assert mock_run.call_count == 2
- assert mock_run.call_args_list[0][0] == (["arduino-cli", "version"],)
- assert mock_run.call_args_list[1][0][0][0:2] == ["make", "flash"]
- mock_run.reset_mock()
-
- # Test exception raised when `arduino-cli upload` returns error code
- mock_run.side_effect = subprocess.CalledProcessError(2, [])
- with pytest.raises(subprocess.CalledProcessError):
- handler.flash(self.DEFAULT_OPTIONS)
-
- # Version information should be cached and not checked again
- mock_run.assert_called_once()
- assert mock_run.call_args[0][0][0:2] == ["make", "flash"]
-
-
-if __name__ == "__main__":
- tvm.testing.main()
diff --git a/tests/micro/project_api/test_project_api.py
b/tests/micro/project_api/test_project_api.py
index 33ece65897..209ab59b4b 100644
--- a/tests/micro/project_api/test_project_api.py
+++ b/tests/micro/project_api/test_project_api.py
@@ -23,6 +23,8 @@ from tvm import relay
from tvm.micro.project_api import server
from tvm.relay.backend import Runtime
from tvm.micro.testing import get_target
+from tvm.relay.backend import Runtime
+import tvm.micro.testing
from .utils import build_project_api
@@ -40,15 +42,36 @@ platform = tvm.testing.parameter(PLATFORM_ARDUINO,
PLATFORM_ZEPHYR)
@tvm.testing.requires_micro
def test_default_options_exist(platform):
- sys.path.insert(0, tvm.micro.get_microtvm_template_projects(platform))
- import microtvm_api_server
-
- platform_options = microtvm_api_server.PROJECT_OPTIONS
+ board = "qemu_x86" if platform == "zephyr" else "due"
+
+ x = relay.var("x", relay.TensorType(shape=(10,), dtype="int8"))
+ xx = relay.multiply(x, x)
+ z = relay.add(xx, relay.const(np.ones(shape=(10,), dtype="int8")))
+ func = relay.Function([x], z)
+ ir_mod = tvm.IRModule.from_expr(func)
+
+ with tvm.transform.PassContext(opt_level=3):
+ mod = tvm.relay.build(
+ ir_mod, target=tvm.micro.testing.get_target("crt"),
runtime=Runtime("crt")
+ )
+
+ temp_dir = tvm.contrib.utils.tempdir()
+ project = tvm.micro.generate_project(
+ str(tvm.micro.get_microtvm_template_projects(platform)),
+ mod,
+ temp_dir / "project",
+ {
+ "board": board,
+ "project_type": "host_driven",
+ },
+ )
+
+ platform_options = project._info["project_options"]
default_options = server.default_project_options()
option_names = []
for option in platform_options:
- option_names.append(option.name)
+ option_names.append(option["name"])
for option in default_options:
assert option.name in option_names
diff --git a/tests/micro/zephyr/test_zephyr.py
b/tests/micro/zephyr/test_zephyr.py
index 89bd9c75fb..59c4cab881 100644
--- a/tests/micro/zephyr/test_zephyr.py
+++ b/tests/micro/zephyr/test_zephyr.py
@@ -547,6 +547,7 @@ def test_autotune_conv2d(workspace_dir, board,
microtvm_debug, use_fvp, serial_n
@tvm.testing.requires_micro
[email protected](reason="due to https://github.com/apache/tvm/issues/13856")
def test_schedule_build_with_cmsis_dependency(workspace_dir, board,
microtvm_debug, use_fvp):
"""Test Relay schedule with CMSIS dependency. This test shows if microTVM
Auto tuning
with Zephyr breaks if CMSIS dependency was required for a schedule.
diff --git a/tests/scripts/task_demo_microtvm.sh
b/tests/scripts/task_demo_microtvm.sh
index 8a79373fba..eca7a0f623 100755
--- a/tests/scripts/task_demo_microtvm.sh
+++ b/tests/scripts/task_demo_microtvm.sh
@@ -24,9 +24,10 @@ pushd apps/microtvm/cmsisnn
timeout 5m ./run_demo.sh
popd
-pushd apps/microtvm/zephyr_cmsisnn
- timeout 5m ./run_demo.sh
-popd
+# TODO(mehrdadh): disabled due to https://github.com/apache/tvm/issues/13856
+# pushd apps/microtvm/zephyr_cmsisnn
+# timeout 5m ./run_demo.sh
+# popd
pushd apps/microtvm/ethosu
FVP_PATH="/opt/arm/FVP_Corstone_SSE-300_Ethos-U55"