Пример #1
0
def update_output_params(ad_prog, \
                  output_entry):
  LOCS = []
  for block_name,loc,config in ad_prog.instances():
    handle = ad_prog.board.handle_by_inst(block_name,loc)
    if handle is None:
      continue

    for port,label,label_kind in config.labels():
      if label == output_entry.variable:
        LOCS.append((block_name,loc,port,handle))

  if len(LOCS) == 0:
    print(output_entry)
    raise Exception("cannot find measurement port")

  if (len(LOCS) > 1):
    raise Exception("more than one port with that label")

  block_name,loc,port,handle = LOCS[0]
  cfg = ad_prog.config(block_name,loc)
  dssim = DSProgDB.get_sim(output_entry.program)

  xform = output_entry.transform
  xform.handle = handle
  xform.time_constant = ad_prog.board.time_constant
  xform.legno_ampl_scale = cfg.scf(port)
  xform.legno_time_scale = ad_prog.tau
  output_entry.transform = xform

  runtime = dssim.sim_time/(xform.time_constant*xform.legno_time_scale)
  output_entry.runtime = runtime
Пример #2
0
def simulate(args):
    import hwlib.hcdc.hwenvs as hwenvs
    from hwlib.hcdc.hcdcv2_4 import make_board
    from hwlib.hcdc.globals import HCDCSubset
    dssim = DSProgDB.get_sim(args.program)
    path_handler = paths.PathHandler(args.subset, args.program)

    if args.reference:
        ref_prog = DSProgDB.get_prog(args.program)
        if args.runtime:
            result = ref_prog.execute_and_profile(dssim)
            print("runtime: %e seconds" % result)
        else:
            plot_reference_simulation(path_handler, ref_prog, dssim)

    if args.adp:
        board = make_board(HCDCSubset(args.subset), \
                                  load_conns=False)
        adp = AnalogDeviceProg.read(board, args.adp)
        init_conds,derivs =  \
                            buildsim.build_simulation(board, \
                                                      adp,
                                                      args.mode)
        V,T,Y = run_adp_simulation(board, \
                                   adp, \
                                   init_conds, \
                                   derivs, \
                                   dssim)
        plot_adp_simulation(path_handler, dssim, args.adp, V, T, Y)
Пример #3
0
def simulate_reference(dev, prog, plot_file, separate_figures=False):
    dssim = DSProgDB.get_sim(prog.name)
    T, Z = prog.execute(dssim)
    if separate_figures:
        plot_separate_simulations(T, Z, plot_file)
    else:
        plot_simulation(T, Z, plot_file)
Пример #4
0
def reference_waveform(adp, waveform):
    program = DSProgDB.get_prog(adp.metadata[ADPMetadata.Keys.DSNAME])
    dssim = DSProgDB.get_sim(program.name)
    dsinfo = DSProgDB.get_info(program.name)
    ref_waveforms = get_reference_waveforms(program, dssim)

    reference = ref_waveforms[waveform.variable]
    return program, dsinfo, dssim, reference
Пример #5
0
def print_summary(dev, adp, rmse):
    program = DSProgDB.get_prog(adp.metadata[ADPMetadata.Keys.DSNAME])
    dssim = DSProgDB.get_sim(program.name)
    dsinfo = DSProgDB.get_info(program.name)

    runtime = dev.time_constant / adp.tau * dssim.sim_time
    bandwidth = (1.0 / dev.time_constant) * adp.tau
    power = energymodel.compute_power(adp, bandwidth)
    energy = runtime * power

    print("--------    general -------------")
    print("runtime = %f ms" % (runtime * 1000))
    print("power    = %f mW" % (power * 1e3))
    print("energy  = %f uJ" % (energy * 1e6))
    print("quality = %f %%" % rmse)

    print("------------ metadata ----------------")
    print(adp.metadata)
    print("------------ lgraph ----------------")
    by_block = {'fanout':[],'adc':[],'dac':[],'mult':[], 'integ':[], \
                'extout':[],'extin':[],'cin':[],'cout':[],'tin':[],'tout':[]}

    total_blocks = 0
    for cfg in adp.configs:
        if cfg.inst.block in by_block:
            by_block[cfg.inst.block].append(cfg.mode)
        total_blocks += 1

    total_conns = len(list(adp.conns))

    for block_name, modes in by_block.items():
        if len(modes) > 0:
            print("%s = %d modes=%s" % (block_name, len(modes), set(modes)))

    print("total blocks = %d" % total_blocks)
    print("total conns = %d" % total_conns)

    print("------------ lscale  ----------------")
    scale_factors = []
    injected_vars = []
    for cfg in adp.configs:
        for stmt in cfg.stmts:
            if stmt.type == adplib.ConfigStmtType.CONSTANT:
                scale_factors.append(stmt.scf)
            if stmt.type == adplib.ConfigStmtType.PORT:
                scale_factors.append(stmt.scf)
            if stmt.type == adplib.ConfigStmtType.EXPR:
                for scf in stmt.scfs:
                    scale_factors.append(scf)
                for inj in stmt.injs:
                    injected_vars.append(inj)

    print("tau=%f" % (adp.tau))
    print("scf total = %d" % len(scale_factors))
    print("scf uniq = %d" % len(set(scale_factors)))
    print("inj total = %d" % len(injected_vars))
    print("inj uniq = %d" % len(set(injected_vars)))
Пример #6
0
def visualize(db):
    header = [
        'description', 'observation', 'time', 'diffeqs', 'funcs', 'nonlinear'
    ]
    desc = 'dynamical system benchmarks used in evaluation. $\dagger$ these benchmarks '
    table = common.Table('Benchmarks', desc, 'bmarksumm', '|c|lccccc|')
    table.two_column = True
    bool_to_field = {True: 'yes', False: 'no'}
    table.set_fields(header)
    table.horiz_rule()
    table.header()
    table.horiz_rule()
    for bmark in table.benchmarks():
        bmark_name = bmark
        if 'heat1d' in bmark:
            bmark_name = 'heat1d'

        if not DSProgDB.has_prog(bmark):
            print("skipping %s... no info" % bmark)
            continue

        info = DSProgDB.get_info(bmark)
        prog = DSProgDB.get_prog(bmark)
        dssim = DSProgDB.get_sim(bmark)
        n_diffeqs = 0
        n_funcs = 0
        for v, bnd in prog.bindings():
            if bnd.op == op.OpType.INTEG:
                n_diffeqs += 1
            else:
                n_funcs += 1
        print(info)
        entry = {
            'description': info.description,
            'observation': info.observation,
            'diffeqs': n_diffeqs,
            'funcs': n_funcs,
            'time': str(dssim.sim_time) + " su",
            'nonlinear': bool_to_field[info.nonlinear]
        }
        table.data(bmark, entry)
    table.horiz_rule()

    table.write(common.get_path('bmarks.tbl'))
Пример #7
0
def simulate_adp(dev,adp,plot_file, \
                 enable_model_error=True, \
                 enable_physical_model=True, \
                 enable_intervals=True, \
                 enable_quantization=True, \
                 separate_figures=False):
    print(adp.metadata)
    prog = adp.metadata[adplib.ADPMetadata.Keys.DSNAME]
    dssim = DSProgDB.get_sim(prog)
    dev.model_number = adp.metadata[adplib.ADPMetadata.Keys.RUNTIME_PHYS_DB]
    times,values = run_adp_simulation(dev, \
                                      adp,
                                      dssim, \
                                      enable_model_error=enable_model_error, \
                                      enable_physical_model=enable_physical_model, \
                                      enable_quantization=enable_quantization)
    if separate_figures:
        plot_separate_simulations(times, values, plot_file)
    else:
        plot_simulation(times, values, plot_file)
Пример #8
0
def update_experiment_params(ad_prog,exper_entry):
  dssim = DSProgDB.get_sim(exper_entry.program)
  tc = ad_prog.board.time_constant*ad_prog.tau
  runtime = dssim.sim_time/tc
  exper_entry.runtime = runtime