def main(): """ Program main """ args = sys.argv[1:] cmdline = CLI("Microprobe Binary to Objdump tool", default_config_file="mp_bin2objdump.cfg", force_required=['target']) groupname = "Binary to Objdump arguments" cmdline.add_group(groupname, "Command arguments related to Binary to Objdump tool") cmdline.add_option("input-bin-file", "i", None, "Binary file to process", group=groupname, opt_type=existing_file, required=True) cmdline.add_option("od-bin", "ob", which("od"), "'od' dump utility. Default: %s" % which("od"), group=groupname, opt_type=existing_file) cmdline.add_option("start-address", "X", 0x0, "Start address. Default: 0x0", group=groupname, opt_type=int_type(0, float("+inf"))) cmdline.add_flag( "strict", "S", "Check relative branches correctness and all instructions valid.", group=groupname) cmdline.main(args, _main)
def main(): """ Program main """ args = sys.argv[1:] cmdline = CLI("Microprobe DMA to Objdump tool", default_config_file="mp_dma2objdump.cfg", force_required=['target']) groupname = "DMA to Objdump arguments" cmdline.add_group(groupname, "Command arguments related to DMA to Objdump tool") cmdline.add_option("input-dma-file", "i", None, "DMA file to process", group=groupname, opt_type=existing_file, required=True) cmdline.add_option( "width-bytes", "w", 8, "Maximum data width in bytes", group=groupname, opt_type=int_type(0, 32), ) cmdline.add_flag( "strict", "s", "Do not allow unrecognized binary", group=groupname, ) cmdline.main(args, _main)
def main(): """ Program main """ args = sys.argv[1:] cmdline = microprobe.utils.cmdline.CLI( "MicroprobeTest (mpt) to TRACE tool", mpt_options=True, default_config_file="mp_mpt2trace.cfg", force_required=['target'] ) groupname = "MPT to trace arguments" cmdline.add_group( groupname, "Command arguments related to MPT to trace tool") cmdline.add_option( "trace-output-file", "O", None, "C output file name", group=groupname, opt_type=new_file_ext([".qt", ".qt.gz", ".qt.bz2"]), required=True ) groupname = "Trace generation options" cmdline.add_group(groupname, "Command arguments related to trace generation options") cmdline.add_option( "default-memory-access-pattern", None, None, "Memory access pattern for memory references that are not modeled by" "Microprobe or not modeled using 'MP' decorator in MPT file. " "Format: comma separated list of addresses or address ranges. If a " "file path is provided, the file is readed to gather the list of " "addresses. The format of the file should be one address or range " "per line. Address range format is : <start>-<end>-<strid>. E.g. " "0x100-0x200-0x010 will generate 0x100,0x110,0x120...0x1F0,0x200 " "pattern.", group=groupname, opt_type=file_with(csv_with_ranges(0, 0xFFFFFFFFFFFFFFFF)), ) cmdline.add_option( "default-branch-pattern", None, None, "Branch pattern for branches that are not modeled by" "Microprobe or not modeled using 'BP' decorator in MPT file. " "Format: string with T or N, for taken and not taken branches, " " respectively. If a file path is provided, the file is readed to " "gather the branch pattern. The format of the file should be one " "string providing the branch pattern (T and N characters).", group=groupname, opt_type=file_with(string_with_chars('TN')), ) cmdline.add_option( "default-branch-indirect-target-pattern", None, None, "Branch target pattern for branches that are not modeled by" "Microprobe or not modeled using 'BT' decorator in MPT file. " "Format: comma separated list of target addresses. If a file " "path is provided, the file is readed to gather the list of addresses." " The format of the file should be one address per line.", group=groupname, opt_type=file_with(csv_with_integer), ) cmdline.add_option( "max-trace-size", None, _DEFAULT_MAX_INS, "Maximum trace size in intructions. Default: %d" % _DEFAULT_MAX_INS, group=groupname, opt_type=int_type(0, 999999999999), ) cmdline.add_flag( "show-trace", None, "Show trace while being generated", group=groupname, ) cmdline.add_flag( "safe-bin", None, "Ignore unrecognized binary codifications (do not" "fail). Useful when MPTs are generated by dumping directly code " "pages, which contain padding zeros and other non-code stuff)", groupname ) print_info("Processing input arguments...") cmdline.main(args, _main)
def main(): """ Program main """ args = sys.argv[1:] cmdline = CLI( "Microprobe Objdump to MPT tool", default_config_file="mp_objdump2mpt.cfg", force_required=['target'] ) groupname = "Objdump to MPT arguments" cmdline.add_group( groupname, "Command arguments related to Objdump to MPT tool" ) cmdline.add_option( "input-objdump-file", "i", None, "Objdump file to process, if not provided, the input is read from" " standard input", group=groupname, opt_type=existing_file, required=False ) cmdline.add_option( "output-mpt-file", "O", None, "Output file name", group=groupname, opt_type=new_file_ext(".mpt"), required=True ) cmdline.add_flag( "strict", "S", "Be strict when parsing objdump input, if not set, silently skip " "unparsed elements", group=groupname ) cmdline.add_option( "sections", "s", ['.text'], "Space separated CODE section names to interpret. " "(default: '.text' section)", group=groupname, nargs='+', required=False ) cmdline.add_option( "from-address", "f", 0x0, "If set, start interpreting from this address", group=groupname, opt_type=int_type(0, float('+inf')), required=False ) cmdline.add_option( "to-address", "t", float('+inf'), "If set, end interpreting at this address", group=groupname, opt_type=int_type(0, float('+inf')), required=False ) cmdline.add_option( "default-code-address", "X", None, "Default code address", group=groupname, opt_type=int_type(0, float('+inf')), required=False ) cmdline.add_option( "default-data-address", "D", None, "Default data address", group=groupname, opt_type=int_type(0, float('+inf')), required=False ) cmdline.add_flag( "elf-abi", None, "Ensure ELF Application Binary Interface (e.g. define stack, stack" " pointer, etc.)", group=groupname ) cmdline.add_option( "stack-size", None, 4096, "Stack size in bytes (Default: 4096)", group=groupname, opt_type=int_type(0, float('+inf')), required=False ) cmdline.add_option( "stack-name", None, None, "Stack name (Default: microprobe_stack)", group=groupname, opt_type=str, required=False ) cmdline.add_option( "stack-address", None, None, "Stack address (Default: allocated in the data area)", group=groupname, opt_type=int_type(0, float('+inf')), required=False ) cmdline.add_option( "start-symbol", None, None, "Symbol to call after initializing the stack. If not specified, " "no call is performed", group=groupname, opt_type=str, required=False ) cmdline.add_flag( "end-branch-to-itself", None, "A branch to itself instruction will be added at the end of the test", group=groupname ) print_info("Processing input arguments...") cmdline.main(args, _main)
def main(): """Program main.""" args = sys.argv[1:] cmdline = microprobe.utils.cmdline.CLI( "MicroprobeTest (mpt) to ELF tool", mpt_options=True, default_config_file="mp_mpt2elf.cfg", force_required=['target'], ) group_name = "MPT to ELF arguments" cmdline.add_group( group_name, "Command arguments related to MPT to ELF tool", ) cmdline.add_option( "elf-output-file", "O", None, "ELF output file name", group=group_name, opt_type=new_file_ext(".s"), required=True, ) cmdline.add_option( "compiler", None, None, "Path to the compiler", group=group_name, ) cmdline.add_option( "compiler-flags", None, "", "Compiler flags to use, if compiler is provided", group=group_name, ) group_name = "Fixing options" cmdline.add_group( group_name, "Command arguments related to fixing options", ) cmdline.add_flag( "fix-indirect-branches", None, "Fix branches without known target", group_name, ) cmdline.add_flag( "fix-branch-next", None, "Force target of branches to be the next " "sequential instruction", group_name, ) cmdline.add_flag( "fix-memory-references", None, "Ensure that registers used by instructions accessing " "storage are initialized to valid locations", group_name, ) cmdline.add_flag( "fix-memory-registers", None, "Fix non-storage instructions touching registers used for" " storage address computations (implies " "--fix-memory-references flag)", group_name, ) cmdline.add_flag( "fix-flatten-code", None, "All code is flatten using consecutive addresses", group_name, ) cmdline.add_flag( "safe-bin", None, "Ignore unrecognized binary codifications (do not" "fail). Useful when MPTs are generated by dumping " "directly code " "pages, which contain padding zeros and other " "non-code stuff)", group_name, ) cmdline.add_flag( "raw-bin", None, "Process all instruction entries together. They " "all shoud be binary entries. Implies --safe-bin " "flag. Useful when MPTs are generated by dumping " "directly code " "pages, which contain padding zeros and other " "non-code stuff)", group_name, ) cmdline.add_flag( "fix-long-jump", None, "Sometimes the generated code is unable compile due a long jump " "displacement required to jump to the start insturction.", group_name, ) cmdline.add_option( "fix-start-address", "S", None, "Sometimes the user requires the main start point to be on specific " "address to avoid compilation issues or comply with the execution " "environment requirements. This flag forces the main entry point of " "execution to be at the specified address. It is up to the user to " "define a proper entry point that does not clash with existing code.", group=group_name, opt_type=int_type(0, 2**64) ) group_name = "Wrapping options" cmdline.add_group( group_name, "Command arguments related to wrapping options", ) cmdline.add_flag( "no-wrap-test", None, "By default the code is wrapped like it was " "a function call, use this flag to disable the " "wrapping", group_name, ) cmdline.add_flag( "wrap-endless", None, "Use this flag to wrap the code in an endless " "loop assuming it is a function. " "If needed (--reset option), additional " "instructions are added to reset the " "the initial state between loop iterations. ", group_name, ) cmdline.add_option( "wrap-endless-threshold", None, 1, "Maximum percentage of instructions allowed in the reset code if " "--wrap-endless and --reset is used. I.e. if 10 is set, the tool will " "fail if the reset code required is more than 10%% of the actual " "code of the test case." " Default is 1%%.", group=group_name, opt_type=float_type(0, 1000), required=False, ) cmdline.add_flag( "reset", None, "Use this flag to enable the generation of reset " "code if wrap-endless is enabled.", group_name, ) print_info("Processing input arguments...") cmdline.main(args, _main)
def main(): """ Program main """ args = sys.argv[1:] cmdline = CLI( "Microprobe C to MPT tool", compilation_options=True, default_config_file="mp_c2mpt.cfg", force_required=['target'], ) groupname = "C to MPT arguments" cmdline.add_group(groupname, "Command arguments related to C to MPT tool") cmdline.add_option("input-c-file", "i", None, "C file to process", group=groupname, opt_type=existing_file_ext(".c"), required=False) cmdline.add_option("output-mpt-file", "O", None, "Output file name", group=groupname, opt_type=new_file_ext(".mpt"), required=True) cmdline.add_flag( "strict", "S", "Be strict when parsing objdump input, if not set, silently skip " "unparsed elements", group=groupname) cmdline.add_option("default-code-address", "X", 0x10030000, "Default code address (default: 0x10030000)", group=groupname, opt_type=int_type(0, float('+inf')), required=False) cmdline.add_option("default-data-address", "D", 0x10040000, "Default data address (default: 0x10040000)", group=groupname, opt_type=int_type(0, float('+inf')), required=False) cmdline.add_option("stack-size", None, 4096, "Stack size in bytes (Default: 4096)", group=groupname, opt_type=int_type(0, float('+inf')), required=False) cmdline.add_option( "host-displacement", None, None, "Displacement between static objdump code and loaded image on the " "host. Default computed automatically", group=groupname, opt_type=int_type(0, float('+inf')), required=False) cmdline.add_flag( "fix-displacement", None, "If data contains addresses (such as pointers) to code or data " "regions, the tool will try to fix them adding the necessary " "displacement", group=groupname, ) cmdline.add_option("stack-name", None, "microprobe_stack", "Stack name (Default: microprobe_stack)", group=groupname, opt_type=str, required=False) cmdline.add_option("stack-address", None, None, "Stack address (Default: allocated in the data area)", group=groupname, opt_type=int_type(0, float('+inf')), required=False) cmdline.add_flag( "no-data-initialization", None, "Do not run the compiled code locally to get the contents of" " registered variables before executing the *c2mpt_function*. Only " "statically specified variable contents will be dumped in the MPT" " generated", group=groupname) cmdline.add_flag( "save-temps", None, "Store the generated intermediate files permanently; place them in " "the input source file directory and name them based on the source " "file", group=groupname) cmdline.add_flag( "dump-c2mpt-template", None, "Dump a template C file, which can be used afterwards as an input " "file", group=groupname) cmdline.add_flag( "end-branch-to-itself", None, "A branch to itself instruction will be added at the end of the test", group=groupname) print_info("Processing input arguments...") cmdline.main(args, _main)
def main(): """ Program main """ args = sys.argv[1:] cmdline = CLI("Microprobe epi tool", default_config_file="mp_epi.cfg", force_required=['target']) groupname = "EPI arguments" cmdline.add_group(groupname, "Command arguments related to EPI generation") cmdline.add_option("epi-output-file", "O", None, "Output file name", group=groupname, opt_type=new_file, required=False) cmdline.add_option("epi-output-dir", "D", None, "Output directory name", group=groupname, opt_type=existing_dir, required=False) cmdline.add_option( "instructions", "ins", None, "Comma separated list of instructions to generate a benchmark with", group=groupname, opt_type=str, required=False) cmdline.add_option("benchmark-size", "B", 4096, "Size in instructions of the microbenchmark." " If more instruction are needed, nested loops are " "automatically generated", group=groupname, opt_type=int_type(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_option( "data-init", None, "random", "Data initialization values (memory and registers). It can be set" " to zero (all zeros) or to random. ", group=groupname, choices=["random", "zero"], opt_type=str) 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( "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)
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])
def main(): """ Program main """ args = sys.argv[1:] cmdline = CLI("Microprobe seq tool", default_config_file="mp_seq.cfg", force_required=['target']) groupname = "SEQ arguments" cmdline.add_group(groupname, "Command arguments related to Sequence generation") cmdline.add_option("seq-output-dir", "D", None, "Output directory name", group=groupname, opt_type=existing_dir, required=True) cmdline.add_option( "instruction-slots", "is", 4, "Number of instructions slots in the sequence. E.g. '-l 4' will " "generate sequences of length 4.", group=groupname, opt_type=int_type(1, 999999999999)) cmdline.add_option( "instruction-groups", "ig", None, "Comma separated list of instruction candidates per group. E.g. " "-ins ins1,ins2 ins3,ins4. Defines two groups of instruction " "candidates: group 1: ins1,ins2 and group 2: ins3,ins4.", group=groupname, opt_type=str, action="append", nargs="+") cmdline.add_option( "instruction-map", "im", None, "Comma separated list specifying groups instruction candidate groups " "to be used on each instruction slot. The list length should match " "the number of instruction slots defined. A -1 value means all groups" " can be used for that slot. E.g. -im 1 2,3 will generate sequences " "containing in slot 1 instructions from group 1, and in slot 2 " "instructions from groups 2 and 3.", group=groupname, opt_type=str, required=False, action="append", nargs="+") cmdline.add_option( "base-seq", "bs", None, "Comma separated list specifying the base instruction sequence", group=groupname, opt_type=str, required=False, ) cmdline.add_option( "group-max", "gM", None, "Comma separated list specifying the maximum number of instructions " " of each group to be used. E.g. -gM 1,3 will generate sequences " "containing at most 1 instruction of group 1 and 3 instructions of " "group 2. A -1 value means no maximum. The list length should match " "the number of instruction groups defined.", group=groupname, opt_type=str, required=False, action="append", nargs="+") cmdline.add_option( "group-min", "gm", None, "Comma separated list specifying the minimum number of instructions " " of each group to be used. E.g. -gm 1,3 will generate sequences " "containing at least 1 instruction of group 1 and 3 instructions of " "group 2. A -1 value means no minimum. The list length should match " "the number of instruction groups defined.", group=groupname, opt_type=str, required=False, action="append", nargs="+") cmdline.add_option("benchmark-size", "B", 4096, "Size in instructions of the microbenchmark." " If more instruction are needed, nested loops are " "automatically generated", group=groupname, opt_type=int_type(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( "force-switch", "fs", "Force data switching in all instructions, fail if not supported.", group=groupname, ) 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, ) print_info("Processing input arguments...") cmdline.main(args, _main)
def main(): """ Program main """ args = sys.argv[1:] cmdline = CLI("Microprobe COBOL lst to MPT tool", default_config_file="mp_coblst2mpt.cfg", force_required=['target']) groupname = "COBOL lst to MPT arguments" cmdline.add_group(groupname, "Command arguments related to COBOL lst to MPT tool") cmdline.add_option( "input-coblst-file", "i", None, "COBOL lst file to process, if not provided, the input is read from" " standard input", group=groupname, opt_type=existing_file, required=False) cmdline.add_option("output-mpt-file", "O", None, "Output file name", group=groupname, opt_type=new_file_ext(".mpt"), required=True) cmdline.add_flag( "strict", "S", "Be strict when parsing objdump input, if not set, silently skip " "unparsed elements", group=groupname) cmdline.add_option("from-address", "f", 0x0, "If set, start interpreting from this address", group=groupname, opt_type=int_type(0, float('+inf')), required=False) cmdline.add_option("to-address", "t", float('+inf'), "If set, end interpreting at this address", group=groupname, opt_type=int_type(0, float('+inf')), required=False) cmdline.add_option("default-code-address", "X", None, "Default code address", group=groupname, opt_type=int_type(0, float('+inf')), required=False) cmdline.add_option("default-data-address", "D", None, "Default data address", group=groupname, opt_type=int_type(0, float('+inf')), required=False) print_info("Processing input arguments...") cmdline.main(args, _main)
def main_setup(): """ Set up the command line interface (CLI) with the arguments required by this command line tool. """ args = sys.argv[1:] # Get the target definition try: target = import_definition("power_v206-power7-ppc64_linux_gcc") except MicroprobeTargetDefinitionError as exc: print_error("Unable to import target definition") print_error("Exception message: %s" % str(exc)) exit(-1) func_units = {} valid_units = [elem.name for elem in target.elements.values()] for instr in target.isa.instructions.values(): if instr.execution_units == "None": LOG.debug("Execution units for: '%s' not defined", instr.name) continue for unit in instr.execution_units: if unit not in valid_units: continue if unit not in func_units: func_units[unit] = [ elem for elem in target.elements.values() if elem.name == unit ][0] # Create the CLI interface object cmdline = microprobe.utils.cmdline.CLI("ISA power v206 profile example", config_options=False, target_options=False, debug_options=False) # Add the different parameters for this particular tool cmdline.add_option("functional_unit", "f", [func_units['ALU']], "Functional units to stress. Default: ALU", required=False, nargs="+", choices=func_units, opt_type=dict_key(func_units), metavar="FUNCTIONAL_UNIT_NAME") cmdline.add_option( "output_prefix", None, "POWER_V206_FU_STRESS", "Output prefix of the generated files. Default: POWER_V206_FU_STRESS", opt_type=str, required=False, metavar="PREFIX") cmdline.add_option("output_path", "O", "./", "Output path. Default: current path", opt_type=existing_dir, metavar="PATH") cmdline.add_option( "size", "S", 64, "Benchmark size (number of instructions in the endless loop). " "Default: 64 instructions", opt_type=int_type(1, 2**20), metavar="BENCHMARK_SIZE") cmdline.add_option("dependency_distance", "D", 1000, "Average dependency distance between the instructions. " "Default: 1000 (no dependencies)", opt_type=int_type(1, 1000), metavar="DEPENDECY_DISTANCE") cmdline.add_option("average_latency", "L", 2, "Average latency of the selected instructins. " "Default: 2 cycles", opt_type=float_type(1, 1000), metavar="AVERAGE_LATENCY") # Start the main print_info("Processing input arguments...") cmdline.main(args, _main)
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)
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)