|
| 1 | +####################################################################### |
| 2 | +# Copyright (c) 2019-present, Blosc Development Team <[email protected]> |
| 3 | +# All rights reserved. |
| 4 | +# |
| 5 | +# This source code is licensed under a BSD-style license (found in the |
| 6 | +# LICENSE file in the root directory of this source tree) |
| 7 | +####################################################################### |
| 8 | + |
| 9 | +# This script compares the performance impact of different DDR5 memory speeds |
| 10 | +# (4800 MT/s vs 6000 MT/s) on NumPy/NumExpr operations on an AMD 7800X3D system. |
| 11 | +# It plots GFLOPS vs Arithmetic Intensity to visualize how memory bandwidth |
| 12 | +# affects performance across different workload intensities. |
| 13 | + |
| 14 | +mem_4800 = {'low': {'GFLOPS': 4.493354439009314, |
| 15 | + 'Intensity': 5.5, |
| 16 | + 'Time': 0.5508134365081787}, |
| 17 | + 'matmul0': {'GFLOPS': 258.19222456293943, |
| 18 | + 'Intensity': 1000, |
| 19 | + 'Time': 0.008714437484741211}, |
| 20 | + 'matmul1': {'GFLOPS': 364.1837565094117, |
| 21 | + 'Intensity': 5000, |
| 22 | + 'Time': 0.7722749710083008}, |
| 23 | + 'matmul2': {'GFLOPS': 370.6084229401238, |
| 24 | + 'Intensity': 10000, |
| 25 | + 'Time': 6.0710978507995605}, |
| 26 | + 'medium': {'GFLOPS': 17.71942775308632, |
| 27 | + 'Intensity': 36.75, |
| 28 | + 'Time': 0.9332976341247559}, |
| 29 | + 'very low': {'GFLOPS': 1.0880454532877077, |
| 30 | + 'Intensity': 0.5, |
| 31 | + 'Time': 0.20679283142089844} |
| 32 | + } |
| 33 | + |
| 34 | +mem_6000 = {'low': {'GFLOPS': 4.530616712594456, |
| 35 | + 'Intensity': 5.5, |
| 36 | + 'Time': 0.5462832450866699}, |
| 37 | + 'matmul0': {'GFLOPS': 241.78069276491084, |
| 38 | + 'Intensity': 1000, |
| 39 | + 'Time': 0.009305953979492188}, |
| 40 | + 'matmul1': {'GFLOPS': 364.46651669646604, |
| 41 | + 'Intensity': 5000, |
| 42 | + 'Time': 0.7716758251190186}, |
| 43 | + 'matmul2': {'GFLOPS': 371.2794341995866, |
| 44 | + 'Intensity': 10000, |
| 45 | + 'Time': 6.0601255893707275}, |
| 46 | + 'medium': {'GFLOPS': 17.79626768253134, |
| 47 | + 'Intensity': 36.75, |
| 48 | + 'Time': 0.9292678833007812}, |
| 49 | + 'very low': {'GFLOPS': 1.4817325114381805, |
| 50 | + 'Intensity': 0.5, |
| 51 | + 'Time': 0.15184926986694336} |
| 52 | + } |
| 53 | + |
| 54 | +if __name__ == "__main__": |
| 55 | + import matplotlib.pyplot as plt |
| 56 | + |
| 57 | + # Collect intensities and GFLOPS for each memory speed |
| 58 | + def extract_xy(mem_dict): |
| 59 | + intensities, gflops = [], [] |
| 60 | + for name, metrics in mem_dict.items(): |
| 61 | + intensities.append(metrics["Intensity"]) |
| 62 | + gflops.append(metrics["GFLOPS"]) |
| 63 | + # Sort by intensity for nicer lines |
| 64 | + order = sorted(range(len(intensities)), key=lambda i: intensities[i]) |
| 65 | + intensities = [intensities[i] for i in order] |
| 66 | + gflops = [gflops[i] for i in order] |
| 67 | + return intensities, gflops |
| 68 | + |
| 69 | + x4800, y4800 = extract_xy(mem_4800) |
| 70 | + x6000, y6000 = extract_xy(mem_6000) |
| 71 | + |
| 72 | + fig, ax = plt.subplots(figsize=(10, 6)) |
| 73 | + |
| 74 | + # Plot performance curves for both memory speeds |
| 75 | + ax.loglog(x4800, y4800, "-o", label="DDR5 @ 4800 MT/s", alpha=0.8) |
| 76 | + ax.loglog(x6000, y6000, "-s", label="DDR5 @ 6000 MT/s", alpha=0.8) |
| 77 | + |
| 78 | + # Same limits as roofline-plot2.py for mem_mode=True |
| 79 | + ax.set_xlim(0.1, 5e4) |
| 80 | + ax.set_ylim(0.1, 2000.0) |
| 81 | + |
| 82 | + # Annotate the first data point where the performance difference is most visible |
| 83 | + # (memory-bound region shows the biggest impact of faster RAM) |
| 84 | + x0_4800, y0_4800 = x4800[0], y4800[0] |
| 85 | + x0_6000, y0_6000 = x6000[0], y6000[0] |
| 86 | + |
| 87 | + # 6000 has larger value, annotate above with more spacing |
| 88 | + ax.annotate( |
| 89 | + f"{y0_6000:.2f} GFLOPS", |
| 90 | + (x0_6000, y0_6000), |
| 91 | + xytext=(x0_6000 * 2.5, y0_6000 * 3.5), |
| 92 | + textcoords="data", |
| 93 | + arrowprops=dict(arrowstyle="->", lw=0.8), |
| 94 | + fontsize=9, |
| 95 | + ha="left", |
| 96 | + va="bottom", |
| 97 | + ) |
| 98 | + |
| 99 | + # 4800 has smaller value, annotate below |
| 100 | + ax.annotate( |
| 101 | + f"{y0_4800:.2f} GFLOPS", |
| 102 | + (x0_4800, y0_4800), |
| 103 | + xytext=(x0_4800 * 2.5, y0_4800 * 0.55), |
| 104 | + textcoords="data", |
| 105 | + arrowprops=dict(arrowstyle="->", lw=0.8), |
| 106 | + fontsize=9, |
| 107 | + ha="left", |
| 108 | + va="top", |
| 109 | + ) |
| 110 | + |
| 111 | + ax.set_xlabel("Arithmetic Intensity (FLOPs/element)") |
| 112 | + ax.set_ylabel("Performance (GFLOPS/sec)") |
| 113 | + ax.set_title("Memory speed impact on NumPy/NumExpr performance\nAMD 7800X3D (in-memory)") |
| 114 | + ax.legend(loc="upper left") |
| 115 | + ax.grid(False) |
| 116 | + |
| 117 | + plt.tight_layout() |
| 118 | + plt.savefig("roofline-mem-speed-AMD-7800X3D.png", dpi=300, bbox_inches="tight") |
| 119 | + plt.show() |
0 commit comments