Пример #1
0
def run_thread(params, count_only=False):
    if len(params) == 4:
        layer, tc_list, spatial_factor, env_config = params
    else:
        layer_index, tc_list, spatial_factor, env_config, expr_params = params
        global PARAMS
        PARAMS = expr_params

    if env_config != None:
        PARAMS.env.rf_energy = env_config["rf_energy"]
        PARAMS.env.spm_energy = env_config["spm_energy"]

    if len(params) == 5:
        layer_args = layer_info.resnet_parameters[layer_index]
        layer = ConvLayer(PARAMS.env, **layer_args)

    try:
        stride = layer.strides
    except:
        stride = None

    tc_list_after_spatial = [ int(x/y) for x, y in zip(tc_list, spatial_factor) ]
    tc_list_factors_spatial = [ factors(tc) for tc in tc_list_after_spatial ]

    min_energy = float("inf")
    min_energy_sequence = None
    min_edp = float("inf")
    min_edp_sequence = None
    min_cycle = float("inf")
    min_cycle_sequence = None

    evaluated = 0

    for rf_factor in of_bucket(tc_list_factors_spatial):
        if not valid_rf(layer, stride, rf_factor):
            continue

        tc_list_after_rf = [ int(x/y) for x, y in zip(tc_list_after_spatial, rf_factor)]
        tc_list_factors_rf = [ factors(tc) for tc in tc_list_after_rf]

        for spm_factor in of_bucket(tc_list_factors_rf):
            spatial_rf_factor = ( x*y for x, y in zip(spatial_factor, rf_factor))
            if not valid_spm(layer, stride, spatial_rf_factor, spm_factor):
                continue

            tc_list_after_spm = tuple([ int(x/y) for x, y in zip(tc_list_after_rf, spm_factor) ])
            dram_factor = tc_list_after_spm
            if not valid_dram(layer, dram_factor):
                continue
            #assert tc_list == [ x*y*z*w for x,y,z,w in zip(spatial_factor, rf_factor, spm_factor, dram_factor)]

            evaluated += 1
            if count_only:
                continue

            IV_ORDER = layer._default_loop_order
            for idx in range(len(IV_ORDER)):
                tiling_factor = [dram_factor[idx], spm_factor[idx], rf_factor[idx], spatial_factor[idx]]
                layer.set_tiling(IV_ORDER[idx], tiling_factor)

            edp, energy, cycle = layer.get_min_edp_energy_cycle()
            if edp < min_edp:
                min_edp = edp
                min_edp_sequence = (dram_factor, spm_factor, rf_factor, spatial_factor)

            if energy < min_energy:
                min_energy = energy
                min_energy_sequence = (dram_factor, spm_factor, rf_factor, spatial_factor)

            if cycle < min_cycle:
                min_cycle = cycle
                min_cycle_sequence = (dram_factor, spm_factor, rf_factor, spatial_factor)

    """
    file_name = "_".join([ str(i) for i in spatial_factor ])
    file_name = str(layer_index) + "_" + file_name
    output_file = "out/" + expr_name + "/" + file_name + ".txt"
    with open(output_file, "w") as outFile:
        line = ",".join([ str(item) for item in [min_edp, min_edp_sequence, min_energy, min_energy_sequence] ])
        outFile.write(line)
    """

    if count_only:
        return evaluated

    return min_edp, min_edp_sequence, min_energy, min_energy_sequence, min_cycle, min_cycle_sequence, evaluated
Пример #2
0
def run_thread(params):
    layer_index, tc_list, spatial_factor, env_config = params

    if env_config != None:
        env = expr_parameters.Environment(
            rf_energy=env_config["rf_energy"],
            spm_energy=env_config["spm_energy"],
        )
    else:
        env = expr_parameters.Environment()

    env.pe_pipeline_stages = 1
    layer_args = layer_info.resnet_parameters[layer_index]
    layer = ConvLayer(env, **layer_args)
    stride = layer.strides

    tc_list_after_spatial = [
        int(x / y) for x, y in zip(tc_list, spatial_factor)
    ]
    tc_list_factors_spatial = [factors(tc) for tc in tc_list_after_spatial]

    min_energy = float("inf")
    min_energy_sequence = None
    min_edp = float("inf")
    min_edp_sequence = None

    evaluated = 0

    for rf_factor in of_bucket(tc_list_factors_spatial):
        if not valid_rf(stride, rf_factor):
            continue

        tc_list_after_rf = [
            int(x / y) for x, y in zip(tc_list_after_spatial, rf_factor)
        ]
        tc_list_factors_rf = [factors(tc) for tc in tc_list_after_rf]

        for spm_factor in of_bucket(tc_list_factors_rf):
            spatial_rf_factor = (x * y
                                 for x, y in zip(spatial_factor, rf_factor))
            if not valid_spm(stride, spatial_rf_factor, spm_factor):
                continue

            tc_list_after_spm = tuple(
                [int(x / y) for x, y in zip(tc_list_after_rf, spm_factor)])
            dram_factor = tc_list_after_spm
            if not valid_dram(dram_factor):
                continue
            #assert tc_list == [ x*y*z*w for x,y,z,w in zip(spatial_factor, rf_factor, spm_factor, dram_factor)]

            evaluated += 1

            for idx in range(len(IV_ORDER)):
                tiling_factor = [
                    dram_factor[idx], spm_factor[idx], rf_factor[idx],
                    spatial_factor[idx]
                ]
                layer.set_tiling(IV_ORDER[idx], tiling_factor)

            edp, energy, cycle = layer.get_min_edp_energy_cycle()
            if edp < min_edp:
                min_edp = edp
                min_edp_sequence = (dram_factor, spm_factor, rf_factor,
                                    spatial_factor)

            if energy < min_energy:
                min_energy = energy
                min_energy_sequence = (dram_factor, spm_factor, rf_factor,
                                       spatial_factor)
    """
    file_name = "_".join([ str(i) for i in spatial_factor ])
    file_name = str(layer_index) + "_" + file_name
    output_file = "out/" + expr_name + "/" + file_name + ".txt"
    with open(output_file, "w") as outFile:
        line = ",".join([ str(item) for item in [min_edp, min_edp_sequence, min_energy, min_energy_sequence] ])
        outFile.write(line)
    """

    return min_edp, min_edp_sequence, min_energy, min_energy_sequence, evaluated