Example #1
0
def build_interpolate(app_data, g_size = None, t_size = None):
    pipe_data = app_data['pipe_data']
    
    out_interpolate = interpolate(pipe_data)
    
    R = pipe_data['R']
    C = pipe_data['C']

    live_outs = [out_interpolate]
    pipe_name = app_data['app']

    rows = app_data['R']-2
    cols = app_data['C']-2

    p_estimates = [(R, rows), (C, cols)]
    p_constraints = [ Condition(R, "==", rows), \
                      Condition(C, "==", cols) ]
    if (t_size == None):
	    t_size = [4, 64, 128]
    if (g_size == None):
        g_size = 4
 
    opts = []
    if app_data['early_free']:
        opts += ['early_free']
    if app_data['optimize_storage']:
        opts += ['optimize_storage']
    if app_data['pool_alloc']:
        opts += ['pool_alloc']
    if app_data['multi-level-tiling']:
        opts += ['multi-level-tiling']
    if app_data['dpfuse']:
        opts += ['dpfuse']
    if app_data['logdpchoices']:
        opts += ['logdpchoices']
    if app_data['logmaxchildren']:
        logmaxchildren = app_data['logmaxchildren']

    pipe = buildPipeline(live_outs,
                         param_estimates=p_estimates,
                         param_constraints=p_constraints,
                         tile_sizes = t_size,
                         group_size = g_size,
                         options = opts,
                         pipe_name = pipe_name,
                         logMaxChildren = logmaxchildren)

    return pipe
Example #2
0
def build_interpolate(app_data):
    pipe_data = app_data['pipe_data']
    
    out_interpolate = interpolate(pipe_data)
    
    R = pipe_data['R']
    C = pipe_data['C']

    live_outs = [out_interpolate]
    pipe_name = app_data['app']

    rows = app_data['R']-2
    cols = app_data['C']-2

    p_estimates = [(R, rows), (C, cols)]
    p_constraints = [ Condition(R, "==", rows), \
                      Condition(C, "==", cols) ]
    t_size = [16, 16]
    g_size = 11
    opts = []
    if app_data['early_free']:
        opts += ['early_free']
    if app_data['optimize_storage']:
        opts += ['optimize_storage']
    if app_data['pool_alloc']:
        opts += ['pool_alloc']

    pipe = buildPipeline(live_outs,
                         param_estimates=p_estimates,
                         param_constraints=p_constraints,
                         tile_sizes = t_size,
                         group_size = g_size,
                         options = opts,
                         pipe_name = pipe_name)

    return pipe
Example #3
0
def build_interpolate(app_data):
    pipe_data = app_data['pipe_data']

    out_interpolate = interpolate(pipe_data)

    R = pipe_data['R']
    C = pipe_data['C']

    live_outs = [out_interpolate]
    pipe_name = app_data['app']

    rows = app_data['R'] - 2
    cols = app_data['C'] - 2

    p_estimates = [(R, rows), (C, cols)]
    p_constraints = [ Condition(R, "==", rows), \
                      Condition(C, "==", cols) ]
    t_size = [16, 16]
    g_size = 11
    opts = []
    if app_data['early_free']:
        opts += ['early_free']
    if app_data['optimize_storage']:
        opts += ['optimize_storage']
    if app_data['pool_alloc']:
        opts += ['pool_alloc']

    pipe = buildPipeline(live_outs,
                         param_estimates=p_estimates,
                         param_constraints=p_constraints,
                         tile_sizes=t_size,
                         group_size=g_size,
                         options=opts,
                         pipe_name=pipe_name)

    return pipe
Example #4
0
    def rec_v_cycle(v, f, l):

        # coarsest level
        if l == 0:
            ''' COARSE-SMOOTHING '''
            if nuc == 0:
                return v

            smooth_p1[l] = {}
            for t in range(0, nuc):
                if l == L and t == nuc-1:
                    fname = app_data['cycle_name']
                else:
                    fname = "T"+str(t)+"_coarse"

                if t == 0:
                    in_func = v
                else:
                    in_func = smooth_p1[l][t-1]

                smooth_p1[l][t] = w_jacobi(in_func, f, l, fname, app_data)

            return smooth_p1[l][nuc-1]
        ###################################################
        # all other finer levels
        else:
            ''' PRE-SMOOTHING '''
            smooth_p1[l] = {}
            for t in range(0, nu1):
                fname = "T"+str(t)+"_pre_L"+str(l)
                if t == 0:
                    in_func = v
                else:
                    in_func = smooth_p1[l][t-1]

                smooth_p1[l][t] = w_jacobi(in_func, f, l, fname, app_data)

            if nu1 <= 0:
                smooth_out = v
            else:
                smooth_out = smooth_p1[l][nu1-1]

            ###############################################
            ''' RESIDUAL '''

            r_h[l] = defect(smooth_out, f, l, "defect_L"+str(l),
                            pipe_data)

            ###############################################
            ''' RESTRICTION '''
            r_2h[l] = restrict(r_h[l], l, "restrict_L"+str(l-1), pipe_data)

            ###############################################
 
            ''''''''''''''''''
            ''' NEXT LEVEL '''
            ''''''''''''''''''
            # e_2h <- 0
            e_2h[l] = rec_v_cycle(None, r_2h[l], l-1)

            ###############################################

            ''' INTERPOLATION & CORRECTION '''
            if l == L and nu2 <= 0:
                fname = app_data['cycle_name']
            else:
                fname = "interp_correct_L"+str(l)

            if nu1 <= 0:
                correct_in = v
            else:
                correct_in = smooth_p1[l][nu1-1]

            ec[l] = interpolate(e_2h[l], correct_in, l, fname, pipe_data)

            if nu2 <= 0:
                return ec[l]
 
            ###############################################

            ''' POST-SMOOTHING '''
            smooth_p2[l] = {}
            for t in range(0, nu2):
                fname = "T"+str(t)+"_post_L"+str(l)
                if l == L and t == nu2-1:
                    fname = app_data['cycle_name']

                if t == 0:
                    in_func = ec[l]
                else:
                    in_func = smooth_p2[l][t-1]

                smooth_p2[l][t] = w_jacobi(in_func, f, l, fname, app_data)
 
            return smooth_p2[l][nu2-1]
    def rec_w_cycle(v, f, l, visit):

        visit[l] += 1

        # coarsest level
        if l == 0:
            ''' COARSE-SMOOTHING '''
            if nuc == 0:
                return v

            if visit[l] == 1:
                smooth_p1[l] = {}

            smooth_p1[l][visit[l]] = {}

            for t in range(0, nuc):
                if l == L and t == nuc - 1:
                    fname = "Wcycle"
                else:
                    fname = "T" + str(t) + "_coarse" + "__" + str(visit[l])

                if t == 0:
                    in_func = v
                else:
                    in_func = smooth_p1[l][visit[l]][t - 1]

                smooth_p1[l][visit[l]][t] = \
                    w_jacobi(in_func, f, l, fname, app_data)

            return smooth_p1[l][visit[l]][nuc - 1]
        ###################################################
        # all other finer levels
        else:
            ''' PRE-SMOOTHING '''
            if visit[l] == 1:
                smooth_p1[l] = {}

            smooth_p1[l][visit[l]] = {}

            for t in range(0, nu1):
                fname = "T" + str(t) + "_pre_L" + str(l) + "__" + str(visit[l])
                if t == 0:
                    in_func = v
                else:
                    in_func = smooth_p1[l][visit[l]][t - 1]

                smooth_p1[l][visit[l]][t] = \
                    w_jacobi(in_func, f, l, fname, app_data)

            if nu1 <= 0:
                smooth_out = v
            else:
                smooth_out = smooth_p1[l][visit[l]][nu1 - 1]

            ###############################################
            ''' RESIDUAL '''

            if visit[l] == 1:
                r_h[l] = {}

            name = "defect_L" + str(l) + "__" + str(visit[l])
            r_h[l][visit[l]] = defect(smooth_out, f, l, name, pipe_data)

            ###############################################
            ''' RESTRICTION '''
            if visit[l] == 1:
                r_2h[l] = {}

            name = "restrict_L" + str(l - 1) + "__" + str(visit[l])
            r_2h[l][visit[l]] = restrict(r_h[l][visit[l]], l, name, pipe_data)

            ###############################################
            '''''' '''''' ''''''
            ''' NEXT LEVEL '''
            '''''' '''''' ''''''

            if visit[l] == 1:
                e_2h[l] = {}

            # e_2h <- 0
            e_2h[l][visit[l]] = \
                rec_w_cycle(None, r_2h[l][visit[l]], l-1, visit)

            e_2h[l][visit[l]] = \
                rec_w_cycle(e_2h[l][visit[l]], r_2h[l][visit[l]], l-1, visit)

            ###############################################
            ''' INTERPOLATION & CORRECTION '''
            if l == L and nu2 <= 0:
                fname = "Wcycle"
            else:
                fname = "interp_correct_L" + str(l) + "__" + str(visit[l])

            if nu1 <= 0:
                correct_in = v
            else:
                correct_in = smooth_p1[l][visit[l]][nu1 - 1]

            if visit[l] == 1:
                ec[l] = {}

            ec[l][visit[l]] = \
                interpolate(e_2h[l][visit[l]], correct_in, l, fname, pipe_data)

            if nu2 <= 0:
                return ec[l][visit[l]]

            ###############################################
            ''' POST-SMOOTHING '''

            if visit[l] == 1:
                smooth_p2[l] = {}

            smooth_p2[l][visit[l]] = {}
            for t in range(0, nu2):
                fname = "T" + str(t) + "_post_L" + str(l) + "__" + str(
                    visit[l])
                if l == L and t == nu2 - 1:
                    fname = "Wcycle"

                if t == 0:
                    in_func = ec[l][visit[l]]
                else:
                    in_func = smooth_p2[l][visit[l]][t - 1]

                smooth_p2[l][visit[l]][t] = \
                    w_jacobi(in_func, f, l, fname, app_data)

            return smooth_p2[l][visit[l]][nu2 - 1]
Example #6
0
    def rec_v_cycle(v, f, l):

        # coarsest level
        if l == 0:
            ''' COARSE-SMOOTHING '''
            if nuc == 0:
                return v

            smooth_p1[l] = {}
            for t in range(0, nuc):
                if l == L and t == nuc - 1:
                    fname = app_data['cycle_name']
                else:
                    fname = "T" + str(t) + "_coarse"

                if t == 0:
                    in_func = v
                else:
                    in_func = smooth_p1[l][t - 1]

                smooth_p1[l][t] = w_jacobi(in_func, f, l, fname, app_data)

            return smooth_p1[l][nuc - 1]
        ###################################################
        # all other finer levels
        else:
            ''' PRE-SMOOTHING '''
            smooth_p1[l] = {}
            for t in range(0, nu1):
                fname = "T" + str(t) + "_pre_L" + str(l)
                if t == 0:
                    in_func = v
                else:
                    in_func = smooth_p1[l][t - 1]

                smooth_p1[l][t] = w_jacobi(in_func, f, l, fname, app_data)

            if nu1 <= 0:
                smooth_out = v
            else:
                smooth_out = smooth_p1[l][nu1 - 1]

            ###############################################
            ''' RESIDUAL '''

            r_h[l] = defect(smooth_out, f, l, "defect_L" + str(l), pipe_data)

            ###############################################
            ''' RESTRICTION '''
            r_2h[l] = restrict(r_h[l], l, "restrict_L" + str(l - 1), pipe_data)

            ###############################################
            '''''' '''''' ''''''
            ''' NEXT LEVEL '''
            '''''' '''''' ''''''
            # e_2h <- 0
            e_2h[l] = rec_v_cycle(None, r_2h[l], l - 1)

            ###############################################
            ''' INTERPOLATION & CORRECTION '''
            if l == L and nu2 <= 0:
                fname = app_data['cycle_name']
            else:
                fname = "interp_correct_L" + str(l)

            if nu1 <= 0:
                correct_in = v
            else:
                correct_in = smooth_p1[l][nu1 - 1]

            ec[l] = interpolate(e_2h[l], correct_in, l, fname, pipe_data)

            if nu2 <= 0:
                return ec[l]

            ###############################################
            ''' POST-SMOOTHING '''
            smooth_p2[l] = {}
            for t in range(0, nu2):
                fname = "T" + str(t) + "_post_L" + str(l)
                if l == L and t == nu2 - 1:
                    fname = app_data['cycle_name']

                if t == 0:
                    in_func = ec[l]
                else:
                    in_func = smooth_p2[l][t - 1]

                smooth_p2[l][t] = w_jacobi(in_func, f, l, fname, app_data)

            return smooth_p2[l][nu2 - 1]
Example #7
0
    def rec_w_cycle(v, f, l, visit):

        visit[l] += 1

        # coarsest level
        if l == 0:
            ''' COARSE-SMOOTHING '''
            if nuc == 0:
                return v

            if visit[l] == 1:
                smooth_p1[l] = {}

            smooth_p1[l][visit[l]] = {}

            for t in range(0, nuc):
                if l == L and t == nuc-1:
                    fname = "Wcycle"
                else:
                    fname = "T"+str(t)+"_coarse"+"__"+str(visit[l])

                if t == 0:
                    in_func = v
                else:
                    in_func = smooth_p1[l][visit[l]][t-1]

                smooth_p1[l][visit[l]][t] = \
                    w_jacobi(in_func, f, l, fname, app_data)

            return smooth_p1[l][visit[l]][nuc-1]
        ###################################################
        # all other finer levels
        else:
            ''' PRE-SMOOTHING '''
            if visit[l] == 1:
                smooth_p1[l] = {}

            smooth_p1[l][visit[l]] = {}

            for t in range(0, nu1):
                fname = "T"+str(t)+"_pre_L"+str(l)+"__"+str(visit[l])
                if t == 0:
                    in_func = v
                else:
                    in_func = smooth_p1[l][visit[l]][t-1]

                smooth_p1[l][visit[l]][t] = \
                    w_jacobi(in_func, f, l, fname, app_data)

            if nu1 <= 0:
                smooth_out = v
            else:
                smooth_out = smooth_p1[l][visit[l]][nu1-1]

            ###############################################
            ''' RESIDUAL '''

            if visit[l] == 1:
                r_h[l] = {}

            name = "defect_L"+str(l)+"__"+str(visit[l])
            r_h[l][visit[l]] = defect(smooth_out, f, l, name, pipe_data)

            ###############################################
  
            ''' RESTRICTION '''
            if visit[l] == 1:
                r_2h[l] = {}

            name = "restrict_L"+str(l-1)+"__"+str(visit[l])
            r_2h[l][visit[l]] = restrict(r_h[l][visit[l]], l, name, pipe_data)

            ###############################################
 
            ''''''''''''''''''
            ''' NEXT LEVEL '''
            ''''''''''''''''''

            if visit[l] == 1:
                e_2h[l] = {}

            # e_2h <- 0
            e_2h[l][visit[l]] = \
                rec_w_cycle(None, r_2h[l][visit[l]], l-1, visit)

            e_2h[l][visit[l]] = \
                rec_w_cycle(e_2h[l][visit[l]], r_2h[l][visit[l]], l-1, visit)

            ###############################################

            ''' INTERPOLATION & CORRECTION '''
            if l == L and nu2 <= 0:
                fname = "Wcycle"
            else:
                fname = "interp_correct_L"+str(l)+"__"+str(visit[l])

            if nu1 <= 0:
                correct_in = v
            else:
                correct_in = smooth_p1[l][visit[l]][nu1-1]

            if visit[l] == 1:
                ec[l] = {}

            ec[l][visit[l]] = \
                interpolate(e_2h[l][visit[l]], correct_in, l, fname, pipe_data)

            if nu2 <= 0:
                return ec[l][visit[l]]
 
            ###############################################

            ''' POST-SMOOTHING '''

            if visit[l] == 1:
                smooth_p2[l] = {}

            smooth_p2[l][visit[l]] = {}
            for t in range(0, nu2):
                fname = "T"+str(t)+"_post_L"+str(l)+"__"+str(visit[l])
                if l == L and t == nu2-1:
                    fname = "Wcycle"

                if t == 0:
                    in_func = ec[l][visit[l]]
                else:
                    in_func = smooth_p2[l][visit[l]][t-1]

                smooth_p2[l][visit[l]][t] = \
                    w_jacobi(in_func, f, l, fname, app_data)
 
            return smooth_p2[l][visit[l]][nu2-1]
Example #8
0
def auto_tune(app_data):
    pipe_data = app_data['pipe_data']

    app_name = app_data['app']
    pipe_name = app_data['app']

    out_harrispipe = interpolate(pipe_data)
    live_outs = [out_harrispipe]

    R = pipe_data['R']
    C = pipe_data['C']

    rows = app_data['R']
    cols = app_data['C']

    param_estimates = [(R, rows), (C, cols)]
    param_constraints = [ Condition(R, "==", rows), \
                          Condition(C, "==", cols) ]

    dst_path = "/tmp"

    group_size_configs = [int(i) for i in [0.2 * 49, 0.4 * 49, 0.5 * 49]]

    tile_size_configs = []

    #tile_size_configs.append([64, 256])
    #tile_size_configs.append([64, 128])

    tile_size_configs.append([32, 512])
    tile_size_configs.append([32, 256])
    tile_size_configs.append([32, 128])
    tile_size_configs.append([32, 64])

    tile_size_configs.append([16, 512])
    tile_size_configs.append([16, 256])
    tile_size_configs.append([16, 128])
    tile_size_configs.append([16, 64])

    tile_size_configs.append([8, 512])
    tile_size_configs.append([8, 256])
    tile_size_configs.append([8, 128])
    tile_size_configs.append([8, 64])
    tile_size_configs.append([8, 32])

    # relative path to root directory from app dir
    ROOT = app_data['ROOT']
    opts = []
    if app_data['early_free']:
        opts += ['early_free']
    if app_data['optimize_storage']:
        opts += ['optimize_storage']
    if app_data['pool_alloc']:
        opts += ['pool_alloc']
    if app_data['dpfuse']:
        opts += ['dpfuse']

    gen_compile_string(app_data)
    cxx_string = app_data['cxx_string']

    # Generate Variants for Tuning
    # ============================

    gen_config = {
        "_tuner_app_name": app_name,
        "_tuner_live_outs": live_outs,
        "_tuner_param_constraints": param_constraints,  #optional
        "_tuner_param_estimates": param_estimates,  #optional
        "_tuner_tile_size_configs": tile_size_configs,  #optional
        "_tuner_group_size_configs": group_size_configs,  #optional
        "_tuner_opts": opts,  #optional
        "_tuner_dst_path": dst_path,  # optional
        "_tuner_cxx_string": cxx_string,  # optional
        "_tuner_root_path": ROOT,  # needed if pool_alloc is set
        "_tuner_debug_flag": True,  # optional
        "_tuner_opt_datadict": app_data
    }

    _tuner_src_path, _tuner_configs_count, _tuner_pipe = \
        tuner.generate(gen_config)
    '''
    _tuner_src_path = '/tmp/PolycNUUEYoLt2Mage'
    _tuner_configs_count = 75
    _tuner_pipe = buildPipeline(live_outs)
    '''

    img_data = app_data['img_data']
    IN = img_data['IN']
    OUT = img_data['OUT']

    pipe_args = {}
    pipe_args['R'] = rows
    pipe_args['C'] = cols
    pipe_args['img'] = IN
    pipe_args['interpolate'] = OUT

    # Execute the generated variants
    # ==============================

    exec_config = {
        "_tuner_app_name": app_name,
        "_tuner_pipe": _tuner_pipe,
        "_tuner_pipe_arg_data": pipe_args,
        "_tuner_src_path": _tuner_src_path,  # optional
        "_tuner_configs_count": _tuner_configs_count,  # optional
        "_tuner_omp_threads": 4,  # optional
        "_tuner_nruns": int(app_data['app_args'].runs),  # optional
        "_tuner_debug_flag": True,  # optional
        #"_tuner_custom_executor": minimal_exec_mg,
        "_tuner_app_data": app_data
    }

    tuner.execute(exec_config)