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
5import exagrype
6from exahype2.api.generators.KernelMicrobenchmarkMain import KernelMicrobenchmarkMain
7from applications import set_euler_pde_terms
8
9parser = argparse.ArgumentParser(
10 description="ExaHyPE 2 - RusanovWithExplicitEuler Microbenchmarking Script"
11)
12parser.add_argument(
13 "--application",
14 type=str,
15 choices=["euler", "ccz4"],
16 required=True,
17 help="Which application should be microbenchmarked",
18)
19parser.add_argument(
20 "-d",
21 "--dimensions",
22 default=3,
23 type=int,
24 choices=[2,3],
25 help="Number of spatial dimensions.",
26)
27parser.add_argument(
28 "-ps",
29 "--patch-size",
30 default=16,
31 type=int,
32 help="Number of finite volumes per axis (dimension) per patch.",
33)
34parser.add_argument(
35 "-p",
36 "--num-patches",
37 nargs="+",
38 default=[32, 64, 128, 256, 512, 1024, 2048],
39 type=int,
40 help="Number of patches to study",
41)
42parser.add_argument(
43 "-samples",
44 "--samples",
45 default=10,
46 type=int,
47 help="Number of samples per measurement",
48)
49parser.add_argument(
50 "-a",
51 "--accuracy",
52 default=0.0,
53 type=float,
54 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).",
55)
56parser.add_argument(
57 "-cpu",
58 "--cpu",
59 action="store_true",
60 help="Assess host kernels",
61)
62parser.add_argument(
63 "-gpu",
64 "--gpu",
65 action="store_true",
66 help="Assess device kernels",
67)
68args = parser.parse_args()
69
71 namespace=["exahype2", "fv", "rusanov", "microbenchmark"],
72 project_name="kernel-microbenchmark",
73 directory=".",
74 executable="kernel-microbenchmark",
75)
76solver_name = "EulerFVSmooth"
77
78addition_includes = f"""
79#include "kernels/{solver_name}_rusanov.h"
80"""
81
82function_calls = ""
83if args.cpu == True or args.gpu == False:
84 function_calls += f"""
85 assessKernel(wrapHostKernel<
86 cpp::nested::{solver_name}_timeStepWithRusanovStateless<
87 Abstract{solver_name}
88 >
89 >,
90 "host, AoSNested, serial, cpp, stateless",
91 launchingThreads,
92 ::tarch::accelerator::Device::HostDevice,
93 localPatches
94 );
95 """
96 function_calls += f"""
97 assessKernel(wrapFlattenedHostKernel<
98 cpp::cell_data_flattened_temporaries_nested::{solver_name}_timeStepWithRusanovStateless<
99 Abstract{solver_name}
100 >
101 >,
102 "host, AoS_CellDataFlattened_TemporariesNested, serial, cpp, stateless",
103 launchingThreads,
104 ::tarch::accelerator::Device::HostDevice,
105 localPatches
106 );
107 """
108 function_calls += f"""
109 assessKernel(wrapHostKernel<
110 cpp::cell_data_nested_temporaries_flattened::{solver_name}_timeStepWithRusanovStateless<
111 Abstract{solver_name}
112 >
113 >,
114 "host, AoS_CellDataNested_TemporariesFlattened, serial, cpp, stateless",
115 launchingThreads,
116 ::tarch::accelerator::Device::HostDevice,
117 localPatches
118 );
119 """
120 function_calls += f"""
121 assessKernel(wrapFlattenedHostKernel<
122 cpp::flattened::{solver_name}_timeStepWithRusanovStateless<
123 Abstract{solver_name}
124 >
125 >,
126 "host, AoSFlattened, serial, cpp, stateless",
127 launchingThreads,
128 ::tarch::accelerator::Device::HostDevice,
129 localPatches
130 );
131 """
132 function_calls += f"""
133 assessKernel(wrapMLIRNestedHostKernel<
134 mlir::nested::{solver_name}_timeStepWithRusanovStateless
135 >,
136 "host, AoSNested, serial, mlir, stateless",
137 launchingThreads,
138 ::tarch::accelerator::Device::HostDevice,
139 localPatches
140 );
141 """
142 function_calls += f"""
143 assessKernel(wrapMLIRFlattenedHostKernel<
144 mlir::cell_data_flattened_temporaries_nested::{solver_name}_timeStepWithRusanovStateless
145 >,
146 "host, AoS_CellDataFlattened_TemporariesNested, serial, mlir, stateless",
147 launchingThreads,
148 ::tarch::accelerator::Device::HostDevice,
149 localPatches
150 );
151 """
152 function_calls += f"""
153 assessKernel(wrapMLIRNestedHostKernel<
154 mlir::cell_data_nested_temporaries_flattened::{solver_name}_timeStepWithRusanovStateless
155 >,
156 "host, AoS_CellDataNested_TemporariesFlattened, serial, mlir, stateless",
157 launchingThreads,
158 ::tarch::accelerator::Device::HostDevice,
159 localPatches
160 );
161 """
162 function_calls += f"""
163 assessKernel(wrapMLIRFlattenedHostKernel<
164 mlir::flattened::{solver_name}_timeStepWithRusanovStateless
165 >,
166 "host, AoSFlattened, serial, mlir, stateless",
167 launchingThreads,
168 ::tarch::accelerator::Device::HostDevice,
169 localPatches
170 );
171 """
172
173
174
175if args.gpu:
176 function_calls += f"""
177 assessKernel(wrapDeviceKernel<
178 cpp::flattened::{solver_name}_timeStepWithRusanovStateless<
179 Abstract{solver_name}
180 >
181 >,
182 "device, AoS, parallel, omp",
183 launchingThreads,
184 0,
185 localPatches
186 );
187 """
188
189project.mainfile_generator = KernelMicrobenchmarkMain(project, function_calls, addition_includes)
190
191verbosity = peano4.api.LoggerVerbosity.OFF
192
193
194if args.application == "euler":
195 unknowns = 2 + args.dimensions
197 solver_name,
198 unknowns,
199 )
200 thesolver.add_user_solver_includes("#include <cmath>\n" "#include <algorithm>\n")
201
202 for stateless in [True, False]:
203 set_euler_pde_terms(thesolver, args.dimensions, stateless)
204
205 thesolver.add_pde_term(exahype2.api.InitPointWisely(implementation = """
206 constexpr double gamma = 1.4;
207 constexpr double p = 1.0;
208 constexpr double u = 1.0;
209 constexpr double domainLeft = -0.1;
210 constexpr double domainWidth = 0.2;
211 const double rho = 0.2 * std::sin(2.0 * M_PI * (x[0] - domainLeft) / domainWidth);
212 Q[0] = rho;
213 Q[1] = rho * u;
214 Q[2] = 0.0;
215 #if Dimensions == 2
216 Q[3] = p / (gamma - 1) + 0.5 * rho * u * u;
217 #else
218 Q[3] = 0.0;
219 Q[4] = p / (gamma - 1) + 0.5 * rho * u * u;
220 #endif
221 """,
222 stateless=False,
223 )
224 )
225
226elif args.application == "ccz4":
227 thesolver = exagrype.api.FOCCZ4Solver(solver_name)
228
229thesolver.numerical_scheme = exahype2.api.fv.RusanovWithExplicitEuler(thesolver, args.patch_size)
230solver_variants = []
231if args.cpu == True or args.gpu == False:
232 solver_variants.append((exahype2.api.Target.Serial, True, exahype2.api.OutputLanguage.CPP, exahype2.api.MemoryLayout.AoS_AllNested))
233 solver_variants.append((exahype2.api.Target.Serial, True, exahype2.api.OutputLanguage.CPP, exahype2.api.MemoryLayout.AoS_CellDataFlattened_TemporariesNested))
234 solver_variants.append((exahype2.api.Target.Serial, True, exahype2.api.OutputLanguage.CPP, exahype2.api.MemoryLayout.AoS_CellDataNested_TemporariesFlattened))
235 solver_variants.append((exahype2.api.Target.Serial, True, exahype2.api.OutputLanguage.CPP, exahype2.api.MemoryLayout.AoS_AllFlattened))
236
237 solver_variants.append((exahype2.api.Target.Serial, True, exahype2.api.OutputLanguage.MLIR, exahype2.api.MemoryLayout.AoS_AllNested))
238 solver_variants.append((exahype2.api.Target.Serial, True, exahype2.api.OutputLanguage.MLIR, exahype2.api.MemoryLayout.AoS_CellDataFlattened_TemporariesNested))
239 solver_variants.append((exahype2.api.Target.Serial, True, exahype2.api.OutputLanguage.MLIR, exahype2.api.MemoryLayout.AoS_CellDataNested_TemporariesFlattened))
240 solver_variants.append((exahype2.api.Target.Serial, True, exahype2.api.OutputLanguage.MLIR, exahype2.api.MemoryLayout.AoS_AllFlattened))
241if args.gpu == True:
242 solver_variants.append((exahype2.api.Target.Accelerator, True, exahype2.api.OutputLanguage.CPP, exahype2.api.MemoryLayout.AoS_AllFlattened))
243
244thesolver.numerical_scheme._generator = exahype2.api.fv.RusanovWithExplicitEulerGenerator(thesolver, solver_variants)
246 thesolver, volume_size=0.001
247)
248
249project.add_solver(thesolver)
250
251build_mode = peano4.api.output.CompileMode.RELEASE
252project.set_global_simulation_parameters(
253 dimensions=args.dimensions,
254 offset=[-0.1, -0.1] if args.dimensions == 2 else [-0.1, -0.1, -0.1],
255 size=[0.2, 0.2] if args.dimensions == 2 else [0.2, 0.2, 0.2],
256 min_end_time=0.01,
257 max_end_time=0.01,
258 periodic_BC=[True, True, True],
259)
260
261
262project.set_Peano4_installation("../../../../../", build_mode)
263peano4_project = project.generate_Peano4_project(verbosity=verbosity)
264
265peano4_project.constants.export_constexpr_with_type("Accuracy", str(args.accuracy), "double")
266peano4_project.constants.export_constexpr_with_type("NumberOfSamples", str(args.samples), "int")
267
268formatted_num_patches = "{{{}}}".format(", ".join(str(val) for val in args.num_patches))
269peano4_project.constants.export_const_with_type("NumberOfPatchesToStudy", str(formatted_num_patches), "tarch::la::Vector<%s, int>" % len(args.num_patches))
270peano4_project.constants.export_constexpr_with_type("NumberOfLaunchingThreads", str(1), "int")
271
272peano4_project.output.makefile.add_CXX_flag("-MD")
273peano4_project.generate()
274peano4_project.build(make_clean_first=False)
Solver for the Einstein equations in the first-order CCZ4 formulation.
Point-wise initial condition: given the physical position of a single degree of freedom,...
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.