Example #1
0
def profile_adp(args):
    board = runtime_util.get_device(args.model_number)
    calib_obj = llenums.CalibrateObjective(args.method)
    runtime = GrendelRunner()

    runtime.initialize()
    if args.missing:
        for exp_delta_model in delta_model_lib.get_all(board):
            profile_kernel(runtime,board, \
                           exp_delta_model.block, \
                           exp_delta_model.config, \
                           calib_obj, \
                           min_points=args.min_points, \
                           grid_size=args.grid_size)

    else:
        adp = runtime_util.get_adp(board, args.adp, widen=args.widen)
        for cfg in adp.configs:
            blk = board.get_block(cfg.inst.block)
            cfg_modes = cfg.modes
            for mode in cfg_modes:
                cfg.modes = [mode]
                profile_kernel(runtime,board,blk,cfg,calib_obj, \
                               args.min_points, args.max_points, \
                               args.grid_size, \
                               force=args.force, adp=adp)
Example #2
0
def make_histogram(args):
    board = runtime_util.get_device(args.model_number,layout=True)
    ph = paths.DeviceStatePathHandler(board.name, \
                                  board.model_number,make_dirs=True)

    models = {}
    for exp_model in delta_model_lib.get_all(board):
        key = (exp_model.block, exp_model.output,\
               runtime_util.get_static_cfg(exp_model.block,exp_model.config), \
               exp_model.calib_obj)
        if not key in models:
            models[key] = []
        models[key].append(exp_model)

    for key,models in models.items():
        blk,out,cfg,lbl = key
        print("%s:%s = %d models" % (blk.name,cfg,len(models)))
        png_file = ph.get_histogram_vis('merr', \
                                        blk.name, \
                                        out.name, \
                                        cfg, \
                                        lbl)
        vizlib.model_error_histogram(models, \
                                     png_file, \
                                     num_bins=10, \
                                     relative=True)

        png_file = ph.get_histogram_vis('objf', \
                                        blk.name, \
                                        out.name, \
                                        cfg, \
                                        lbl)
        vizlib.objective_fun_histogram(models, \
                                       png_file, \
                                       num_bins=10)
def preprocess_board_data(board):
    def insert(d,ks):
            for k in ks:
                if not k in d:
                    d[k] = {}
                d = d[k]

    datasets = {}
    models = {}

    for model in exp_delta_model_lib.get_all(board):
        keypath = [(model.block.name, str(model.config.mode),model.output.name), \
                   model.loc]
        insert(models,keypath)
        insert(datasets,keypath)
        models[keypath[0]][keypath[1]][model.hidden_cfg] = model
        datasets[keypath[0]][keypath[1]][model.hidden_cfg] = None

    for data in exp_profile_dataset_lib.get_all(board):
        keypath = [(data.block.name, str(data.config.mode),data.output.name), \
                   data.loc]
        insert(datasets,keypath)
        datasets[keypath[0]][keypath[1]][data.hidden_cfg] = data

    return models,datasets
def update_predictor(predictor,char_board):
     for model in exp_delta_model_lib.get_all(char_board):
        for var,val in model.variables().items():
            predictor.data.add_datapoint(model.output, var,  \
                                         dict(model.hidden_codes()), val)


     predictor.fit()
def group_by_configured_block(board):
    instances = {}
    for model in exp_delta_model_lib.get_all(board):
        key = (model.block.name, \
               str(model.loc), \
               model.static_cfg)
        if not key in instances:
            instances[key] = []

        instances[key].append(model)

    return instances.values()
def load_code_pool_from_database(char_board,predictor,objectives):
    hidden_codes = list(map(lambda st: st.name, \
                            runtime_util.get_hidden_codes(predictor.block)))
    code_pool= poollib.HiddenCodePool(hidden_codes,predictor,objectives)
    # setting ranges of values in code pool
    for hc in hidden_codes:
        vals  = predictor.block.state[hc].values
        code_pool.set_range(hc,vals)

    by_output = {}
    print("===== Database Models ====")
    for mdl in exp_delta_model_lib.get_all(char_board):
        print(mdl)
        insert_into_dict(by_output, [mdl.hidden_cfg], mdl)

    print("===== Initial Code Pool ====")
    for _,mdls in by_output.items():
        if any(map(lambda mdl: not mdl.complete, mdls)):
           continue

        codes = dict(mdls[0].hidden_codes())
        pred_deltavars,_ = code_pool.predictor.predict(codes)
        pred_obj = code_pool.objectives.compute(pred_deltavars)
        vs = {}
        for mdl in mdls:
            vs[mdl.output.name] = mdl.variables()

        actual_obj = code_pool.objectives.compute(vs)

        print("hist %s" % (codes))
        for (_,expr),pred,act in zip(code_pool.objectives,pred_obj,actual_obj):
            print("  obj=%s pred=%f meas=%f" % (expr,pred,act))

        if not code_pool.has_code(codes):
           code_pool .add_labeled_code(codes,vs)

    print("==== pool (best to worst) ====")
    print(predictor.config)
    print("")
    for fxn,score in code_pool.meas_view.order_by_dominance():
        print("%s  result=%s" % (fxn,score))

    return code_pool
Example #7
0
def visualize(args):
    board = runtime_util.get_device(args.model_number,layout=True)
    calib_obj = llenums.CalibrateObjective(args.calib_obj) if args.calib_obj else None
    ph = paths.DeviceStatePathHandler(board.name, \
                                      board.model_number,make_dirs=True)
    if args.histogram:
        make_histogram(args)

    for delta_model in delta_model_lib.get_all(board):
        if not calib_obj is None and delta_model.calib_obj != calib_obj:
            continue

        if delta_model.complete and \
           delta_model.calib_obj != llenums.CalibrateObjective.NONE:

            print(delta_model.config)
            print(delta_model)
            if delta_model.is_integration_op:
                dataset = dataset_lib.load(board, delta_model.block, \
                                           delta_model.loc, \
                                           delta_model.output, \
                                           delta_model.config, \
                                           llenums.ProfileOpType.INTEG_INITIAL_COND)
            else:
                dataset = dataset_lib.load(board, delta_model.block, \
                                           delta_model.loc, \
                                           delta_model.output, \
                                           delta_model.config, \
                                           llenums.ProfileOpType.INPUT_OUTPUT)

            if dataset is None:
                print("-> no dataset")
                continue

            assert(isinstance(dataset, dataset_lib.ExpProfileDataset))
            png_file = ph.get_delta_vis(delta_model.block.name, \
                                        delta_model.loc.file_string(),\
                                        str(delta_model.output.name), \
                                        str(delta_model.static_cfg), \
                                        str(delta_model.hidden_cfg), \
                                        delta_model.calib_obj)
            print(png_file)
            vizlib.deviation(delta_model, \
                             dataset, \
                             png_file, \
                             baseline=vizlib.ReferenceType.MODEL_PREDICTION, \
                             num_bins=10, \
                             amplitude=args.max_error, \
                             relative=not args.absolute)

            png_file = ph.get_correctable_delta_vis(delta_model.block.name, \
                                                    delta_model.loc.file_string(), \
                                                    str(delta_model.output.name), \
                                                    str(delta_model.static_cfg), \
                                                    str(delta_model.hidden_cfg), \
                                                    delta_model.calib_obj)
            print(png_file)
            vizlib.deviation(delta_model, \
                             dataset, \
                             png_file, \
                             baseline=vizlib.ReferenceType.CORRECTABLE_MODEL_PREDICTION, \
                             num_bins=10, \
                             amplitude=args.max_error, \
                             relative=not args.absolute)

            model_file = ph.get_model_file(delta_model.block.name, \
                                           delta_model.loc.file_string(), \
                                           str(delta_model.output.name), \
                                           str(delta_model.static_cfg), \
                                           str(delta_model.hidden_cfg), \
                                           delta_model.calib_obj)

            with open(model_file,'w') as fh:
                fh.write(str(delta_model.config))
                fh.write(str(delta_model))
                fh.write("\n\n")
                fh.write(str(delta_model.spec))
Example #8
0
def homogenous_database_get_block_info(board, use_output=True):
    models = list(exp_delta_model_lib.get_all(board))
    return models_get_block_info(models, use_output)
Example #9
0
def homogenous_database_get_calibration_objective_scores(board):
    all_models = list(exp_delta_model_lib.get_all(board))
    for models, score in get_calibration_objective_scores(all_models):
        yield models, score
Example #10
0
def database_is_homogenous(board, enable_outputs=False):
    models = list(exp_delta_model_lib.get_all(board))
    return models_are_homogenous(models, \
                                 enable_outputs=enable_outputs)
Example #11
0
def database_is_empty(board):
    for model in exp_delta_model_lib.get_all(board):
        return False
    return True