Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[microTVM][tutorial] Add ENV variable to enable testing on physical hardware #9993

Merged
merged 6 commits into from
Jan 26, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions gallery/how_to/work_with_microtvm/micro_tflite.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
from tvm.contrib.download import download_testdata
from tvm import relay

use_physical_hw = True if os.getenv("TVM_MICRO_USE_HW") else False
mehrdadh marked this conversation as resolved.
Show resolved Hide resolved
model_url = "https://people.linaro.org/~tom.gall/sine_model.tflite"
model_file = "sine_model.tflite"
model_path = download_testdata(model_url, model_file, module="data")
Expand Down Expand Up @@ -181,7 +182,7 @@
#
RUNTIME = tvm.relay.backend.Runtime("crt", {"system-lib": True})
TARGET = tvm.target.target.micro("host")
BOARD = "qemu_x86"

#
# Compiling for physical hardware
# When running on physical hardware, choose a TARGET and a BOARD that describe the hardware. The
Expand All @@ -190,8 +191,23 @@
# board but a couple of wirings and configs differ, it's necessary to select the "stm32f746g_disco"
# board to generated the right firmware image.
#
# TARGET = tvm.target.target.micro("stm32f746xx")
# BOARD = "nucleo_f746zg" # or "stm32f746g_disco#"

import json
import pathlib

if use_physical_hw:
if os.getenv("TVM_MICRO_BOARD"):
BOARD = os.getenv("TVM_MICRO_BOARD")
with open(
pathlib.Path(tvm.micro.get_microtvm_template_projects("zephyr")) / "boards.json"
) as f:
board_properties = json.load(f)
boards_model = {board: info["model"] for board, info in board_properties.items()}
mehrdadh marked this conversation as resolved.
Show resolved Hide resolved
TARGET = tvm.target.target.micro(boards_model[BOARD])
else:
BOARD = "nucleo_f746zg"
TARGET = tvm.target.target.micro("stm32f746xx")

#
# For some boards, Zephyr runs them emulated by default, using QEMU. For example, below is the
# TARGET and BOARD used to build a microTVM firmware for the mps2-an521 board. Since that board
Expand Down Expand Up @@ -264,7 +280,6 @@
# this lives in a file ``microtvm_api_server.py`` in the root directory). Let's use the example ``host``
# project in this tutorial, which simulates the device using a POSIX subprocess and pipes:

import subprocess
import pathlib

template_project_path = pathlib.Path(tvm.micro.get_microtvm_template_projects("crt"))
Expand All @@ -275,8 +290,10 @@
# For physical hardware, you can try out the Zephyr platform by using a different template project
# and options:
#
# template_project_path = pathlib.Path(tvm.micro.get_microtvm_template_projects("zephyr"))
# project_options = {"project_type": "host_driven", zephyr_board": "nucleo_f746zg"}}

if use_physical_hw:
template_project_path = pathlib.Path(tvm.micro.get_microtvm_template_projects("zephyr"))
project_options = {"project_type": "host_driven", "zephyr_board": BOARD}

# Create a temporary directory
import tvm.contrib.utils
Expand Down