Peano
Loading...
Searching...
No Matches
rusanov-with-explicit-euler-kernel-microbenchmark.py
Go to the documentation of this file.
1import os, sys
2import argparse
3import peano4.api
4import exahype2
5from exahype2.api.generators.KernelMicrobenchmarkMain import KernelMicrobenchmarkMain
6
7parser = argparse.ArgumentParser(
8 description="ExaHyPE 2 - RusanovWithExplicitEuler Microbenchmarking Script"
9)
10parser.add_argument(
11 "-ps",
12 "--patch-size",
13 default=16,
14 type=int,
15 help="Number of finite volumes per axis (dimension) per patch.",
16)
17parser.add_argument(
18 "-p",
19 "--num-patches",
20 nargs="+",
21 default=[32, 64, 128, 256, 512, 1024, 2048],
22 type=int,
23 help="Number of patches to study",
24)
25parser.add_argument(
26 "-samples",
27 "--samples",
28 default=10,
29 type=int,
30 help="Number of samples per measurement",
31)
32parser.add_argument(
33 "-a",
34 "--accuracy",
35 default=0.0,
36 type=float,
37 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).",
38)
39parser.add_argument(
40 "-cpu",
41 "--cpu",
42 action="store_true",
43 help="Assess host kernels",
44)
45parser.add_argument(
46 "-gpu",
47 "--gpu",
48 action="store_true",
49 help="Assess device kernels",
50)
51args = parser.parse_args()
52
54 namespace=["exahype2", "fv", "rusanov", "microbenchmark"],
55 project_name="kernel-microbenchmark",
56 directory=".",
57 executable="kernel-microbenchmark",
58)
59solver_name = "EulerFVSmooth"
60
61addition_includes = f"""
62#include "kernels/{solver_name}_rusanov.h"
63"""
64
65function_calls = ""
66if args.cpu == True or args.gpu == False:
67 function_calls += f"""
68 assessKernel(wrapHostKernel<
69 {solver_name}_timeStepWithRusanovStateless<
70 Abstract{solver_name},
71 Abstract{solver_name}::PatchSize,
72 Abstract{solver_name}::HaloSize,
73 Abstract{solver_name}::NumberOfUnknowns,
74 Abstract{solver_name}::NumberOfAuxiliaryVariables
75 >
76 >,
77 "host, AoS, serial, cpp, stateless",
78 launchingThreads,
79 ::tarch::accelerator::Device::HostDevice,
80 localPatches
81 );
82 """
83 function_calls += f"""
84 assessKernel(wrapHostKernel<
85 {solver_name}_timeStepWithRusanov<
86 Abstract{solver_name}::PatchSize,
87 Abstract{solver_name}::HaloSize,
88 Abstract{solver_name}::NumberOfUnknowns,
89 Abstract{solver_name}::NumberOfAuxiliaryVariables
90 >
91 >,
92 "host, AoS, serial, cpp",
93 launchingThreads,
94 ::tarch::accelerator::Device::HostDevice,
95 localPatches
96 );
97 """
98
99
100if args.gpu:
101 function_calls += f"""
102 assessKernel(wrapDeviceKernel<
103 {solver_name}_timeStepWithRusanovStateless<
104 Abstract{solver_name},
105 Abstract{solver_name}::PatchSize,
106 Abstract{solver_name}::HaloSize,
107 Abstract{solver_name}::NumberOfUnknowns,
108 Abstract{solver_name}::NumberOfAuxiliaryVariables
109 >
110 >,
111 "device, AoS, parallel, omp",
112 launchingThreads,
113 0,
114 localPatches
115 );
116 """
117
118project.mainfile_generator = KernelMicrobenchmarkMain(project, function_calls, addition_includes)
119
120unknowns = 4
121auxiliary_variables = 0
122dimensions = 2
123verbosity = peano4.api.LoggerVerbosity.OFF
124
126 solver_name,
127 unknowns,
128 auxiliary_variables,
129)
130
131thesolver.add_user_solver_includes("#include <cmath>\n" "#include <algorithm>\n")
132
133for stateless in [True, False]:
134 thesolver.add_pde_term(
136 implementation="""
137 const double irho = 1.0 / Q[0];
138 constexpr double gamma = 1.4;
139 const double p = (gamma - 1.0) * (Q[3] - 0.5 * irho * (Q[1] * Q[1] + Q[2] * Q[2]));
140
141 switch (normal) {
142 case 0:
143 F[0] = Q[1];
144 F[1] = irho * Q[1] * Q[1] + p;
145 F[2] = irho * Q[1] * Q[2];
146 F[3] = irho * Q[1] * (Q[3] + p);
147 break;
148 case 1:
149 F[0] = Q[2];
150 F[1] = irho * Q[2] * Q[1];
151 F[2] = irho * Q[2] * Q[2] + p;
152 F[3] = irho * Q[2] * (Q[3] + p);
153 break;
154 }
155 """,
156 stateless=stateless,
157 )
158 )
159 thesolver.add_pde_term(
161 implementation="""
162 // Eigenvalues of the Euler flux Jacobian in direction "normal" are
163 // u_n +/- c, where u_n is the *velocity* component (momentum/density),
164 // not the raw momentum component - several earlier ExaHyPE
165 // applications/benchmarks used the raw momentum here by mistake, which
166 // silently gives a wrong (and usually too small) CFL time step bound.
167 const double irho = 1.0 / Q[0];
168 constexpr double gamma = 1.4;
169 const double p = (gamma - 1.0) * (Q[3] - 0.5 * irho * (Q[1] * Q[1] + Q[2] * Q[2]));
170 const double c = gamma * p * irho;
171
172 switch (normal) {
173 case 0:
174 lambdaMax[0] = std::fmax(std::fabs(Q[1] * irho + c), std::fabs(Q[1] * irho - c));
175 break;
176 case 1:
177 lambdaMax[0] = std::fmax(std::fabs(Q[2] * irho + c), std::fabs(Q[2] * irho - c));
178 break;
179 }
180 """,
181 stateless=stateless,
182 )
183 )
184thesolver.add_pde_term(exahype2.api.InitPointWisely(implementation = """
185 constexpr double gamma = 1.4;
186 constexpr double p = 1.0;
187 constexpr double u = 1.0;
188 constexpr double domainLeft = -0.1;
189 constexpr double domainWidth = 0.2;
190 const double rho = 1.0 + 0.2 * std::sin(2.0 * M_PI * (x[0] - domainLeft) / domainWidth);
191 Q[0] = rho;
192 Q[1] = rho * u;
193 Q[2] = 0.0;
194 Q[3] = p / (gamma - 1) + 0.5 * rho * u * u;
195 """,
196 stateless=False,
197 )
198)
199
200thesolver.numerical_scheme = exahype2.api.fv.RusanovWithExplicitEuler(thesolver, args.patch_size)
201solver_variants = []
202if args.cpu == True or args.gpu == False:
203 solver_variants.append((exahype2.api.Target.Serial, True))
204 solver_variants.append((exahype2.api.Target.Serial, False))
205if args.gpu == True:
206 solver_variants.append((exahype2.api.Target.Accelerator, True))
207
208thesolver.numerical_scheme._generator = exahype2.api.fv.RusanovWithExplicitEulerGenerator(thesolver, solver_variants)
210 thesolver, volume_size=0.001
211)
212
213project.add_solver(thesolver)
214
215build_mode = peano4.api.output.CompileMode.RELEASE
216project.set_global_simulation_parameters(
217 dimensions=dimensions,
218 offset=[-0.1, -0.1],
219 size=[0.2, 0.2],
220 min_end_time=0.01,
221 max_end_time=0.01,
222 periodic_BC=[True, True, True],
223)
224
225
226project.set_Peano4_installation("../../../../../", build_mode)
227peano4_project = project.generate_Peano4_project(verbosity=verbosity)
228
229peano4_project.constants.export_constexpr_with_type("Accuracy", str(args.accuracy), "double")
230peano4_project.constants.export_constexpr_with_type("NumberOfSamples", str(args.samples), "int")
231
232formatted_num_patches = "{{{}}}".format(", ".join(str(val) for val in args.num_patches))
233peano4_project.constants.export_const_with_type("NumberOfPatchesToStudy", str(formatted_num_patches), "tarch::la::Vector<%s, int>" % len(args.num_patches))
234peano4_project.constants.export_constexpr_with_type("NumberOfLaunchingThreads", str(1), "int")
235
236peano4_project.generate()
237peano4_project.build(make_clean_first=True)
The conservative flux F(Q) of a hyperbolic PDE.
Definition Flux.py:8
Point-wise initial condition: given the physical position of a single degree of freedom,...
The maximum absolute eigenvalue of the flux Jacobian in a given direction, i.e.
ExaHyPE 2 project.
Definition Project.py:15
Abstract base class for all ExaHyPE 2 solvers.
Definition Solver.py:17
Finite Volumes with a Rusanov Riemann solver and explicit Euler time stepping, realised over a block-...
Setup phase counterpart to RusanovWithExplicitEuler: sets the initial condition for a Finite Volume s...
Optional realisation of exahype2.api.Project.mainfile_generator.