Peano
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
3 import sys, os, argparse
4 import peano4, exahype2
5 
6 sys.path.insert(0, os.path.abspath("../../../../tests/exahype2/aderdg"))
7 import scenarios
8 
9 available_scenarios = {
10  "AcousticPlanarWaves": scenarios.AcousticPlanarWaves(dimensions=2),
11  "AdvectionLinear": scenarios.AdvectionLinear(),
12  "ElasticPlanarWaves": scenarios.ElasticPlanarWaves(dimensions=2),
13  "EulerGaussianBell": scenarios.EulerGaussianBell(),
14  "EulerIsotropicVortex": scenarios.EulerIsotropicVortex(),
15  "SWERadialDamBreak": scenarios.SWERadialDamBreak(),
16  "SWERestingLake": scenarios.SWERestingLake(),
17 }
18 
19 parser = argparse.ArgumentParser(
20  description="ExaHyPE 2 - Fused ADER-DG Kernel Benchmarking Script"
21 )
22 parser.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 )
29 parser.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 )
37 parser.add_argument(
38  "-o",
39  "--order",
40  type=int,
41  default=5,
42  help="Order of the underlying ADER-DG solver.",
43 )
44 parser.add_argument(
45  "-c",
46  "--num-cells",
47  type=int,
48  nargs="+",
49  default=[64, 81, 128, 256, 512, 729, 1024, 2048],#, 4096, 6561, 16384, 32768, 59049, 65536],
50  help="Number of patches to study",
51 )
52 parser.add_argument(
53  "-samples",
54  "--samples",
55  type=int,
56  default=10,
57  help="Number of samples per measurement",
58 )
59 parser.add_argument(
60  "-a",
61  "--accuracy",
62  type=float,
63  default=0.0,
64  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).",
65 )
66 parser.add_argument(
67  "-cpu",
68  "--cpu",
69  action="store_true",
70  help="Assess host kernels",
71 )
72 parser.add_argument(
73  "-gpu",
74  "--gpu",
75  action="store_true",
76  help="Assess device kernels",
77 )
78 parser.add_argument(
79  "-fpe",
80  "--fpe",
81  action="store_true",
82  help="Enable a floating-point exception handler.",
83 )
84 parser.add_argument(
85  "-pr",
86  "--precision",
87  choices=["double", "float", "fp16", "bf16"],
88  default="double",
89  help="Precision in which the solver should be computed.",
90 )
91 parser.add_argument(
92  "-s",
93  "--scenario",
94  choices=available_scenarios.keys(),
95  default="ElasticPlanarWaves",
96  help="Scenario which should be used as a base for the benchmarking",
97 )
98 
99 args = parser.parse_args()
100 
101 scenario = available_scenarios[args.scenario]
102 
103 ader_solver = exahype2.solvers.aderdg.GlobalAdaptiveTimeStep(
104  name="AderSolver",
105  order=args.order,
106  unknowns=scenario._equation.num_unknowns,
107  auxiliary_variables=scenario._equation.num_auxiliary_variables,
108  min_cell_h=0.001, # max_cell_size -> arbitrary value
109  max_cell_h=0.001, # min_cell_size -> arbitrary value
110  time_step_relaxation=0.5,
111 )
112 
113 ader_solver.add_kernel_optimisations(
114  polynomials=exahype2.solvers.aderdg.Polynomials.Gauss_Legendre,
115  is_linear=scenario._equation.is_linear,
116  precision=args.precision,
117 )
118 
119 ader_solver.set_implementation(
120  initial_conditions=scenario.initial_conditions(),
121  boundary_conditions=scenario.boundary_conditions(),
122  max_eigenvalue=scenario._equation.eigenvalues(),
123  flux=scenario._equation.flux(),
124  ncp=scenario._equation.ncp(),
125  riemann_solver=scenario._equation.riemann_solver(),
126 )
127 
128 project = exahype2.Project(
129  namespace=["benchmarks", "exahype2", "kernelbenchmarks"],
130  project_name="KernelBenchmarks",
131  directory=".",
132  executable="KernelBenchmarks",
133 )
134 project.add_solver(ader_solver)
135 
136 project.set_global_simulation_parameters(
137  dimensions=2,
138  size=[1.0, 1.0],
139  offset=[0.0, 0.0],
140  min_end_time=0.1,
141  max_end_time=0.1,
142  first_plot_time_stamp=0.0,
143  time_in_between_plots=0.0,
144  periodic_BC=[False, False],
145 )
146 
147 project.set_Peano4_installation(
148  "../../../../", mode=peano4.output.string_to_mode(args.build_mode)
149 )
150 project = project.generate_Peano4_project(verbose=False)
151 
152 accuracy = args.accuracy
153 if accuracy < 0:
154  import numpy
155 
156  accuracy = default = numpy.finfo(float).eps
157 project.constants.export_constexpr_with_type("Accuracy", str(accuracy), "double")
158 
159 project.constants.export_constexpr_with_type(
160  "NumberOfSamples", str(args.samples), "int"
161 )
162 
163 formatted_num_cells = "{{{}}}".format(", ".join(str(val) for val in args.num_cells))
164 project.constants.export_const_with_type(
165  "NumberOfCellsToStudy",
166  str(formatted_num_cells),
167  "tarch::la::Vector<%s, int>" % len(args.num_cells),
168 )
169 
170 formatted_num_threads = "{{{}}}".format(", ".join(str(val) for val in args.num_threads))
171 project.constants.export_const_with_type(
172  "NumberOfLaunchingThreads", str(formatted_num_threads),
173  "tarch::la::Vector<%s, int>" % len(args.num_threads),
174 )
175 
176 if args.fpe:
177  project.constants.export_boolean("EnableFPE", True)
178 else:
179  project.constants.export_boolean("EnableFPE", False)
180 
181 if args.cpu == False and args.gpu == False:
182  project.constants.export_boolean("AssessHostKernels", True)
183  project.constants.export_boolean("AssessDeviceKernels", True)
184 else:
185  project.constants.export_boolean("AssessHostKernels", True if args.cpu else False)
186  project.constants.export_boolean("AssessDeviceKernels", True if args.gpu else False)
187 
188 makefile = project.output.makefile
189 
190 makefile.add_CXX_flag("-DSolverPrecision="+args.precision)
191 
192 for i in range(1, 7):
193  makefile.add_cpp_file("Variant" + str(i) + ".cpp")
194 makefile.add_h_file("Variants.h")
195 makefile.add_cpp_file("KernelBenchmarks-main.cpp")
196 
197 project.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.
str
Definition: ccz4.py:55