Nektar++
Loading...
Searching...
No Matches
PhysDerivBlockOpDeviceSumFacKernels.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: PhysDerivBlockOpDeviceSumFacKernels.hpp
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description: Device SumFac kernels of the physical derivative.
32///////////////////////////////////////////////////////////////////////////////
33
34/**
35 * @file PhysDerivBlockOpDeviceSumFacKernels.hpp
36 * @brief Device SumFac kernels of the physical derivative: one element
37 * per warp lane.
38 *
39 * @details
40 * Every kernel here is constrained to the MultiRegions::SumFac strategy
41 * and comes in two layers:
42 * - the per-element kernels (`PhysDeriv{,Dir}{1,2,3}DSumFacKernel`
43 * taking an @p ilane), which do the whole element's work in one lane:
44 * for each of the element's quadrature points they take the
45 * tensorial derivatives with the 1D differentiation matrices, apply
46 * the shape's collapsed-coordinate correction and contract the
47 * result with the derivative factors. All arrays are warp
48 * interleaved, entry @em n of an element being at
49 * `warpsize * n + ilane`;
50 * - the launch entry points, which check the size-parameter type at
51 * compile time, unpack it, stage any collapsed-coordinate tables the
52 * shape needs in shared memory, then grid-stride over the block's
53 * elements: split the global index into lane and warp, offset the
54 * data pointers to that warp and call the per-element kernel. The
55 * three PhysDerivKernelLauncher overloads (one per dimension,
56 * selected by the size-parameter type) are what the block operator
57 * launches through DEVICE_3DGRID_KERNEL_LAUNCHER, whose grid Y and Z
58 * axes carry the homogeneous-mode and component counts so a single
59 * launch covers every component and mode of the block, the one- and
60 * two-dimensional overloads reserving a third output plane per
61 * component once the mode count exceeds one (see the 1D overload).
62 * The per-direction `PhysDerivDir{1,2,3}DKernelLauncher` are not
63 * instantiated anywhere (see their warnings).
64 *
65 * The derivative factors are untransposed and warp interleaved: the
66 * `ndf = coordDim * dimension` factors of one point are adjacent
67 * (stride warpsize), and consecutive points follow, so a deformed
68 * element addresses factor @em c of point @em n at
69 * `warpsize * (ndf * n + c) + ilane` and a regular one simply at
70 * `warpsize * c + ilane`. That is what the DEFORMED template flag
71 * selects; nothing else about the two instantiations differs.
72 *
73 * The per-direction ("Dir") kernels produce a single Cartesian
74 * component, optionally accumulating; PhysDeriv itself never calls
75 * them, the Divergence device SumFac kernels (and, in one dimension,
76 * the CurlCurl ones) do. The all-component per-element kernels are in
77 * turn shared with the AdvectionDealias, Helmholtz, Laplacian and
78 * LinAdvDiffReaction device SumFac kernels.
79 *
80 * The SumDerivTensor kernels in this file are the transposes of the
81 * tensorial derivative and belong to the weak-form families
82 * (IProductWRTDerivBase, Laplacian, Helmholtz, LinAdvDiffReaction)
83 * rather than to PhysDeriv; they are collected here alongside the
84 * forward derivative kernels they mirror.
85 *
86 * The whole file is compiled only for the device back-ends
87 * (NEKTAR_ENABLE_DEVICE together with DEVICE_COMPILE_ONLY).
88 *
89 * @see PhysDerivBlockOpDeviceSumFacTOPKernels.hpp for the SumFacTOP
90 * counterparts, which spread one element over a whole thread block.
91 */
92
93#pragma once
94
99
101
103{
104
105#if defined(NEKTAR_ENABLE_DEVICE) && defined(DEVICE_COMPILE_ONLY)
106/**
107 * @brief Dynamic shared memory, in elements of the data type, a 1D
108 * SumFac launch needs: none, since a segment has no
109 * collapsed-coordinate tables to stage.
110 *
111 * @tparam SHAPE_TYPE Element shape; unused.
112 * @tparam Implementation Constrained to MultiRegions::SumFac.
113 * @tparam TPhysSizeParameter1D 1D physical-space size parameter (see
114 * ElmtHelper.hpp).
115 *
116 * @param sizeParam1D Element sizes; unused.
117 * @param elmtsPerBlock Elements per thread block; unused.
118 * @param useSharedMemoryWsp Unused; SumFac reads the input in place.
119 *
120 * @return Zero.
121 */
122template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
123 typename TPhysSizeParameter1D,
124 std::enable_if_t<std::is_same_v<Implementation, SumFac> &&
125 IsPhysSizeParameter1D_v<TPhysSizeParameter1D>,
126 bool>
127 Enable = true>
128inline constexpr unsigned int PhysDerivSharedMemorySize(
129 [[maybe_unused]] const TPhysSizeParameter1D sizeParam1D,
130 [[maybe_unused]] const unsigned int elmtsPerBlock,
131 [[maybe_unused]] const bool useSharedMemoryWsp)
132{
133 return 0;
134}
135
136/**
137 * @brief Dynamic shared memory, in elements of the data type, a 2D
138 * SumFac launch needs: room for the collapsed-coordinate tables of a
139 * triangle, none for a quadrilateral.
140 *
141 * @tparam SHAPE_TYPE Quad, Tri or NodalTri.
142 * @tparam Implementation Constrained to MultiRegions::SumFac.
143 * @tparam TPhysSizeParameter2D 2D physical-space size parameter (see
144 * ElmtHelper.hpp).
145 *
146 * @param sizeParam2D Quadrature-point counts per direction.
147 * @param elmtsPerBlock Elements per thread block; unused.
148 * @param useSharedMemoryWsp Unused; SumFac reads the input in place.
149 *
150 * @return Table entries to allocate per thread block.
151 */
152template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
153 typename TPhysSizeParameter2D,
154 std::enable_if_t<std::is_same_v<Implementation, SumFac> &&
155 IsPhysSizeParameter2D_v<TPhysSizeParameter2D>,
156 bool>
157 Enable = true>
158inline constexpr unsigned int PhysDerivSharedMemorySize(
159 [[maybe_unused]] const TPhysSizeParameter2D sizeParam2D,
160 [[maybe_unused]] const unsigned int elmtsPerBlock,
161 [[maybe_unused]] const bool useSharedMemoryWsp)
162{
163 if constexpr (SHAPE_TYPE == LibUtilities::Quad)
164 {
165 return 0;
166 }
167 else if constexpr (SHAPE_TYPE == LibUtilities::Tri ||
168 SHAPE_TYPE == LibUtilities::NodalTri)
169 {
170 const unsigned int nq0 = sizeParam2D.nq0();
171 const unsigned int nq1 = sizeParam2D.nq1();
172
173 return nq0 + nq1;
174 }
175}
176
177/**
178 * @brief Dynamic shared memory, in elements of the data type, a 3D
179 * SumFac launch needs: room for the collapsed-coordinate tables the
180 * shape uses, none for a hexahedron.
181 *
182 * A (nodal) tetrahedron stages four tables (`nq0 + 2 * nq1 + nq2`
183 * entries, direction 1 contributing both \f$\tfrac{1}{2}(1+\eta_1)\f$
184 * and \f$2/(1-\eta_1)\f$), a (nodal) prism two and a pyramid three.
185 *
186 * @tparam SHAPE_TYPE Hex, Tet, NodalTet, Prism, NodalPrism,
187 * Pyr or NodalPyr.
188 * @tparam Implementation Constrained to MultiRegions::SumFac.
189 * @tparam TPhysSizeParameter3D 3D physical-space size parameter (see
190 * ElmtHelper.hpp).
191 *
192 * @param sizeParam3D Quadrature-point counts per direction.
193 * @param elmtsPerBlock Elements per thread block; unused.
194 * @param useSharedMemoryWsp Unused; SumFac reads the input in place.
195 *
196 * @return Table entries to allocate per thread block.
197 */
198template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
199 typename TPhysSizeParameter3D,
200 std::enable_if_t<std::is_same_v<Implementation, SumFac> &&
201 IsPhysSizeParameter3D_v<TPhysSizeParameter3D>,
202 bool>
203 Enable = true>
204inline constexpr unsigned int PhysDerivSharedMemorySize(
205 const TPhysSizeParameter3D sizeParam3D,
206 [[maybe_unused]] const unsigned int elmtsPerBlock,
207 [[maybe_unused]] const bool useSharedMemoryWsp)
208{
209 const unsigned int nq0 = sizeParam3D.nq0();
210 const unsigned int nq1 = sizeParam3D.nq1();
211 const unsigned int nq2 = sizeParam3D.nq2();
212
213 if constexpr (SHAPE_TYPE == LibUtilities::Hex)
214 {
215 return 0;
216 }
217 else if constexpr (SHAPE_TYPE == LibUtilities::Tet ||
218 SHAPE_TYPE == LibUtilities::NodalTet)
219 {
220 return nq0 + 2u * nq1 + nq2;
221 }
222 else if constexpr (SHAPE_TYPE == LibUtilities::Prism ||
223 SHAPE_TYPE == LibUtilities::NodalPrism)
224 {
225 return nq0 + nq2;
226 }
227 else if constexpr (SHAPE_TYPE == LibUtilities::Pyr ||
228 SHAPE_TYPE == LibUtilities::NodalPyr)
229 {
230 return nq0 + nq1 + nq2;
231 }
232}
233
234/**
235 * @brief One element, one dimension: differentiate a segment in the
236 * calling lane and scale by the derivative factors.
237 *
238 * With one standard direction there is nothing to contract and no
239 * collapsed-coordinate correction:
240 * `out[k][i] = df[k] * sum_q D0[q * nq0 + i] * in[q]`.
241 *
242 * @tparam DEFORMED Derivative factors vary point by point.
243 * @tparam TData Floating-point type of the field data.
244 *
245 * @param ilane Lane index within the warp; selects the element.
246 * @param ncoord Cartesian components to produce (coordDim);
247 * also the number of derivative factors per point.
248 * @param nq0 Quadrature points of the element.
249 * @param outoffset Stride between the Cartesian planes of @p out.
250 * @param D0 1D differentiation matrix, column-major:
251 * `D0[q * nq0 + i]` differentiates at point i.
252 * @param df Derivative factors of this lane's warp.
253 * @param in Input values, warp interleaved.
254 * @param out Cartesian derivatives, plane @em k written at
255 * `k * outoffset`.
256 */
257template <bool DEFORMED, typename TData>
258NEK_DEVICE_INLINE static void PhysDeriv1DSumFacKernel(
259 const unsigned int ilane, const unsigned int ncoord, const unsigned int nq0,
260 const size_t outoffset, const TData *NEK_RESTRICT D0,
261 const TData *NEK_RESTRICT df, const TData *NEK_RESTRICT in,
262 TData *NEK_RESTRICT out)
263{
264 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
265
266 for (unsigned int i = 0u; i < nq0; ++i)
267 {
268 const unsigned int index = warpsize * i + ilane;
269 const unsigned int dfindex =
270 DEFORMED ? ncoord * warpsize * i + ilane : ilane;
271
272 // Compute tensorial derivative.
273 TData d0 = 0.0;
274#pragma unroll
275 for (unsigned int q = 0u; q < nq0; ++q)
276 {
277 d0 += D0[q * nq0 + i] * in[warpsize * q + ilane];
278 }
279
280 // Multiply by derivative factors.
281 for (unsigned int k = 0u; k < ncoord; k++)
282 {
283 out[k * outoffset + index] = d0 * df[k * warpsize + dfindex];
284 }
285 }
286}
287
288/**
289 * @brief One element, one dimension, single component: as
290 * PhysDeriv1DSumFacKernel but writing only Cartesian component DIR.
291 *
292 * Template parameter order is `<APPEND, DEFORMED, DIR, TData>`. This is
293 * the entry point the Divergence and CurlCurl device SumFac kernels
294 * call into.
295 *
296 * @tparam APPEND Accumulate onto @p out instead of overwriting.
297 * @tparam DEFORMED Derivative factors vary point by point.
298 * @tparam DIR Cartesian component to produce.
299 * @tparam TData Floating-point type of the field data.
300 *
301 * @param ilane Lane index within the warp; selects the element.
302 * @param ncoord Derivative factors per point; sets the per-point
303 * factor stride when @p DEFORMED.
304 * @param nq0 Quadrature points of the element.
305 * @param D0 1D differentiation matrix, column-major.
306 * @param df Derivative factors of this lane's warp.
307 * @param in Input values, warp interleaved.
308 * @param out Cartesian component DIR, warp interleaved.
309 */
310template <bool APPEND, bool DEFORMED, unsigned int DIR, typename TData>
311NEK_DEVICE_INLINE static void PhysDerivDir1DSumFacKernel(
312 const unsigned int ilane, const unsigned int ncoord, const unsigned int nq0,
313 const TData *NEK_RESTRICT D0, const TData *NEK_RESTRICT df,
314 const TData *NEK_RESTRICT in, TData *NEK_RESTRICT out)
315{
316 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
317
318 for (unsigned int i = 0u; i < nq0; ++i)
319 {
320 const unsigned int index = warpsize * i + ilane;
321 const unsigned int dfindex =
322 DEFORMED ? ncoord * warpsize * i + ilane : ilane;
323
324 // Compute tensorial derivative.
325 TData d0 = 0.0;
326#pragma unroll
327 for (unsigned int q = 0u; q < nq0; ++q)
328 {
329 d0 += D0[q * nq0 + i] * in[warpsize * q + ilane];
330 }
331
332 // Multiply by derivative factors.
333 if constexpr (APPEND)
334 {
335 out[index] += d0 * df[DIR * warpsize + dfindex];
336 }
337 else
338 {
339 out[index] = d0 * df[DIR * warpsize + dfindex];
340 }
341 }
342}
343
344/**
345 * @brief One element, one dimension: apply the transpose of the 1D
346 * differentiation matrix, optionally scaled and accumulated.
347 *
348 * The counterpart of the forward tensorial derivative, indexing
349 * `D0[i * nq0 + q]` instead of `D0[q * nq0 + i]`. Not used by
350 * PhysDeriv; it serves the weak-form families, which need
351 * \f$\sum_d D_d^{\mathsf{T}} v_d\f$.
352 *
353 * @tparam SCALE Multiply the result by @p scale.
354 * @tparam APPEND Accumulate onto @p out instead of overwriting.
355 * @tparam TData Floating-point type of the field data.
356 *
357 * @param ilane Lane index within the warp; selects the element.
358 * @param nq0 Quadrature points of the element.
359 * @param D0 1D differentiation matrix, applied transposed.
360 * @param in0 Input values, warp interleaved.
361 * @param out Output values, warp interleaved.
362 * @param scale Factor applied when @p SCALE.
363 */
364template <bool SCALE, bool APPEND, typename TData>
366 const unsigned int ilane, const unsigned int nq0,
367 const TData *NEK_RESTRICT D0, const TData *NEK_RESTRICT in0,
368 TData *NEK_RESTRICT out, const TData scale = 1.0)
369{
370 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
371
372 for (unsigned int i = 0u; i < nq0; ++i)
373 {
374 // Compute tensorial derivative.
375 TData d0 = 0.0;
376#pragma unroll
377 for (unsigned int q = 0u; q < nq0; ++q)
378 {
379 d0 += D0[i * nq0 + q] * in0[warpsize * q + ilane];
380 }
381
382 if constexpr (SCALE)
383 {
384 d0 *= scale;
385 }
386
387 if constexpr (APPEND)
388 {
389 out[warpsize * i + ilane] += d0;
390 }
391 else
392 {
393 out[warpsize * i + ilane] = d0;
394 }
395 }
396}
397
398/**
399 * @brief One element, two dimensions: differentiate a quadrilateral or
400 * triangle in the calling lane and write all @p ncoord Cartesian
401 * components.
402 *
403 * Per point the two collapsed derivatives are formed, the triangle
404 * correction `d0 *= f1[j]; d1 += d0 * f0[i]` is applied where the shape
405 * requires it, and each output component is
406 * `d0 * df[2k] + d1 * df[2k+1]`. The third component is produced only
407 * for an element embedded in three dimensions.
408 *
409 * @tparam SHAPE_TYPE Quad, Tri or NodalTri.
410 * @tparam DEFORMED Derivative factors vary point by point.
411 * @tparam TData Floating-point type of the field data.
412 *
413 * @param ilane Lane index within the warp; selects the element.
414 * @param ncoord Cartesian components to produce (coordDim); the
415 * derivative factors come `ndf = 2 * ncoord` per
416 * point.
417 * @param nq0,nq1 Quadrature points per direction.
418 * @param outoffset Stride between the Cartesian planes of @p out.
419 * @param D0,D1 1D differentiation matrices, column-major.
420 * @param f0 \f$\tfrac{1}{2}(1+\eta_0)\f$ at the direction-0
421 * points (triangles only).
422 * @param f1 \f$2/(1-\eta_1)\f$ at the direction-1 points
423 * (triangles only).
424 * @param df Derivative factors of this lane's warp.
425 * @param in Input values, warp interleaved.
426 * @param out Cartesian derivatives, plane @em k written at
427 * `k * outoffset`.
428 */
429template <LibUtilities::ShapeType SHAPE_TYPE, bool DEFORMED, typename TData>
430NEK_DEVICE_INLINE static void PhysDeriv2DSumFacKernel(
431 const unsigned int ilane, const unsigned int ncoord, const unsigned int nq0,
432 const unsigned int nq1, const size_t outoffset,
433 const TData *NEK_RESTRICT D0, const TData *NEK_RESTRICT D1,
434 [[maybe_unused]] const TData *NEK_RESTRICT f0,
435 [[maybe_unused]] const TData *NEK_RESTRICT f1, const TData *NEK_RESTRICT df,
436 const TData *NEK_RESTRICT in, TData *NEK_RESTRICT out)
437{
438 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
439
440 const unsigned int ndf = 2 * ncoord;
441
442 for (unsigned int j = 0u, cnt_ji = 0u; j < nq1; ++j)
443 {
444 for (unsigned int i = 0u; i < nq0; ++i, ++cnt_ji)
445 {
446 const unsigned int index = warpsize * cnt_ji + ilane;
447 const unsigned int dfindex =
448 DEFORMED ? ndf * warpsize * cnt_ji + ilane : ilane;
449
450 // Compute tensorial derivative.
451 // Direction 0
452 TData d0 = 0.0;
453#pragma unroll
454 for (unsigned int q = 0u; q < nq0; ++q)
455 {
456 d0 += D0[q * nq0 + i] * in[warpsize * (nq0 * j + q) + ilane];
457 }
458
459 // Direction 1
460 TData d1 = 0.0;
461#pragma unroll
462 for (unsigned int q = 0u; q < nq1; ++q)
463 {
464 d1 += D1[q * nq1 + j] * in[warpsize * (nq0 * q + i) + ilane];
465 }
466
467 // Moving from collapsed to standard coordinates.
468 if constexpr (SHAPE_TYPE == LibUtilities::Tri ||
469 SHAPE_TYPE == LibUtilities::NodalTri)
470 {
471 d0 *= f1[j];
472 d1 += d0 * f0[i];
473 }
474
475 // Multiply by derivative factors.
476 out[index] = d0 * df[0u * warpsize + dfindex] +
477 d1 * df[1u * warpsize + dfindex];
478 out[outoffset + index] = d0 * df[2u * warpsize + dfindex] +
479 d1 * df[3u * warpsize + dfindex];
480 if (ncoord == 3u)
481 {
482 out[2u * outoffset + index] = d0 * df[4u * warpsize + dfindex] +
483 d1 * df[5u * warpsize + dfindex];
484 }
485 }
486 }
487}
488
489/**
490 * @brief One element, two dimensions, single component: as
491 * PhysDeriv2DSumFacKernel but writing only Cartesian component DIR,
492 * `d0 * df[2 * DIR] + d1 * df[2 * DIR + 1]`.
493 *
494 * Template parameter order is
495 * `<SHAPE_TYPE, APPEND, DEFORMED, DIR, TData>`. This is the entry point
496 * the Divergence device SumFac kernels call into.
497 *
498 * @tparam SHAPE_TYPE Quad, Tri or NodalTri.
499 * @tparam APPEND Accumulate onto @p out instead of overwriting.
500 * @tparam DEFORMED Derivative factors vary point by point.
501 * @tparam DIR Cartesian component to produce.
502 * @tparam TData Floating-point type of the field data.
503 *
504 * @param ilane Lane index within the warp; selects the element.
505 * @param ncoord Cartesian components the factor array holds;
506 * sets the per-point factor stride
507 * `ndf = 2 * ncoord`.
508 * @param nq0,nq1 Quadrature points per direction.
509 * @param D0,D1 1D differentiation matrices, column-major.
510 * @param f0,f1 Collapsed-coordinate factor tables, as in
511 * PhysDeriv2DSumFacKernel (triangles only).
512 * @param df Derivative factors of this lane's warp.
513 * @param in Input values, warp interleaved.
514 * @param out Cartesian component DIR, warp interleaved.
515 */
516template <LibUtilities::ShapeType SHAPE_TYPE, bool APPEND, bool DEFORMED,
517 unsigned int DIR, typename TData>
518NEK_DEVICE_INLINE static void PhysDerivDir2DSumFacKernel(
519 const unsigned int ilane, const unsigned int ncoord, const unsigned int nq0,
520 const unsigned int nq1, const TData *NEK_RESTRICT D0,
521 const TData *NEK_RESTRICT D1, [[maybe_unused]] const TData *NEK_RESTRICT f0,
522 [[maybe_unused]] const TData *NEK_RESTRICT f1, const TData *NEK_RESTRICT df,
523 const TData *NEK_RESTRICT in, TData *NEK_RESTRICT out)
524{
525 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
526
527 const unsigned int ndf = 2 * ncoord;
528
529 for (unsigned int j = 0u, cnt_ji = 0u; j < nq1; ++j)
530 {
531 for (unsigned int i = 0u; i < nq0; ++i, ++cnt_ji)
532 {
533 const unsigned int index = warpsize * cnt_ji + ilane;
534 const unsigned int dfindex =
535 DEFORMED ? ndf * warpsize * cnt_ji + ilane : ilane;
536
537 // Compute tensorial derivative.
538 // Direction 0
539 TData d0 = 0.0;
540#pragma unroll
541 for (unsigned int q = 0u; q < nq0; ++q)
542 {
543 d0 += D0[q * nq0 + i] * in[warpsize * (nq0 * j + q) + ilane];
544 }
545
546 TData d1 = 0.0;
547#pragma unroll
548 for (unsigned int q = 0u; q < nq1; ++q)
549 {
550 d1 += D1[q * nq1 + j] * in[warpsize * (nq0 * q + i) + ilane];
551 }
552
553 // Moving from collapsed to standard coordinates.
554 if constexpr (SHAPE_TYPE == LibUtilities::Tri ||
555 SHAPE_TYPE == LibUtilities::NodalTri)
556 {
557 d0 *= f1[j];
558 d1 += d0 * f0[i];
559 }
560
561 // Multiply by derivative factors.
562 if constexpr (APPEND)
563 {
564 out[index] += d0 * df[2u * DIR * warpsize + dfindex] +
565 d1 * df[(2u * DIR + 1u) * warpsize + dfindex];
566 }
567 else
568 {
569 out[index] = d0 * df[2u * DIR * warpsize + dfindex] +
570 d1 * df[(2u * DIR + 1u) * warpsize + dfindex];
571 }
572 }
573 }
574}
575
576/**
577 * @brief One element, two dimensions: apply the transposes of both 1D
578 * differentiation matrices to their own inputs and sum the two
579 * contributions, optionally scaled and accumulated.
580 *
581 * As SumDerivTensor1DKernel, this serves the weak-form families rather
582 * than PhysDeriv.
583 *
584 * @tparam SCALE Multiply the sum by @p scale.
585 * @tparam APPEND Accumulate onto @p out instead of overwriting.
586 * @tparam TData Floating-point type of the field data.
587 *
588 * @param ilane Lane index within the warp; selects the element.
589 * @param nq0,nq1 Quadrature points per direction.
590 * @param D0,D1 1D differentiation matrices, applied transposed.
591 * @param in0 Input differentiated along direction 0.
592 * @param in1 Input differentiated along direction 1.
593 * @param out Output values, warp interleaved.
594 * @param scale Factor applied when @p SCALE.
595 */
596template <bool SCALE, bool APPEND, typename TData>
598 const unsigned int ilane, const unsigned int nq0, const unsigned int nq1,
599 const TData *NEK_RESTRICT D0, const TData *NEK_RESTRICT D1,
600 const TData *NEK_RESTRICT in0, const TData *NEK_RESTRICT in1,
601 TData *NEK_RESTRICT out, const TData scale = 1.0)
602{
603 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
604
605 for (unsigned int j = 0u, cnt_ji = 0u; j < nq1; ++j)
606 {
607 for (unsigned int i = 0u; i < nq0; ++i, ++cnt_ji)
608 {
609 // Compute tensorial derivative.
610 // Direction 0
611 TData d0 = 0.0;
612#pragma unroll
613 for (unsigned int q = 0u; q < nq0; ++q)
614 {
615 d0 += D0[i * nq0 + q] * in0[warpsize * (nq0 * j + q) + ilane];
616 }
617
618 // Direction 1
619 TData d1 = 0.0;
620#pragma unroll
621 for (unsigned int q = 0u; q < nq1; ++q)
622 {
623 d1 += D1[j * nq1 + q] * in1[warpsize * (nq0 * q + i) + ilane];
624 }
625
626 if constexpr (APPEND)
627 {
628 if constexpr (SCALE)
629 {
630 out[warpsize * cnt_ji + ilane] += scale * (d0 + d1);
631 }
632 else
633 {
634 out[warpsize * cnt_ji + ilane] += d0 + d1;
635 }
636 }
637 else
638 {
639 if constexpr (SCALE)
640 {
641 out[warpsize * cnt_ji + ilane] = scale * (d0 + d1);
642 }
643 else
644 {
645 out[warpsize * cnt_ji + ilane] = d0 + d1;
646 }
647 }
648 }
649 }
650}
651
652/**
653 * @brief One element, three dimensions: differentiate the element in
654 * the calling lane and write all three Cartesian components.
655 *
656 * Per point the three collapsed derivatives are formed, the shape's
657 * collapsed-to-standard correction is applied -- a prism scales
658 * direction 0 by @p f2 and adds its @p f0 multiple onto direction 2, a
659 * pyramid does the same for directions 0 and 1 with @p f0 and @p f1, a
660 * (nodal) tetrahedron scales direction 0 by @p f1m and @p f2 and
661 * direction 1 by @p f2 and folds both into directions 1 and 2, a
662 * hexahedron needs none -- and each output component is
663 * `sum_d d_d * df[3k+d]` over the nine derivative factors.
664 *
665 * @tparam SHAPE_TYPE Hex, Tet, NodalTet, Prism, NodalPrism, Pyr or NodalPyr.
666 * @tparam DEFORMED Derivative factors vary point by point.
667 * @tparam TData Floating-point type of the field data.
668 *
669 * @param ilane Lane index within the warp; selects the
670 * element.
671 * @param nq0,nq1,nq2 Quadrature points per direction.
672 * @param outoffset Stride between the Cartesian planes of
673 * @p out.
674 * @param D0,D1,D2 1D differentiation matrices, column-major.
675 * @param f0 \f$\tfrac{1}{2}(1+\eta_0)\f$ at the
676 * direction-0 points.
677 * @param f1 \f$\tfrac{1}{2}(1+\eta_1)\f$ at the
678 * direction-1 points.
679 * @param f1m \f$2/(1-\eta_1)\f$ at the direction-1
680 * points.
681 * @param f2 \f$2/(1-\eta_2)\f$ at the direction-2
682 * points.
683 * @param df Derivative factors of this lane's warp,
684 * nine per point or per element.
685 * @param in Input values, warp interleaved.
686 * @param out Cartesian derivatives, plane @em k written
687 * at `k * outoffset`.
688 */
689template <LibUtilities::ShapeType SHAPE_TYPE, bool DEFORMED, typename TData>
690NEK_DEVICE_INLINE static void PhysDeriv3DSumFacKernel(
691 const unsigned int ilane, const unsigned int nq0, const unsigned int nq1,
692 const unsigned int nq2, const size_t outoffset,
693 const TData *NEK_RESTRICT D0, const TData *NEK_RESTRICT D1,
694 const TData *NEK_RESTRICT D2, [[maybe_unused]] const TData *NEK_RESTRICT f0,
695 [[maybe_unused]] const TData *NEK_RESTRICT f1,
696 [[maybe_unused]] const TData *NEK_RESTRICT f1m,
697 [[maybe_unused]] const TData *NEK_RESTRICT f2, const TData *NEK_RESTRICT df,
698 const TData *NEK_RESTRICT in, TData *NEK_RESTRICT out)
699{
700 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
701
702 constexpr unsigned int ndf = 9u;
703
704 for (unsigned int k = 0u, cnt_kji = 0u; k < nq2; k++)
705 {
706 for (unsigned int j = 0u; j < nq1; j++)
707 {
708 for (unsigned int i = 0u; i < nq0; i++, cnt_kji++)
709 {
710 const unsigned int index = warpsize * cnt_kji + ilane;
711 const unsigned int dfindex =
712 DEFORMED ? ndf * warpsize * cnt_kji + ilane : ilane;
713
714 // Compute tensorial derivative.
715 // Direction 0
716 TData d0 = 0.0;
717#pragma unroll
718 for (unsigned int q = 0u; q < nq0; ++q)
719 {
720 d0 += D0[q * nq0 + i] *
721 in[warpsize * (nq0 * nq1 * k + nq0 * j + q) + ilane];
722 }
723
724 // Direction 1
725 TData d1 = 0.0;
726#pragma unroll
727 for (unsigned int q = 0u; q < nq1; ++q)
728 {
729 d1 += D1[q * nq1 + j] *
730 in[warpsize * (nq0 * nq1 * k + nq0 * q + i) + ilane];
731 }
732
733 // Direction 2
734 TData d2 = 0.0;
735#pragma unroll
736 for (unsigned int q = 0u; q < nq2; ++q)
737 {
738 d2 += D2[q * nq2 + k] *
739 in[warpsize * (nq0 * nq1 * q + nq0 * j + i) + ilane];
740 }
741
742 // Moving from collapsed to standard coordinates.
743 if constexpr (SHAPE_TYPE == LibUtilities::Tet ||
744 SHAPE_TYPE == LibUtilities::NodalTet)
745 {
746 TData tmp0 = f1m[j] * f2[k] * d0;
747 TData tmp1 = f0[i] * tmp0;
748 TData tmp2 = f2[k] * d1;
749 d0 = tmp0;
750 d1 = tmp1 + tmp2;
751 d2 += tmp1 + f1[j] * tmp2;
752 }
753 else if constexpr (SHAPE_TYPE == LibUtilities::Prism ||
754 SHAPE_TYPE == LibUtilities::NodalPrism)
755 {
756 d0 *= f2[k];
757 d2 += f0[i] * d0;
758 }
759 else if constexpr (SHAPE_TYPE == LibUtilities::Pyr ||
760 SHAPE_TYPE == LibUtilities::NodalPyr)
761 {
762 d0 *= f2[k];
763 d1 *= f2[k];
764 d2 += f0[i] * d0 + f1[j] * d1;
765 }
766
767 // Multiply by derivative factors.
768 out[index] = d0 * df[0u * warpsize + dfindex] +
769 d1 * df[1u * warpsize + dfindex] +
770 d2 * df[2u * warpsize + dfindex];
771 out[outoffset + index] = d0 * df[3u * warpsize + dfindex] +
772 d1 * df[4u * warpsize + dfindex] +
773 d2 * df[5u * warpsize + dfindex];
774 out[2u * outoffset + index] = d0 * df[6u * warpsize + dfindex] +
775 d1 * df[7u * warpsize + dfindex] +
776 d2 * df[8u * warpsize + dfindex];
777 }
778 }
779 }
780}
781
782/**
783 * @brief One element, three dimensions, single component: as
784 * PhysDeriv3DSumFacKernel but writing only Cartesian component DIR,
785 * `sum_d d_d * df[3 * DIR + d]`.
786 *
787 * Template parameter order is
788 * `<SHAPE_TYPE, APPEND, DEFORMED, DIR, TData>`. This is the entry point
789 * the Divergence device SumFac kernels call into.
790 *
791 * @tparam SHAPE_TYPE Hex, Tet, NodalTet, Prism, NodalPrism, Pyr or NodalPyr.
792 * @tparam APPEND Accumulate onto @p out instead of overwriting.
793 * @tparam DEFORMED Derivative factors vary point by point.
794 * @tparam DIR Cartesian component to produce.
795 * @tparam TData Floating-point type of the field data.
796 *
797 * @param ilane Lane index within the warp; selects the
798 * element.
799 * @param nq0,nq1,nq2 Quadrature points per direction.
800 * @param D0,D1,D2 1D differentiation matrices, column-major.
801 * @param f0,f1,f1m,f2 Collapsed-coordinate factor tables, as in
802 * PhysDeriv3DSumFacKernel.
803 * @param df Derivative factors of this lane's warp.
804 * @param in Input values, warp interleaved.
805 * @param out Cartesian component DIR, warp interleaved.
806 */
807template <LibUtilities::ShapeType SHAPE_TYPE, bool APPEND, bool DEFORMED,
808 unsigned int DIR, typename TData>
809NEK_DEVICE_INLINE static void PhysDerivDir3DSumFacKernel(
810 const unsigned int ilane, const unsigned int nq0, const unsigned int nq1,
811 const unsigned int nq2, const TData *NEK_RESTRICT D0,
812 const TData *NEK_RESTRICT D1, const TData *NEK_RESTRICT D2,
813 [[maybe_unused]] const TData *NEK_RESTRICT f0,
814 [[maybe_unused]] const TData *NEK_RESTRICT f1,
815 [[maybe_unused]] const TData *NEK_RESTRICT f1m,
816 [[maybe_unused]] const TData *NEK_RESTRICT f2, const TData *NEK_RESTRICT df,
817 const TData *NEK_RESTRICT in, TData *NEK_RESTRICT out)
818{
819 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
820
821 constexpr unsigned int ndf = 9u;
822
823 for (unsigned int k = 0u, cnt_kji = 0u; k < nq2; k++)
824 {
825 for (unsigned int j = 0u; j < nq1; j++)
826 {
827 for (unsigned int i = 0u; i < nq0; i++, cnt_kji++)
828 {
829 const unsigned int index = warpsize * cnt_kji + ilane;
830 const unsigned int dfindex =
831 DEFORMED ? ndf * warpsize * cnt_kji + ilane : ilane;
832
833 // Compute tensorial derivative.
834 // Direction 0
835 TData d0 = 0.0;
836#pragma unroll
837 for (unsigned int q = 0u; q < nq0; ++q)
838 {
839 d0 += D0[q * nq0 + i] *
840 in[warpsize * (nq0 * nq1 * k + nq0 * j + q) + ilane];
841 }
842
843 // Direction 1
844 TData d1 = 0.0;
845#pragma unroll
846 for (unsigned int q = 0u; q < nq1; ++q)
847 {
848 d1 += D1[q * nq1 + j] *
849 in[warpsize * (nq0 * nq1 * k + nq0 * q + i) + ilane];
850 }
851
852 // Direction 2
853 TData d2 = 0.0;
854#pragma unroll
855 for (unsigned int q = 0u; q < nq2; ++q)
856 {
857 d2 += D2[q * nq2 + k] *
858 in[warpsize * (nq0 * nq1 * q + nq0 * j + i) + ilane];
859 }
860
861 // Moving from collapsed to standard coordinates.
862 if constexpr (SHAPE_TYPE == LibUtilities::Tet ||
863 SHAPE_TYPE == LibUtilities::NodalTet)
864 {
865 TData tmp0 = f1m[j] * f2[k] * d0;
866 TData tmp1 = f0[i] * tmp0;
867 TData tmp2 = f2[k] * d1;
868 d0 = tmp0;
869 d1 = tmp1 + tmp2;
870 d2 += tmp1 + f1[j] * tmp2;
871 }
872 else if constexpr (SHAPE_TYPE == LibUtilities::Prism ||
873 SHAPE_TYPE == LibUtilities::NodalPrism)
874 {
875 d0 *= f2[k];
876 d2 += f0[i] * d0;
877 }
878 else if constexpr (SHAPE_TYPE == LibUtilities::Pyr ||
879 SHAPE_TYPE == LibUtilities::NodalPyr)
880 {
881 d0 *= f2[k];
882 d1 *= f2[k];
883 d2 += f0[i] * d0 + f1[j] * d1;
884 }
885
886 // Multiply by derivative factors.
887 if constexpr (APPEND)
888 {
889 out[index] += d0 * df[(3u * DIR) * warpsize + dfindex] +
890 d1 * df[(3u * DIR + 1) * warpsize + dfindex] +
891 d2 * df[(3u * DIR + 2) * warpsize + dfindex];
892 }
893 else
894 {
895 out[index] = d0 * df[(3u * DIR) * warpsize + dfindex] +
896 d1 * df[(3u * DIR + 1) * warpsize + dfindex] +
897 d2 * df[(3u * DIR + 2) * warpsize + dfindex];
898 }
899 }
900 }
901 }
902}
903
904/**
905 * @brief One element, three dimensions: apply the transposes of the
906 * three 1D differentiation matrices to their own inputs and sum the
907 * contributions, optionally scaled and accumulated.
908 *
909 * As SumDerivTensor1DKernel, this serves the weak-form families rather
910 * than PhysDeriv.
911 *
912 * @tparam SCALE Multiply the sum by @p scale.
913 * @tparam APPEND Accumulate onto @p out instead of overwriting.
914 * @tparam TData Floating-point type of the field data.
915 *
916 * @param ilane Lane index within the warp; selects the
917 * element.
918 * @param nq0,nq1,nq2 Quadrature points per direction.
919 * @param D0,D1,D2 1D differentiation matrices, applied
920 * transposed.
921 * @param in0,in1,in2 Inputs differentiated along directions 0, 1
922 * and 2.
923 * @param out Output values, warp interleaved.
924 * @param scale Factor applied when @p SCALE.
925 */
926template <bool SCALE, bool APPEND, typename TData>
928 const unsigned int ilane, const unsigned int nq0, const unsigned int nq1,
929 const unsigned int nq2, const TData *NEK_RESTRICT D0,
930 const TData *NEK_RESTRICT D1, const TData *NEK_RESTRICT D2,
931 const TData *NEK_RESTRICT in0, const TData *NEK_RESTRICT in1,
932 const TData *NEK_RESTRICT in2, TData *NEK_RESTRICT out,
933 const TData scale = 1.0)
934{
935 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
936
937 for (unsigned int k = 0u, cnt_kji = 0u; k < nq2; k++)
938 {
939 for (unsigned int j = 0u; j < nq1; j++)
940 {
941 for (unsigned int i = 0u; i < nq0; i++, cnt_kji++)
942 {
943 // Compute tensorial derivative.
944 // Direction 0
945 TData d0 = 0.0;
946#pragma unroll
947 for (unsigned int q = 0u; q < nq0; ++q)
948 {
949 d0 += D0[i * nq0 + q] *
950 in0[warpsize * (nq0 * nq1 * k + nq0 * j + q) + ilane];
951 }
952
953 // Direction 1
954 TData d1 = 0.0;
955#pragma unroll
956 for (unsigned int q = 0u; q < nq1; ++q)
957 {
958 d1 += D1[j * nq1 + q] *
959 in1[warpsize * (nq0 * nq1 * k + nq0 * q + i) + ilane];
960 }
961
962 // Direction 2
963 TData d2 = 0.0;
964#pragma unroll
965 for (unsigned int q = 0u; q < nq2; ++q)
966 {
967 d2 += D2[k * nq2 + q] *
968 in2[warpsize * (nq0 * nq1 * q + nq0 * j + i) + ilane];
969 }
970
971 if constexpr (APPEND)
972 {
973 if constexpr (SCALE)
974 {
975 out[warpsize * cnt_kji + ilane] +=
976 scale * (d0 + d1 + d2);
977 }
978 else
979 {
980 out[warpsize * cnt_kji + ilane] += d0 + d1 + d2;
981 }
982 }
983 else
984 {
985 if constexpr (SCALE)
986 {
987 out[warpsize * cnt_kji + ilane] =
988 scale * (d0 + d1 + d2);
989 }
990 else
991 {
992 out[warpsize * cnt_kji + ilane] = d0 + d1 + d2;
993 }
994 }
995 }
996 }
997 }
998}
999
1000/**
1001 * @brief SumFac launch entry point for a block of segments: unpacks the
1002 * size parameter, then grid-strides over the block's segments on the
1003 * grid's X axis, one element per warp lane, while the Y and Z axes
1004 * select the homogeneous mode and component of a single fused launch
1005 * that covers every (component, mode) pair at once.
1006 *
1007 * Selected over the SumFacTOP overload of the same name by the
1008 * Implementation tag, and over the two- and three-dimensional
1009 * overloads by the size-parameter type, which may be either the
1010 * runtime or the compile-time form.
1011 *
1012 * The global thread index is split into a lane and a warp; the
1013 * derivative-factor pointer is offset to that warp only -- `ndf *
1014 * dfsize` values per element, `dfsize` being `nq0` for a deformed
1015 * element and 1 for a regular one -- since the factors do not depend on
1016 * component or mode. The data pointers additionally carry the block
1017 * index `m` (mode, range `nmode`) and `c` (component): the input slab
1018 * is `nmode * c + m`, matching the component-major, mode-minor order of
1019 * the block storage, and the output slab `outDim * nmode * c + m`,
1020 * where `outDim` is `ncoord` unless the launch is homogeneous
1021 * (`nmode > 1`), in which case it is always three: a homogeneous
1022 * expansion reserves the output's third (z) plane even for this
1023 * in-plane kernel, which only ever writes `ncoord` of the `outDim`
1024 * planes it reserves, leaving the rest for detail::DerivZOpImpl to fill
1025 * in. No shared memory is used in one dimension; @p shmemptr is
1026 * accepted so that all three overloads share one launch macro.
1027 *
1028 * @tparam SHAPE_TYPE Element shape (segments only; unused).
1029 * @tparam Implementation Constrained to MultiRegions::SumFac.
1030 * @tparam DEFORMED Derivative factors vary point by point.
1031 * @tparam TPhysSizeParameter1D 1D physical size-parameter type.
1032 * @tparam TthreadBlock Thread-block handle type.
1033 * @tparam TData Floating-point type of the field data.
1034 *
1035 * @param sizeParam1D Coordinate dimension and point count of the
1036 * element.
1037 * @param nelmt Elements in the block, including padding.
1038 * @param elmtsPerBlock Elements per thread block, one per thread; unused.
1039 * @param outoffset Stride between the Cartesian planes of @p out.
1040 * @param useSharedMemoryWsp Unused; SumFac reads the input in place.
1041 * @param D0 1D differentiation matrix.
1042 * @param df Derivative factors of the block.
1043 * @param in Input values of the block, warp interleaved and
1044 * spanning every component and homogeneous mode.
1045 * @param out Output values of the block, warp interleaved and
1046 * spanning every component and homogeneous mode.
1047 * @param shmemptr Dynamic shared memory of this thread block;
1048 * unused in one dimension.
1049 * @param threadBlock Thread-block handle supplied by the launch
1050 * macro.
1051 */
1052template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
1053 bool DEFORMED, typename TPhysSizeParameter1D, typename TthreadBlock,
1054 typename TData,
1055 std::enable_if_t<std::is_same_v<Implementation, SumFac>, bool>
1056 Enable = true>
1058 const TPhysSizeParameter1D sizeParam1D, const size_t nelmt,
1059 [[maybe_unused]] const unsigned int elmtsPerBlock, const size_t outoffset,
1060 [[maybe_unused]] const bool useSharedMemoryWsp,
1061 const TData *NEK_RESTRICT D0, const TData *NEK_RESTRICT df,
1062 const TData *NEK_RESTRICT in, TData *NEK_RESTRICT out,
1063 [[maybe_unused]] unsigned char *shmemptr, const TthreadBlock &threadBlock)
1064{
1065 static_assert(
1066 IsPhysSizeParameter1D_v<TPhysSizeParameter1D>,
1067 "Template argument must be either of type "
1068 "NonTemplatedPhysSizeParameter1D or TemplatedPhysSizeParameter1D.");
1069
1070 const unsigned int ncoord = sizeParam1D.ncoord();
1071 const unsigned int nq0 = sizeParam1D.nq0();
1072
1073 const unsigned int ndf = ncoord;
1074 const unsigned int dfsize = DEFORMED ? nq0 : 1u;
1075
1076 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
1077
1078 size_t e = getGlobalIdx<0>(threadBlock);
1079 const unsigned int m = getBlockIdx<1>(threadBlock);
1080 const unsigned int c = getBlockIdx<2>(threadBlock);
1081 const unsigned int nmode = getBlockRange<1>(threadBlock);
1082 const unsigned int outDim = (nmode > 1) ? 3u : ncoord;
1083 while (e < nelmt)
1084 {
1085 const size_t ilane = e % warpsize;
1086 const size_t iwarp = e / warpsize;
1087 const TData *dfptr = df + ndf * dfsize * warpsize * iwarp;
1088 const TData *inptr =
1089 in + nq0 * (nelmt * (nmode * c + m) + warpsize * iwarp);
1090 TData *outptr =
1091 out + nq0 * (nelmt * (outDim * nmode * c + m) + warpsize * iwarp);
1092 PhysDeriv1DSumFacKernel<DEFORMED>(ilane, ncoord, nq0, outoffset, D0,
1093 dfptr, inptr, outptr);
1094
1095 e += getGlobalRange<0>(threadBlock);
1096 }
1097}
1098
1099/**
1100 * @brief SumFac launch entry point for one Cartesian component of a
1101 * block of segments: unpacks the size parameter, then grid-strides
1102 * over the block's segments on the grid's X axis, one element per warp
1103 * lane, offsetting the data pointers by the block index `c`
1104 * (component) alone -- there is no homogeneous-mode axis here.
1105 *
1106 * @warning Not compilable if ever instantiated: the call below passes
1107 * eight arguments to the per-element PhysDerivDir1DSumFacKernel, which
1108 * declares seven; the extra is a literal `0` between `nq0` and @p D0,
1109 * in the position an `outoffset` parameter would occupy. Harmless
1110 * only because this launcher currently has no call site; callers
1111 * needing a single Cartesian component use the per-element
1112 * PhysDerivDir1DSumFacKernel directly, as the Divergence and CurlCurl
1113 * kernels do.
1114 *
1115 * @tparam Implementation Constrained to MultiRegions::SumFac.
1116 * @tparam APPEND Accumulate onto @p out.
1117 * @tparam DEFORMED Derivative factors vary point by point.
1118 * @tparam DIR Cartesian component to produce.
1119 * @tparam TPhysSizeParameter1D 1D physical size-parameter type.
1120 * @tparam TthreadBlock Thread-block handle type.
1121 * @tparam TData Floating-point type of the field data.
1122 *
1123 * @param sizeParam1D Coordinate dimension and point count of the
1124 * element.
1125 * @param nelmt Elements in the block, including padding.
1126 * @param elmtsPerBlock Elements per thread block, one per thread; unused.
1127 * @param D0 1D differentiation matrix.
1128 * @param df Derivative factors of the block.
1129 * @param in Input values of the block.
1130 * @param out Cartesian component DIR of the block.
1131 * @param threadBlock Thread-block handle supplied by the launch
1132 * macro.
1133 */
1134template <typename Implementation, bool APPEND, bool DEFORMED, unsigned int DIR,
1135 typename TPhysSizeParameter1D, typename TthreadBlock, typename TData,
1136 std::enable_if_t<std::is_same_v<Implementation, SumFac>, bool>
1137 Enable = true>
1138NEK_DEVICE_KERNEL void PhysDerivDir1DKernelLauncher(
1139 const TPhysSizeParameter1D sizeParam1D, const size_t nelmt,
1140 [[maybe_unused]] const unsigned int elmtsPerBlock,
1141 const TData *NEK_RESTRICT D0, const TData *NEK_RESTRICT df,
1142 const TData *NEK_RESTRICT in, TData *NEK_RESTRICT out,
1143 const TthreadBlock &threadBlock)
1144{
1145 static_assert(
1146 IsPhysSizeParameter1D_v<TPhysSizeParameter1D>,
1147 "Template argument must be either of type "
1148 "NonTemplatedPhysSizeParameter1D or TemplatedPhysSizeParameter1D.");
1149
1150 const unsigned int ncoord = sizeParam1D.ncoord();
1151 const unsigned int nq0 = sizeParam1D.nq0();
1152
1153 const unsigned int ndf = ncoord;
1154 const unsigned int dfsize = DEFORMED ? nq0 : 1u;
1155
1156 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
1157
1158 size_t e = getGlobalIdx<0>(threadBlock);
1159 const unsigned int c = getBlockIdx<1>(threadBlock);
1160 while (e < nelmt)
1161 {
1162 const size_t ilane = e % warpsize;
1163 const size_t iwarp = e / warpsize;
1164 const TData *dfptr = df + ndf * dfsize * warpsize * iwarp;
1165 const TData *inptr = in + nq0 * (nelmt * c + warpsize * iwarp);
1166 TData *outptr = out + nq0 * (nelmt * c + warpsize * iwarp);
1167 PhysDerivDir1DSumFacKernel<APPEND, DEFORMED, DIR>(
1168 ilane, ncoord, nq0, 0, D0, dfptr, inptr, outptr);
1169
1170 e += getGlobalRange<0>(threadBlock);
1171 }
1172}
1173
1174/**
1175 * @brief SumFac launch entry point for a block of quadrilaterals or
1176 * triangles: claims the dynamic shared memory, unpacks the size
1177 * parameter, stages the collapsed-coordinate tables it needs, then
1178 * grid-strides over the block's elements on the grid's X axis, one
1179 * element per warp lane, while the Y and Z axes select the homogeneous
1180 * mode and component of a single fused launch that covers every
1181 * (component, mode) pair at once.
1182 *
1183 * For a (nodal) triangle the two tables are copied into the dynamic
1184 * shared memory sized by PhysDerivSharedMemorySize and the block
1185 * synchronises before the element loop; for a quadrilateral no shared
1186 * memory is used and null pointers are handed on. Each iteration offsets
1187 * the derivative-factor pointer to its warp only -- `ndf * dfsize`
1188 * values per element, `dfsize` being nqTot when deformed and 1
1189 * otherwise, since the factors do not depend on component or mode --
1190 * and calls PhysDeriv2DSumFacKernel. The data pointers additionally
1191 * carry the block index `m` (mode, range `nmode`) and `c` (component),
1192 * exactly as in the one-dimensional overload above: the input slab is
1193 * `nmode * c + m` and the output slab `outDim * nmode * c + m`,
1194 * `outDim` collapsing to `ncoord` unless the launch is homogeneous, in
1195 * which case it reserves the third plane for the z-derivative backend
1196 * as described there.
1197 *
1198 * @tparam SHAPE_TYPE Quad, Tri or NodalTri.
1199 * @tparam Implementation Constrained to MultiRegions::SumFac.
1200 * @tparam DEFORMED Derivative factors vary point by point.
1201 * @tparam TPhysSizeParameter2D 2D physical size-parameter type.
1202 * @tparam TthreadBlock Thread-block handle type.
1203 * @tparam TData Floating-point type of the field data.
1204 *
1205 * @param sizeParam2D Coordinate dimension and point counts of the
1206 * element.
1207 * @param nelmt Elements in the block, including padding.
1208 * @param elmtsPerBlock Elements per thread block, one per thread; unused.
1209 * @param outoffset Stride between the Cartesian planes of @p out.
1210 * @param useSharedMemoryWsp Unused; SumFac reads the input in place.
1211 * @param D0,D1 1D differentiation matrices.
1212 * @param f0,f1 Collapsed-coordinate factor tables.
1213 * @param df Derivative factors of the block.
1214 * @param in Input values of the block, warp interleaved and
1215 * spanning every component and homogeneous mode.
1216 * @param out Output values of the block, warp interleaved and
1217 * spanning every component and homogeneous mode.
1218 * @param shmemptr Dynamic shared memory of this thread block.
1219 * @param threadBlock Thread-block handle supplied by the launch
1220 * macro.
1221 */
1222template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
1223 bool DEFORMED, typename TPhysSizeParameter2D, typename TthreadBlock,
1224 typename TData,
1225 std::enable_if_t<std::is_same_v<Implementation, SumFac>, bool>
1226 Enable = true>
1228 const TPhysSizeParameter2D sizeParam2D, const size_t nelmt,
1229 [[maybe_unused]] const unsigned int elmtsPerBlock, const size_t outoffset,
1230 [[maybe_unused]] const bool useSharedMemoryWsp,
1231 const TData *NEK_RESTRICT D0, const TData *NEK_RESTRICT D1,
1232 const TData *NEK_RESTRICT f0, const TData *NEK_RESTRICT f1,
1233 const TData *NEK_RESTRICT df, const TData *NEK_RESTRICT in,
1234 TData *NEK_RESTRICT out, unsigned char *shmemptr,
1235 const TthreadBlock &threadBlock)
1236{
1237 static_assert(
1238 IsPhysSizeParameter2D_v<TPhysSizeParameter2D>,
1239 "Template argument must be either of type "
1240 "NonTemplatedPhysSizeParameter2D or TemplatedPhysSizeParameter2D.");
1241
1243
1244 const unsigned int ncoord = sizeParam2D.ncoord();
1245 const unsigned int nq0 = sizeParam2D.nq0();
1246 const unsigned int nq1 = sizeParam2D.nq1();
1247 const unsigned int nqTot = sizeParam2D.nqTot();
1248
1249 const unsigned int ndf = 2 * ncoord;
1250 const unsigned int dfsize = DEFORMED ? nqTot : 1u;
1251
1252 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
1253
1254 TData *s_f0 = nullptr;
1255 TData *s_f1 = nullptr;
1256
1257 // Precompute geometric factors.
1258 if constexpr (SHAPE_TYPE == LibUtilities::Tri ||
1259 SHAPE_TYPE == LibUtilities::NodalTri)
1260 {
1261 s_f0 = (TData *)shmemptr;
1262 s_f1 = s_f0 + nq0;
1263
1264 // Copy to shared memory.
1265 LoadToSharedMemory(nq0, f0, s_f0, threadBlock);
1266 LoadToSharedMemory(nq1, f1, s_f1, threadBlock);
1267
1268 localBarrier(threadBlock);
1269 }
1270
1271 size_t e = getGlobalIdx<0>(threadBlock);
1272 const unsigned int m = getBlockIdx<1>(threadBlock);
1273 const unsigned int c = getBlockIdx<2>(threadBlock);
1274 const unsigned int nmode = getBlockRange<1>(threadBlock);
1275 const unsigned int outDim = (nmode > 1) ? 3u : ncoord;
1276 while (e < nelmt)
1277 {
1278 const size_t ilane = e % warpsize;
1279 const size_t iwarp = e / warpsize;
1280 const TData *dfptr = df + ndf * dfsize * warpsize * iwarp;
1281 const TData *inptr =
1282 in + nqTot * (nelmt * (nmode * c + m) + warpsize * iwarp);
1283 TData *outptr =
1284 out + nqTot * (nelmt * (outDim * nmode * c + m) + warpsize * iwarp);
1285 PhysDeriv2DSumFacKernel<SHAPE_TYPE, DEFORMED>(
1286 ilane, ncoord, nq0, nq1, outoffset, D0, D1, s_f0, s_f1, dfptr,
1287 inptr, outptr);
1288
1289 e += getGlobalRange<0>(threadBlock);
1290 }
1291}
1292
1293/**
1294 * @brief SumFac launch entry point for one Cartesian component of a
1295 * block of quadrilaterals or triangles: claims the dynamic shared
1296 * memory, unpacks the size parameter, stages the collapsed-coordinate
1297 * tables it needs, then grid-strides over the block's elements on the
1298 * grid's X axis, one element per warp lane, offsetting the data
1299 * pointers by the block index `c` (component) alone -- there is no
1300 * homogeneous-mode axis here.
1301 *
1302 * @warning Not compilable if ever instantiated: the call below omits
1303 * `ncoord`, which the eleven-parameter per-element
1304 * PhysDerivDir2DSumFacKernel declares as its second argument; only ten
1305 * arguments are passed. Nor does the launcher unpack `ncoord` for
1306 * itself, so its per-element factor stride is fixed at `ndf = 4`, i.e.
1307 * a coordinate dimension of two. Harmless only because this launcher
1308 * currently has no call site; callers needing a single Cartesian
1309 * component use the per-element PhysDerivDir2DSumFacKernel directly, as
1310 * the Divergence kernels do.
1311 *
1312 * @tparam SHAPE_TYPE Quad, Tri or NodalTri.
1313 * @tparam Implementation Constrained to MultiRegions::SumFac.
1314 * @tparam APPEND Accumulate onto @p out.
1315 * @tparam DEFORMED Derivative factors vary point by point.
1316 * @tparam DIR Cartesian component to produce.
1317 * @tparam TPhysSizeParameter2D 2D physical size-parameter type.
1318 * @tparam TthreadBlock Thread-block handle type.
1319 * @tparam TData Floating-point type of the field data.
1320 *
1321 * @param sizeParam2D Coordinate dimension and point counts of the
1322 * element.
1323 * @param nelmt Elements in the block, including padding.
1324 * @param elmtsPerBlock Elements per thread block, one per thread; unused.
1325 * @param D0,D1 1D differentiation matrices.
1326 * @param f0,f1 Collapsed-coordinate factor tables.
1327 * @param df Derivative factors of the block.
1328 * @param in Input values of the block.
1329 * @param out Cartesian component DIR of the block.
1330 * @param shmemptr Dynamic shared memory of this thread block.
1331 * @param threadBlock Thread-block handle supplied by the launch
1332 * macro.
1333 */
1334template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
1335 bool APPEND, bool DEFORMED, unsigned int DIR,
1336 typename TPhysSizeParameter2D, typename TthreadBlock, typename TData,
1337 std::enable_if_t<std::is_same_v<Implementation, SumFac>, bool>
1338 Enable = true>
1339NEK_DEVICE_KERNEL void PhysDerivDir2DKernelLauncher(
1340 const TPhysSizeParameter2D sizeParam2D, const size_t nelmt,
1341 [[maybe_unused]] const unsigned int elmtsPerBlock,
1342 const TData *NEK_RESTRICT D0, const TData *NEK_RESTRICT D1,
1343 const TData *NEK_RESTRICT f0, const TData *NEK_RESTRICT f1,
1344 const TData *NEK_RESTRICT df, const TData *NEK_RESTRICT in,
1345 TData *NEK_RESTRICT out, unsigned char *shmemptr,
1346 const TthreadBlock &threadBlock)
1347{
1348 static_assert(
1349 IsPhysSizeParameter2D_v<TPhysSizeParameter2D>,
1350 "Template argument must be either of type "
1351 "NonTemplatedPhysSizeParameter2D or TemplatedPhysSizeParameter2D.");
1352
1354
1355 const unsigned int nq0 = sizeParam2D.nq0();
1356 const unsigned int nq1 = sizeParam2D.nq1();
1357 const unsigned int nqTot = sizeParam2D.nqTot();
1358
1359 const unsigned int ndf = 4u;
1360 const unsigned int dfsize = DEFORMED ? nqTot : 1u;
1361
1362 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
1363
1364 TData *s_f0 = nullptr;
1365 TData *s_f1 = nullptr;
1366
1367 // Precompute geometric factors.
1368 if constexpr (SHAPE_TYPE == LibUtilities::Tri ||
1369 SHAPE_TYPE == LibUtilities::NodalTri)
1370 {
1371 s_f0 = (TData *)shmemptr;
1372 s_f1 = s_f0 + nq0;
1373
1374 // Copy to shared memory.
1375 LoadToSharedMemory(nq0, f0, s_f0, threadBlock);
1376 LoadToSharedMemory(nq1, f1, s_f1, threadBlock);
1377
1378 localBarrier(threadBlock);
1379 }
1380
1381 size_t e = getGlobalIdx<0>(threadBlock);
1382 const unsigned int c = getBlockIdx<1>(threadBlock);
1383 while (e < nelmt)
1384 {
1385 const size_t ilane = e % warpsize;
1386 const size_t iwarp = e / warpsize;
1387 const TData *dfptr = df + ndf * dfsize * warpsize * iwarp;
1388 const TData *inptr = in + nqTot * (nelmt * c + warpsize * iwarp);
1389 TData *outptr = out + nqTot * (nelmt * c + warpsize * iwarp);
1390
1391 PhysDerivDir2DSumFacKernel<SHAPE_TYPE, APPEND, DEFORMED, DIR>(
1392 ilane, nq0, nq1, D0, D1, s_f0, s_f1, dfptr, inptr, outptr);
1393
1394 e += getGlobalRange<0>(threadBlock);
1395 }
1396}
1397
1398/**
1399 * @brief SumFac launch entry point for a block of three-dimensional
1400 * elements: claims the dynamic shared memory, unpacks the size
1401 * parameter, stages the shape's collapsed-coordinate tables, then
1402 * grid-strides over the block's elements on the grid's X axis, one
1403 * element per warp lane, while the Y and Z axes select the homogeneous
1404 * mode and component of a single fused launch that covers every
1405 * (component, mode) pair at once.
1406 *
1407 * Which tables are staged depends on the shape -- four for a (nodal)
1408 * tetrahedron, two for a (nodal) prism, three for a pyramid, none for a
1409 * hexahedron, matching PhysDerivSharedMemorySize -- after which the
1410 * block synchronises. Each iteration offsets the derivative-factor
1411 * pointer to its warp only, `9 * dfsize` values per element, since the
1412 * factors do not depend on component or mode. The data pointers
1413 * additionally carry the block index `m` (mode, range `nmode`) and `c`
1414 * (component), exactly as in the one- and two-dimensional overloads
1415 * above: the input slab is `nmode * c + m`, and the output slab
1416 * `3 * nmode * c + m`, the factor of three fixed rather than `outDim`
1417 * because a three-dimensional element always yields three Cartesian
1418 * derivatives regardless of homogeneity.
1419 *
1420 * @tparam SHAPE_TYPE Hex, Tet, NodalTet, Prism, NodalPrism, Pyr or
1421 * NodalPyr.
1422 * @tparam Implementation Constrained to MultiRegions::SumFac.
1423 * @tparam DEFORMED Derivative factors vary point by point.
1424 * @tparam TPhysSizeParameter3D 3D physical size-parameter type.
1425 * @tparam TthreadBlock Thread-block handle type.
1426 * @tparam TData Floating-point type of the field data.
1427 *
1428 * @param sizeParam3D Point counts of the element.
1429 * @param nelmt Elements in the block, including padding.
1430 * @param elmtsPerBlock Elements per thread block, one per thread; unused.
1431 * @param outoffset Stride between the Cartesian planes of
1432 * @p out.
1433 * @param useSharedMemoryWsp Unused; SumFac reads the input in place.
1434 * @param D0,D1,D2 1D differentiation matrices.
1435 * @param f0,f1,f1m,f2 Collapsed-coordinate factor tables.
1436 * @param df Derivative factors of the block.
1437 * @param in Input values of the block, warp interleaved
1438 * and spanning every component and
1439 * homogeneous mode.
1440 * @param out Output values of the block, warp
1441 * interleaved and spanning every component
1442 * and homogeneous mode.
1443 * @param shmemptr Dynamic shared memory of this thread block.
1444 * @param threadBlock Thread-block handle supplied by the launch
1445 * macro.
1446 */
1447template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
1448 bool DEFORMED, typename TPhysSizeParameter3D, typename TthreadBlock,
1449 typename TData,
1450 std::enable_if_t<std::is_same_v<Implementation, SumFac>, bool>
1451 Enable = true>
1453 const TPhysSizeParameter3D sizeParam3D, const size_t nelmt,
1454 [[maybe_unused]] const unsigned int elmtsPerBlock, const size_t outoffset,
1455 [[maybe_unused]] const bool useSharedMemoryWsp,
1456 const TData *NEK_RESTRICT D0, const TData *NEK_RESTRICT D1,
1457 const TData *NEK_RESTRICT D2, const TData *NEK_RESTRICT f0,
1458 const TData *NEK_RESTRICT f1, const TData *NEK_RESTRICT f1m,
1459 const TData *NEK_RESTRICT f2, const TData *NEK_RESTRICT df,
1460 const TData *NEK_RESTRICT in, TData *NEK_RESTRICT out,
1461 unsigned char *shmemptr, const TthreadBlock &threadBlock)
1462{
1463 static_assert(
1464 IsPhysSizeParameter3D_v<TPhysSizeParameter3D>,
1465 "Template argument must be either of type "
1466 "NonTemplatedPhysSizeParameter3D or TemplatedPhysSizeParameter3D.");
1467
1469
1470 const unsigned int nq0 = sizeParam3D.nq0();
1471 const unsigned int nq1 = sizeParam3D.nq1();
1472 const unsigned int nq2 = sizeParam3D.nq2();
1473 const unsigned int nqTot = sizeParam3D.nqTot();
1474
1475 constexpr unsigned int ndf = 9u;
1476 const unsigned int dfsize = DEFORMED ? nqTot : 1u;
1477
1478 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
1479
1480 TData *s_f0 = nullptr;
1481 TData *s_f1 = nullptr;
1482 TData *s_f1m = nullptr;
1483 TData *s_f2 = nullptr;
1484
1485 // Precompute geometric factors.
1486 if constexpr (SHAPE_TYPE == LibUtilities::Tet ||
1487 SHAPE_TYPE == LibUtilities::NodalTet)
1488 {
1489 s_f0 = (TData *)shmemptr;
1490 s_f1 = s_f0 + nq0;
1491 s_f1m = s_f1 + nq1;
1492 s_f2 = s_f1m + nq1;
1493
1494 // Copy to shared memory.
1495 LoadToSharedMemory(nq0, f0, s_f0, threadBlock);
1496 LoadToSharedMemory(nq1, f1, s_f1, threadBlock);
1497 LoadToSharedMemory(nq1, f1m, s_f1m, threadBlock);
1498 LoadToSharedMemory(nq2, f2, s_f2, threadBlock);
1499
1500 localBarrier(threadBlock);
1501 }
1502 else if constexpr (SHAPE_TYPE == LibUtilities::Prism ||
1503 SHAPE_TYPE == LibUtilities::NodalPrism)
1504 {
1505 s_f0 = (TData *)shmemptr;
1506 s_f2 = s_f0 + nq0;
1507
1508 // Copy to shared memory.
1509 LoadToSharedMemory(nq0, f0, s_f0, threadBlock);
1510 LoadToSharedMemory(nq2, f2, s_f2, threadBlock);
1511
1512 localBarrier(threadBlock);
1513 }
1514 else if constexpr (SHAPE_TYPE == LibUtilities::Pyr ||
1515 SHAPE_TYPE == LibUtilities::NodalPyr)
1516 {
1517 s_f0 = (TData *)shmemptr;
1518 s_f1 = s_f0 + nq0;
1519 s_f2 = s_f1 + nq1;
1520
1521 // Copy to shared memory.
1522 LoadToSharedMemory(nq0, f0, s_f0, threadBlock);
1523 LoadToSharedMemory(nq1, f1, s_f1, threadBlock);
1524 LoadToSharedMemory(nq2, f2, s_f2, threadBlock);
1525
1526 localBarrier(threadBlock);
1527 }
1528
1529 size_t e = getGlobalIdx<0>(threadBlock); // use size_t to prevent overflow
1530 const unsigned int m = getBlockIdx<1>(threadBlock);
1531 const unsigned int c = getBlockIdx<2>(threadBlock);
1532 const unsigned int nmode = getBlockRange<1>(threadBlock);
1533 while (e < nelmt)
1534 {
1535 const size_t ilane = e % warpsize;
1536 const size_t iwarp = e / warpsize;
1537 const TData *dfptr = df + ndf * dfsize * warpsize * iwarp;
1538 const TData *inptr =
1539 in + nqTot * (nelmt * (nmode * c + m) + warpsize * iwarp);
1540 TData *outptr =
1541 out + nqTot * (nelmt * (3 * nmode * c + m) + warpsize * iwarp);
1542 PhysDeriv3DSumFacKernel<SHAPE_TYPE, DEFORMED>(
1543 ilane, nq0, nq1, nq2, outoffset, D0, D1, D2, s_f0, s_f1, s_f1m,
1544 s_f2, dfptr, inptr, outptr);
1545
1546 e += getGlobalRange<0>(threadBlock);
1547 }
1548}
1549
1550/**
1551 * @brief SumFac launch entry point for one Cartesian component of a
1552 * block of three-dimensional elements: claims the dynamic shared
1553 * memory, unpacks the size parameter, stages the shape's
1554 * collapsed-coordinate tables, then grid-strides over the block's
1555 * elements on the grid's X axis, one element per warp lane, calling the
1556 * per-direction per-element kernel so that only Cartesian component DIR
1557 * is written.
1558 *
1559 * The only per-direction launcher of the three whose argument list
1560 * matches its per-element kernel; it is nevertheless not instantiated
1561 * anywhere, the Divergence family launching its own kernels and
1562 * calling the per-element PhysDeriv kernels from inside them.
1563 *
1564 * @tparam SHAPE_TYPE Hex, Tet, NodalTet, Prism, NodalPrism, Pyr or
1565 * NodalPyr.
1566 * @tparam Implementation Constrained to MultiRegions::SumFac.
1567 * @tparam APPEND Accumulate onto @p out.
1568 * @tparam DEFORMED Derivative factors vary point by point.
1569 * @tparam DIR Cartesian component to produce.
1570 * @tparam TPhysSizeParameter3D 3D physical size-parameter type.
1571 * @tparam TthreadBlock Thread-block handle type.
1572 * @tparam TData Floating-point type of the field data.
1573 *
1574 * @param sizeParam3D Point counts of the element.
1575 * @param nelmt Elements in the block, including padding.
1576 * @param elmtsPerBlock Elements per thread block, one per thread; unused.
1577 * @param D0,D1,D2 1D differentiation matrices.
1578 * @param f0,f1,f1m,f2 Collapsed-coordinate factor tables.
1579 * @param df Derivative factors of the block.
1580 * @param in Input values of the block, warp interleaved.
1581 * @param out Cartesian component DIR of the block, warp
1582 * interleaved.
1583 * @param shmemptr Dynamic shared memory of this thread block.
1584 * @param threadBlock Thread-block handle supplied by the launch
1585 * macro.
1586 */
1587template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
1588 bool APPEND, bool DEFORMED, unsigned int DIR,
1589 typename TPhysSizeParameter3D, typename TthreadBlock, typename TData,
1590 std::enable_if_t<std::is_same_v<Implementation, SumFac>, bool>
1591 Enable = true>
1592NEK_DEVICE_KERNEL void PhysDerivDir3DKernelLauncher(
1593 const TPhysSizeParameter3D sizeParam3D, const size_t nelmt,
1594 [[maybe_unused]] const unsigned int elmtsPerBlock,
1595 const TData *NEK_RESTRICT D0, const TData *NEK_RESTRICT D1,
1596 const TData *NEK_RESTRICT D2, const TData *NEK_RESTRICT f0,
1597 const TData *NEK_RESTRICT f1, const TData *NEK_RESTRICT f1m,
1598 const TData *NEK_RESTRICT f2, const TData *NEK_RESTRICT df,
1599 const TData *NEK_RESTRICT in, TData *NEK_RESTRICT out,
1600 unsigned char *shmemptr, const TthreadBlock &threadBlock)
1601{
1602 static_assert(
1603 IsPhysSizeParameter3D_v<TPhysSizeParameter3D>,
1604 "Template argument must be either of type "
1605 "NonTemplatedPhysSizeParameter3D or TemplatedPhysSizeParameter3D.");
1606
1608
1609 const unsigned int nq0 = sizeParam3D.nq0();
1610 const unsigned int nq1 = sizeParam3D.nq1();
1611 const unsigned int nq2 = sizeParam3D.nq2();
1612 const unsigned int nqTot = sizeParam3D.nqTot();
1613
1614 constexpr unsigned int ndf = 9u;
1615 const unsigned int dfsize = DEFORMED ? nqTot : 1u;
1616
1617 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
1618
1619 TData *s_f0 = nullptr;
1620 TData *s_f1 = nullptr;
1621 TData *s_f1m = nullptr;
1622 TData *s_f2 = nullptr;
1623
1624 // Precompute geometric factors.
1625 if constexpr (SHAPE_TYPE == LibUtilities::Tet ||
1626 SHAPE_TYPE == LibUtilities::NodalTet)
1627 {
1628 s_f0 = (TData *)shmemptr;
1629 s_f1 = s_f0 + nq0;
1630 s_f1m = s_f1 + nq1;
1631 s_f2 = s_f1m + nq1;
1632
1633 // Copy to shared memory.
1634 LoadToSharedMemory(nq0, f0, s_f0, threadBlock);
1635 LoadToSharedMemory(nq1, f1, s_f1, threadBlock);
1636 LoadToSharedMemory(nq1, f1m, s_f1m, threadBlock);
1637 LoadToSharedMemory(nq2, f2, s_f2, threadBlock);
1638
1639 localBarrier(threadBlock);
1640 }
1641 else if constexpr (SHAPE_TYPE == LibUtilities::Prism ||
1642 SHAPE_TYPE == LibUtilities::NodalPrism)
1643 {
1644 s_f0 = (TData *)shmemptr;
1645 s_f2 = s_f0 + nq0;
1646
1647 // Copy to shared memory.
1648 LoadToSharedMemory(nq0, f0, s_f0, threadBlock);
1649 LoadToSharedMemory(nq2, f2, s_f2, threadBlock);
1650
1651 localBarrier(threadBlock);
1652 }
1653 else if constexpr (SHAPE_TYPE == LibUtilities::Pyr ||
1654 SHAPE_TYPE == LibUtilities::NodalPyr)
1655 {
1656 s_f0 = (TData *)shmemptr;
1657 s_f1 = s_f0 + nq0;
1658 s_f2 = s_f1 + nq1;
1659
1660 // Copy to shared memory.
1661 LoadToSharedMemory(nq0, f0, s_f0, threadBlock);
1662 LoadToSharedMemory(nq1, f1, s_f1, threadBlock);
1663 LoadToSharedMemory(nq2, f2, s_f2, threadBlock);
1664
1665 localBarrier(threadBlock);
1666 }
1667
1668 size_t e = getGlobalIdx<0>(threadBlock); // use size_t to prevent overflow
1669 const unsigned int c = getBlockIdx<1>(threadBlock);
1670 while (e < nelmt)
1671 {
1672 const size_t ilane = e % warpsize;
1673 const size_t iwarp = e / warpsize;
1674 const TData *dfptr = df + ndf * dfsize * warpsize * iwarp;
1675 const TData *inptr = in + nqTot * (nelmt * c + warpsize * iwarp);
1676 TData *outptr = out + nqTot * (nelmt * c + warpsize * iwarp);
1677 PhysDerivDir3DSumFacKernel<SHAPE_TYPE, APPEND, DEFORMED, DIR>(
1678 ilane, nq0, nq1, nq2, D0, D1, D2, s_f0, s_f1, s_f1m, s_f2, dfptr,
1679 inptr, outptr);
1680
1681 e += getGlobalRange<0>(threadBlock);
1682 }
1683}
1684
1685#endif
1686
1687} // namespace Nektar::MultiRegions::detail
#define NEK_RESTRICT
Definition Backends.hpp:254
#define NEK_DEVICE_INLINE
Definition Backends.hpp:283
#define NEK_DEVICE_KERNEL
Definition Backends.hpp:297
Kernel size-parameter types shared by every element-operator family, the traits that recognise them a...
static NEK_FORCE_INLINE void SumDerivTensor1DKernel(const unsigned int nq0, const simd_type *in0, const typename simd_type::scalarType *D0, simd_type *out)
static NEK_FORCE_INLINE void SumDerivTensor3DKernel(const unsigned int nq0, const unsigned int nq1, const unsigned int nq2, const simd_type *in0, const simd_type *in1, const simd_type *in2, const typename simd_type::scalarType *D0, const typename simd_type::scalarType *D1, const typename simd_type::scalarType *D2, simd_type *out, bool Deriv0=true, bool Deriv1=true, bool Deriv2=true)
static NEK_FORCE_INLINE void SumDerivTensor2DKernel(const unsigned int nq0, const unsigned int nq1, const simd_type *in0, const simd_type *in1, const typename simd_type::scalarType *D0, const typename simd_type::scalarType *D1, simd_type *out, bool Deriv0=true, bool Deriv1=true)
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const size_t const unsigned int const unsigned int const unsigned int const unsigned int const size_t const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TUseSharedWsp TData *NEK_RESTRICT const TData *NEK_RESTRICT TData *NEK_RESTRICT const bool const bool unsigned char const TthreadBlock & threadBlock
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const size_t const unsigned int const unsigned int const unsigned int const unsigned int const size_t const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TUseSharedWsp useSharedMemoryWsp
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const size_t const unsigned int const unsigned int const unsigned int const unsigned int const size_t const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TUseSharedWsp TData *NEK_RESTRICT const TData *NEK_RESTRICT in
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const size_t const unsigned int const unsigned int const unsigned int const unsigned int const size_t const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TUseSharedWsp TData *NEK_RESTRICT const TData *NEK_RESTRICT TData *NEK_RESTRICT const bool const bool unsigned char * shmemptr
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const size_t const unsigned int elmtsPerBlock
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const size_t nelmt
static NEK_FORCE_INLINE void PhysDerivKernelLauncher(const TPhysSizeParameter1D sizeParam1D, const typename simd_type::scalarType *D0, const simd_type *df_ptr, const simd_type *in, simd_type *out[3])
Differentiate one element group of a 1D block: the standard derivative into out[0],...
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const size_t const unsigned int const unsigned int const unsigned int const unsigned int const size_t const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TUseSharedWsp TData *NEK_RESTRICT const TData *NEK_RESTRICT TData *NEK_RESTRICT out
static constexpr unsigned int warpSize
Definition Backends.hpp:143