Skip to content

Commit

Permalink
Add env variable to micro tflite tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
mehrdadh committed Jan 20, 2022
1 parent bae144c commit 51577d1
Showing 1 changed file with 23 additions and 6 deletions.
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
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()}
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

0 comments on commit 51577d1

Please sign in to comment.