Beispiel #1
0
def vtr_command_main(arg_list, prog=None):
    """Run the vtr tasks given and the tasks in the lists given"""
    # Load the arguments
    args = vtr_command_argparser(prog).parse_args(arg_list)

    # Don't run if parsing or handling golden results
    args.run = not (args.parse or args.create_golden or args.check_golden
                    or args.calc_geomean)

    # Always parse if running
    if args.run:
        args.parse = True

    num_failed = -1
    try:
        task_names = args.task

        for list_file in args.list_file:
            task_names += load_list_file(list_file)

        config_files = [
            find_task_config_file(task_name) for task_name in task_names
        ]
        configs = []
        common_task_prefix = ""  # common task prefix to shorten task names
        for config_file in config_files:
            config = load_task_config(config_file)
            configs += [config]
            if not common_task_prefix:
                common_task_prefix = config.task_name
            else:
                match = SequenceMatcher(None, common_task_prefix,
                                        config.task_name).find_longest_match(
                                            0, len(common_task_prefix), 0,
                                            len(config.task_name))
                common_task_prefix = common_task_prefix[match.a:match.a +
                                                        match.size]
        if args.short_task_names:
            configs = shorten_task_names(configs, common_task_prefix)
        num_failed = run_tasks(args, configs)

    except CommandError as exception:
        print("Error: {msg}".format(msg=exception.msg))
        print("\tfull command: ", exception.cmd)
        print("\treturncode  : ", exception.returncode)
        print("\tlog file    : ", exception.log)
    except InspectError as exception:
        print("Error: {msg}".format(msg=exception.msg))
        if exception.filename:
            print("\tfile: ", exception.filename)
    except VtrError as exception:
        print("Error:", exception.msg)
    if __name__ == "main":
        sys.exit(num_failed)
    return num_failed
Beispiel #2
0
def vtr_command_main(arg_list, prog=None):
    """
    Main function for parse_vtr_task
    Parses in the results from run_vtr_task.py
    """
    # Load the arguments
    args = vtr_command_argparser(prog).parse_args(arg_list)
    try:
        task_names = args.task

        for list_file in args.list_file:
            task_names += load_list_file(list_file)

        config_files = [
            find_task_config_file(task_name) for task_name in task_names
        ]

        configs = [
            load_task_config(config_file) for config_file in config_files
        ]
        num_failed = 0

        jobs = create_jobs(args, configs, after_run=True)
        parse_tasks(configs, jobs)

        if args.create_golden:
            create_golden_results_for_tasks(configs)

        if args.check_golden:
            num_failed += check_golden_results_for_tasks(configs)

        if args.calc_geomean:
            summarize_qor(configs)
            calc_geomean(args, configs)

    except CommandError as error:
        print("Error: {msg}".format(msg=error.msg))
        print("\tfull command: ", error.cmd)
        print("\treturncode  : ", error.returncode)
        print("\tlog file    : ", error.log)
        num_failed += 1
    except InspectError as error:
        print("Error: {msg}".format(msg=error.msg))
        if error.filename:
            print("\tfile: ", error.filename)
        num_failed += 1
    except VtrError as error:
        print("Error:", error.msg)
        num_failed += 1

    return num_failed
def load_task_config(config_file):
    """
    Load task config information
    """
    # Load the file stripping comments
    values = load_list_file(config_file)

    # Keys that can appear only once
    unique_keys = set([
        "circuits_dir",
        "archs_dir",
        "additional_files",
        "parse_file",
        "script_path",
        "script_params",
        "script_params_common",
        "pass_requirements_file",
        "sdc_dir",
        "place_constr_dir",
        "qor_parse_file",
        "cmos_tech_behavior",
        "pad_file",
    ])

    # Keys that are repeated to create lists
    repeated_key_pattern = "_list_add"

    # Keys that are required
    required_keys = set([
        "circuits_dir", "archs_dir", "circuit_list_add", "arch_list_add",
        "parse_file"
    ])

    # Interpret the file
    key_values = {}
    for line in values:
        key, value = line.split("=")

        # Trim whitespace
        key = key.strip()
        value = value.strip()

        if key in unique_keys:
            if key not in key_values:
                key_values[key] = value
            elif key == "parse_file":
                key_values["second_parse_file"] = value
            else:
                raise VtrError("Duplicate {key} in config file {file}".format(
                    key=key, file=config_file))

        elif repeated_key_pattern in key:
            if key not in key_values:
                key_values[key] = []
            if key == "script_params_list_add":
                key_values[key] += [value]
            else:
                key_values[key].append(value)

        else:
            # All valid keys should have been collected by now
            raise VtrError(
                "Unrecognzied key '{key}' in config file {file}".format(
                    key=key, file=config_file))

    # We split the script params into a list
    if "script_params" in key_values:
        key_values["script_params"] = split(key_values["script_params"])

    if "script_params_common" in key_values:
        key_values["script_params_common"] = split(
            key_values["script_params_common"])

    check_required_fields(config_file, required_keys, key_values)

    # Useful meta-data about the config
    config_dir = str(Path(config_file).parent)
    key_values["config_dir"] = config_dir
    key_values["task_name"] = Path(config_dir).parent.name

    # Create the task config object
    return TaskConfig(**key_values)