Exemplo n.º 1
0
def export_to_file(backend, modes, threads, best, gpu):
    if gpu:
        path_to_files = lut_output_path + "GPU" + '/lookup_tables/' + modes_string(
            modes)
    else:
        path_to_files = lut_output_path + backend + '/lookup_tables/' + modes_string(
            modes) + '/' + str(threads)
    logger.info('Path to files: {}'.format(path_to_files))

    Path(path_to_files).mkdir(parents=True, exist_ok=True)

    for idx, mode in enumerate(modes):
        f = open(path_to_files + '/' + str(idx), "w")
        for (rank, flops, time, method) in best[idx]:
            f.write('{} {}\n'.format(rank, method))
Exemplo n.º 2
0
def mttkrp_performance_analysis(backend, modes, threads, gpu=False):
    fig, ax = plt.subplots(len(modes), 1, sharex='all')
    fig.set_size_inches(w=fig_size_in['width'], h=5)

    if gpu:
        mfps = GPU_FPS
    else:
        mfps = CPU_FPS[str(threads)]
    mttkrp_configurations = [
        MttkrpMethod.MTTKRP, MttkrpMethod.TWOSTEP0, MttkrpMethod.TWOSTEP1
    ]

    for midx, mode in enumerate(modes):
        for m in mttkrp_configurations:
            dic = read_bench(backend, threads, modes, m, gpu)
            df = dic['data']
            dm = df.loc[df['MODE'] == midx]
            y = dm['FLOPS'] / dm['TIME'] / mfps
            label, color = get_label_and_color(dic['mttkrp_method'], midx,
                                               modes)
            ax[midx].plot(dm['RANK'],
                          y,
                          '-o',
                          label=label,
                          c=color,
                          markersize=markersize,
                          linewidth=linewidth)
            # ax[midx].set_xticks(np.arange(dm['RANK'].min(), dm['RANK'].max(), step=49))
            ax[midx].set_ylim([0, 1])
            ax[midx].set_yticks(np.arange(0, 1.1, step=0.2))
            ax[midx].set_ylabel('Efficiency')
            ax[midx].grid(True)
            ax[midx].set_xscale('log')
            ax[midx].set_title('Mode {}'.format(midx))
            ax[midx].tick_params(labelright=True)
            ax[midx].legend(loc='upper left')
    ax[-1].set_xlabel('Components')
    ax[-1].set_xticks([1, 10, 100, 1000])
    ax[-1].set_xticklabels(['1', '10', '100', '1000'])
    fig.suptitle('CALS Implementations (BLAS: ' + backend + ', Threads: ' +
                 str(threads) + ', Modes: ' + modes_title_string(modes) + ')')

    plt.tight_layout()
    fig.savefig(plot_output_path + 'MTTKRP_Perf_' + backend + '_threads_' +
                str(threads) + '_modes_' + modes_string(modes) + fig_format)
    return fig
Exemplo n.º 3
0
def read_bench(backend, threads, modes, mttkrp_method, gpu=False):
    bench_dict = {}
    folder = input_path + '{}/benchmark/'.format(backend)
    mode_name = modes_string(modes)
    if gpu:
        cuda = "_CUDA"
    else:
        cuda = ""
    bench_file_name = '{}benchmark{}_{}_{}_{}_{}.csv'.format(
        folder, cuda, backend, mode_name, threads, mttkrp_method)
    if os.path.isfile(bench_file_name):
        logger.info('Found file: {}'.format(bench_file_name))
        bench_dict.update({
            'backend': backend,
            'modes': modes,
            'threads': threads,
            'mttkrp_method': mttkrp_method,
            'data': pd.read_csv(bench_file_name, delimiter=';')
        })
    else:
        logger.warning('File: {} Not Found!'.format(bench_file_name))
    return bench_dict
Exemplo n.º 4
0
def read_data(backend, threads, modes, gpu=False):
    results_dict = {}
    folder = input_path + '{}/'.format(backend)
    mode_name = modes_string(modes)

    if gpu:
        jk_file_name = '{}JKCUDA__{}_{}.csv'.format(folder, mode_name, threads)
    else:
        jk_file_name = '{}JK_{}_{}.csv'.format(folder, mode_name, threads)

    if not os.path.isfile(jk_file_name):
        logger.warning('File: {} not found.'.format(jk_file_name))
        jkdata = []
    else:
        jkdata = pd.read_csv(jk_file_name, delimiter=';')

    results_dict.update({
        'backend': backend,
        'threads': threads,
        'modes': modes,
        'gpu': gpu,
        'jkdata': jkdata
    })
    return results_dict
Exemplo n.º 5
0
                          f_xlabel=f_xlabel,
                          f_legend=f_legend)
    threads = 12
    best = best_method_per_rank(backend, modes, threads)
    ax = plot_best_mttkrp(backend,
                          modes,
                          threads,
                          best,
                          ax,
                          'C1',
                          f_ylabel=f_ylabel,
                          f_xlabel=f_xlabel,
                          f_legend=f_legend)
    threads = 24
    best = best_method_per_rank(backend, modes, threads)
    ax = plot_best_mttkrp(backend,
                          modes,
                          threads,
                          best,
                          ax,
                          'C3',
                          f_ylabel=f_ylabel,
                          f_xlabel=f_xlabel,
                          f_legend=f_legend)

    fig.tight_layout()
    fig.savefig(plot_output_path + 'MTTKRP_Best_Benchmark_' + backend +
                '_modes_' + modes_string(modes) + '_sec_3' + fig_format)

    plt.show()
Exemplo n.º 6
0
def performance_plot_both(dic, ax=None, print_all=False):
    als_df = dic['alsdata']
    als_omp = dic['alsompdata']
    cals_df = dic['calsdata']
    ccals_df = dic['ccalsdata']
    ttb_l = dic['ttbdata']

    if ax is None:
        fig, ax = plt.subplots(1, 1)
        fig.set_size_inches(w=4.68596, h=3.5)

    threads = str(cals_df['NUM_THREADS'][0])

    mfps = CPU_FPS[threads]
    gemm = GEMM[modes_string(dic['modes'])][str(threads)]

    ttime, ctime, flops, ranks, ittime = extract_als_data(als_df)
    flop_cumsum_als = np.cumsum(flops)

    ttime_omp, ctime_omp, flops_omp, ranks_omp, ittime_omp = extract_als_data(
        als_omp)
    flop_cumsum_als_omp = np.cumsum(flops_omp)

    flop_cumsum_cals = cals_df['FLOPS'].cumsum()

    print()
    print(
        'CALS Flops: {:>14}, Total: {:>8.2f}, Iteration sum: {:>8.2f}'.format(
            list(flop_cumsum_cals)[-1], cals_df['ITERATION'].sum(),
            cals_df['TOTAL'].max()))
    print('OALS Flops: {:>14}, Total: {:>8.2f}'.format(
        list(flop_cumsum_als_omp)[-1], ttime_omp.max()))
    print(
        ' ALS Flops: {:>14}, Total: {:>8.2f}, Iteration sum: {:>8.2f}'.format(
            list(flop_cumsum_als)[-1], ittime.sum(), ttime.sum()))
    print()

    ax.step(flop_cumsum_cals,
            cals_df['FLOPS'] / cals_df['ITERATION'] / mfps,
            '-',
            label='CALS',
            color='C0',
            markersize=markersize,
            linewidth=linewidth)

    print('{} {} {} {}'.format(flops_omp[-1], ttime_omp.max(), mfps,
                               flops_omp[-1] / ttime_omp.max() / mfps))

    if threads != '1':
        val = flop_cumsum_als_omp[-1] / ttime_omp.max() / mfps
        ax.step([flop_cumsum_als_omp[0], flop_cumsum_als_omp[-1]], [val, val],
                '-',
                label='OMP ALS',
                color='C6',
                markersize=markersize,
                linewidth=linewidth)

    ax.step(flop_cumsum_als,
            flops / ttime / mfps,
            '-',
            label='ALS',
            color='C1',
            markersize=markersize,
            linewidth=linewidth)

    if ttb_l:
        ax.step(flop_cumsum_als,
                flops / np.array(ttb_l) / mfps,
                '-',
                label='TTB',
                color='C4',
                markersize=markersize,
                linewidth=linewidth)

    plot_gemm(gemm, ax, flop_cumsum_als)

    # Plot the CALS buffer size as xticks
    # xticks = np.arange(1, cals_df['COLS'].count(), step=3)
    # plt.xticks(ticks=xticks, labels=np.array(cals_df['COLS'])[xticks - 1], rotation=45, fontsize=3)

    # Plot the ALS ranks as xticks
    # xticks = np.arange(1, len(ranks), step=1)
    # plt.xticks(ticks=xticks, labels=ranks[xticks - 1], rotation=45, fontsize=3)

    # Plot total distance as xticks
    flop_cumsum_cals = np.array(flop_cumsum_cals)
    ax.set_xticks([
        0, 0.33 * flop_cumsum_cals[-1], 0.66 * flop_cumsum_cals[-1],
        flop_cumsum_cals[-1]
    ])

    if threads == '24' or print_all:
        ax.set_xticklabels(['0', '.33', '.66', '1'])
    # xticks = np.arange(1, len(ranks), step=1)
    # plt.xticks(ticks=xticks, labels=ranks[xticks - 1], rotation=45, fontsize=3)

    # if (dic['modes'] == (200, 200, 200)) and (threads == '1'):
    plot_x_ranks(ax, als_df)

    if ((dic['modes'] == (100, 100, 100) or dic['modes'] == (299, 301, 41)) and
        (threads == '12')) or print_all:
        ax.legend()

    if ((dic['modes'] == (100, 100, 100)) or
        (dic['modes'] == (100, 100, 100) and threads == '1')) or print_all:
        ax.set_ylabel('Efficiency (Threads: {})'.format(threads))
    else:
        ax.tick_params(labelleft=False, left=True)

    if dic['modes'] == (299, 301, 41):
        ax.set_ylabel('Efficiency (Threads: {})'.format(threads))
        ax.tick_params(labelleft=True, left=True)
    else:
        if threads == '24':
            ax.set_xlabel('Total computation')

    # if threads_on_title:
    #     ax.set_title('Threads: {}'.format(threads))
    # else:
    #     ax.set_title(mode_string_title(dic['modes']))

    if threads == "1" or print_all:
        ax.set_title(modes_title_string(dic['modes']))

    ax.set_xlim([
        -0.02 * flop_cumsum_cals[-1],
        flop_cumsum_cals[-1] + 0.02 * flop_cumsum_cals[-1]
    ])

    ax.set_ylim([0, 1])
    ax.set_yticks(ticks=np.arange(0, 1.1, step=0.1))

    ax.grid(True, axis='y')
    # plt.tight_layout()
    if ax is None:
        plt.savefig(plot_output_path + 'ALS_v_CALS_' + dic['backend'] +
                    '_modes_' + modes_string(dic['modes']) + '_threads_' +
                    str(dic['threads']) + fig_format)
Exemplo n.º 7
0
if __name__ == '__main__':

    backend = 'MKL'
    modes = (50, 200, 200)

    f_xlabel = True
    f_ylabel = True
    f_legend = True

    fig, ax = plt.subplots(1, 1)
    fig.set_size_inches(w=fig_size_in['width']*0.8, h=3)

    threads = 1
    best = best_method_per_rank(backend, modes, threads)
    ax = plot_best_mttkrp(backend, modes, threads, best, ax, 'C0',
                          f_ylabel=f_ylabel, f_xlabel=f_xlabel, f_legend=f_legend)

    threads = 24
    best = best_method_per_rank(backend, modes, threads)
    ax = plot_best_mttkrp(backend, modes, threads, best, ax, 'C3',
                          f_ylabel=f_ylabel, f_xlabel=f_xlabel, f_legend=f_legend)

    fig.tight_layout()
    fig.savefig(plot_output_path
                + 'MTTKRP_Best_Benchmark_'
                + '_modes_' + modes_string(modes)
                + fig_format)

    plt.show()
Exemplo n.º 8
0
def plot_best_mttkrp(backend,
                     modes,
                     threads,
                     best,
                     ax=None,
                     c=None,
                     f_ylabel=True,
                     f_xlabel=True,
                     f_legend=True,
                     gpu=False):

    mfps = CPU_FPS[str(threads)]
    if gpu:
        mfps = 7e12

    # Accumulate the FLOPS and the TIME per mode, in order to calculate the efficiency of MTTKRP for all modes
    x = np.array(0)
    y_time = np.array(0)
    y_flops = np.array(0)
    for idx, data in enumerate(best):
        if idx == 0:
            x = np.array([rank for rank, flops, time, method in data])
            y_time = np.array([time for rank, flops, time, method in data])
            y_flops = np.array([flops for rank, flops, time, method in data])
        else:
            y_time += np.array([time for rank, flops, time, method in data])
            y_flops += np.array([flops for rank, flops, time, method in data])
    y = y_flops / y_time / mfps

    # Remove rank values from 11 to 19 (to conform to log scale)
    x, y = list(x), list(y)
    for rank in range(11, 20):
        if rank in x:
            ind = x.index(rank)
            x.pop(ind)
            y.pop(ind)
    x, y = np.array(x), np.array(y)

    if threads == 1:
        label = '1 thread'
    else:
        label = '{} threads'.format(threads)

    fig = None
    if ax is None:
        fig, ax = plt.subplots(1, 1)
    ax.plot(x,
            y,
            '-o',
            color=c,
            label=label,
            markersize=markersize,
            linewidth=linewidth)

    ###################
    # Figure formatting
    ###################

    # y axis
    ax.set_ylim([0, 1])
    ax.set_yticks(np.arange(0, 1.1, step=0.2))
    if f_ylabel:
        ax.set_ylabel('Efficiency')

    # x axis
    # if modes == (300, 300, 300) or modes == (299, 301, 41):
    ax.set_xscale('log')
    ax.set_xticks([1, 10, 100, 1000])

    if f_xlabel:
        ax.set_xticklabels([str(i) for i in [1, 10, 100, 1000]])
        ax.set_xlabel('Components')

    # rest
    ax.tick_params(labelleft=True, left=True)
    ax.grid(b=True, axis='y')

    if f_legend:
        ax.legend(loc='upper left')

    ax.set_title(modes_title_string(modes))
    if fig:
        fig.savefig(plot_output_path + 'MTTKRP_Best_Benchmark_' + backend +
                    '_threads_' + str(threads) + '_modes_' +
                    modes_string(modes) + fig_format)
    return ax
Exemplo n.º 9
0
        index = ['1 thread', '24 threads', 'CUDA']
        df.index = index

        print(df.to_latex(float_format="{:0.2f}".format, na_rep='-'))
        df.plot.bar(ax=ax, color=['C4', 'C1', 'C6', 'C0', 'C3'], rot=0)
        ax.set_title(modes_title_string(modes))
        ax.set_ylabel('Time in seconds')
        # ax.set_yscale('log')
        # yticks = [1, 10, 100, 1000, 10000]
        # ax.set_yticks(yticks)
        # ax.set_yticklabels([str(i) for i in yticks])
        # ax.set_ylim([0.9, 110])

        old_lim = list(ax.get_ylim())
        old_lim[1] += 0.05 * old_lim[1]
        ax.set_ylim(old_lim)
        for p in ax.patches:
            height = int(round(p.get_height()))
            if not p.get_height() == 0:
                ax.annotate(
                    str(height),
                    xy=(p.get_x() + p.get_width() / 2, height),
                    xytext=(0, 1),  # 3 points vertical offset
                    textcoords="offset points",
                    ha='center',
                    va='bottom')
        plt.tight_layout()
        plt.savefig(plot_output_path + 'ALS_v_CALS_' + backend + '_real_' +
                    modes_string(modes) + fig_format)
    plt.show()
Exemplo n.º 10
0
def read_data(backend, threads, modes, suffix=None):
    results_dict = {}
    folder = input_path + '{}/'.format(backend)
    mode_name = modes_string(modes)
    if suffix is None:
        suffix = ''
    else:
        suffix = '_{}'.format(suffix)

    als_file_name = '{}ALS_{}_{}_{}{}.csv'.format(folder, backend, mode_name,
                                                  threads, suffix)
    als_omp_file_name = '{}ALS_OMP_{}_{}_{}{}.csv'.format(
        folder, backend, mode_name, threads, suffix)
    als_cuda_file_name = '{}ALS_CUDA_{}_{}_{}{}.csv'.format(
        folder, backend, mode_name, threads, suffix)
    als_omp_cuda_file_name = '{}ALS_OMP_CUDA_{}_{}_{}{}.csv'.format(
        folder, backend, mode_name, threads, suffix)
    cals_file_name = '{}CALS_{}_{}_{}{}.csv'.format(folder, backend, mode_name,
                                                    threads, suffix)
    cals_cuda_file_name = '{}CALS_CUDA_{}_{}_{}{}.csv'.format(
        folder, backend, mode_name, threads, suffix)
    ttb_file_name = '{}TTB_{}_{}.csv'.format(folder, modes_string(modes),
                                             threads)

    if not os.path.isfile(als_file_name):
        logger.warning('File: {} not found.'.format(als_file_name))
        alsdata = []
    else:
        alsdata = pd.read_csv(als_file_name, delimiter=';')
    if not os.path.isfile(als_omp_file_name):
        logger.warning('File: {} not found.'.format(als_omp_file_name))
        alsompdata = []
    else:
        alsompdata = pd.read_csv(als_omp_file_name, delimiter=';')
    if not os.path.isfile(als_cuda_file_name):
        logger.warning('File: {} not found.'.format(als_cuda_file_name))
        alscudadata = []
    else:
        alscudadata = pd.read_csv(als_cuda_file_name, delimiter=';')
    if not os.path.isfile(als_omp_cuda_file_name):
        logger.warning('File: {} not found.'.format(als_omp_cuda_file_name))
        alsompcudadata = []
    else:
        alsompcudadata = pd.read_csv(als_omp_cuda_file_name, delimiter=';')
    if not os.path.isfile(cals_file_name):
        logger.warning('File: {} not found.'.format(cals_file_name))
        calsdata = []
    else:
        calsdata = pd.read_csv(cals_file_name, delimiter=';')
    if not os.path.isfile(cals_cuda_file_name):
        logger.warning('File: {} not found.'.format(cals_cuda_file_name))
        calscudadata = []
    else:
        calscudadata = read_cuda_csv(cals_cuda_file_name)
    if not os.path.isfile(ttb_file_name):
        logger.warning('File: {} not found.'.format(ttb_file_name))
        ttbdata = []
    else:
        ttbdata = read_ttb(ttb_file_name)

    results_dict.update({
        'backend': backend,
        'threads': threads,
        'modes': modes,
        'alsdata': alsdata,
        'alsompdata': alsompdata,
        'alscudadata': alscudadata,
        'alsompcudadata': alsompcudadata,
        'calsdata': calsdata,
        'calscudadata': calscudadata,
        'ttbdata': ttbdata
    })
    return results_dict