diff --git a/apps/microtvm/zephyr/template_project/CMakeLists.txt.template b/apps/microtvm/zephyr/template_project/CMakeLists.txt.template index cec29e724882..f468affbac84 100644 --- a/apps/microtvm/zephyr/template_project/CMakeLists.txt.template +++ b/apps/microtvm/zephyr/template_project/CMakeLists.txt.template @@ -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) @@ -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}) diff --git a/gallery/how_to/work_with_microtvm/micro_mlperftiny.py b/gallery/how_to/work_with_microtvm/micro_mlperftiny.py index bb7abddddce6..d9d178f3bf91 100644 --- a/gallery/how_to/work_with_microtvm/micro_mlperftiny.py +++ b/gallery/how_to/work_with_microtvm/micro_mlperftiny.py @@ -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, @@ -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( diff --git a/tests/micro/zephyr/test_zephyr.py b/tests/micro/zephyr/test_zephyr.py index 79e4f46e0f93..72a0a85cf96f 100644 --- a/tests/micro/zephyr/test_zephyr.py +++ b/tests/micro/zephyr/test_zephyr.py @@ -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 @@ -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() diff --git a/tests/micro/zephyr/test_zephyr_aot_exec_standalone.py b/tests/micro/zephyr/test_zephyr_aot_exec_standalone.py index 8c6bc272f0f0..cd652067127d 100644 --- a/tests/micro/zephyr/test_zephyr_aot_exec_standalone.py +++ b/tests/micro/zephyr/test_zephyr_aot_exec_standalone.py @@ -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 @@ -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() diff --git a/tests/micro/zephyr/utils.py b/tests/micro/zephyr/utils.py index fdd873c8e8c3..fed7c53c2915 100644 --- a/tests/micro/zephyr/utils.py +++ b/tests/micro/zephyr/utils.py @@ -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, @@ -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