diff --git a/python/tvm/driver/tvmc/composite_target.py b/python/tvm/driver/tvmc/composite_target.py index de743799f01c..88bea9980014 100644 --- a/python/tvm/driver/tvmc/composite_target.py +++ b/python/tvm/driver/tvmc/composite_target.py @@ -18,12 +18,13 @@ Provides support to composite target on TVMC. """ import logging +import warnings # Make sure Vitis AI codegen is registered import tvm.contrib.target.vitis_ai # pylint: disable=unused-import from tvm.relay.op.contrib.arm_compute_lib import partition_for_arm_compute_lib -from tvm.relay.op.contrib.ethosn import partition_for_ethosn78 +from tvm.relay.op.contrib.ethosn import partition_for_ethosn from tvm.relay.op.contrib.cmsisnn import partition_for_cmsisnn from tvm.relay.op.contrib.ethosu import partition_for_ethosu from tvm.relay.op.contrib.bnns import partition_for_bnns @@ -55,9 +56,9 @@ "config_key": "relay.ext.cmsisnn.options", "pass_pipeline": partition_for_cmsisnn, }, - "ethos-n78": { + "ethos-n": { "config_key": "relay.ext.ethos-n.options", - "pass_pipeline": partition_for_ethosn78, + "pass_pipeline": partition_for_ethosn, }, "ethos-u": { "config_key": "relay.ext.ethos-u.options", @@ -71,6 +72,11 @@ "config_key": "relay.ext.vitis_ai.options", "pass_pipeline": partition_for_vitis_ai, }, + # Deprecated in favour of "ethos-n". + "ethos-n78": { + "config_key": "relay.ext.ethos-n.options", + "pass_pipeline": partition_for_ethosn, + }, } @@ -99,6 +105,12 @@ def get_codegen_by_target(name): requested target codegen information """ try: + if name == "ethos-n78": + warnings.warn( + "Please use 'ethos-n' instead of the deprecated 'ethos-n78' target, " + "which will be removed in a later release of TVM.", + DeprecationWarning, + ) return REGISTERED_CODEGEN[name] except KeyError: raise TVMCException("Composite target %s is not defined in TVMC." % name) diff --git a/python/tvm/relay/op/contrib/ethosn.py b/python/tvm/relay/op/contrib/ethosn.py index a1a3e2dccc4c..17038e749f8e 100644 --- a/python/tvm/relay/op/contrib/ethosn.py +++ b/python/tvm/relay/op/contrib/ethosn.py @@ -17,6 +17,7 @@ # pylint: disable=invalid-name, unused-argument """Arm(R) Ethos(TM)-N NPU supported operators.""" from enum import Enum +import warnings import tvm.ir from tvm.relay import transform @@ -46,7 +47,7 @@ def ethosn_available(): return Available.SW_AND_HW if hw else Available.SW_ONLY -def partition_for_ethosn78(mod, params=None, **opts): +def partition_for_ethosn(mod, params=None, **opts): """Partition the graph greedily offloading supported operators to Arm Ethos-N NPU. @@ -61,8 +62,19 @@ def partition_for_ethosn78(mod, params=None, **opts): ------- ret : annotated and partitioned module. """ - if not opts or opts.get("variant", "").lower() != "ethos-n78": - raise ValueError("When targeting Ethos(TM)-N78, -variant=Ethos-N78 should be set.") + opts = opts or {} + if "variant" not in opts: + raise ValueError("Please specify a variant in the target string, e.g. -variant=n78.") + + # -variant=ethos-n78 deprecated in favour of -variant=n78 + if opts["variant"].lower() == "ethos-n78": + warnings.warn( + "Please use '-variant=n78' instead of the deprecated " + "'-variant=ethos-n78', which will be removed in TVM v0.9.", + DeprecationWarning, + ) + elif opts["variant"] != "n78": + raise ValueError("When targeting Ethos(TM)-N78, -variant=n78 should be set.") if params: mod["main"] = bind_params_by_name(mod["main"], params) diff --git a/src/relay/backend/contrib/ethosn/codegen.cc b/src/relay/backend/contrib/ethosn/codegen.cc index d9f7b84b2f76..fc8a4c48dfef 100644 --- a/src/relay/backend/contrib/ethosn/codegen.cc +++ b/src/relay/backend/contrib/ethosn/codegen.cc @@ -213,9 +213,14 @@ String MakeVariant(Optional configuration) { String variant = configuration.value()->variant; // Transform variant string to lowercase for comparison std::string variant_string = variant.c_str(); - std::transform(variant_string.begin(), variant_string.end(), variant_string.begin(), ::tolower); - std::string variant_n78 = "ethos-n78"; - if (variant_string == variant_n78) { + + // Checking deprecated variant format. Support for specifying + // the variant in this way only remains for backwards compatibility + // and will be removed in a later release of TVM. + std::string deprecated_variant_string = variant_string; + std::transform(deprecated_variant_string.begin(), deprecated_variant_string.end(), + deprecated_variant_string.begin(), ::tolower); + if (variant_string == "n78" || deprecated_variant_string == "ethos-n78") { String tops = configuration.value()->tops; String ple_ratio = configuration.value()->ple_ratio; variant = "Ethos-N78_" + tops + "TOPS_" + ple_ratio + "PLE_RATIO"; diff --git a/src/relay/backend/contrib/ethosn/codegen_ethosn.h b/src/relay/backend/contrib/ethosn/codegen_ethosn.h index cca96c044c84..9da4e5b18bd5 100644 --- a/src/relay/backend/contrib/ethosn/codegen_ethosn.h +++ b/src/relay/backend/contrib/ethosn/codegen_ethosn.h @@ -251,7 +251,7 @@ struct EthosnCompilerConfigNode : public tvm::AttrsNode 0 diff --git a/tests/python/driver/tvmc/test_target.py b/tests/python/driver/tvmc/test_target.py index eb3ffdea42b3..b842618efccd 100644 --- a/tests/python/driver/tvmc/test_target.py +++ b/tests/python/driver/tvmc/test_target.py @@ -153,10 +153,10 @@ def test_parse_quotes_and_separators_on_options(): def test_parse_multiple_target_with_opts_ethos_n78(): - targets = parse_target("ethos-n78 -myopt=value, llvm -device=arm_cpu --system-lib") + targets = parse_target("ethos-n -myopt=value, llvm -device=arm_cpu --system-lib") assert len(targets) == 2 - assert "ethos-n78" == targets[0]["name"] + assert "ethos-n" == targets[0]["name"] assert "myopt" in targets[0]["opts"] assert "value" == targets[0]["opts"]["myopt"] assert "llvm" == targets[1]["name"]