Exemple #1
0
    def generate_estimations(self, action_counts_path, ERT_path, output_path,
                             precision):
        print('\n=========================================')
        print('Generating energy estimation')
        print('=========================================')
        # load and parse access counts
        self.energy_reference_table = load(open(ERT_path), accelergy_loader)
        self.construct_action_counts(
            load(open(action_counts_path), accelergy_loader))
        INFO('design under evaluation:', self.design_name)
        INFO('processing action counts file:',
             os.path.abspath(action_counts_path))

        self.decimal_points = precision

        for name, action_count_list in self.action_counts.items():
            INFO('processing for component:', name)
            # the components in the list are stored differently in ERT
            processed_name = self.process_name(name)
            component_ERT = self.energy_reference_table[processed_name]
            # generate the total energy for the component
            component_energy = self.process_component_action_counts(
                action_count_list, component_ERT)

            self.energy_estimation_table[name] = round(component_energy,
                                                       self.decimal_points)

        # save results
        file_path = output_path + '/estimation.yaml'
        write_yaml_file(file_path, self.energy_estimation_table)
        print(
            '---> Finished: energy calculation finished, estimation saved to:\n',
            os.path.abspath(output_path))
Exemple #2
0
    def generate_ERTs(self, design_path, output_path, precision,
                      flatten_arch_flag):
        """
        main function to start the energy reference generator
        parses the input files
        produces the energy reference tables for components
        """
        print('\n=========================================')
        print('Generating energy reference tables')
        print('=========================================')

        # Interpret inputs
        self.design_path = design_path
        self.output_path = output_path
        self.decimal_place = precision

        # Load accelergy config and design specification
        self.config = config_file_checker()
        self.design = load(open(self.design_path), accelergy_loader)
        INFO('design loaded:', design_path)
        self.construct_compound_class_description(
            self.design['compound_components'])

        # Load the primitive classes library
        self.construct_primitive_class_description()

        # Parse the architecture description and save the parsed version if flag high
        self.construct_save_architecture_description(
            self.design['architecture'])
        if flatten_arch_flag:
            self.generate_easy_to_read_flattened_architecture()
            arch_file_path = self.output_path + '/' + 'flattened_architecture.yaml'
            flattened_architecture_yaml = {
                'flattened_architecture': {
                    'version': self.arch_version,
                    'components': self.easy_to_read_flattened_architecture
                }
            }
            write_yaml_file(arch_file_path, flattened_architecture_yaml)
            INFO('Architecture flattened ... saved to ', arch_file_path)

        # Instantiate the estimation plug-ins as intances of the corresponding plug-in classes
        self.instantiate_estimator_plug_ins()

        # Generate Energy Reference Tables for the components
        self.generate_ERTs_for_architecture()

        # Save the ERTs to ERT.yaml in the output directory
        ERT_file_path = self.output_path + '/' + 'ERT.yaml'
        ERT_dict = {
            'ERT': {
                'version': self.arch_version,
                'tables': self.energy_reference_table
            }
        }
        write_yaml_file(ERT_file_path, ERT_dict)
        print('---> Finished: ERT generation finished, ERT saved to:\n',
              os.path.abspath(output_path))
def config_file_v02():
    possible_config_dirs = [
        '.' + os.sep,
        os.path.expanduser('~') + '/.config/accelergy/'
    ]
    config_file_name = 'accelergy_config.yaml'
    for possible_dir in possible_config_dirs:
        if os.path.exists(possible_dir + config_file_name):
            original_config_file_path = possible_dir + config_file_name
            original_content = load(open(original_config_file_path),
                                    accelergy_loader)
            INFO('config file located:', original_config_file_path)
            print('config file content: \n', original_content)
            if 'version' not in original_content:
                ERROR_CLEAN_EXIT(
                    'config file has no version number, cannot proceed')
            file_version = original_content['version']
            if file_version == 0.1 or file_version == 1.0:  # probably exist 1.0 in the very initial version
                ERROR_CLEAN_EXIT(
                    'config file version outdated. Latest version is 0.2.'
                    '\nPlease delete the original file, and run accelergy to create a new default config file.'
                    '\nPlease ADD YOUR USER_DEFINED file paths BACK to the updated config file at '
                    '~/.config/accelergy/accelergy_config.yaml')
            else:
                return original_content
    else:
        create_folder(possible_config_dirs[1])
        config_file_path = possible_config_dirs[1] + config_file_name
        curr_file_path = os.path.abspath(__file__)
        accelergy_share_folder_path = os.path.abspath(
            curr_file_path + '../../../../../../share/accelergy/')
        default_estimator_path = os.path.abspath(accelergy_share_folder_path +
                                                 '/estimation_plug_ins/')
        default_pc_lib_path = os.path.abspath(accelergy_share_folder_path +
                                              '/primitive_component_libs/')
        config_file_content = {
            'version': 0.2,
            'estimator_plug_ins': [default_estimator_path],
            'primitive_components': [default_pc_lib_path]
        }
        INFO('Accelergy creating default config at:',
             possible_config_dirs[1] + config_file_name, 'with:\n',
             config_file_content)
        write_yaml_file(config_file_path, config_file_content)
        return config_file_content
Exemple #4
0
    def generate_estimations(self, araw_action_counts, raw_ERT, output_path,
                             precision, raw_flattened_arch):
        print('\n=========================================')
        print('Generating energy estimation')
        print('=========================================')
        # load and parse access counts
        self.extract_ERT(raw_ERT['ERT'])
        self.construct_action_counts(araw_action_counts)
        self.decimal_points = precision
        if raw_flattened_arch is None:
            WARN(
                'flattened architecture is not given or --enable_flattened_arch not set high, will not perform legal component name check'
            )
        else:
            self.flattened_list = {}
            self.load_flattened_arch(
                raw_flattened_arch['flattened_architecture']['components'])

        for name, action_count_list in self.action_counts.items():
            INFO('processing for component:', name)
            # the components in the list are stored differently in ERT
            processed_name = self.process_name(name)
            component_ERT = self.energy_reference_table[processed_name]
            # generate the total energy for the component
            component_energy = self.process_component_action_counts(
                action_count_list, component_ERT)
            self.energy_estimation_table[name] = round(component_energy,
                                                       self.decimal_points)

        # save results
        file_path = output_path + '/estimation.yaml'
        write_yaml_file(
            file_path, {
                'energy_estimation': {
                    'components': self.energy_estimation_table,
                    'version': self.action_counts_version
                }
            })
        print(
            '---> Finished: energy calculation finished, estimation saved to:\n',
            os.path.abspath(output_path))
Exemple #5
0
    def generate_ERTs(self, raw_architecture_description,
                      raw_compound_class_description, output_path, precision,
                      flatten_arch_flag, verbose, show_ERT_summary):
        """
        main function to start the energy reference generator
        parses the input files
        produces the energy reference tables for components
        """
        print('\n=========================================')
        print('Generating energy reference tables')
        print('=========================================')

        # Interpret inputs
        self.verbose = verbose
        self.output_path = output_path
        self.decimal_place = precision
        self.flattened_arch = flatten_arch_flag
        self.show_ERT_summary = show_ERT_summary

        # Load accelergy config
        self.config = config_file_checker()

        # interpret the list of files
        # for file_path in path_arglist:
        #     self.interpret_input_path(file_path)
        #     INFO('Input file parsed: ', file_path)
        self.raw_architecture_description = raw_architecture_description[
            'architecture']
        self.raw_compound_class_description = raw_compound_class_description[
            'compound_components']

        # self.design = load(open(self.design_path), accelergy_loader)
        # INFO('design loaded:', design_path)
        self.construct_compound_class_description()

        # Load the primitive classes library
        self.construct_primitive_class_description()
        ASSERT_MSG(
            not len(self.primitive_class_description) == 0,
            'No primitive component class found, '
            'please check if the paths in config file are correct')

        # Parse the architecture description and save the parsed version if flag high
        self.construct_save_architecture_description()

        # Instantiate the estimation plug-ins as intances of the corresponding plug-in classes
        self.instantiate_estimator_plug_ins()
        ASSERT_MSG(
            not len(self.estimator_plug_ins) == 0,
            'No estimation plug-in found, '
            'please check if the paths in config file are correct')

        # Generate Energy Reference Tables for the components
        self.generate_ERTs_for_architecture()

        if self.flattened_arch or self.show_ERT_summary:
            self.generate_easy_to_read_flattened_architecture_ERT_summary()

        # Save the ERTs to ERT.yaml in the output directory
        ERT_file_path = self.output_path + '/' + 'ERT.yaml'
        ERT_dict = {
            'ERT': {
                'version': self.arch_version,
                'tables': self.energy_reference_table
            }
        }
        write_yaml_file(ERT_file_path, ERT_dict)
        print('---> Finished: ERT generation finished, ERT saved to:\n',
              os.path.abspath(output_path))
Exemple #6
0
    def generate_easy_to_read_flattened_architecture_ERT_summary(self):
        easy_to_read_flattened_architecture = {}
        list_names = {}
        ERT_summary = {}
        for component_name, component_info in self.architecture_description.items(
        ):

            if '[' not in component_name or ']' not in component_name:
                easy_to_read_flattened_architecture[component_name] = deepcopy(
                    component_info)
                if self.show_ERT_summary:
                    ERT_summary[component_name] = self.generate_ERT_summary(
                        component_name)
            else:
                name_base = EnergyReferenceTableGenerator.remove_brackets(
                    component_name)
                idx_list = []
                for match in re.finditer(r'\[\w+\]', component_name):
                    idx_list.append(
                        int(component_name[match.start() + 1:match.end() - 1]))
                if name_base not in list_names:
                    list_names[name_base] = {}
                    list_names[name_base]['format'] = []
                    parts = component_name.split('.')
                    for part_idx in range(len(parts)):
                        if '[' and ']' in parts[part_idx]:
                            list_names[name_base]['format'].append(part_idx)
                    list_names[name_base]['idx_list'] = idx_list
                else:
                    i = 0
                    for existing_idx in list_names[name_base]['idx_list']:
                        if idx_list[i] > existing_idx:
                            list_names[name_base]['idx_list'][i] = idx_list[i]
                        i += 1

        for name_base, list_info in list_names.items():
            ranged_name_list = name_base.split('.')
            max_name_list = name_base.split('.')
            for idx in range(len(list_info['format'])):
                range_location = list_info['format'][idx]
                range_max = list_info['idx_list'][idx]
                ranged_name_list[range_location] += '[0..' + str(
                    range_max) + ']'
                max_name_list[range_location] += '[' + str(range_max) + ']'
            sep = '.'
            ranged_name_str = sep.join(ranged_name_list)
            max_name_str = sep.join(max_name_list)
            easy_to_read_flattened_architecture[
                ranged_name_str] = self.architecture_description[max_name_str]
            if self.show_ERT_summary:

                ERT_summary[ranged_name_str] = self.generate_ERT_summary(
                    name_base)

        if self.show_ERT_summary:
            ERT_summary_file = {
                'ERT_summary': {
                    'version': self.compound_class_version,
                    'ERT summaries': ERT_summary
                }
            }
            write_yaml_file(self.output_path + '/ERT_summary.yaml',
                            ERT_summary_file)
            INFO('ERT summary saved to ',
                 self.output_path + '/ERT_summary.yaml')
        if self.flattened_arch:
            arch_file_path = self.output_path + '/' + 'flattened_architecture.yaml'
            flattened_architecture_yaml = {
                'flattened_architecture': {
                    'version': self.arch_version,
                    'components': easy_to_read_flattened_architecture
                }
            }
            write_yaml_file(arch_file_path, flattened_architecture_yaml)
            INFO('Architecture flattened ... saved to ', arch_file_path)