1919"""
2020
2121from tvm .driver import tvmc
22- from tvm .target import Target
22+ from tvm .target import Target , TargetKind
2323
2424# We can't tell the type inside an Array but all current options are strings so
2525# it can default to that. Bool is used alongside Integer but aren't distinguished
@@ -33,14 +33,14 @@ def _valid_target_kinds():
3333 return filter (lambda target : target not in codegen_names , Target .list_kinds ())
3434
3535
36- def _generate_target_kind_args (parser , kind ):
37- target_group = parser .add_argument_group (f"target { kind . name } " )
38- for target_option , target_type in kind . options .items ():
36+ def _generate_target_kind_args (parser , kind_name ):
37+ target_group = parser .add_argument_group (f"target { kind_name } " )
38+ for target_option , target_type in TargetKind . options_from_name ( kind_name ) .items ():
3939 if target_type in INTERNAL_TO_NATIVE_TYPE :
4040 target_group .add_argument (
41- f"--target-{ kind . name } -{ target_option } " ,
41+ f"--target-{ kind_name } -{ target_option } " ,
4242 type = INTERNAL_TO_NATIVE_TYPE [target_type ],
43- help = f"target { kind . name } { target_option } { INTERNAL_TO_HELP [target_type ]} " ,
43+ help = f"target { kind_name } { target_option } { INTERNAL_TO_HELP [target_type ]} " ,
4444 )
4545
4646
@@ -52,15 +52,14 @@ def generate_target_args(parser):
5252 required = True ,
5353 )
5454 for target_kind in _valid_target_kinds ():
55- target = Target (target_kind )
56- _generate_target_kind_args (parser , target .kind )
55+ _generate_target_kind_args (parser , target_kind )
5756
5857
59- def _reconstruct_target_kind_args (args , kind ):
58+ def _reconstruct_target_kind_args (args , kind_name ):
6059 kind_options = {}
61- for target_option , target_type in kind . options .items ():
60+ for target_option , target_type in TargetKind . options_from_name ( kind_name ) .items ():
6261 if target_type in INTERNAL_TO_NATIVE_TYPE :
63- var_name = f"target_{ kind . name .replace ('-' , '_' )} _{ target_option .replace ('-' , '_' )} "
62+ var_name = f"target_{ kind_name .replace ('-' , '_' )} _{ target_option .replace ('-' , '_' )} "
6463 option_value = getattr (args , var_name )
6564 if option_value is not None :
6665 kind_options [target_option ] = getattr (args , var_name )
@@ -71,8 +70,7 @@ def reconstruct_target_args(args):
7170 """Reconstructs the target options from the arguments"""
7271 reconstructed = {}
7372 for target_kind in _valid_target_kinds ():
74- target = Target (target_kind )
75- kind_options = _reconstruct_target_kind_args (args , target .kind )
73+ kind_options = _reconstruct_target_kind_args (args , target_kind )
7674 if kind_options :
77- reconstructed [target . kind . name ] = kind_options
75+ reconstructed [target_kind ] = kind_options
7876 return reconstructed
0 commit comments