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()),
25 DSL.SyntaxTree.Argument(
"SecondOrderFormulation", DSL.SyntaxTree.TBoolean()),
26 DSL.SyntaxTree.Argument(
"FirstOrderFormulation", DSL.SyntaxTree.TBoolean())]
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&"))]
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()
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()
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()
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()
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()
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()
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*"))]
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()
85 if not os.path.exists(
"kernels"):
86 os.makedirs(
"kernels")
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"
98{FD4InExaGRyPE_kernel_declaration}
99{FD4InExaGRyPE_call_with_measurement_declaration}
100{FD4InExaGRyPE_stateless_kernel_declaration}
101{FD4InExaGRyPE_stateless_call_with_measurement_declaration}
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}
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}
117#if defined(GPUOffloadingSYCL)
118{FD4InExaGRyPE_sycl_accelerator_kernel_declaration}
119{FD4InExaGRyPE_sycl_accelerator_call_with_measurement_declaration}
122#include "FD4InExaGRyPE.cpph"
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)
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")
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")
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")
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())]
159 functor_arguments = []
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()
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()
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()
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()
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()
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()
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*"))]
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()
214 if not os.path.exists(
"kernels"):
215 os.makedirs(
"kernels")
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"
227{DeriCallInExaGRyPE_kernel_declaration}
228{DeriCallInExaGRyPE_call_with_measurement_declaration}
229{DeriCallInExaGRyPE_stateless_kernel_declaration}
230{DeriCallInExaGRyPE_stateless_call_with_measurement_declaration}
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}
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}
246#if defined(GPUOffloadingSYCL)
247{DeriCallInExaGRyPE_sycl_accelerator_kernel_declaration}
248{DeriCallInExaGRyPE_sycl_accelerator_call_with_measurement_declaration}
251#include "DeriCallInExaGRyPE.cpph"
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)
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")
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")
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")
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())]
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)]
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()
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()
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()
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()
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()
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()
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)
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()
347 mlir_cpu_function_definitions = [
348 FD4_mlir_function_definition,
349 FD4_mlir_stateless_function_definition,
350 FD4_mlir_stateless_omp_function_definition
353 if not os.path.exists(
"kernels"):
354 os.makedirs(
"kernels")
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"
366 file = open(
"kernels/FD4.h",
"w")
367 file.write(f
"""#pragma once
370{FD4_kernel_declaration}
371{FD4_call_with_measurement_declaration}
372{FD4_stateless_kernel_declaration}
373{FD4_stateless_call_with_measurement_declaration}
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}
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}
391#if defined(GPUOffloadingSYCL)
392{FD4_sycl_accelerator_kernel_declaration}
393{FD4_sycl_accelerator_call_with_measurement_declaration}
397#include "MLIRbridge.cpph"
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)
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")
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")
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")
431 file = open(
"kernels/fd4_3d.mlir",
"w")
432 file.write(FD4_mlir_kernel)
435 file = open(
"kernels/fd4_3d_omp.mlir",
"w")
436 file.write(FD4_mlir_omp_kernel)
440 with open(
"MLIRbridge.cpph",
'w')
as file:
442#include "MemRefDescriptor.cpph"
443// MLIR-compatible structure using memref descriptors
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
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);
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())
478 d[
"KERNEL_NAMESPACE"] =
"exahype2::fd::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"
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
495 template_strings = [argument.print_cpp()
for argument
in FD4_mlir_function_definition._template]
496 d[
"TEMPLATE_DEFINITION"] =
"template <" +
",".join(template_strings) +
">\n"
498 template_call_jinja =
"""
499 {{SOLVER_CLASS_NAMESPACE}}::{{SOLVER_CLASS}},
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 %}
510 d[
"TEMPLATE_CALL"] = jinja2.Template(template_call_jinja).render(**d)
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 %};
523 d[
"TEMPLATE_VALUE_DEFINITIONS"] = jinja2.Template(template_value_definitions_jinja).render(**d)
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)