-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_data.py
More file actions
183 lines (158 loc) · 6.98 KB
/
plot_data.py
File metadata and controls
183 lines (158 loc) · 6.98 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy.interpolate import interp1d
import sys
# Builds a dictionary with references to .csv columns
def get_vals(file_path):
try:
data = pd.read_csv(file_path, skiprows=[0, 1])
except FileNotFoundError:
sys.exit(f"File not found: {file_path}")
except pd.errors.EmptyDataError:
sys.exit(f"Empty data: {file_path}")
except pd.errors.ParserError:
sys.exit(f"Error parsing file: {file_path}")
vals = {
"kernel_size": data['kernel_size'],
"matrix_size": data['matrix_size'],
"mean_exec_time": data['mean_exec_time'],
"stdev_exec_time": data['stdev_exec_time'],
"mean_effective_bandwidth": data['mean_effective_bandwidth'],
"stdev_effective_bandwidth": data['stdev_effective_bandwidth'],
"mean_flops" : data['mean_flops'],
"stdev_flops" : data['stdev_flops']
}
return vals
# Insert a smoothed interpolation of the given data
def add_line(x_vals, y_vals, y_stdev, line_color='blue', label=None):
# Convert string labels to numerical values
x_numeric = np.arange(len(x_vals))
# Interpolate y-values and y_stdev
interp_func = interp1d(x_numeric, y_vals, kind='quadratic')
interp_stdev = interp1d(x_numeric, y_stdev, kind='quadratic')
# Generate a finer grid for x-values
x_fine = np.linspace(0, len(x_vals) - 1, 1000)
# Evaluate interpolated functions at the finer grid
y_smooth = interp_func(x_fine)
y_stdev_smooth = interp_stdev(x_fine)
# Plot the smooth line
plt.plot(x_fine, y_smooth, color=line_color, label=label)
# Fill between the lines
plt.fill_between(x_fine, y_smooth - y_stdev_smooth, y_smooth + y_stdev_smooth, alpha=0.1, color=line_color)
# Set x-axis tick labels
plt.xticks(x_numeric, ['$' + val + '$' for val in x_vals])
if __name__ == "__main__":
colors = ['red', 'blue', 'green', 'orange', 'purple', 'brown', 'pink', 'gray', 'olive', 'cyan']
##
# USER DEFINED DATA
# add as many blocks as lines you need to plot
# (respecting the provided format)
##
inputs = [
{
"file_name": "data/CPU-conv-naive_3-to-9-kernel_6-to-11-size_5-iter.csv",
"line_color": "red",
"label": "Alg. 1"
},
{
"file_name": "data/GPU-conv-naive_3-to-9-kernel_8-to-14-size_16-by-16-th-per-block_50-iter.csv",
"line_color": "blue",
"label": "Alg. 2"
},
{
"file_name": "data/GPU-conv-shared_3-to-9-kernel_8-to-14-size_16-by-16-th-per-block_50-iter.csv",
"line_color": "green",
"label": "Alg. 3"
},
{
"file_name": "data/GPU-conv-shared-constk_3-to-9-kernel_8-to-14-size_16-by-16-th-per-block_50-iter.csv",
"line_color": "orange",
"label": "Alg. 4"
},
{
"file_name": "data/GPU-conv-shared-constk-cached_3-to-9-kernel_8-to-14-size_16-by-16-th-per-block_50-iter.csv",
"line_color": "purple",
"label": "Alg. 5"
}
]
# Begin processing
data = [get_vals(obj["file_name"]) for obj in inputs]
unique_kernels = sorted(set(data[0]["kernel_size"]))
'''
For each algorithm compare all kernel sizes (matrix_size X mean_flops) + (matrix_size X mean_effective_bandwidth)
'''
# Display (matrix_size X mean_effective_bandwidth) graph
for key, elem in enumerate(data):
obj = inputs[key]
plt.figure(figsize=(10, 5))
for i, k_size in enumerate(unique_kernels) :
# Filter data for the current kernel size
idxs = [i for i, x in enumerate(elem['kernel_size']) if x == k_size]
mat_sizes = [elem['matrix_size'][i] for i in idxs]
mean_flops = [elem['mean_flops'][i] for i in idxs]
stdev = [elem['stdev_flops'][i] for i in idxs]
add_line(mat_sizes, mean_flops, stdev, line_color=colors[i], label=f"{obj['label']} [{k_size}]")
# Customize the graph
plt.xlabel('Matrix Size')
plt.ylabel('TFLOPS')
plt.legend(loc='upper left')
plt.xlim(0, len(mean_flops) - 1)
plt.grid(axis='y')
plt.show()
plt.figure(figsize=(10, 5))
for i, k_size in enumerate(unique_kernels) :
# Filter data for the current kernel size
idxs = [i for i, x in enumerate(elem['kernel_size']) if x == k_size]
mat_sizes = [elem['matrix_size'][i] for i in idxs]
mean_bandwidth = [elem['mean_effective_bandwidth'][i] for i in idxs]
stdev = [elem['stdev_effective_bandwidth'][i] for i in idxs]
add_line(mat_sizes, mean_bandwidth, stdev, line_color=colors[i], label=f"{obj['label']} [{k_size}]")
# Customize the graph
plt.xlabel('Matrix Size')
plt.ylabel('Effective Bandwidth (GB/s)')
plt.legend(loc='upper left')
plt.xlim(0, len(mean_bandwidth) - 1)
plt.grid(axis='y')
plt.show()
"""
For each Kernel size compare all algorithms (matrix_size X mean_flops) + (matrix_size X mean_effective_bandwidth)
"""
# Display graphs per matrix size for fixed kernel sizes
for kernel_size in unique_kernels:
plt.figure(figsize=(10, 5))
for key, elem in enumerate(data):
obj = inputs[key]
# Filter data for the current kernel size
idxs = [i for i, x in enumerate(elem['kernel_size']) if x == kernel_size]
if idxs:
mat_sizes = [elem['matrix_size'][i] for i in idxs]
mean_bandwidth = [elem['mean_effective_bandwidth'][i] for i in idxs]
stdev_bandwidth = [elem['stdev_effective_bandwidth'][i] for i in idxs]
add_line(mat_sizes, mean_bandwidth, stdev_bandwidth, line_color=obj["line_color"], label=obj["label"])
# Customize the graph
plt.xlabel('Matrix Size')
plt.ylabel('Effective Bandwidth (GB/s)')
plt.legend(loc='upper left')
plt.title(f'Kernel Size: {kernel_size}')
plt.grid(axis='y')
plt.xlim(0, len(mean_bandwidth) - 1)
plt.show()
plt.figure(figsize=(10, 5))
for key, elem in enumerate(data):
obj = inputs[key]
# Filter data for the current kernel size
idxs = [i for i, x in enumerate(elem['kernel_size']) if x == kernel_size]
if idxs:
mat_sizes = [elem['matrix_size'][i] for i in idxs]
mean_flops = [elem['mean_flops'][i] for i in idxs]
stdev_flops = [elem['stdev_flops'][i] for i in idxs]
add_line(mat_sizes, mean_flops, stdev_flops, line_color=obj["line_color"], label=obj["label"])
# Customize the graph
plt.xlabel('Matrix Size')
plt.ylabel('TFLOPS')
plt.legend(loc='upper left')
plt.title(f'Kernel Size: {kernel_size}')
plt.grid(axis='y')
plt.xlim(0, len(mean_flops) - 1)
plt.show()