Ejemplo n.º 1
0
def get_performance_closest_to_baseline(
    data, algorithm, mnk, gpu_properties, autotuning_properties
):
    """
    Sometimes, the so-called "baseline" parameter set does not appear in the training data.
    This function finds the performance of the parameter set from the training data whose parameters are closest to those of the
    baseline parameter sets.
    """
    m, n, k = mnk_pattern.match(mnk).groups()
    m, n, k = int(m), int(n), int(k)

    data_mnk = data[(data["m"] == m) & (data["n"] == n) & (data["k"] == k)].compute()
    baseline_pars = kernel_algorithm[algorithm].baseline(
        m, n, k, gpu_properties, autotuning_properties
    )

    # Get performance of baseline parameters for this algorithm & this mnk:
    idx_baseline = get_idx_baseline(data_mnk, algorithm, baseline_pars)

    # Get performance of baseline parameters for this algorithm & this mnk:
    if len(idx_baseline) == 0:
        # Generate space of possibilities
        pars_sets = kernel_algorithm[algorithm].promising_parameters(
            m, n, k, gpu_properties, autotuning_properties
        )
        # Sort space by distance to baseline set
        pars_sets.sort(
            key=lambda x: kernel_algorithm[algorithm].parameter_set_distance(
                x, baseline_pars
            )
        )

        for pars_set in pars_sets:
            idx_baseline = get_idx_baseline(data_mnk, algorithm, pars_set)
            if len(idx_baseline) > 0:
                break
        else:
            assert False, (
                'Could not find closest baseline for mnk=({}x{}x{}) and for algorithm "{}".'
                + "\nLast baseline parameters searched:\n{}"
                + "\nParameter sets searched:\n".format(
                    m, n, k, algorithm, baseline_pars
                )
            )

    idx_baseline = idx_baseline[0]
    baseline_perf = data_mnk["perf (Gflop/s)"][idx_baseline]
    return round(baseline_perf, 3)
Ejemplo n.º 2
0
def process_chunk(data_chunk, algorithm, gpu_properties, autotuning_properties):
    """
    Given a chunk of data, compute the baseline and maximum performance of the (m, n, k)-triplets featured in the chunk of data.
    """
    # Add "mnk" column
    data_chunk["mnk"] = (
        data_chunk["m"].astype(str)
        + "x"
        + data_chunk["n"].astype(str)
        + "x"
        + data_chunk["k"].astype(str)
    )
    # Get mnks
    mnks = data_chunk["mnk"].unique()

    # For each (mnk), ...
    baseline_performances = dict()
    max_performances = dict()
    for i, mnk in enumerate(mnks):

        data_mnk = data_chunk[data_chunk["mnk"] == mnk]
        m, n, k = mnk_pattern.match(mnk).groups()
        m, n, k = int(m), int(n), int(k)

        # Get baseline configuration for this algorithm & this mnk:
        baseline_pars = kernel_algorithm[algorithm].baseline(
            m, n, k, gpu_properties, autotuning_properties
        )

        # Get performance of baseline parameters for this algorithm & this mnk:
        idx_baseline = get_idx_baseline(data_mnk, algorithm, baseline_pars)
        if len(idx_baseline) < 1:
            baseline_perf = 0
        else:
            idx_baseline = idx_baseline[0]
            baseline_perf = data_mnk["perf (Gflop/s)"][idx_baseline]

        baseline_performances[mnk] = round(baseline_perf, 3)

        # Get max performance for this algorithm & this mnk
        max_perf = data_mnk["perf (Gflop/s)"].max()
        max_performances[mnk] = round(max_perf, 3)

    return baseline_performances, max_performances