Peano
Loading...
Searching...
No Matches
plots_llvm_paper_likwid_1x3_backup.py
Go to the documentation of this file.
1#!/usr/bin/env python
2
3import numpy as np
4from tkinter import Tcl
5import glob, os
6import re
7from matplotlib import gridspec
8import matplotlib.pyplot as plt
9import matplotlib as mpl
10import pandas as pd
11
12
13"""
14Script to read the likwid output data and make plots.
15Read likwid cvs files using Pandas.
16"""
17
18# Input
19folder_input = "/home/cristianbarrahinojosa/Overleaf/paper-llvm2022/experiments/18_sph_simulation/hamilton8/Noh_2D/output_np_400_et_0.01/likwid/"
20
21datatype_inputs = ["MEM", "CACHE"]
22
23for datatype_input in datatype_inputs:
24 filename_template = "output_" + datatype_input + "_cores_*_*.cvs"
25 filename_template_regex = "output_" + datatype_input + "_cores_(.*)_(.*)"
26
27 cores_array = [1, 2, 4, 8, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64]
28
29 # Initialize template dataframe
30 if datatype_input == "MEM":
31 data_template_SUM = {
32 "Metric SUM": [
33 "Runtime (RDTSC) [s] STAT",
34 "Runtime unhalted [s] STAT",
35 "Clock [MHz] STAT",
36 "CPI STAT",
37 "Memory bandwidth [MBytes/s] STAT",
38 "Memory data volume [GBytes] STAT",
39 ],
40 }
41 data_template_AVG = {
42 "Metric AVG": [
43 "Runtime (RDTSC) [s] STAT",
44 "Runtime unhalted [s] STAT",
45 "Clock [MHz] STAT",
46 "CPI STAT",
47 "Memory bandwidth [MBytes/s] STAT",
48 "Memory data volume [GBytes] STAT",
49 ],
50 }
51 elif datatype_input == "CACHE":
52 data_template_SUM = {
53 "Metric SUM": [
54 "CPI STAT",
55 "data cache requests STAT",
56 "data cache request STAT ",
57 "data cache misses STAT",
58 "data cache miss rate STAT",
59 "data cache miss ratio STAT",
60 ],
61 }
62 data_template_AVG = {
63 "Metric AVG": [
64 "CPI STAT",
65 "data cache requests STAT",
66 "data cache request rate STAT",
67 "data cache misses STAT",
68 "data cache miss rate STAT",
69 "data cache miss ratio STAT",
70 ],
71 }
72
73 # Read cvs data and transform into numpy array
74 data_SUM_on = pd.DataFrame(data_template_SUM)
75 data_SUM_off = pd.DataFrame(data_template_SUM)
76 data_AVG_on = pd.DataFrame(data_template_AVG)
77 data_AVG_off = pd.DataFrame(data_template_AVG)
78
79 # The relevant data is at the bottom of the file, so lets skip some rows
80 N_metrics = len(data_SUM_on)
81 offset_row = -N_metrics
82
83 # List all files matching the template
84 path = glob.glob(folder_input + filename_template)
85 path = Tcl().call("lsort", "-dict", path)
86
87 assert path != "", "No matching file found in path. Check input data."
88
89 for file in path:
90 absfilename = file
91 tempname = os.path.basename(absfilename)
92 filename = os.path.splitext(tempname)[0]
93
94 # Get cores number via regex
95 pf = re.compile(filename_template_regex)
96
97 match = pf.search(filename)
98 cores = match.group(1)
99 clang = match.group(2)
100
101 # Read cvs file and trim
102 df_input = pd.read_csv(file, index_col=0, header=0, on_bad_lines="skip")
103
104 # Column with SUM STAT
105 SUM = df_input["Info"].iloc[offset_row:]
106
107 # Column with Avg STAT
108 if cores != "1":
109 AVG = df_input["Unnamed: 4"].iloc[offset_row:]
110 else:
111 AVG = SUM # no difference for 1 core
112
113 if clang == "on":
114 data_SUM_on["cores " + str(cores)] = SUM.values
115 data_AVG_on["cores " + str(cores)] = AVG.values
116 elif clang == "off":
117 data_SUM_off["cores " + str(cores)] = SUM.values
118 data_AVG_off["cores " + str(cores)] = AVG.values
119
120 # Convert results into python arrays
121 SUM_on = np.zeros((N_metrics, len(cores_array)))
122 AVG_on = np.zeros((N_metrics, len(cores_array)))
123
124 SUM_off = np.zeros((N_metrics, len(cores_array)))
125 AVG_off = np.zeros((N_metrics, len(cores_array)))
126
127 for i, cores in enumerate(cores_array):
128 for metric in range(N_metrics):
129 SUM_on[metric, i] = float(data_SUM_on["cores " + str(cores)][metric])
130 AVG_on[metric, i] = float(data_AVG_on["cores " + str(cores)][metric])
131
132 SUM_off[metric, i] = float(data_SUM_off["cores " + str(cores)][metric])
133 AVG_off[metric, i] = float(data_AVG_off["cores " + str(cores)][metric])
134
135 # Store data for plotting
136 if datatype_input == "MEM":
137 N_dt = 1e2
138 runtime_on = AVG_on[0] / N_dt
139 runtime_off = AVG_off[0] / N_dt
140
141 clock_speed_on = AVG_on[2]
142 clock_speed_off = AVG_off[2]
143
144 elif datatype_input == "CACHE":
145 cache_req_on = AVG_on[1] / 1e12
146 cache_req_off = AVG_off[1] / 1e12
147
148 cache_miss_ratio_on = AVG_on[5]
149 cache_miss_ratio_off = AVG_off[5]
150
151 print(f"Done Reading cvs data for datatype: {datatype_input}.")
152
153
154# Plot Setup
155font = {"size": 12}
156plt.rc("font", **font)
157plt.rc("font", family="serif")
158plt.rc("text", usetex=False)
159
160fig = plt.figure(figsize=(14, 4))
161gs = gridspec.GridSpec(1, 3, wspace=0.2)
162
163ax0 = plt.subplot(gs[0])
164
165# Runtime plot
166plt.scatter(
167 cores_array,
168 runtime_on,
169 marker="o",
170 edgecolors="r",
171 facecolors="r",
172 s=25,
173 zorder=10,
174 label=r"on",
175)
176plt.plot(cores_array, runtime_on, c="r", lw=1.2)
177plt.scatter(cores_array, runtime_off, marker="^", c="b", s=25, zorder=10, label=r"off")
178plt.plot(cores_array, runtime_off, c="b", lw=1.2, zorder=11)
179
180plt.xlabel(r"Cores")
181plt.ylabel(r"Time per time step [s]")
182plt.xscale("log", base=2)
183# plt.yscale( "log", base=2 )
184plt.margins(0.05, 0.1)
185plt.tick_params(direction="in", top=True, right=True)
186plt.tick_params(direction="in", top=True, right=True)
187plt.gca().xaxis.set_major_formatter(mpl.ticker.ScalarFormatter())
188plt.gca().yaxis.set_major_formatter(mpl.ticker.ScalarFormatter())
189plt.xticks([1, 2, 4, 8, 16, 32, 64])
190# plt.yticks([1,2,4,8,16,32,64])
191
192leg = plt.legend(loc="upper right", fontsize=10)
193
194# Cache requests
195ax1 = plt.subplot(gs[1])
196plt.scatter(
197 cores_array,
198 cache_req_on,
199 marker="o",
200 edgecolors="r",
201 facecolors="r",
202 s=25,
203 zorder=10,
204 label=r"on",
205)
206plt.plot(cores_array, cache_req_on, c="r", lw=1.2, zorder=-1)
207plt.scatter(
208 cores_array, cache_req_off, marker="^", c="b", s=25, zorder=10, label=r"off"
209)
210plt.plot(cores_array, cache_req_off, c="b", lw=1.2, zorder=11)
211plt.xlabel(r"Cores")
212plt.ylabel(r"Average cache requests [$\times10^{12}$]")
213plt.margins(0.05, 0.1)
214plt.xscale("log", base=2)
215# plt.yscale( "log", base=10)
216plt.gca().xaxis.set_major_formatter(mpl.ticker.ScalarFormatter())
217# plt.gca().yaxis.set_major_formatter(mpl.ticker.ScalarFormatter())
218plt.xticks([1, 2, 4, 8, 16, 32, 64])
219plt.tick_params(direction="in", top=True, right=True)
220
221# Cache miss rate
222ax2 = plt.subplot(gs[2])
223plt.scatter(
224 cores_array,
225 100 * cache_miss_ratio_on,
226 marker="o",
227 edgecolors="r",
228 facecolors="r",
229 s=25,
230 zorder=10,
231 label=r"on",
232)
233plt.plot(cores_array, 100 * cache_miss_ratio_on, c="r", lw=1.2)
234plt.scatter(
235 cores_array,
236 100 * cache_miss_ratio_off,
237 marker="^",
238 c="b",
239 s=25,
240 zorder=10,
241 label=r"off",
242)
243plt.plot(cores_array, 100 * cache_miss_ratio_off, c="b", lw=1.2)
244plt.xlabel(r"Cores")
245plt.ylabel(r"Average cache miss rate [%]")
246plt.margins(0.05, 0.1)
247plt.xscale("log", base=2)
248plt.gca().xaxis.set_major_formatter(mpl.ticker.ScalarFormatter())
249plt.xticks([1, 2, 4, 8, 16, 32, 64])
250plt.tick_params(direction="in", top=True, right=True)
251
252plt.show()
253fig.savefig("plot_likwid_np_400" + ".pdf", bbox_inches="tight")
254plt.close()