Nektar++
Loading...
Searching...
No Matches
CurlCurlBlockOpDeviceSumFacKernels.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: CurlCurlBlockOpDeviceSumFacKernels.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:
32//
33///////////////////////////////////////////////////////////////////////////////
34
35/**
36 * @file CurlCurlBlockOpDeviceSumFacKernels.hpp
37 * @brief SumFac device kernels of the curl-curl operator: one element per
38 * thread, with the elements of a warp interleaved lane by lane.
39 *
40 * @details
41 * Lane ilane of warp iwarp owns one element, and the block storage is
42 * interleaved at the warp size so the lanes of a warp read consecutive
43 * addresses. Each curl kernel contracts the one-dimensional derivative
44 * matrices itself over all components of its element and then applies, in
45 * the same pass, the collapsed-to-standard coordinate correction for
46 * simplex-type shapes, the geometric derivative factors and the curl.
47 *
48 * The file provides, for each dimensionality: the per-element curl kernels
49 * (Curl2DScalarSumFacKernel and Curl2DVectorSumFacKernel in 2D,
50 * Curl3DSumFacKernel for both curls in 3D) and the device entry point the
51 * block operator launches (the CurlCurlKernelLauncher overload for that
52 * dimension), which unpacks the size parameter, stages any
53 * collapsed-coordinate tables in shared memory, walks the block's elements
54 * with a grid stride and calls the curl kernels twice per element -- omega
55 * = curl u into the workspace, global or, when it fits, shared memory, then
56 * out = curl omega -- so that the
57 * whole double curl is one fused launch. Curl3DH1KernelLauncher, launched
58 * with the planes of a multi-plane 3DH1 block on the second grid
59 * dimension, instead calls each 2D curl kernel once per element, for the
60 * plane part of a single curl, and needs no workspace.
61 * CurlCurlSharedMemorySize and CurlCurlWorkSpaceSize report how much
62 * dynamic shared memory and global workspace such a launch must request.
63 * The launchers and helpers are constrained to the SumFac implementation
64 * tag, so the identically named SumFacTOP ones in
65 * CurlCurlBlockOpDeviceSumFacTOPKernels.hpp are the ones that resolve when that
66 * tag is used instead.
67 *
68 * Everything in the namespace is guarded by NEKTAR_ENABLE_DEVICE and
69 * DEVICE_COMPILE_ONLY, so it exists only in translation units compiled for
70 * a device back-end.
71 */
72
73#pragma once
74
78
80
82{
83
84#if defined(NEKTAR_ENABLE_DEVICE) && defined(DEVICE_COMPILE_ONLY)
85/**
86 * @brief Workspace a SumFac launch needs, in elements of TData, for
87 * a one-dimensional shape: none, since the segment launcher forms no
88 * vorticity.
89 *
90 * Both curls of the operator run inside a single fused kernel, so the only
91 * workspace the 2D and 3D launches need is the one holding the
92 * intermediate omega = curl u between them.
93 *
94 * @tparam SHAPE_TYPE Element shape; unused.
95 * @tparam Implementation Implementation tag; this overload is
96 * constrained to SumFac.
97 * @tparam TPhysSizeParameter1D 1D physical-space size parameter (see
98 * ElmtHelper.hpp).
99 *
100 * @param nelmt Elements in the block; unused.
101 * @param sizeParam1D Element sizes; unused.
102 *
103 * @return Zero.
104 */
105template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
106 typename TPhysSizeParameter1D,
107 std::enable_if_t<std::is_same_v<Implementation, SumFac> &&
108 IsPhysSizeParameter1D_v<TPhysSizeParameter1D>,
109 bool>
110 Enable = true>
111inline constexpr size_t CurlCurlWorkSpaceSize(
112 [[maybe_unused]] const size_t nelmt,
113 [[maybe_unused]] const TPhysSizeParameter1D sizeParam1D)
114{
115 return 0;
116}
117
118/**
119 * @brief Workspace a SumFac launch needs, in elements of TData, for
120 * a two-dimensional shape: one plane of the block's quadrature-point
121 * values, holding the out-of-plane vorticity.
122 *
123 * @tparam SHAPE_TYPE Element shape; unused.
124 * @tparam Implementation Implementation tag; this overload is
125 * constrained to SumFac.
126 * @tparam TPhysSizeParameter2D 2D physical-space size parameter (see
127 * ElmtHelper.hpp).
128 *
129 * @param nelmt Elements in the block, including padding.
130 * @param sizeParam2D Quadrature-point counts per direction.
131 *
132 * @return nq0 * nq1 * nelmt.
133 */
134template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
135 typename TPhysSizeParameter2D,
136 std::enable_if_t<std::is_same_v<Implementation, SumFac> &&
137 IsPhysSizeParameter2D_v<TPhysSizeParameter2D>,
138 bool>
139 Enable = true>
140inline constexpr size_t CurlCurlWorkSpaceSize(
141 const size_t nelmt, const TPhysSizeParameter2D sizeParam2D)
142{
143 // In 2D omega only has an out-of-plane component.
144 return sizeParam2D.nqTot() * nelmt;
145}
146
147/**
148 * @brief Workspace a SumFac launch needs, in elements of TData, for
149 * a three-dimensional shape: three planes of the block's quadrature-point
150 * values, one per vorticity component.
151 *
152 * @tparam SHAPE_TYPE Element shape; unused.
153 * @tparam Implementation Implementation tag; this overload is
154 * constrained to SumFac.
155 * @tparam TPhysSizeParameter3D 3D physical-space size parameter (see
156 * ElmtHelper.hpp).
157 *
158 * @param nelmt Elements in the block, including padding.
159 * @param sizeParam3D Quadrature-point counts per direction.
160 *
161 * @return 3 * nq0 * nq1 * nq2 * nelmt.
162 */
163template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
164 typename TPhysSizeParameter3D,
165 std::enable_if_t<std::is_same_v<Implementation, SumFac> &&
166 IsPhysSizeParameter3D_v<TPhysSizeParameter3D>,
167 bool>
168 Enable = true>
169inline constexpr size_t CurlCurlWorkSpaceSize(
170 const size_t nelmt, const TPhysSizeParameter3D sizeParam3D)
171{
172 return 3u * sizeParam3D.nqTot() * nelmt;
173}
174
175/**
176 * @brief Dynamic shared memory a SumFac launch needs per thread block, in
177 * elements of TData, for a one-dimensional shape: none, since a segment
178 * has no collapsed-coordinate tables to stage and forms no vorticity.
179 *
180 * @tparam SHAPE_TYPE Element shape; unused.
181 * @tparam Implementation Implementation tag; this overload is
182 * constrained to SumFac.
183 * @tparam TPhysSizeParameter1D 1D physical-space size parameter (see
184 * ElmtHelper.hpp).
185 *
186 * @param sizeParam1D Element sizes; unused.
187 * @param elmtsPerBlock Elements per thread block; unused.
188 * @param useSharedMemoryWsp Stage the vorticity in shared memory; unused.
189 *
190 * @return Zero.
191 */
192template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
193 typename TPhysSizeParameter1D,
194 std::enable_if_t<std::is_same_v<Implementation, SumFac> &&
195 IsPhysSizeParameter1D_v<TPhysSizeParameter1D>,
196 bool>
197 Enable = true>
198inline constexpr unsigned int CurlCurlSharedMemorySize(
199 [[maybe_unused]] const TPhysSizeParameter1D sizeParam1D,
200 [[maybe_unused]] const unsigned int elmtsPerBlock,
201 [[maybe_unused]] const bool useSharedMemoryWsp)
202{
203 return 0;
204}
205
206/**
207 * @brief Dynamic shared memory a SumFac launch needs per thread block, in
208 * elements of TData, for a two-dimensional shape.
209 *
210 * The collapsed-coordinate factor tables the launcher stages before the element
211 * loop, none for quadrilaterals and one entry per quadrature point of each
212 * direction for triangles, followed, with @p useSharedMemoryWsp, by the
213 * vorticity of the thread block's @p elmtsPerBlock elements, laid out as
214 * CurlCurlWorkSpaceSize gives for that many elements.
215 *
216 * @tparam SHAPE_TYPE Element shape.
217 * @tparam Implementation Implementation tag; this overload is
218 * constrained to SumFac.
219 * @tparam TPhysSizeParameter2D 2D physical-space size parameter (see
220 * ElmtHelper.hpp).
221 *
222 * @param sizeParam2D Quadrature-point counts per direction.
223 * @param elmtsPerBlock Elements per thread block, from
224 * GetElmtsPerBlock().
225 * @param useSharedMemoryWsp Stage the vorticity in shared memory.
226 *
227 * @return Shared-memory requirement in elements of TData.
228 */
229template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
230 typename TPhysSizeParameter2D,
231 std::enable_if_t<std::is_same_v<Implementation, SumFac> &&
232 IsPhysSizeParameter2D_v<TPhysSizeParameter2D>,
233 bool>
234 Enable = true>
235inline constexpr unsigned int CurlCurlSharedMemorySize(
236 const TPhysSizeParameter2D sizeParam2D, const unsigned int elmtsPerBlock,
237 const bool useSharedMemoryWsp)
238{
239 const unsigned int wspsize =
241 ? static_cast<unsigned int>(
242 CurlCurlWorkSpaceSize<SHAPE_TYPE, Implementation>(
243 elmtsPerBlock, sizeParam2D))
244 : 0u;
245
246 if constexpr (SHAPE_TYPE == LibUtilities::Quad)
247 {
248 return wspsize;
249 }
250 else if constexpr (SHAPE_TYPE == LibUtilities::Tri ||
251 SHAPE_TYPE == LibUtilities::NodalTri)
252 {
253 const unsigned int nq0 = sizeParam2D.nq0();
254 const unsigned int nq1 = sizeParam2D.nq1();
255
256 return nq0 + nq1 + wspsize;
257 }
258}
259
260/**
261 * @brief Dynamic shared memory a SumFac launch needs per thread block, in
262 * elements of TData, for a three-dimensional shape.
263 *
264 * As in two dimensions: the collapsed-coordinate factor tables (none for
265 * hexahedra, one table per direction for pyramids, two (directions 0 and
266 * 2) for prisms, and four for tetrahedra, which stage two tables over
267 * direction 1), followed, with @p useSharedMemoryWsp, by the three vorticity
268 * components of the thread block's @p elmtsPerBlock elements.
269 *
270 * @tparam SHAPE_TYPE Element shape.
271 * @tparam Implementation Implementation tag; this overload is
272 * constrained to SumFac.
273 * @tparam TPhysSizeParameter3D 3D physical-space size parameter (see
274 * ElmtHelper.hpp).
275 *
276 * @param sizeParam3D Quadrature-point counts per direction.
277 * @param elmtsPerBlock Elements per thread block, from
278 * GetElmtsPerBlock().
279 * @param useSharedMemoryWsp Stage the vorticity in shared memory.
280 *
281 * @return Shared-memory requirement in elements of TData.
282 */
283template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
284 typename TPhysSizeParameter3D,
285 std::enable_if_t<std::is_same_v<Implementation, SumFac> &&
286 IsPhysSizeParameter3D_v<TPhysSizeParameter3D>,
287 bool>
288 Enable = true>
289inline constexpr unsigned int CurlCurlSharedMemorySize(
290 const TPhysSizeParameter3D sizeParam3D, const unsigned int elmtsPerBlock,
291 const bool useSharedMemoryWsp)
292{
293 const unsigned int nq0 = sizeParam3D.nq0();
294 const unsigned int nq1 = sizeParam3D.nq1();
295 const unsigned int nq2 = sizeParam3D.nq2();
296
297 const unsigned int wspsize =
299 ? static_cast<unsigned int>(
300 CurlCurlWorkSpaceSize<SHAPE_TYPE, Implementation>(
301 elmtsPerBlock, sizeParam3D))
302 : 0u;
303
304 if constexpr (SHAPE_TYPE == LibUtilities::Hex)
305 {
306 return wspsize;
307 }
308 else if constexpr (SHAPE_TYPE == LibUtilities::Tet ||
309 SHAPE_TYPE == LibUtilities::NodalTet)
310 {
311 return nq0 + 2u * nq1 + nq2 + wspsize;
312 }
313 else if constexpr (SHAPE_TYPE == LibUtilities::Prism ||
314 SHAPE_TYPE == LibUtilities::NodalPrism)
315 {
316 return nq0 + nq2 + wspsize;
317 }
318 else if constexpr (SHAPE_TYPE == LibUtilities::Pyr ||
319 SHAPE_TYPE == LibUtilities::NodalPyr)
320 {
321 return nq0 + nq1 + nq2 + wspsize;
322 }
323}
324
325/**
326 * @brief One element of a 2D block, held by one warp lane: the scalar curl
327 * omega = d(u1)/dx0 - d(u0)/dx1 at every quadrature point, from the
328 * element's values of both components.
329 *
330 * For each quadrature point the derivatives of both components along the
331 * two tensor directions are formed by contracting @p D0 and @p D1 over the
332 * element's values, in registers and at once, so that the
333 * collapsed-coordinate correction, the chain rule and the curl are applied
334 * in a single sweep. For triangles the direction-0 derivatives are
335 * multiplied by f1[j] = 2/(1 - eta_1) and the direction-1 derivatives
336 * augmented by them times f0[i] = (1 + eta_0)/2, recovering the
337 * standard-coordinate derivatives; the derivative-factor entry k * 2 + d
338 * then maps the direction-d derivative into the Cartesian-k gradient
339 * component and the two off-diagonal Cartesian derivatives are combined
340 * into omega.
341 *
342 * All arrays are addressed lane by lane: entry i of this element sits at
343 * warpsize * i + ilane of a warp's slice. The derivative factors follow
344 * suit, with the 2 * ncoord factors of a point adjacent when the geometry
345 * is deformed and a single set per element otherwise.
346 *
347 * @tparam SHAPE_TYPE Element shape; selects the collapsed-coordinate
348 * correction.
349 * @tparam DEFORMED Read per-point rather than per-element derivative
350 * factors.
351 *
352 * @param ilane Lane index within the warp, i.e. which element of
353 * the warp's slice this thread owns.
354 * @param ncoord Coordinate dimension; sets the number 2 * ncoord
355 * of derivative factors per point.
356 * @param nq0 Quadrature points in direction 0.
357 * @param nq1 Quadrature points in direction 1.
358 * @param inoffset Stride between the two components of @p in.
359 * @param D0 1D derivative matrix of direction 0.
360 * @param D1 1D derivative matrix of direction 1.
361 * @param f0 Collapsed-coordinate factor (1 + eta_0)/2 at the
362 * direction-0 points (triangles only).
363 * @param f1 Collapsed-coordinate factor 2/(1 - eta_1) at the
364 * direction-1 points (triangles only).
365 * @param df Derivative factors of this warp's elements.
366 * @param in Input values of this warp's elements; component 1
367 * starts at @p inoffset.
368 * @param omega Output values of this warp's elements.
369 */
370template <LibUtilities::ShapeType SHAPE_TYPE, bool DEFORMED, typename TData>
372 const unsigned int ilane, const unsigned int ncoord, const unsigned int nq0,
373 const unsigned int nq1, const size_t inoffset, const TData *NEK_RESTRICT D0,
374 const TData *NEK_RESTRICT D1, [[maybe_unused]] const TData *NEK_RESTRICT f0,
375 [[maybe_unused]] const TData *NEK_RESTRICT f1, const TData *NEK_RESTRICT df,
376 const TData *NEK_RESTRICT in, TData *NEK_RESTRICT omega)
377{
378 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
379
380 const unsigned int ndf = 2u * ncoord;
381
382 for (unsigned int j = 0u, cnt_ji = 0u; j < nq1; ++j)
383 {
384 for (unsigned int i = 0u; i < nq0; ++i, ++cnt_ji)
385 {
386 const unsigned int index = warpsize * cnt_ji + ilane;
387 const unsigned int dfindex =
388 DEFORMED ? ndf * warpsize * cnt_ji + ilane : ilane;
389
390 // Compute tensorial derivatives of both components at once.
391 // Direction 0
392 TData d0u = 0.0;
393 TData d0v = 0.0;
394#pragma unroll
395 for (unsigned int q = 0u; q < nq0; ++q)
396 {
397 const TData Dq = D0[q * nq0 + i];
398 const unsigned int qsource = warpsize * (nq0 * j + q) + ilane;
399 d0u += Dq * in[qsource];
400 d0v += Dq * in[inoffset + qsource];
401 }
402
403 // Direction 1
404 TData d1u = 0.0;
405 TData d1v = 0.0;
406#pragma unroll
407 for (unsigned int q = 0u; q < nq1; ++q)
408 {
409 const TData Dq = D1[q * nq1 + j];
410 const unsigned int qsource = warpsize * (nq0 * q + i) + ilane;
411 d1u += Dq * in[qsource];
412 d1v += Dq * in[inoffset + qsource];
413 }
414
415 // Moving from collapsed to standard coordinates.
416 if constexpr (SHAPE_TYPE == LibUtilities::Tri ||
417 SHAPE_TYPE == LibUtilities::NodalTri)
418 {
419 d0u *= f1[j];
420 d1u += d0u * f0[i];
421 d0v *= f1[j];
422 d1v += d0v * f0[i];
423 }
424
425 // Multiply by derivative factors and take the curl.
426 const TData dvdx = d0v * df[0u * warpsize + dfindex] +
427 d1v * df[1u * warpsize + dfindex];
428 const TData dudy = d0u * df[2u * warpsize + dfindex] +
429 d1u * df[3u * warpsize + dfindex];
430
431 omega[index] = dvdx - dudy;
432 }
433 }
434}
435
436/**
437 * @brief One element of a 2D block, held by one warp lane: the vector curl
438 * out = ( d(omega)/dx1, -d(omega)/dx0 ) at every quadrature point, from
439 * the element's values of the vorticity.
440 *
441 * The tensor-direction derivatives of omega are formed as in
442 * Curl2DScalarSumFacKernel, corrected and chain-ruled the same way, and
443 * both output components are written by the same sweep.
444 *
445 * @tparam SHAPE_TYPE Element shape; selects the collapsed-coordinate
446 * correction.
447 * @tparam DEFORMED Read per-point rather than per-element derivative
448 * factors.
449 *
450 * @param ilane Lane index within the warp, i.e. which element of
451 * the warp's slice this thread owns.
452 * @param ncoord Coordinate dimension; sets the number 2 * ncoord
453 * of derivative factors per point.
454 * @param nq0 Quadrature points in direction 0.
455 * @param nq1 Quadrature points in direction 1.
456 * @param outoffset Stride between the two components of @p out.
457 * @param D0 1D derivative matrix of direction 0.
458 * @param D1 1D derivative matrix of direction 1.
459 * @param f0 Collapsed-coordinate factor (1 + eta_0)/2 at the
460 * direction-0 points (triangles only).
461 * @param f1 Collapsed-coordinate factor 2/(1 - eta_1) at the
462 * direction-1 points (triangles only).
463 * @param df Derivative factors of this warp's elements.
464 * @param omega Vorticity values of this warp's elements.
465 * @param out Output values of this warp's elements; component 1
466 * starts at @p outoffset.
467 */
468template <LibUtilities::ShapeType SHAPE_TYPE, bool DEFORMED, typename TData>
470 const unsigned int ilane, const unsigned int ncoord, const unsigned int nq0,
471 const unsigned int nq1, const size_t outoffset,
472 const TData *NEK_RESTRICT D0, const TData *NEK_RESTRICT D1,
473 [[maybe_unused]] const TData *NEK_RESTRICT f0,
474 [[maybe_unused]] const TData *NEK_RESTRICT f1, const TData *NEK_RESTRICT df,
475 const TData *NEK_RESTRICT omega, TData *NEK_RESTRICT out)
476{
477 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
478
479 const unsigned int ndf = 2u * ncoord;
480
481 for (unsigned int j = 0u, cnt_ji = 0u; j < nq1; ++j)
482 {
483 for (unsigned int i = 0u; i < nq0; ++i, ++cnt_ji)
484 {
485 const unsigned int index = warpsize * cnt_ji + ilane;
486 const unsigned int dfindex =
487 DEFORMED ? ndf * warpsize * cnt_ji + ilane : ilane;
488
489 // Compute tensorial derivative.
490 // Direction 0
491 TData d0 = 0.0;
492#pragma unroll
493 for (unsigned int q = 0u; q < nq0; ++q)
494 {
495 d0 += D0[q * nq0 + i] * omega[warpsize * (nq0 * j + q) + ilane];
496 }
497
498 // Direction 1
499 TData d1 = 0.0;
500#pragma unroll
501 for (unsigned int q = 0u; q < nq1; ++q)
502 {
503 d1 += D1[q * nq1 + j] * omega[warpsize * (nq0 * q + i) + ilane];
504 }
505
506 // Moving from collapsed to standard coordinates.
507 if constexpr (SHAPE_TYPE == LibUtilities::Tri ||
508 SHAPE_TYPE == LibUtilities::NodalTri)
509 {
510 d0 *= f1[j];
511 d1 += d0 * f0[i];
512 }
513
514 // Multiply by derivative factors and take the curl.
515 out[index] = d0 * df[2u * warpsize + dfindex] +
516 d1 * df[3u * warpsize + dfindex];
517 out[outoffset + index] = -(d0 * df[0u * warpsize + dfindex] +
518 d1 * df[1u * warpsize + dfindex]);
519 }
520 }
521}
522
523/**
524 * @brief One element of a 3D block, held by one warp lane: the curl of a
525 * three-component field at every quadrature point; used for both passes
526 * of the curl-curl operator, omega = curl u and out = curl omega.
527 *
528 * For each quadrature point the derivatives of the three components along
529 * the three tensor directions are formed by contracting @p D0, @p D1 and
530 * @p D2 over the element's values, in registers and at once. For the
531 * simplex-type shapes each component's derivatives are then chain-ruled
532 * back to the standard coordinates -- a prism scales direction 0 by f2[k]
533 * and adds f0[i] times it to direction 2; a pyramid scales directions 0
534 * and 1 by f2[k] and adds f0[i] and f1[j] times them to direction 2; a
535 * tetrahedron scales direction 0 by f1m[j] * f2[k], rebuilds direction 1
536 * from f0[i] times that and f2[k] times the old direction-1 derivative,
537 * and adds both contributions, the second weighted by f1[j], to direction
538 * 2; hexahedra need no correction -- before the derivative-factor entry
539 * k * 3 + d maps the direction-d derivative into the Cartesian-k gradient
540 * component. Only the six off-diagonal Cartesian derivatives are formed,
541 * the diagonal ones cancelling out of the curl:
542 * out0 = d(u2)/dx1 - d(u1)/dx2,
543 * out1 = d(u0)/dx2 - d(u2)/dx0,
544 * out2 = d(u1)/dx0 - d(u0)/dx1.
545 *
546 * All arrays are addressed lane by lane as in Curl2DScalarSumFacKernel,
547 * with nine derivative factors per point (deformed) or per element (regular).
548 *
549 * @tparam SHAPE_TYPE Element shape; selects the collapsed-coordinate
550 * correction.
551 * @tparam DEFORMED Read per-point rather than per-element derivative
552 * factors.
553 *
554 * @param ilane Lane index within the warp, i.e. which element of
555 * the warp's slice this thread owns.
556 * @param nq0 Quadrature points in direction 0.
557 * @param nq1 Quadrature points in direction 1.
558 * @param nq2 Quadrature points in direction 2.
559 * @param inoffset Stride between the components of @p in.
560 * @param outoffset Stride between the components of @p out.
561 * @param D0 1D derivative matrix of direction 0.
562 * @param D1 1D derivative matrix of direction 1.
563 * @param D2 1D derivative matrix of direction 2.
564 * @param f0 Collapsed-coordinate factor (1 + eta_0)/2 at the
565 * direction-0 points (prisms, pyramids and
566 * tetrahedra).
567 * @param f1 Collapsed-coordinate factor (1 + eta_1)/2 at the
568 * direction-1 points (pyramids and tetrahedra).
569 * @param f1m Collapsed-coordinate factor 2/(1 - eta_1) at the
570 * direction-1 points (tetrahedra only).
571 * @param f2 Collapsed-coordinate factor 2/(1 - eta_2) at the
572 * direction-2 points (prisms, pyramids and
573 * tetrahedra).
574 * @param df Derivative factors of this warp's elements.
575 * @param in Input values of this warp's elements, three
576 * components at @p inoffset from each other.
577 * @param out Output values of this warp's elements, three
578 * components at @p outoffset from each other.
579 */
580template <LibUtilities::ShapeType SHAPE_TYPE, bool DEFORMED, typename TData>
582 const unsigned int ilane, const unsigned int nq0, const unsigned int nq1,
583 const unsigned int nq2, const size_t inoffset, const size_t outoffset,
584 const TData *NEK_RESTRICT D0, const TData *NEK_RESTRICT D1,
585 const TData *NEK_RESTRICT D2, [[maybe_unused]] const TData *NEK_RESTRICT f0,
586 [[maybe_unused]] const TData *NEK_RESTRICT f1,
587 [[maybe_unused]] const TData *NEK_RESTRICT f1m,
588 [[maybe_unused]] const TData *NEK_RESTRICT f2, const TData *NEK_RESTRICT df,
589 const TData *NEK_RESTRICT in, TData *NEK_RESTRICT out)
590{
591 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
592
593 constexpr unsigned int ndf = 9u;
594
595 for (unsigned int k = 0u, cnt_kji = 0u; k < nq2; k++)
596 {
597 for (unsigned int j = 0u; j < nq1; j++)
598 {
599 for (unsigned int i = 0u; i < nq0; i++, cnt_kji++)
600 {
601 const unsigned int index = warpsize * cnt_kji + ilane;
602 const unsigned int dfindex =
603 DEFORMED ? ndf * warpsize * cnt_kji + ilane : ilane;
604
605 // Compute the tensorial derivatives of the three components
606 // at once.
607 // Direction 0
608 TData d0[3] = {0.0, 0.0, 0.0};
609#pragma unroll
610 for (unsigned int q = 0u; q < nq0; ++q)
611 {
612 const TData Dq = D0[q * nq0 + i];
613 const unsigned int qsource =
614 warpsize * (nq0 * nq1 * k + nq0 * j + q) + ilane;
615 d0[0] += Dq * in[qsource];
616 d0[1] += Dq * in[inoffset + qsource];
617 d0[2] += Dq * in[2u * inoffset + qsource];
618 }
619
620 // Direction 1
621 TData d1[3] = {0.0, 0.0, 0.0};
622#pragma unroll
623 for (unsigned int q = 0u; q < nq1; ++q)
624 {
625 const TData Dq = D1[q * nq1 + j];
626 const unsigned int qsource =
627 warpsize * (nq0 * nq1 * k + nq0 * q + i) + ilane;
628 d1[0] += Dq * in[qsource];
629 d1[1] += Dq * in[inoffset + qsource];
630 d1[2] += Dq * in[2u * inoffset + qsource];
631 }
632
633 // Direction 2
634 TData d2[3] = {0.0, 0.0, 0.0};
635#pragma unroll
636 for (unsigned int q = 0u; q < nq2; ++q)
637 {
638 const TData Dq = D2[q * nq2 + k];
639 const unsigned int qsource =
640 warpsize * (nq0 * nq1 * q + nq0 * j + i) + ilane;
641 d2[0] += Dq * in[qsource];
642 d2[1] += Dq * in[inoffset + qsource];
643 d2[2] += Dq * in[2u * inoffset + qsource];
644 }
645
646 // Moving from collapsed to standard coordinates.
647#pragma unroll
648 for (unsigned int c = 0u; c < 3u; ++c)
649 {
650 if constexpr (SHAPE_TYPE == LibUtilities::Tet ||
651 SHAPE_TYPE == LibUtilities::NodalTet)
652 {
653 TData tmp0 = f1m[j] * f2[k] * d0[c];
654 TData tmp1 = f0[i] * tmp0;
655 TData tmp2 = f2[k] * d1[c];
656 d0[c] = tmp0;
657 d1[c] = tmp1 + tmp2;
658 d2[c] += tmp1 + f1[j] * tmp2;
659 }
660 else if constexpr (SHAPE_TYPE == LibUtilities::Prism ||
661 SHAPE_TYPE == LibUtilities::NodalPrism)
662 {
663 d0[c] *= f2[k];
664 d2[c] += f0[i] * d0[c];
665 }
666 else if constexpr (SHAPE_TYPE == LibUtilities::Pyr ||
667 SHAPE_TYPE == LibUtilities::NodalPyr)
668 {
669 d0[c] *= f2[k];
670 d1[c] *= f2[k];
671 d2[c] += f0[i] * d0[c] + f1[j] * d1[c];
672 }
673 }
674
675 // Multiply by the derivative factors and take the curl. Only
676 // the six off-diagonal physical derivatives are needed, the
677 // diagonal ones cancel out.
678 const TData df0 = df[0u * warpsize + dfindex];
679 const TData df1 = df[1u * warpsize + dfindex];
680 const TData df2 = df[2u * warpsize + dfindex];
681 const TData df3 = df[3u * warpsize + dfindex];
682 const TData df4 = df[4u * warpsize + dfindex];
683 const TData df5 = df[5u * warpsize + dfindex];
684 const TData df6 = df[6u * warpsize + dfindex];
685 const TData df7 = df[7u * warpsize + dfindex];
686 const TData df8 = df[8u * warpsize + dfindex];
687
688 // dw/dy - dv/dz
689 out[index] = (d0[2] * df3 + d1[2] * df4 + d2[2] * df5) -
690 (d0[1] * df6 + d1[1] * df7 + d2[1] * df8);
691 // du/dz - dw/dx
692 out[outoffset + index] =
693 (d0[0] * df6 + d1[0] * df7 + d2[0] * df8) -
694 (d0[2] * df0 + d1[2] * df1 + d2[2] * df2);
695 // dv/dx - du/dy
696 out[2u * outoffset + index] =
697 (d0[1] * df0 + d1[1] * df1 + d2[1] * df2) -
698 (d0[0] * df3 + d1[0] * df4 + d2[0] * df5);
699 }
700 }
701 }
702}
703
704/**
705 * @brief Device entry point of the 1D SumFac kernel: the curl-curl is
706 * undefined on a segment, so each element's single component is
707 * differentiated once along its direction.
708 *
709 * Exists so that the generated segment ShapeBlock() compiles; the block
710 * operator's constructor asserts that the block is two- or
711 * three-dimensional (see CurlCurlBlockOpDeviceSumFac.hpp). Launched by
712 * CurlCurlBlockOpImpl::OperatorNDImpl through
713 * DEVICE_1DGRID_KERNEL_LAUNCHER, which appends the shared-memory pointer
714 * (unused here) and the thread-block handle. Unpacks the size parameter --
715 * runtime or compile-time, both satisfying IsPhysSizeParameter1D_v as the
716 * static_assert enforces. Each thread then starts at its global index and
717 * strides by the grid's range, so the block's @p nelmt elements (padding
718 * included) are covered whatever grid size was launched. The element index
719 * splits into the warp it belongs to and the lane within it: the warp's
720 * slice of the input, output and derivative-factor arrays is selected by
721 * pointer arithmetic and the lane is passed to PhysDerivDir1DSumFacKernel,
722 * which writes the element's derivative with the direction-0 derivative
723 * factor. The enable_if pins this overload to the SumFac tag, leaving the
724 * SumFacTOP tag to the identically named launcher in
725 * CurlCurlBlockOpDeviceSumFacTOPKernels.hpp.
726 *
727 * @tparam SHAPE_TYPE Element shape (segments only; unused).
728 * @tparam Implementation Implementation tag; SumFac here.
729 * @tparam DEFORMED Per-point derivative factors.
730 * @tparam TPhysSizeParameter1D 1D physical-space size parameter.
731 * @tparam TthreadBlock Back-end thread-block handle type.
732 * @tparam TUseSharedWsp Type of @p useSharedMemoryWsp: `bool`, or a
733 * `std::bool_constant` SelectSharedWorkSpace()
734 * fixed.
735 *
736 * @param sizeParam1D Element sizes: coordinate dimension and
737 * quadrature points.
738 * @param nelmt Elements in the block, including padding.
739 * @param elmtsPerBlock Elements per thread block, one per thread;
740 * unused.
741 * @param inoffset Component stride; unused in one dimension.
742 * @param useSharedMemoryWsp Stage the vorticity in @p shmemptr; unused in
743 * one dimension.
744 * @param D0 1D derivative matrix of the direction.
745 * @param df Derivative factors of the block.
746 * @param in Input values of the block.
747 * @param wsp Global workspace; unused in one dimension.
748 * @param out Output values of the block.
749 * @param shmemptr Dynamic shared memory of the thread block; unused
750 * in one dimension.
751 * @param threadBlock Thread-block handle supplied by the launcher
752 * macro.
753 */
754template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
755 bool DEFORMED, typename TPhysSizeParameter1D, typename TthreadBlock,
756 typename TData, typename TUseSharedWsp,
757 std::enable_if_t<std::is_same_v<Implementation, SumFac>, bool>
758 Enable = true>
760 const TPhysSizeParameter1D sizeParam1D, const size_t nelmt,
761 [[maybe_unused]] const unsigned int elmtsPerBlock,
762 [[maybe_unused]] const size_t inoffset,
763 [[maybe_unused]] const TUseSharedWsp useSharedMemoryWsp,
764 const TData *NEK_RESTRICT D0, const TData *NEK_RESTRICT df,
765 const TData *NEK_RESTRICT in, [[maybe_unused]] TData *NEK_RESTRICT wsp,
766 TData *NEK_RESTRICT out, [[maybe_unused]] unsigned char *shmemptr,
767 const TthreadBlock &threadBlock)
768{
769 static_assert(
770 IsPhysSizeParameter1D_v<TPhysSizeParameter1D>,
771 "Template argument must be either of type "
772 "NonTemplatedPhysSizeParameter1D or TemplatedPhysSizeParameter1D.");
773
774 const unsigned int ncoord = sizeParam1D.ncoord();
775 const unsigned int nq0 = sizeParam1D.nq0();
776
777 const unsigned int ndf = ncoord;
778 const unsigned int dfsize = DEFORMED ? nq0 : 1u;
779
780 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
781
782 size_t e = getGlobalIdx<0>(threadBlock);
783 while (e < nelmt)
784 {
785 const size_t ilane = e % warpsize;
786 const size_t iwarp = e / warpsize;
787 const TData *dfptr = df + ndf * dfsize * warpsize * iwarp;
788 const TData *inptr = in + nq0 * warpsize * iwarp;
789 TData *outptr = out + nq0 * warpsize * iwarp;
790 PhysDerivDir1DSumFacKernel<false, DEFORMED, 0>(ilane, ncoord, nq0, D0,
791 dfptr, inptr, outptr);
792
793 e += getGlobalRange<0>(threadBlock);
794 }
795}
796
797/**
798 * @brief Device entry point of the 2D SumFac kernel: both curls of the
799 * operator for every element of the block in one launch.
800 *
801 * As in 1D, but the shared memory is used: FETCH_SHARED_MEMORY() binds
802 * @p shmemptr to the block's dynamic shared memory (a no-op on the
803 * back-ends that pass it in). For triangles the collapsed-coordinate
804 * factor tables are then copied from global into the thread block's shared
805 * memory once, before the element loop, and a barrier makes them visible
806 * to the whole block; the curl kernels then read the shared copies. For
807 * quadrilaterals the two table pointers stay null. With @p useSharedMemoryWsp
808 * the vorticity of the thread block's single warp follows the tables in shared
809 * memory; otherwise it is the warp's slice of @p wsp. The grid-stride loop
810 * then selects, per element, the warp's slices of the input, workspace,
811 * output and derivative-factor arrays and calls Curl2DScalarSumFacKernel to
812 * write the element's vorticity into the workspace and
813 * Curl2DVectorSumFacKernel to write the output from it. Each lane owns a
814 * complete element and uses only its own column of the workspace, so no
815 * synchronisation is needed between the two curls.
816 *
817 * @tparam SHAPE_TYPE Element shape.
818 * @tparam Implementation Implementation tag; SumFac here.
819 * @tparam DEFORMED Per-point derivative factors.
820 * @tparam TPhysSizeParameter2D 2D physical-space size parameter.
821 * @tparam TthreadBlock Back-end thread-block handle type.
822 * @tparam TUseSharedWsp Type of @p useSharedMemoryWsp: `bool`, or a
823 * `std::bool_constant` SelectSharedWorkSpace()
824 * fixed.
825 *
826 * @param sizeParam2D Element sizes: coordinate dimension and
827 * per-direction quadrature points.
828 * @param nelmt Elements in the block, including padding.
829 * @param elmtsPerBlock Elements per thread block, one per thread;
830 * unused.
831 * @param inoffset Stride between the components of @p in, also used
832 * between those of @p out.
833 * @param useSharedMemoryWsp Stage the vorticity in @p shmemptr rather than
834 * in
835 * @p wsp.
836 * @param D0 1D derivative matrix of direction 0.
837 * @param D1 1D derivative matrix of direction 1.
838 * @param f0 Collapsed-coordinate factor of direction 0.
839 * @param f1 Collapsed-coordinate factor of direction 1.
840 * @param df Derivative factors of the block.
841 * @param in Input values of the block, two components.
842 * @param wsp Global workspace of CurlCurlWorkSpaceSize
843 * elements, receiving the vorticity; unused if
844 * @p useSharedMemoryWsp.
845 * @param out Output values of the block, two components.
846 * @param shmemptr Dynamic shared memory of the thread block, at
847 * least CurlCurlSharedMemorySize elements of TData:
848 * the factor tables, then the vorticity if
849 * @p useSharedMemoryWsp.
850 * @param threadBlock Thread-block handle supplied by the launcher
851 * macro.
852 */
853template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
854 bool DEFORMED, typename TPhysSizeParameter2D, typename TthreadBlock,
855 typename TData, typename TUseSharedWsp,
856 std::enable_if_t<std::is_same_v<Implementation, SumFac>, bool>
857 Enable = true>
859 const TPhysSizeParameter2D sizeParam2D, const size_t nelmt,
860 [[maybe_unused]] const unsigned int elmtsPerBlock, const size_t inoffset,
861 const TUseSharedWsp useSharedMemoryWsp, const TData *NEK_RESTRICT D0,
862 const TData *NEK_RESTRICT D1, const TData *NEK_RESTRICT f0,
863 const TData *NEK_RESTRICT f1, const TData *NEK_RESTRICT df,
864 const TData *NEK_RESTRICT in, TData *NEK_RESTRICT wsp,
865 TData *NEK_RESTRICT out, unsigned char *shmemptr,
866 const TthreadBlock &threadBlock)
867{
868 static_assert(
869 IsPhysSizeParameter2D_v<TPhysSizeParameter2D>,
870 "Template argument must be either of type "
871 "NonTemplatedPhysSizeParameter2D or TemplatedPhysSizeParameter2D.");
872
874
875 const unsigned int ncoord = sizeParam2D.ncoord();
876 const unsigned int nq0 = sizeParam2D.nq0();
877 const unsigned int nq1 = sizeParam2D.nq1();
878 const unsigned int nqTot = sizeParam2D.nqTot();
879
880 const unsigned int ndf = 2 * ncoord;
881 const unsigned int dfsize = DEFORMED ? nqTot : 1u;
882
883 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
884
885 TData *s_f0 = nullptr;
886 TData *s_f1 = nullptr;
887 unsigned int ntable = 0u;
888
889 // Precompute geometric factors.
890 if constexpr (SHAPE_TYPE == LibUtilities::Tri ||
891 SHAPE_TYPE == LibUtilities::NodalTri)
892 {
893 s_f0 = (TData *)shmemptr;
894 s_f1 = s_f0 + nq0;
895 ntable = nq0 + nq1;
896
897 // Copy to shared memory.
898 LoadToSharedMemory(nq0, f0, s_f0, threadBlock);
899 LoadToSharedMemory(nq1, f1, s_f1, threadBlock);
900
901 localBarrier(threadBlock);
902 }
903
904 DispatchWorkSpace(useSharedMemoryWsp, [&](const auto isShared) {
905 // Vorticity after the factor tables, or in the global workspace.
906 TData *wspbase = isShared ? (TData *)shmemptr + ntable : wsp;
907
908 size_t e = getGlobalIdx<0>(threadBlock);
909 while (e < nelmt)
910 {
911 const size_t ilane = e % warpsize;
912 const size_t iwarp = e / warpsize;
913 const TData *dfptr = df + ndf * dfsize * warpsize * iwarp;
914 const TData *inptr = in + nqTot * warpsize * iwarp;
915 TData *outptr = out + nqTot * warpsize * iwarp;
916 TData *wspptr = wspbase + (isShared ? 0 : nqTot * warpsize * iwarp);
917
918 // omega = dv/dx - du/dy
919 Curl2DScalarSumFacKernel<SHAPE_TYPE, DEFORMED>(
920 ilane, ncoord, nq0, nq1, inoffset, D0, D1, s_f0, s_f1, dfptr,
921 inptr, wspptr);
922
923 // out = {d(omega)/dy, -d(omega)/dx}
924 Curl2DVectorSumFacKernel<SHAPE_TYPE, DEFORMED>(
925 ilane, ncoord, nq0, nq1, inoffset, D0, D1, s_f0, s_f1, dfptr,
926 wspptr, outptr);
927
928 e += getGlobalRange<0>(threadBlock);
929 }
930 });
931}
932
933// One curl's plane part on each plane of a 3DH1 block: three components in,
934// three out.
935//
936// The curl of a 3DH1 field splits into a part that differentiates in the
937// plane, (df_z/dy, -df_z/dx, df_y/dx - df_x/dy), and a part that
938// differentiates along z. This writes the first; the operator's z-op adds the
939// second, and CurlCurlOpImpl takes the pair twice, the output carrying omega
940// in between. Both halves of
941// the plane part are already in the 2D kernels: the scalar one is the third
942// component, taken from the first two, and the vector one is the first two
943// components, taken from the third. Neither writes an intermediate any other
944// lane reads, so this pass needs no workspace at all, and useSharedMemoryWsp
945// is unused.
946//
947// Each plane holds one plane curl over the same geometry, so they ride the
948// second grid dimension of a single launch and the kernel picks its plane
949// from the block index.
950template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
951 bool DEFORMED, typename TPhysSizeParameter2D, typename TthreadBlock,
952 typename TData, typename TUseSharedWsp,
953 std::enable_if_t<std::is_same_v<Implementation, SumFac>, bool>
954 Enable = true>
956 const TPhysSizeParameter2D sizeParam2D, const size_t nelmt,
957 [[maybe_unused]] const unsigned int elmtsPerBlock, const size_t inoffset,
958 const size_t outoffset,
959 [[maybe_unused]] const TUseSharedWsp useSharedMemoryWsp,
960 const TData *NEK_RESTRICT D0, const TData *NEK_RESTRICT D1,
961 const TData *NEK_RESTRICT f0, const TData *NEK_RESTRICT f1,
962 const TData *NEK_RESTRICT df, const TData *NEK_RESTRICT in,
963 TData *NEK_RESTRICT out, unsigned char *shmemptr,
964 const TthreadBlock &threadBlock)
965{
966 static_assert(
967 IsPhysSizeParameter2D_v<TPhysSizeParameter2D>,
968 "Template argument must be either of type "
969 "NonTemplatedPhysSizeParameter2D or TemplatedPhysSizeParameter2D.");
970
972
973 const unsigned int ncoord = sizeParam2D.ncoord();
974 const unsigned int nq0 = sizeParam2D.nq0();
975 const unsigned int nq1 = sizeParam2D.nq1();
976 const unsigned int nqTot = sizeParam2D.nqTot();
977
978 const unsigned int ndf = 2 * ncoord;
979 const unsigned int dfsize = DEFORMED ? nqTot : 1u;
980
981 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
982
983 TData *s_f0 = nullptr;
984 TData *s_f1 = nullptr;
985
986 // Precompute geometric factors.
987 if constexpr (SHAPE_TYPE == LibUtilities::Tri ||
988 SHAPE_TYPE == LibUtilities::NodalTri)
989 {
990 s_f0 = (TData *)shmemptr;
991 s_f1 = s_f0 + nq0;
992
993 // Copy to shared memory.
994 LoadToSharedMemory(nq0, f0, s_f0, threadBlock);
995 LoadToSharedMemory(nq1, f1, s_f1, threadBlock);
996
997 localBarrier(threadBlock);
998 }
999
1000 size_t e = getGlobalIdx<0>(threadBlock);
1001 const unsigned int p = getBlockIdx<1>(threadBlock);
1002 while (e < nelmt)
1003 {
1004 const size_t ilane = e % warpsize;
1005 const size_t iwarp = e / warpsize;
1006 const TData *dfptr = df + ndf * dfsize * warpsize * iwarp;
1007 const TData *inptr = in + nqTot * (nelmt * p + warpsize * iwarp);
1008 TData *outptr = out + nqTot * (nelmt * p + warpsize * iwarp);
1009
1010 // The third component, df_y/dx - df_x/dy.
1011 Curl2DScalarSumFacKernel<SHAPE_TYPE, DEFORMED>(
1012 ilane, ncoord, nq0, nq1, inoffset, D0, D1, s_f0, s_f1, dfptr, inptr,
1013 outptr + 2u * outoffset);
1014
1015 // The first two components, {df_z/dy, -df_z/dx}.
1016 Curl2DVectorSumFacKernel<SHAPE_TYPE, DEFORMED>(
1017 ilane, ncoord, nq0, nq1, outoffset, D0, D1, s_f0, s_f1, dfptr,
1018 inptr + 2u * inoffset, outptr);
1019
1020 e += getGlobalRange<0>(threadBlock);
1021 }
1022}
1023
1024/**
1025 * @brief Device entry point of the 3D SumFac kernel: both curls of the
1026 * operator for every element of the block in one launch.
1027 *
1028 * As in 2D, with the collapsed-coordinate tables staged per shape -- four
1029 * for tetrahedra, two (directions 0 and 2) for prisms, three for pyramids,
1030 * none for hexahedra -- and Curl3DSumFacKernel called twice per element:
1031 * once from the input into the three vorticity planes of the workspace,
1032 * once from those planes into the output. The planes are @p inoffset
1033 * apart in @p wsp and nqTot * warpSize apart in shared memory with
1034 * @p useSharedMemoryWsp.
1035 *
1036 * @tparam SHAPE_TYPE Element shape.
1037 * @tparam Implementation Implementation tag; SumFac here.
1038 * @tparam DEFORMED Per-point derivative factors.
1039 * @tparam TPhysSizeParameter3D 3D physical-space size parameter.
1040 * @tparam TthreadBlock Back-end thread-block handle type.
1041 * @tparam TUseSharedWsp Type of @p useSharedMemoryWsp: `bool`, or a
1042 * `std::bool_constant` SelectSharedWorkSpace()
1043 * fixed.
1044 *
1045 * @param sizeParam3D Element sizes: per-direction quadrature points.
1046 * @param nelmt Elements in the block, including padding.
1047 * @param elmtsPerBlock Elements per thread block, one per thread;
1048 * unused.
1049 * @param inoffset Stride between the components of @p in, of
1050 * @p wsp and of @p out.
1051 * @param useSharedMemoryWsp Stage the vorticity in @p shmemptr rather than
1052 * in
1053 * @p wsp.
1054 * @param D0 1D derivative matrix of direction 0.
1055 * @param D1 1D derivative matrix of direction 1.
1056 * @param D2 1D derivative matrix of direction 2.
1057 * @param f0 Collapsed-coordinate factor (1 + eta_0)/2 of
1058 * direction 0.
1059 * @param f1 Collapsed-coordinate factor (1 + eta_1)/2 of
1060 * direction 1.
1061 * @param f1m Collapsed-coordinate factor 2/(1 - eta_1) of
1062 * direction 1.
1063 * @param f2 Collapsed-coordinate factor 2/(1 - eta_2) of
1064 * direction 2.
1065 * @param df Derivative factors of the block.
1066 * @param in Input values of the block, three components.
1067 * @param wsp Global workspace of CurlCurlWorkSpaceSize
1068 * elements, receiving the vorticity; unused if
1069 * @p useSharedMemoryWsp.
1070 * @param out Output values of the block, three components.
1071 * @param shmemptr Dynamic shared memory of the thread block, at
1072 * least CurlCurlSharedMemorySize elements of TData:
1073 * the factor tables, then the vorticity if
1074 * @p useSharedMemoryWsp.
1075 * @param threadBlock Thread-block handle supplied by the launcher
1076 * macro.
1077 */
1078template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
1079 bool DEFORMED, typename TPhysSizeParameter3D, typename TthreadBlock,
1080 typename TData, typename TUseSharedWsp,
1081 std::enable_if_t<std::is_same_v<Implementation, SumFac>, bool>
1082 Enable = true>
1084 const TPhysSizeParameter3D sizeParam3D, const size_t nelmt,
1085 [[maybe_unused]] const unsigned int elmtsPerBlock, const size_t inoffset,
1086 const TUseSharedWsp useSharedMemoryWsp, const TData *NEK_RESTRICT D0,
1087 const TData *NEK_RESTRICT D1, const TData *NEK_RESTRICT D2,
1088 const TData *NEK_RESTRICT f0, const TData *NEK_RESTRICT f1,
1089 const TData *NEK_RESTRICT f1m, const TData *NEK_RESTRICT f2,
1090 const TData *NEK_RESTRICT df, const TData *NEK_RESTRICT in,
1091 TData *NEK_RESTRICT wsp, TData *NEK_RESTRICT out, unsigned char *shmemptr,
1092 const TthreadBlock &threadBlock)
1093{
1094 static_assert(
1095 IsPhysSizeParameter3D_v<TPhysSizeParameter3D>,
1096 "Template argument must be either of type "
1097 "NonTemplatedPhysSizeParameter3D or TemplatedPhysSizeParameter3D.");
1098
1100
1101 const unsigned int nq0 = sizeParam3D.nq0();
1102 const unsigned int nq1 = sizeParam3D.nq1();
1103 const unsigned int nq2 = sizeParam3D.nq2();
1104 const unsigned int nqTot = sizeParam3D.nqTot();
1105
1106 constexpr unsigned int ndf = 9u;
1107 const unsigned int dfsize = DEFORMED ? nqTot : 1u;
1108
1109 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
1110
1111 TData *s_f0 = nullptr;
1112 TData *s_f1 = nullptr;
1113 TData *s_f1m = nullptr;
1114 TData *s_f2 = nullptr;
1115 unsigned int ntable = 0u;
1116
1117 // Precompute geometric factors.
1118 if constexpr (SHAPE_TYPE == LibUtilities::Tet ||
1119 SHAPE_TYPE == LibUtilities::NodalTet)
1120 {
1121 s_f0 = (TData *)shmemptr;
1122 s_f1 = s_f0 + nq0;
1123 s_f1m = s_f1 + nq1;
1124 s_f2 = s_f1m + nq1;
1125 ntable = nq0 + 2u * nq1 + nq2;
1126
1127 // Copy to shared memory.
1128 LoadToSharedMemory(nq0, f0, s_f0, threadBlock);
1129 LoadToSharedMemory(nq1, f1, s_f1, threadBlock);
1130 LoadToSharedMemory(nq1, f1m, s_f1m, threadBlock);
1131 LoadToSharedMemory(nq2, f2, s_f2, threadBlock);
1132
1133 localBarrier(threadBlock);
1134 }
1135 else if constexpr (SHAPE_TYPE == LibUtilities::Prism ||
1136 SHAPE_TYPE == LibUtilities::NodalPrism)
1137 {
1138 s_f0 = (TData *)shmemptr;
1139 s_f2 = s_f0 + nq0;
1140 ntable = nq0 + nq2;
1141
1142 // Copy to shared memory.
1143 LoadToSharedMemory(nq0, f0, s_f0, threadBlock);
1144 LoadToSharedMemory(nq2, f2, s_f2, threadBlock);
1145
1146 localBarrier(threadBlock);
1147 }
1148 else if constexpr (SHAPE_TYPE == LibUtilities::Pyr ||
1149 SHAPE_TYPE == LibUtilities::NodalPyr)
1150 {
1151 s_f0 = (TData *)shmemptr;
1152 s_f1 = s_f0 + nq0;
1153 s_f2 = s_f1 + nq1;
1154 ntable = nq0 + nq1 + nq2;
1155
1156 // Copy to shared memory.
1157 LoadToSharedMemory(nq0, f0, s_f0, threadBlock);
1158 LoadToSharedMemory(nq1, f1, s_f1, threadBlock);
1159 LoadToSharedMemory(nq2, f2, s_f2, threadBlock);
1160
1161 localBarrier(threadBlock);
1162 }
1163
1164 DispatchWorkSpace(useSharedMemoryWsp, [&](const auto isShared) {
1165 // Vorticity after the factor tables, or in the global workspace.
1166 TData *wspbase = isShared ? (TData *)shmemptr + ntable : wsp;
1167 const size_t wspoffset = isShared ? nqTot * warpsize : inoffset;
1168
1169 // Use size_t to prevent overflow.
1170 size_t e = getGlobalIdx<0>(threadBlock);
1171 while (e < nelmt)
1172 {
1173 const size_t ilane = e % warpsize;
1174 const size_t iwarp = e / warpsize;
1175 const TData *dfptr = df + ndf * dfsize * warpsize * iwarp;
1176 const TData *inptr = in + nqTot * warpsize * iwarp;
1177 TData *outptr = out + nqTot * warpsize * iwarp;
1178 TData *wspptr = wspbase + (isShared ? 0 : nqTot * warpsize * iwarp);
1179
1180 // omega = curl(u)
1181 Curl3DSumFacKernel<SHAPE_TYPE, DEFORMED>(
1182 ilane, nq0, nq1, nq2, inoffset, wspoffset, D0, D1, D2, s_f0,
1183 s_f1, s_f1m, s_f2, dfptr, inptr, wspptr);
1184
1185 // out = curl(omega)
1186 Curl3DSumFacKernel<SHAPE_TYPE, DEFORMED>(
1187 ilane, nq0, nq1, nq2, wspoffset, inoffset, D0, D1, D2, s_f0,
1188 s_f1, s_f1m, s_f2, dfptr, wspptr, outptr);
1189
1190 e += getGlobalRange<0>(threadBlock);
1191 }
1192 });
1193}
1194
1195#endif
1196
1197} // 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
Device SumFac kernels of the physical derivative: one element per warp lane.
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
static NEK_FORCE_INLINE void Curl2DScalarSumFacKernel(const unsigned nq0, const unsigned nq1, const unsigned int ncoord, const simd_type *f0, const simd_type *f1, const simd_type *df_ptr, const simd_type *tderiv0_0, const simd_type *tderiv1_0, const simd_type *tderiv0_1, const simd_type *tderiv1_1, simd_type *out)
Scalar curl of a two-dimensional vector field, omega = d(u1)/dx0 - d(u0)/dx1, from the tensor-directi...
static NEK_FORCE_INLINE void CurlCurlKernelLauncher(const TPhysSizeParameter1D sizeParam1D, const typename simd_type::scalarType *D0, const simd_type *df_ptr, simd_type *wsp, const simd_type *in0, simd_type *out0)
1D entry point: the curl-curl is undefined on a segment, so the group's single component is different...
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
DispatchWorkSpace(useSharedMemoryWsp, [&](const auto isShared) { TData *wspbase=isShared ?(TData *) shmemptr+tableSize :wsp;while(e< nelmt) { const size_t ilane=e % warpsize;const size_t iwarp=e/warpsize;const TData *inptr=in+numDataIn *(nelmt *c+warpsize *iwarp);TData *outptr=out+numDataOut *(nelmt *c+warpsize *iwarp);const size_t wspOffset=isShared ? 0 :nelmt *c+warpsize *iwarp;TData *wspptr=wspbase+(edgeSize+numDataOut) *wspOffset;TData *volptr=wspptr+edgeSize *warpsize;const unsigned int off1=warpsize *2 *tnq00;const unsigned int joff1=(DEFORMED) ? off1 :warpsize *2;for(unsigned int d=0;d< 2;++d) { const bool useD1=CompNeedsCollapsedFac(SHAPE_TYPE, d, 1);const TData *jacptr=jac+d *jacCompStride+numDataJac *warpsize *iwarp;if(!(append||d > 0)) { for(unsigned int p=0;p< numDataOut;++p) { outptr[warpsize *p+ilane]=0.0;} } { TData *dst=useD1 ? volptr :outptr;if(useD1) { for(unsigned int p=0;p< numDataOut;++p) { dst[warpsize *p+ilane]=0.0;} } const TData *nb=(0==d) ? dnbasis0 :nbasis0;const TData *tb=(traceDir0==d) ? dtbasis0 :tbasis0;const bool coll=(traceDir0==d) ? false :isColl0;const bool endp=(0==d) ? false :endPtsColl0;if(endp) { IPWRTPhysTraceEdgeN0Kernel< true, DEFORMED >(ilane, 0, 2, 2, nm0, nm1, nb, tnq00, tb, tw0, jacptr, wspptr, inptr, dst, coll);} else { IPWRTPhysTraceEdgeN0Kernel< false, DEFORMED >(ilane, 0, 2, 2, nm0, nm1, nb, tnq00, tb, tw0, jacptr, wspptr, inptr, dst, coll);} if(useD1) { ScaleAddCollapsedFacKernel(ilane, nm0, nm1, 1u, true, false, s_twoOver1, s_twoOver1, volptr, outptr);} } { const TData *nb=(1==d) ? dnbasis1 :nbasis1;const TData *tb=(traceDir1==d) ? dtbasis1 :tbasis1;const bool coll=(traceDir1==d) ? false :isColl1;const bool endp=(1==d) ? false :endPtsColl1;if(endp) { IPWRTPhysTraceEdgeN1Kernel< true, DEFORMED >(ilane, 0, nedgeN1, nedgeN1, nm0, nm1, nb, tnq10, tb, tw1, jacptr+joff1, wspptr, inptr+off1, outptr, coll);} else { IPWRTPhysTraceEdgeN1Kernel< false, DEFORMED >(ilane, 0, nedgeN1, nedgeN1, nm0, nm1, nb, tnq10, tb, tw1, jacptr+joff1, wspptr, inptr+off1, outptr, coll);} } } e+=getGlobalRange< 0 >(threadBlock);} })
static NEK_FORCE_INLINE void Curl2DVectorSumFacKernel(const unsigned nq0, const unsigned nq1, const unsigned int ncoord, const simd_type *f0, const simd_type *f1, const simd_type *df_ptr, const simd_type *tderiv0, const simd_type *tderiv1, simd_type *out0, simd_type *out1)
Vector curl of a two-dimensional scalar field, out = ( d(omega)/dx1, -d(omega)/dx0 ),...
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 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 wsp
static NEK_FORCE_INLINE void Curl3DH1KernelLauncher(const TPhysSizeParameter2D sizeParam2D, const typename simd_type::scalarType *D0, const typename simd_type::scalarType *D1, const simd_type *f0, const simd_type *f1, const simd_type *df_ptr, simd_type *wsp, const simd_type *in0, const simd_type *in1, const simd_type *in2, simd_type *out0, simd_type *out1, simd_type *out2)
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const size_t nelmt
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 NEK_FORCE_INLINE void Curl3DSumFacKernel(const unsigned nq0, const unsigned nq1, const unsigned nq2, const simd_type *f0, const simd_type *f1, const simd_type *f1m, const simd_type *f2, const simd_type *df_ptr, const simd_type *tderiv0_0, const simd_type *tderiv1_0, const simd_type *tderiv2_0, const simd_type *tderiv0_1, const simd_type *tderiv1_1, const simd_type *tderiv2_1, const simd_type *tderiv0_2, const simd_type *tderiv1_2, const simd_type *tderiv2_2, simd_type *out0, simd_type *out1, simd_type *out2)
Curl of a three-dimensional vector field from the tensor-direction derivatives of its three component...
std::vector< double > p(NPUPPER)
static constexpr unsigned int warpSize
Definition Backends.hpp:143