From 176736100d8b2a7ee8cce98fdec005f751afbb43 Mon Sep 17 00:00:00 2001 From: Mehrdad Hessar Date: Mon, 13 Feb 2023 12:57:20 -0800 Subject: [PATCH 1/7] Enable USMP by default for AOT + CRT runtime --- src/relay/backend/aot_executor_codegen.cc | 13 ++++++-- tests/python/relay/aot/test_crt_aot_usmp.py | 35 +++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/relay/backend/aot_executor_codegen.cc b/src/relay/backend/aot_executor_codegen.cc index 65088e38a563..a42ae6901fee 100644 --- a/src/relay/backend/aot_executor_codegen.cc +++ b/src/relay/backend/aot_executor_codegen.cc @@ -44,6 +44,7 @@ #include #include +#include "../../target/parsers/mprofile.h" #include "../../target/source/codegen_source_base.h" #include "../op/annotation/annotation.h" #include "../op/call/call.h" @@ -1047,7 +1048,7 @@ class AOTExecutorCodegen : public MixedModeVisitor { std::string interface_api = executor_config->GetAttr("interface-api").value_or("packed"); bool unpacked_api = executor_config->GetAttr("unpacked-api").value_or(Bool(false)); - + // Validate choice of unpacked_api and use_call_cpacked_ if (runtime_config->name == kTvmRuntimeCrt) { if (unpacked_api == true) { @@ -1209,7 +1210,15 @@ class AOTExecutorCodegen : public MixedModeVisitor { // Parallel for loops are not supported in AoT codegen. lowered_mod = tir::transform::ConvertForLoopsToSerial()(lowered_mod); - bool enable_usmp = pass_ctx->GetConfig(kUSMPEnableOption, Bool(false)).value(); + // Check USMP option + bool enable_usmp = false; + if (runtime_config->name == kTvmRuntimeCrt) { + enable_usmp = true; + } + if (pass_ctx->GetConfig(kUSMPEnableOption) != nullptr) { + enable_usmp = pass_ctx->GetConfig(kUSMPEnableOption, Bool(false)).value(); + } + if (enable_usmp) { lowered_mod = PlanMemoryWithUSMP(lowered_mod); } else { diff --git a/tests/python/relay/aot/test_crt_aot_usmp.py b/tests/python/relay/aot/test_crt_aot_usmp.py index 12c60a726651..83aa46dc3189 100644 --- a/tests/python/relay/aot/test_crt_aot_usmp.py +++ b/tests/python/relay/aot/test_crt_aot_usmp.py @@ -907,5 +907,40 @@ def test_incompatible_interface_api_errors(): tvm.relay.build(mod, target, executor=executor, runtime=runtime, params=params) +@parametrize_aot_options +def test_usmp_enabled_by_default_for_crt(interface_api, use_unpacked_api, test_runner): + """This test checks whether USMP is enabled by default + for cortex-M targets. + """ + dtype = "float32" + ishape = (1, 32, 14, 14) + wshape = (32, 32, 3, 3) + + data0 = relay.var("data", shape=ishape, dtype=dtype) + weight0 = relay.var("weight", shape=wshape, dtype=dtype) + out = relay.nn.conv2d(data0, weight0, kernel_size=(3, 3), padding=(1, 1), groups=1) + main_f = relay.Function([data0, weight0], out) + mod = tvm.IRModule() + mod["main"] = main_f + mod = transform.InferType()(mod) + + i_data = np.random.uniform(0, 1, ishape).astype(dtype) + w1_data = np.random.uniform(0, 1, wshape).astype(dtype) + + inputs = OrderedDict([("data", i_data), ("weight", w1_data)]) + output_list = generate_ref_data(mod, inputs) + + compiled_test_mods = compile_models( + models=AOTTestModel(module=mod, inputs=inputs, outputs=output_list), + interface_api=interface_api, + use_unpacked_api=use_unpacked_api, + pass_config=test_runner.pass_config, + target=tvm.target.target.micro("host"), + ) + + for compiled_model in compiled_test_mods: + _check_for_no_tvm_backendallocworkspace_calls(compiled_model.executor_factory.lib) + + if __name__ == "__main__": tvm.testing.main() From 98795181175a2ca4793120229c78da926cad63da Mon Sep 17 00:00:00 2001 From: Mehrdad Hessar Date: Wed, 15 Feb 2023 15:35:16 -0800 Subject: [PATCH 2/7] refactor passes for Zephyr --- tests/micro/zephyr/test_ms_tuning.py | 3 ++- tests/micro/zephyr/test_zephyr.py | 16 ++++++++-------- tests/micro/zephyr/test_zephyr_aot_exec.py | 4 ++-- .../zephyr/test_zephyr_aot_exec_standalone.py | 4 +--- tests/micro/zephyr/test_zephyr_armv7m.py | 2 +- tests/micro/zephyr/utils.py | 1 + 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/micro/zephyr/test_ms_tuning.py b/tests/micro/zephyr/test_ms_tuning.py index 560f5e09596a..aa651b6d9d6a 100644 --- a/tests/micro/zephyr/test_ms_tuning.py +++ b/tests/micro/zephyr/test_ms_tuning.py @@ -29,6 +29,7 @@ from tvm.contrib.micro.meta_schedule.local_builder_micro import get_local_builder_micro from tvm.contrib.micro.meta_schedule.rpc_runner_micro import get_rpc_runner_micro +from . import utils def create_relay_module(): data_shape = (1, 3, 16, 16) @@ -161,7 +162,7 @@ def test_ms_tuning_conv2d(workspace_dir, board, microtvm_debug, use_fvp, serial_ dev = tvm.cpu() target = tvm.micro.testing.get_target("crt") with tvm.transform.PassContext( - opt_level=3, config={"tir.disable_vectorize": True}, disabled_pass=["AlterOpLayout"] + opt_level=3, config=utils.PASS_CONFIG, disabled_pass=["AlterOpLayout"] ): ref_mod = relay.build( mod, diff --git a/tests/micro/zephyr/test_zephyr.py b/tests/micro/zephyr/test_zephyr.py index 72a0a85cf96f..f5f37d476f74 100644 --- a/tests/micro/zephyr/test_zephyr.py +++ b/tests/micro/zephyr/test_zephyr.py @@ -52,7 +52,7 @@ def _make_sess_from_op( runtime = Runtime("crt", {"system-lib": True}) target = tvm.micro.testing.get_target("zephyr", board) target = tvm.target.Target(target=target, host=target) - with tvm.transform.PassContext(opt_level=3, config={"tir.disable_vectorize": True}): + with tvm.transform.PassContext(opt_level=3, config=utils.PASS_CONFIG): mod = tvm.build(sched, arg_bufs, target=target, runtime=runtime, name=op_name) return _make_session(temp_dir, board, mod, build_config, use_fvp, serial_number) @@ -209,7 +209,7 @@ def test_relay(workspace_dir, board, microtvm_debug, use_fvp, serial_number): runtime = Runtime("crt", {"system-lib": True}) target = tvm.micro.testing.get_target("zephyr", board) - with tvm.transform.PassContext(opt_level=3, config={"tir.disable_vectorize": True}): + with tvm.transform.PassContext(opt_level=3, config=utils.PASS_CONFIG): mod = tvm.relay.build(ir_mod, target=target, runtime=runtime) with _make_session(workspace_dir, board, mod, build_config, use_fvp, serial_number) as session: @@ -252,7 +252,7 @@ def test_onnx(workspace_dir, board, microtvm_debug, use_fvp, serial_number): # the model weights when set using graph_mod.set_input(). # See: https://github.com/apache/tvm/issues/7567 target = tvm.micro.testing.get_target("zephyr", board) - with tvm.transform.PassContext(opt_level=3, config={"tir.disable_vectorize": True}): + with tvm.transform.PassContext(opt_level=3, config=utils.PASS_CONFIG): executor = Executor("graph", {"link-params": True}) runtime = Runtime("crt", {"system-lib": True}) lowered = relay.build(relay_mod, target, params=params, executor=executor, runtime=runtime) @@ -293,7 +293,7 @@ def check_result( TOL = 1e-5 runtime = Runtime("crt", {"system-lib": True}) target = tvm.micro.testing.get_target("zephyr", board) - with tvm.transform.PassContext(opt_level=3, config={"tir.disable_vectorize": True}): + with tvm.transform.PassContext(opt_level=3, config=utils.PASS_CONFIG): mod = tvm.relay.build(relay_mod, target=target, runtime=runtime) with _make_session(temp_dir, board, mod, build_config, use_fvp, serial_number) as session: @@ -454,7 +454,7 @@ def test_autotune_conv2d(workspace_dir, board, microtvm_debug, use_fvp, serial_n params = {mod["main"].params[1].name_hint: weight_sample} target = tvm.micro.testing.get_target("zephyr", board) - pass_context = tvm.transform.PassContext(opt_level=3, config={"tir.disable_vectorize": True}) + pass_context = tvm.transform.PassContext(opt_level=3, config=utils.PASS_CONFIG) with pass_context: tasks = tvm.autotvm.task.extract_from_program(mod["main"], {}, target) assert len(tasks) > 0 @@ -482,7 +482,7 @@ def test_autotune_conv2d(workspace_dir, board, microtvm_debug, use_fvp, serial_n builder = tvm.autotvm.LocalBuilder( timeout=timeout, n_parallel=1, - build_kwargs={"build_option": {"tir.disable_vectorize": True}}, + build_kwargs={"build_option": utils.PASS_CONFIG}, do_fork=True, build_func=tvm.micro.autotvm_build_func, runtime=runtime, @@ -580,7 +580,7 @@ def test_schedule_build_with_cmsis_dependency(workspace_dir, board, microtvm_deb runtime = Runtime("crt", {"system-lib": True}) - with tvm.transform.PassContext(opt_level=3, config={"tir.disable_vectorize": True}): + with tvm.transform.PassContext(opt_level=3, config=utils.PASS_CONFIG): mod = tvm.relay.build(ir_mod, target=target, runtime=runtime) project_options = { @@ -633,7 +633,7 @@ def test_debugging_enabled(workspace_dir): executor = Executor("aot") target = tvm.micro.testing.get_target("zephyr", board) - with tvm.transform.PassContext(opt_level=3, config={"tir.disable_vectorize": True}): + with tvm.transform.PassContext(opt_level=3, config=utils.PASS_CONFIG): mod = tvm.relay.build(ir_mod, target=target, runtime=runtime, executor=executor) project = tvm.micro.generate_project( diff --git a/tests/micro/zephyr/test_zephyr_aot_exec.py b/tests/micro/zephyr/test_zephyr_aot_exec.py index d5bcf08a0cb6..76e03c35c511 100644 --- a/tests/micro/zephyr/test_zephyr_aot_exec.py +++ b/tests/micro/zephyr/test_zephyr_aot_exec.py @@ -78,7 +78,7 @@ def test_relay(workspace_dir, board, microtvm_debug, use_fvp, serial_number): runtime = Runtime("crt", {"system-lib": True}) executor = Executor("aot") target = tvm.micro.testing.get_target("zephyr", board) - with tvm.transform.PassContext(opt_level=3, config={"tir.disable_vectorize": True}): + with tvm.transform.PassContext(opt_level=3, config=utils.PASS_CONFIG): mod = tvm.relay.build(ir_mod, target=target, runtime=runtime, executor=executor) with _make_session(workspace_dir, board, mod, build_config, use_fvp, serial_number) as session: @@ -117,7 +117,7 @@ def @main(%a : Tensor[(1, 2), uint8], %b : Tensor[(1, 2), uint8]) { runtime = Runtime("crt", {"system-lib": True}) executor = Executor("aot") target = tvm.micro.testing.get_target("zephyr", board) - with tvm.transform.PassContext(opt_level=3, config={"tir.disable_vectorize": True}): + with tvm.transform.PassContext(opt_level=3, config=utils.PASS_CONFIG): mod = tvm.relay.build(relay_mod, target=target, runtime=runtime, executor=executor) def do_test(): diff --git a/tests/micro/zephyr/test_zephyr_aot_exec_standalone.py b/tests/micro/zephyr/test_zephyr_aot_exec_standalone.py index 1a15d2ae3a3f..fc73ba8121f6 100644 --- a/tests/micro/zephyr/test_zephyr_aot_exec_standalone.py +++ b/tests/micro/zephyr/test_zephyr_aot_exec_standalone.py @@ -62,9 +62,7 @@ def test_tflite(workspace_dir, board, microtvm_debug, serial_number): "aot", {"unpacked-api": True, "interface-api": "c", "workspace-byte-alignment": 4} ) runtime = Runtime("crt") - with tvm.transform.PassContext( - opt_level=3, config={"tir.disable_vectorize": True, "tir.usmp.enable": True} - ): + with tvm.transform.PassContext(opt_level=3, config=utils.PASS_CONFIG): lowered = relay.build(relay_mod, target, params=params, runtime=runtime, executor=executor) sample_url = "https://github.com/tlc-pack/web-data/raw/main/testdata/microTVM/data/keyword_spotting_int8_6.pyc.npy" diff --git a/tests/micro/zephyr/test_zephyr_armv7m.py b/tests/micro/zephyr/test_zephyr_armv7m.py index cd589a19e886..05e3c5330394 100644 --- a/tests/micro/zephyr/test_zephyr_armv7m.py +++ b/tests/micro/zephyr/test_zephyr_armv7m.py @@ -128,7 +128,7 @@ def test_armv7m_intrinsic(workspace_dir, board, microtvm_debug, serial_number): os.makedirs(workspace_dir_simd, exist_ok=True) os.makedirs(workspace_dir_no_simd, exist_ok=True) - with tvm.transform.PassContext(opt_level=3, config={"tir.disable_vectorize": True}): + with tvm.transform.PassContext(opt_level=3, config=utils.PASS_CONFIG): lowered_simd = relay.build( relay_mod_simd, target_simd, params=params, runtime=runtime, executor=executor ) diff --git a/tests/micro/zephyr/utils.py b/tests/micro/zephyr/utils.py index fed7c53c2915..d46a1b644cbd 100644 --- a/tests/micro/zephyr/utils.py +++ b/tests/micro/zephyr/utils.py @@ -42,6 +42,7 @@ _LOG = logging.getLogger(__name__) +PASS_CONFIG = {"tir.disable_vectorize": True} def zephyr_boards() -> dict: """Returns Zephyr board properties""" From 40ed10962d40c0e428e6d98fd73b3f30712d30b4 Mon Sep 17 00:00:00 2001 From: Mehrdad Hessar Date: Wed, 15 Feb 2023 15:36:03 -0800 Subject: [PATCH 3/7] refactor config for arduino --- tests/micro/arduino/__init__.py | 18 ++++++++++++++ .../arduino/test_arduino_error_detection.py | 4 ++-- .../micro/arduino/test_arduino_rpc_server.py | 24 +++++++++---------- tests/micro/arduino/test_arduino_workflow.py | 6 ++--- .../micro/arduino/{test_utils.py => utils.py} | 3 ++- 5 files changed, 37 insertions(+), 18 deletions(-) create mode 100644 tests/micro/arduino/__init__.py rename tests/micro/arduino/{test_utils.py => utils.py} (96%) diff --git a/tests/micro/arduino/__init__.py b/tests/micro/arduino/__init__.py new file mode 100644 index 000000000000..5c5b65e7cdde --- /dev/null +++ b/tests/micro/arduino/__init__.py @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +""" Testing infrastructure for microTVM Arduino """ diff --git a/tests/micro/arduino/test_arduino_error_detection.py b/tests/micro/arduino/test_arduino_error_detection.py index 75b97fa86ca3..17b3007d7926 100644 --- a/tests/micro/arduino/test_arduino_error_detection.py +++ b/tests/micro/arduino/test_arduino_error_detection.py @@ -19,13 +19,13 @@ from tvm.micro.project_api.server import ServerError -import test_utils +from . import utils import tvm.testing @pytest.fixture def project(board, microtvm_debug, workspace_dir, serial_number): - return test_utils.make_kws_project(board, microtvm_debug, workspace_dir, serial_number) + return utils.make_kws_project(board, microtvm_debug, workspace_dir, serial_number) def test_blank_project_compiles(workspace_dir, project): diff --git a/tests/micro/arduino/test_arduino_rpc_server.py b/tests/micro/arduino/test_arduino_rpc_server.py index 38f34de82beb..c7aa441b5f7d 100644 --- a/tests/micro/arduino/test_arduino_rpc_server.py +++ b/tests/micro/arduino/test_arduino_rpc_server.py @@ -35,7 +35,7 @@ from tvm.relay.testing import byoc from tvm.relay.backend import Executor, Runtime -import test_utils +from . import utils def _make_session( @@ -47,7 +47,7 @@ def _make_session( serial_number: str = None, ): project = tvm.micro.generate_project( - str(test_utils.TEMPLATE_PROJECT_DIR), + str(utils.TEMPLATE_PROJECT_DIR), mod, workspace_dir / "project", { @@ -74,7 +74,7 @@ def _make_sess_from_op( ): target = tvm.target.target.micro(model) runtime = Runtime("crt", {"system-lib": True}) - with tvm.transform.PassContext(opt_level=3, config={"tir.disable_vectorize": True}): + with tvm.transform.PassContext(opt_level=3, config=utils.PASS_CONFIG): mod = tvm.build(sched, arg_bufs, target=target, runtime=runtime, name=op_name) return _make_session(model, arduino_board, workspace_dir, mod, build_config, serial_number) @@ -103,7 +103,7 @@ def _make_add_sess(model, arduino_board, workspace_dir, build_config, serial_num def test_compile_runtime(board, microtvm_debug, workspace_dir, serial_number): """Test compiling the on-device runtime.""" - model = test_utils.ARDUINO_BOARDS[board] + model = utils.ARDUINO_BOARDS[board] build_config = {"debug": microtvm_debug} # NOTE: run test in a nested function so cPython will delete arrays before closing the session. @@ -128,7 +128,7 @@ def test_basic_add(sess): def test_platform_timer(board, microtvm_debug, workspace_dir, serial_number): """Test compiling the on-device runtime.""" - model = test_utils.ARDUINO_BOARDS[board] + model = utils.ARDUINO_BOARDS[board] build_config = {"debug": microtvm_debug} # NOTE: run test in a nested function so cPython will delete arrays before closing the session. @@ -157,7 +157,7 @@ def test_basic_add(sess): @pytest.mark.requires_hardware def test_relay(board, microtvm_debug, workspace_dir, serial_number): """Testing a simple relay graph""" - model = test_utils.ARDUINO_BOARDS[board] + model = utils.ARDUINO_BOARDS[board] build_config = {"debug": microtvm_debug} shape = (10,) @@ -171,7 +171,7 @@ def test_relay(board, microtvm_debug, workspace_dir, serial_number): target = tvm.target.target.micro(model) runtime = Runtime("crt", {"system-lib": True}) - with tvm.transform.PassContext(opt_level=3, config={"tir.disable_vectorize": True}): + with tvm.transform.PassContext(opt_level=3, config=utils.PASS_CONFIG): mod = tvm.relay.build(func, target=target, runtime=runtime) with _make_session(model, board, workspace_dir, mod, build_config, serial_number) as session: @@ -190,7 +190,7 @@ def test_relay(board, microtvm_debug, workspace_dir, serial_number): @pytest.mark.requires_hardware def test_onnx(board, microtvm_debug, workspace_dir, serial_number): """Testing a simple ONNX model.""" - model = test_utils.ARDUINO_BOARDS[board] + model = utils.ARDUINO_BOARDS[board] build_config = {"debug": microtvm_debug} # Load test images. @@ -212,7 +212,7 @@ def test_onnx(board, microtvm_debug, workspace_dir, serial_number): target = tvm.target.target.micro(model) runtime = Runtime("crt", {"system-lib": True}) - with tvm.transform.PassContext(opt_level=3, config={"tir.disable_vectorize": True}): + with tvm.transform.PassContext(opt_level=3, config=utils.PASS_CONFIG): executor = Executor("graph", {"link-params": True}) lowered = relay.build(relay_mod, target, params=params, executor=executor, runtime=runtime) graph = lowered.get_graph_json() @@ -253,7 +253,7 @@ def check_result( TOL = 1e-5 target = tvm.target.target.micro(model) runtime = Runtime("crt", {"system-lib": True}) - with tvm.transform.PassContext(opt_level=3, config={"tir.disable_vectorize": True}): + with tvm.transform.PassContext(opt_level=3, config=utils.PASS_CONFIG): mod = tvm.relay.build(relay_mod, target=target, runtime=runtime) with _make_session( @@ -281,7 +281,7 @@ def check_result( @pytest.mark.requires_hardware def test_byoc_microtvm(board, microtvm_debug, workspace_dir, serial_number): """This is a simple test case to check BYOC capabilities of microTVM""" - model = test_utils.ARDUINO_BOARDS[board] + model = utils.ARDUINO_BOARDS[board] build_config = {"debug": microtvm_debug} x = relay.var("x", shape=(10, 10)) @@ -377,7 +377,7 @@ def _make_add_sess_with_shape( @pytest.mark.requires_hardware def test_rpc_large_array(board, microtvm_debug, workspace_dir, shape, serial_number): """Test large RPC array transfer.""" - model = test_utils.ARDUINO_BOARDS[board] + model = utils.ARDUINO_BOARDS[board] build_config = {"debug": microtvm_debug} # NOTE: run test in a nested function so cPython will delete arrays before closing the session. diff --git a/tests/micro/arduino/test_arduino_workflow.py b/tests/micro/arduino/test_arduino_workflow.py index 8c39dc4f16da..5c0c19e2f9df 100644 --- a/tests/micro/arduino/test_arduino_workflow.py +++ b/tests/micro/arduino/test_arduino_workflow.py @@ -23,7 +23,7 @@ import tvm.testing -import test_utils +from . import utils """ This unit test simulates a simple user workflow, where we: @@ -43,7 +43,7 @@ @pytest.fixture(scope="module") def workflow_workspace_dir(request): board = request.config.getoption("--board") - return test_utils.make_workspace_dir("arduino_workflow", board) + return utils.make_workspace_dir("arduino_workflow", board) @pytest.fixture(scope="module") @@ -57,7 +57,7 @@ def project_dir(workflow_workspace_dir): def project(request, microtvm_debug, workflow_workspace_dir): board = request.config.getoption("--board") serial_number = request.config.getoption("--serial-number") - return test_utils.make_kws_project(board, microtvm_debug, workflow_workspace_dir, serial_number) + return utils.make_kws_project(board, microtvm_debug, workflow_workspace_dir, serial_number) def _get_directory_elements(directory): diff --git a/tests/micro/arduino/test_utils.py b/tests/micro/arduino/utils.py similarity index 96% rename from tests/micro/arduino/test_utils.py rename to tests/micro/arduino/utils.py index 1456e1f7591e..37668b3ba640 100644 --- a/tests/micro/arduino/test_utils.py +++ b/tests/micro/arduino/utils.py @@ -31,6 +31,7 @@ BOARDS = TEMPLATE_PROJECT_DIR / "boards.json" +PASS_CONFIG = {"tir.disable_vectorize": True} def arduino_boards() -> dict: """Returns a dict mapping board to target model""" @@ -76,7 +77,7 @@ def make_kws_project(board, microtvm_debug, workspace_dir, serial_number: str): runtime = Runtime("crt") executor = Executor("aot", {"unpacked-api": True}) - with tvm.transform.PassContext(opt_level=3, config={"tir.disable_vectorize": True}): + with tvm.transform.PassContext(opt_level=3, config=PASS_CONFIG): mod = relay.build(mod, target, runtime=runtime, executor=executor, params=params) return tvm.micro.generate_project( From 827646e132f864274c89d8d30ebbf2f1792387ab Mon Sep 17 00:00:00 2001 From: Mehrdad Hessar Date: Thu, 23 Feb 2023 14:00:06 -0800 Subject: [PATCH 4/7] lint --- src/relay/backend/aot_executor_codegen.cc | 2 +- tests/micro/arduino/test_arduino_workflow.py | 2 +- tests/micro/arduino/utils.py | 1 + tests/micro/zephyr/test_ms_tuning.py | 1 + tests/micro/zephyr/utils.py | 1 + 5 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/relay/backend/aot_executor_codegen.cc b/src/relay/backend/aot_executor_codegen.cc index a42ae6901fee..d31dea69aac9 100644 --- a/src/relay/backend/aot_executor_codegen.cc +++ b/src/relay/backend/aot_executor_codegen.cc @@ -1048,7 +1048,7 @@ class AOTExecutorCodegen : public MixedModeVisitor { std::string interface_api = executor_config->GetAttr("interface-api").value_or("packed"); bool unpacked_api = executor_config->GetAttr("unpacked-api").value_or(Bool(false)); - + // Validate choice of unpacked_api and use_call_cpacked_ if (runtime_config->name == kTvmRuntimeCrt) { if (unpacked_api == true) { diff --git a/tests/micro/arduino/test_arduino_workflow.py b/tests/micro/arduino/test_arduino_workflow.py index 5c0c19e2f9df..03b16569e243 100644 --- a/tests/micro/arduino/test_arduino_workflow.py +++ b/tests/micro/arduino/test_arduino_workflow.py @@ -23,7 +23,7 @@ import tvm.testing -from . import utils +from . import utils """ This unit test simulates a simple user workflow, where we: diff --git a/tests/micro/arduino/utils.py b/tests/micro/arduino/utils.py index 37668b3ba640..6d518800acab 100644 --- a/tests/micro/arduino/utils.py +++ b/tests/micro/arduino/utils.py @@ -33,6 +33,7 @@ PASS_CONFIG = {"tir.disable_vectorize": True} + def arduino_boards() -> dict: """Returns a dict mapping board to target model""" with open(BOARDS) as f: diff --git a/tests/micro/zephyr/test_ms_tuning.py b/tests/micro/zephyr/test_ms_tuning.py index aa651b6d9d6a..4dc2942436b6 100644 --- a/tests/micro/zephyr/test_ms_tuning.py +++ b/tests/micro/zephyr/test_ms_tuning.py @@ -31,6 +31,7 @@ from . import utils + def create_relay_module(): data_shape = (1, 3, 16, 16) weight_shape = (8, 3, 5, 5) diff --git a/tests/micro/zephyr/utils.py b/tests/micro/zephyr/utils.py index d46a1b644cbd..a4fcc215658e 100644 --- a/tests/micro/zephyr/utils.py +++ b/tests/micro/zephyr/utils.py @@ -44,6 +44,7 @@ PASS_CONFIG = {"tir.disable_vectorize": True} + def zephyr_boards() -> dict: """Returns Zephyr board properties""" with open(TEMPLATE_PROJECT_DIR / "boards.json") as f: From 42a081b73971055fdcabccb2b7c1a43fb61798d3 Mon Sep 17 00:00:00 2001 From: Mehrdad Hessar Date: Fri, 24 Feb 2023 12:35:38 -0800 Subject: [PATCH 5/7] Fix errors --- apps/microtvm/cmsisnn/run_demo.sh | 1 - apps/microtvm/ethosu/run_demo.sh | 1 - tests/python/contrib/test_cmsisnn/test_conv2d.py | 1 + tests/python/relay/aot/test_crt_aot.py | 3 +++ tests/python/unittest/test_micro_model_library_format.py | 8 ++++++-- 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/apps/microtvm/cmsisnn/run_demo.sh b/apps/microtvm/cmsisnn/run_demo.sh index e5d1064e6e65..c807aa6a3a8e 100755 --- a/apps/microtvm/cmsisnn/run_demo.sh +++ b/apps/microtvm/cmsisnn/run_demo.sh @@ -125,7 +125,6 @@ python3 -m tvm.driver.tvmc compile --target=cmsis-nn,c \ --executor=aot \ --executor-aot-interface-api=c \ --executor-aot-unpacked-api=1 \ - --pass-config tir.usmp.enable=1 \ --pass-config tir.usmp.algorithm=hill_climb \ --pass-config tir.disable_storage_rewrite=1 \ --pass-config tir.disable_vectorize=1 ./person_detect.tflite \ diff --git a/apps/microtvm/ethosu/run_demo.sh b/apps/microtvm/ethosu/run_demo.sh index 7490f979b834..958c29057405 100755 --- a/apps/microtvm/ethosu/run_demo.sh +++ b/apps/microtvm/ethosu/run_demo.sh @@ -152,7 +152,6 @@ python3 -m tvm.driver.tvmc compile --target=ethos-u,cmsis-nn,c \ --executor=aot \ --executor-aot-interface-api=c \ --executor-aot-unpacked-api=1 \ - --pass-config tir.usmp.enable=1 \ --pass-config tir.usmp.algorithm=hill_climb \ --pass-config tir.disable_storage_rewrite=1 \ --pass-config tir.disable_vectorize=1 ./mobilenet_v2_1.0_224_INT8.tflite --output-format=mlf diff --git a/tests/python/contrib/test_cmsisnn/test_conv2d.py b/tests/python/contrib/test_cmsisnn/test_conv2d.py index 20e7b9ed2f62..6f012640c2ae 100644 --- a/tests/python/contrib/test_cmsisnn/test_conv2d.py +++ b/tests/python/contrib/test_cmsisnn/test_conv2d.py @@ -210,6 +210,7 @@ def test_conv2d_number_primfunc_args( AOTTestModel(module=cmsisnn_mod, inputs=inputs, outputs=output_list, params=params), interface_api, use_unpacked_api, + pass_config={"tir.usmp.enable": False}, ) # validate number of TIR primfunc args diff --git a/tests/python/relay/aot/test_crt_aot.py b/tests/python/relay/aot/test_crt_aot.py index d99d6173bc5f..1eb34b07d7ab 100644 --- a/tests/python/relay/aot/test_crt_aot.py +++ b/tests/python/relay/aot/test_crt_aot.py @@ -802,6 +802,7 @@ def @main(%data: Tensor[(1, 4, 4, 4), float32], %weight: Tensor[(4, 4, 3, 3), fl models=AOTTestModel(module=relay_mod, inputs=None, outputs=None), interface_api="c", use_unpacked_api=True, + pass_config={"tir.usmp.enable": False}, ) source = compiled_test_mods[0].executor_factory.lib.imported_modules[0].get_source() # There should be three allocates created for three primitive relay function @@ -827,6 +828,7 @@ def test_constants_alignment(constants_byte_alignment): interface_api, use_unpacked_api, target=tvm.target.Target(target, host=target), + pass_config={"tir.usmp.enable": False}, ) source = compiled_test_mods[0].executor_factory.lib.imported_modules[0].get_source() assert f'__attribute__((section(".rodata.tvm"), aligned({constants_byte_alignment})))' in source @@ -966,6 +968,7 @@ def test_workspace_calculation(workspace_byte_alignment, main_workspace_size): opt_level=3, config={ "tir.disable_vectorize": True, + "tir.usmp.enable": False, }, ): lib = tvm.relay.build(mod, target, executor=executor, runtime=runtime, params=params) diff --git a/tests/python/unittest/test_micro_model_library_format.py b/tests/python/unittest/test_micro_model_library_format.py index 6f79723de456..d4886456d98b 100644 --- a/tests/python/unittest/test_micro_model_library_format.py +++ b/tests/python/unittest/test_micro_model_library_format.py @@ -159,7 +159,9 @@ def test_export_model_library_format_c( ): target = tvm.target.target.micro("host") with utils.TempDirectory.set_keep_for_debug(True): - with tvm.transform.PassContext(opt_level=3, config={"tir.disable_vectorize": True}): + with tvm.transform.PassContext( + opt_level=3, config={"tir.disable_vectorize": True, "tir.usmp.enable": False} + ): relay_mod = tvm.relay.fromtext( """ #[version = "0.0.5"] @@ -338,7 +340,9 @@ def @main(%a : Tensor[(1, 2), uint8], %b : Tensor[(1, 2), float32], %c : Tensor[ ) def test_export_model_library_format_workspace(executor, runtime): target = tvm.target.target.micro("host") - with tvm.transform.PassContext(opt_level=3, config={"tir.disable_vectorize": True}): + with tvm.transform.PassContext( + opt_level=3, config={"tir.disable_vectorize": True, "tir.usmp.enable": False} + ): relay_mod = tvm.relay.fromtext( """ #[version = "0.0.5"] From 1f3bf1da3e039981bf2f6cb1917641388cb1c114 Mon Sep 17 00:00:00 2001 From: Mehrdad Hessar Date: Wed, 1 Mar 2023 12:20:01 -0800 Subject: [PATCH 6/7] cleanup --- apps/microtvm/cmsisnn/run_demo.sh | 1 + apps/microtvm/ethosu/run_demo.sh | 1 + src/relay/backend/aot_executor_codegen.cc | 1 - tests/micro/arduino/__init__.py | 18 ------------- .../arduino/test_arduino_error_detection.py | 4 +-- .../micro/arduino/test_arduino_rpc_server.py | 25 +++++++++---------- tests/micro/arduino/test_arduino_workflow.py | 7 +++--- .../micro/arduino/{utils.py => test_utils.py} | 4 +-- tests/micro/zephyr/test_ms_tuning.py | 6 ++--- tests/micro/zephyr/test_zephyr.py | 16 ++++++------ tests/micro/zephyr/test_zephyr_aot_exec.py | 5 ++-- .../zephyr/test_zephyr_aot_exec_standalone.py | 5 +--- tests/micro/zephyr/test_zephyr_armv7m.py | 2 +- tests/micro/zephyr/utils.py | 2 -- 14 files changed, 34 insertions(+), 63 deletions(-) delete mode 100644 tests/micro/arduino/__init__.py rename tests/micro/arduino/{utils.py => test_utils.py} (96%) diff --git a/apps/microtvm/cmsisnn/run_demo.sh b/apps/microtvm/cmsisnn/run_demo.sh index c807aa6a3a8e..e5d1064e6e65 100755 --- a/apps/microtvm/cmsisnn/run_demo.sh +++ b/apps/microtvm/cmsisnn/run_demo.sh @@ -125,6 +125,7 @@ python3 -m tvm.driver.tvmc compile --target=cmsis-nn,c \ --executor=aot \ --executor-aot-interface-api=c \ --executor-aot-unpacked-api=1 \ + --pass-config tir.usmp.enable=1 \ --pass-config tir.usmp.algorithm=hill_climb \ --pass-config tir.disable_storage_rewrite=1 \ --pass-config tir.disable_vectorize=1 ./person_detect.tflite \ diff --git a/apps/microtvm/ethosu/run_demo.sh b/apps/microtvm/ethosu/run_demo.sh index 958c29057405..7490f979b834 100755 --- a/apps/microtvm/ethosu/run_demo.sh +++ b/apps/microtvm/ethosu/run_demo.sh @@ -152,6 +152,7 @@ python3 -m tvm.driver.tvmc compile --target=ethos-u,cmsis-nn,c \ --executor=aot \ --executor-aot-interface-api=c \ --executor-aot-unpacked-api=1 \ + --pass-config tir.usmp.enable=1 \ --pass-config tir.usmp.algorithm=hill_climb \ --pass-config tir.disable_storage_rewrite=1 \ --pass-config tir.disable_vectorize=1 ./mobilenet_v2_1.0_224_INT8.tflite --output-format=mlf diff --git a/src/relay/backend/aot_executor_codegen.cc b/src/relay/backend/aot_executor_codegen.cc index d31dea69aac9..6bbb43f50f21 100644 --- a/src/relay/backend/aot_executor_codegen.cc +++ b/src/relay/backend/aot_executor_codegen.cc @@ -44,7 +44,6 @@ #include #include -#include "../../target/parsers/mprofile.h" #include "../../target/source/codegen_source_base.h" #include "../op/annotation/annotation.h" #include "../op/call/call.h" diff --git a/tests/micro/arduino/__init__.py b/tests/micro/arduino/__init__.py deleted file mode 100644 index 5c5b65e7cdde..000000000000 --- a/tests/micro/arduino/__init__.py +++ /dev/null @@ -1,18 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. - -""" Testing infrastructure for microTVM Arduino """ diff --git a/tests/micro/arduino/test_arduino_error_detection.py b/tests/micro/arduino/test_arduino_error_detection.py index 17b3007d7926..75b97fa86ca3 100644 --- a/tests/micro/arduino/test_arduino_error_detection.py +++ b/tests/micro/arduino/test_arduino_error_detection.py @@ -19,13 +19,13 @@ from tvm.micro.project_api.server import ServerError -from . import utils +import test_utils import tvm.testing @pytest.fixture def project(board, microtvm_debug, workspace_dir, serial_number): - return utils.make_kws_project(board, microtvm_debug, workspace_dir, serial_number) + return test_utils.make_kws_project(board, microtvm_debug, workspace_dir, serial_number) def test_blank_project_compiles(workspace_dir, project): diff --git a/tests/micro/arduino/test_arduino_rpc_server.py b/tests/micro/arduino/test_arduino_rpc_server.py index c7aa441b5f7d..bc31ceb60570 100644 --- a/tests/micro/arduino/test_arduino_rpc_server.py +++ b/tests/micro/arduino/test_arduino_rpc_server.py @@ -23,7 +23,6 @@ """ import pathlib -import sys import numpy as np import onnx import pytest @@ -35,7 +34,7 @@ from tvm.relay.testing import byoc from tvm.relay.backend import Executor, Runtime -from . import utils +import test_utils def _make_session( @@ -47,7 +46,7 @@ def _make_session( serial_number: str = None, ): project = tvm.micro.generate_project( - str(utils.TEMPLATE_PROJECT_DIR), + str(test_utils.TEMPLATE_PROJECT_DIR), mod, workspace_dir / "project", { @@ -74,7 +73,7 @@ def _make_sess_from_op( ): target = tvm.target.target.micro(model) runtime = Runtime("crt", {"system-lib": True}) - with tvm.transform.PassContext(opt_level=3, config=utils.PASS_CONFIG): + with tvm.transform.PassContext(opt_level=3, config={"tir.disable_vectorize": True}): mod = tvm.build(sched, arg_bufs, target=target, runtime=runtime, name=op_name) return _make_session(model, arduino_board, workspace_dir, mod, build_config, serial_number) @@ -103,7 +102,7 @@ def _make_add_sess(model, arduino_board, workspace_dir, build_config, serial_num def test_compile_runtime(board, microtvm_debug, workspace_dir, serial_number): """Test compiling the on-device runtime.""" - model = utils.ARDUINO_BOARDS[board] + model = test_utils.ARDUINO_BOARDS[board] build_config = {"debug": microtvm_debug} # NOTE: run test in a nested function so cPython will delete arrays before closing the session. @@ -128,7 +127,7 @@ def test_basic_add(sess): def test_platform_timer(board, microtvm_debug, workspace_dir, serial_number): """Test compiling the on-device runtime.""" - model = utils.ARDUINO_BOARDS[board] + model = test_utils.ARDUINO_BOARDS[board] build_config = {"debug": microtvm_debug} # NOTE: run test in a nested function so cPython will delete arrays before closing the session. @@ -157,7 +156,7 @@ def test_basic_add(sess): @pytest.mark.requires_hardware def test_relay(board, microtvm_debug, workspace_dir, serial_number): """Testing a simple relay graph""" - model = utils.ARDUINO_BOARDS[board] + model = test_utils.ARDUINO_BOARDS[board] build_config = {"debug": microtvm_debug} shape = (10,) @@ -171,7 +170,7 @@ def test_relay(board, microtvm_debug, workspace_dir, serial_number): target = tvm.target.target.micro(model) runtime = Runtime("crt", {"system-lib": True}) - with tvm.transform.PassContext(opt_level=3, config=utils.PASS_CONFIG): + with tvm.transform.PassContext(opt_level=3, config={"tir.disable_vectorize": True}): mod = tvm.relay.build(func, target=target, runtime=runtime) with _make_session(model, board, workspace_dir, mod, build_config, serial_number) as session: @@ -190,7 +189,7 @@ def test_relay(board, microtvm_debug, workspace_dir, serial_number): @pytest.mark.requires_hardware def test_onnx(board, microtvm_debug, workspace_dir, serial_number): """Testing a simple ONNX model.""" - model = utils.ARDUINO_BOARDS[board] + model = test_utils.ARDUINO_BOARDS[board] build_config = {"debug": microtvm_debug} # Load test images. @@ -212,7 +211,7 @@ def test_onnx(board, microtvm_debug, workspace_dir, serial_number): target = tvm.target.target.micro(model) runtime = Runtime("crt", {"system-lib": True}) - with tvm.transform.PassContext(opt_level=3, config=utils.PASS_CONFIG): + with tvm.transform.PassContext(opt_level=3, config={"tir.disable_vectorize": True}): executor = Executor("graph", {"link-params": True}) lowered = relay.build(relay_mod, target, params=params, executor=executor, runtime=runtime) graph = lowered.get_graph_json() @@ -253,7 +252,7 @@ def check_result( TOL = 1e-5 target = tvm.target.target.micro(model) runtime = Runtime("crt", {"system-lib": True}) - with tvm.transform.PassContext(opt_level=3, config=utils.PASS_CONFIG): + with tvm.transform.PassContext(opt_level=3, config={"tir.disable_vectorize": True}): mod = tvm.relay.build(relay_mod, target=target, runtime=runtime) with _make_session( @@ -281,7 +280,7 @@ def check_result( @pytest.mark.requires_hardware def test_byoc_microtvm(board, microtvm_debug, workspace_dir, serial_number): """This is a simple test case to check BYOC capabilities of microTVM""" - model = utils.ARDUINO_BOARDS[board] + model = test_utils.ARDUINO_BOARDS[board] build_config = {"debug": microtvm_debug} x = relay.var("x", shape=(10, 10)) @@ -377,7 +376,7 @@ def _make_add_sess_with_shape( @pytest.mark.requires_hardware def test_rpc_large_array(board, microtvm_debug, workspace_dir, shape, serial_number): """Test large RPC array transfer.""" - model = utils.ARDUINO_BOARDS[board] + model = test_utils.ARDUINO_BOARDS[board] build_config = {"debug": microtvm_debug} # NOTE: run test in a nested function so cPython will delete arrays before closing the session. diff --git a/tests/micro/arduino/test_arduino_workflow.py b/tests/micro/arduino/test_arduino_workflow.py index 03b16569e243..a9b7e48c452a 100644 --- a/tests/micro/arduino/test_arduino_workflow.py +++ b/tests/micro/arduino/test_arduino_workflow.py @@ -18,12 +18,11 @@ import pathlib import re import shutil -import sys import pytest import tvm.testing -from . import utils +import test_utils """ This unit test simulates a simple user workflow, where we: @@ -43,7 +42,7 @@ @pytest.fixture(scope="module") def workflow_workspace_dir(request): board = request.config.getoption("--board") - return utils.make_workspace_dir("arduino_workflow", board) + return test_utils.make_workspace_dir("arduino_workflow", board) @pytest.fixture(scope="module") @@ -57,7 +56,7 @@ def project_dir(workflow_workspace_dir): def project(request, microtvm_debug, workflow_workspace_dir): board = request.config.getoption("--board") serial_number = request.config.getoption("--serial-number") - return utils.make_kws_project(board, microtvm_debug, workflow_workspace_dir, serial_number) + return test_utils.make_kws_project(board, microtvm_debug, workflow_workspace_dir, serial_number) def _get_directory_elements(directory): diff --git a/tests/micro/arduino/utils.py b/tests/micro/arduino/test_utils.py similarity index 96% rename from tests/micro/arduino/utils.py rename to tests/micro/arduino/test_utils.py index 6d518800acab..1456e1f7591e 100644 --- a/tests/micro/arduino/utils.py +++ b/tests/micro/arduino/test_utils.py @@ -31,8 +31,6 @@ BOARDS = TEMPLATE_PROJECT_DIR / "boards.json" -PASS_CONFIG = {"tir.disable_vectorize": True} - def arduino_boards() -> dict: """Returns a dict mapping board to target model""" @@ -78,7 +76,7 @@ def make_kws_project(board, microtvm_debug, workspace_dir, serial_number: str): runtime = Runtime("crt") executor = Executor("aot", {"unpacked-api": True}) - with tvm.transform.PassContext(opt_level=3, config=PASS_CONFIG): + with tvm.transform.PassContext(opt_level=3, config={"tir.disable_vectorize": True}): mod = relay.build(mod, target, runtime=runtime, executor=executor, params=params) return tvm.micro.generate_project( diff --git a/tests/micro/zephyr/test_ms_tuning.py b/tests/micro/zephyr/test_ms_tuning.py index 4dc2942436b6..3adc9ce2c8fc 100644 --- a/tests/micro/zephyr/test_ms_tuning.py +++ b/tests/micro/zephyr/test_ms_tuning.py @@ -24,13 +24,11 @@ from tvm import relay import tvm.micro.testing from tvm.relay.backend import Executor -from tvm.contrib import graph_executor, utils +from tvm.contrib import graph_executor from tvm import meta_schedule as ms from tvm.contrib.micro.meta_schedule.local_builder_micro import get_local_builder_micro from tvm.contrib.micro.meta_schedule.rpc_runner_micro import get_rpc_runner_micro -from . import utils - def create_relay_module(): data_shape = (1, 3, 16, 16) @@ -163,7 +161,7 @@ def test_ms_tuning_conv2d(workspace_dir, board, microtvm_debug, use_fvp, serial_ dev = tvm.cpu() target = tvm.micro.testing.get_target("crt") with tvm.transform.PassContext( - opt_level=3, config=utils.PASS_CONFIG, disabled_pass=["AlterOpLayout"] + opt_level=3, config={"tir.disable_vectorize": True}, disabled_pass=["AlterOpLayout"] ): ref_mod = relay.build( mod, diff --git a/tests/micro/zephyr/test_zephyr.py b/tests/micro/zephyr/test_zephyr.py index f5f37d476f74..72a0a85cf96f 100644 --- a/tests/micro/zephyr/test_zephyr.py +++ b/tests/micro/zephyr/test_zephyr.py @@ -52,7 +52,7 @@ def _make_sess_from_op( runtime = Runtime("crt", {"system-lib": True}) target = tvm.micro.testing.get_target("zephyr", board) target = tvm.target.Target(target=target, host=target) - with tvm.transform.PassContext(opt_level=3, config=utils.PASS_CONFIG): + with tvm.transform.PassContext(opt_level=3, config={"tir.disable_vectorize": True}): mod = tvm.build(sched, arg_bufs, target=target, runtime=runtime, name=op_name) return _make_session(temp_dir, board, mod, build_config, use_fvp, serial_number) @@ -209,7 +209,7 @@ def test_relay(workspace_dir, board, microtvm_debug, use_fvp, serial_number): runtime = Runtime("crt", {"system-lib": True}) target = tvm.micro.testing.get_target("zephyr", board) - with tvm.transform.PassContext(opt_level=3, config=utils.PASS_CONFIG): + with tvm.transform.PassContext(opt_level=3, config={"tir.disable_vectorize": True}): mod = tvm.relay.build(ir_mod, target=target, runtime=runtime) with _make_session(workspace_dir, board, mod, build_config, use_fvp, serial_number) as session: @@ -252,7 +252,7 @@ def test_onnx(workspace_dir, board, microtvm_debug, use_fvp, serial_number): # the model weights when set using graph_mod.set_input(). # See: https://github.com/apache/tvm/issues/7567 target = tvm.micro.testing.get_target("zephyr", board) - with tvm.transform.PassContext(opt_level=3, config=utils.PASS_CONFIG): + with tvm.transform.PassContext(opt_level=3, config={"tir.disable_vectorize": True}): executor = Executor("graph", {"link-params": True}) runtime = Runtime("crt", {"system-lib": True}) lowered = relay.build(relay_mod, target, params=params, executor=executor, runtime=runtime) @@ -293,7 +293,7 @@ def check_result( TOL = 1e-5 runtime = Runtime("crt", {"system-lib": True}) target = tvm.micro.testing.get_target("zephyr", board) - with tvm.transform.PassContext(opt_level=3, config=utils.PASS_CONFIG): + with tvm.transform.PassContext(opt_level=3, config={"tir.disable_vectorize": True}): mod = tvm.relay.build(relay_mod, target=target, runtime=runtime) with _make_session(temp_dir, board, mod, build_config, use_fvp, serial_number) as session: @@ -454,7 +454,7 @@ def test_autotune_conv2d(workspace_dir, board, microtvm_debug, use_fvp, serial_n params = {mod["main"].params[1].name_hint: weight_sample} target = tvm.micro.testing.get_target("zephyr", board) - pass_context = tvm.transform.PassContext(opt_level=3, config=utils.PASS_CONFIG) + pass_context = tvm.transform.PassContext(opt_level=3, config={"tir.disable_vectorize": True}) with pass_context: tasks = tvm.autotvm.task.extract_from_program(mod["main"], {}, target) assert len(tasks) > 0 @@ -482,7 +482,7 @@ def test_autotune_conv2d(workspace_dir, board, microtvm_debug, use_fvp, serial_n builder = tvm.autotvm.LocalBuilder( timeout=timeout, n_parallel=1, - build_kwargs={"build_option": utils.PASS_CONFIG}, + build_kwargs={"build_option": {"tir.disable_vectorize": True}}, do_fork=True, build_func=tvm.micro.autotvm_build_func, runtime=runtime, @@ -580,7 +580,7 @@ def test_schedule_build_with_cmsis_dependency(workspace_dir, board, microtvm_deb runtime = Runtime("crt", {"system-lib": True}) - with tvm.transform.PassContext(opt_level=3, config=utils.PASS_CONFIG): + with tvm.transform.PassContext(opt_level=3, config={"tir.disable_vectorize": True}): mod = tvm.relay.build(ir_mod, target=target, runtime=runtime) project_options = { @@ -633,7 +633,7 @@ def test_debugging_enabled(workspace_dir): executor = Executor("aot") target = tvm.micro.testing.get_target("zephyr", board) - with tvm.transform.PassContext(opt_level=3, config=utils.PASS_CONFIG): + with tvm.transform.PassContext(opt_level=3, config={"tir.disable_vectorize": True}): mod = tvm.relay.build(ir_mod, target=target, runtime=runtime, executor=executor) project = tvm.micro.generate_project( diff --git a/tests/micro/zephyr/test_zephyr_aot_exec.py b/tests/micro/zephyr/test_zephyr_aot_exec.py index 76e03c35c511..7c8018134599 100644 --- a/tests/micro/zephyr/test_zephyr_aot_exec.py +++ b/tests/micro/zephyr/test_zephyr_aot_exec.py @@ -22,7 +22,6 @@ import tvm.micro.testing import tvm.relay as relay from tvm.relay.backend import Executor, Runtime -from tvm.contrib import utils from . import utils @@ -78,7 +77,7 @@ def test_relay(workspace_dir, board, microtvm_debug, use_fvp, serial_number): runtime = Runtime("crt", {"system-lib": True}) executor = Executor("aot") target = tvm.micro.testing.get_target("zephyr", board) - with tvm.transform.PassContext(opt_level=3, config=utils.PASS_CONFIG): + with tvm.transform.PassContext(opt_level=3, config={"tir.disable_vectorize": True}): mod = tvm.relay.build(ir_mod, target=target, runtime=runtime, executor=executor) with _make_session(workspace_dir, board, mod, build_config, use_fvp, serial_number) as session: @@ -117,7 +116,7 @@ def @main(%a : Tensor[(1, 2), uint8], %b : Tensor[(1, 2), uint8]) { runtime = Runtime("crt", {"system-lib": True}) executor = Executor("aot") target = tvm.micro.testing.get_target("zephyr", board) - with tvm.transform.PassContext(opt_level=3, config=utils.PASS_CONFIG): + with tvm.transform.PassContext(opt_level=3, config={"tir.disable_vectorize": True}): mod = tvm.relay.build(relay_mod, target=target, runtime=runtime, executor=executor) def do_test(): diff --git a/tests/micro/zephyr/test_zephyr_aot_exec_standalone.py b/tests/micro/zephyr/test_zephyr_aot_exec_standalone.py index fc73ba8121f6..6995bacdb5d0 100644 --- a/tests/micro/zephyr/test_zephyr_aot_exec_standalone.py +++ b/tests/micro/zephyr/test_zephyr_aot_exec_standalone.py @@ -14,9 +14,6 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -import os -import pathlib - import pytest import numpy as np @@ -62,7 +59,7 @@ def test_tflite(workspace_dir, board, microtvm_debug, serial_number): "aot", {"unpacked-api": True, "interface-api": "c", "workspace-byte-alignment": 4} ) runtime = Runtime("crt") - with tvm.transform.PassContext(opt_level=3, config=utils.PASS_CONFIG): + with tvm.transform.PassContext(opt_level=3, config={"tir.disable_vectorize": True}): lowered = relay.build(relay_mod, target, params=params, runtime=runtime, executor=executor) sample_url = "https://github.com/tlc-pack/web-data/raw/main/testdata/microTVM/data/keyword_spotting_int8_6.pyc.npy" diff --git a/tests/micro/zephyr/test_zephyr_armv7m.py b/tests/micro/zephyr/test_zephyr_armv7m.py index 05e3c5330394..cd589a19e886 100644 --- a/tests/micro/zephyr/test_zephyr_armv7m.py +++ b/tests/micro/zephyr/test_zephyr_armv7m.py @@ -128,7 +128,7 @@ def test_armv7m_intrinsic(workspace_dir, board, microtvm_debug, serial_number): os.makedirs(workspace_dir_simd, exist_ok=True) os.makedirs(workspace_dir_no_simd, exist_ok=True) - with tvm.transform.PassContext(opt_level=3, config=utils.PASS_CONFIG): + with tvm.transform.PassContext(opt_level=3, config={"tir.disable_vectorize": True}): lowered_simd = relay.build( relay_mod_simd, target_simd, params=params, runtime=runtime, executor=executor ) diff --git a/tests/micro/zephyr/utils.py b/tests/micro/zephyr/utils.py index a4fcc215658e..fed7c53c2915 100644 --- a/tests/micro/zephyr/utils.py +++ b/tests/micro/zephyr/utils.py @@ -42,8 +42,6 @@ _LOG = logging.getLogger(__name__) -PASS_CONFIG = {"tir.disable_vectorize": True} - def zephyr_boards() -> dict: """Returns Zephyr board properties""" From e4d10e576787c4c7064c1b3116ad64a2ad9583d5 Mon Sep 17 00:00:00 2001 From: Mehrdad Hessar Date: Wed, 1 Mar 2023 16:47:49 -0800 Subject: [PATCH 7/7] remove workspace in mlperftiny project --- .../template_project/src/mlperftiny/platform.cc | 17 ----------------- .../src/mlperftiny/submitter_implemented.cc | 2 +- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/apps/microtvm/zephyr/template_project/src/mlperftiny/platform.cc b/apps/microtvm/zephyr/template_project/src/mlperftiny/platform.cc index 9dc4516271df..f50911b52dbc 100644 --- a/apps/microtvm/zephyr/template_project/src/mlperftiny/platform.cc +++ b/apps/microtvm/zephyr/template_project/src/mlperftiny/platform.cc @@ -38,10 +38,6 @@ #include "crt_config.h" -// TVM_WORKSPACE_SIZE_BYTES is defined in python -static uint8_t g_aot_memory[TVM_WORKSPACE_SIZE_BYTES]; -tvm_workspace_t app_workspace; - size_t TVMPlatformFormatMessage(char* out_buf, size_t out_buf_size_bytes, const char* fmt, va_list args) { return vsnprintk(out_buf, out_buf_size_bytes, fmt, args); @@ -53,16 +49,3 @@ void TVMPlatformAbort(tvm_crt_error_t error) { for (;;) ; } - -tvm_crt_error_t TVMPlatformMemoryAllocate(size_t num_bytes, DLDevice dev, void** out_ptr) { - return StackMemoryManager_Allocate(&app_workspace, num_bytes, out_ptr); -} - -tvm_crt_error_t TVMPlatformMemoryFree(void* ptr, DLDevice dev) { - return StackMemoryManager_Free(&app_workspace, ptr); -} - -tvm_crt_error_t TVMPlatformInitialize() { - StackMemoryManager_Init(&app_workspace, g_aot_memory, sizeof(g_aot_memory)); - return kTvmErrorNoError; -} diff --git a/apps/microtvm/zephyr/template_project/src/mlperftiny/submitter_implemented.cc b/apps/microtvm/zephyr/template_project/src/mlperftiny/submitter_implemented.cc index 96c04b1e80a0..b74c6e8eaf6f 100644 --- a/apps/microtvm/zephyr/template_project/src/mlperftiny/submitter_implemented.cc +++ b/apps/microtvm/zephyr/template_project/src/mlperftiny/submitter_implemented.cc @@ -259,7 +259,7 @@ void th_infer() { Infer(g_input_data); } /// \brief optional API. // Modified from source -void th_final_initialize(void) { TVMPlatformInitialize(); } +void th_final_initialize(void) {} void th_pre() {} void th_post() {}