Peano
Loading...
Searching...
No Matches
kernel-benchmarks-discontinuous-galerkin-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 argparse
5
6import peano4.api
7import exahype2
8import exahype2.dslhype as DSL
9
10parser = argparse.ArgumentParser(
11 description="ExaHyPE 2 - Euler Discontinuous Galerkin Kernel Benchmarking Script"
12)
13parser.add_argument(
14 "-m",
15 "--build-mode",
16 choices=peano4.api.output.CompileModes,
17 default=peano4.api.output.CompileModes[0], # Release
18 help="|".join(peano4.api.output.CompileModes),
19)
20parser.add_argument(
21 "-t",
22 "--num-threads",
23 default=1,
24 type=int,
25 help="Number of launching threads",
26)
27parser.add_argument(
28 "-d",
29 "--dimensions",
30 default=2,
31 type=int,
32 help="Number of Dimensions for patch.",
33)
34parser.add_argument(
35 "-dg",
36 "--dg_order",
37 default=4,
38 type=int,
39 help="Number of finite volumes per axis (dimension) per patch.",
40)
41parser.add_argument(
42 "-p",
43 "--num-patches",
44 nargs="+",
45 default=[32, 64, 128, 256],
46 type=int,
47 help="Number of patches to study",
48)
49parser.add_argument(
50 "-samples",
51 "--samples",
52 default=10,
53 type=int,
54 help="Number of samples per measurement",
55)
56parser.add_argument(
57 "-a",
58 "--accuracy",
59 default=0.0,
60 type=float,
61 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).",
62)
63parser.add_argument(
64 "-e",
65 "--eval-eig",
66 action="store_true",
67 help="Evaluate max. eigenvalue",
68)
69parser.add_argument(
70 "--enable-mlir",
71 dest="enable_mlir",
72 action="store_true",
73 help="Enable MLIR kernel compilation support",
74)
75parser.add_argument(
76 "--enable-cpp",
77 dest="enable_cpp",
78 action="store_true",
79 help="Enable CPP kernels",
80)
81parser.add_argument(
82 "-cpu",
83 "--cpu",
84 action="store_true",
85 help="Assess host kernels",
86)
87parser.add_argument(
88 "-gpu",
89 "--gpu",
90 action="store_true",
91 help="Assess device kernels",
92)
93parser.add_argument(
94 "-serial",
95 "--serial",
96 action="store_true",
97 help="Assess serial kernels",
98)
99parser.add_argument(
100 "-parallel",
101 "--parallel",
102 action="store_true",
103 help="Assess parallel kernels",
104)
105parser.add_argument(
106 "-fpe",
107 "--fpe",
108 action="store_true",
109 help="Enable a floating-point exception handler.",
110)
111parser.add_argument(
112 "-f",
113 "--function",
114 dest="function_to_benchmark",
115 choices=["cellIntegral", "riemannProblem"],
116 default="cellIntegral",
117 help="Set which function to benchmark.",
118)
119
120args = parser.parse_args()
121
122dg_solver = exahype2.solvers.rkdg.rusanov.GlobalAdaptiveTimeStep(
123 name="DG",
124 polynomials=exahype2.solvers.GaussLegendreBasis(args.dg_order),
125 rk_order=1,
126 unknowns={"rho": 1, "u": 1, "v": 1, "w": 1, "e": 1} if args.dimensions == 3 else {"rho": 1, "u": 1, "v": 1, "e": 1},
127 auxiliary_variables = {},
128 min_cell_h=0.001, # max_cell_size -> arbitrary value
129 max_cell_h=0.001, # min_cell_size -> arbitrary value
130 time_step_relaxation=0.5,
131 pde_terms_without_state=True,
132)
133
134dg_solver.set_implementation(
135 initial_conditions="",
136 boundary_conditions=exahype2.solvers.PDETerms.Empty_Implementation,
137 refinement_criterion=exahype2.solvers.PDETerms.Empty_Implementation,
138 flux="applications::exahype2::euler::flux(Q, faceCentre, faceCentre, t, dt, normal, F);",
139 ncp=exahype2.solvers.PDETerms.None_Implementation,
140 eigenvalues="applications::exahype2::euler::maxEigenvalue(Q, faceCentre, faceCentre, t, dt, normal, maxEigenvalue);",
141 source_term=exahype2.solvers.PDETerms.None_Implementation,
142 point_source=exahype2.solvers.PDETerms.None_Implementation
143)
144dg_solver.add_user_solver_includes(
145 """
146 #include "../../../../applications/exahype2/euler/Euler.h"
147 """
148)
149
150project = exahype2.Project(
151 namespace=["benchmarks", "exahype2", "kernelbenchmarks"],
152 project_name="KernelBenchmarksDiscontinuousGalerkinDSL",
153 directory=".",
154 executable=f"KernelBenchmarksDiscontinuousGalerkinDSL.{args.build_mode}",
155)
156project.add_solver(dg_solver)
157
158project.set_global_simulation_parameters(
159 dimensions=args.dimensions,
160 size=[1.0, 1.0] if args.dimensions == 2 else [1.0, 1.0, 1.0],
161 offset=[0.0, 0.0] if args.dimensions == 2 else [0.0, 0.0, 0.0],
162 min_end_time=0.1,
163 max_end_time=0.1,
164 first_plot_time_stamp=0.0,
165 time_in_between_plots=0.0,
166 periodic_BC=[False, False] if args.dimensions == 2 else [False, False, False]
167)
168
169project.set_Peano4_installation("../../../../", mode=peano4.api.output.string_to_mode(args.build_mode))
170project = project.generate_Peano4_project(verbose=True)
171
172accuracy = args.accuracy
173if accuracy < 0:
174 import numpy
175 accuracy = default = numpy.finfo(float).eps
176project.constants.export_constexpr_with_type("Accuracy", str(accuracy), "double")
177
178project.constants.export_constexpr_with_type("NumberOfSamples", str(args.samples), "int")
179
180formatted_num_patches = "{{{}}}".format(", ".join(str(val) for val in args.num_patches))
181project.constants.export_const_with_type("NumberOfPatchesToStudy", str(formatted_num_patches), "tarch::la::Vector<%s, int>" % len(args.num_patches))
182
183project.constants.export_constexpr_with_type("NumberOfLaunchingThreads", str(args.num_threads), "int")
184
185if args.fpe:
186 project.constants.export_boolean("EnableFPE", True)
187else:
188 project.constants.export_boolean("EnableFPE", False)
189
190# CPU is enabled by default if neither CPU nor GPU are specified
191if args.cpu == False and args.gpu == False:
192 project.output.makefile.add_CXX_flag("-DASSESS_HOST_KERNELS")
193else:
194 if args.cpu: project.output.makefile.add_CXX_flag("-DASSESS_HOST_KERNELS")
195 if args.gpu: project.output.makefile.add_CXX_flag("-DASSESS_DEVICE_KERNELS")
196
197if args.serial == False and args.parallel == False:
198 project.output.makefile.add_CXX_flag("-DASSESS_SERIAL_KERNELS")
199 project.output.makefile.add_CXX_flag("-DASSESS_PARALLEL_KERNELS")
200else:
201 if args.serial: project.output.makefile.add_CXX_flag("-DASSESS_SERIAL_KERNELS")
202 if args.parallel: project.output.makefile.add_CXX_flag("-DASSESS_PARALLEL_KERNELS")
203
204project.constants.export_boolean("EvaluateFlux", True)
205project.constants.export_boolean("EvaluateNonconservativeProduct", False)
206project.constants.export_boolean("EvaluateSource", False)
207project.constants.export_boolean("EvaluatePointSources", False)
208project.constants.export_boolean("EvaluateMaximumEigenvalueAfterTimeStep", True if args.eval_eig else False) # Reduction
209
210project.constants.define_value("FluxMacro", "1")
211
212if args.function_to_benchmark == "cellIntegral":
213 project.output.makefile.add_CXX_flag("-DASSESS_CELL_INTEGRAL_KERNELS")
214elif args.function_to_benchmark == "riemannProblem":
215 project.output.makefile.add_CXX_flag("-DASSESS_RIEMANN_PROBLEM_KERNELS")
216
217project.constants.define_value("GAMMA", str(1.0))
218
219benchmark_main_file = "../../kernel-benchmarks/KernelBenchmarksDiscontinuousGalerkinDSL-main.cpp"
220os.system("cp {} KernelBenchmarksDiscontinuousGalerkinDSL-main.cpp".format(benchmark_main_file))
221
222project.output.makefile.add_CXX_flag("-DGRAV=9.81")
223
224# MLIR Integration Support
225if args.enable_mlir:
226 DSL.set_mlir_environment(project, "dg_cellIntegral", f"euler_{args.dimensions}d.mlir", args.dimensions, args.gpu)
227 project.output.makefile.add_CXX_flag("-DASSESS_MLIR_KERNELS")
228
229# CPP is enabled by default if MLIR is not enabled
230if args.enable_cpp or not args.enable_mlir:
231 project.output.makefile.add_CXX_flag("-DASSESS_CPP_KERNELS")
232
233project.build(make=True, make_clean_first=True, throw_away_data_after_build=True)
234
235print(project)
236print(dg_solver)