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