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 "input_coblst_file" in arguments: print_info("Input file provided") file_fd = open(arguments["input_coblst_file"], 'rb') if struct.unpack("cc", file_fd.read(2)) == ('\x1f', '\x8b'): print_info("Compressed GZIP file detected") file_fd.close() file_fd = gzip.open(arguments["input_coblst_file"]) else: file_fd.close() file_fd = open(arguments["input_coblst_file"]) else: print_info("No input file provided, reading from standard input... ") file_fd = sys.stdin dump_mpt(file_fd, target, arguments)
def _main(arguments): """ Main program. Called after the arguments from the CLI interface have been processed. """ print_info("Arguments processed!") print_info("Importing target definition " "'power_v206-power7-ppc64_linux_gcc'...") target = import_definition("power_v206-power7-ppc64_linux_gcc") # Get the arguments functional_units = arguments["functional_unit"] prefix = arguments["output_prefix"] output_path = arguments["output_path"] size = arguments["size"] latency = arguments["average_latency"] distance = arguments["dependency_distance"] if functional_units is None: functional_units = ["ALL"] _generate_benchmark(target, "%s/%s_" % (output_path, prefix), (functional_units, size, latency, distance))
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...") if 'raw_bin' in arguments: arguments['safe_bin'] = True if 'safe_bin' in arguments: microprobe.MICROPROBE_RC['safe_bin'] = True if 'fix_start_address' not in arguments: arguments['fix_start_address'] = None if "no_wrap_test" in arguments and "wrap_endless" in arguments: print_error( "--no-wrap-test specified and --wrap-endless specified. " "Incompatible options." ) target = import_definition(arguments.pop('target')) test_definition = arguments['mpt_definition'] output_file = arguments['elf_output_file'] print_info("Start generating '%s'" % output_file) generate( test_definition, output_file, target, **arguments )
def _main(arguments): """ Program main, after processing the command line arguments :param arguments: Dictionary with command line arguments and values :type arguments: :class:`dict` """ target = import_definition(arguments['target']) if 'strict' not in arguments: arguments['strict'] = False dump_objdump(target, arguments)
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.pop('target')) test_definition = arguments.pop('mpt_definition') outputfile = arguments.pop('c_output_file') print_info("Start generating '%s'" % outputfile) generate(test_definition, outputfile, target, **arguments) print_info("'%s' generated!" % outputfile)
def _main(arguments): """ Program main, after processing the command line arguments :param arguments: Dictionary with command line arguments and values :type arguments: :class:`dict` """ target = import_definition(arguments['target']) if arguments['od_bin'] is None: print_error("Unable to find a 'od' utility. Edit your $PATH or use" " the --od-bin parameter") exit(-1) if "strict" not in arguments: arguments["strict"] = False dump_objdump(target, arguments)
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 "input_objdump_file" in arguments: print_info("Input file provided") file_fd = open_generic_fd(arguments["input_objdump_file"], 'r') else: print_info("No input file provided, reading from standard input... ") file_fd = sys.stdin dump_mpt(file_fd, target, arguments)
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...") if 'safe-bin' in arguments: microprobe.MICROPROBE_RC['safe_bin'] = True target = import_definition(arguments.pop('target')) test_definition = arguments['mpt_definition'] output_file = arguments['bin_output_file'] print_info("Start generating '%s'" % output_file) generate( test_definition, output_file, target, **arguments ) print_info("'%s' generated!" % output_file)
def _main(arguments): """ Program main, after processing the command line arguments :param arguments: Dictionary with command line arguments and values :type arguments: :class:`dict` """ if "dump_c2mpt_template" in arguments: dump_c2mpt_template(arguments) _exit(0) if "input_c_file" not in arguments: print_error("argument -i/--input-c-file is required") _exit(-1) print_info("Arguments processed!") print_info("Importing target definition...") target = import_definition(arguments['target']) c2mpt(target, arguments)
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)
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 arguments['od_bin'] is None: print_error("Unable to find a 'od' utility. Edit your $PATH or use" " the --od-bin parameter") exit(-1) if 'safe' not in arguments: arguments['safe'] = False dump_bin(target, arguments)
def __init__(self): self.args = self._parse_options() self.target = import_definition( str.format("{}-{}-{}", self.args.isa, self.args.uarch, self.args.env))
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] )
# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from __future__ import absolute_import from __future__ import print_function import sys from microprobe.target import import_definition from microprobe.utils.bin import interpret_bin from microprobe.code.ins import instruction_from_definition from microprobe.utils.asm import interpret_asm target = import_definition(sys.argv[1]) print(sys.argv[2:]) for elem in sys.argv[2:]: instr_def = interpret_bin(elem, target)[0] instr = instruction_from_definition(instr_def) codification = int(instr.binary(), 2) assembly = instr.assembly() instr_def2 = interpret_asm(assembly, target, [])[0] print(hex(codification)) instr_def3 = interpret_bin(hex(codification)[2:], target)[0] instr2 = instruction_from_definition(instr_def2) instr3 = instruction_from_definition(instr_def3) assert instr.assembly() == instr2.assembly() assert instr2.assembly() == instr3.assembly() assert instr.binary() == instr2.binary()
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']])
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_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)
from microprobe.model.memory import EndlessLoopDataMemoryModel from microprobe.target import import_definition from microprobe.utils.cmdline import print_error, print_info __author__ = "Ramon Bertran" __copyright__ = "Copyright 2011-2021 IBM Corporation" __credits__ = [] __license__ = "IBM (c) 2011-2021 All rights reserved" __version__ = "0.5" __maintainer__ = "Ramon Bertran" __email__ = "*****@*****.**" __status__ = "Development" # "Prototype", "Development", or "Production" # 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) BASE_ELEMENT = [ element for element in TARGET.elements.values() if element.name == 'L1D' ][0] CACHE_HIERARCHY = TARGET.cache_hierarchy.get_data_hierarchy_from_element( BASE_ELEMENT) # Benchmark size BENCHMARK_SIZE = 8 * 1024 # Fill a list of the models to be generated
else: _PARAM1 = ['', '-dd 1', '-dd 5.5'] _PARAM2 = ['', '-R'] _PARAM3 = ['', '-B 10'] if MP_TESTING_ARCH is "RISCV": TEST_TARGETS.append(("riscv_v22-riscv_generic-riscv64_linux_gcc", "c")) TEST_TARGETS.append(("riscv_v22-riscv_generic-riscv64_test_p", "S")) TEST_FLAGS = [] TEST_FLAGS.extend(variations("", [_PARAM1, _PARAM2, _PARAM3])) _TEST_NUMBER = 1 for _TEST_TARGET in TEST_TARGETS: _TARGET = import_definition(_TEST_TARGET[0]) for _TEST_INSTR in [ my_instr.name for my_instr in subins(list(_TARGET.isa.instructions.values())) ]: for _TEST_FLAG in TEST_FLAGS: def test_function(self): """ test_function """ self.wrapper(_TEST_TARGET[0], _TEST_TARGET[1], _TEST_INSTR, extra=_TEST_FLAG)