Peano
Loading...
Searching...
No Matches
benchmark-output-plotter.py
Go to the documentation of this file.
1import numpy as np
2import json
3import matplotlib.pyplot as plt
4import argparse
5from enum import Enum
6
7# For CPU runs compute time and launch time are functionally equivalent
8
9class MeasurementType(Enum):
10 COMPUTE_TIME = 0
11 COMPUTE_TIME_NORMALISED = 1
12 LAUNCH_TIME = 2
13 LAUNCH_TIME_NORMALISED = 3
14
15def string_to_enum(measurement_type: str) -> MeasurementType:
16 if measurement_type == "ComputeTime":
17 return MeasurementType.COMPUTE_TIME
18 if measurement_type == "ComputeTimeNormalised":
19 return MeasurementType.COMPUTE_TIME_NORMALISED
20 if measurement_type == "LaunchTime":
21 return MeasurementType.LAUNCH_TIME
22 if measurement_type == "LaunchTimeNormalised":
23 return MeasurementType.LAUNCH_TIME_NORMALISED
24 raise ValueError(f"Unknown measurement type: {measurement_type}")
25
26def enum_to_axis_label(measurement_type: MeasurementType):
27 match measurement_type:
28 case MeasurementType.COMPUTE_TIME:
29 return "Run Time (s)"
30 case MeasurementType.COMPUTE_TIME_NORMALISED:
31 return "Run Time per Cell (s)"
32 case MeasurementType.LAUNCH_TIME:
33 return "Launch Time (s)"
34 case MeasurementType.LAUNCH_TIME_NORMALISED:
35 return "Launch Time per Cell (s)"
36
37
38MeasurementTypes = [ "ComputeTime", "ComputeTimeNormalised", "LaunchTime", "LaunchTimeNormalised" ]
39
40parser = argparse.ArgumentParser(
41 description="ExaHyPE 2 - CCZ4 Finite Volume Rusanov Kernel Benchmarking Script"
42)
43parser.add_argument(
44 "-m",
45 "--measurement-type",
46 choices=MeasurementTypes,
47 required=True,
48 help="|".join(MeasurementTypes)
49)
50args = parser.parse_args()
51
53 patch_sizes = [3, 6, 16]
54 numbers_of_threads = [1, 2, 4, 8, 16, 32]
55
56 for patch_size in patch_sizes:
57 data = {}
58 number_of_patches = None
59 id = None
60 measurement_number = 0
61
62 for number_of_threads in numbers_of_threads:
63 print (number_of_threads)
64 input_file = f"mlir_results/ccz4_rusanov_parallel_size_{patch_size}_threads_{number_of_threads}.txt"
65 with open(input_file, 'r') as file:
66 for line in file:
67 if 'Number of patches per rank:' in line:
68 words = line.split()
69 number_of_patches = int(words[-1])
70 if not any(char.isdigit() for char in line) and ':' in line and 'Kernel ID' not in line:
71 # Only ids left (e.g. "host, AoS, serial")
72 id = line.split(':')[0].strip()
73 if '|' in line and '(' not in line and any(char.isdigit() for char in line):
74 measurement_type = MeasurementType(measurement_number)
75 if id not in data:
76 data[id] = {}
77 if number_of_threads not in data[id]:
78 data[id][number_of_threads] = {}
79 if measurement_type not in data[id][number_of_threads]:
80 data[id][number_of_threads][measurement_type] = {}
81 data[id][number_of_threads][measurement_type][number_of_patches] = float(line.split('|')[0].strip())
82 measurement_number += 1
83 if measurement_number > 3:
84 measurement_number = 0
85
86 measurement_type = string_to_enum(args.measurement_type)
87 color_cycle = plt.rcParams["axes.prop_cycle"].by_key()["color"]
88 color_map = {}
89 for i, number_of_threads in enumerate(numbers_of_threads):
90 color_map[number_of_threads] = color_cycle[i]
91
92 for id in data.keys():
93 print(id)
94 for number_of_threads in numbers_of_threads:
95 print(number_of_threads)
96 x_axis = list(data[id][number_of_threads][measurement_type].keys())
97 y_axis = list(data[id][number_of_threads][measurement_type].values())
98 if "mlir" not in id:
99 plt.plot(x_axis, y_axis, "--", color = color_map[number_of_threads], label=id)
100 else:
101 plt.plot(x_axis, y_axis, color = color_map[number_of_threads], label=id)
102
103 plt.title(f"CCZ4 Rusanov Kernel Performance (Patch Size: {patch_size})")
104 plt.xlabel("Number of Patches")
105 plt.ylabel(enum_to_axis_label(measurement_type))
106 plt.xscale("log", base=2)
107 if 'Normalised' not in args.measurement_type:
108 plt.yscale("log", base=2)
109 else:
110 plt.ylim(bottom=0)
111 plt.legend()
112 plt.show()
113
115 patch_sizes = [3, 6, 16]
116
117 for patch_size in patch_sizes:
118 data = {}
119 number_of_patches = None
120 id = None
121 measurement_number = 0
122
123 input_files = [f"mlir_results/ccz4_rusanov_cpu_serial_size_{patch_size}.txt",
124 f"mlir_results/ccz4_rusanov_parallel_size_{patch_size}_threads_1.txt"]
125
126 # Read the input files and parse the data into nested dictionaries
127 for input_file in input_files:
128 with open(input_file, 'r') as file:
129 for line in file:
130 if 'Number of patches per rank:' in line:
131 words = line.split()
132 number_of_patches = int(words[-1])
133 if not any(char.isdigit() for char in line) and ':' in line and 'Kernel ID' not in line:
134 # Only ids left (e.g. "host, AoS, serial")
135 id = line.split(':')[0].strip()
136 if '|' in line and '(' not in line and any(char.isdigit() for char in line):
137 measurement_type = MeasurementType(measurement_number)
138 if id not in data:
139 data[id] = {}
140 if measurement_type not in data[id]:
141 data[id][measurement_type] = {}
142 data[id][measurement_type][number_of_patches] = float(line.split('|')[0].strip())
143 print (data[id][measurement_type][number_of_patches])
144 measurement_number += 1
145 if measurement_number > 3:
146 measurement_number = 0
147
148 measurement_type = string_to_enum(args.measurement_type)
149 for id in data.keys():
150 x_axis = list(data[id][measurement_type].keys())
151 y_axis = list(data[id][measurement_type].values())
152 plt.plot(x_axis, y_axis, label=id)
153
154 plt.title(f"CCZ4 Rusanov Kernel Performance (Patch Size: {patch_size})")
155 plt.xlabel("Number of Patches")
156 plt.ylabel(enum_to_axis_label(measurement_type))
157 plt.xscale("log", base=2)
158 if 'Normalised' not in args.measurement_type:
159 plt.yscale("log", base=2)
160 else:
161 plt.ylim(bottom=0)
162 plt.legend()
163 plt.show()
164
enum_to_axis_label(MeasurementType measurement_type)
MeasurementType string_to_enum(str measurement_type)