Skip to content

Commit

Permalink
Add Arm(R) Ethos(TM)-U codegen support on tvmc
Browse files Browse the repository at this point in the history
* Include `ethos-u` as a new target for tvmc
* Adds testing for the new target

Co-authored-by: Manupa Karunaratne <manupa.karunaratne@arm.com>
  • Loading branch information
leandron and manupak committed Aug 26, 2021
1 parent ea1021a commit a9b3b88
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
5 changes: 5 additions & 0 deletions python/tvm/driver/tvmc/composite_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down
36 changes: 36 additions & 0 deletions tests/python/driver/tvmc/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit a9b3b88

Please sign in to comment.