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
8
9
10from exahype2.solvers.rkfd.kernels import SolverVariant
11from exahype2.solvers.rkfd.kernels import KernelVariant
12
13
14def create_compute_kernel_for_FD4(flux_implementation,
15 ncp_implementation,
16 source_implementation,
17 compute_max_eigenvalue_of_next_time_step,
18 solver_variant,
19 kernel_variant,
20 KOSigma):
21 """
22
23 I return only the unqualified function call, i.e. without any namespaces.
24 So by setting the right namespace as prefix, you can direct it to particular
25 implementations.
26
27 """
28 KernelCalls = {
29 KernelVariant.PatchWiseAoSHeap: "timeStep_patchwise_heap",
30 KernelVariant.PatchWiseAoSoAHeap: "timeStep_patchwise_heap",
31 KernelVariant.PatchWiseSoAHeap: "timeStep_patchwise_heap",
32 KernelVariant.BatchedAoSHeap: "timeStep_batched_heap",
33 KernelVariant.BatchedAoSoAHeap: "timeStep_batched_heap",
34 KernelVariant.BatchedSoAHeap: "timeStep_batched_heap",
35 KernelVariant.TaskGraphAoSHeap: "timeStep_taskgraph_heap",
36 KernelVariant.TaskGraphAoSoAHeap: "timeStep_taskgraph_heap",
37 KernelVariant.TaskGraphSoAHeap: "timeStep_taskgraph_heap",
38 }
39
40 EnumeratorTemplateTypes = {
41 KernelVariant.PatchWiseAoSHeap: "::exahype2::enumerator::AoSLexicographicEnumerator",
42 KernelVariant.PatchWiseAoSoAHeap: "::exahype2::enumerator::AoSoALexicographicEnumerator",
43 KernelVariant.PatchWiseSoAHeap: "::exahype2::enumerator::SoALexicographicEnumerator",
44 KernelVariant.BatchedAoSHeap: "::exahype2::enumerator::AoSLexicographicEnumerator",
45 KernelVariant.BatchedAoSoAHeap: "::exahype2::enumerator::AoSoALexicographicEnumerator",
46 KernelVariant.BatchedSoAHeap: "::exahype2::enumerator::SoALexicographicEnumerator",
47 KernelVariant.TaskGraphAoSHeap: "::exahype2::enumerator::AoSLexicographicEnumerator",
48 KernelVariant.TaskGraphAoSoAHeap: "::exahype2::enumerator::AoSoALexicographicEnumerator",
49 KernelVariant.TaskGraphSoAHeap: "::exahype2::enumerator::SoALexicographicEnumerator",
50 }
51
52 template = KernelCalls[kernel_variant]
53
54 if solver_variant == SolverVariant.WithVirtualFunctions:
55 template += """_functors(
56 patchData,
57 {{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}},
58 {{HALO_SIZE}},
59 {{NUMBER_OF_UNKNOWNS}},
60 {{NUMBER_OF_AUXILIARY_VARIABLES}},
61 {{KOSIGMA}},
62 {% if FLUX_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
63 {% if NCP_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
64 {% if SOURCE_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
65 false, // Runge-Kutta, so no need to copy old data over or to take dt into account
66 ::exahype2::fd::fd4::DifferentialSourceTermVariant::CentralDifferencesWithLopsidedAdvection,
67 [&](
68 const double * __restrict__ Q,
69 const tarch::la::Vector<Dimensions,double>& faceCentre,
70 const tarch::la::Vector<Dimensions,double>& volumeH,
71 double t,
72 double dt,
73 int normal,
74 double * __restrict__ F
75 )->void {
76 {% if FLUX_IMPLEMENTATION!="<none>" %}
77 repositories::{{SOLVER_INSTANCE}}.flux( Q, faceCentre, volumeH, t, dt, normal, F );
78 {% endif %}
79 },
80 [&](
81 const double * __restrict__ Q,
82 const double * __restrict__ deltaQ,
83 const tarch::la::Vector<Dimensions,double>& faceCentre,
84 const tarch::la::Vector<Dimensions,double>& volumeH,
85 double t,
86 double dt,
87 int normal,
88 double * __restrict__ BTimesDeltaQ
89 )->void {
90 {% if NCP_IMPLEMENTATION!="<none>" %}
91 repositories::{{SOLVER_INSTANCE}}.nonconservativeProduct( Q, deltaQ, faceCentre, volumeH, t, dt, normal, BTimesDeltaQ );
92 {% endif %}
93 },
94 [&](
95 const double * __restrict__ Q,
96 const tarch::la::Vector<Dimensions,double>& volumeX,
97 const tarch::la::Vector<Dimensions,double>& volumeH,
98 double t,
99 double dt,
100 double * __restrict__ S
101 )->void {
102 {% if SOURCE_IMPLEMENTATION!="<none>" %}
103 repositories::{{SOLVER_INSTANCE}}.sourceTerm( Q, volumeX, volumeH, t, dt, S );
104 {% endif %}
105 }
106);
107 """
108 elif solver_variant == SolverVariant.Stateless:
109 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}}>(
110 patchData,
111 {{KOSIGMA}},
112 {% if FLUX_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
113 {% if NCP_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
114 {% if SOURCE_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
115 false, // Runge-Kutta, so no need to copy old data over or to take dt into account
116 ::exahype2::fd::fd4::DifferentialSourceTermVariant::CentralDifferencesWithLopsidedAdvection
117 );
118 """
119 elif solver_variant == SolverVariant.Multicore:
120 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}}>(
121 patchData,
122 {{KOSIGMA}},
123 {% if FLUX_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
124 {% if NCP_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
125 {% if SOURCE_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
126 false, // Runge-Kutta, so no need to copy old data over or to take dt into account
127 ::exahype2::fd::fd4::DifferentialSourceTermVariant::CentralDifferencesWithLopsidedAdvection
128 );
129 """
130 elif solver_variant == SolverVariant.AcceleratorWithExplicitCopy:
131 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}}>(
132 targetDevice,
133 patchData,
134 {{KOSIGMA}},
135 {% if FLUX_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
136 {% if NCP_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
137 {% if SOURCE_IMPLEMENTATION=="<none>" %} false {% else %} true {% endif %},
138 false, // Runge-Kutta, so no need to copy old data over or to take dt into account
139 ::exahype2::fd::fd4::DifferentialSourceTermVariant::CentralDifferencesWithLopsidedAdvection
140 );
141 """
142 else:
143 assert False, "not supported combination: {} x {}".format( solver_variant, kernel_variant )
144
145 result = jinja2.Template( template, undefined=jinja2.DebugUndefined)
146 d= {}
147 d[ "FLUX_IMPLEMENTATION" ] = flux_implementation
148 d[ "NCP_IMPLEMENTATION" ] = ncp_implementation
149 d[ "SOURCE_IMPLEMENTATION" ] = source_implementation
150 d[ "COMPUTE_MAX_EIGENVALUE" ] = compute_max_eigenvalue_of_next_time_step
151 d[ "KOSIGMA" ] = KOSigma
152 d[ "TEMP_DATA_ENUMERATOR" ] = EnumeratorTemplateTypes[kernel_variant]
153 return result.render(**d)
create_compute_kernel_for_FD4(flux_implementation, ncp_implementation, source_implementation, compute_max_eigenvalue_of_next_time_step, solver_variant, kernel_variant, KOSigma)
I return only the unqualified function call, i.e.
Definition kernels.py:20