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][Zephyr] Remove unnecessary use of generate_c_interface_header #14091

Merged
merged 2 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions apps/microtvm/zephyr/template_project/CMakeLists.txt.template
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ endforeach(crt_lib_name ${CRT_LIBS})
zephyr_library_named(tvm_model)
file(GLOB_RECURSE tvm_model_srcs model/codegen/host/src/*.c model/codegen/host/lib/*.o)
target_sources(tvm_model PRIVATE ${tvm_model_srcs})
target_include_directories(tvm_model PRIVATE ${CMAKE_SOURCE_DIR}/include crt_config crt/include ${cmsis_includes})
target_include_directories(tvm_model PRIVATE ${CMAKE_SOURCE_DIR}/include crt_config crt/include model/codegen/host/include ${cmsis_includes})
target_compile_options(tvm_model PRIVATE -Wno-unused-variable) # TVM-generated code tends to include lots of these.
target_link_libraries(app PRIVATE tvm_model)

Expand All @@ -83,4 +83,4 @@ endif()

file(GLOB_RECURSE app_srcs src/**.c src/**.cc)
target_sources(app PRIVATE ${app_srcs} ${cmsis_lib_srcs})
target_include_directories(app PRIVATE crt_config include ${CMAKE_SOURCE_DIR}/include crt/include ${cmsis_includes})
target_include_directories(app PRIVATE crt_config include ${CMAKE_SOURCE_DIR}/include crt/include model/codegen/host/include ${cmsis_includes})
9 changes: 0 additions & 9 deletions gallery/how_to/work_with_microtvm/micro_mlperftiny.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
from tvm.relay.backend import Executor, Runtime
from tvm.contrib.download import download_testdata
from tvm.micro import export_model_library_format
from tvm.micro.model_library_format import generate_c_interface_header
import tvm.micro.testing
from tvm.micro.testing.utils import (
create_header_file,
Expand Down Expand Up @@ -212,14 +211,6 @@
extra_tar_file = extra_tar_dir / "extra.tar"

with tarfile.open(extra_tar_file, "w:gz") as tf:
with tempfile.TemporaryDirectory() as tar_temp_dir:
model_files_path = os.path.join(tar_temp_dir, "include")
os.mkdir(model_files_path)
header_path = generate_c_interface_header(
module.libmod_name, [input_name], [output_name], [], {}, [], 0, model_files_path, {}, {}
)
tf.add(header_path, arcname=os.path.relpath(header_path, tar_temp_dir))

create_header_file(
"output_data",
np.zeros(
Expand Down
51 changes: 51 additions & 0 deletions tests/micro/zephyr/test_zephyr.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import tvm.relay as relay
from tvm.relay.backend import Executor, Runtime
from tvm.relay.testing import byoc
from tvm.micro.project_api import server
from tvm.contrib import utils
from tvm.micro.testing.utils import check_tune_log

Expand Down Expand Up @@ -644,5 +645,55 @@ def test_debugging_enabled(workspace_dir):
project.build()


@tvm.testing.requires_micro
@pytest.mark.skip_boards(["mps2_an521", "mps3_an547"])
def test_qemu_make_fail(workspace_dir, board, microtvm_debug, serial_number):
"""Testing QEMU make fail."""
if not utils.ZEPHYR_BOARDS[board]["is_qemu"]:
pytest.skip(msg="Only for QEMU targets.")

build_config = {"debug": microtvm_debug}
shape = (10,)
dtype = "float32"

# Construct Relay program.
x = relay.var("x", relay.TensorType(shape=shape, dtype=dtype))
xx = relay.multiply(x, x)
z = relay.add(xx, relay.const(np.ones(shape=shape, dtype=dtype)))
func = relay.Function([x], z)
ir_mod = tvm.IRModule.from_expr(func)

target = tvm.micro.testing.get_target("zephyr", board)
executor = Executor("aot")
runtime = Runtime("crt", {"system-lib": True})
with tvm.transform.PassContext(opt_level=3, config={"tir.disable_vectorize": True}):
lowered = relay.build(ir_mod, target, executor=executor, runtime=runtime)

project_options = {
"project_type": "host_driven",
"verbose": bool(build_config.get("debug")),
"board": board,
}

sample = np.zeros(shape=shape, dtype=dtype)
project = tvm.micro.generate_project(
str(utils.TEMPLATE_PROJECT_DIR),
lowered,
workspace_dir / "project",
project_options,
)
project.build()

file_path = workspace_dir / "project" / "build" / "build.ninja"
assert file_path.is_file(), f"[{file_path}] does not exist."

# Remove a file to create make failure.
os.remove(file_path)
project.flash()
with pytest.raises(server.JSONRPCError) as excinfo:
project.transport().open()
assert "QEMU setup failed" in str(excinfo.value)


if __name__ == "__main__":
tvm.testing.main()
49 changes: 0 additions & 49 deletions tests/micro/zephyr/test_zephyr_aot_exec_standalone.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import tvm
import tvm.testing
import tvm.micro.testing
from tvm.micro.project_api import server
import tvm.relay as relay
from tvm.relay.backend import Executor, Runtime
from tvm.contrib.download import download_testdata
Expand Down Expand Up @@ -88,53 +87,5 @@ def test_tflite(workspace_dir, board, microtvm_debug, serial_number):
assert result == 6


@tvm.testing.requires_micro
@pytest.mark.skip_boards(["mps2_an521", "mps3_an547"])
def test_qemu_make_fail(workspace_dir, board, microtvm_debug, serial_number):
"""Testing QEMU make fail."""
if not utils.ZEPHYR_BOARDS[board]["is_qemu"]:
pytest.skip(msg="Only for QEMU targets.")

build_config = {"debug": microtvm_debug}
shape = (10,)
dtype = "float32"

# Construct Relay program.
x = relay.var("x", relay.TensorType(shape=shape, dtype=dtype))
xx = relay.multiply(x, x)
z = relay.add(xx, relay.const(np.ones(shape=shape, dtype=dtype)))
func = relay.Function([x], z)
ir_mod = tvm.IRModule.from_expr(func)

target = tvm.micro.testing.get_target("zephyr", board)
executor = Executor("aot")
runtime = Runtime("crt")
with tvm.transform.PassContext(opt_level=3, config={"tir.disable_vectorize": True}):
lowered = relay.build(ir_mod, target, executor=executor, runtime=runtime)

sample = np.zeros(shape=shape, dtype=dtype)
project, project_dir = utils.generate_project(
workspace_dir,
board,
lowered,
build_config,
sample,
shape,
dtype,
False,
serial_number,
)

file_path = pathlib.Path(project_dir) / "build" / "build.ninja"
assert file_path.is_file(), f"[{file_path}] does not exist."

# Remove a file to create make failure.
os.remove(file_path)
project.flash()
with pytest.raises(server.JSONRPCError) as excinfo:
project.transport().open()
assert "QEMU setup failed" in str(excinfo.value)


if __name__ == "__main__":
tvm.testing.main()
15 changes: 0 additions & 15 deletions tests/micro/zephyr/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

import tvm.micro
from tvm.micro import export_model_library_format
from tvm.micro.model_library_format import generate_c_interface_header
from tvm.micro.testing.utils import create_header_file
from tvm.micro.testing.utils import (
mlf_extract_workspace_size_bytes,
Expand Down Expand Up @@ -160,20 +159,6 @@ def generate_project(
tf.add(
model_files_path, arcname=os.path.relpath(model_files_path, tar_temp_dir)
)
header_path = generate_c_interface_header(
lowered.libmod_name,
["input_1"],
["Identity"],
[],
{},
[],
0,
model_files_path,
{},
{},
)
tf.add(header_path, arcname=os.path.relpath(header_path, tar_temp_dir))

create_header_file("input_data", sample, "include/tvm", tf)
create_header_file(
"output_data", np.zeros(shape=output_shape, dtype=output_type), "include/tvm", tf
Expand Down