17 #ifndef dealii_cuda_tensor_product_kernels_h 18 #define dealii_cuda_tensor_product_kernels_h 20 #include <deal.II/base/config.h> 23 DEAL_II_NAMESPACE_OPEN
51 template <EvaluatorVariant variant,
int dim,
int fe_degree,
int n_q_po
ints_1d,
typename Number>
63 template <
int dim,
int fe_degree,
int n_q_po
ints_1d,
typename Number>
65 n_q_points_1d, Number>
67 static constexpr
unsigned int dofs_per_cell =
Utilities::pow(fe_degree + 1, dim);
68 static constexpr
unsigned int n_q_points =
Utilities::pow(n_q_points_1d, dim);
76 template <
int direction,
bool dof_to_quad,
bool add,
bool in_place>
77 __device__
void values(
const Number *in, Number *out)
const;
83 template <
int direction,
bool dof_to_quad,
bool add,
bool in_place>
84 __device__
void gradients(
const Number *in, Number *out)
const;
89 template <
int direction,
bool dof_to_quad,
bool add,
bool in_place>
90 __device__
void apply(Number shape_data[],
97 __device__
void value_at_quad_pts(Number *u);
102 __device__
void integrate_value(Number *u);
108 __device__
void gradient_at_quad_pts(
const Number *
const u,
109 Number *grad_u[dim]);
116 __device__
void integrate_gradient(Number *u,
117 Number *grad_u[dim]);
122 template <
int dim,
int fe_degree,
int n_q_po
ints_1d,
typename Number>
129 template <
int dim,
int fe_degree,
int n_q_po
ints_1d,
typename Number>
130 template <
int direction,
bool dof_to_quad,
bool add,
bool in_place>
131 __device__
void EvaluatorTensorProduct<evaluate_general, dim, fe_degree,
132 n_q_points_1d, Number>::values(
const Number *in,
135 apply<direction, dof_to_quad, add, in_place>(global_shape_values, in, out);
140 template <
int dim,
int fe_degree,
int n_q_po
ints_1d,
typename Number>
141 template <
int direction,
bool dof_to_quad,
bool add,
bool in_place>
143 n_q_points_1d, Number>::gradients(
const Number *in,
146 apply<direction, dof_to_quad, add, in_place>(global_shape_gradients, in, out);
151 template <
int dim,
int fe_degree,
int n_q_po
ints_1d,
typename Number>
152 template <
int direction,
bool dof_to_quad,
bool add,
bool in_place>
154 n_q_points_1d, Number>::apply(Number shape_data[],
158 const unsigned int i = (dim == 1) ? 0 : threadIdx.x%n_q_points_1d;
159 const unsigned int j = (dim == 3) ? threadIdx.y : 0;
160 const unsigned int q =
161 (dim == 1) ? (threadIdx.x%n_q_points_1d) :
162 (dim == 2) ? threadIdx.y :
168 for (
int k=0; k<n_q_points_1d; ++k)
170 const unsigned int shape_idx = dof_to_quad ? (q+k*n_q_points_1d) :
172 const unsigned int source_idx =
173 (direction == 0) ? (k + n_q_points_1d*(i + n_q_points_1d*j)) :
174 (direction == 1) ? (i + n_q_points_1d*(k + n_q_points_1d*j)) :
175 (i + n_q_points_1d*(j + n_q_points_1d*k));
176 t += shape_data[shape_idx] * (in_place ? out[source_idx] : in[source_idx]);
182 const unsigned int destination_idx =
183 (direction == 0) ? (q + n_q_points_1d*(i + n_q_points_1d*j)) :
184 (direction == 1) ? (i + n_q_points_1d*(q + n_q_points_1d*j)) :
185 (i + n_q_points_1d*(j + n_q_points_1d*q));
188 out[destination_idx] += t;
190 out[destination_idx] = t;
195 template <
int dim,
int fe_degree,
int n_q_po
ints_1d,
typename Number>
198 n_q_points_1d, Number>::value_at_quad_pts(Number *u)
204 values<0, true, false, true>(u, u);
210 values<0, true, false, true>(u, u);
212 values<1, true, false, true>(u, u);
218 values<0, true, false, true>(u, u);
220 values<1, true, false, true>(u, u);
222 values<2, true, false, true>(u, u);
235 template <
int dim,
int fe_degree,
int n_q_po
ints_1d,
typename Number>
238 n_q_points_1d, Number>::integrate_value(Number *u)
244 values<0, false, false, true> (u,u);
250 values<0, false, false, true> (u,u);
252 values<1, false, false, true> (u,u);
258 values<0, false, false, true> (u,u);
260 values<1, false, false, true> (u,u);
262 values<2, false, false, true> (u,u);
275 template <
int dim,
int fe_degree,
int n_q_po
ints_1d,
typename Number>
278 n_q_points_1d, Number>::gradient_at_quad_pts(
279 const Number *
const u,
286 gradients<0, true, false, false>(u, grad_u[0]);
292 gradients<0, true, false, false>(u, grad_u[0]);
293 values<0, true, false, false>(u, grad_u[1]);
297 values<1, true, false, true>(grad_u[0], grad_u[0]);
298 gradients<1, true, false, true>(grad_u[1], grad_u[1]);
304 gradients<0, true, false, false>(u, grad_u[0]);
305 values<0, true, false, false>(u, grad_u[1]);
306 values<0, true, false, false>(u, grad_u[2]);
310 values<1, true, false, true>(grad_u[0], grad_u[0]);
311 gradients<1, true, false, true>(grad_u[1], grad_u[1]);
312 values<1, true, false, true>(grad_u[2], grad_u[2]);
316 values<2, true, false, true>(grad_u[0], grad_u[0]);
317 values<2, true, false, true>(grad_u[1], grad_u[1]);
318 gradients<2, true, false, true>(grad_u[2], grad_u[2]);
331 template <
int dim,
int fe_degree,
int n_q_po
ints_1d,
typename Number>
335 n_q_points_1d, Number>::integrate_gradient(
343 gradients<0, false, add, false> (grad_u[dim], u);
349 gradients<0, false, false, true> (grad_u[0], grad_u[0]);
350 values<0, false, false, true> (grad_u[1], grad_u[1]);
354 values<1, false, add, false> (grad_u[0], u);
356 gradients<1, false, true, false> (grad_u[1], u);
362 gradients<0, false, false, true> (grad_u[0], grad_u[0]);
363 values<0, false, false, true> (grad_u[1], grad_u[1]);
364 values<0, false, false, true> (grad_u[2], grad_u[2]);
368 values<1, false, false, true> (grad_u[0], grad_u[0]);
369 gradients<1, false, false, true> (grad_u[1], grad_u[1]);
370 values<1, false, false, true> (grad_u[2], grad_u[2]);
374 values<2, false, add, false> (grad_u[0], u);
376 values<2, false, true, false> (grad_u[1], u);
378 gradients<2, false, true, false> (grad_u[2], u);
391 DEAL_II_NAMESPACE_CLOSE
constexpr unsigned int pow(const unsigned int base, const unsigned int iexp)