diff --git a/plotting/roofline.py b/plotting/roofline.py index 19e1c71928ab4c4c4e4ea7d445a158a3bbf5b551..2abe542c4d2d57a74a51de850d018e6d97f0470a 100644 --- a/plotting/roofline.py +++ b/plotting/roofline.py @@ -16,27 +16,35 @@ SKYLAKE = CPUInfo("Intel(R) Xeon(R) Gold 6148 CPU @ 2.40GHz", DEFAULT_MARKER = dict(size=10, color='green') +def add_compute_roofline(fig, peak_perf: float, ridge_point: float, max_x: float): + fig.add_trace( + go.Scatter(x=[ridge_point, max_x], + y=[peak_perf, peak_perf], + mode='lines+text', + name=f'Peak Performance: {peak_perf/1e9} GFlop/s', + textposition="top right", + line=dict(color='blue', width=2)) + ) + return fig + + +def add_memory_roofline(fig, peak_perf: float, ridge_point: float, max_bw: float): + fig.add_trace( + go.Scatter(x=[0, ridge_point], + y=[0, peak_perf], + mode='lines+text', + name=f"Maximum Memory bandwidth: {max_bw/1e9} GB/s", + textposition="bottom left", + line=dict(color='green', width=2)) + ) + return fig + + def add_rooflines(fig, peak_perf, max_bw, max_x): - # Calculate maximum flops/byte value + # Calculate oi where oi*max_bw == peak_perf ridge_point = peak_perf / max_bw - - # Add horizontal bandwidth roofline - x_bw = [ridge_point, max_x] - y_bw = [peak_perf, peak_perf] - fig.add_trace(go.Scatter(x=x_bw, y=y_bw, mode='lines+text', - name="Compute Roofline", - text=[f'Peak Performance {peak_perf/1e9} GFlop/s',], - textposition="top right", - line=dict(color='blue', width=2))) - - # Add diagonal compute roofline - x_compute = [0, ridge_point] - y_compute = [0, peak_perf] - fig.add_trace(go.Scatter(x=x_compute, y=y_compute, mode='lines+text', - name="Memory Roofline", - text=["", f"Memory bandwidth : {max_bw/1e9} GB/s",], - textposition="bottom left", - line=dict(color='green', width=2))) + fig = add_compute_roofline(fig, peak_perf, ridge_point, max_x) + fig = add_memory_roofline(fig, peak_perf, ridge_point, max_bw) return fig @@ -50,32 +58,37 @@ def add_data_point(fig, x, y, *, y=[y], mode='markers', marker=marker, - name=name + name=name, + text=name, )) return fig def set_axis(fig): # Add roofline axes labels + common_config = dict( + type='log', + zeroline=True, + exponentformat="SI" + ) fig.update_layout( - xaxis=dict( - type='log', - title='Operational Intensity (Flop/Byte)', - zeroline=True - ), - yaxis=dict( - type='log', - title='Performance (Flop/s)', - zeroline=True - ) + xaxis={ + 'title': 'Operational Intensity (Flop/Byte)', + **common_config, + }, + yaxis={ + 'title': 'Performance (Flop/s)', + **common_config, + }, ) return fig -def create_plot(peak_perf, max_band): +def create_plot(peak_perf, max_band, title): fig = go.Figure() fig = add_rooflines(fig, peak_perf, max_band, 100) fig = set_axis(fig) + fig.update_layout(title=title) return fig