Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[microNPU][ETHOSU] Fix compiler attributes types #15159

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions cmake/modules/LibInfo.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ function(add_lib_info src_file)
TVM_INFO_USE_AMX="${USE_AMX}"
TVM_INFO_USE_DNNL="${USE_DNNL}"
TVM_INFO_USE_ETHOSN="${USE_ETHOSN}"
TVM_INFO_USE_ETHOSU="${USE_ETHOSU}"
TVM_INFO_USE_FALLBACK_STL_MAP="${USE_FALLBACK_STL_MAP}"
TVM_INFO_USE_GRAPH_EXECUTOR_CUDA_GRAPH="${USE_GRAPH_EXECUTOR_CUDA_GRAPH}"
TVM_INFO_USE_GRAPH_EXECUTOR="${USE_GRAPH_EXECUTOR}"
Expand Down
8 changes: 4 additions & 4 deletions python/tvm/relay/backend/contrib/ethosu/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,10 @@ def get_accelerator_config():
return compiler_attrs.accelerator_config


def is_cascader_enabled():
def is_cascader_enabled() -> bool:
"""Determine whether the cascader is enabled"""
compiler_attrs = tvm.get_global_func("relay.ext.ethos-u.get_compiler_attrs")()
return compiler_attrs.enable_cascader
return bool(compiler_attrs.enable_cascader)


def is_copying_constants_disabled() -> bool:
Expand All @@ -264,10 +264,10 @@ def is_copying_constants_disabled() -> bool:
return bool(compiler_attrs.disable_copying_constants)


def is_striping_enabled():
def is_striping_enabled() -> bool:
"""Determine whether the cascader is enabled"""
compiler_attrs = tvm.get_global_func("relay.ext.ethos-u.get_compiler_attrs")()
return compiler_attrs.enable_striping
return bool(compiler_attrs.enable_striping)


def get_arg_count(func):
Expand Down
3 changes: 3 additions & 0 deletions python/tvm/testing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,9 @@ def _any_gpu_exists():
# Mark a test as requiring Arm(R) Ethos(TM)-N to run
requires_ethosn = Feature("ethosn", "Arm(R) Ethos(TM)-N", cmake_flag="USE_ETHOSN")

# Mark a test as requiring Arm(R) Ethos(TM)-U to run
requires_ethosu = Feature("ethosu", "Arm(R) Ethos(TM)-U", cmake_flag="USE_ETHOSU")

# Mark a test as requiring libtorch to run
requires_libtorch = Feature("libtorch", "LibTorch", cmake_flag="USE_LIBTORCH")

Expand Down
28 changes: 14 additions & 14 deletions src/relay/backend/contrib/ethosu/compiler_attrs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ namespace ethosu {
/*! \brief Attributes to store the compiler options for Arm(R) Ethos(TM)-U NPU. */
struct EthosUCompilerConfigNode : public tvm::AttrsNode<EthosUCompilerConfigNode> {
String accelerator_config;
bool enable_cascader;
bool enable_striping;
Bool enable_cascader = Bool(false);
Bool enable_striping = Bool(false);
Bool disable_copying_constants = Bool(false);
String dev_force_block_config;
String dev_max_open_plans;
String dev_max_closed_plans;
String dev_select_proposal_idx;
bool dev_disable_pareto_plans;
bool dev_disable_pareto_proposals;
bool dev_disable_block_culling;
bool dev_cascader_logging;
Bool dev_disable_pareto_plans = Bool(false);
Bool dev_disable_pareto_proposals = Bool(false);
Bool dev_disable_block_culling = Bool(false);
Bool dev_cascader_logging = Bool(false);

TVM_DECLARE_ATTRS(EthosUCompilerConfigNode, "ext.attrs.EthosUCompilerConfigNode") {
TVM_ATTR_FIELD(accelerator_config)
Expand All @@ -59,7 +59,10 @@ struct EthosUCompilerConfigNode : public tvm::AttrsNode<EthosUCompilerConfigNode
.set_default("ethos-u55-256");
TVM_ATTR_FIELD(enable_cascader)
.describe("Whether the cascader should be enabled")
.set_default(false);
.set_default(Bool(false));
TVM_ATTR_FIELD(enable_striping)
.describe("Whether the cascader should be striping")
.set_default(Bool(false));
TVM_ATTR_FIELD(disable_copying_constants)
.describe(
"Whether copying constants is disabled for case without the cascader. When this option "
Expand All @@ -68,9 +71,6 @@ struct EthosUCompilerConfigNode : public tvm::AttrsNode<EthosUCompilerConfigNode
"in "
"the linker script for section \".rodata.tvm\" that the constants are located in SRAM)")
.set_default(Bool(false));
TVM_ATTR_FIELD(enable_striping)
.describe("Whether the cascader should be striping")
.set_default(false);
String dev_warning = "Option is intended for development and debugging purposes only. ";
TVM_ATTR_FIELD(dev_force_block_config)
.describe((dev_warning + String("Force the block config to a given value; format = "
Expand All @@ -92,17 +92,17 @@ struct EthosUCompilerConfigNode : public tvm::AttrsNode<EthosUCompilerConfigNode
.set_default("-1");
TVM_ATTR_FIELD(dev_disable_pareto_plans)
.describe((dev_warning + String("Disable pareto culling for plans")).data())
.set_default(false);
.set_default(Bool(false));
TVM_ATTR_FIELD(dev_disable_pareto_proposals)
.describe((dev_warning + String("Disable pareto culling for proposals")).data())
.set_default(false);
.set_default(Bool(false));
TVM_ATTR_FIELD(dev_disable_block_culling)
.describe((dev_warning + String("Disable culling for block configs")).data())
.set_default(false);
.set_default(Bool(false));
TVM_ATTR_FIELD(dev_cascader_logging)
.describe(
(dev_warning + String("Enable cascader logging, log is dumped to .json file")).data())
.set_default(false);
.set_default(Bool(false));
}
};

Expand Down
1 change: 1 addition & 0 deletions src/support/libinfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ TVM_DLL Map<String, String> GetLibInfo() {
{"USE_AMX", TVM_INFO_USE_AMX},
{"USE_DNNL", TVM_INFO_USE_DNNL},
{"USE_ETHOSN", TVM_INFO_USE_ETHOSN},
{"USE_ETHOSU", TVM_INFO_USE_ETHOSU},
{"USE_FALLBACK_STL_MAP", TVM_INFO_USE_FALLBACK_STL_MAP},
{"USE_GRAPH_EXECUTOR_CUDA_GRAPH", TVM_INFO_USE_GRAPH_EXECUTOR_CUDA_GRAPH},
{"USE_GRAPH_EXECUTOR", TVM_INFO_USE_GRAPH_EXECUTOR},
Expand Down
67 changes: 63 additions & 4 deletions tests/python/contrib/test_ethosu/test_attr_passing.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,82 @@
def test_compiler_attr():
config = {
"accelerator_config": "ethos-u55-32",
"enable_cascader": True,
"enable_striping": True,
"disable_copying_constants": True,
"dev_force_block_config": "2x4x16",
"dev_max_open_plans": "256",
"dev_max_closed_plans": "128",
"dev_select_proposal_idx": "1",
"dev_disable_pareto_plans": True,
"dev_disable_pareto_proposals": True,
"dev_disable_block_culling": True,
"dev_cascader_logging": True,
}
with tvm.transform.PassContext(opt_level=3, config={"relay.ext.ethos-u.options": config}):
with tvm.target.Target("c"):
compiler_attrs = tvm.get_global_func("relay.ext.ethos-u.get_compiler_attrs")()
accel_config_str = compiler_attrs.accelerator_config
assert accel_config_str == config["accelerator_config"]
assert compiler_attrs.accelerator_config == config["accelerator_config"]
assert compiler_attrs.enable_cascader == config["enable_cascader"]
assert compiler_attrs.enable_striping == config["enable_striping"]
assert compiler_attrs.disable_copying_constants == config["disable_copying_constants"]
assert compiler_attrs.dev_force_block_config == config["dev_force_block_config"]
assert compiler_attrs.dev_max_open_plans == config["dev_max_open_plans"]
assert compiler_attrs.dev_max_closed_plans == config["dev_max_closed_plans"]
assert compiler_attrs.dev_select_proposal_idx == config["dev_select_proposal_idx"]
assert compiler_attrs.dev_disable_pareto_plans == config["dev_disable_pareto_plans"]
assert (
compiler_attrs.dev_disable_pareto_proposals
== config["dev_disable_pareto_proposals"]
)
assert compiler_attrs.dev_disable_block_culling == config["dev_disable_block_culling"]
assert compiler_attrs.dev_cascader_logging == config["dev_cascader_logging"]


def test_compiler_attr_default():
default_config = {
"accelerator_config": "ethos-u55-256",
"enable_cascader": False,
"enable_striping": False,
"disable_copying_constants": False,
"dev_force_block_config": "",
"dev_max_open_plans": "8",
"dev_max_closed_plans": "32",
"dev_select_proposal_idx": "-1",
"dev_disable_pareto_plans": False,
"dev_disable_pareto_proposals": False,
"dev_disable_block_culling": False,
"dev_cascader_logging": False,
}
with tvm.transform.PassContext(opt_level=3):
with tvm.target.Target("c"):
compiler_attrs = tvm.get_global_func("relay.ext.ethos-u.get_compiler_attrs")()
accel_config_str = compiler_attrs.accelerator_config
assert accel_config_str == default_config["accelerator_config"]
assert compiler_attrs.accelerator_config == default_config["accelerator_config"]
assert compiler_attrs.enable_cascader == default_config["enable_cascader"]
assert compiler_attrs.enable_striping == default_config["enable_striping"]
assert (
compiler_attrs.disable_copying_constants
== default_config["disable_copying_constants"]
)
assert compiler_attrs.dev_force_block_config == default_config["dev_force_block_config"]
assert compiler_attrs.dev_max_open_plans == default_config["dev_max_open_plans"]
assert compiler_attrs.dev_max_closed_plans == default_config["dev_max_closed_plans"]
assert (
compiler_attrs.dev_select_proposal_idx == default_config["dev_select_proposal_idx"]
)
assert (
compiler_attrs.dev_disable_pareto_plans
== default_config["dev_disable_pareto_plans"]
)
assert (
compiler_attrs.dev_disable_pareto_proposals
== default_config["dev_disable_pareto_proposals"]
)
assert (
compiler_attrs.dev_disable_block_culling
== default_config["dev_disable_block_culling"]
)
assert compiler_attrs.dev_cascader_logging == default_config["dev_cascader_logging"]


if __name__ == "__main__":
Expand Down
14 changes: 14 additions & 0 deletions tests/python/driver/tvmc/test_target_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,20 @@ def test_include_known_codegen():
}


@tvm.testing.requires_ethosu
def test_ethosu_compiler_attrs():
# It is checked that the represented string and boolean types in the
# EthosUCompilerConfigNode structure can be passed via the command line
parser = argparse.ArgumentParser()
generate_target_args(parser)
parsed, _ = parser.parse_known_args(
["--target-ethos-u-accelerator_config=ethos-u55-32", "--target-ethos-u-enable_cascader=1"]
)
assert reconstruct_target_args(parsed) == {
"ethos-u": {"accelerator_config": "ethos-u55-32", "enable_cascader": 1},
}


def test_skip_target_from_codegen():
parser = argparse.ArgumentParser()
generate_target_args(parser)
Expand Down