From d8434bf6e030c36abc45199a3c3de510a9b2f6d0 Mon Sep 17 00:00:00 2001 From: JanLJL Date: Thu, 24 Oct 2019 12:38:26 +0200 Subject: [PATCH] fixed last problems with ibench import --- osaca/db_interface.py | 29 +++++++++++++-------------- osaca/frontend.py | 3 ++- osaca/osaca.py | 8 +++----- osaca/parser/parser_AArch64v81.py | 1 + osaca/parser/parser_x86att.py | 22 +++++++++++++------- osaca/semantics/hw_model.py | 7 ++++--- osaca/semantics/semantics_appender.py | 4 ++-- 7 files changed, 41 insertions(+), 33 deletions(-) diff --git a/osaca/db_interface.py b/osaca/db_interface.py index 3acd17d..048a1e8 100755 --- a/osaca/db_interface.py +++ b/osaca/db_interface.py @@ -52,23 +52,22 @@ def import_benchmark_output(arch, bench_type, filepath): with open(filepath, 'r') as f: input_data = f.readlines() db_entries = None + mm = MachineModel(arch) if bench_type == 'ibench': - db_entries = _get_ibench_output(input_data) + db_entries = _get_ibench_output(input_data, mm.get_ISA()) elif bench_type == 'asmbench': raise NotImplementedError # write entries to DB - mm = MachineModel(arch) for entry in db_entries: - mm.set_instruction_entry(entry) - with open(filepath, 'w') as f: - mm.dump(f) + mm.set_instruction_entry(db_entries[entry]) + print(mm.dump()) ################## # HELPERS IBENCH # ################## -def _get_ibench_output(input_data): +def _get_ibench_output(input_data, isa): db_entries = {} for line in input_data: if 'Using frequency' in line or len(line) == 0: @@ -81,7 +80,7 @@ def _get_ibench_output(input_data): else: mnemonic = instruction.split('-')[0] operands = instruction.split('-')[1].split('_') - operands = [_create_db_operand(op) for op in operands] + operands = [_create_db_operand(op, isa) for op in operands] entry = { 'name': mnemonic, 'operands': operands, @@ -107,7 +106,7 @@ def _get_ibench_output(input_data): return db_entries -def _validate_measurement(self, measurement, is_tp): +def _validate_measurement(measurement, is_tp): if not is_tp: if ( math.floor(measurement) * 1.05 >= measurement @@ -127,14 +126,14 @@ def _validate_measurement(self, measurement, is_tp): return None -def _create_db_operand(self, operand): - if self.isa == 'aarch64': - return self._create_db_operand_aarch64(operand) - elif self.isa == 'x86': - return self._create_db_operand_x86(operand) +def _create_db_operand(operand, isa): + if isa == 'aarch64': + return _create_db_operand_aarch64(operand) + elif isa == 'x86': + return _create_db_operand_x86(operand) -def _create_db_operand_aarch64(self, operand): +def _create_db_operand_aarch64(operand): if operand == 'i': return {'class': 'immediate', 'imd': 'int'} elif operand in 'wxbhsdq': @@ -155,7 +154,7 @@ def _create_db_operand_aarch64(self, operand): raise ValueError('Parameter {} is not a valid operand code'.format(operand)) -def _create_db_operand_x86(self, operand): +def _create_db_operand_x86(operand): if operand == 'r': return {'class': 'register', 'name': 'gpr'} elif operand in 'xyz': diff --git a/osaca/frontend.py b/osaca/frontend.py index a2fc131..845c266 100755 --- a/osaca/frontend.py +++ b/osaca/frontend.py @@ -113,6 +113,7 @@ class Frontend(object): def print_combined_view(self, kernel, cp_kernel: KernelDG, dep_dict, show_cmnts=True): self._print_header_report() self._print_symbol_map() + print('\n\nCombined Analysis Report\n' + '-----------------------') lineno_filler = ' ' port_len = self._get_max_port_len(kernel) # Separator for ports @@ -123,7 +124,7 @@ class Frontend(object): # for LCD/CP column separator += '-' * (2 * 6 + len(col_sep)) + '-' * len(col_sep) sep_list = self._get_separator_list(col_sep) - headline = 'Ports' + headline = 'Port pressure in cycles' headline_str = '{{:^{}}}'.format(len(separator)) # Prepare CP/LCD variable cp_lines = [x['line_number'] for x in cp_kernel] diff --git a/osaca/osaca.py b/osaca/osaca.py index a49ff31..4ff3864 100755 --- a/osaca/osaca.py +++ b/osaca/osaca.py @@ -5,9 +5,7 @@ import io import os import re import sys -from filecmp import dircmp from subprocess import call -import warnings from osaca.db_interface import sanity_check, import_benchmark_output from osaca.frontend import Frontend @@ -198,10 +196,10 @@ def run(args, output_file=sys.stdout): # Sanity check on DB verbose = True if args.verbose > 0 else False sanity_check(args.arch, verbose=verbose) - if 'import_data' in args: + elif 'import_data' in args: # Import microbench output file into DB - import_data(args.import_data, args.arch, args.file) - if args.insert_marker: + import_data(args.import_data, args.arch, args.file.name) + elif args.insert_marker: # Try to add IACA marker insert_byte_marker(args) else: diff --git a/osaca/parser/parser_AArch64v81.py b/osaca/parser/parser_AArch64v81.py index 8aa4585..56abb98 100755 --- a/osaca/parser/parser_AArch64v81.py +++ b/osaca/parser/parser_AArch64v81.py @@ -9,6 +9,7 @@ from osaca.parser import AttrDict, BaseParser class ParserAArch64v81(BaseParser): def __init__(self): super().__init__() + self.isa = 'aarch64' def construct_parser(self): # Comment diff --git a/osaca/parser/parser_x86att.py b/osaca/parser/parser_x86att.py index 15c0da1..7063721 100755 --- a/osaca/parser/parser_x86att.py +++ b/osaca/parser/parser_x86att.py @@ -8,6 +8,7 @@ from osaca.parser import AttrDict, BaseParser class ParserX86ATT(BaseParser): def __init__(self): super().__init__() + self.isa = 'x86' def construct_parser(self): decimal_number = pp.Combine( @@ -67,8 +68,13 @@ class ParserX86ATT(BaseParser): directive_option = pp.Combine( pp.Word('#@.', exact=1) + pp.Word(pp.printables, excludeChars=',') ) - directive_parameter = (pp.quotedString | directive_option | identifier | hex_number | - decimal_number | self.register + directive_parameter = ( + pp.quotedString + | directive_option + | identifier + | hex_number + | decimal_number + | self.register ) commaSeparatedList = pp.delimitedList(pp.Optional(directive_parameter), delim=',') self.directive = pp.Group( @@ -172,9 +178,10 @@ class ParserX86ATT(BaseParser): if result is None: try: result = self.parse_instruction(line) - except pp.ParseException as e: - raise ValueError('Could not parse instruction on line {}: {!r}'.format( - line_number, line)) + except pp.ParseException: + raise ValueError( + 'Could not parse instruction on line {}: {!r}'.format(line_number, line) + ) instruction_form[self.INSTRUCTION_ID] = result[self.INSTRUCTION_ID] instruction_form[self.OPERANDS_ID] = result[self.OPERANDS_ID] instruction_form[self.COMMENT_ID] = result[self.COMMENT_ID] @@ -202,8 +209,9 @@ class ParserX86ATT(BaseParser): { self.INSTRUCTION_ID: result['mnemonic'], self.OPERANDS_ID: operands, - self.COMMENT_ID: - ' '.join(result[self.COMMENT_ID]) if self.COMMENT_ID in result else None, + self.COMMENT_ID: ' '.join(result[self.COMMENT_ID]) + if self.COMMENT_ID in result + else None, } ) return return_dict diff --git a/osaca/semantics/hw_model.py b/osaca/semantics/hw_model.py index 60f5dc7..4271276 100755 --- a/osaca/semantics/hw_model.py +++ b/osaca/semantics/hw_model.py @@ -189,9 +189,10 @@ class MachineModel(object): # Replace instruction form's port_pressure with styled version for RoundtripDumper formatted_instruction_forms = deepcopy(self._data['instruction_forms']) for instruction_form in formatted_instruction_forms: - cs = ruamel.yaml.comments.CommentedSeq(instruction_form['port_pressure']) - cs.fa.set_flow_style() - instruction_form['port_pressure'] = cs + if instruction_form['port_pressure'] is not None: + cs = ruamel.yaml.comments.CommentedSeq(instruction_form['port_pressure']) + cs.fa.set_flow_style() + instruction_form['port_pressure'] = cs # Create YAML object yaml = self._create_yaml_object() diff --git a/osaca/semantics/semantics_appender.py b/osaca/semantics/semantics_appender.py index 0c92272..2116ad5 100755 --- a/osaca/semantics/semantics_appender.py +++ b/osaca/semantics/semantics_appender.py @@ -319,14 +319,14 @@ class SemanticsAppender(object): def _get_regular_source_x86ATT(self, instruction_form): # return all but last operand sources = [ - op for op in instruction_form['operands'][0 : len(instruction_form['operands']) - 1] + op for op in instruction_form['operands'][0:len(instruction_form['operands']) - 1] ] return sources def _get_regular_source_AArch64(self, instruction_form): # return all but first operand sources = [ - op for op in instruction_form['operands'][1 : len(instruction_form['operands'])] + op for op in instruction_form['operands'][1:len(instruction_form['operands'])] ] return sources