Peano
Loading...
Searching...
No Matches
aderdg-fused.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 sys, os, argparse
4import peano4, exahype2
5
6sys.path.insert(0, os.path.abspath("../../../tests/aderdg"))
7import scenarios
8
9available_scenarios = {
10 "AcousticPlanarWaves": scenarios.AcousticPlanarWaves(dimensions=2),
11 "AdvectionLinear": scenarios.AdvectionLinear(),
12 "ElasticPlanarWaves": scenarios.ElasticPlanarWaves(dimensions=2),
13 "EulerGaussianBell": scenarios.EulerGaussianBell(),
14 "EulerIsentropicVortex": scenarios.EulerIsentropicVortex(),
15 "SWERadialDamBreak": scenarios.SWERadialDamBreak(),
16 "SWERestingLake": scenarios.SWERestingLake(),
17}
18
19parser = argparse.ArgumentParser(
20 description="ExaHyPE 2 - Fused ADER-DG Kernel Benchmarking Script"
21)
22parser.add_argument(
23 "-m",
24 "--build-mode",
25 choices=peano4.output.CompileModes,
26 default=peano4.output.CompileModes[0], # Release
27 help="|".join(peano4.output.CompileModes),
28)
29parser.add_argument(
30 "-t",
31 "--num-threads",
32 type=int,
33 nargs="+",
34 default=[1, 2, 4, 8, 16],
35 help="Number of launching threads",
36)
37parser.add_argument(
38 "-o",
39 "--order",
40 type=int,
41 default=5,
42 help="Order of the underlying ADER-DG solver.",
43)
44parser.add_argument(
45 "-c",
46 "--num-cells",
47 type=int,
48 nargs="+",
49 default=[
50 64,
51 81,
52 128,
53 256,
54 512,
55 729,
56 1024,
57 2048,
58 ], # , 4096, 6561, 16384, 32768, 59049, 65536],
59 help="Number of patches to study",
60)
61parser.add_argument(
62 "-samples",
63 "--samples",
64 type=int,
65 default=10,
66 help="Number of samples per measurement",
67)
68parser.add_argument(
69 "-a",
70 "--accuracy",
71 type=float,
72 default=0.0,
73 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).",
74)
75parser.add_argument(
76 "-cpu",
77 "--cpu",
78 action="store_true",
79 help="Assess host kernels",
80)
81parser.add_argument(
82 "-gpu",
83 "--gpu",
84 action="store_true",
85 help="Assess device kernels",
86)
87parser.add_argument(
88 "-pr",
89 "--precision",
90 choices=["double", "float", "fp16", "bf16"],
91 default="double",
92 help="Precision in which the solver should be computed.",
93)
94parser.add_argument(
95 "-s",
96 "--scenario",
97 choices=available_scenarios.keys(),
98 default="ElasticPlanarWaves",
99 help="Scenario which should be used as a base for the benchmarking",
100)
101parser.add_argument(
102 "-md",
103 "--min-depth",
104 type=int,
105 default=6,
106 help="Determines maximum size of a single cell on each axis.",
107)
108
109args = parser.parse_args()
110
111scenario = available_scenarios[args.scenario]
112
113ader_solver = exahype2.solvers.aderdg.GlobalAdaptiveTimeStep(
114 name="AderSolver",
115 order=args.order,
116 unknowns=scenario._equation.num_unknowns,
117 auxiliary_variables=scenario._equation.num_auxiliary_variables,
118 min_cell_h=0.001, # max_cell_size -> arbitrary value
119 max_cell_h=0.001, # min_cell_size -> arbitrary value
120 time_step_relaxation=0.5,
121)
122
123ader_solver.add_kernel_optimisations(
124 polynomials=exahype2.solvers.aderdg.Polynomials.Gauss_Legendre,
125 is_linear=scenario._equation.is_linear,
126 precision=args.precision,
127)
128
129ader_solver.set_implementation(
130 initial_conditions=scenario.initial_conditions(),
131 boundary_conditions=scenario.boundary_conditions(),
132 max_eigenvalue=scenario._equation.eigenvalues(),
133 flux=scenario._equation.flux(),
134 ncp=scenario._equation.ncp(),
135 riemann_solver=scenario._equation.riemann_solver(),
136)
137
138project = exahype2.Project(
139 namespace=["benchmarks", "exahype2", "kernelbenchmarks"],
140 project_name="KernelBenchmarks",
141 directory=".",
142 executable="KernelBenchmarks",
143)
144project.add_solver(ader_solver)
145
146project.set_global_simulation_parameters(
147 dimensions=2,
148 size=[1.0, 1.0],
149 offset=[0.0, 0.0],
150 min_end_time=0.1,
151 max_end_time=0.1,
152 first_plot_time_stamp=0.0,
153 time_in_between_plots=0.0,
154 periodic_BC=[False, False],
155)
156
157project.set_build_mode(mode=peano4.output.string_to_mode(args.build_mode))
158project = project.generate_Peano4_project(verbose=False)
159
160accuracy = args.accuracy
161if accuracy < 0:
162 import numpy
163
164 accuracy = default = numpy.finfo(float).eps
165project.constants.export_constexpr_with_type("Accuracy", str(accuracy), "double")
166
167project.constants.export_constexpr_with_type(
168 "NumberOfSamples", str(args.samples), "int"
169)
170
171formatted_num_cells = "{{{}}}".format(", ".join(str(val) for val in args.num_cells))
172project.constants.export_const_with_type(
173 "NumberOfCellsToStudy",
174 str(formatted_num_cells),
175 "tarch::la::Vector<%s, int>" % len(args.num_cells),
176)
177
178formatted_num_threads = "{{{}}}".format(", ".join(str(val) for val in args.num_threads))
179project.constants.export_const_with_type(
180 "NumberOfLaunchingThreads",
181 str(formatted_num_threads),
182 "tarch::la::Vector<%s, int>" % len(args.num_threads),
183)
184
185if args.cpu == False and args.gpu == False:
186 project.constants.export_boolean("AssessHostKernels", True)
187 project.constants.export_boolean("AssessDeviceKernels", True)
188else:
189 project.constants.export_boolean("AssessHostKernels", True if args.cpu else False)
190 project.constants.export_boolean("AssessDeviceKernels", True if args.gpu else False)
191
192makefile = project.output.makefile
193
194makefile.add_CXX_flag("-DSolverPrecision=" + args.precision)
195
196for i in range(1, 7):
197 makefile.add_cpp_file("Variant" + str(i) + ".cpp")
198makefile.add_h_file("Variants.h")
199makefile.add_cpp_file("KernelBenchmarks-main.cpp")
200
201project.build(make=True, make_clean_first=True, throw_away_data_after_build=True)
Scenario reproduced from Dumbser & Käser, https://doi.org/10.1111/j.1365-246X.2006....
Very simple scenario in which the initial value of x is shifted in each spatial dimension.
Scenario reproduced from Dumbser & Käser, https://doi.org/10.1111/j.1365-246X.2006....
Scenario reproduced from Ioratti, Dumbser & Loubère, https://doi.org/10.1007/s10915-020-01209-w (p.
Scenario reproduced from Ioratti, Dumbser & Loubère, https://doi.org/10.1007/s10915-020-01209-w (p.
Classic radial dam break SWE equations, with constant initial water height but a bump in the bathymet...
Resting lake scenario for the shallow water equations.