def _generate_codegen_args(parser, codegen_name): codegen = get_codegen_by_target(codegen_name) pass_configs = PassContext.list_configs() if codegen["config_key"] is not None and codegen["config_key"] in pass_configs: target_group = parser.add_argument_group(f"target {codegen_name}") attrs = make_node(pass_configs[codegen["config_key"]]["type"]) fields = attrs_api.AttrsListFieldInfo(attrs) for field in fields: for tvm_type, python_type in INTERNAL_TO_NATIVE_TYPE.items(): if field.type_info.startswith(tvm_type): target_option = field.name target_group.add_argument( f"--target-{codegen_name}-{target_option}", type=python_type, help=f"target {codegen_name} {target_option}{python_type}", )
def _reconstruct_codegen_args(args, codegen_name): codegen = get_codegen_by_target(codegen_name) pass_configs = PassContext.list_configs() codegen_options = {} if codegen["config_key"] is not None and codegen["config_key"] in pass_configs: attrs = make_node(pass_configs[codegen["config_key"]]["type"]) fields = attrs_api.AttrsListFieldInfo(attrs) for field in fields: for tvm_type in INTERNAL_TO_NATIVE_TYPE: if field.type_info.startswith(tvm_type): target_option = field.name var_name = ( f"target_{codegen_name.replace('-', '_')}_{target_option.replace('-', '_')}" ) option_value = getattr(args, var_name) if option_value is not None: codegen_options[target_option] = option_value return codegen_options