From a68cfcc8f4d00c63bfaa87744cfcc4033ac62818 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Oberhuber?= <oberhuber.tomas@gmail.com> Date: Fri, 6 Aug 2021 17:03:58 +0200 Subject: [PATCH] Working on the script for processing results of SpMV benchmark. --- .../tnl-spmv-benchmark-make-tables-json.py | 428 +++++++++++++++--- 1 file changed, 356 insertions(+), 72 deletions(-) diff --git a/src/Benchmarks/scripts/tnl-spmv-benchmark-make-tables-json.py b/src/Benchmarks/scripts/tnl-spmv-benchmark-make-tables-json.py index 69e23fa2d0..b9f2ddeda6 100755 --- a/src/Benchmarks/scripts/tnl-spmv-benchmark-make-tables-json.py +++ b/src/Benchmarks/scripts/tnl-spmv-benchmark-make-tables-json.py @@ -7,6 +7,21 @@ from pandas.io.json import json_normalize import matplotlib.pyplot as plt import numpy as np +#Latex fonst set-up + +#plt.rcParams.update({ +# "text.usetex": True, +# "font.family": "sans-serif", +# "font.sans-serif": ["Helvetica"]}) +# +# for Palatino and other serif fonts use: +#plt.rcParams.update({ +# "text.usetex": True, +# "font.family": "serif", +# "font.serif": ["Palatino"], +#}) + + #### # Helper function def slugify(s): @@ -51,35 +66,50 @@ def get_multiindex( input_df, formats ): level3.append( 'speed-up') level4.append( speedup ) df_data[ 0 ].append( ' ' ) - if format == 'CSR< Light >': - level1.append( format ) - level2.append( 'GPU' ) - level3.append( 'speed-up') - level4.append( 'LightSpMV Vector' ) - df_data[ 0 ].append( ' ' ) - if format == 'TNL Best': - level1.append( format ) - level2.append( 'GPU' ) - level3.append( 'format') - level4.append( '' ) - df_data[ 0 ].append( ' ' ) + if 'Binary' in format: + level1.append( format ) + level2.append( 'GPU' ) + level3.append( 'speed-up') + level4.append( 'non-binary' ) + df_data[ 0 ].append( ' ' ) + if 'Symmetric' in format: + level1.append( format ) + level2.append( 'GPU' ) + level3.append( 'speed-up') + level4.append( 'non-symmetric' ) + df_data[ 0 ].append( ' ' ) + if format == 'CSR< Light >': + level1.append( format ) + level2.append( 'GPU' ) + level3.append( 'speed-up') + level4.append( 'LightSpMV Vector' ) + df_data[ 0 ].append( ' ' ) + if format == 'TNL Best': + level1.append( format ) + level2.append( 'GPU' ) + level3.append( 'format') + level4.append( '' ) + df_data[ 0 ].append( ' ' ) multiColumns = pd.MultiIndex.from_arrays([ level1, level2, level3, level4 ] ) return multiColumns, df_data #### # Convert input table to better structured one -def convert_data_frame( input_df, multicolumns, df_data, max_rows = -1 ): +def convert_data_frame( input_df, multicolumns, df_data, begin_idx = 0, end_idx = -1 ): frames = [] in_idx = 0 out_idx = 0 - max_out_idx = max_rows - if max_out_idx == -1: - max_out_idx = len(input_df.index) - while in_idx < len(input_df.index) and out_idx < max_out_idx: + #max_out_idx = max_rows + if end_idx == -1: + end_idx = len(input_df.index) + while in_idx < len(input_df.index) and out_idx < end_idx: matrixName = input_df.iloc[in_idx]['matrix name'] df_matrix = input_df.loc[input_df['matrix name'] == matrixName] - print( out_idx, ":", in_idx, "/", len(input_df.index), ":", matrixName ) + if out_idx >= begin_idx: + print( f'{out_idx} : {in_idx} / {len(input_df.index)} : {matrixName}' ) + else: + print( f'{out_idx} : {in_idx} / {len(input_df.index)} : {matrixName} - SKIP' ) aux_df = pd.DataFrame( df_data, columns = multicolumns, index = [out_idx] ) best_bw = 0 for index,row in df_matrix.iterrows(): @@ -97,6 +127,7 @@ def convert_data_frame( input_df, multicolumns, df_data, max_rows = -1 ): not 'Legacy' in current_format and not 'cusparse' in current_format and not 'LightSpMV' in current_format and + not 'Hybrid' in current_format and bw > best_bw ): best_bw = bw best_format = current_format @@ -114,7 +145,8 @@ def convert_data_frame( input_df, multicolumns, df_data, max_rows = -1 ): aux_df.iloc[0][('TNL Best','GPU','format','')] = best_format else: aux_df.iloc[0][('TNL Best','GPU','format','')] = 'cusparse' - frames.append( aux_df ) + if out_idx >= begin_idx: + frames.append( aux_df ) out_idx = out_idx + 1 in_idx = in_idx + len(df_matrix.index) result = pd.concat( frames ) @@ -122,7 +154,7 @@ def convert_data_frame( input_df, multicolumns, df_data, max_rows = -1 ): #### # Compute speed-up of particular formats compared to Cusparse on GPU and CSR on CPU -def compute_speedup( df, formats ): +def compute_cusparse_speedup( df, formats ): for format in formats: if not format in [ 'cusparse', 'CSR' ]: print( 'Adding speed-up for ', format ) @@ -135,22 +167,17 @@ def compute_speedup( df, formats ): try: cusparse_speedup_list.append( format_bdw / cusparse_bdw ) except: - cusparse_speedup_list.append('') + cusparse_speedup_list.append(float('nan')) try: csr_speedup_list.append( format_bdw / csr_bdw ) except: - csr_speedup_list.append('') - #print( f'**{type(format_bdw)}** -- {type(5.2)}' ) - #if type(format_bdw) == "<class 'numpy.float64'>": - # print( f'##########{format_bdw / cusparse_bdw}' ) - # cusparse_speedup_list.append( format_bdw / cusparse_bdw ) - # csr_speedup_list.append( format_bdw / csr_bdw ) - #else: - # cusparse_speedup_list.append('') - # csr_speedup_list.append('') + csr_speedup_list.append(float('nan')) df[(format,'GPU','speed-up','cusparse')] = cusparse_speedup_list df[(format,'GPU','speed-up','CSR CPU')] = csr_speedup_list +#### +# Compute speedup of Light CSR +def compute_csr_light_speedup( df ): csr_light_bdw_list = df[('CSR< Light >','GPU','bandwidth')] light_spmv_bdw_list = df[('LightSpMV Vector','GPU','bandwidth')] @@ -159,20 +186,154 @@ def compute_speedup( df, formats ): try: csr_light_speedup_list.append( csr_light_bdw / light_spmv_bdw ) except: - csr_light_speedup_list.append('') + csr_light_speedup_list.append(float('nan')) df[('CSR< Light >','GPU','speed-up','LightSpMV Vector')] = csr_light_speedup_list +#### +# Compute speed-up of binary formats +def compute_binary_speedup( df, formats ): + for format in formats: + if 'Binary' in format: + non_binary_format = format.replace( 'Binary ', '' ) + print( f'Adding speed-up of {format} vs {non_binary_format}' ) + format_bdw_list = df[(format,'GPU','bandwidth')] + non_binary_bdw_list = df[(non_binary_format,'GPU','bandwidth')] + binary_speedup_list = [] + for ( format_bdw, non_binary_bdw ) in zip( format_bdw_list, non_binary_bdw_list ): + try: + binary_speedup_list.append( format_bdw / non_binary_bdw ) + except: + binary_speedup_list.append( float('nan')) + df[(format,'GPU','speed-up','non-binary')] = binary_speedup_list + +#### +# Compute speed-up of symmetric formats +def compute_symmetric_speedup( df, formats ): + for format in formats: + if 'Symmetric' in format: + non_symmetric_format = format.replace( 'Symmetric ', '' ) + print( f'Adding speed-up of {format} vs {non_symmetric_format}' ) + format_bdw_list = df[(format,'GPU','bandwidth')] + non_symmetric_bdw_list = df[(non_symmetric_format,'GPU','bandwidth')] + symmetric_speedup_list = [] + for ( format_bdw, non_symmetric_bdw ) in zip( format_bdw_list, non_symmetric_bdw_list ): + try: + symmetric_speedup_list.append( format_bdw / non_symmetric_bdw ) + except: + symmetric_speedup_list.append(float('nan')) + df[(format,'GPU','speed-up','non-symmetric')] = symmetric_speedup_list + +def compute_speedup( df, formats ): + compute_cusparse_speedup( df, formats ) + compute_csr_light_speedup( df ) + compute_binary_speedup( df, formats ) + compute_symmetric_speedup( df, formats ) + +### +# Draw several profiles into one figure +def draw_profiles( formats, profiles, xlabel, ylabel, filename, style=[] ): + fig, axs = plt.subplots( 1, 1, figsize=(6,4) ) + latexNames = [] + size = 1 + for format in formats: + t = np.arange(profiles[format].size ) + axs.plot( t, profiles[format], '-o', ms=1, lw=1 ) + size = len( profiles[format] ) + latexNames.append( latexFormatName( format ) ) + if 'draw-bar' in style: + #print( f'size = {size}' ) + bar = np.full( size, 1 ) + axs.plot( t, bar, '-', ms=1, lw=1.5 ) + + axs.legend( latexNames, loc='upper right' ) + axs.set_xlabel( xlabel ) + axs.set_ylabel( ylabel ) + axs.set_yscale( 'log' ) + plt.rcParams.update({ + "text.usetex": True, + "font.family": "sans-serif", + "font.sans-serif": ["Helvetica"]}) + plt.savefig( filename ) + plt.close(fig) + + +#### +# Effective BW profile +def effective_bw_profile( df, formats, head_size=10 ): + if not os.path.exists("BW-profile"): + os.mkdir("BW-profile") + profiles = {} + for format in formats: + print( f"Writing BW profile of {format}" ) + fig, axs = plt.subplots( 1, 1, figsize=(6,4) ) + t = np.arange(df[(format,'GPU','bandwidth')].size ) + if format == 'CSR': + df.sort_values(by=[(format,'CPU','bandwidth')],inplace=True,ascending=False) + profiles[format] = df[(format,'CPU','bandwidth')].copy() + axs.plot( t, df[(format,'CPU','bandwidth')], '-o', ms=1, lw=1 ) + else: + df.sort_values(by=[(format,'GPU','bandwidth')],inplace=True,ascending=False) + profiles[format] = df[(format,'GPU','bandwidth')].copy() + axs.plot( t, df[(format,'GPU','bandwidth')], '-o', ms=1, lw=1 ) + axs.legend( [ latexFormatName(format), 'CSR on CPU' ], loc='upper right' ) + axs.set_ylabel( 'Bandwidth in GB/sec' ) + plt.rcParams.update({ + "text.usetex": True, + "font.family": "sans-serif", + "font.sans-serif": ["Helvetica"]}) + plt.savefig( f"BW-profile/{format}.pdf") + plt.close(fig) + fig, axs = plt.subplots( 1, 1, figsize=(6,4) ) + axs.set_yscale( 'log' ) + axs.plot( t, result[(format,'GPU','bandwidth')], '-o', ms=1, lw=1 ) + axs.legend( [ latexFormatName(format), 'CSR on CPU' ], loc='lower left' ) + axs.set_xlabel( f"Matrix ID - sorted w.r.t. {latexFormatName(format)} performance" ) + axs.set_ylabel( 'Bandwidth in GB/sec' ) + plt.rcParams.update({ + "text.usetex": True, + "font.family": "sans-serif", + "font.sans-serif": ["Helvetica"]}) + plt.savefig( f"BW-profile/{format}-log.pdf") + plt.close(fig) + copy_df = df.copy() + for f in formats: + if not f in ['cusparse','CSR',format]: + copy_df.drop( labels=f, axis='columns', level=0, inplace=True ) + copy_df.to_html( f"BW-profile/{format}.html" ) + + # Draw ellpack formats profiles + current_formats = [] + xlabel = "Matrix ID - sorted by particular formats effective BW" + ylabel = "Bandwidth in GB/sec" + for format in formats: + if( ( 'Ellpack' in format and not 'Binary' in format and not 'Legacy' in format ) or + format == 'CSR' or + format == 'cusparse' ): + current_formats.append( format ) + draw_profiles( current_formats, profiles, xlabel, ylabel, "ellpack-profiles-bw.pdf" ) + + # Draw CSR formats profiles + current_formats.clear() + for format in formats: + if( ( 'CSR' in format and not 'Binary' in format and not 'Legacy' in format and not 'Hybrid' in format ) or + format == 'cusparse' ): + current_formats.append( format ) + draw_profiles( current_formats, profiles, xlabel, ylabel, "csr-profiles-bw.pdf" ) + #### # Comparison with Cusparse def cusparse_comparison( df, formats, head_size=10 ): if not os.path.exists("Cusparse-bw"): os.mkdir("Cusparse-bw") + ascend_df = df.copy() df.sort_values(by=[('cusparse','GPU','bandwidth')],inplace=True,ascending=False) + ascend_df.sort_values(by=[('cusparse','GPU','bandwidth')],inplace=True,ascending=True) for format in formats: if not format in ['cusparse','CSR']: print( f"Writing comparison of {format} and Cusparse" ) filtered_df = df.dropna( subset=[(format,'GPU','bandwidth','')] ) + filtered_ascend_df = ascend_df.dropna( subset=[(format,'GPU','bandwidth','')] ) t = np.arange(filtered_df[(format,'GPU','bandwidth')].size ) fig, axs = plt.subplots( 2, 1 ) axs[0].plot( t, filtered_df[(format,'GPU','bandwidth')], '-o', ms=1, lw=1 ) @@ -187,12 +348,11 @@ def cusparse_comparison( df, formats, head_size=10 ): axs[1].set_ylabel( 'Bandwidth in GB/sec' ) plt.savefig( f"Cusparse-bw/{format}.pdf" ) plt.close(fig) - head_df = filtered_df.head( head_size ) + copy_df = df.copy() for f in formats: if not f in ['cusparse','CSR',format]: - #print( f"Droping {f}..." ) - head_df.drop( labels=f, axis='columns', level=0, inplace=True ) - head_df.to_html( f"Cusparse-bw/{format}-head.html" ) + copy_df.drop( labels=f, axis='columns', level=0, inplace=True ) + copy_df.to_html( f"Cusparse-bw/{format}.html" ) #### # Comparison with CSR on CPU @@ -202,11 +362,13 @@ def csr_comparison( df, formats, head_size=10 ): for format in formats: if not format in ['cusparse','CSR']: print( f"Writing comparison of {format} and CSR on CPU" ) - result.sort_values(by=[(format,'GPU','bandwidth')],inplace=True,ascending=False) + ascend_df = df.copy() + df.sort_values(by=[(format,'GPU','bandwidth')],inplace=True,ascending=False) + ascend_df.sort_values(by=[(format,'GPU','bandwidth')],inplace=True,ascending=True) fig, axs = plt.subplots( 2, 1 ) - t = np.arange(result[(format,'GPU','bandwidth')].size ) - axs[0].plot( t, result[(format,'GPU','bandwidth')], '-o', ms=1, lw=1 ) - axs[0].plot( t, result[('CSR','CPU','bandwidth')], '-o', ms=1, lw=1 ) + t = np.arange(df[(format,'GPU','bandwidth')].size ) + axs[0].plot( t, df[(format,'GPU','bandwidth')], '-o', ms=1, lw=1 ) + axs[0].plot( t, df[('CSR','CPU','bandwidth')], '-o', ms=1, lw=1 ) axs[0].legend( [ latexFormatName(format), 'CSR on CPU' ], loc='upper right' ) axs[0].set_ylabel( 'Bandwidth in GB/sec' ) axs[1].set_yscale( 'log' ) @@ -219,20 +381,13 @@ def csr_comparison( df, formats, head_size=10 ): "text.usetex": True, "font.family": "sans-serif", "font.sans-serif": ["Helvetica"]}) - # for Palatino and other serif fonts use: - #plt.rcParams.update({ - # "text.usetex": True, - # "font.family": "serif", - # "font.serif": ["Palatino"], - #}) plt.savefig( f"CSR-bw/{format}.pdf") plt.close(fig) - head_df = df.head( head_size ) + copy_df = df.copy() for f in formats: if not f in ['cusparse','CSR',format]: - #print( f"Droping {f}..." ) - head_df.drop( labels=f, axis='columns', level=0, inplace=True ) - head_df.to_html( f"CSR-bw/{format}-head.html" ) + copy_df.drop( labels=f, axis='columns', level=0, inplace=True ) + copy_df.to_html( f"CSR-bw/{format}.html" ) #### # Comparison of Legacy formats @@ -248,7 +403,9 @@ def legacy_formats_comparison( df, formats, head_size=10 ): ('CSR< Vector >', 'CSR Legacy Vector') ]: if ref_format in formats and legacy_format in formats: print( f"Writing comparison of {ref_format} and {legacy_format}" ) + ascend_df = df.copy() df.sort_values(by=[(ref_format,'GPU','bandwidth')],inplace=True,ascending=False) + ascend_df.sort_values(by=[(ref_format,'GPU','bandwidth')],inplace=True,ascending=True) fig, axs = plt.subplots( 2, 1 ) t = np.arange(df[(ref_format,'GPU','bandwidth')].size ) axs[0].plot( t, df[(ref_format,'GPU','bandwidth')], '-o', ms=1, lw=1 ) @@ -265,32 +422,27 @@ def legacy_formats_comparison( df, formats, head_size=10 ): "text.usetex": True, "font.family": "sans-serif", "font.sans-serif": ["Helvetica"]}) - # for Palatino and other serif fonts use: - #plt.rcParams.update({ - # "text.usetex": True, - # "font.family": "serif", - # "font.serif": ["Palatino"], - #}) plt.savefig( f"Legacy-bw/{ref_format}.pdf") plt.close(fig) - head_df = df.head( head_size ) + copy_df = df.copy() for f in formats: if not f in ['cusparse','CSR',format]: - #print( f"Droping {f}..." ) - head_df.drop( labels=f, axis='columns', level=0, inplace=True ) - head_df.to_html( f"Legacy-bw/{format}-head.html" ) + copy_df.drop( labels=f, axis='columns', level=0, inplace=True ) + copy_df.to_html( f"Legacy-bw/{format}.html" ) #### # Comparison of speed-up w.r.t. Cusparse def cusparse_speedup_comparison( df, formats, head_size=10 ): if not os.path.exists("Cusparse-speed-up"): os.mkdir("Cusparse-speed-up") + profiles = {} for format in formats: if not format in ['cusparse','CSR']: print( f"Writing comparison of speed-up of {format} compared to Cusparse" ) df['tmp'] = df[(format, 'GPU','bandwidth')] filtered_df=df.dropna(subset=[('tmp','','','')]) filtered_df.sort_values(by=[(format,'GPU','speed-up','cusparse')],inplace=True,ascending=False) + profiles[format] = filtered_df[(format,'GPU','speed-up','cusparse')].copy() fig, axs = plt.subplots( 1, 1, figsize=(6,4) ) size = len(filtered_df[(format,'GPU','speed-up','cusparse')].index) t = np.arange( size ) @@ -300,6 +452,68 @@ def cusparse_speedup_comparison( df, formats, head_size=10 ): axs.legend( [ latexFormatName(format), 'Cusparse' ], loc='upper right' ) axs.set_ylabel( 'Speedup' ) axs.set_xlabel( f"Matrix ID - sorted w.r.t. {latexFormatName(format)} speed-up" ) + plt.rcParams.update({ + "text.usetex": True, + "font.family": "sans-serif", + "font.sans-serif": ["Helvetica"]}) + plt.savefig( f"Cusparse-speed-up/{format}.pdf") + plt.close(fig) + + fig, axs = plt.subplots( 1, 1, figsize=(6,4) ) + axs.set_yscale( 'log' ) + axs.plot( t, filtered_df[(format,'GPU','speed-up','cusparse')], '-o', ms=1, lw=1 ) + axs.plot( t, bar, '-', ms=1, lw=1 ) + axs.legend( [ latexFormatName(format), 'Cusparse' ], loc='lower left' ) + axs.set_xlabel( f"Matrix ID - sorted w.r.t. {latexFormatName(format)} speed-up" ) + axs.set_ylabel( 'Speedup' ) + plt.savefig( f"Cusparse-speed-up/{format}-log.pdf") + plt.close(fig) + copy_df = df.copy() + for f in formats: + if not f in ['cusparse','CSR',format]: + copy_df.drop( labels=f, axis='columns', level=0, inplace=True ) + copy_df.to_html( f"Cusparse-speed-up/{format}.html" ) + + # Draw Ellpack formats profiles + xlabel = "Matrix ID - sorted particular by formats speedup compared to Cusparse" + ylabel = "Speedup" + current_formats = [] + for format in formats: + if( 'Ellpack' in format and not 'Binary' in format and not 'Legacy' in format ): + current_formats.append( format ) + draw_profiles( current_formats, profiles, xlabel, ylabel, "ellpack-profiles-cusparse-speedup.pdf", "draw-bar" ) + + # Draw CSR formats profiles + current_formats.clear() + for format in formats: + if( 'CSR' in format and not 'Binary' in format and not 'Legacy' in format and not 'Hybrid' in format and format != 'CSR' ): + current_formats.append( format ) + draw_profiles( current_formats, profiles, xlabel, ylabel, "csr-profiles-cusparse-speedup.pdf", "draw-bar" ) + +#### +# Comparison of binary matrices +def binary_matrices_comparison( df, formats, head_size = 10 ): + if not os.path.exists("Binary-speed-up"): + os.mkdir("Binary-speed-up") + for format in formats: + if 'Binary' in format: + non_binary_format = format.replace('Binary ','') + print( f"Writing comparison of speed-up of {format} vs {non_binary_format}" ) + #df['tmp'] = df[(format, 'GPU','speed-up','non-binary')] + filtered_df=df.dropna(subset=[(format, 'GPU','speed-up','non-binary')]) #('tmp','','','')]) + #print( f"{format} -> {filtered_df[(format,'GPU','speed-up','non-binary')]}" ) + ascend_df = filtered_df.copy() + filtered_df.sort_values(by=[(format,'GPU','speed-up','non-binary')],inplace=True,ascending=False) + ascend_df.sort_values(by=[(format,'GPU','speed-up','non-binary')],inplace=True,ascending=True) + fig, axs = plt.subplots( 1, 1, figsize=(6,4) ) + size = len(filtered_df[(format,'GPU','speed-up','non-binary')].index) + t = np.arange( size ) + bar = np.full( size, 1 ) + axs.plot( t, filtered_df[(format,'GPU','speed-up','non-binary')], '-o', ms=1, lw=1 ) + axs.plot( t, bar, '-', ms=1, lw=1 ) + axs.legend( [ latexFormatName(format), latexFormatName(non_binary_format) ], loc='upper right' ) + axs.set_ylabel( 'Speedup' ) + axs.set_xlabel( f"Matrix ID - sorted w.r.t. {latexFormatName(format)} speed-up" ) plt.rcParams.update({ "text.usetex": True, "font.family": "sans-serif", @@ -310,24 +524,85 @@ def cusparse_speedup_comparison( df, formats, head_size=10 ): # "font.family": "serif", # "font.serif": ["Palatino"], #}) - plt.savefig( f"Cusparse-speed-up/{format}.pdf") + plt.savefig( f"Binary-speed-up/{format}.pdf") plt.close(fig) fig, axs = plt.subplots( 1, 1, figsize=(6,4) ) axs.set_yscale( 'log' ) - axs.plot( t, filtered_df[(format,'GPU','speed-up','cusparse')], '-o', ms=1, lw=1 ) + axs.plot( t, filtered_df[(format,'GPU','speed-up','non-binary')], '-o', ms=1, lw=1 ) axs.plot( t, bar, '-', ms=1, lw=1 ) - axs.legend( [ latexFormatName(format), 'Cusparse' ], loc='lower left' ) + axs.legend( [ latexFormatName(format), latexFormatName(non_binary_format) ], loc='upper right' ) axs.set_xlabel( f"Matrix ID - sorted w.r.t. {latexFormatName(format)} speed-up" ) axs.set_ylabel( 'Speedup' ) - plt.savefig( f"Cusparse-speed-up/{format}-log.pdf") + plt.savefig( f"Binary-speed-up/{format}-log.pdf") plt.close(fig) - head_df = filtered_df.head( head_size ) + #head_df = filtered_df.head( head_size ) + #bottom_df = ascend_df.head( head_size ) + copy_df = df.copy() for f in formats: - if not f in ['cusparse','CSR',format]: + if not f in ['cusparse','CSR',format,non_binary_format]: + #print( f"Droping {f}..." ) + #head_df.drop( labels=f, axis='columns', level=0, inplace=True ) + copy_df.drop( labels=f, axis='columns', level=0, inplace=True ) + #head_df.to_html( f"Binary-speed-up/{format}-head.html" ) + copy_df.to_html( f"Binary-speed-up/{format}.html" ) + +#### +# Comparison of symmetric matrices +def symmetric_matrices_comparison( df, formats, head_size = 10 ): + if not os.path.exists("Symmetric-speed-up"): + os.mkdir("Symmetric-speed-up") + for format in formats: + if 'Symmetric' in format: + non_symmetric_format = format.replace('Symmetric ','') + print( f"Writing comparison of speed-up of {format} vs {non_symmetric_format}" ) + #df['tmp'] = df[(format, 'GPU','speed-up','non-symmetric')] + filtered_df=df.dropna(subset=[(format, 'GPU','speed-up','non-symmetric')]) #('tmp','','','')]) + ascend_df = filtered_df.copy() + #print( f"{format} -> {filtered_df[(format,'GPU','speed-up','non-symmetric')]}" ) + filtered_df.sort_values(by=[(format,'GPU','speed-up','non-symmetric')],inplace=True,ascending=False) + ascend_df.sort_values(by=[(format,'GPU','speed-up','non-symmetric')],inplace=True,ascending=True) + fig, axs = plt.subplots( 1, 1, figsize=(6,4) ) + size = len(filtered_df[(format,'GPU','speed-up','non-symmetric')].index) + t = np.arange( size ) + bar = np.full( size, 1 ) + axs.plot( t, filtered_df[(format,'GPU','speed-up','non-symmetric')], '-o', ms=1, lw=1 ) + axs.plot( t, bar, '-', ms=1, lw=1 ) + axs.legend( [ latexFormatName(format), latexFormatName(non_symmetric_format) ], loc='upper right' ) + axs.set_ylabel( 'Speedup' ) + axs.set_xlabel( f"Matrix ID - sorted w.r.t. {latexFormatName(format)} speed-up" ) + plt.rcParams.update({ + "text.usetex": True, + "font.family": "sans-serif", + "font.sans-serif": ["Helvetica"]}) + # for Palatino and other serif fonts use: + #plt.rcParams.update({ + # "text.usetex": True, + # "font.family": "serif", + # "font.serif": ["Palatino"], + #}) + plt.savefig( f"Symmetric-speed-up/{format}.pdf") + plt.close(fig) + + fig, axs = plt.subplots( 1, 1, figsize=(6,4) ) + axs.set_yscale( 'log' ) + axs.plot( t, filtered_df[(format,'GPU','speed-up','non-symmetric')], '-o', ms=1, lw=1 ) + axs.plot( t, bar, '-', ms=1, lw=1 ) + axs.legend( [ latexFormatName(format), latexFormatName(non_symmetric_format) ], loc='lower left' ) + axs.set_xlabel( f"Matrix ID - sorted w.r.t. {latexFormatName(format)} speed-up" ) + axs.set_ylabel( 'Speedup' ) + plt.savefig( f"Symmetric-speed-up/{format}-log.pdf") + plt.close(fig) + #head_df = filtered_df.head( head_size ) + #bottom_df = ascend_df.head( head_size ) + copy_df = df.copy() + for f in formats: + if not f in ['cusparse','CSR',format,non_symmetric_format]: #print( f"Droping {f}..." ) - head_df.drop( labels=f, axis='columns', level=0, inplace=True ) - head_df.to_html( f"Cusparse-speed-up/{format}-head.html" ) + #head_df.drop( labels=f, axis='columns', level=0, inplace=True ) + copy_df.drop( labels=f, axis='columns', level=0, inplace=True ) + #head_df.to_html( f"Symmetric-speed-up/{format}-head.html" ) + copy_df.to_html( f"Symmetric-speed-up/{format}.html" ) #### # Comparison of speed-up w.r.t. LightSpMV @@ -336,7 +611,9 @@ def csr_light_speedup_comparison( df, head_size=10 ): print( f"Writing comparison of speed-up of CSR Light compared to LightSPMV" ) df['tmp'] = df[(format, 'GPU','bandwidth')] filtered_df=df.dropna(subset=[('tmp','','','')]) + ascend_df = filtered_df.copy() filtered_df.sort_values(by=[(format,'GPU','speed-up','LightSpMV Vector')],inplace=True,ascending=False) + ascend_df.sort_values(by=[(format,'GPU','speed-up','LightSpMV Vector')],inplace=True,ascending=True) fig, axs = plt.subplots( 1, 1, figsize=(6,4) ) size = len(filtered_df[(format,'GPU','speed-up','LightSpMV Vector')].index) t = np.arange( size ) @@ -368,12 +645,16 @@ def csr_light_speedup_comparison( df, head_size=10 ): axs.set_ylabel( 'Speedup' ) plt.savefig( f"LightSpMV-speed-up-log.pdf") plt.close(fig) - head_df = filtered_df.head( head_size ) + #head_df = filtered_df.head( head_size ) + #bottom_df = ascend_df.head( head_size ) + copy_df = df.copy() for f in formats: if not f in ['cusparse','CSR',format]: #print( f"Droping {f}..." ) - head_df.drop( labels=f, axis='columns', level=0, inplace=True ) - head_df.to_html( f"LightSpMV-speed-up-head.html" ) + #head_df.drop( labels=f, axis='columns', level=0, inplace=True ) + copy_df.drop( labels=f, axis='columns', level=0, inplace=True ) + #head_df.to_html( f"LightSpMV-speed-up-head.html" ) + copy_df.to_html( f"LightSpMV-speed-up-bottom.html" ) #### @@ -388,7 +669,7 @@ formats = get_formats( input_df ) multicolumns, df_data = get_multiindex( input_df, formats ) print( "Converting data..." ) -result = convert_data_frame( input_df, multicolumns, df_data, 20 ) +result = convert_data_frame( input_df, multicolumns, df_data, 0, 10000 ) compute_speedup( result, formats ) result.replace( to_replace=' ',value=np.nan,inplace=True) @@ -400,10 +681,13 @@ def processDf( df, formats, head_size = 10 ): df.to_html( f'output.html' ) # Generate tables and figures + effective_bw_profile( df, formats, head_size ) cusparse_comparison( df, formats, head_size ) csr_comparison( df, formats, head_size ) legacy_formats_comparison( df, formats, head_size ) cusparse_speedup_comparison( df, formats, head_size ) + binary_matrices_comparison( df, formats, head_size ) + symmetric_matrices_comparison( df, formats, head_size ) csr_light_speedup_comparison( df, head_size ) best = df[('TNL Best','GPU','format')].tolist() @@ -416,7 +700,7 @@ def processDf( df, formats, head_size = 10 ): cases = best.count(format) print( f'{format} is best in {cases} cases.') -head_size = 10 +head_size = 25 if not os.path.exists( 'general' ): os.mkdir( 'general' ) os.chdir( 'general' ) -- GitLab