def test_DictToObj(self):
        raw_input_info = {
            'path_arglist': ['./data/hierarchical_primitive_arch.yaml'],
            'parser_version': self.version
        }
        raw_dicts = RawInputs2Dicts(raw_input_info)
        interpreted_arch_dict = raw_dicts.get_arch_spec_dict()

        system_state = SystemState()
        for pc_name, pc_info in raw_dicts.get_pc_classses().items():
            system_state.add_pc_class(ComponentClass(pc_info))

        fully_defined_dict = fully_define_arch_dict(interpreted_arch_dict, {},
                                                    system_state.pc_classes)
        for component_name, component_info in self.desired_fully_defined_arch_dict[
                'components'].items():
            self.assertEqual(
                fully_defined_dict['components'][component_name]['name'],
                component_info['name'])
            self.assertEqual(
                fully_defined_dict['components'][component_name]['class'],
                component_info['class'])
            for attr_name, attr_val in component_info['attributes'].items():
                self.assertEqual(
                    fully_defined_dict['components'][component_name]
                    ['attributes'][attr_name], attr_val)
    def test_fromYAMLfileToERTDict(self):
        """ generate desired ERT dictionary representation from YAML file input """

        raw_input_info = {
            'path_arglist': ['./data/ERT.yaml'],
            'parser_version': self.version
        }
        raw_dicts = RawInputs2Dicts(raw_input_info)
        self.assertEqual(raw_dicts.get_ERT_dict(), self.desired_ERT_dict)
    def test_constructActionCountsObj(self):
        """ construct action counts obj with raw dictionary representation"""

        raw_input_info = {
            'path_arglist': ['./data/action_counts.yaml'],
            'parser_version': self.version
        }
        raw_dicts = RawInputs2Dicts(raw_input_info)
        action_counts_obj = action_counts_dict_2_obj(
            raw_dicts.get_action_counts_dict())
    def test_fromYAMLfileToActionCountsDict(self):
        """generate desired action counts dictionary representation from YAML file input"""

        raw_input_info = {
            'path_arglist': ['./data/action_counts.yaml'],
            'parser_version': self.version
        }
        raw_dicts = RawInputs2Dicts(raw_input_info)
        self.assertEqual(raw_dicts.get_action_counts_dict(),
                         self.desired_action_counts_dict)
    def test_constructERTobj(self):
        """ construct ERT obj with raw dictionary representation"""

        raw_input_info = {
            'path_arglist': ['./data/ERT.yaml'],
            'parser_version': self.version
        }
        raw_dicts = RawInputs2Dicts(raw_input_info)
        ERT_info = {}
        ERT_info['ERT_dict'] = raw_dicts.get_ERT_dict()
        ERT_info['parser_version'] = self.version
        ERT_info['precision'] = 3
        ERT_obj = ERT_dict_to_obj(ERT_info)
 def test_fromYAMLtoDict(self):
     """ step01: contruct dictionary representation of the architecture with YAML file
     define all the component names, project attributes
     """
     # accelergy's dict representation of the arch spec
     #  1. flattens all the component names
     #  2. projects all the shared attributes
     #  3. DO NOT perform mappings/arithmetic operations of the attributes,
     #      as default attributes from the classes are not available from just parsing the input arch yaml file
     raw_input_info = {
         'path_arglist': ['./data/hierarchical_primitive_arch.yaml'],
         'parser_version': self.version
     }
     raw_dicts = RawInputs2Dicts(raw_input_info)
     interpreted_arch_dict = raw_dicts.get_arch_spec_dict()
     self.assertEqual(interpreted_arch_dict, self.desired_arch_dict)
    def test_wrongActionCounts(self):
        """ test if wrong component name in action count will result in error"""

        desired_ERT_obj = ERT_dict_to_obj({
            'ERT_dict': self.desired_ERT_dict,
            'parser_version': self.version,
            'precision': 3
        })
        raw_input_info = {
            'path_arglist': ['./data/action_counts_error.yaml'],
            'parser_version': self.version
        }
        raw_dicts = RawInputs2Dicts(raw_input_info)
        action_counts_error_obj = action_counts_dict_2_obj(
            raw_dicts.get_action_counts_dict())
        init_info = {
            'action_counts': action_counts_error_obj,
            'ERT': desired_ERT_obj,
            'parser_version': self.version
        }
        with self.assertRaises(SystemExit) as cm:
            EnergyCalculator(init_info)
        self.assertEqual(cm.exception.code, 1)
def main():
    accelergy_version = 0.3

    # ----- Interpret Commandline Arguments
    args = parse_commandline_args()
    output_prefix = args.oprefix
    path_arglist = args.files
    output_path = args.outdir

    # ----- Global Storage of System Info
    system_state = SystemState()
    system_state.set_accelergy_version(accelergy_version)

    # ----- Load Raw Inputs to Parse into Dicts
    raw_input_info = {'path_arglist': path_arglist, 'parser_version': accelergy_version}
    raw_dicts = RawInputs2Dicts(raw_input_info)

    # ----- Interpret the input architecture description using only the input information (w/o class definitions)
    system_state.set_hier_arch_spec(raw_dicts.get_hier_arch_spec_dict())

    # save file to correct output path location
    path = os.path.join(output_path, output_prefix + 'defined_input_architecture.yaml')
    write_yaml_file(path, system_state.hier_arch_spec)
    INFO('defined input architecture is saved to:', path)
Beispiel #9
0
def main():
    accelergy_version = 0.3

    # ----- Interpret Commandline Arguments
    args = parse_commandline_args()
    output_prefix = args.oprefix
    path_arglist = args.files
    precision = args.precision
    desired_output_files = args.output_files
    # interpret desired output files
    oflags = {
        'ERT': 0,
        'ERT_summary': 0,
        'ART': 0,
        'ART_summary': 0,
        'energy_estimation': 0,
        'flattened_arch': 0
    }
    for key, val in oflags.items():
        if 'all' in desired_output_files or key in desired_output_files:
            oflags[key] = 1

    INFO(
        "generating outputs according to the following specified output flags... \n "
        "Please use the -f flag to update the preference (default to all output files)"
    )
    print(oflags)

    oflags['output_prefix'] = output_prefix
    # interpret the types of processing that need to be performed
    flatten_architecture = 1 if oflags['flattened_arch'] else 0
    compute_ERT = 1 if oflags['ERT'] or oflags['ERT_summary'] or oflags[
        'energy_estimation'] else 0
    compute_energy_estimate = 1 if oflags['energy_estimation'] else 0
    compute_ART = 1 if oflags['ART'] or oflags['ART_summary'] else 0

    # ----- Global Storage of System Info
    system_state = SystemState()
    system_state.set_accelergy_version(accelergy_version)
    # transport the input flag information to system state
    system_state.set_flag_s({
        'output_path': args.outdir,
        'verbose': args.verbose
    })
    system_state.set_flag_s(oflags)

    # ----- Load Raw Inputs to Parse into Dicts
    raw_input_info = {
        'path_arglist': path_arglist,
        'parser_version': accelergy_version
    }
    raw_dicts = RawInputs2Dicts(raw_input_info)

    # ----- Determine what operations should be performed
    available_inputs = raw_dicts.get_available_inputs()

    # ---- Detecting config only cases and gracefully exiting
    if len(available_inputs) == 0:
        INFO("no input is provided, exiting...")
        sys.exit(0)

    if compute_ART or flatten_architecture or compute_ERT and 'ERT' not in available_inputs:
        # ----- Interpret the input architecture description using only the input information (w/o class definitions)
        system_state.set_hier_arch_spec(raw_dicts.get_hier_arch_spec_dict())

    if flatten_architecture or (compute_ERT and 'ERT'
                                not in available_inputs) or compute_ART:
        # architecture needs to be defined if
        #    (1) flattened architecture required output,
        #    (2) ERT needed but bot provided,
        #    (3) ART needed

        # ----- Add the Component Classes
        for pc_name, pc_info in raw_dicts.get_pc_classses().items():
            system_state.add_pc_class(ComponentClass(pc_info))
        for cc_name, cc_info in raw_dicts.get_cc_classses().items():
            system_state.add_cc_class(ComponentClass(cc_info))

        # ----- Set Architecture Spec (all attributes defined)
        arch_obj = arch_dict_2_obj(raw_dicts.get_flatten_arch_spec_dict(),
                                   system_state.cc_classes,
                                   system_state.pc_classes)
        system_state.set_arch_spec(arch_obj)

    if (compute_ERT and 'ERT' not in available_inputs) or compute_ART:
        # ERT/ERT_summary/energy estimates/ART/ART summary need to be generated without provided ERT
        #        ----> all components need to be defined
        # ----- Add the Fully Defined Components (all flattened out)

        for arch_component in system_state.arch_spec:
            if arch_component.get_class_name() in system_state.pc_classes:
                class_name = arch_component.get_class_name()
                pc = PrimitiveComponent({
                    'component':
                    arch_component,
                    'pc_class':
                    system_state.pc_classes[class_name]
                })
                system_state.add_pc(pc)
            elif arch_component.get_class_name() in system_state.cc_classes:
                cc = CompoundComponent({
                    'component': arch_component,
                    'pc_classes': system_state.pc_classes,
                    'cc_classes': system_state.cc_classes
                })
                system_state.add_cc(cc)
            else:
                ERROR_CLEAN_EXIT(
                    'Cannot find class name %s specified in architecture' %
                    arch_component.get_class())

        # ----- Add all available plug-ins
        system_state.add_plug_ins(
            plug_in_path_to_obj(raw_dicts.get_estimation_plug_in_paths(),
                                output_prefix))

    if compute_ERT and 'ERT' in available_inputs:
        # ERT/ ERT_summary/ energy estimates need to be generated with provided ERT
        #      ----> do not need to define components
        # ----- Get the ERT from raw inputs
        ert_dict = raw_dicts.get_ERT_dict()
        system_state.set_ERT(
            ERT_dict_to_obj({
                'ERT_dict': ert_dict,
                'parser_version': accelergy_version,
                'precision': precision
            }))

    if compute_ERT and 'ERT' not in available_inputs:
        # ----- Generate Energy Reference Table
        ert_gen = EnergyReferenceTableGenerator({
            'parser_version': accelergy_version,
            'pcs': system_state.pcs,
            'ccs': system_state.ccs,
            'plug_ins': system_state.plug_ins,
            'precision': precision
        })
        system_state.set_ERT(ert_gen.get_ERT())

    if compute_energy_estimate:  # if energy estimates need to be generated
        # ----- Generate Energy Estimates
        action_counts_obj = action_counts_dict_2_obj(
            raw_dicts.get_action_counts_dict())
        system_state.set_action_counts(action_counts_obj)
        energy_calc = EnergyCalculator({
            'parser_version': accelergy_version,
            'action_counts': system_state.action_counts,
            'ERT': system_state.ERT
        })
        system_state.set_energy_estimations(energy_calc.energy_estimates)

    if compute_ART:  # if ART, ART_summary need to be generated
        # ----- Generate Area Reference Table
        art_gen = AreaReferenceTableGenerator({
            'parser_version': accelergy_version,
            'pcs': system_state.pcs,
            'ccs': system_state.ccs,
            'plug_ins': system_state.plug_ins,
            'precision': precision
        })
        system_state.set_ART(art_gen.get_ART())

    # ----- Generate All Necessary Output Files
    generate_output_files(system_state)