コード例 #1
0
ファイル: mp_target.py プロジェクト: IBM/microprobe
def _main(arguments):
    """
    Program main, after processing the command line arguments

    :param arguments: Dictionary with command line arguments and values
    :type arguments: :class:`dict`
    """
    print_info("Arguments processed!")
    print_info("Importing target definition...")
    target = import_definition(arguments['target'])

    if 'instructions' not in arguments:
        print_info("Dumping target %s" % target.name)
        print_target_info(target, None)
    else:

        arguments['instructions'] = parse_instruction_list(
            target, arguments['instructions'])

        for instruction in arguments['instructions']:
            print_instruction_info(instruction, None)
コード例 #2
0
ファイル: mp_seq.py プロジェクト: 2henwei/microprobe
def _main(arguments):
    """
    Program main, after processing the command line arguments

    :param arguments: Dictionary with command line arguments and values
    :type arguments: :class:`dict`
    """
    print_info("Arguments processed!")

    print_info("Checking input arguments for consistency...")

    slots = arguments['instruction_slots']

    instruction_groups = list(
        iter_flatten(arguments.get('instruction_groups', [])))
    check_group_length_func = int_type(1, len(instruction_groups))
    check_slots_length_func = int_type(0, slots)

    instruction_map = arguments.get('instruction_map', None)
    if instruction_map is None:
        instruction_map = ['-1'] * slots
    else:
        instruction_map = list(iter_flatten(instruction_map))

    if len(instruction_map) != slots:
        print_error('Instruction map: %s' % instruction_map)
        print_error('Instruction map incorrect. Length should be: %s' % slots)
        exit(-1)

    new_map = []
    for gmap in instruction_map:
        ngmap = []

        if gmap == "-1":
            ngmap = list(range(1, len(instruction_groups) + 1))
            new_map.append(ngmap)
            continue

        for cmap in gmap.split(','):
            try:
                ngmap.append(check_group_length_func(cmap))
            except argparse.ArgumentTypeError as exc:
                print_error('Instruction map incorrect')
                print_error(exc)
                exit(-1)
        new_map.append(ngmap)

    instruction_map = new_map

    group_max = arguments.get('group_max', None)
    if group_max is None:
        group_max = ['-1'] * len(instruction_groups)
    else:
        group_max = list(iter_flatten(group_max))

    if len(group_max) != len(instruction_groups):
        print_error('Group max: %s' % group_max)
        print_error('Group max incorrect. Length should be: %s' %
                    len(instruction_groups))
        exit(-1)

    new_map = []
    for gmap in group_max:

        if gmap == "-1":
            new_map.append(slots)
            continue

        try:
            new_map.append(check_slots_length_func(gmap))
        except argparse.ArgumentTypeError as exc:
            print_error('Group max incorrect')
            print_error(exc)
            exit(-1)

    group_max = new_map

    group_min = arguments.get('group_min', None)
    if group_min is None:
        group_min = ['-1'] * len(instruction_groups)
    else:
        group_min = list(iter_flatten(group_min))

    if len(group_min) != len(instruction_groups):
        print_error('Group min: %s' % group_min)
        print_error('Group min incorrect. Length should be: %s' %
                    len(instruction_groups))
        exit(-1)

    new_map = []
    for gmap in group_min:

        if gmap == "-1":
            new_map.append(0)
            continue

        try:
            new_map.append(check_slots_length_func(gmap))
        except argparse.ArgumentTypeError as exc:
            print_error('Group min incorrect')
            print_error(exc)
            exit(-1)

    group_min = new_map

    print_info("Importing target definition...")
    target = import_definition(arguments.pop('target'))

    policy = find_policy(target.name, 'seq')

    if policy is None:
        print_error("Target does not implement the default SEQ policy")
        exit(-1)

    instruction_groups = [
        parse_instruction_list(target, group) for group in instruction_groups
    ]

    base_seq = []
    if 'base_seq' in arguments:
        base_seq = parse_instruction_list(target, arguments['base_seq'])

    sequences = [base_seq]
    if len(instruction_groups) > 0:
        sequences = _generate_sequences(slots, instruction_groups,
                                        instruction_map, group_max, group_min,
                                        base_seq)

    if 'count' in arguments:
        print_info("Total number of sequences defined : %s" %
                   len(list(sequences)))
        exit(0)

    outputdir = arguments['seq_output_dir']

    if _BALANCE_EXECUTION:
        global _DIRCONTENTS  # pylint: disable=global-statement
        _DIRCONTENTS = set(findfiles([outputdir], ""))

    outputname = "%INSTR%.%EXT%"

    if 'reset' not in arguments:
        arguments['reset'] = False

    if 'skip' not in arguments:
        arguments['skip'] = False

    if 'force_switch' not in arguments:
        arguments['force_switch'] = False

    if 'parallel' not in arguments:
        print_info("Start sequential generation. Use parallel flag to speed")
        print_info("up the benchmark generation.")
        for sequence in sequences:
            _generic_policy_wrapper(
                (sequence, outputdir, outputname, target, arguments))

    else:
        print_info("Start parallel generation. Threads: %s" % mp.cpu_count())
        pool = mp.Pool(processes=mp.cpu_count())
        pool.map(_generic_policy_wrapper,
                 [(sequence, outputdir, outputname, target, arguments)
                  for sequence in sequences])
コード例 #3
0
ファイル: mp_epi.py プロジェクト: rommelsv/microprobe
def _main(arguments):
    """
    Program main, after processing the command line arguments

    :param arguments: Dictionary with command line arguments and values
    :type arguments: :class:`dict`
    """
    print_info("Arguments processed!")

    print_info("Checking input arguments for consistency...")

    if ("epi_output_file" not in arguments
            and "epi_output_dir" not in arguments):
        print_error("No output provided")
        exit(-1)

    if ("epi_output_file" in arguments and "epi_output_dir" in arguments):
        print_error("--epi-output-file and --epi-output-dir options conflict")
        print_error("Use one of them")
        exit(-1)

    if ("instructions" not in arguments and "epi_output_dir" not in arguments):
        print_error("If --instructions is not provided, you need to provide")
        print_error("--epi-output-dir and not --epi-output-file")
        exit(-1)

    print_info("Importing target definition...")
    target = import_definition(arguments.pop('target'))

    policy = find_policy(target.name, 'epi')

    if policy is None:
        print_error("Target does not implement the default EPI policy")
        exit(-1)

    if 'instructions' not in arguments:
        arguments['instructions'] = list(target.isa.instructions.values())
        outputdir = arguments['epi_output_dir']
        outputname = "%INSTR%.%EXT%"
    else:

        arguments['instructions'] = parse_instruction_list(
            target, arguments['instructions'])

        if ("epi_output_file" in arguments
                and len(arguments['instructions']) != 1):
            print_error("More than one microbenchmark to generate.")
            print_error("Use --epi-output-dir parameter")
            exit(-1)

        if "epi_output_file" in arguments:
            outputdir = os.path.dirname(arguments['epi_output_file'])
            outputname = arguments['epi_output_file']
        else:
            outputdir = arguments['epi_output_dir']
            outputname = "%INSTR%.%EXT%"

    if 'reset' not in arguments:
        arguments['reset'] = False

    if 'skip' not in arguments:
        arguments['skip'] = False

    if 'ignore_errors' not in arguments:
        arguments['ignore_errors'] = False

    if 'parallel' not in arguments:
        print_info("Start sequential generation. Use parallel flag to speed")
        print_info("up the benchmark generation.")
        for instruction in arguments['instructions']:
            _generic_policy_wrapper(
                (instruction, outputdir, outputname, target, arguments))

    else:
        print_info("Start parallel generation. Threads: %s" % mp.cpu_count())
        pool = mp.Pool(processes=mp.cpu_count())
        pool.map(_generic_policy_wrapper,
                 [(instruction, outputdir, outputname, target, arguments)
                  for instruction in arguments['instructions']])
コード例 #4
0
ファイル: mp_seqtune.py プロジェクト: rommelsv/microprobe
def _main(arguments):
    """
    Program main, after processing the command line arguments

    :param arguments: Dictionary with command line arguments and values
    :type arguments: :class:`dict`
    """
    print_info("Arguments processed!")

    print_info("Checking input arguments for consistency...")

    flags = ["data_switch", "memory_switch",
             "ignore_errors", "switch_branch"]

    for flag in flags:
        if flag not in arguments:
            arguments[flag] = False

    args = ["replace_every", "add_every", "branch_every", "branch_pattern",
            "memory_stream"]
    for arg in args:
        if arg not in arguments:
            arguments[arg] = []

    if (len(arguments['branch_every']) >
            0 and len(arguments['branch_pattern']) > 0):
        print_error("--branch-every and --branch-pattern flags are "
                    "mutually exclusive. Use only on of them.")
        exit(-1)
    elif len(arguments['branch_pattern']) > 0:
        arguments['branch_pattern'] = _process_branch_pattern(
            arguments['branch_pattern']
        )
    elif len(arguments['branch_every']) > 0:
        arguments['branch_pattern'] = _process_branch_every(
            arguments['branch_every']
        )
    else:
        arguments['branch_pattern'] = ['0']

    print_info("Importing target definition...")
    target = import_definition(arguments.pop('target'))

    policy = find_policy(target.name, 'seqtune')

    if policy is None:
        print_error("Target does not implement the default SEQTUNE policy")
        exit(-1)

    arguments['sequence'] = parse_instruction_list(
        target,
        arguments['sequence'])

    for elem in arguments["replace_every"]:
        elem[0] = parse_instruction_list(target, elem[0])
        elem[1] = parse_instruction_list(target, elem[1])

    for elem in arguments["add_every"]:
        elem[0] = parse_instruction_list(target, elem[0])

    configurations = _generate_configurations(arguments)
    configurations = _filter_configurations(configurations, arguments)

    if 'count' in arguments:
        print_info("Total number of variations defined : %s" %
                   len(list(configurations)))
        exit(0)

    outputdir = arguments['seq_output_dir']
    outputname = "%BASENAME%.%EXT%"

    if 'reset' not in arguments:
        arguments['reset'] = False

    if 'skip' not in arguments:
        arguments['skip'] = False

    if 'parallel' not in arguments:
        print_info("Start sequential generation. Use parallel flag to speed")
        print_info("up the benchmark generation.")
        for params in configurations:
            _generic_policy_wrapper(
                (params,
                 outputdir,
                 outputname,
                 target,
                 arguments))

    else:
        print_info("Start parallel generation. Threads: %s" % mp.cpu_count())
        pool = mp.Pool(processes=mp.cpu_count())
        pool.map(_generic_policy_wrapper,
                 [(params, outputdir, outputname, target,
                   arguments)
                  for params in configurations]
                 )