Skip to content

Commit 02fe0c5

Browse files
MNGanesanM N Ganesan
andauthored
[Frontend][ArgParse] Pass default values to target compiler(#13264) (#17014)
* [Frontend][ArgParse] Pass default values to target compiler(#13264) BYOC Compiler's Config node defines the target compiler's command line options, along with default values. This change extract the default values from config node, while constructing target options for codegen/target compiler. Added test case for this feature as well. Signed-off-by: M N Ganesan <[email protected]> * [Frontend][ArgParse] Pass default values to target compiler(#13264) BYOC Compiler's Config node defines the target compiler's command line options, along with default values. This change extract the default values from config node, while constructing target options for codegen/target compiler. Added test case for this feature as well. Signed-off-by: M N Ganesan <[email protected]> * Lint Fix Signed-off-by: M N Ganesan <[email protected]> --------- Signed-off-by: M N Ganesan <[email protected]> Co-authored-by: M N Ganesan <[email protected]>
1 parent c0abab7 commit 02fe0c5

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

python/tvm/driver/tvmc/composite_target.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,34 +51,42 @@
5151
REGISTERED_CODEGEN = {
5252
"compute-library": {
5353
"config_key": None,
54+
"pass_default": False,
5455
"pass_pipeline": partition_for_arm_compute_lib,
5556
},
5657
"cmsis-nn": {
5758
"config_key": "relay.ext.cmsisnn.options",
59+
"pass_default": False,
5860
"pass_pipeline": partition_for_cmsisnn,
5961
},
6062
"ethos-n": {
6163
"config_key": "relay.ext.ethos-n.options",
64+
"pass_default": False,
6265
"pass_pipeline": partition_for_ethosn,
6366
},
6467
"ethos-u": {
6568
"config_key": "relay.ext.ethos-u.options",
69+
"pass_default": False,
6670
"pass_pipeline": partition_for_ethosu,
6771
},
6872
"bnns": {
6973
"config_key": None,
74+
"pass_default": False,
7075
"pass_pipeline": partition_for_bnns,
7176
},
7277
"vitis-ai": {
7378
"config_key": "relay.ext.vitis_ai.options",
79+
"pass_default": False,
7480
"pass_pipeline": partition_for_vitis_ai,
7581
},
7682
"clml": {
7783
"config_key": None,
84+
"pass_default": False,
7885
"pass_pipeline": partition_for_clml,
7986
},
8087
"mrvl": {
8188
"config_key": "relay.ext.mrvl.options",
89+
"pass_default": True,
8290
"pass_pipeline": partition_for_mrvl,
8391
},
8492
}

python/tvm/driver/tvmc/target.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,28 @@ def _generate_codegen_args(parser, codegen_name):
6969
for tvm_type, python_type in INTERNAL_TO_NATIVE_TYPE.items():
7070
if field.type_info.startswith(tvm_type):
7171
target_option = field.name
72+
default_value = None
73+
74+
# Retrieve the default value string from attrs(field) of config node
75+
# Eg: "default=target_cpu_name"
76+
target_option_default_str = field.type_info.split("default=")[1]
77+
78+
# Extract the defalut value based on the tvm type
79+
if target_option_default_str and tvm_type == "runtime.String":
80+
default_value = target_option_default_str
81+
elif target_option_default_str and tvm_type == "IntImm":
82+
# Extract the numeric value from the python Int string, Eg: T.int64(8)
83+
str_slice = target_option_default_str.split("(")[1]
84+
default_value = str_slice.split(")")[0]
85+
86+
if codegen["pass_default"] is False:
87+
default_value = None
88+
7289
target_group.add_argument(
7390
f"--target-{codegen_name}-{target_option}",
7491
type=python_type,
7592
help=field.description,
93+
default=default_value,
7694
)
7795

7896

@@ -133,7 +151,6 @@ def reconstruct_target_args(args):
133151
codegen_options = _reconstruct_codegen_args(args, codegen_name)
134152
if codegen_options:
135153
reconstructed[codegen_name] = codegen_options
136-
137154
return reconstructed
138155

139156

tests/python/driver/tvmc/test_target_options.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,21 @@ def test_target_to_argparse_for_mrvl_hybrid():
7272
assert parsed.target_mrvl_mcpu == "cnf10kb"
7373

7474

75+
@tvm.testing.requires_mrvl
76+
def test_default_arg_for_mrvl_hybrid():
77+
parser = argparse.ArgumentParser()
78+
generate_target_args(parser)
79+
parsed, _ = parser.parse_known_args(
80+
[
81+
"--target=mrvl, llvm",
82+
]
83+
)
84+
assert parsed.target == "mrvl, llvm"
85+
assert parsed.target_mrvl_mcpu == "cn10ka"
86+
assert parsed.target_mrvl_num_tiles == 8
87+
88+
89+
@tvm.testing.requires_cmsisnn
7590
def test_mapping_target_args():
7691
parser = argparse.ArgumentParser()
7792
generate_target_args(parser)
@@ -129,6 +144,7 @@ def test_ethosu_compiler_attrs():
129144
}
130145

131146

147+
@tvm.testing.requires_cmsisnn
132148
def test_skip_target_from_codegen():
133149
parser = argparse.ArgumentParser()
134150
generate_target_args(parser)

0 commit comments

Comments
 (0)