Example #1
0
def main():

    parser = argparse.ArgumentParser()
    parser.add_argument('design_path',
                        type=str,
                        help='path to input file design.yaml')
    parser.add_argument('action_counts_path',
                        type=str,
                        help='path to input file action_counts.yaml')
    parser.add_argument('-o',
                        '--outdir',
                        type=str,
                        default='./',
                        help='optional path to output directory')
    parser.add_argument('-p',
                        '--precision',
                        type=int,
                        default='3',
                        help='number of decimal points for energy values')

    args = parser.parse_args()
    design_path = args.design_path
    action_counts_path = args.action_counts_path
    output_path = args.outdir
    precision = args.precision

    generator = EnergyReferenceTableGenerator()
    generator.generate_ERTs(design_path, output_path, precision)

    ert_path = output_path + '/' + 'ERT.yaml'
    estimator = EnergyCalculator()
    estimator.generate_estimations(action_counts_path, ert_path, output_path,
                                   precision)
def main():

    parser = argparse.ArgumentParser()
    parser.add_argument('design_path',
                        type=str,
                        help='path to input file design.yaml')
    parser.add_argument('-o',
                        '--outdir',
                        type=str,
                        default='./',
                        help='optional path to output directory')
    parser.add_argument('-p',
                        '--precision',
                        type=int,
                        default='3',
                        help='number of decimal points for energy values')
    parser.add_argument(
        '--enable_flattened_arch',
        type=int,
        default='0',
        help=
        'enable Accelergy to show the flattened architecture interpretation')

    args = parser.parse_args()
    design_path = args.design_path
    output_path = args.outdir
    precision = args.precision
    flatten_arch_flag = args.enable_flattened_arch

    generator = EnergyReferenceTableGenerator()
    generator.generate_ERTs(design_path, output_path, precision,
                            flatten_arch_flag)
Example #3
0
def main():

    parser = argparse.ArgumentParser(
        description=
        'Accelergy is an architecture-level energy estimator for accelerator designs. Accelergy allows '
        ' users to describe the architecture of a design with user-defined compound components and generates energy '
        'estimations according to the workload-generated action counts.')
    parser.add_argument(
        '-o',
        '--outdir',
        type=str,
        default='./',
        help='Path to output directory that stores '
        'the ERT and/or flattened_architecture and/or energy estimation. '
        'Default is current directory.')
    parser.add_argument(
        '-p',
        '--precision',
        type=int,
        default='3',
        help='Number of decimal points for generated energy values. '
        'Default is 3.')
    parser.add_argument(
        '-v',
        '--verbose',
        type=int,
        default=0,
        help=
        'If set to 1, Accelergy outputs the interactions between the estimation plug-ins. '
        'Default is 0')
    parser.add_argument(
        '-s',
        '--ERT_summary',
        type=int,
        default=1,
        help='If set to 1, Accelergy outputs an easy-to-read '
        'ERT summary that contains the average, min and max energy/action'
        'for all the actions of all the components. '
        'Default is 1')
    parser.add_argument(
        '--enable_flattened_arch',
        type=int,
        default='0',
        help=
        'If set to 1, Accelergy outputs an architecture summary in the output directory and checks'
        ' the validity of component names in the action counts file. '
        'The flattened architecture includes all the interpreted attribute values and classes '
        'for all the components in the design. '
        'Default is 0.')

    parser.add_argument(
        'files',
        nargs='*',
        help='list of input files in arbitrary order.'
        'Accelergy parses the top keys of the files to decide the type of input the file describes, '
        'e.g., architecture description, '
        'compound component class descriptions, etc. ')

    args = parser.parse_args()
    path_arglist = args.files
    output_path = args.outdir
    precision = args.precision
    verbose = args.verbose
    flatten_arch_flag = args.enable_flattened_arch
    ERT_summary = args.ERT_summary

    print(
        '\n#===================================================================================#'
    )
    print(
        '#=========================== Running Accelergy =====================================#'
    )
    print(
        '#===================================================================================#\n'
    )

    raw_architecture_description, \
    raw_compound_class_description,\
    raw_action_counts,\
    raw_ERT,\
    raw_flattened_arch = interpret_input_path(path_arglist)
    INFO('Summary of collected inputs:'
         '\n   Architecture description found: %s '
         '\n   Compound component description found: %s '
         '\n   Action counts found: %s'
         '\n   ERT found: %s '
         '\n   Flattened architecture found: %s' %
         (raw_architecture_description is not None,
          raw_compound_class_description is not None, raw_action_counts
          is not None, raw_ERT is not None, raw_flattened_arch is not None))

    if raw_ERT is not None and raw_action_counts is not None:
        INFO('Accelergy found ERT and ACTION COUNTS '
             '\n----------> DIRECTLY PERFORM ENERGY ESTIMATION')
        if flatten_arch_flag == 0:
            raw_flattened_arch = None
        else:
            if raw_flattened_arch is None:
                ERROR_CLEAN_EXIT(
                    'enable_flattened_arch flag is set high, '
                    'but no flattened architecture yaml file provided')
        estimator = EnergyCalculator()
        estimator.generate_estimations(raw_action_counts, raw_ERT, output_path,
                                       precision, raw_flattened_arch)

    elif raw_compound_class_description is not None and raw_architecture_description is not None:
        if raw_action_counts is None:
            INFO(
                'Accelergy found ARCHITECTURE and COMPOUND COMPONENT but NO ERT or ACTION COUNTS  '
                '\n---------->  PERFORM ERT GENERATION')
        else:
            INFO(
                'Accelergy found ARCHITECTURE, COMPOUND COMPONENT, and ACTION COUNTS but NO ERT  '
                '\n----------> PERFORM ERT GENERATION AND ENERGY ESTIMATION')

        generator = EnergyReferenceTableGenerator()
        generator.generate_ERTs(raw_architecture_description,
                                raw_compound_class_description, output_path,
                                precision, flatten_arch_flag, verbose,
                                ERT_summary)

        if raw_action_counts is not None:
            ert_path = output_path + '/' + 'ERT.yaml'
            raw_ERT = load(open(ert_path), accelergy_loader)
            if flatten_arch_flag == 0:
                raw_flattened_arch = None
            else:
                arch_path = output_path + '/' + 'flattened_architecture.yaml'
                raw_flattened_arch = load(open(arch_path), accelergy_loader)
            estimator = EnergyCalculator()
            estimator.generate_estimations(raw_action_counts, raw_ERT,
                                           output_path, precision,
                                           raw_flattened_arch)
    else:
        INFO('Not enough inputs to start computations. ')
Example #4
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)