Пример #1
0
def _process_branch_pattern(patterns):

    rpattern = []
    for pattern in patterns:
        if pattern.replace("0", "").replace("1", "") == "":
            rpattern.append(pattern)
        elif pattern.startswith("L"):
            pattern_lengths = int_range(1, 100)(pattern[1:])
            for pattern_length in pattern_lengths:
                strfmt = "0%db" % pattern_length
                rpattern += [
                    format(elem, strfmt)
                    for elem in range(0, 2**pattern_length)
                ]
        else:
            print_error("Wrong format for branch pattern '%s'." % pattern)
            exit(-1)

    rpattern = sorted(
        list(set(rpattern)),
        key=lambda x: len(x)  # pylint: disable=unnecessary-lambda
    )
    numbers = set([len(elem) for elem in rpattern])
    cmul = 1
    for num in numbers:
        cmul = cmul * num

    for idx, elem in enumerate(rpattern):
        rpattern[idx] = [elem, len(elem), elem * (cmul // len(elem))]

    rlist = []
    llist = []
    for elem in rpattern:
        if elem[2] in llist:
            continue
        rlist.append(elem[0])
        llist.append(elem[2])

    return rlist
Пример #2
0
def main():
    """
    Program main
    """
    args = sys.argv[1:]
    cmdline = CLI(
        "Microprobe seqtune tool",
        default_config_file="mp_seqtune.cfg",
        force_required=['target']
    )

    groupname = "SEQTUNE arguments"
    cmdline.add_group(
        groupname, "Command arguments related to Sequence tuner generator"
    )

    cmdline.add_option(
        "seq-output-dir",
        "D",
        None,
        "Output directory name",
        group=groupname,
        opt_type=existing_dir,
        required=True
    )

    cmdline.add_option(
        "sequence",
        "seq",
        None,
        "Base instruction sequence to modify (command separated list of "
        "instructions).",
        group=groupname,
        opt_type=str,
        required=True
    )

    cmdline.add_option(
        "replace-every",
        "re",
        None,
        "Replace every. String with the format 'INSTR1:INSTR2:RANGE' to "
        "specfy that INSTR1 will be replaced by INSTR2 every RANGE "
        "instructions. Range can be just an integer or a RANGE specifier of "
        "the form: #1:#2 to generate a range from #1 to #2, or #1:#2:#3 to "
        "generate a range between #1 to #2 with step #3. E.g. 10:20 generates "
        "10, 11, 12 ... 19, 20 and 10:20:2 generates 10, 12, 14, ... 18, 20.",
        group=groupname,
        opt_type=string_with_fields(":", 3, 3,
                                    [str, str, int_range(1, 10000)]),
        required=False,
        action="append"
    )

    cmdline.add_option(
        "add-every",
        "ae",
        None,
        "Add every. String with the format 'INSTR1:RANGE' to "
        "specfy that INSTR1 will be added to the sequence every RANGE "
        "instructions. Range can be just an integer or a RANGE specifier of "
        "the form: #1-#2 to generate a range from #1 to #2, or #1-#2-#3 to "
        "generate a range between #1 to #2 with step #3. E.g. 10:20 generates "
        "10, 11, 12 ... 19, 20 and 10:20:2 generates 10, 12, 14, ... 18, 20.",
        group=groupname,
        opt_type=string_with_fields(":", 2, 2,
                                    [str, int_range(1, 10000)]),
        required=False,
        action="append"
    )

    cmdline.add_option(
        "branch-every",
        "be",
        None,
        "Conditional branches are modeled not taken by default. Using this "
        "paratemeter, every N will be taken.",
        group=groupname,
        opt_type=int_range(1, 10000),
        required=False,
        action="append"
    )

    cmdline.add_option(
        "branch-pattern",
        "bp",
        None,
        "Branch pattern (in binary) to be generated. E.g 0010 will model the "
        "conditional branches as NotTaken NotTaken Taken NotTaken in a round "
        "robin fashion. One can use 'L<range>' to generate all the patterns "
        "possible of length #. E.g. 'L2-5' will generate all unique possible "
        "branch patterns of length 2,3,4 and 5.",
        group=groupname,
        opt_type=str,
        required=False,
        action="append")

    cmdline.add_flag(
        "data-switch",
        "ds",
        "Enable data switching for instruction. It tries to maximize the "
        "data switching factor on inputs and outputs of instructions.",
        group=groupname,
    )

    cmdline.add_flag(
        "switch-branch",
        "sb",
        "Switch branch pattern in each iteration.",
        group=groupname,
    )

    cmdline.add_flag(
        "memory-switch",
        "ms",
        "Enable data switching for memory operations. It tries to maximize the"
        " data switching factor on loads and store operations.",
        group=groupname,
    )

    cmdline.add_option(
        "memory-stream",
        "me",
        None,
        "Memory stream definition. String with the format "
        "NUM:SIZE:WEIGHT:STRIDE:REGS where NUM is the number of streams of "
        "this type, SIZE is the working set size of the stream in bytes, "
        "WEIGHT is the probability of the stream. E.g. streams with the same"
        "weight will have same probability to be generated. "
        "STRIDE is the stride access patern between the elements of the "
        "stream and REGS is the number of register sets (address base + "
        "address index) to be used for each stream. All the elements of "
        "this format stream can be just a number or a range specfication "
        "(start-end) or (start-end-step). This flag can be specified "
        "multiple times",
        group=groupname,
        opt_type=string_with_fields(":", 5, 5,
                                    [int_range(1, 100),
                                     int_range(1, 2**32),
                                     int_range(1, 10000),
                                     int_range(1, 2**32),
                                     int_range(1, 10)
                                     ]
                                    ),
        required=False,
        action="append"
    )

    cmdline.add_option(
        "benchmark-size",
        "B",
        [4096],
        "Size in instructions of the microbenchmark main loop.",
        group=groupname,
        opt_type=int_range(1, 999999999999),
    )

    cmdline.add_option(
        "dependency-distance",
        "dd",
        0,
        "Average dependency distance between instructions. A value"
        " below 1 means not dependency between instructions. A value of "
        "1 means a chain of dependent instructions.",
        group=groupname,
        opt_type=float_type(0, 999999999999)
    )

    cmdline.add_flag(
        "reset",
        "R",
        "Reset the register contents on each loop iteration",
        group=groupname,
    )

    cmdline.add_flag(
        "parallel",
        "p",
        "Generate benchmarks in parallel",
        group=groupname,
    )

    cmdline.add_flag(
        "skip",
        "s",
        "Skip benchmarks already generated",
        group=groupname,
    )

    cmdline.add_flag(
        "count",
        "N",
        "Only count the number of sequence to generate. Do not generate "
        "anything",
        group=groupname,
    )

    cmdline.add_option(
        "max-memory",
        "Mm",
        999999999999,
        "Maximum memory for all the streams generated",
        group=groupname,
        opt_type=int_type(0, 999999999999)
    )

    cmdline.add_option(
        "min-memory",
        "mm",
        0,
        "Minimum memory for all the streams generated",
        group=groupname,
        opt_type=int_type(0, 999999999999)
    )

    cmdline.add_option(
        "max-regsets",
        "Mr",
        999999999999,
        "Maximum number of regsets for all the streams generated",
        group=groupname,
        opt_type=int_type(1, 999999999999)
    )

    cmdline.add_flag(
        "ignore-errors",
        "ie",
        "Ignore error during code generation (continue in case of "
        "an error in a particular parameter combination)",
        group=groupname,
    )

    print_info("Processing input arguments...")
    cmdline.main(args, _main)
Пример #3
0
def main():
    """
    Program main
    """
    args = sys.argv[1:]
    cmdline = CLI(
        "Microprobe seqtune tool",
        default_config_file="mp_seqtune.cfg",
        force_required=['target']
    )

    groupname = "SEQTUNE arguments"
    cmdline.add_group(
        groupname, "Command arguments related to Sequence tuner generator"
    )

    cmdline.add_option(
        "seq-output-dir",
        "D",
        None,
        "Output directory name",
        group=groupname,
        opt_type=existing_dir,
        required=True
    )

    cmdline.add_option(
        "sequence",
        "seq",
        None,
        "Base instruction sequence to modify (command separated list of "
        "instructions). If multiple sequences are provided (separated by"
        " a space) they are combined (product).",
        group=groupname,
        opt_type=str,
        required=True,
        nargs="+"
    )

    cmdline.add_option(
        "repeat",
        "r",
        1,
        "If multiple sequences are provided in --sequence, this parameter"
        " specifies how many of them are concated to generate the final "
        "sequence.",
        group=groupname,
        opt_type=int_type(1, 999999999999),
    )

    cmdline.add_option(
        "replace-every",
        "re",
        None,
        "Replace every. String with the format 'INSTR1:INSTR2:RANGE' to "
        "specfy that INSTR1 will be replaced by INSTR2 every RANGE "
        "instructions. Range can be just an integer or a RANGE specifier of "
        "the form: #1:#2 to generate a range from #1 to #2, or #1:#2:#3 to "
        "generate a range between #1 to #2 with step #3. E.g. 10:20 generates "
        "10, 11, 12 ... 19, 20 and 10:20:2 generates 10, 12, 14, ... 18, 20.",
        group=groupname,
        opt_type=string_with_fields(":", 3, 3,
                                    [str, str, int_range(1, 10000)]),
        required=False,
        action="append"
    )

    cmdline.add_option(
        "add-every",
        "ae",
        None,
        "Add every. String with the format 'INSTR1:RANGE' to "
        "specfy that INSTR1 will be added to the sequence every RANGE "
        "instructions. Range can be just an integer or a RANGE specifier of "
        "the form: #1-#2 to generate a range from #1 to #2, or #1-#2-#3 to "
        "generate a range between #1 to #2 with step #3. E.g. 10:20 generates "
        "10, 11, 12 ... 19, 20 and 10:20:2 generates 10, 12, 14, ... 18, 20.",
        group=groupname,
        opt_type=string_with_fields(":", 2, 2,
                                    [str, int_range(1, 10000)]),
        required=False,
        action="append"
    )

    cmdline.add_option(
        "branch-every",
        "be",
        None,
        "Conditional branches are modeled not taken by default. Using this "
        "paratemeter, every N will be taken.",
        group=groupname,
        opt_type=int_range(1, 10000),
        required=False,
        action="append"
    )

    cmdline.add_option(
        "branch-pattern",
        "bp",
        None,
        "Branch pattern (in binary) to be generated. E.g 0010 will model the "
        "conditional branches as NotTaken NotTaken Taken NotTaken in a round "
        "robin fashion. One can use 'L<range>' to generate all the patterns "
        "possible of length #. E.g. 'L2-5' will generate all unique possible "
        "branch patterns of length 2,3,4 and 5.",
        group=groupname,
        opt_type=str,
        required=False,
        action="append")

    cmdline.add_flag(
        "data-switch",
        "ds",
        "Enable data switching for instruction. It tries to maximize the "
        "data switching factor on inputs and outputs of instructions.",
        group=groupname,
    )

    cmdline.add_flag(
        "switch-branch",
        "sb",
        "Switch branch pattern in each iteration.",
        group=groupname,
    )

    cmdline.add_flag(
        "memory-switch",
        "ms",
        "Enable data switching for memory operations. It tries to maximize the"
        " data switching factor on loads and store operations.",
        group=groupname,
    )

    cmdline.add_option(
        "memory-stream",
        "me",
        None,
        "Memory stream definition. String with the format "
        "NUM:SIZE:WEIGHT:STRIDE:REGS:RND:LOC1:LOC2 where NUM is the number "
        "of streams of "
        "this type, SIZE is the working set size of the stream in bytes, "
        "WEIGHT is the probability of the stream. E.g. streams with the same"
        "weight will have same probability to be generated. "
        "STRIDE is the stride access patern between the elements of the "
        "stream and REGS is the number of register sets (address base + "
        "address index) to be used for each stream. "
        "RND controls the randomess of the generated memory access "
        "stream. -1 is full randomness, 0 is not randomness, and any "
        "value above 0 control the randomness range. E.g. a value of "
        "1024 randomizes the accesses within 1024 bytes memory ranges."
        "LOC1 and LOC2 control the temporal locality of the memory access "
        "stream in the following way: the last LOC1 accesses are going "
        "to be accessed again LOC2 times before moving forward to the "
        "next addresses. If LOC2 is 0 not temporal locality is generated "
        "besides the implicit one from the memory access stream definition. "
        "All the elements of "
        "this format stream can be just a number or a range specfication "
        "(start-end) or (start-end-step). This flag can be specified "
        "multiple times",
        group=groupname,
        opt_type=string_with_fields(":", 8, 8,
                                    [int_range(1, 100),
                                     int_range(1, 2**32),
                                     int_range(1, 10000),
                                     int_range(1, 2**32),
                                     int_range(1, 10),
                                     int_range(-1, 2**32),
                                     int_range(1, 2**32),
                                     int_range(0, 2**32),
                                     ]
                                    ),
        required=False,
        action="append"
    )

    cmdline.add_option(
        "benchmark-size",
        "B",
        [4096],
        "Size in instructions of the microbenchmark main loop.",
        group=groupname,
        opt_type=int_range(1, 999999999999),
    )

    cmdline.add_option(
        "dependency-distance",
        "dd",
        0,
        "Average dependency distance between instructions. A value"
        " below 1 means not dependency between instructions. A value of "
        "1 means a chain of dependent instructions.",
        group=groupname,
        opt_type=float_type(0, 999999999999)
    )

    cmdline.add_flag(
        "reset",
        "R",
        "Reset the register contents on each loop iteration",
        group=groupname,
    )

    cmdline.add_flag(
        "endless",
        "e",
        "Some backends allow the control to wrap the sequence generated in an"
        " endless loop. Depending on the target specified, this flag will "
        "force to generate sequences in an endless loop (some targets "
        " might ignore it)",
        group=groupname,
    )

    cmdline.add_flag(
        "parallel",
        "p",
        "Generate benchmarks in parallel",
        group=groupname,
    )

    cmdline.add_option(
        "batch-number",
        "bn",
        1,
        "Batch number to generate. Check --num-batches option for more "
        "details",
        group=groupname,
        opt_type=int_type(1, 10000)
    )

    cmdline.add_option(
        "num-batches",
        "nb",
        1,
        "Number of batches. The number of microbenchmark to generate "
        "is divided by this number, and the number the batch number "
        "specified using -bn option is generated. This is useful to "
        "split the generation of many test cases in various batches.",
        group=groupname,
        opt_type=int_type(1, 10000)
    )

    cmdline.add_flag(
        "skip",
        "s",
        "Skip benchmarks already generated",
        group=groupname,
    )

    cmdline.add_flag(
        "shortnames",
        "sn",
        "Use short output names",
        group=groupname,
    )

    cmdline.add_flag(
        "compress",
        "CC",
        "Compress output files",
        group=groupname,
    )

    cmdline.add_flag(
        "count",
        "N",
        "Only count the number of sequence to generate. Do not generate "
        "anything",
        group=groupname,
    )

    cmdline.add_option(
        "max-memory",
        "Mm",
        999999999999,
        "Maximum memory for all the streams generated",
        group=groupname,
        opt_type=int_type(0, 999999999999)
    )

    cmdline.add_option(
        "min-memory",
        "mm",
        0,
        "Minimum memory for all the streams generated",
        group=groupname,
        opt_type=int_type(0, 999999999999)
    )

    cmdline.add_option(
        "max-regsets",
        "Mr",
        999999999999,
        "Maximum number of regsets for all the streams generated",
        group=groupname,
        opt_type=int_type(1, 999999999999)
    )

    cmdline.add_flag(
        "ignore-errors",
        "ie",
        "Ignore error during code generation (continue in case of "
        "an error in a particular parameter combination)",
        group=groupname,
    )

    print_info("Processing input arguments...")
    cmdline.main(args, _main)