Updated Python scripts' logic
This commit is contained in:
parent
2f377907e3
commit
2c802509a0
Binary file not shown.
|
Before Width: | Height: | Size: 31 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 26 KiB |
BIN
mflops_plot.png
BIN
mflops_plot.png
Binary file not shown.
|
Before Width: | Height: | Size: 26 KiB |
@ -59,7 +59,6 @@ plt.title('Problem Size vs. MFLOP/s')
|
||||
plt.xlabel('Problem Size')
|
||||
plt.ylabel('MFLOP/s')
|
||||
plt.legend()
|
||||
plt.savefig('mflops_plot.png')
|
||||
|
||||
# Plot Memory Bandwidth Utilization
|
||||
plt.figure()
|
||||
@ -70,7 +69,6 @@ plt.title('Problem Size vs. Memory Bandwidth Utilization')
|
||||
plt.xlabel('Problem Size')
|
||||
plt.ylabel('Memory Bandwidth Utilization (%)')
|
||||
plt.legend()
|
||||
plt.savefig('memory_bandwidth_plot.png')
|
||||
|
||||
# Plot Memory Latency
|
||||
plt.figure()
|
||||
@ -81,6 +79,5 @@ plt.title('Problem Size vs. Memory Latency')
|
||||
plt.xlabel('Problem Size')
|
||||
plt.ylabel('Memory Latency')
|
||||
plt.legend()
|
||||
plt.savefig('memory_latency_plot.png')
|
||||
|
||||
plt.show()
|
||||
@ -19,51 +19,68 @@ Assumptions: developed and tested using Python version 3.8.8 on macOS 11.6
|
||||
import pandas as pd
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
plot_fname = "myplot.png"
|
||||
# Constants for calculations
|
||||
OPS = 1e6 # 1 million operations
|
||||
BYTES_ACCESSED = 1e9 # Example: 1 GB accessed
|
||||
PEAK_MEMORY_BANDWIDTH = 100 # Example: 100 GB/s
|
||||
MEMORY_ACCESSES = 1e6 # Example: 1 million memory accesses
|
||||
|
||||
# Read the CSV file
|
||||
fname = "benchmark_data.csv"
|
||||
df = pd.read_csv(fname, comment="#")
|
||||
print(df)
|
||||
|
||||
var_names = list(df.columns)
|
||||
# Extract columns
|
||||
problem_sizes = df['Problem Size'].values.tolist()
|
||||
elapsed_times_direct = df['sum_direct'].values.tolist()
|
||||
elapsed_times_indirect = df['sum_indirect'].values.tolist()
|
||||
elapsed_times_vector = df['sum_vector'].values.tolist()
|
||||
|
||||
print("var names =", var_names)
|
||||
# Calculate MFLOP/s
|
||||
mflops_direct = [OPS / time for time in elapsed_times_direct]
|
||||
mflops_indirect = [OPS / time for time in elapsed_times_indirect]
|
||||
mflops_vector = [OPS / time for time in elapsed_times_vector]
|
||||
|
||||
# split the df into individual vars
|
||||
# assumption: column order - 0=problem size, 1=blas time, 2=basic time
|
||||
# Calculate Memory Bandwidth Utilization (%)
|
||||
memory_bandwidth_direct = [(BYTES_ACCESSED / time) / PEAK_MEMORY_BANDWIDTH * 100 for time in elapsed_times_direct]
|
||||
memory_bandwidth_indirect = [(BYTES_ACCESSED / time) / PEAK_MEMORY_BANDWIDTH * 100 for time in elapsed_times_indirect]
|
||||
memory_bandwidth_vector = [(BYTES_ACCESSED / time) / PEAK_MEMORY_BANDWIDTH * 100 for time in elapsed_times_vector]
|
||||
|
||||
problem_sizes = df[var_names[0]].values.tolist()
|
||||
code1_time = df[var_names[1]].values.tolist()
|
||||
code2_time = df[var_names[2]].values.tolist()
|
||||
code3_time = df[var_names[3]].values.tolist()
|
||||
# Calculate Memory Latency
|
||||
memory_latency_direct = [time / MEMORY_ACCESSES for time in elapsed_times_direct]
|
||||
memory_latency_indirect = [time / MEMORY_ACCESSES for time in elapsed_times_indirect]
|
||||
memory_latency_vector = [time / MEMORY_ACCESSES for time in elapsed_times_vector]
|
||||
|
||||
# Plot MFLOP/s
|
||||
plt.figure()
|
||||
plt.plot(problem_sizes, mflops_direct, label='Direct')
|
||||
plt.plot(problem_sizes, mflops_indirect, label='Indirect')
|
||||
plt.plot(problem_sizes, mflops_vector, label='Vector')
|
||||
plt.title('Problem Size vs. MFLOP/s')
|
||||
plt.xlabel('Problem Size')
|
||||
plt.ylabel('MFLOP/s')
|
||||
plt.legend()
|
||||
plt.savefig('mflops_plot.png')
|
||||
|
||||
plt.title("Comparison of 3 Codes")
|
||||
# Plot Memory Bandwidth Utilization
|
||||
plt.figure()
|
||||
plt.plot(problem_sizes, memory_bandwidth_direct, label='Direct')
|
||||
plt.plot(problem_sizes, memory_bandwidth_indirect, label='Indirect')
|
||||
plt.plot(problem_sizes, memory_bandwidth_vector, label='Vector')
|
||||
plt.title('Problem Size vs. Memory Bandwidth Utilization')
|
||||
plt.xlabel('Problem Size')
|
||||
plt.ylabel('Memory Bandwidth Utilization (%)')
|
||||
plt.legend()
|
||||
plt.savefig('memory_bandwidth_plot.png')
|
||||
|
||||
xlocs = [i for i in range(len(problem_sizes))]
|
||||
# Plot Memory Latency
|
||||
plt.figure()
|
||||
plt.plot(problem_sizes, memory_latency_direct, label='Direct')
|
||||
plt.plot(problem_sizes, memory_latency_indirect, label='Indirect')
|
||||
plt.plot(problem_sizes, memory_latency_vector, label='Vector')
|
||||
plt.title('Problem Size vs. Memory Latency')
|
||||
plt.xlabel('Problem Size')
|
||||
plt.ylabel('Memory Latency')
|
||||
plt.legend()
|
||||
plt.savefig('memory_latency_plot.png')
|
||||
|
||||
plt.xticks(xlocs, problem_sizes)
|
||||
|
||||
plt.plot(code1_time, "r-o")
|
||||
plt.plot(code2_time, "b-x")
|
||||
plt.plot(code3_time, "g-^")
|
||||
|
||||
#plt.xscale("log")
|
||||
#plt.yscale("log")
|
||||
|
||||
plt.xlabel("Problem Sizes")
|
||||
plt.ylabel("runtime")
|
||||
|
||||
varNames = [var_names[1], var_names[2], var_names[3]]
|
||||
plt.legend(varNames, loc="best")
|
||||
|
||||
plt.grid(axis='both')
|
||||
|
||||
# save the figure before trying to show the plot
|
||||
plt.savefig(plot_fname, dpi=300)
|
||||
|
||||
|
||||
plt.show()
|
||||
|
||||
# EOF
|
||||
plt.show()
|
||||
Loading…
Reference in New Issue
Block a user