Peano
Loading...
Searching...
No Matches
kernel-benchmarks-fd4-dsl.py
Go to the documentation of this file.
1# This file is part of the ExaHyPE2 project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3import os
4import subprocess
5import argparse
6
7import peano4.api
8import exahype2
9import exahype2.dslhype as DSL
10
11parser = argparse.ArgumentParser(
12 description="ExaHyPE 2 - Euler FD4 Kernel Benchmarking Script"
13)
14parser.add_argument(
15 "-m",
16 "--build-mode",
17 choices=peano4.api.output.CompileModes,
18 default=peano4.api.output.CompileModes[0], # Release
19 help="|".join(peano4.api.output.CompileModes),
20)
21parser.add_argument(
22 "-t",
23 "--num-threads",
24 default=1,
25 type=int,
26 help="Number of launching threads",
27)
28parser.add_argument(
29 "-ps",
30 "--patch-size",
31 default=16,
32 type=int,
33 help="Number of finite volumes per axis (dimension) per patch.",
34)
35parser.add_argument(
36 "-p",
37 "--num-patches",
38 nargs="+",
39 default=[32, 64, 128, 256],
40 type=int,
41 help="Number of patches to study",
42)
43parser.add_argument(
44 "-samples",
45 "--samples",
46 default=10,
47 type=int,
48 help="Number of samples per measurement",
49)
50parser.add_argument(
51 "-a",
52 "--accuracy",
53 default=0.0,
54 type=float,
55 help="Floating point accuracy to which the different kernel variants have to match (absolute). Pass in 0 to disable correctness check. Pass in values < 0 to use machine epsilon (default).",
56)
57parser.add_argument(
58 "-e",
59 "--eval-eig",
60 action="store_false",
61 help="Evaluate max. eigenvalue",
62)
63parser.add_argument(
64 "-cpu",
65 "--cpu",
66 action="store_true",
67 help="Assess host kernels",
68)
69parser.add_argument(
70 "-gpu",
71 "--gpu",
72 action="store_true",
73 help="Assess device kernels",
74)
75parser.add_argument(
76 "-serial",
77 "--serial",
78 action="store_true",
79 help="Assess serial kernels",
80)
81parser.add_argument(
82 "-parallel",
83 "--parallel",
84 action="store_true",
85 help="Assess parallel kernels",
86)
87parser.add_argument(
88 "-fpe",
89 "--fpe",
90 action="store_true",
91 help="Enable a floating-point exception handler.",
92)
93# This solver is only implemented for 3D
94parser.add_argument(
95 "-d",
96 "--dimensions",
97 default=3,
98 choices = [3],
99 type=int,
100 help="Number of dimensions to use: 3",
101)
102parser.add_argument(
103 "--enable-mlir",
104 dest="enable_mlir",
105 action="store_true",
106 help="Enable MLIR kernel compilation support",
107)
108parser.add_argument(
109 "--enable-cpp",
110 dest="enable_cpp",
111 action="store_true",
112 help="Enable CPP kernels",
113)
114parser.add_argument(
115 "--enable-memref-flattening",
116 dest="enable_memref_flattening",
117 action="store_true",
118 help="Enable CPP kernels",
119)
120parser.add_argument(
121 "--enable-function-inlining",
122 dest="enable_function_inlining",
123 action="store_true",
124 help="Enable inlining of Polygeist functions",
125)
126parser.add_argument(
127 "--enable-memory-reuse",
128 dest="enable_memory_reuse",
129 action="store_true",
130 help="Enable reuse of scratchpad memory allocations",
131)
132parser.add_argument(
133 "--enable-memory-fusion",
134 dest="enable_memory_fusion",
135 action="store_true",
136 help="Enable fusion of allocations into one",
137)
138parser.add_argument(
139 "--enable-loop-fusion",
140 dest="enable_loop_fusion",
141 action="store_true",
142 help="Enable fusion of loops with the same bounds",
143)
144parser.add_argument(
145 "--enable-imperfect-nested-loops-to-perfect",
146 dest="enable_imperfect_nested_loops_to_perfect",
147 action="store_true",
148 help="Enable conversion of imperfectly nested parallels into a perfectly nested parallels",
149)
150parser.add_argument(
151 "--enable-nested-parallel-ops-to-multidimensional",
152 dest="enable_nested_parallel_ops_to_multidimensional",
153 action="store_true",
154 help="Enable conversion of nested parallels into a single multidimensional operation",
155)
156parser.add_argument(
157 "--enable-omp-tasks",
158 dest="enable_omp_tasks",
159 action="store_true",
160 help="Enable use of OpenMP tasks as opposed to loop parallelism",
161)
162parser.add_argument(
163 "--omp-task-version",
164 choices=["task", "taskloop"],
165 default="taskloop"
166)
167parser.add_argument(
168 "--omp-single-region",
169 action="store_true",
170)
171parser.add_argument(
172 "--nested-parallel-count",
173 default=-1,
174 type=int,
175 help="Number of dimensions to use: 2 or 3. Conversion is enabled if the count is positive.",
176)
177parser.add_argument(
178 "-o",
179 default="KernelBenchmarksFD4DSL",
180 type=str,
181 help="Name of final application",
182)
183parser.add_argument(
184 "-j",
185 default=-1,
186 type=int,
187 help="Number of parallel builds to use",
188)
189
190args = parser.parse_args()
191
192fd4_solver = exahype2.solvers.rkfd.fd4.GlobalAdaptiveTimeStepWithEnclaveTasking(
193 name="FD4",
194 patch_size=args.patch_size,
195 unknowns={"rho": 1, "u": 1, "v": 1, "e": 1} if args.dimensions == 2 else {"rho": 1, "u": 1, "v": 1, "w": 1, "e": 1},
196 auxiliary_variables = {},
197 min_meshcell_h=0.001, # max_cell_size -> arbitrary value
198 max_meshcell_h=0.001, # min_cell_size -> arbitrary value
199 time_step_relaxation=0.5,
200 rk_order=1,
201 pde_terms_without_state=True
202)
203
204fd4_solver.set_implementation(
205 initial_conditions="",
206 boundary_conditions=exahype2.solvers.PDETerms.Empty_Implementation,
207 refinement_criterion=exahype2.solvers.PDETerms.Empty_Implementation,
208 flux="applications::exahype2::euler::flux(Q, faceCentre, gridCellH, t, dt, normal, F);",
209 ncp=None,
210 eigenvalues="applications::exahype2::euler::maxEigenvalue(Q, faceCentre, gridCellH, t, dt, normal, maxEigenvalue);",
211 source_term=None,
212)
213fd4_solver.add_user_solver_includes(
214 """
215 #include "../../../../applications/exahype2/euler/Euler.h"
216 """
217)
218exahype2.solvers.rkfd.fd4.switch_to_FD4_second_order_interpolation(fd4_solver)
219exahype2.solvers.rkfd.fd4.switch_to_FD4_second_order_restriction(fd4_solver)
220
221project = exahype2.Project(
222 namespace=["benchmarks", "exahype2", "kernelbenchmarks"],
223 project_name="KernelBenchmarksFD4DSL",
224 directory=".",
225 executable=f"{args.o}.{args.build_mode}",
226)
227project.add_solver(fd4_solver)
228
229project.set_global_simulation_parameters(
230 dimensions=args.dimensions,
231 size=[1.0] * args.dimensions,
232 offset=[0.0] * args.dimensions,
233 min_end_time=0.1,
234 max_end_time=0.1,
235 first_plot_time_stamp=0.0,
236 time_in_between_plots=0.0,
237 periodic_BC=[False] * args.dimensions
238)
239
240project.set_Peano4_installation("../../../../", mode=peano4.api.output.string_to_mode(args.build_mode))
241project = project.generate_Peano4_project(verbose=True)
242
243accuracy = args.accuracy
244if accuracy < 0:
245 import numpy
246 accuracy = default = numpy.finfo(float).eps
247project.constants.export_constexpr_with_type("Accuracy", str(accuracy), "double")
248
249project.constants.export_constexpr_with_type("NumberOfSamples", str(args.samples), "int")
250
251formatted_num_patches = "{{{}}}".format(", ".join(str(val) for val in args.num_patches))
252project.constants.export_const_with_type("NumberOfPatchesToStudy", str(formatted_num_patches), "tarch::la::Vector<%s, int>" % len(args.num_patches))
253
254project.constants.export_constexpr_with_type("NumberOfLaunchingThreads", str(args.num_threads), "int")
255
256if args.fpe:
257 project.constants.export_boolean("EnableFPE", True)
258else:
259 project.constants.export_boolean("EnableFPE", False)
260
261# CPU is enabled by default if neither CPU nor GPU are specified
262if args.cpu == False and args.gpu == False:
263 project.output.makefile.add_CXX_flag("-DASSESS_HOST_KERNELS")
264else:
265 if args.cpu: project.output.makefile.add_CXX_flag("-DASSESS_HOST_KERNELS")
266 if args.gpu: project.output.makefile.add_CXX_flag("-DASSESS_DEVICE_KERNELS")
267
268if args.serial == False and args.parallel == False:
269 project.output.makefile.add_CXX_flag("-DASSESS_SERIAL_KERNELS")
270 project.output.makefile.add_CXX_flag("-DASSESS_PARALLEL_KERNELS")
271else:
272 if args.serial: project.output.makefile.add_CXX_flag("-DASSESS_SERIAL_KERNELS")
273 if args.parallel: project.output.makefile.add_CXX_flag("-DASSESS_PARALLEL_KERNELS")
274
275
276project.constants.export_boolean("EvaluateFlux", True)
277project.constants.export_boolean("EvaluateNonconservativeProduct", False)
278project.constants.export_boolean("EvaluateSource", False)
279project.constants.export_boolean("EvaluateMaximumEigenvalueAfterTimeStep", True if args.eval_eig else False) # Reduction
280
281project.constants.define_value("GAMMA", str(1.0))
282project.constants.define_value("KOSigma", str(8))
283
284benchmark_main_file = "../../kernel-benchmarks/KernelBenchmarksFD4DSL-main.cpp"
285os.system("cp {} KernelBenchmarksFD4DSL-main.cpp".format(benchmark_main_file))
286
287project.output.makefile.add_CXX_flag("-DGRAV=9.81")
288
289# MLIR Integration Support
290if args.enable_mlir:
291 if args.enable_memory_reuse:
292 max_patch_size = (args.patch_size + 6) * (args.patch_size + 6)
293 if args.dimensions == 2:
294 max_patch_size = max_patch_size * 4
295 else:
296 max_patch_size = max_patch_size * 5 * (args.patch_size + 6)
297 else:
298 max_patch_size = -1
299 DSL.set_mlir_environment(project, "FD4", f"euler_physics_{args.dimensions}d.mlir", args.dimensions, args.gpu,
300 args.enable_memref_flattening,
301 args.enable_function_inlining,
302 args.nested_parallel_count,
303 args.enable_imperfect_nested_loops_to_perfect,
304 args.enable_nested_parallel_ops_to_multidimensional,
305 args.enable_omp_tasks,
306 args.omp_task_version,
307 args.omp_single_region,
308 max_patch_size,
309 args.enable_memory_fusion,
310 args.enable_loop_fusion
311 )
312 project.output.makefile.add_CXX_flag("-DASSESS_MLIR_KERNELS")
313
314# CPP is enabled by default if MLIR is not enabled
315if args.enable_cpp or not args.enable_mlir:
316 project.output.makefile.add_CXX_flag("-DASSESS_CPP_KERNELS")
317
318project.build(make=True, make_clean_first=True, throw_away_data_after_build=True, number_of_parallel_builds=args.j)
319
320print(project)
321print(fd4_solver)