Peano
Loading...
Searching...
No Matches
kernel-benchmarks-fv-rusanov-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 - Shallow Water Finite Volume Rusanov 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)
93parser.add_argument(
94 "-d",
95 "--dimensions",
96 default=2,
97 choices = [2, 3],
98 type=int,
99 help="Number of dimensions to use: 2 or 3",
100)
101parser.add_argument(
102 "--enable-mlir",
103 dest="enable_mlir",
104 action="store_true",
105 help="Enable MLIR kernel compilation support",
106)
107parser.add_argument(
108 "--enable-cpp",
109 dest="enable_cpp",
110 action="store_true",
111 help="Enable CPP kernels",
112)
113parser.add_argument(
114 "--enable-memref-flattening",
115 dest="enable_memref_flattening",
116 action="store_true",
117 help="Enable CPP kernels",
118)
119parser.add_argument(
120 "--enable-function-inlining",
121 dest="enable_function_inlining",
122 action="store_true",
123 help="Enable inlining of Polygeist functions",
124)
125parser.add_argument(
126 "--enable-memory-reuse",
127 dest="enable_memory_reuse",
128 action="store_true",
129 help="Enable reuse of scratchpad memory allocations",
130)
131parser.add_argument(
132 "--enable-memory-fusion",
133 dest="enable_memory_fusion",
134 action="store_true",
135 help="Enable fusion of allocations into one",
136)
137parser.add_argument(
138 "--enable-loop-fusion",
139 dest="enable_loop_fusion",
140 action="store_true",
141 help="Enable fusion of loops with the same bounds",
142)
143parser.add_argument(
144 "--enable-imperfect-nested-loops-to-perfect",
145 dest="enable_imperfect_nested_loops_to_perfect",
146 action="store_true",
147 help="Enable conversion of imperfectly nested parallels into a perfectly nested parallels",
148)
149parser.add_argument(
150 "--enable-nested-parallel-ops-to-multidimensional",
151 dest="enable_nested_parallel_ops_to_multidimensional",
152 action="store_true",
153 help="Enable conversion of nested parallels into a single multidimensional operation",
154)
155parser.add_argument(
156 "--enable-omp-tasks",
157 dest="enable_omp_tasks",
158 action="store_true",
159 help="Enable use of OpenMP tasks as opposed to loop parallelism",
160)
161parser.add_argument(
162 "--omp-task-version",
163 choices=["task", "taskloop"],
164 default="taskloop"
165)
166parser.add_argument(
167 "--omp-single-region",
168 action="store_true",
169)
170parser.add_argument(
171 "--nested-parallel-count",
172 default=-1,
173 type=int,
174 help="Number of dimensions to use: 2 or 3. Conversion is enabled if the count is positive.",
175)
176parser.add_argument(
177 "-o",
178 default="KernelBenchmarksFVRusanovDSL",
179 type=str,
180 help="Name of final application",
181)
182parser.add_argument(
183 "-j",
184 default=-1,
185 type=int,
186 help="Number of parallel builds to use",
187)
188args = parser.parse_args()
189
190fv_rusanov_solver = exahype2.solvers.fv.rusanov.GlobalAdaptiveTimeStepWithEnclaveTasking(
191 name="FVRusanov",
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 = {},
195 min_volume_h=0.001, # max_cell_size -> arbitrary value
196 max_volume_h=0.001, # min_cell_size -> arbitrary value
197 time_step_relaxation=0.5,
198 pde_terms_without_state=True
199)
200
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);",
206 ncp=None,
207 eigenvalues="applications::exahype2::euler::maxEigenvalue(Q, faceCentre, volumeH, t, dt, normal, maxEigenvalue);",
208 source_term=None
209)
210fv_rusanov_solver.add_user_solver_includes(
211 """
212 #include "../../../../applications/exahype2/euler/Euler.h"
213 """
214)
215
216project = exahype2.Project(
217 namespace=["benchmarks", "exahype2", "kernelbenchmarks"],
218 project_name="KernelBenchmarksFVRusanovDSL",
219 directory=".",
220 executable=f"{args.o}.{args.build_mode}",
221)
222project.add_solver(fv_rusanov_solver)
223
224project.set_global_simulation_parameters(
225 dimensions=args.dimensions,
226 size=[1.0] * args.dimensions,
227 offset=[0.0] * args.dimensions,
228 min_end_time=0.1,
229 max_end_time=0.1,
230 first_plot_time_stamp=0.0,
231 time_in_between_plots=0.0,
232 periodic_BC=[False] * args.dimensions
233)
234
235project.set_Peano4_installation("../../../../", mode=peano4.api.output.string_to_mode(args.build_mode))
236project = project.generate_Peano4_project(verbose=True)
237
238accuracy = args.accuracy
239if accuracy < 0:
240 import numpy
241 accuracy = default = numpy.finfo(float).eps
242project.constants.export_constexpr_with_type("Accuracy", str(accuracy), "double")
243
244project.constants.export_constexpr_with_type("NumberOfSamples", str(args.samples), "int")
245
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))
248
249project.constants.export_constexpr_with_type("NumberOfLaunchingThreads", str(args.num_threads), "int")
250
251if args.fpe:
252 project.constants.export_boolean("EnableFPE", True)
253else:
254 project.constants.export_boolean("EnableFPE", False)
255
256# CPU is enabled by default if neither CPU nor GPU are specified
257if args.cpu == False and args.gpu == False:
258 project.output.makefile.add_CXX_flag("-DASSESS_HOST_KERNELS")
259else:
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")
262
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")
266else:
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")
269
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) # Reduction
274
275project.constants.define_value("GAMMA", str(1.0))
276
277benchmark_main_file = "../../kernel-benchmarks/KernelBenchmarksFVRusanovDSL-main.cpp"
278os.system("cp {} KernelBenchmarksFVRusanovDSL-main.cpp".format(benchmark_main_file))
279
280project.output.makefile.add_CXX_flag("-DGRAV=9.81")
281
282# MLIR Integration Support
283if args.enable_mlir:
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
288 else:
289 max_patch_size = max_patch_size * 5 * (args.patch_size + 2)
290 else:
291 max_patch_size = -1
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,
301 max_patch_size,
302 args.enable_memory_fusion,
303 args.enable_loop_fusion
304 )
305 project.output.makefile.add_CXX_flag("-DASSESS_MLIR_KERNELS")
306
307# CPP is enabled by default if MLIR is not enabled
308if args.enable_cpp or not args.enable_mlir:
309 project.output.makefile.add_CXX_flag("-DASSESS_CPP_KERNELS")
310
311project.build(make=True, make_clean_first=True, throw_away_data_after_build=True, number_of_parallel_builds=32)
312
313print(project)
314print(fv_rusanov_solver)
315