-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_differences_singular.py
129 lines (111 loc) · 4.63 KB
/
plot_differences_singular.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import os
import pandas as pd
import matplotlib.pyplot as plt
import argparse
import math
import numpy as np
from matplotlib.colors import ListedColormap
from matplotlib.cm import hsv
def plot(results_dir):
import matplotlib.pyplot as plt
import pandas as pd
import os
# Markers for omp and sycl
markers = {'omp': 'o', 'sycl': 'x'}
csv_file = results_dir
# Generate a color map for consistent coloring across CSV files
#color_map = plt.cm.get_cmap('tab10')
color_map = generate_colormap(100)
# Keep track of unique legend entries
legend_entries = []
implementations = ['omp', 'sycl', 'hip']
metric_totals = {impl: {} for impl in implementations}
metric_counts = {impl: {} for impl in implementations}
runtime_omp = {}
runtime_hip = {}
runtime_sycl = {}
if csv_file.endswith('.csv'):
file_path = csv_file
print(csv_file)
# Read CSV into a DataFrame
df = pd.read_csv(file_path, index_col=0)
# Iterate over rows and columns to accumulate metrics
for metric, row in df.iterrows():
for i, impl in enumerate(implementations):
value = row[i] # Select the appropriate column by index
if "per wave" in metric:
continue
if "DtoH" in metric or "HtoD" in metric:
continue
if metric not in metric_totals[impl]:
metric_totals[impl][metric] = 0
metric_counts[impl][metric] = 0
metric_totals[impl][metric] += value
metric_counts[impl][metric] += 1
if metric == "Runtime":
if impl == "omp":
runtime_omp[csv_file] = value
if impl == "sycl":
runtime_sycl[csv_file] = value
if impl == "hip":
runtime_hip[csv_file] = value
relative_runtime_omp = {
key: runtime_omp[key] / runtime_hip[key]
for key in runtime_omp if key in runtime_hip and runtime_hip[key] != 0
}
relative_runtime_sycl = {
key: runtime_sycl[key] / runtime_hip[key]
for key in runtime_sycl if key in runtime_hip and runtime_hip[key] != 0
}
# Calculate averages
average_metrics = {impl: {} for impl in implementations}
for impl in implementations:
for metric in metric_totals[impl]:
total = metric_totals[impl][metric]
count = metric_counts[impl][metric]
average_metrics[impl][metric] = total / count if count > 0 else 0
remove_metrics = []
# Print averages
print("Average Metrics Across All CSV Files:")
for impl in implementations:
print(f"\nImplementation: {impl}")
for metric, avg in average_metrics[impl].items():
print(f" {metric}: {avg:.2f}")
relative_metrics = {'omp': {}, 'sycl': {}}
for metric in average_metrics['hip']:
hip_value = average_metrics['hip'][metric]
if hip_value > 0: # Avoid division by zero
for impl in ['omp', 'sycl']:
relative_metrics[impl][metric] = average_metrics[impl][metric] / hip_value
elif average_metrics['omp'][metric] > 0 or average_metrics['sycl'][metric] > 0:
for impl in ['omp', 'sycl']:
relative_metrics[impl][metric] = 0
else:
remove_metrics.append(metric)
average_metrics['hip'] = {key: value for key, value in average_metrics['hip'].items() if key not in remove_metrics}
# Plotting relative metrics
metrics = list(a for a in average_metrics['hip'].keys()) # Metric names
x = range(len(metrics)) # X-axis positions
plt.figure(figsize=(14, 8))
bar_width = 0.35
plt.bar(x, relative_metrics['omp'].values(), bar_width, label='OMP', color='blue', alpha=0.7)
plt.bar([i + bar_width for i in x], relative_metrics['sycl'].values(), bar_width, label='SYCL', color='orange', alpha=0.7)
# Add labels and titles
plt.axhline(y=1, color='red', linestyle='--', linewidth=1, label='Baseline (HIP)')
plt.xticks([i + bar_width / 2 for i in x], metrics, rotation=45, ha='right')
plt.ylabel('Factor Relative to HIP')
plt.title('Metrics Relative to HIP')
plt.legend()
# Show/Save the plot
plt.tight_layout()
#plt.show()
plt.savefig("relative_hip.pdf")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Plot relative runtimes (OMP & SYCL relative to HIP/CUDA).")
parser.add_argument(
"csv_file",
type=str,
help="csv file to generate plot for"
)
args = parser.parse_args()
plot(args.results_dir)