Peano
Loading...
Searching...
No Matches
kernels.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
3from exahype2.solvers.PDETerms import PDETerms
4
5import jinja2
6
7from enum import Enum
8import os
9import exahype2
10import exahype2.dslhype as DSL
11
12from exahype2.solvers.rkfd.kernels import SolverVariant
13from exahype2.solvers.rkfd.kernels import KernelVariant
14
16 template_parameters = [DSL.SyntaxTree.Argument("NC", DSL.SyntaxTree.TInteger()),
17 DSL.SyntaxTree.Argument("H", DSL.SyntaxTree.TInteger()),
18 DSL.SyntaxTree.Argument("NumberOfUnknowns", DSL.SyntaxTree.TInteger()),
19 DSL.SyntaxTree.Argument("NumberOfAuxiliaryVariables", DSL.SyntaxTree.TInteger()),
20 DSL.SyntaxTree.Argument("KOsigma", DSL.SyntaxTree.TInteger()),
21 DSL.SyntaxTree.Argument("EvaluateFlux", DSL.SyntaxTree.TBoolean()),
22 DSL.SyntaxTree.Argument("EvaluateNonconservativeProduct", DSL.SyntaxTree.TBoolean()),
23 DSL.SyntaxTree.Argument("EvaluateSource", DSL.SyntaxTree.TBoolean()),
24 DSL.SyntaxTree.Argument("copyOldTimeStepAndScaleWithTimeStepSize", DSL.SyntaxTree.TBoolean()), #not use actually
25 DSL.SyntaxTree.Argument("SecondOrderFormulation", DSL.SyntaxTree.TBoolean()),
26 DSL.SyntaxTree.Argument("FirstOrderFormulation", DSL.SyntaxTree.TBoolean())]
27
28 functor_arguments = [DSL.SyntaxTree.Argument("flux", DSL.SyntaxTree.TCustom("const Flux&")),
29 DSL.SyntaxTree.Argument("nonconservativeProduct", DSL.SyntaxTree.TCustom("const NonconservativeProduct&")),
30 DSL.SyntaxTree.Argument("sourceTerm", DSL.SyntaxTree.TCustom("const Source&"))]
31
32 FD4InExaGRyPE_tree = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.timeStepWithFD4InExaGRyPE, template_parameters, functor_arguments, ["exahype2", "fd", "fd4"])
33 FD4InExaGRyPE_kernel = FD4InExaGRyPE_tree.print_cpp()
34 FD4InExaGRyPE_call_with_measurement = FD4InExaGRyPE_tree.print_definition_with_timer()
35 FD4InExaGRyPE_kernel_declaration = FD4InExaGRyPE_tree.print_declaration()
36 FD4InExaGRyPE_call_with_measurement_declaration = FD4InExaGRyPE_tree.print_declaration_with_timer()
37
38 FD4InExaGRyPE_stateless_tree = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.timeStepWithFD4InExaGRyPE, template_parameters, functor_arguments, ["exahype2", "fd", "fd4"], stateless=True)
39 FD4InExaGRyPE_stateless_kernel = FD4InExaGRyPE_stateless_tree.print_cpp()
40 FD4InExaGRyPE_stateless_call_with_measurement = FD4InExaGRyPE_stateless_tree.print_definition_with_timer()
41 FD4InExaGRyPE_stateless_kernel_declaration = FD4InExaGRyPE_stateless_tree.print_declaration()
42 FD4InExaGRyPE_stateless_call_with_measurement_declaration = FD4InExaGRyPE_stateless_tree.print_declaration_with_timer()
43
44 #FD4InExaGRyPE_accelerator_tree = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.timeStepWithFD4InExaGRyPE, template_parameters, functor_arguments, ["exahype2", "fd", "fd4"], True, True).print_cpp()
45 #FD4InExaGRyPE_accelerator_kernel = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.timeStepWithFD4InExaGRyPE, template_parameters, functor_arguments, ["exahype2", "fd", "fd4"], True, True).print_cpp()
46 #FD4InExaGRyPE_accelerator_call_with_measurement = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.timeStepWithFD4InExaGRyPE, template_parameters, functor_arguments, ["exahype2", "fd", "fd4"], True, True).print_definition_with_timer()
47 #FD4InExaGRyPE_accelerator_kernel_declaration = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.timeStepWithFD4InExaGRyPE, template_parameters, functor_arguments, ["exahype2", "fd", "fd4"], True, True).print_declaration()
48 #FD4InExaGRyPE_accelerator_call_with_measurement_declaration = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.timeStepWithFD4InExaGRyPE, template_parameters, functor_arguments, ["exahype2", "fd", "fd4"], True, True).print_declaration_with_timer()
49
50 FD4InExaGRyPE_omp_tree = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.timeStepWithFD4InExaGRyPE, template_parameters, functor_arguments, ["exahype2", "fd", "fd4", "omp"])
51 FD4InExaGRyPE_omp_kernel = FD4InExaGRyPE_omp_tree.print_omp()
52 FD4InExaGRyPE_omp_call_with_measurement = FD4InExaGRyPE_omp_tree.print_definition_with_timer()
53 FD4InExaGRyPE_omp_kernel_declaration = FD4InExaGRyPE_omp_tree.print_declaration()
54 FD4InExaGRyPE_omp_call_with_measurement_declaration = FD4InExaGRyPE_omp_tree.print_declaration_with_timer()
55
56 FD4InExaGRyPE_omp_stateless_tree = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.timeStepWithFD4InExaGRyPE, template_parameters, functor_arguments, ["exahype2", "fd", "fd4", "omp"], stateless=True)
57 FD4InExaGRyPE_omp_stateless_kernel = FD4InExaGRyPE_omp_stateless_tree.print_omp()
58 FD4InExaGRyPE_omp_stateless_call_with_measurement = FD4InExaGRyPE_omp_stateless_tree.print_definition_with_timer()
59 FD4InExaGRyPE_omp_stateless_kernel_declaration = FD4InExaGRyPE_omp_stateless_tree.print_declaration()
60 FD4InExaGRyPE_omp_stateless_call_with_measurement_declaration = FD4InExaGRyPE_omp_stateless_tree.print_declaration_with_timer()
61
62 FD4InExaGRyPE_omp_accelerator_tree = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.timeStepWithFD4InExaGRyPE, template_parameters, functor_arguments, ["exahype2", "fd", "fd4", "omp"], stateless=True, use_accelerator=True)
63 FD4InExaGRyPE_omp_accelerator_kernel = FD4InExaGRyPE_omp_accelerator_tree.print_omp()
64 FD4InExaGRyPE_omp_accelerator_call_with_measurement = FD4InExaGRyPE_omp_accelerator_tree.print_definition_with_timer()
65 FD4InExaGRyPE_omp_accelerator_kernel_declaration = FD4InExaGRyPE_omp_accelerator_tree.print_declaration()
66 FD4InExaGRyPE_omp_accelerator_call_with_measurement_declaration = FD4InExaGRyPE_omp_accelerator_tree.print_declaration_with_timer()
67
68 FD4InExaGRyPE_sycl_accelerator_tree = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.timeStepWithFD4InExaGRyPE, template_parameters, functor_arguments, ["exahype2", "fd", "fd4", "sycl"], stateless=True, use_accelerator=True)
69 FD4InExaGRyPE_sycl_accelerator_kernel = FD4InExaGRyPE_sycl_accelerator_tree.print_sycl()
70 FD4InExaGRyPE_sycl_accelerator_call_with_measurement = FD4InExaGRyPE_sycl_accelerator_tree.print_definition_with_timer()
71 FD4InExaGRyPE_sycl_accelerator_kernel_declaration = FD4InExaGRyPE_sycl_accelerator_tree.print_declaration()
72 FD4InExaGRyPE_sycl_accelerator_call_with_measurement_declaration = FD4InExaGRyPE_sycl_accelerator_tree.print_declaration_with_timer()
73
74 template_parameters = [DSL.SyntaxTree.Argument("NC", DSL.SyntaxTree.TInteger()),
75 DSL.SyntaxTree.Argument("NumberOfUnknowns", DSL.SyntaxTree.TInteger()),
76 DSL.SyntaxTree.Argument("RKOrder", DSL.SyntaxTree.TInteger())]
77 functor_arguments = [DSL.SyntaxTree.Argument("RKWeights", DSL.SyntaxTree.TCustom("const double*"))]
78
79 ComputeLinearCombination_omp_accelerator_tree = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.ComputeLinearCombination, template_parameters, functor_arguments, ["exahype2", "fd", "fd4", "omp"], stateless=True, use_accelerator=True)
80 ComputeLinearCombination_omp_accelerator_kernel = ComputeLinearCombination_omp_accelerator_tree.print_omp()
81 ComputeLinearCombination_omp_accelerator_call_with_measurement = ComputeLinearCombination_omp_accelerator_tree.print_definition_with_timer()
82 ComputeLinearCombination_omp_accelerator_kernel_declaration = ComputeLinearCombination_omp_accelerator_tree.print_declaration()
83 ComputeLinearCombination_omp_accelerator_call_with_measurement_declaration = ComputeLinearCombination_omp_accelerator_tree.print_declaration_with_timer()
84
85 if not os.path.exists("kernels"):
86 os.makedirs("kernels")
87
88 file = open("kernels/FD4InExaGRyPE.h", "w")
89 file.write(f"""#pragma once
90#include "exahype2/CellData.h"
91#include "exahype2/VolumeIndex.h"
92#include "exahype2/fd/PatchUtils.h"
93#include "exahype2/fd/Functors.h"
94#include "peano4/utils/Loop.h"
95#include "tarch/timing/Measurement.h"
96#include "tarch/timing/Watch.h"
97
98{FD4InExaGRyPE_kernel_declaration}
99{FD4InExaGRyPE_call_with_measurement_declaration}
100{FD4InExaGRyPE_stateless_kernel_declaration}
101{FD4InExaGRyPE_stateless_call_with_measurement_declaration}
102
103#if defined(SharedOMP)
104{FD4InExaGRyPE_omp_kernel_declaration}
105{FD4InExaGRyPE_omp_call_with_measurement_declaration}
106{FD4InExaGRyPE_omp_stateless_kernel_declaration}
107{FD4InExaGRyPE_omp_stateless_call_with_measurement_declaration}
108#endif
109
110#if defined(GPUOffloadingOMP)
111{FD4InExaGRyPE_omp_accelerator_kernel_declaration}
112{FD4InExaGRyPE_omp_accelerator_call_with_measurement_declaration}
113{ComputeLinearCombination_omp_accelerator_kernel_declaration}
114{ComputeLinearCombination_omp_accelerator_call_with_measurement_declaration}
115#endif
116
117#if defined(GPUOffloadingSYCL)
118{FD4InExaGRyPE_sycl_accelerator_kernel_declaration}
119{FD4InExaGRyPE_sycl_accelerator_call_with_measurement_declaration}
120#endif
121
122#include "FD4InExaGRyPE.cpph"
123""")
124 file.close()
125
126 file = open("kernels/FD4InExaGRyPE.cpph", "w")
127 file.write(FD4InExaGRyPE_kernel)
128 file.write(FD4InExaGRyPE_call_with_measurement)
129 file.write(FD4InExaGRyPE_stateless_kernel)
130 file.write(FD4InExaGRyPE_stateless_call_with_measurement)
131
132 file.write("#if defined(SharedOMP)\n")
133 file.write(FD4InExaGRyPE_omp_kernel)
134 file.write(FD4InExaGRyPE_omp_call_with_measurement)
135 file.write(FD4InExaGRyPE_omp_stateless_kernel)
136 file.write(FD4InExaGRyPE_omp_stateless_call_with_measurement)
137 file.write("#endif\n")
138
139 file.write("#if defined(GPUOffloadingOMP)\n")
140 file.write(FD4InExaGRyPE_omp_accelerator_kernel)
141 file.write(FD4InExaGRyPE_omp_accelerator_call_with_measurement)
142 file.write(ComputeLinearCombination_omp_accelerator_kernel)
143 file.write(ComputeLinearCombination_omp_accelerator_call_with_measurement)
144 file.write("#endif\n")
145
146 file.write("#if defined(GPUOffloadingSYCL)\n")
147 file.write(FD4InExaGRyPE_sycl_accelerator_kernel)
148 file.write(FD4InExaGRyPE_sycl_accelerator_call_with_measurement)
149 file.write("#endif\n")
150 file.close()
151
153 template_parameters = [DSL.SyntaxTree.Argument("NC", DSL.SyntaxTree.TInteger()),
154 DSL.SyntaxTree.Argument("H", DSL.SyntaxTree.TInteger()),
155 DSL.SyntaxTree.Argument("NumberOfUnknowns", DSL.SyntaxTree.TInteger()),
156 DSL.SyntaxTree.Argument("NumberOfAuxiliaryVariables", DSL.SyntaxTree.TInteger()),
157 DSL.SyntaxTree.Argument("SecondOrderFormulation", DSL.SyntaxTree.TBoolean())]
158
159 functor_arguments = []
160
161 DeriCallInExaGRyPE_tree = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.DerivativesCalInExaGRyPE, template_parameters, functor_arguments, ["exahype2", "fd", "fd4"])
162 DeriCallInExaGRyPE_kernel = DeriCallInExaGRyPE_tree.print_cpp()
163 DeriCallInExaGRyPE_call_with_measurement = DeriCallInExaGRyPE_tree.print_definition_with_timer()
164 DeriCallInExaGRyPE_kernel_declaration = DeriCallInExaGRyPE_tree.print_declaration()
165 DeriCallInExaGRyPE_call_with_measurement_declaration = DeriCallInExaGRyPE_tree.print_declaration_with_timer()
166
167 DeriCallInExaGRyPE_stateless_tree = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.DerivativesCalInExaGRyPE, template_parameters, functor_arguments, ["exahype2", "fd", "fd4"], stateless=True)
168 DeriCallInExaGRyPE_stateless_kernel = DeriCallInExaGRyPE_stateless_tree.print_cpp()
169 DeriCallInExaGRyPE_stateless_call_with_measurement = DeriCallInExaGRyPE_stateless_tree.print_definition_with_timer()
170 DeriCallInExaGRyPE_stateless_kernel_declaration = DeriCallInExaGRyPE_stateless_tree.print_declaration()
171 DeriCallInExaGRyPE_stateless_call_with_measurement_declaration = DeriCallInExaGRyPE_stateless_tree.print_declaration_with_timer()
172
173 #DeriCallInExaGRyPE_accelerator_tree = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.DerivativesCalInExaGRyPE, template_parameters, functor_arguments, ["exahype2", "fd", "fd4"], True, True).print_cpp()
174 #DeriCallInExaGRyPE_accelerator_kernel = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.DerivativesCalInExaGRyPE, template_parameters, functor_arguments, ["exahype2", "fd", "fd4"], True, True).print_cpp()
175 #DeriCallInExaGRyPE_accelerator_call_with_measurement = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.DerivativesCalInExaGRyPE, template_parameters, functor_arguments, ["exahype2", "fd", "fd4"], True, True).print_definition_with_timer()
176 #DeriCallInExaGRyPE_accelerator_kernel_declaration = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.DerivativesCalInExaGRyPE, template_parameters, functor_arguments, ["exahype2", "fd", "fd4"], True, True).print_declaration()
177 #DeriCallInExaGRyPE_accelerator_call_with_measurement_declaration = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.DerivativesCalInExaGRyPE, template_parameters, functor_arguments, ["exahype2", "fd", "fd4"], True, True).print_declaration_with_timer()
178
179 DeriCallInExaGRyPE_omp_tree = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.DerivativesCalInExaGRyPE, template_parameters, functor_arguments, ["exahype2", "fd", "fd4", "omp"])
180 DeriCallInExaGRyPE_omp_kernel = DeriCallInExaGRyPE_omp_tree.print_omp()
181 DeriCallInExaGRyPE_omp_call_with_measurement = DeriCallInExaGRyPE_omp_tree.print_definition_with_timer()
182 DeriCallInExaGRyPE_omp_kernel_declaration = DeriCallInExaGRyPE_omp_tree.print_declaration()
183 DeriCallInExaGRyPE_omp_call_with_measurement_declaration = DeriCallInExaGRyPE_omp_tree.print_declaration_with_timer()
184
185 DeriCallInExaGRyPE_omp_stateless_tree = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.DerivativesCalInExaGRyPE, template_parameters, functor_arguments, ["exahype2", "fd", "fd4", "omp"], stateless=True)
186 DeriCallInExaGRyPE_omp_stateless_kernel = DeriCallInExaGRyPE_omp_stateless_tree.print_omp()
187 DeriCallInExaGRyPE_omp_stateless_call_with_measurement = DeriCallInExaGRyPE_omp_stateless_tree.print_definition_with_timer()
188 DeriCallInExaGRyPE_omp_stateless_kernel_declaration = DeriCallInExaGRyPE_omp_stateless_tree.print_declaration()
189 DeriCallInExaGRyPE_omp_stateless_call_with_measurement_declaration = DeriCallInExaGRyPE_omp_stateless_tree.print_declaration_with_timer()
190
191 DeriCallInExaGRyPE_omp_accelerator_tree = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.DerivativesCalInExaGRyPE, template_parameters, functor_arguments, ["exahype2", "fd", "fd4", "omp"], stateless=True, use_accelerator=True)
192 DeriCallInExaGRyPE_omp_accelerator_kernel = DeriCallInExaGRyPE_omp_accelerator_tree.print_omp()
193 DeriCallInExaGRyPE_omp_accelerator_call_with_measurement = DeriCallInExaGRyPE_omp_accelerator_tree.print_definition_with_timer()
194 DeriCallInExaGRyPE_omp_accelerator_kernel_declaration = DeriCallInExaGRyPE_omp_accelerator_tree.print_declaration()
195 DeriCallInExaGRyPE_omp_accelerator_call_with_measurement_declaration = DeriCallInExaGRyPE_omp_accelerator_tree.print_declaration_with_timer()
196
197 DeriCallInExaGRyPE_sycl_accelerator_tree = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.DerivativesCalInExaGRyPE, template_parameters, functor_arguments, ["exahype2", "fd", "fd4", "sycl"], stateless=True, use_accelerator=True)
198 DeriCallInExaGRyPE_sycl_accelerator_kernel = DeriCallInExaGRyPE_sycl_accelerator_tree.print_sycl()
199 DeriCallInExaGRyPE_sycl_accelerator_call_with_measurement = DeriCallInExaGRyPE_sycl_accelerator_tree.print_definition_with_timer()
200 DeriCallInExaGRyPE_sycl_accelerator_kernel_declaration = DeriCallInExaGRyPE_sycl_accelerator_tree.print_declaration()
201 DeriCallInExaGRyPE_sycl_accelerator_call_with_measurement_declaration = DeriCallInExaGRyPE_sycl_accelerator_tree.print_declaration_with_timer()
202
203 template_parameters = [DSL.SyntaxTree.Argument("NC", DSL.SyntaxTree.TInteger()),
204 DSL.SyntaxTree.Argument("NumberOfUnknowns", DSL.SyntaxTree.TInteger()),
205 DSL.SyntaxTree.Argument("RKOrder", DSL.SyntaxTree.TInteger())]
206 functor_arguments = [DSL.SyntaxTree.Argument("RKWeights", DSL.SyntaxTree.TCustom("const double*"))]
207
208 ComputeLinearCombination_omp_accelerator_tree = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.ComputeLinearCombination, template_parameters, functor_arguments, ["exahype2", "fd", "fd4", "omp"], stateless=True, use_accelerator=True)
209 ComputeLinearCombination_omp_accelerator_kernel = ComputeLinearCombination_omp_accelerator_tree.print_omp()
210 ComputeLinearCombination_omp_accelerator_call_with_measurement = ComputeLinearCombination_omp_accelerator_tree.print_definition_with_timer()
211 ComputeLinearCombination_omp_accelerator_kernel_declaration = ComputeLinearCombination_omp_accelerator_tree.print_declaration()
212 ComputeLinearCombination_omp_accelerator_call_with_measurement_declaration = ComputeLinearCombination_omp_accelerator_tree.print_declaration_with_timer()
213
214 if not os.path.exists("kernels"):
215 os.makedirs("kernels")
216
217 file = open("kernels/DeriCallInExaGRyPE.h", "w")
218 file.write(f"""#pragma once
219#include "exahype2/CellData.h"
220#include "exahype2/VolumeIndex.h"
221#include "exahype2/fd/PatchUtils.h"
222#include "exahype2/fd/Functors.h"
223#include "peano4/utils/Loop.h"
224#include "tarch/timing/Measurement.h"
225#include "tarch/timing/Watch.h"
226
227{DeriCallInExaGRyPE_kernel_declaration}
228{DeriCallInExaGRyPE_call_with_measurement_declaration}
229{DeriCallInExaGRyPE_stateless_kernel_declaration}
230{DeriCallInExaGRyPE_stateless_call_with_measurement_declaration}
231
232#if defined(SharedOMP)
233{DeriCallInExaGRyPE_omp_kernel_declaration}
234{DeriCallInExaGRyPE_omp_call_with_measurement_declaration}
235{DeriCallInExaGRyPE_omp_stateless_kernel_declaration}
236{DeriCallInExaGRyPE_omp_stateless_call_with_measurement_declaration}
237#endif
238
239#if defined(GPUOffloadingOMP)
240{DeriCallInExaGRyPE_omp_accelerator_kernel_declaration}
241{DeriCallInExaGRyPE_omp_accelerator_call_with_measurement_declaration}
242{ComputeLinearCombination_omp_accelerator_kernel_declaration}
243{ComputeLinearCombination_omp_accelerator_call_with_measurement_declaration}
244#endif
245
246#if defined(GPUOffloadingSYCL)
247{DeriCallInExaGRyPE_sycl_accelerator_kernel_declaration}
248{DeriCallInExaGRyPE_sycl_accelerator_call_with_measurement_declaration}
249#endif
250
251#include "DeriCallInExaGRyPE.cpph"
252""")
253 file.close()
254
255 file = open("kernels/DeriCallInExaGRyPE.cpph", "w")
256 file.write(DeriCallInExaGRyPE_kernel)
257 file.write(DeriCallInExaGRyPE_call_with_measurement)
258 file.write(DeriCallInExaGRyPE_stateless_kernel)
259 file.write(DeriCallInExaGRyPE_stateless_call_with_measurement)
260
261 file.write("#if defined(SharedOMP)\n")
262 file.write(DeriCallInExaGRyPE_omp_kernel)
263 file.write(DeriCallInExaGRyPE_omp_call_with_measurement)
264 file.write(DeriCallInExaGRyPE_omp_stateless_kernel)
265 file.write(DeriCallInExaGRyPE_omp_stateless_call_with_measurement)
266 file.write("#endif\n")
267
268 file.write("#if defined(GPUOffloadingOMP)\n")
269 file.write(DeriCallInExaGRyPE_omp_accelerator_kernel)
270 file.write(DeriCallInExaGRyPE_omp_accelerator_call_with_measurement)
271 file.write(ComputeLinearCombination_omp_accelerator_kernel)
272 file.write(ComputeLinearCombination_omp_accelerator_call_with_measurement)
273 file.write("#endif\n")
274
275 file.write("#if defined(GPUOffloadingSYCL)\n")
276 file.write(DeriCallInExaGRyPE_sycl_accelerator_kernel)
277 file.write(DeriCallInExaGRyPE_sycl_accelerator_call_with_measurement)
278 file.write("#endif\n")
279 file.close()
280
281def create_FD4_kernel_definitions_3d(patch_size, unknowns, auxiliary_variables, ko_sigma, flux_implementation, ncp_implementation, source_term_implementation, compute_max_eigenvalue_of_next_time_step):
282 template_parameters = [DSL.SyntaxTree.Argument("NC", DSL.SyntaxTree.TInteger(), "applications::exahype2::ccz4::AbstractCCZ4"),
283 DSL.SyntaxTree.Argument("H", DSL.SyntaxTree.TInteger(), "applications::exahype2"),
284 DSL.SyntaxTree.Argument("NumberOfUnknowns", DSL.SyntaxTree.TInteger(), "applications::exahype2::ccz4::AbstractCCZ4"),
285 DSL.SyntaxTree.Argument("NumberOfAuxiliaryVariables", DSL.SyntaxTree.TInteger(), "applications::exahype2::ccz4::AbstractCCZ4"),
286 DSL.SyntaxTree.Argument("KOsigma", DSL.SyntaxTree.TInteger(), "applications::exahype2::ccz4::AbstractCCZ4"),
287 DSL.SyntaxTree.Argument("EvaluateFlux", DSL.SyntaxTree.TBoolean(), "applications::exahype2::ccz4"),
288 DSL.SyntaxTree.Argument("EvaluateNonconservativeProduct", DSL.SyntaxTree.TBoolean(), "applications::exahype2::ccz4"),
289 DSL.SyntaxTree.Argument("EvaluateSource", DSL.SyntaxTree.TBoolean(), "applications::exahype2::ccz4"),
290 DSL.SyntaxTree.Argument("copyOldTimeStepAndScaleWithTimeStepSize", DSL.SyntaxTree.TBoolean())] #not use actually
291
292 functor_arguments = [DSL.SyntaxTree.Argument("flux", DSL.SyntaxTree.TCustom("const Flux&"), "(!llvm.ptr, !llvm.ptr, !llvm.ptr, f64, f64, i32, !llvm.ptr) -> ()", is_function=True),
293 DSL.SyntaxTree.Argument("nonconservativeProduct", DSL.SyntaxTree.TCustom("const NonconservativeProduct&"), "(!llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, f64, f64, i32, !llvm.ptr) -> ()", is_function=True),
294 DSL.SyntaxTree.Argument("sourceTerm", DSL.SyntaxTree.TCustom("const Source&"), "(!llvm.ptr, !llvm.ptr, !llvm.ptr, f64, f64, !llvm.ptr) -> ()", is_function=True)]
295
296 FD4_tree = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.timeStepWithFD4, template_parameters, functor_arguments, ["exahype2", "fd", "fd4"])
297 FD4_kernel = FD4_tree.print_cpp()
298 FD4_call_with_measurement = FD4_tree.print_definition_with_timer()
299 FD4_kernel_declaration = FD4_tree.print_declaration()
300 FD4_call_with_measurement_declaration = FD4_tree.print_declaration_with_timer()
301
302 FD4_stateless_tree = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.timeStepWithFD4, template_parameters, functor_arguments, ["exahype2", "fd", "fd4"], stateless=True)
303 FD4_stateless_kernel = FD4_stateless_tree.print_cpp()
304 FD4_stateless_call_with_measurement = FD4_stateless_tree.print_definition_with_timer()
305 FD4_stateless_kernel_declaration = FD4_stateless_tree.print_declaration()
306 FD4_stateless_call_with_measurement_declaration = FD4_stateless_tree.print_declaration_with_timer()
307
308 #FD4_accelerator_tree = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.timeStepWithFD4, template_parameters, functor_arguments, ["exahype2", "fd", "fd4"], True, True).print_cpp()
309 #FD4_accelerator_kernel = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.timeStepWithFD4, template_parameters, functor_arguments, ["exahype2", "fd", "fd4"], True, True).print_cpp()
310 #FD4_accelerator_call_with_measurement = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.timeStepWithFD4, template_parameters, functor_arguments, ["exahype2", "fd", "fd4"], True, True).print_definition_with_timer()
311 #FD4_accelerator_kernel_declaration = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.timeStepWithFD4, template_parameters, functor_arguments, ["exahype2", "fd", "fd4"], True, True).print_declaration()
312 #FD4_accelerator_call_with_measurement_declaration = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.timeStepWithFD4, template_parameters, functor_arguments, ["exahype2", "fd", "fd4"], True, True).print_declaration_with_timer()
313
314 FD4_omp_tree = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.timeStepWithFD4, template_parameters, functor_arguments, ["exahype2", "fd", "fd4", "omp"])
315 FD4_omp_kernel = FD4_omp_tree.print_omp()
316 FD4_omp_call_with_measurement = FD4_omp_tree.print_definition_with_timer()
317 FD4_omp_kernel_declaration = FD4_omp_tree.print_declaration()
318 FD4_omp_call_with_measurement_declaration = FD4_omp_tree.print_declaration_with_timer()
319
320 FD4_omp_stateless_tree = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.timeStepWithFD4, template_parameters, functor_arguments, ["exahype2", "fd", "fd4", "omp"], stateless=True)
321 FD4_omp_stateless_kernel = FD4_omp_stateless_tree.print_omp()
322 FD4_omp_stateless_call_with_measurement = FD4_omp_stateless_tree.print_definition_with_timer()
323 FD4_omp_stateless_kernel_declaration = FD4_omp_stateless_tree.print_declaration()
324 FD4_omp_stateless_call_with_measurement_declaration = FD4_omp_stateless_tree.print_declaration_with_timer()
325
326 FD4_omp_accelerator_tree = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.timeStepWithFD4, template_parameters, functor_arguments, ["exahype2", "fd", "fd4", "omp"], stateless=True, use_accelerator=True)
327 FD4_omp_accelerator_kernel = FD4_omp_accelerator_tree.print_omp()
328 FD4_omp_accelerator_call_with_measurement = FD4_omp_accelerator_tree.print_definition_with_timer()
329 FD4_omp_accelerator_kernel_declaration = FD4_omp_accelerator_tree.print_declaration()
330 FD4_omp_accelerator_call_with_measurement_declaration = FD4_omp_accelerator_tree.print_declaration_with_timer()
331
332 FD4_sycl_accelerator_tree = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.timeStepWithFD4, template_parameters, functor_arguments, ["exahype2", "fd", "fd4", "sycl"], stateless=True, use_accelerator=True)
333 FD4_sycl_accelerator_kernel = FD4_sycl_accelerator_tree.print_sycl()
334 FD4_sycl_accelerator_call_with_measurement = FD4_sycl_accelerator_tree.print_definition_with_timer()
335 FD4_sycl_accelerator_kernel_declaration = FD4_sycl_accelerator_tree.print_declaration()
336 FD4_sycl_accelerator_call_with_measurement_declaration = FD4_sycl_accelerator_tree.print_declaration_with_timer()
337
338 # These function definitions are used to generate declarations in the MLIR bridge files
339 FD4_mlir_function_definition = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.timeStepWithFD4, template_parameters, functor_arguments, ["exahype2", "fd", "fd4", "mlir"])
340 FD4_mlir_stateless_function_definition = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.timeStepWithFD4, template_parameters, functor_arguments, ["exahype2", "fd", "fd4", "mlir"], stateless=True)
341 FD4_mlir_stateless_omp_function_definition = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.timeStepWithFD4, template_parameters, functor_arguments, ["exahype2", "fd", "fd4", "mlir", "omp"], stateless=True)
342 FD4_mlir_gpu_function_definition = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.timeStepWithFD4, template_parameters, functor_arguments, ["exahype2", "fd", "fd4", "mlir", "gpu"], stateless=True, use_accelerator=True)
343
344 FD4_mlir_kernel = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.timeStepWithFD4, template_parameters, functor_arguments, ["exahype2", "fd", "fd4"]).print_mlir()
345 FD4_mlir_omp_kernel = DSL.Parser().parse(exahype2.solvers.rkfd.fd4.timeStepWithFD4, template_parameters, functor_arguments, ["exahype2", "fd", "fd4"], mlir_omp=True).print_mlir()
346
347 mlir_cpu_function_definitions = [
348 FD4_mlir_function_definition,
349 FD4_mlir_stateless_function_definition,
350 FD4_mlir_stateless_omp_function_definition
351 ]
352
353 if not os.path.exists("kernels"):
354 os.makedirs("kernels")
355
356 solver_includes = """
357#include "exahype2/CellData.h"
358#include "exahype2/VolumeIndex.h"
359#include "exahype2/fd/PatchUtils.h"
360#include "exahype2/fd/Functors.h"
361#include "peano4/utils/Loop.h"
362#include "tarch/timing/Measurement.h"
363#include "tarch/timing/Watch.h"
364"""
365
366 file = open("kernels/FD4.h", "w")
367 file.write(f"""#pragma once
368{solver_includes}
369
370{FD4_kernel_declaration}
371{FD4_call_with_measurement_declaration}
372{FD4_stateless_kernel_declaration}
373{FD4_stateless_call_with_measurement_declaration}
374
375#if defined(SharedOMP)
376{FD4_omp_kernel_declaration}
377{FD4_omp_call_with_measurement_declaration}
378{FD4_omp_stateless_kernel_declaration}
379{FD4_omp_stateless_call_with_measurement_declaration}
380#endif
381
382#if defined(GPUOffloadingOMP)
383{FD4_omp_accelerator_kernel_declaration}
384{FD4_omp_accelerator_call_with_measurement_declaration}
385{ComputeLinearCombination_omp_accelerator_kernel_declaration}
386{ComputeLinearCombination_omp_accelerator_call_with_measurement_declaration}
387{ComputeFinalLinearCombination_omp_accelerator_kernel_declaration}
388{ComputeFinalLinearCombination_omp_accelerator_call_with_measurement_declaration}
389#endif
390
391#if defined(GPUOffloadingSYCL)
392{FD4_sycl_accelerator_kernel_declaration}
393{FD4_sycl_accelerator_call_with_measurement_declaration}
394#endif
395
396#ifdef USE_MLIR
397#include "MLIRbridge.cpph"
398#endif
399#include "FD4.cpph"
400""")
401 file.close()
402
403 file = open("kernels/FD4.cpph", "w")
404 file.write(FD4_kernel)
405 file.write(FD4_call_with_measurement)
406 file.write(FD4_stateless_kernel)
407 file.write(FD4_stateless_call_with_measurement)
408
409 file.write("#if defined(SharedOMP)\n")
410 file.write(FD4_omp_kernel)
411 file.write(FD4_omp_call_with_measurement)
412 file.write(FD4_omp_stateless_kernel)
413 file.write(FD4_omp_stateless_call_with_measurement)
414 file.write("#endif\n")
415
416 file.write("#if defined(GPUOffloadingOMP)\n")
417 file.write(FD4_omp_accelerator_kernel)
418 file.write(FD4_omp_accelerator_call_with_measurement)
419 file.write(ComputeLinearCombination_omp_accelerator_kernel)
420 file.write(ComputeLinearCombination_omp_accelerator_call_with_measurement)
421 file.write(ComputeFinalLinearCombination_omp_accelerator_kernel)
422 file.write(ComputeFinalLinearCombination_omp_accelerator_call_with_measurement)
423 file.write("#endif\n")
424
425 file.write("#if defined(GPUOffloadingSYCL)\n")
426 file.write(FD4_sycl_accelerator_kernel)
427 file.write(FD4_sycl_accelerator_call_with_measurement)
428 file.write("#endif\n")
429 file.close()
430
431 file = open("kernels/fd4_3d.mlir", "w")
432 file.write(FD4_mlir_kernel)
433 file.close()
434
435 file = open("kernels/fd4_3d_omp.mlir", "w")
436 file.write(FD4_mlir_omp_kernel)
437 file.close()
438
439 # Generate MLIR bridge files
440 with open("MLIRbridge.cpph", 'w') as file:
441 file.write("""
442#include "MemRefDescriptor.cpph"
443// MLIR-compatible structure using memref descriptors
444struct MLIRCellData {
445 MemRefDescriptor2D QIn; // Field 0
446 MemRefDescriptor2D QOut; // Field 1
447 MemRefDescriptorNested cellCentre; // Field 2
448 MemRefDescriptorNested cellSize; // Field 3
449 MemRefDescriptor1D t; // Field 4
450 MemRefDescriptor1D dt; // Field 5
451 MemRefDescriptor1D id; // Field 6
452 int64_t numberOfCells; // Field 7
453 int64_t memoryLocation; // Field 8
454 int64_t targetDevice; // Field 9
455 double** QOut_legacy; // Field 10
456 double* maxEigenvalue; // Field 11
457};
458void convertToMLIRStruct(exahype2::CellData<double, double>* patchData, MLIRCellData* mlir_data);
459void convertToMLIRStructGPU(exahype2::CellData<double, double>* copyCellData, MLIRCellData* mlir_data);
460void cleanupMLIRStruct(MLIRCellData* mlir_data);
461void cleanupMLIRStructGPU(MLIRCellData* mlir_data);
462void copybackMLIRresults(exahype2::CellData<double, double>* patchData, MLIRCellData* mlir_data);
463""")
464 file.write("""extern "C" void timeStepWithFD4_MLIR_wrapper(exahype2::CellData<double, double>* patchData, bool use_omp);\n""")
465 for definition in mlir_cpu_function_definitions:
466 file.write(definition.print_declaration())
467 file.write(definition.print_declaration_with_timer())
468 definition._arguments[0]._type = DSL.SyntaxTree.TCustom("MLIRCellData*")
469 file.write(definition.print_declaration())
470 file.write(definition.print_declaration_with_timer())
471 file.write("#ifdef MLIR_GPU\n")
472 FD4_mlir_gpu_function_definition._arguments[1]._type = DSL.SyntaxTree.TCustom("MLIRCellData*")
473 file.write(FD4_mlir_gpu_function_definition.print_declaration())
474 file.write(FD4_mlir_gpu_function_definition.print_declaration_with_timer())
475 file.write("#endif")
476
477 d = {}
478 d["KERNEL_NAMESPACE"] = "exahype2::fd::fd4"
479 d["SOLVER"] = "FD4"
480 d["SOLVER_CLASS"] = "FD4"
481 d["KERNEL_NAME"] = "timeStepWithFD4"
482 d["SOLVER_INCLUDES"] = solver_includes
483 d["SOLVER_CLASS_NAMESPACE"] = "benchmarks::exahype2::kernelbenchmarks"
484
485 d["PATCH_SIZE"] = patch_size
486 d["NUMBER_OF_UNKNOWNS"] = unknowns
487 d["NUMBER_OF_AUXILIARY_VARIABLES"] = auxiliary_variables
488 d["KOSIGMA"] = ko_sigma
489 d["FLUX_IMPLEMENTATION"] = flux_implementation
490 d["NCP_IMPLEMENTATION"] = ncp_implementation
491 d["SOURCE_IMPLEMENTATION"] = source_term_implementation
492 d["COMPUTE_MAX_EIGENVALUE"] = compute_max_eigenvalue_of_next_time_step
493 d["HALO_SIZE"] = 3
494
495 template_strings = [argument.print_cpp() for argument in FD4_mlir_function_definition._template]
496 d["TEMPLATE_DEFINITION"] = "template <" + ",".join(template_strings) + ">\n"
497
498 template_call_jinja = """
499 {{SOLVER_CLASS_NAMESPACE}}::{{SOLVER_CLASS}},
500 {{PATCH_SIZE}},
501 {{HALO_SIZE}},
502 {{NUMBER_OF_UNKNOWNS}},
503 {{NUMBER_OF_AUXILIARY_VARIABLES}},
504 static_cast<int>({{KOSIGMA}}),
505 {% if FLUX_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
506 {% if NCP_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
507 {% if SOURCE_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
508 {% if COMPUTE_MAX_EIGENVALUE==False %} false {% else %} true {% endif %}
509 """
510 d["TEMPLATE_CALL"] = jinja2.Template(template_call_jinja).render(**d)
511
512 template_value_definitions_jinja = """
513 int NC = {{PATCH_SIZE}};
514 int NumberOfUnknowns = {{NUMBER_OF_UNKNOWNS}};
515 int NumberOfAuxiliaryVariables = {{NUMBER_OF_AUXILIARY_VARIABLES}};
516 int H = {{HALO_SIZE}};
517 int KOsigma = static_cast<int>({{KOSIGMA}});
518 bool EvaluateFlux = {% if FLUX_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %};
519 bool EvaluateNonconservativeProduct = {% if NCP_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %};
520 bool EvaluateSource = {% if SOURCE_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %};
521 bool EvaluateMaximumEigenvalueAfterTimeStep = {% if COMPUTE_MAX_EIGENVALUE==False %} false {% else %} true {% endif %};
522 """
523 d["TEMPLATE_VALUE_DEFINITIONS"] = jinja2.Template(template_value_definitions_jinja).render(**d)
524
525 filepath = os.path.realpath(__file__)
526 filepath_root = filepath[0:filepath.find("solvers/")]
527 with open(filepath_root + "dslhype/MLIRbridge.template.cpp", 'r') as template_file:
528 mlir_bridge_template = template_file.read()
529 mlir_bridge_cpp = jinja2.Template(mlir_bridge_template).render(**d)
530 with open("MLIRbridge.cpp", 'w') as file:
531 file.write(mlir_bridge_cpp)
532
534 ncp_implementation,
535 source_implementation,
536 compute_max_eigenvalue_of_next_time_step,
537 solver_variant: SolverVariant,
538 kernel_variant: KernelVariant,
539 KOSigma,
540 SecondOrder):
541 """
542
543 I return only the unqualified function call, i.e. without any namespaces.
544 So by setting the right namespace as prefix, you can direct it to particular
545 implementations.
546
547 """
548
549 template = "timeStepWithFD4InExaGRyPE"
550
551 if solver_variant == SolverVariant.WithVirtualFunctions:
552 template += """<
553 {{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}},
554 {{HALO_SIZE}},
555 {{NUMBER_OF_UNKNOWNS}},
556 {{NUMBER_OF_AUXILIARY_VARIABLES}},
557 static_cast<int>({{KOSIGMA}}),
558 {% if FLUX_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
559 {% if NCP_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
560 {% if SOURCE_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
561 false, // Runge-Kutta, so no need to copy old data over or to take dt into account
562 {% if SECONDORDER %} true {% else %} false {% endif %}, //if we have SO enabled, the quantities that get advections would be different
563 {% if SECONDORDER %} false {% else %} true {% endif %} //if we have SO enabled, the quantities that get advections would be different
564 >(patchData,
565 [&](
566 const double * __restrict__ Q,
567 const tarch::la::Vector<Dimensions,double>& faceCentre,
568 const tarch::la::Vector<Dimensions,double>& volumeH,
569 double t,
570 double dt,
571 int normal,
572 double * __restrict__ F
573 )->void {
574 {% if FLUX_IMPLEMENTATION!="<none>" %}
575 repositories::{{SOLVER_INSTANCE}}.flux( Q, faceCentre, volumeH, t, dt, normal, F );
576 {% endif %}
577 },
578 [&](
579 const double * __restrict__ Q,
580 const double * __restrict__ deltaQ,
581 const tarch::la::Vector<Dimensions,double>& faceCentre,
582 const tarch::la::Vector<Dimensions,double>& volumeH,
583 double t,
584 double dt,
585 int normal,
586 double * __restrict__ BTimesDeltaQ
587 )->void {
588 {% if NCP_IMPLEMENTATION!="<none>" %}
589 repositories::{{SOLVER_INSTANCE}}.nonconservativeProduct( Q, deltaQ, faceCentre, volumeH, t, dt, normal, BTimesDeltaQ );
590 {% endif %}
591 },
592 [&](
593 const double * __restrict__ Q,
594 const tarch::la::Vector<Dimensions,double>& volumeX,
595 const tarch::la::Vector<Dimensions,double>& volumeH,
596 double t,
597 double dt,
598 double * __restrict__ S
599 )->void {
600 {% if SOURCE_IMPLEMENTATION!="<none>" %}
601 repositories::{{SOLVER_INSTANCE}}.sourceTerm( Q, volumeX, volumeH, t, dt, S );
602 {% endif %}
603 }
604);
605 """
606 elif solver_variant == SolverVariant.Stateless:
607 template += """Stateless<
608 {{SOLVER_NAME}},
609 {{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}},
610 {{HALO_SIZE}},
611 {{NUMBER_OF_UNKNOWNS}},
612 {{NUMBER_OF_AUXILIARY_VARIABLES}},
613 static_cast<int>({{KOSIGMA}}),
614 {% if FLUX_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
615 {% if NCP_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
616 {% if SOURCE_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
617 false, // Runge-Kutta, so no need to copy old data over or to take dt into account
618 {% if SECONDORDER %} true {% else %} false {% endif %}, //if we have SO enabled, the quantities that get advections would be different
619 {% if SECONDORDER %} false {% else %} true {% endif %} //if we have SO enabled, the quantities that get advections would be different
620 >(patchData);
621 """
622 elif solver_variant == SolverVariant.AcceleratorWithExplicitCopy:
623 template += """Stateless<
624 {{SOLVER_NAME}},
625 {{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}},
626 {{HALO_SIZE}},
627 {{NUMBER_OF_UNKNOWNS}},
628 {{NUMBER_OF_AUXILIARY_VARIABLES}},
629 static_cast<int>({{KOSIGMA}}),
630 {% if FLUX_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
631 {% if NCP_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
632 {% if SOURCE_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
633 false, // Runge-Kutta, so no need to copy old data over or to take dt into account
634 {% if SECONDORDER %} true {% else %} false {% endif %}, //if we have SO enabled, the quantities that get advections would be different
635 {% if SECONDORDER %} false {% else %} true {% endif %} //if we have SO enabled, the quantities that get advections would be different
636 >(gpuPatchData.targetDevice, gpuPatchData);
637 """
638 else:
639 assert False, "not supported combination: {} x {}".format( solver_variant, kernel_variant )
640
641 result = jinja2.Template( template, undefined=jinja2.DebugUndefined)
642 d= {}
643 d[ "FLUX_IMPLEMENTATION" ] = flux_implementation
644 d[ "NCP_IMPLEMENTATION" ] = ncp_implementation
645 d[ "SOURCE_IMPLEMENTATION" ] = source_implementation
646 d[ "COMPUTE_MAX_EIGENVALUE" ] = compute_max_eigenvalue_of_next_time_step
647 d[ "KOSIGMA" ] = KOSigma
648 d[ "SECONDORDER" ] = SecondOrder
649 return result.render(**d)
650
651def create_compute_kernel_for_FD4_DSL(flux_implementation,
652 ncp_implementation,
653 source_implementation,
654 compute_max_eigenvalue_of_next_time_step,
655 solver_variant: SolverVariant,
656 kernel_variant: KernelVariant,
657 KOSigma):
658 """
659
660 I return only the unqualified function call, i.e. without any namespaces.
661 So by setting the right namespace as prefix, you can direct it to particular
662 implementations.
663
664 """
665
666 template = "timeStepWithFD4"
667
668 if solver_variant == SolverVariant.WithVirtualFunctions:
669 template += """<
670 {{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}},
671 {{HALO_SIZE}},
672 {{NUMBER_OF_UNKNOWNS}},
673 {{NUMBER_OF_AUXILIARY_VARIABLES}},
674 static_cast<int>({{KOSIGMA}}),
675 {% if FLUX_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
676 {% if NCP_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
677 {% if SOURCE_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
678 false // Runge-Kutta, so no need to copy old data over or to take dt into account
679 >(patchData,
680 [&](
681 const double * __restrict__ Q,
682 const tarch::la::Vector<Dimensions,double>& faceCentre,
683 const tarch::la::Vector<Dimensions,double>& volumeH,
684 double t,
685 double dt,
686 int normal,
687 double * __restrict__ F
688 )->void {
689 {% if FLUX_IMPLEMENTATION!="<none>" %}
690 repositories::{{SOLVER_INSTANCE}}.flux( Q, faceCentre, volumeH, t, dt, normal, F );
691 {% endif %}
692 },
693 [&](
694 const double * __restrict__ Q,
695 const double * __restrict__ deltaQ,
696 const tarch::la::Vector<Dimensions,double>& faceCentre,
697 const tarch::la::Vector<Dimensions,double>& volumeH,
698 double t,
699 double dt,
700 int normal,
701 double * __restrict__ BTimesDeltaQ
702 )->void {
703 {% if NCP_IMPLEMENTATION!="<none>" %}
704 repositories::{{SOLVER_INSTANCE}}.nonconservativeProduct( Q, deltaQ, faceCentre, volumeH, t, dt, normal, BTimesDeltaQ );
705 {% endif %}
706 },
707 [&](
708 const double * __restrict__ Q,
709 const tarch::la::Vector<Dimensions,double>& volumeX,
710 const tarch::la::Vector<Dimensions,double>& volumeH,
711 double t,
712 double dt,
713 double * __restrict__ S
714 )->void {
715 {% if SOURCE_IMPLEMENTATION!="<none>" %}
716 repositories::{{SOLVER_INSTANCE}}.sourceTerm( Q, volumeX, volumeH, t, dt, S );
717 {% endif %}
718 }
719);
720 """
721 elif solver_variant == SolverVariant.Stateless:
722 template += """Stateless<
723 {{SOLVER_NAME}},
724 {{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}},
725 {{HALO_SIZE}},
726 {{NUMBER_OF_UNKNOWNS}},
727 {{NUMBER_OF_AUXILIARY_VARIABLES}},
728 static_cast<int>({{KOSIGMA}}),
729 {% if FLUX_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
730 {% if NCP_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
731 {% if SOURCE_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
732 false // Runge-Kutta, so no need to copy old data over or to take dt into account
733 >(patchData);
734 """
735 elif solver_variant == SolverVariant.AcceleratorWithExplicitCopy:
736 template += """Stateless<
737 {{SOLVER_NAME}},
738 {{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}},
739 {{HALO_SIZE}},
740 {{NUMBER_OF_UNKNOWNS}},
741 {{NUMBER_OF_AUXILIARY_VARIABLES}},
742 static_cast<int>({{KOSIGMA}}),
743 {% if FLUX_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
744 {% if NCP_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
745 {% if SOURCE_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
746 false // Runge-Kutta, so no need to copy old data over or to take dt into account
747 >(gpuPatchData.targetDevice, gpuPatchData);
748 """
749 else:
750 assert False, "not supported combination: {} x {}".format( solver_variant, kernel_variant )
751
752 result = jinja2.Template( template, undefined=jinja2.DebugUndefined)
753 d= {}
754 d[ "FLUX_IMPLEMENTATION" ] = flux_implementation
755 d[ "NCP_IMPLEMENTATION" ] = ncp_implementation
756 d[ "SOURCE_IMPLEMENTATION" ] = source_implementation
757 d[ "COMPUTE_MAX_EIGENVALUE" ] = compute_max_eigenvalue_of_next_time_step
758 d[ "KOSIGMA" ] = KOSigma
759 return result.render(**d)
760
762 kernel_variant: KernelVariant,
763 SecondOrder):
764
765 template = "DerivativesCalInExaGRyPE"
766
767 if solver_variant == SolverVariant.WithVirtualFunctions:
768 template += """<
769 {{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}},
770 {{HALO_SIZE}},
771 {{NUMBER_OF_UNKNOWNS}},
772 {{NUMBER_OF_AUXILIARY_VARIABLES}},
773 {% if SECONDORDER %} true {% else %} false {% endif %} //if we have SO enabled, the quantities that get advections would be different
774 >(patchData);
775 """
776 elif solver_variant == SolverVariant.Stateless:
777 template += """Stateless<
778 {{SOLVER_NAME}},
779 {{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}},
780 {{HALO_SIZE}},
781 {{NUMBER_OF_UNKNOWNS}},
782 {{NUMBER_OF_AUXILIARY_VARIABLES}},
783 {% if SECONDORDER %} true {% else %} false {% endif %} //if we have SO enabled, the quantities that get advections would be different
784 >(patchData);
785 """
786 elif solver_variant == SolverVariant.AcceleratorWithExplicitCopy:
787 template += """Stateless<
788 {{SOLVER_NAME}},
789 {{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}},
790 {{HALO_SIZE}},
791 {{NUMBER_OF_UNKNOWNS}},
792 {{NUMBER_OF_AUXILIARY_VARIABLES}},
793 {% if SECONDORDER %} true {% else %} false {% endif %} //if we have SO enabled, the quantities that get advections would be different
794 >(targetDevice, gpuPatchData);
795 """
796 else:
797 assert False, "not supported combination: {} x {}".format( solver_variant, kernel_variant )
798
799 result = jinja2.Template( template, undefined=jinja2.DebugUndefined)
800 d= {}
801 d[ "SECONDORDER" ] = SecondOrder
802 return result.render(**d)
803
804
805#def create_compute_kernel_for_FD4(flux_implementation,
806# ncp_implementation,
807# source_implementation,
808# compute_max_eigenvalue_of_next_time_step,
809# solver_variant,
810# kernel_variant,
811# KOSigma):
812# """
813#
814# I return only the unqualified function call, i.e. without any namespaces.
815# So by setting the right namespace as prefix, you can direct it to particular
816# implementations.
817#
818# """
819# KernelCalls = {
820# KernelVariant.PatchWiseAoSHeap: "timeStep_patchwise_heap",
821# KernelVariant.PatchWiseAoSoAHeap: "timeStep_patchwise_heap",
822# KernelVariant.PatchWiseSoAHeap: "timeStep_patchwise_heap",
823# KernelVariant.BatchedAoSHeap: "timeStep_batched_heap",
824# KernelVariant.BatchedAoSoAHeap: "timeStep_batched_heap",
825# KernelVariant.BatchedSoAHeap: "timeStep_batched_heap",
826# KernelVariant.TaskGraphAoSHeap: "timeStep_taskgraph_heap",
827# KernelVariant.TaskGraphAoSoAHeap: "timeStep_taskgraph_heap",
828# KernelVariant.TaskGraphSoAHeap: "timeStep_taskgraph_heap",
829# }
830#
831# EnumeratorTemplateTypes = {
832# KernelVariant.PatchWiseAoSHeap: "::exahype2::enumerator::AoSLexicographicEnumerator",
833# KernelVariant.PatchWiseAoSoAHeap: "::exahype2::enumerator::AoSoALexicographicEnumerator",
834# KernelVariant.PatchWiseSoAHeap: "::exahype2::enumerator::SoALexicographicEnumerator",
835# KernelVariant.BatchedAoSHeap: "::exahype2::enumerator::AoSLexicographicEnumerator",
836# KernelVariant.BatchedAoSoAHeap: "::exahype2::enumerator::AoSoALexicographicEnumerator",
837# KernelVariant.BatchedSoAHeap: "::exahype2::enumerator::SoALexicographicEnumerator",
838# KernelVariant.TaskGraphAoSHeap: "::exahype2::enumerator::AoSLexicographicEnumerator",
839# KernelVariant.TaskGraphAoSoAHeap: "::exahype2::enumerator::AoSoALexicographicEnumerator",
840# KernelVariant.TaskGraphSoAHeap: "::exahype2::enumerator::SoALexicographicEnumerator",
841# }
842#
843# template = KernelCalls[kernel_variant]
844#
845# if solver_variant == SolverVariant.WithVirtualFunctions:
846# template += """_functors(
847# patchData,
848# {{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}},
849# {{HALO_SIZE}},
850# {{NUMBER_OF_UNKNOWNS}},
851# {{NUMBER_OF_AUXILIARY_VARIABLES}},
852# {{KOSIGMA}},
853# {% if FLUX_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
854# {% if NCP_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
855# {% if SOURCE_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
856# false, // Runge-Kutta, so no need to copy old data over or to take dt into account
857# ::exahype2::fd::fd4::DifferentialSourceTermVariant::CentralDifferencesWithLopsidedAdvection,
858# [&](
859# const double * __restrict__ Q,
860# const tarch::la::Vector<Dimensions,double>& faceCentre,
861# const tarch::la::Vector<Dimensions,double>& volumeH,
862# double t,
863# double dt,
864# int normal,
865# double * __restrict__ F
866# )->void {
867# {% if FLUX_IMPLEMENTATION!="<none>" %}
868# repositories::{{SOLVER_INSTANCE}}.flux( Q, faceCentre, volumeH, t, dt, normal, F );
869# {% endif %}
870# },
871# [&](
872# const double * __restrict__ Q,
873# const double * __restrict__ deltaQ,
874# const tarch::la::Vector<Dimensions,double>& faceCentre,
875# const tarch::la::Vector<Dimensions,double>& volumeH,
876# double t,
877# double dt,
878# int normal,
879# double * __restrict__ BTimesDeltaQ
880# )->void {
881# {% if NCP_IMPLEMENTATION!="<none>" %}
882# repositories::{{SOLVER_INSTANCE}}.nonconservativeProduct( Q, deltaQ, faceCentre, volumeH, t, dt, normal, BTimesDeltaQ );
883# {% endif %}
884# },
885# [&](
886# const double * __restrict__ Q,
887# const tarch::la::Vector<Dimensions,double>& volumeX,
888# const tarch::la::Vector<Dimensions,double>& volumeH,
889# double t,
890# double dt,
891# double * __restrict__ S
892# )->void {
893# {% if SOURCE_IMPLEMENTATION!="<none>" %}
894# repositories::{{SOLVER_INSTANCE}}.sourceTerm( Q, volumeX, volumeH, t, dt, S );
895# {% endif %}
896# }
897#);
898# """
899# elif solver_variant == SolverVariant.Stateless:
900# template += """_static_calls<{{SOLVER_NAME}},{{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}},{{HALO_SIZE}}, {{NUMBER_OF_UNKNOWNS}}, {{NUMBER_OF_AUXILIARY_VARIABLES}}, {{TEMP_DATA_ENUMERATOR}}>(
901# patchData,
902# {{KOSIGMA}},
903# {% if FLUX_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
904# {% if NCP_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
905# {% if SOURCE_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
906# false, // Runge-Kutta, so no need to copy old data over or to take dt into account
907# ::exahype2::fd::fd4::DifferentialSourceTermVariant::CentralDifferencesWithLopsidedAdvection
908# );
909# """
910# elif solver_variant == SolverVariant.Multicore:
911# template += """_multicore_static_calls<{{SOLVER_NAME}},{{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}},{{HALO_SIZE}}, {{NUMBER_OF_UNKNOWNS}}, {{NUMBER_OF_AUXILIARY_VARIABLES}}, {{TEMP_DATA_ENUMERATOR}}>(
912# patchData,
913# {{KOSIGMA}},
914# {% if FLUX_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
915# {% if NCP_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
916# {% if SOURCE_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
917# false, // Runge-Kutta, so no need to copy old data over or to take dt into account
918# ::exahype2::fd::fd4::DifferentialSourceTermVariant::CentralDifferencesWithLopsidedAdvection
919# );
920# """
921# elif solver_variant == SolverVariant.AcceleratorWithExplicitCopy:
922# template += """_static_calls<{{SOLVER_NAME}},{{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}},{{HALO_SIZE}}, {{NUMBER_OF_UNKNOWNS}}, {{NUMBER_OF_AUXILIARY_VARIABLES}}, {{TEMP_DATA_ENUMERATOR}}>(
923# targetDevice,
924# patchData,
925# {{KOSIGMA}},
926# {% if FLUX_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
927# {% if NCP_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
928# {% if SOURCE_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
929# false, // Runge-Kutta, so no need to copy old data over or to take dt into account
930# ::exahype2::fd::fd4::DifferentialSourceTermVariant::CentralDifferencesWithLopsidedAdvection
931# );
932# """
933# else:
934# assert False, "not supported combination: {} x {}".format( solver_variant, kernel_variant )
935#
936# result = jinja2.Template( template, undefined=jinja2.DebugUndefined)
937# d= {}
938# d[ "FLUX_IMPLEMENTATION" ] = flux_implementation
939# d[ "NCP_IMPLEMENTATION" ] = ncp_implementation
940# d[ "SOURCE_IMPLEMENTATION" ] = source_implementation
941# d[ "COMPUTE_MAX_EIGENVALUE" ] = compute_max_eigenvalue_of_next_time_step
942# d[ "KOSIGMA" ] = KOSigma
943# d[ "TEMP_DATA_ENUMERATOR" ] = EnumeratorTemplateTypes[kernel_variant]
944# return result.render(**d)
create_FD4_kernel_definitions_3d(patch_size, unknowns, auxiliary_variables, ko_sigma, flux_implementation, ncp_implementation, source_term_implementation, compute_max_eigenvalue_of_next_time_step)
Definition kernels.py:281
create_derivative_calculation_kernel_for_FD4InExaGRyPE_DSL(SolverVariant solver_variant, KernelVariant kernel_variant, SecondOrder)
Definition kernels.py:763
create_compute_kernel_for_FD4InExaGRyPE_DSL(flux_implementation, ncp_implementation, source_implementation, compute_max_eigenvalue_of_next_time_step, SolverVariant solver_variant, KernelVariant kernel_variant, KOSigma, SecondOrder)
I return only the unqualified function call, i.e.
Definition kernels.py:540
create_compute_kernel_for_FD4_DSL(flux_implementation, ncp_implementation, source_implementation, compute_max_eigenvalue_of_next_time_step, SolverVariant solver_variant, KernelVariant kernel_variant, KOSigma)
I return only the unqualified function call, i.e.
Definition kernels.py:657