9import exahype2.dslhype
as DSL
11parser = argparse.ArgumentParser(
12 description=
"ExaHyPE 2 - Euler FD4 Kernel Benchmarking Script"
17 choices=peano4.api.output.CompileModes,
18 default=peano4.api.output.CompileModes[0],
19 help=
"|".join(peano4.api.output.CompileModes),
26 help=
"Number of launching threads",
33 help=
"Number of finite volumes per axis (dimension) per patch.",
39 default=[32, 64, 128, 256],
41 help=
"Number of patches to study",
48 help=
"Number of samples per measurement",
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).",
61 help=
"Evaluate max. eigenvalue",
67 help=
"Assess host kernels",
73 help=
"Assess device kernels",
79 help=
"Assess serial kernels",
85 help=
"Assess parallel kernels",
91 help=
"Enable a floating-point exception handler.",
100 help=
"Number of dimensions to use: 3",
106 help=
"Enable MLIR kernel compilation support",
112 help=
"Enable CPP kernels",
115 "--enable-memref-flattening",
116 dest=
"enable_memref_flattening",
118 help=
"Enable CPP kernels",
121 "--enable-function-inlining",
122 dest=
"enable_function_inlining",
124 help=
"Enable inlining of Polygeist functions",
127 "--enable-memory-reuse",
128 dest=
"enable_memory_reuse",
130 help=
"Enable reuse of scratchpad memory allocations",
133 "--enable-memory-fusion",
134 dest=
"enable_memory_fusion",
136 help=
"Enable fusion of allocations into one",
139 "--enable-loop-fusion",
140 dest=
"enable_loop_fusion",
142 help=
"Enable fusion of loops with the same bounds",
145 "--enable-imperfect-nested-loops-to-perfect",
146 dest=
"enable_imperfect_nested_loops_to_perfect",
148 help=
"Enable conversion of imperfectly nested parallels into a perfectly nested parallels",
151 "--enable-nested-parallel-ops-to-multidimensional",
152 dest=
"enable_nested_parallel_ops_to_multidimensional",
154 help=
"Enable conversion of nested parallels into a single multidimensional operation",
157 "--enable-omp-tasks",
158 dest=
"enable_omp_tasks",
160 help=
"Enable use of OpenMP tasks as opposed to loop parallelism",
163 "--omp-task-version",
164 choices=[
"task",
"taskloop"],
168 "--omp-single-region",
172 "--nested-parallel-count",
175 help=
"Number of dimensions to use: 2 or 3. Conversion is enabled if the count is positive.",
179 default=
"KernelBenchmarksFD4DSL",
181 help=
"Name of final application",
187 help=
"Number of parallel builds to use",
190args = parser.parse_args()
192fd4_solver = exahype2.solvers.rkfd.fd4.GlobalAdaptiveTimeStepWithEnclaveTasking(
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,
198 max_meshcell_h=0.001,
199 time_step_relaxation=0.5,
201 pde_terms_without_state=
True
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);",
210 eigenvalues=
"applications::exahype2::euler::maxEigenvalue(Q, faceCentre, gridCellH, t, dt, normal, maxEigenvalue);",
213fd4_solver.add_user_solver_includes(
215 #include "../../../../applications/exahype2/euler/Euler.h"
218exahype2.solvers.rkfd.fd4.switch_to_FD4_second_order_interpolation(fd4_solver)
219exahype2.solvers.rkfd.fd4.switch_to_FD4_second_order_restriction(fd4_solver)
221project = exahype2.Project(
222 namespace=[
"benchmarks",
"exahype2",
"kernelbenchmarks"],
223 project_name=
"KernelBenchmarksFD4DSL",
225 executable=f
"{args.o}.{args.build_mode}",
227project.add_solver(fd4_solver)
229project.set_global_simulation_parameters(
230 dimensions=args.dimensions,
231 size=[1.0] * args.dimensions,
232 offset=[0.0] * args.dimensions,
235 first_plot_time_stamp=0.0,
236 time_in_between_plots=0.0,
237 periodic_BC=[
False] * args.dimensions
240project.set_Peano4_installation(
"../../../../", mode=peano4.api.output.string_to_mode(args.build_mode))
241project = project.generate_Peano4_project(verbose=
True)
243accuracy = args.accuracy
246 accuracy = default = numpy.finfo(float).eps
247project.constants.export_constexpr_with_type(
"Accuracy", str(accuracy),
"double")
249project.constants.export_constexpr_with_type(
"NumberOfSamples", str(args.samples),
"int")
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))
254project.constants.export_constexpr_with_type(
"NumberOfLaunchingThreads", str(args.num_threads),
"int")
257 project.constants.export_boolean(
"EnableFPE",
True)
259 project.constants.export_boolean(
"EnableFPE",
False)
262if args.cpu ==
False and args.gpu ==
False:
263 project.output.makefile.add_CXX_flag(
"-DASSESS_HOST_KERNELS")
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")
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")
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")
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)
281project.constants.define_value(
"GAMMA", str(1.0))
282project.constants.define_value(
"KOSigma", str(8))
284benchmark_main_file =
"../../kernel-benchmarks/KernelBenchmarksFD4DSL-main.cpp"
285os.system(
"cp {} KernelBenchmarksFD4DSL-main.cpp".format(benchmark_main_file))
287project.output.makefile.add_CXX_flag(
"-DGRAV=9.81")
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
296 max_patch_size = max_patch_size * 5 * (args.patch_size + 6)
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,
309 args.enable_memory_fusion,
310 args.enable_loop_fusion
312 project.output.makefile.add_CXX_flag(
"-DASSESS_MLIR_KERNELS")
315if args.enable_cpp
or not args.enable_mlir:
316 project.output.makefile.add_CXX_flag(
"-DASSESS_CPP_KERNELS")
318project.build(make=
True, make_clean_first=
True, throw_away_data_after_build=
True, number_of_parallel_builds=args.j)