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] Remove Arduino aot code #8869

Merged
merged 4 commits into from
Sep 4, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
2 changes: 1 addition & 1 deletion apps/microtvm/arduino/example_project/src/model.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
#include "model.h"

#include "Arduino.h"
#include "standalone_crt/include/dlpack/dlpack.h"
#include "standalone_crt/include/tvm/runtime/crt/stack_allocator.h"

// AOT memory array
static uint8_t g_aot_memory[WORKSPACE_SIZE];
extern tvm_model_t tvmgen_default_network;
tvm_workspace_t app_workspace;

// Blink code for debugging purposes
Expand Down
2 changes: 2 additions & 0 deletions apps/microtvm/arduino/host_driven/src/model_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* under the License.
*/

#include "standalone_crt/include/dlpack/dlpack.h"
#include "standalone_crt/include/tvm/runtime/crt/error_codes.h"
#include "stdarg.h"

// Blink code for debugging purposes
Expand Down
8 changes: 5 additions & 3 deletions apps/microtvm/arduino/template_project/microtvm_api_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def build(self, options):
compile_cmd.append("--verbose")

# Specify project to compile
subprocess.run(compile_cmd)
subprocess.run(compile_cmd, check=True)

BOARD_LIST_HEADERS = ("Port", "Type", "Board Name", "FQBN", "Core")

Expand Down Expand Up @@ -402,7 +402,9 @@ def _parse_boards_tabular_str(self, tabular_str):

def _auto_detect_port(self, options):
list_cmd = [options["arduino_cli_cmd"], "board", "list"]
list_cmd_output = subprocess.run(list_cmd, stdout=subprocess.PIPE).stdout.decode("utf-8")
list_cmd_output = subprocess.run(
list_cmd, check=True, stdout=subprocess.PIPE
).stdout.decode("utf-8")

desired_fqbn = self._get_fqbn(options)
for line in self._parse_boards_tabular_str(list_cmd_output):
Expand Down Expand Up @@ -439,7 +441,7 @@ def flash(self, options):
if options.get("verbose"):
upload_cmd.append("--verbose")

subprocess.run(upload_cmd)
subprocess.run(upload_cmd, check=True)

def open_transport(self, options):
# Zephyr example doesn't throw an error in this case
Expand Down
44 changes: 42 additions & 2 deletions tests/micro/arduino/test_arduino_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
import pathlib
import shutil
import sys
import tempfile

import pytest
import tvm
from tvm import micro, relay

import conftest
import tvm
from tvm import micro, relay
from tvm.micro.project_api.server import ServerError

"""
This unit test simulates a simple user workflow, where we:
Expand All @@ -49,6 +51,30 @@ def project_dir(workspace_dir):
return workspace_dir / "project"


# Saves the Arduino project's state, runs the test, then resets it
@pytest.fixture(scope="function")
def does_not_affect_state(project_dir):
guberti marked this conversation as resolved.
Show resolved Hide resolved
with tempfile.TemporaryDirectory() as temp_dir:
prev_project_state = pathlib.Path(temp_dir)
shutil.copytree(project_dir, prev_project_state / "project")
yield

# We can't delete project_dir or it'll mess up the Arduino CLI working directory
guberti marked this conversation as resolved.
Show resolved Hide resolved
# Instead, delete everything in project_dir, and then copy over the files
for item in project_dir.iterdir():
if item.is_dir():
shutil.rmtree(item)
else:
item.unlink() # Delete file
# Once we upgrade to Python 3.7, this can be replaced with
# shutil.copytree(dirs_exist_ok=True)
for item in (prev_project_state / "project").iterdir():
if item.is_dir():
shutil.copytree(item, project_dir / item.name)
else:
shutil.copy2(item, project_dir)


def _generate_project(arduino_board, arduino_cli_cmd, workspace_dir, mod, build_config):
return tvm.micro.generate_project(
str(conftest.TEMPLATE_PROJECT_DIR),
Expand Down Expand Up @@ -135,6 +161,20 @@ def test_import_rerouting(project_dir, project):
assert "include/tvm/runtime/crt/platform.h" in c_backend_api_c


@pytest.mark.usefixtures("does_not_affect_state")
def test_blank_project_compiles(project):
project.build()


# Add a bug (an extra curly brace) and make sure the project doesn't compile
@pytest.mark.usefixtures("does_not_affect_state")
def test_bugged_project_compile_fails(project_dir, project):
with open(project_dir / "project.ino", "a") as main_file:
main_file.write("}\n")
with pytest.raises(ServerError):
project.build()


# Build on top of the generated project by replacing the
# top-level .ino fileand adding data input files, much
# like a user would
Expand Down