86 lines
3.0 KiB
Python
86 lines
3.0 KiB
Python
"""
|
|
|
|
E. Wes Bethel, Copyright (C) 2022
|
|
|
|
October 2022
|
|
|
|
Description: This code loads a .csv file and creates a 3-variable plot, and saves it to a file named "myplot.png"
|
|
|
|
Inputs: the named file "sample_data_3vars.csv"
|
|
|
|
Outputs: displays a chart with matplotlib
|
|
|
|
Dependencies: matplotlib, pandas modules
|
|
|
|
Assumptions: developed and tested using Python version 3.8.8 on macOS 11.6
|
|
|
|
"""
|
|
|
|
import pandas as pd
|
|
import matplotlib.pyplot as plt
|
|
|
|
# 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="#")
|
|
|
|
# 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()
|
|
|
|
# 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]
|
|
|
|
# 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]
|
|
|
|
# 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')
|
|
|
|
# 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')
|
|
|
|
# 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.show() |