9sys.path.insert(1,
"/home/tvwh77/exahype/DSL/ExaHyPE")
10from exahype.frontend
import general_builder
11from exahype.printers
import cpp_printer
15 "Release": peano4.output.CompileMode.Release,
16 "Trace": peano4.output.CompileMode.Trace,
17 "Assert": peano4.output.CompileMode.Asserts,
18 "Stats": peano4.output.CompileMode.Stats,
19 "Debug": peano4.output.CompileMode.Debug,
23parser = argparse.ArgumentParser(
24 description=
"ExaHyPE 2 - Finite Volumes Rusanov Kernel Benchmarking Script"
30 choices=build_modes.keys(),
32 help=
"|".join(build_modes.keys()),
40 help=
"Number of space dimensions",
48 help=
"Number of launching threads",
55 default=[32, 64, 128, 256, 512, 1024, 2048],
57 help=
"Number of patches to study",
65 help=
"Number of finite volumes per axis (dimension) per patch",
73 help=
"Number of samples per measurement",
81 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).",
88 help=
"Evaluate max. eigenvalue",
95 help=
"Evaluate host kernels",
102 help=
"Evaluate device kernels",
109 help=
"Enable a floating-point exception handler",
115 help=
"Do not compile the code after generation",
117args = parser.parse_args()
119if args.dim
not in [2, 3]:
120 print(
"Error, dimension must be 2 or 3, you supplied {}".format(args.dim))
123if args.build_mode
not in build_modes:
125 "Error, mode must be {} or {}, you supplied {}".format(
126 ", ".join(list(build_modes.keys())[:-1]),
127 list(build_modes.keys())[-1],
133accuracy = args.accuracy
137 accuracy = default = numpy.finfo(float).eps
140 "kernel-benchmarks-fv-rusanov-"
143 + str(args.patch_size)
145 + str(args.build_mode)
149kernel = general_builder(dim=args.dim,patch_size=args.patch_size,halo_size=1,n_real=args.dim+2,n_aux=0,n_patches=args.num_patches[0])
151Data = kernel.item(
'patchData',in_type=
'::exahype2::CellData&')
152timer = kernel.const(
'timingComputeKernel',in_type=
'::tarch::timing::Measurement&')
154Q_out = kernel.item(
'QOut',parent=Data)
155Q = kernel.item(
'QIn',parent=Data)
156Q_copy = kernel.item(
'Qcopy')
158tmp_flux = kernel.directional_item(
'tmp_flx')
159tmp_eig = kernel.directional_item(
'tmp_eigen',struct=
False)
160tmp_n = kernel.directional_item(
'tmp_non_conserve_prod',struct=
False)
161avgQ = kernel.directional_item(
'average_Q')
162deltaQ = kernel.directional_item(
'delta_Q')
164dt = kernel.const(
'dt',parent=Data)
165t = kernel.const(
't',parent=Data)
166cellCentre = kernel.const(
'cellCentre',parent=Data)
167cellSize = kernel.const(
'cellSize',parent=Data)
170 normal = kernel.directional_const(
'normal',[0,1])
172 normal = kernel.directional_const(
'normal',[0,1,2])
174Flux = kernel.function(
'flux',parent=
'benchmarks::exahype2::kernelbenchmarks::repositories::instanceOfFVRusanovSolver')
175Eigen = kernel.function(
'maxEigenvalue',parent=
'benchmarks::exahype2::kernelbenchmarks::repositories::instanceOfFVRusanovSolver')
176Max = kernel.function(
'max')
177Centre = kernel.function(
'getVolumeCentre',parent=
'exahype2::fv::')
178Size = kernel.function(
'getVolumeSize',parent=
'exahype2::fv::')
179ncp = kernel.function(
'nonconservativeProduct',parent=
'benchmarks::exahype2::kernelbenchmarks::repositories::instanceOfFVRusanovSolver')
181patch = kernel.all_items[
"patch"]
182patch_size = kernel.all_items[
"patch_size"]
183n_real = kernel.all_items[
"n_real"]
184n_aux = kernel.all_items[
"n_aux"]
185i = kernel.all_items[
"i"]
186j = kernel.all_items[
"j"]
187k = kernel.all_items[
"k"]
190 x =
Centre(cellCentre,cellSize,patch_size,{i,j})
192 x =
Centre(cellCentre,cellSize,patch_size,{i,j,k})
195kernel.single(Q_copy[0],Q[0])
196kernel.directional(tmp_eig[0],
Eigen(Q[0],x,h,t,dt,normal))
197left = -
Max(tmp_eig[-1],tmp_eig[0])*(Q[0]-Q[-1])
198right = -
Max(tmp_eig[1],tmp_eig[0])*(Q[1]-Q[0])
199kernel.directional(Q_copy[0], Q_copy[0] + 0.5*dt*(left-right),struct=
True)
200kernel.directional(
Flux(Q[0],x,h,t,dt,normal,tmp_flux[0]))
201kernel.directional(Q_copy[0], Q_copy[0] + 0.5*dt*(tmp_flux[-1]-tmp_flux[1]))
203kernel.directional(avgQ[0],0.5*(Q[0]+Q[1]))
204kernel.directional(deltaQ[0],Q[1]-Q[0])
205kernel.directional(tmp_n[0],0)
206kernel.directional(
ncp(avgQ[0],deltaQ[0],x,h,t,dt,normal,tmp_n[0]))
207kernel.directional(Q_copy[0], Q_copy[0] + 0.5*dt*(-tmp_n[-1]-tmp_n[0]))
209kernel.single(Q_out[0],Q_copy[0])
211cpp_printer(kernel).file(
'generated_kernel.cpp',header=
'Functions.h')
215 namespace=[
"benchmarks",
"exahype2",
"kernelbenchmarks"],
216 project_name=
"KernelBenchmarksFVRusanov",
218 executable=executable_name,
222 name=
"FVRusanovSolver",
223 patch_size=args.patch_size,
224 unknowns={
"rho": 1,
"v": args.dim,
"e": 1},
225 auxiliary_variables=0,
228 time_step_relaxation=0.5,
229 pde_terms_without_state=
True,
232my_solver.set_implementation(
233 initial_conditions=
"",
234 boundary_conditions=exahype2.solvers.PDETerms.Empty_Implementation,
235 flux=
"::applications::exahype2::euler::flux(Q, normal, F);",
236 eigenvalues=
"return ::applications::exahype2::euler::maxEigenvalue(Q, normal);",
237 refinement_criterion=exahype2.solvers.PDETerms.Empty_Implementation,
242my_solver.add_user_solver_includes(
244#include "../../../../applications/exahype2/euler/EulerKernels.h"
248my_project.add_solver(my_solver)
250my_project.set_global_simulation_parameters(
252 size=[1.0, 1.0, 1.0][0 : args.dim],
253 offset=[0.0, 0.0, 0.0][0 : args.dim],
256 first_plot_time_stamp=0.0,
257 time_in_between_plots=0.0,
258 periodic_BC=[
False,
False,
False],
261my_project.set_Peano4_installation(
"../../../../", mode=build_modes[args.build_mode])
262my_project = my_project.generate_Peano4_project(verbose=
True)
264my_project.output.makefile.add_cpp_file(
"KernelBenchmarksFVRusanov-main.cpp")
266my_project.constants.export_constexpr_with_type(
"Accuracy", str(accuracy),
"double")
267my_project.constants.export_constexpr_with_type(
268 "NumberOfSamples", str(args.samples),
"int"
270formatted_num_patches =
"{{{}}}".format(
", ".join(str(val)
for val
in args.num_patches))
271my_project.constants.export_const_with_type(
272 "NumberOfPatchesToStudy",
273 str(formatted_num_patches),
274 "::tarch::la::Vector<%s, int>" % len(args.num_patches),
276my_project.constants.export_constexpr_with_type(
277 "NumberOfLaunchingThreads", str(args.num_threads),
"int"
287 my_project.constants.export_boolean(
"EnableFPE",
True)
289 my_project.constants.export_boolean(
"EnableFPE",
False)
291my_project.constants.export_boolean(
"EvaluateFlux",
True)
292my_project.constants.export_boolean(
"EvaluateNonconservativeProduct",
False)
293my_project.constants.export_boolean(
"EvaluateSource",
False)
294my_project.constants.export_boolean(
295 "EvaluateMaximumEigenvalueAfterTimeStep",
True if args.eval_eig
else False
298if args.eval_cpu ==
False and args.eval_gpu ==
False:
299 my_project.constants.export_boolean(
"EvaluateHostKernels",
True)
300 my_project.constants.export_boolean(
"EvaluateDeviceKernels",
True)
302 my_project.constants.export_boolean(
303 "EvaluateHostKernels",
True if args.eval_cpu
else False
305 my_project.constants.export_boolean(
306 "EvaluateDeviceKernels",
True if args.eval_gpu
else False
309my_project.constants.define_value(
"GAMMA", str(1.0))
313my_project.output.makefile.add_cpp_file(
"generated_kernel.cpp")
314my_project.output.makefile.add_cpp_file(
"Functions.cpp")
317 make=
not args.no_make, make_clean_first=
True, throw_away_data_after_build=
True
320print(
"Executable is ", executable_name)
321print(
"Clean object files via 'make clean'")
322print(
"Recompile the generated code via 'make -j'")
323print(
"Remove all generated code via 'make distclean'")
324print(
"Regenerate all code by running 'python3 kernel-benchmarks-fv-rusanov.py' again")