9import exahype2.dslhype
as DSL
11parser = argparse.ArgumentParser(
12 description=
"ExaHyPE 2 - Shallow Water Finite Volume Rusanov 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.",
99 help=
"Number of dimensions to use: 2 or 3",
105 help=
"Enable MLIR kernel compilation support",
111 help=
"Enable CPP kernels",
114 "--enable-memref-flattening",
115 dest=
"enable_memref_flattening",
117 help=
"Enable CPP kernels",
120 "--enable-function-inlining",
121 dest=
"enable_function_inlining",
123 help=
"Enable inlining of Polygeist functions",
126 "--enable-memory-reuse",
127 dest=
"enable_memory_reuse",
129 help=
"Enable reuse of scratchpad memory allocations",
132 "--enable-memory-fusion",
133 dest=
"enable_memory_fusion",
135 help=
"Enable fusion of allocations into one",
138 "--enable-loop-fusion",
139 dest=
"enable_loop_fusion",
141 help=
"Enable fusion of loops with the same bounds",
144 "--enable-imperfect-nested-loops-to-perfect",
145 dest=
"enable_imperfect_nested_loops_to_perfect",
147 help=
"Enable conversion of imperfectly nested parallels into a perfectly nested parallels",
150 "--enable-nested-parallel-ops-to-multidimensional",
151 dest=
"enable_nested_parallel_ops_to_multidimensional",
153 help=
"Enable conversion of nested parallels into a single multidimensional operation",
156 "--enable-omp-tasks",
157 dest=
"enable_omp_tasks",
159 help=
"Enable use of OpenMP tasks as opposed to loop parallelism",
162 "--omp-task-version",
163 choices=[
"task",
"taskloop"],
167 "--omp-single-region",
171 "--nested-parallel-count",
174 help=
"Number of dimensions to use: 2 or 3. Conversion is enabled if the count is positive.",
178 default=
"KernelBenchmarksFVRusanovDSL",
180 help=
"Name of final application",
186 help=
"Number of parallel builds to use",
188args = parser.parse_args()
190fv_rusanov_solver = exahype2.solvers.fv.rusanov.GlobalAdaptiveTimeStepWithEnclaveTasking(
192 patch_size=args.patch_size,
193 unknowns={
"rho": 1,
"u": 1,
"v": 1,
"e": 1}
if args.dimensions == 2
else {
"rho": 1,
"u": 1,
"v": 1,
"w": 1,
"e": 1},
194 auxiliary_variables = {},
197 time_step_relaxation=0.5,
198 pde_terms_without_state=
True
201fv_rusanov_solver.set_implementation(
202 initial_conditions=
"",
203 boundary_conditions=exahype2.solvers.PDETerms.Empty_Implementation,
204 refinement_criterion=exahype2.solvers.PDETerms.Empty_Implementation,
205 flux=
"applications::exahype2::euler::flux(Q, faceCentre, volumeH, t, dt, normal, F);",
207 eigenvalues=
"applications::exahype2::euler::maxEigenvalue(Q, faceCentre, volumeH, t, dt, normal, maxEigenvalue);",
210fv_rusanov_solver.add_user_solver_includes(
212 #include "../../../../applications/exahype2/euler/Euler.h"
216project = exahype2.Project(
217 namespace=[
"benchmarks",
"exahype2",
"kernelbenchmarks"],
218 project_name=
"KernelBenchmarksFVRusanovDSL",
220 executable=f
"{args.o}.{args.build_mode}",
222project.add_solver(fv_rusanov_solver)
224project.set_global_simulation_parameters(
225 dimensions=args.dimensions,
226 size=[1.0] * args.dimensions,
227 offset=[0.0] * args.dimensions,
230 first_plot_time_stamp=0.0,
231 time_in_between_plots=0.0,
232 periodic_BC=[
False] * args.dimensions
235project.set_Peano4_installation(
"../../../../", mode=peano4.api.output.string_to_mode(args.build_mode))
236project = project.generate_Peano4_project(verbose=
True)
238accuracy = args.accuracy
241 accuracy = default = numpy.finfo(float).eps
242project.constants.export_constexpr_with_type(
"Accuracy", str(accuracy),
"double")
244project.constants.export_constexpr_with_type(
"NumberOfSamples", str(args.samples),
"int")
246formatted_num_patches =
"{{{}}}".format(
", ".join(str(val)
for val
in args.num_patches))
247project.constants.export_const_with_type(
"NumberOfPatchesToStudy", str(formatted_num_patches),
"tarch::la::Vector<%s, int>" % len(args.num_patches))
249project.constants.export_constexpr_with_type(
"NumberOfLaunchingThreads", str(args.num_threads),
"int")
252 project.constants.export_boolean(
"EnableFPE",
True)
254 project.constants.export_boolean(
"EnableFPE",
False)
257if args.cpu ==
False and args.gpu ==
False:
258 project.output.makefile.add_CXX_flag(
"-DASSESS_HOST_KERNELS")
260 if args.cpu: project.output.makefile.add_CXX_flag(
"-DASSESS_HOST_KERNELS")
261 if args.gpu: project.output.makefile.add_CXX_flag(
"-DASSESS_DEVICE_KERNELS")
263if args.serial ==
False and args.parallel ==
False:
264 project.output.makefile.add_CXX_flag(
"-DASSESS_SERIAL_KERNELS")
265 project.output.makefile.add_CXX_flag(
"-DASSESS_PARALLEL_KERNELS")
267 if args.serial: project.output.makefile.add_CXX_flag(
"-DASSESS_SERIAL_KERNELS")
268 if args.parallel: project.output.makefile.add_CXX_flag(
"-DASSESS_PARALLEL_KERNELS")
270project.constants.export_boolean(
"EvaluateFlux",
True)
271project.constants.export_boolean(
"EvaluateNonconservativeProduct",
False)
272project.constants.export_boolean(
"EvaluateSource",
False)
273project.constants.export_boolean(
"EvaluateMaximumEigenvalueAfterTimeStep",
True if args.eval_eig
else False)
275project.constants.define_value(
"GAMMA", str(1.0))
277benchmark_main_file =
"../../kernel-benchmarks/KernelBenchmarksFVRusanovDSL-main.cpp"
278os.system(
"cp {} KernelBenchmarksFVRusanovDSL-main.cpp".format(benchmark_main_file))
280project.output.makefile.add_CXX_flag(
"-DGRAV=9.81")
284 if args.enable_memory_reuse:
285 max_patch_size = (args.patch_size + 2) * (args.patch_size + 2)
286 if args.dimensions == 2:
287 max_patch_size = max_patch_size * 4
289 max_patch_size = max_patch_size * 5 * (args.patch_size + 2)
292 DSL.set_mlir_environment(project,
"rusanov", f
"euler_physics_{args.dimensions}d.mlir", args.dimensions, args.gpu,
293 args.enable_memref_flattening,
294 args.enable_function_inlining,
295 args.nested_parallel_count,
296 args.enable_imperfect_nested_loops_to_perfect,
297 args.enable_nested_parallel_ops_to_multidimensional,
298 args.enable_omp_tasks,
299 args.omp_task_version,
300 args.omp_single_region,
302 args.enable_memory_fusion,
303 args.enable_loop_fusion
305 project.output.makefile.add_CXX_flag(
"-DASSESS_MLIR_KERNELS")
308if args.enable_cpp
or not args.enable_mlir:
309 project.output.makefile.add_CXX_flag(
"-DASSESS_CPP_KERNELS")
311project.build(make=
True, make_clean_first=
True, throw_away_data_after_build=
True, number_of_parallel_builds=32)
314print(fv_rusanov_solver)