Peano
Loading...
Searching...
No Matches
kernel-benchmarks-fv-rusanov-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
8
9parser = argparse.ArgumentParser(
10 description="ExaHyPE 2 - Acoustic Finite Volume Rusanov Kernel Benchmarking Script"
11)
12parser.add_argument(
13 "-m",
14 "--build-mode",
15 choices=peano4.api.output.CompileModes,
16 default=peano4.api.output.CompileModes[0], # Release
17 help="|".join(peano4.api.output.CompileModes),
18)
19parser.add_argument(
20 "-t",
21 "--num-threads",
22 default=1,
23 type=int,
24 help="Number of launching threads",
25)
26parser.add_argument(
27 "-ps",
28 "--patch-size",
29 default=16,
30 type=int,
31 help="Number of finite volumes per axis (dimension) per patch.",
32)
33parser.add_argument(
34 "-p",
35 "--num-patches",
36 nargs="+",
37 default=[32, 64, 128, 256],
38 type=int,
39 help="Number of patches to study",
40)
41parser.add_argument(
42 "-samples",
43 "--samples",
44 default=10,
45 type=int,
46 help="Number of samples per measurement",
47)
48parser.add_argument(
49 "-a",
50 "--accuracy",
51 default=0.0,
52 type=float,
53 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).",
54)
55parser.add_argument(
56 "-e",
57 "--eval-eig",
58 action="store_true",
59 help="Evaluate max. eigenvalue",
60)
61parser.add_argument(
62 "-cpu",
63 "--cpu",
64 action="store_true",
65 help="Assess host kernels",
66)
67parser.add_argument(
68 "-gpu",
69 "--gpu",
70 action="store_true",
71 help="Assess device kernels",
72)
73parser.add_argument(
74 "-serial",
75 "--serial",
76 action="store_true",
77 help="Assess serial kernels",
78)
79parser.add_argument(
80 "-parallel",
81 "--parallel",
82 action="store_true",
83 help="Assess parallel kernels",
84)
85parser.add_argument(
86 "-fpe",
87 "--fpe",
88 action="store_true",
89 help="Enable a floating-point exception handler.",
90)
91
92args = parser.parse_args()
93
94fv_rusanov_solver = exahype2.solvers.fv.rusanov.GlobalAdaptiveTimeStepWithEnclaveTasking(
95 name="FVRusanov",
96 patch_size=args.patch_size,
97 unknowns={"p": 1, "u": 1, "v": 1},
98 auxiliary_variables = {},
99 min_volume_h=0.001, # max_cell_size -> arbitrary value
100 max_volume_h=0.001, # min_cell_size -> arbitrary value
101 time_step_relaxation=0.5,
102 pde_terms_without_state=True,
103)
104
105fv_rusanov_solver.set_implementation(
106 initial_conditions="",
107 boundary_conditions=exahype2.solvers.PDETerms.Empty_Implementation,
108 refinement_criterion=exahype2.solvers.PDETerms.Empty_Implementation,
109 flux="applications::exahype2::acoustic::flux(Q, faceCentre, volumeH, t, dt, normal, F);",
110 ncp="",
111 eigenvalues="applications::exahype2::acoustic::maxEigenvalue(Q, faceCentre, volumeH, t, dt, normal, maxEigenvalue);",
112 source_term="applications::exahype2::acoustic::sourceTerm(Q, volumeCentre, volumeH, t, dt, S);",
113)
114fv_rusanov_solver.add_user_solver_includes(
115 """
116 #include "../../../../applications/exahype2/acoustic/Acoustic.h"
117 """
118)
119
120project = exahype2.Project(
121 namespace=["benchmarks", "exahype2", "kernelbenchmarks"],
122 project_name="KernelBenchmarksFVRusanovDSL",
123 directory=".",
124 executable=f"KernelBenchmarksFVRusanovDSL.{args.build_mode}",
125)
126project.add_solver(fv_rusanov_solver)
127
128project.set_global_simulation_parameters(
129 dimensions=2,
130 size=[1.0, 1.0],
131 offset=[0.0, 0.0],
132 min_end_time=0.1,
133 max_end_time=0.1,
134 first_plot_time_stamp=0.0,
135 time_in_between_plots=0.0,
136 periodic_BC=[False, False]
137)
138
139project.set_Peano4_installation("../../../../", mode=peano4.api.output.string_to_mode(args.build_mode))
140project = project.generate_Peano4_project(verbose=True)
141
142accuracy = args.accuracy
143if accuracy < 0:
144 import numpy
145 accuracy = default = numpy.finfo(float).eps
146project.constants.export_constexpr_with_type("Accuracy", str(accuracy), "double")
147
148project.constants.export_constexpr_with_type("NumberOfSamples", str(args.samples), "int")
149
150formatted_num_patches = "{{{}}}".format(", ".join(str(val) for val in args.num_patches))
151project.constants.export_const_with_type("NumberOfPatchesToStudy", str(formatted_num_patches), "tarch::la::Vector<%s, int>" % len(args.num_patches))
152
153project.constants.export_constexpr_with_type("NumberOfLaunchingThreads", str(args.num_threads), "int")
154
155if args.fpe:
156 project.constants.export_boolean("EnableFPE", True)
157else:
158 project.constants.export_boolean("EnableFPE", False)
159
160# CPU is enabled by default if neither CPU nor GPU are specified
161if args.cpu == False and args.gpu == False:
162 project.output.makefile.add_CXX_flag("-DASSESS_HOST_KERNELS")
163else:
164 if args.cpu: project.output.makefile.add_CXX_flag("-DASSESS_HOST_KERNELS")
165 if args.gpu: project.output.makefile.add_CXX_flag("-DASSESS_DEVICE_KERNELS")
166
167if args.serial == False and args.parallel == False:
168 project.output.makefile.add_CXX_flag("-DASSESS_SERIAL_KERNELS")
169 project.output.makefile.add_CXX_flag("-DASSESS_PARALLEL_KERNELS")
170else:
171 if args.serial: project.output.makefile.add_CXX_flag("-DASSESS_SERIAL_KERNELS")
172 if args.parallel: project.output.makefile.add_CXX_flag("-DASSESS_PARALLEL_KERNELS")
173
174project.output.makefile.add_CXX_flag("-DASSESS_CPP_KERNELS")
175
176project.constants.export_boolean("EvaluateFlux", True)
177project.constants.export_boolean("EvaluateNonconservativeProduct", False)
178project.constants.export_boolean("EvaluateSource", True)
179project.constants.export_boolean("EvaluateMaximumEigenvalueAfterTimeStep", True if args.eval_eig else False) # Reduction
180
181project.constants.define_value("RHO", str(1.0))
182project.constants.define_value("WAVE_SPEED", str(1.0))
183project.constants.define_value("SIGMA", str(1.0))
184
185benchmark_main_file = "../../kernel-benchmarks/KernelBenchmarksFVRusanovDSL-main.cpp"
186os.system("cp {} KernelBenchmarksFVRusanovDSL-main.cpp".format(benchmark_main_file))
187
188project.build(make=True, make_clean_first=True, throw_away_data_after_build=True)
189
190print(project)
191print(fv_rusanov_solver)