From f78bbc401e70da43cbcb531c9115ac197115ef51 Mon Sep 17 00:00:00 2001 From: Andrew Reusch Date: Wed, 13 Jan 2021 13:14:37 -0800 Subject: [PATCH] fix mcpu on os x --- python/tvm/micro/compiler.py | 6 ++++++ python/tvm/target/target.py | 2 +- tests/python/unittest/test_link_params.py | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/python/tvm/micro/compiler.py b/python/tvm/micro/compiler.py index 3b62e9347c7f..765c1a8b264b 100644 --- a/python/tvm/micro/compiler.py +++ b/python/tvm/micro/compiler.py @@ -106,6 +106,12 @@ def _target_from_sources(cls, sources): } def _autodetect_toolchain_prefix(self, target): + # Treat absence of -mcpu as if -mcpu=native is specified. The gcc shipped with OS X + # complains if -mcpu=native is given, so this approach allows model targets to avoid + # specifying this flag e.g. for tutorials. + if "mcpu" not in target.attrs: + return self.TOOLCHAIN_PREFIX_BY_CPU_REGEX["native"] + matches = [] for regex, prefix in self.TOOLCHAIN_PREFIX_BY_CPU_REGEX.items(): if re.match(regex, target.attrs["mcpu"]): diff --git a/python/tvm/target/target.py b/python/tvm/target/target.py index edbb0fa3792a..161cd549fade 100644 --- a/python/tvm/target/target.py +++ b/python/tvm/target/target.py @@ -232,7 +232,7 @@ def micro(model="unknown", options=None): Additional options """ trans_table = { - "host": ["-mcpu=native"], + "host": [], "stm32f746xx": ["-mcpu=cortex-m7", "-march=armv7e-m"], } opts = _merge_opts( diff --git a/tests/python/unittest/test_link_params.py b/tests/python/unittest/test_link_params.py index da87a3177c7c..52d7a27838d7 100644 --- a/tests/python/unittest/test_link_params.py +++ b/tests/python/unittest/test_link_params.py @@ -347,7 +347,7 @@ def test_crt_link_params(): mod, param_init = _make_mod_and_params(dtype) rand_input = _make_random_tensor(dtype, INPUT_SHAPE) main_func = mod["main"] - target = "c -mcpu=native --system-lib --runtime=c --link-params" + target = "c --system-lib --runtime=c --link-params" with tvm.transform.PassContext(opt_level=3, config={"tir.disable_vectorize": True}): graph_json, lib, params = tvm.relay.build(mod, target, params=param_init) assert set(params.keys()) == {"p0", "p1"} # NOTE: op folded