From a9b3b880533959d824fe396f9de637f19158364c Mon Sep 17 00:00:00 2001 From: Leandro Nunes Date: Tue, 18 May 2021 11:32:05 +0100 Subject: [PATCH] Add Arm(R) Ethos(TM)-U codegen support on tvmc * Include `ethos-u` as a new target for tvmc * Adds testing for the new target Co-authored-by: Manupa Karunaratne --- python/tvm/driver/tvmc/composite_target.py | 5 +++ tests/python/driver/tvmc/test_compiler.py | 36 ++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/python/tvm/driver/tvmc/composite_target.py b/python/tvm/driver/tvmc/composite_target.py index ac1a41a0c4a97..eb2ffd8cd3e3b 100644 --- a/python/tvm/driver/tvmc/composite_target.py +++ b/python/tvm/driver/tvmc/composite_target.py @@ -24,6 +24,7 @@ from tvm.relay.op.contrib.arm_compute_lib import partition_for_arm_compute_lib from tvm.relay.op.contrib.ethosn import partition_for_ethosn +from tvm.relay.backend.contrib.ethosu import partition_for_ethosu from tvm.relay.op.contrib.bnns import partition_for_bnns from tvm.relay.op.contrib.vitis_ai import partition_for_vitis_ai @@ -53,6 +54,10 @@ "config_key": "relay.ext.ethos-n.options", "pass_pipeline": partition_for_ethosn, }, + "ethos-u": { + "config_key": "relay.ext.ethosu.options", + "pass_pipeline": partition_for_ethosu, + }, "bnns": { "config_key": None, "pass_pipeline": partition_for_bnns, diff --git a/tests/python/driver/tvmc/test_compiler.py b/tests/python/driver/tvmc/test_compiler.py index 16c02335c8a04..c2bdf7d2ec2e0 100644 --- a/tests/python/driver/tvmc/test_compiler.py +++ b/tests/python/driver/tvmc/test_compiler.py @@ -15,7 +15,9 @@ # specific language governing permissions and limitations # under the License. import os +import re import shutil +import tarfile from os import path from unittest import mock @@ -331,6 +333,40 @@ def test_compile_tflite_module_with_external_codegen_vitis_ai(tflite_mobilenet_v assert os.path.exists(dumps_path) +def test_compile_tflite_module_with_external_codegen_ethosu( + tmpdir_factory, tflite_mobilenet_v1_1_quant +): + pytest.importorskip("tflite") + ACCEL_TYPES = ["ethos-u55-256", "ethos-u55-128", "ethos-u55-64", "ethos-u55-32"] + + output_dir = tmpdir_factory.mktemp("mlf") + + tvmc_model = tvmc.load(tflite_mobilenet_v1_1_quant) + + for accel_type in ACCEL_TYPES: + output_file_name = f"{output_dir}/file_{accel_type}.tar" + + tvmc_package = tvmc.compiler.compile_model( + tvmc_model, + target=f"ethos-u -accelerator_config={accel_type}, c -runtime=c --system-lib --link-params -mcpu=cortex-m55 --executor=aot", + output_format="mlf", + package_path=output_file_name, + pass_context_configs=["tir.disable_vectorize=true"], + ) + + # check whether an MLF package was created + assert os.path.exists(output_file_name) + + # check whether the expected number of C sources are in the tarfile + with tarfile.open(output_file_name) as mlf_package: + c_source_files = [ + name + for name in mlf_package.getnames() + if re.match(r"\./codegen/host/src/\D+\d+\.c", name) + ] + assert len(c_source_files) == 17 + + @mock.patch("tvm.relay.build") @mock.patch("tvm.driver.tvmc.composite_target.get_codegen_by_target") @mock.patch("tvm.driver.tvmc.load")