Nektar++
Loading...
Searching...
No Matches
PhysLiftProjectBlockOpDeviceSumFacKernels.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: PhysLiftProjectBlockOpDeviceSumFacKernels.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 lift-and-project element operator.
32//
33///////////////////////////////////////////////////////////////////////////////
34
35/**
36 * @file PhysLiftProjectBlockOpDeviceSumFacKernels.hpp
37 * @brief Device SumFac kernels of the lift-and-project operator: the direct
38 * lift of the Pointwise form, the fused launches of the StdInvMass form, and
39 * the scales the separate-operator route takes.
40 *
41 * @details
42 * As the other SumFac Device kernels, one thread per element: the block is
43 * at warpSize, element `e` is lane `ilane = e % warpSize` of element group
44 * `iwarp = e / warpSize`, consecutive threads touch consecutive entries, and
45 * each thread loops over its element's points or modes. Each kernel is
46 * restricted to Implementation SumFac; its SumFacTOP counterpart has the
47 * same name and arguments, so that the caller launches
48 * `Kernel<Implementation, ...>` for either.
49 *
50 * The fused launches are built from the per-element functions of the
51 * IProductWRTPhysTrace, IProductWRTBase and BwdTrans SumFac kernels, as
52 * the Mass kernels chain BwdTrans and IProductWRTBase:
53 * - PhysLiftProjectKernelLauncher: the StdInvMass form with a diagonal
54 * standard inverse mass, in one launch;
55 * - PhysLiftProjectLiftBasisTransposeKernelLauncher and
56 * PhysLiftProjectScaleBwdTransKernelLauncher: the StdInvMass form with a
57 * dense standard inverse mass, either side of the batched product.
58 * Their intermediates live in the global workspace, one region per
59 * intermediate laid out as a block at warpSize.
60 *
61 * PhysLiftProjectPointwiseKernel and PhysLiftProjectInvMassScaleKernel
62 * serve the separate-operator route, which takes the nodal shapes and the
63 * Pointwise blocks the direct lift does not.
64 *
65 * PhysLiftProjectDirectLiftKernelLauncher, the Pointwise form's direct
66 * lift, takes one thread per point of each element instead, lanes first, a
67 * thread block being a warp as for the other kernels. The quadrature
68 * weights are read
69 * once per point and broadcast across the lanes, as the basis is.
70 */
71
72#pragma once
73
82
83#include <type_traits>
84
86{
87
88#if defined(NEKTAR_ENABLE_DEVICE) && defined(DEVICE_COMPILE_ONLY)
89
90/**
91 * @brief Per-element size of the first sum-factorisation stage scratch of
92 * the fused SumFac kernels, which the basis transpose and the backward
93 * transform share: the larger of what IProductWRTBase and BwdTrans take for
94 * the shape. None in one dimension.
95 */
96template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
97 typename TSizeParameter,
98 std::enable_if_t<std::is_same_v<Implementation, SumFac>, bool>
99 Enable = true>
100NEK_HOSTDEVICE_INLINE constexpr unsigned int PhysLiftProjectStage0Size(
101 [[maybe_unused]] const TSizeParameter sizeParam)
102{
103 if constexpr (IsSizeParameter2D_v<TSizeParameter>)
104 {
105 const unsigned int nq1 = sizeParam.nq1();
106 if constexpr (SHAPE_TYPE == LibUtilities::Quad)
107 {
108 return std::max(nq1, sizeParam.nm1());
109 }
110 else if constexpr (SHAPE_TYPE == LibUtilities::Tri)
111 {
112 return std::max(nq1, sizeParam.nm0());
113 }
114 }
115 else if constexpr (IsSizeParameter3D_v<TSizeParameter>)
116 {
117 const unsigned int nm0 = sizeParam.nm0();
118 const unsigned int nm1 = sizeParam.nm1();
119 const unsigned int nq12 = sizeParam.nq1() * sizeParam.nq2();
120 if constexpr (SHAPE_TYPE == LibUtilities::Hex)
121 {
122 return std::max(nq12, nm1 * sizeParam.nm2());
123 }
124 else if constexpr (SHAPE_TYPE == LibUtilities::Tet)
125 {
126 return std::max(nq12, (2u * nm1 - nm0 + 1u) * nm0 / 2u);
127 }
128 else if constexpr (SHAPE_TYPE == LibUtilities::Prism ||
129 SHAPE_TYPE == LibUtilities::Pyr ||
130 SHAPE_TYPE == LibUtilities::NodalPyr)
131 {
132 return std::max(nq12, nm0 * nm1);
133 }
134 }
135 else
136 {
137 return 0u;
138 }
139}
140
141/**
142 * @brief Per-element size of the second sum-factorisation stage scratch of
143 * the fused SumFac kernels, as PhysLiftProjectStage0Size(). Three dimensions
144 * only.
145 */
146template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
147 typename TSizeParameter,
148 std::enable_if_t<std::is_same_v<Implementation, SumFac>, bool>
149 Enable = true>
150NEK_HOSTDEVICE_INLINE constexpr unsigned int PhysLiftProjectStage1Size(
151 [[maybe_unused]] const TSizeParameter sizeParam)
152{
153 if constexpr (IsSizeParameter3D_v<TSizeParameter>)
154 {
155 const unsigned int nq2 = sizeParam.nq2();
156 if constexpr (SHAPE_TYPE == LibUtilities::Hex)
157 {
158 return std::max(nq2, sizeParam.nm2());
159 }
160 else if constexpr (SHAPE_TYPE == LibUtilities::Tet ||
161 SHAPE_TYPE == LibUtilities::Prism ||
162 SHAPE_TYPE == LibUtilities::Pyr ||
163 SHAPE_TYPE == LibUtilities::NodalPyr)
164 {
165 return std::max(nq2, sizeParam.nm0());
166 }
167 }
168 else
169 {
170 return 0u;
171 }
172}
173
174/**
175 * @brief Dynamic shared memory of the fused SumFac kernels: none, their
176 * intermediates living in the global workspace.
177 */
178template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
179 PhysLiftProjectKernel KERNEL, typename TData, typename TSizeParameter,
180 typename TTraceSizeParameter,
181 std::enable_if_t<std::is_same_v<Implementation, SumFac>, bool>
182 Enable = true>
183inline constexpr unsigned int PhysLiftProjectSharedMemorySize(
184 [[maybe_unused]] const TSizeParameter sizeParam,
185 [[maybe_unused]] const TTraceSizeParameter traceSizeParam,
186 [[maybe_unused]] const unsigned int elmtsPerBlock)
187{
188 return 0u;
189}
190
191/// The lift of the two end values of a segment onto its points, in place
192/// on @p vol at warpSize (one dimension has no lift function of its own).
193template <typename TData>
194NEK_DEVICE_INLINE static void PhysLiftProjectSegLiftKernel(
195 const unsigned int ilane, const unsigned int nq0,
196 const TData *NEK_RESTRICT nbasis0, const bool endPtsCollocated0,
197 const TData *NEK_RESTRICT trace, TData *NEK_RESTRICT vol)
198{
199 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
200
202 {
203 vol[ilane] += trace[ilane];
204 vol[warpsize * (nq0 - 1) + ilane] += trace[warpsize + ilane];
205 }
206 else
207 {
208 for (unsigned int p = 0; p < nq0; ++p)
209 {
210 vol[warpsize * p + ilane] +=
211 nbasis0[2 * p] * trace[ilane] +
212 nbasis0[2 * p + 1] * trace[warpsize + ilane];
213 }
214 }
215}
216
217/// Copy @p in into @p vol, both at warpSize, unless they are the same
218/// storage, which they are when the input was interleaved into the
219/// workspace.
220template <typename TData>
221NEK_DEVICE_INLINE static void PhysLiftProjectCopyInKernel(
222 const unsigned int ilane, const unsigned int nqTot, const TData *in,
223 TData *vol)
224{
225 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
226
227 if (in != vol)
228 {
229 for (unsigned int q = 0; q < nqTot; ++q)
230 {
231 vol[warpsize * q + ilane] = in[warpsize * q + ilane];
232 }
233 }
234}
235
236/**
237 * @brief The Pointwise form: `out (+)= scale / (w_q J) * in` at every point,
238 * zero on the padding elements, whose Jacobian is zero. Grid dimension 1 is
239 * the component.
240 *
241 * @param weights The quadrature weights at every point (WeightsKey at
242 * width one), the same for every lane.
243 * @param jac The Jacobians (JacobianKey at warpSize), one per
244 * element, or one per point when @p DEFORMED.
245 */
246template <typename Implementation, bool APPEND, bool DEFORMED,
247 typename TthreadBlock, typename TData,
248 std::enable_if_t<std::is_same_v<Implementation, SumFac>, bool>
249 Enable = true>
251 const size_t nelmt, const unsigned int nqTot, const TData scale,
252 const TData *NEK_RESTRICT weights, const TData *NEK_RESTRICT jac,
253 const TData *NEK_RESTRICT in, TData *NEK_RESTRICT out,
254 const TthreadBlock &threadBlock)
255{
256 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
257
258 const unsigned int c = getBlockIdx<1>(threadBlock);
259 for (size_t e = getGlobalIdx<0>(threadBlock); e < nelmt;
260 e += getGlobalRange<0>(threadBlock))
261 {
262 const size_t ilane = e % warpsize;
263 const size_t iwarp = e / warpsize;
264 const size_t offset = nqTot * (nelmt * c + warpsize * iwarp) + ilane;
265 for (unsigned int q = 0; q < nqTot; ++q)
266 {
267 TData jacobian;
268 if constexpr (DEFORMED)
269 {
270 jacobian = jac[(iwarp * nqTot + q) * warpsize + ilane];
271 }
272 else
273 {
274 jacobian = jac[e];
275 }
276 const TData factor = SafeDivide(scale, weights[q] * jacobian);
277 const size_t i = offset + static_cast<size_t>(q) * warpsize;
278 if constexpr (APPEND)
279 {
280 out[i] += factor * in[i];
281 }
282 else
283 {
284 out[i] = factor * in[i];
285 }
286 }
287 }
288}
289
290/**
291 * @brief The inverse mass of an affine element with the scale: `out[m] =
292 * scale / J * diag[m] * in[m]`, the diagonal of the standard inverse mass
293 * @p diag (eInvMassStdMatDiagonal) left out unless @p DIAG, zero on the
294 * padding elements, whose Jacobian is zero. @p in may be @p out. Grid
295 * dimension 1 is the component.
296 *
297 * @param jac The Jacobians (JacobianKey at warpSize), one per element.
298 */
299template <typename Implementation, bool DIAG, typename TthreadBlock,
300 typename TData,
301 std::enable_if_t<std::is_same_v<Implementation, SumFac>, bool>
302 Enable = true>
303NEK_DEVICE_KERNEL void PhysLiftProjectInvMassScaleKernel(
304 const size_t nelmt, const unsigned int nmTot, const TData scale,
305 const TData *NEK_RESTRICT diag, const TData *NEK_RESTRICT jac,
306 const TData *in, TData *out, const TthreadBlock &threadBlock)
307{
308 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
309
310 const unsigned int c = getBlockIdx<1>(threadBlock);
311 for (size_t e = getGlobalIdx<0>(threadBlock); e < nelmt;
312 e += getGlobalRange<0>(threadBlock))
313 {
314 const size_t ilane = e % warpsize;
315 const size_t iwarp = e / warpsize;
316 const size_t offset = nmTot * (nelmt * c + warpsize * iwarp) + ilane;
317 const TData factor = SafeDivide(scale, jac[e]);
318 for (unsigned int m = 0; m < nmTot; ++m)
319 {
320 const size_t i = offset + static_cast<size_t>(m) * warpsize;
321 if constexpr (DIAG)
322 {
323 out[i] = factor * diag[m] * in[i];
324 }
325 else
326 {
327 out[i] = factor * in[i];
328 }
329 }
330 }
331}
332
333/**
334 * @brief The StdInvMass form with a diagonal standard inverse mass in one
335 * dimension. See the three-dimensional overload.
336 */
337template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
338 bool APPEND, typename TSizeParameter1D,
339 typename TTraceSizeParameter1D, typename TthreadBlock, typename TData,
340 std::enable_if_t<std::is_same_v<Implementation, SumFac>, bool>
341 Enable = true>
343 (GetMaxThreadPerBlock<Implementation, TSizeParameter1D>()))
344 PhysLiftProjectKernelLauncher(
345 const TSizeParameter1D sizeParam1D,
346 [[maybe_unused]] const TTraceSizeParameter1D traceSizeParam1D,
347 const size_t nelmt, const TData scale, const bool lift,
348 [[maybe_unused]] const bool isModified,
349 [[maybe_unused]] const TData *NEK_RESTRICT basis0,
350 const TData *NEK_RESTRICT nbasis0,
351 [[maybe_unused]] const TData *NEK_RESTRICT tjac,
352 const bool endPtsCollocated0, const TData *NEK_RESTRICT jac,
353 const TData *NEK_RESTRICT diag, const TData *in,
354 const TData *NEK_RESTRICT trace, TData *NEK_RESTRICT out, TData *vol,
355 [[maybe_unused]] TData *NEK_RESTRICT coef,
356 [[maybe_unused]] unsigned char *shmemptr,
357 const TthreadBlock &threadBlock)
358{
359 static_assert(IsSizeParameter1D_v<TSizeParameter1D>,
360 "Template argument must be either of type "
361 "NonTemplatedSizeParameter1D or TemplatedSizeParameter1D.");
362
363 const unsigned int nm0 = sizeParam1D.nm0();
364 const unsigned int nq0 = sizeParam1D.nq0();
365
366 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
367
368 size_t e = getGlobalIdx<0>(threadBlock);
369 const unsigned int c = getBlockIdx<1>(threadBlock);
370 while (e < nelmt)
371 {
372 const size_t ilane = e % warpsize;
373 const size_t iwarp = e / warpsize;
374 const size_t slot = nelmt * c + warpsize * iwarp;
375 const TData *inptr = in + nq0 * slot;
376 TData *outptr = out + nq0 * slot;
377 TData *volptr = vol + nq0 * slot;
378
379 PhysLiftProjectCopyInKernel(ilane, nq0, inptr, volptr);
380 if (lift)
381 {
382 PhysLiftProjectSegLiftKernel(ilane, nq0, nbasis0, endPtsCollocated0,
383 trace + 2 * slot, volptr);
384 }
385
386 TData *coefptr = coef + nm0 * slot;
387 IProductWRTBaseSegSumFacKernel<false, false>(
388 ilane, nm0, nq0, basis0, volptr, coefptr, TData(1.0));
389 const TData factor = SafeDivide(scale, jac[e]);
390 for (unsigned int m = 0; m < nm0; ++m)
391 {
392 coefptr[warpsize * m + ilane] *= factor * diag[m];
393 }
394 BwdTransSegSumFacKernel<APPEND>(ilane, nm0, nq0, basis0, coefptr,
395 outptr);
396
397 e += getGlobalRange<0>(threadBlock);
398 }
399}
400
401/**
402 * @brief The StdInvMass form with a diagonal standard inverse mass in two
403 * dimensions. See the three-dimensional overload.
404 */
405template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
406 bool APPEND, typename TSizeParameter2D,
407 typename TTraceSizeParameter2D, typename TthreadBlock, typename TData,
408 std::enable_if_t<std::is_same_v<Implementation, SumFac>, bool>
409 Enable = true>
411 (GetMaxThreadPerBlock<Implementation, TSizeParameter2D>()))
412 PhysLiftProjectKernelLauncher(
413 const TSizeParameter2D sizeParam2D,
414 const TTraceSizeParameter2D traceSizeParam2D, const size_t nelmt,
415 const TData scale, const bool lift, const bool isModified,
416 [[maybe_unused]] const unsigned int *NEK_RESTRICT index0,
417 const TData *NEK_RESTRICT basis0, const TData *NEK_RESTRICT basis1,
418 const TData *NEK_RESTRICT nbasis0, const TData *NEK_RESTRICT nbasis1,
419 const TData *NEK_RESTRICT tbasis0, const TData *NEK_RESTRICT tbasis1,
420 const TData *NEK_RESTRICT tw00, const TData *NEK_RESTRICT tw10,
421 const TData *NEK_RESTRICT tjac, const bool isCollocated0,
422 const bool isCollocated1, const bool endPtsCollocated0,
423 const bool endPtsCollocated1, const TData *NEK_RESTRICT jac,
424 const TData *NEK_RESTRICT diag, const TData *in,
425 const TData *NEK_RESTRICT trace, TData *NEK_RESTRICT out, TData *vol,
426 [[maybe_unused]] TData *NEK_RESTRICT coef, TData *NEK_RESTRICT wsp0,
427 TData *NEK_RESTRICT lift0, [[maybe_unused]] unsigned char *shmemptr,
428 const TthreadBlock &threadBlock)
429{
430 static_assert(IsSizeParameter2D_v<TSizeParameter2D>,
431 "Template argument must be either of type "
432 "NonTemplatedSizeParameter2D or TemplatedSizeParameter2D.");
433
434 const unsigned int nm0 = sizeParam2D.nm0();
435 const unsigned int nm1 = sizeParam2D.nm1();
436 const unsigned int nmTot = sizeParam2D.nmTot();
437 const unsigned int nq0 = sizeParam2D.nq0();
438 const unsigned int nq1 = sizeParam2D.nq1();
439 const unsigned int nqTot = nq0 * nq1;
440
441 const unsigned int tnq00 = traceSizeParam2D.nq00();
442 const unsigned int tnq10 = traceSizeParam2D.nq10();
443 const unsigned int nqTotTrace =
444 traceSizeParam2D.template nqTotTrace<SHAPE_TYPE>();
445 const unsigned int numDataJac =
447
448 const unsigned int wsp0Size =
449 PhysLiftProjectStage0Size<SHAPE_TYPE, Implementation>(sizeParam2D);
450 const unsigned int lift0Size =
451 2u * IProductWRTPhysTraceEdgeModeBlockSize(traceSizeParam2D);
452
453 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
454
455 size_t e = getGlobalIdx<0>(threadBlock);
456 const unsigned int c = getBlockIdx<1>(threadBlock);
457 while (e < nelmt)
458 {
459 const size_t ilane = e % warpsize;
460 const size_t iwarp = e / warpsize;
461 const size_t slot = nelmt * c + warpsize * iwarp;
462 const TData *inptr = in + nqTot * slot;
463 TData *outptr = out + nqTot * slot;
464 TData *volptr = vol + nqTot * slot;
465
466 PhysLiftProjectCopyInKernel(ilane, nqTot, inptr, volptr);
467 if (lift)
468 {
469 IProductWRTPhysTrace2DKernel<SHAPE_TYPE, false, true>(
470 ilane, nq0, nq1, nbasis0, nbasis1, tnq00, tnq10, tbasis0,
471 tbasis1, tw00, tw10, tjac + numDataJac * warpsize * iwarp,
472 lift0 + lift0Size * slot, trace + nqTotTrace * slot, volptr,
473 isCollocated0, isCollocated1, endPtsCollocated0,
474 endPtsCollocated1);
475 }
476
477 TData *coefptr = coef + nmTot * slot;
478 TData *wsp0ptr = wsp0 + wsp0Size * slot;
479 IProductWRTBase2DSumFacKernel<SHAPE_TYPE, false, false>(
480 ilane, nm0, nm1, nq0, nq1, isModified, basis0, basis1, volptr,
481 coefptr, wsp0ptr, TData(1.0));
482 const TData factor = SafeDivide(scale, jac[e]);
483 for (unsigned int m = 0; m < nmTot; ++m)
484 {
485 coefptr[warpsize * m + ilane] *= factor * diag[m];
486 }
487 BwdTrans2DSumFacKernel<SHAPE_TYPE, APPEND>(ilane, nm0, nm1, nq0, nq1,
488 isModified, basis0, basis1,
489 coefptr, outptr, wsp0ptr);
490
491 e += getGlobalRange<0>(threadBlock);
492 }
493}
494
495/**
496 * @brief The StdInvMass form with a diagonal standard inverse mass of a
497 * block of affine three-dimensional elements in one launch, one thread per
498 * element at warpSize.
499 *
500 * Each thread copies its element's inner products into @p vol (unless the
501 * input was interleaved into @p vol already), lifts the trace onto them,
502 * applies the basis transpose into @p coef, `coef *= scale / J * diag` and
503 * the backward transform into @p out, appending when @p APPEND.
504 *
505 * @p in, @p trace, @p out and the workspace regions @p vol, @p coef,
506 * @p wsp0, @p wsp1, @p lift0 and @p lift1 are at warpSize, each region
507 * holding its per-element size for every element and component, laid out
508 * as a block (`size * (nelmt * c + warpSize * iwarp)` to the element's
509 * group). The lift tables and flags are those of IProductWRTPhysTrace, the
510 * bases and the index tables those of IProductWRTBase and BwdTrans; the
511 * index tables are read only by the SumFacTOP counterpart.
512 */
513template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
514 bool APPEND, typename TSizeParameter3D,
515 typename TTraceSizeParameter3D, typename TthreadBlock, typename TData,
516 std::enable_if_t<std::is_same_v<Implementation, SumFac>, bool>
517 Enable = true>
519 (GetMaxThreadPerBlock<Implementation, TSizeParameter3D>()))
520 PhysLiftProjectKernelLauncher(
521 const TSizeParameter3D sizeParam3D,
522 const TTraceSizeParameter3D traceSizeParam3D, const size_t nelmt,
523 const TData scale, const bool lift, const bool isModified,
524 [[maybe_unused]] const unsigned int *NEK_RESTRICT index0,
525 [[maybe_unused]] const unsigned int *NEK_RESTRICT index1,
526 [[maybe_unused]] const unsigned int *NEK_RESTRICT index2,
527 [[maybe_unused]] const unsigned int *NEK_RESTRICT index3,
528 const TData *NEK_RESTRICT basis0, const TData *NEK_RESTRICT basis1,
529 const TData *NEK_RESTRICT basis2, const TData *NEK_RESTRICT nbasis0,
530 const TData *NEK_RESTRICT nbasis1, const TData *NEK_RESTRICT nbasis2,
531 const TData *NEK_RESTRICT tbasis00, const TData *NEK_RESTRICT tbasis01,
532 const TData *NEK_RESTRICT tbasis10, const TData *NEK_RESTRICT tbasis11,
533 const TData *NEK_RESTRICT tbasis20, const TData *NEK_RESTRICT tbasis21,
534 const TData *NEK_RESTRICT tw00, const TData *NEK_RESTRICT tw01,
535 const TData *NEK_RESTRICT tw10, const TData *NEK_RESTRICT tw11,
536 const TData *NEK_RESTRICT tw20, const TData *NEK_RESTRICT tw21,
537 const TData *NEK_RESTRICT tjac, const bool isCollocated00,
538 const bool isCollocated01, const bool isCollocated10,
539 const bool isCollocated11, const bool isCollocated20,
540 const bool isCollocated21, const bool endPtsCollocated0,
541 const bool endPtsCollocated1, const bool endPtsCollocated2,
542 const TData *NEK_RESTRICT jac, const TData *NEK_RESTRICT diag,
543 const TData *in, const TData *NEK_RESTRICT trace,
544 TData *NEK_RESTRICT out, TData *vol,
545 [[maybe_unused]] TData *NEK_RESTRICT coef, TData *NEK_RESTRICT wsp0,
546 TData *NEK_RESTRICT wsp1, TData *NEK_RESTRICT lift0,
547 TData *NEK_RESTRICT lift1, [[maybe_unused]] unsigned char *shmemptr,
548 const TthreadBlock &threadBlock)
549{
550 static_assert(IsSizeParameter3D_v<TSizeParameter3D>,
551 "Template argument must be either of type "
552 "NonTemplatedSizeParameter3D or TemplatedSizeParameter3D.");
553
554 const unsigned int nm0 = sizeParam3D.nm0();
555 const unsigned int nm1 = sizeParam3D.nm1();
556 const unsigned int nm2 = sizeParam3D.nm2();
557 const unsigned int nmTot = sizeParam3D.nmTot();
558 const unsigned int nq0 = sizeParam3D.nq0();
559 const unsigned int nq1 = sizeParam3D.nq1();
560 const unsigned int nq2 = sizeParam3D.nq2();
561 const unsigned int nqTot = nq0 * nq1 * nq2;
562
563 const unsigned int tnq00 = traceSizeParam3D.nq00();
564 const unsigned int tnq01 = traceSizeParam3D.nq01();
565 const unsigned int tnq10 = traceSizeParam3D.nq10();
566 const unsigned int tnq11 = traceSizeParam3D.nq11();
567 const unsigned int tnq20 = traceSizeParam3D.nq20();
568 const unsigned int tnq21 = traceSizeParam3D.nq21();
569 const unsigned int nqTotTrace =
570 traceSizeParam3D.template nqTotTrace<SHAPE_TYPE>();
571 const unsigned int numDataJac =
573
574 const unsigned int wsp0Size =
575 PhysLiftProjectStage0Size<SHAPE_TYPE, Implementation>(sizeParam3D);
576 const unsigned int wsp1Size =
577 PhysLiftProjectStage1Size<SHAPE_TYPE, Implementation>(sizeParam3D);
578 const unsigned int lift0Size =
579 IProductWRTPhysTraceFaceModeBlockSize(traceSizeParam3D);
580 const unsigned int lift1Size =
581 IProductWRTPhysTraceFaceScratchSize(traceSizeParam3D);
582
583 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
584
585 size_t e = getGlobalIdx<0>(threadBlock);
586 const unsigned int c = getBlockIdx<1>(threadBlock);
587 while (e < nelmt)
588 {
589 const size_t ilane = e % warpsize;
590 const size_t iwarp = e / warpsize;
591 const size_t slot = nelmt * c + warpsize * iwarp;
592 const TData *inptr = in + nqTot * slot;
593 TData *outptr = out + nqTot * slot;
594 TData *volptr = vol + nqTot * slot;
595
596 PhysLiftProjectCopyInKernel(ilane, nqTot, inptr, volptr);
597 if (lift)
598 {
599 IProductWRTPhysTrace3DFaceKernel<SHAPE_TYPE, false, true>(
600 ilane, nq0, nq1, nq2, nbasis0, nbasis1, nbasis2, tnq00, tnq01,
603 tw21, tjac + numDataJac * warpsize * iwarp,
604 lift0 + lift0Size * slot, lift1 + lift1Size * slot,
605 trace + nqTotTrace * slot, volptr, isCollocated00,
606 isCollocated01, isCollocated10, isCollocated11, isCollocated20,
607 isCollocated21, endPtsCollocated0, endPtsCollocated1,
608 endPtsCollocated2);
609 }
610
611 TData *coefptr = coef + nmTot * slot;
612 TData *wsp0ptr = wsp0 + wsp0Size * slot;
613 TData *wsp1ptr = wsp1 + wsp1Size * slot;
614 IProductWRTBase3DSumFacKernel<SHAPE_TYPE, false, false>(
615 ilane, nm0, nm1, nm2, nq0, nq1, nq2, isModified, basis0, basis1,
616 basis2, volptr, coefptr, wsp0ptr, wsp1ptr, TData(1.0));
617 const TData factor = SafeDivide(scale, jac[e]);
618 for (unsigned int m = 0; m < nmTot; ++m)
619 {
620 coefptr[warpsize * m + ilane] *= factor * diag[m];
621 }
622 BwdTrans3DSumFacKernel<SHAPE_TYPE, APPEND>(
623 ilane, nm0, nm1, nm2, nq0, nq1, nq2, isModified, basis0, basis1,
624 basis2, coefptr, outptr, wsp0ptr, wsp1ptr);
625
626 e += getGlobalRange<0>(threadBlock);
627 }
628}
629
630/**
631 * @brief The StdInvMass form with a dense standard inverse mass, before
632 * the product: the lift and the basis transpose into @p coef, in one
633 * launch. One dimension; see the three-dimensional overload.
634 */
635template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
636 typename TSizeParameter1D, typename TTraceSizeParameter1D,
637 typename TthreadBlock, typename TData,
638 std::enable_if_t<std::is_same_v<Implementation, SumFac>, bool>
639 Enable = true>
641 (GetMaxThreadPerBlock<Implementation, TSizeParameter1D>()))
642 PhysLiftProjectLiftBasisTransposeKernelLauncher(
643 const TSizeParameter1D sizeParam1D,
644 [[maybe_unused]] const TTraceSizeParameter1D traceSizeParam1D,
645 const size_t nelmt, const bool lift,
646 [[maybe_unused]] const bool isModified,
647 const TData *NEK_RESTRICT basis0, const TData *NEK_RESTRICT nbasis0,
648 [[maybe_unused]] const TData *NEK_RESTRICT tjac,
649 const bool endPtsCollocated0, const TData *in,
650 const TData *NEK_RESTRICT trace, TData *NEK_RESTRICT coef, TData *vol,
651 [[maybe_unused]] unsigned char *shmemptr,
652 const TthreadBlock &threadBlock)
653{
654 const unsigned int nm0 = sizeParam1D.nm0();
655 const unsigned int nq0 = sizeParam1D.nq0();
656
657 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
658
659 size_t e = getGlobalIdx<0>(threadBlock);
660 const unsigned int c = getBlockIdx<1>(threadBlock);
661 while (e < nelmt)
662 {
663 const size_t ilane = e % warpsize;
664 const size_t iwarp = e / warpsize;
665 const size_t slot = nelmt * c + warpsize * iwarp;
666 const TData *inptr = in + nq0 * slot;
667 TData *coefptr = coef + nm0 * slot;
668
669 TData *volptr = vol + nq0 * slot;
670 PhysLiftProjectCopyInKernel(ilane, nq0, inptr, volptr);
671 if (lift)
672 {
673 PhysLiftProjectSegLiftKernel(ilane, nq0, nbasis0, endPtsCollocated0,
674 trace + 2 * slot, volptr);
675 }
676 IProductWRTBaseSegSumFacKernel<false, false>(
677 ilane, nm0, nq0, basis0, volptr, coefptr, TData(1.0));
678
679 e += getGlobalRange<0>(threadBlock);
680 }
681}
682
683/**
684 * @brief The dense StdInvMass form before the product in two dimensions;
685 * see the three-dimensional overload.
686 */
687template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
688 typename TSizeParameter2D, typename TTraceSizeParameter2D,
689 typename TthreadBlock, typename TData,
690 std::enable_if_t<std::is_same_v<Implementation, SumFac>, bool>
691 Enable = true>
693 (GetMaxThreadPerBlock<Implementation, TSizeParameter2D>()))
694 PhysLiftProjectLiftBasisTransposeKernelLauncher(
695 const TSizeParameter2D sizeParam2D,
696 const TTraceSizeParameter2D traceSizeParam2D, const size_t nelmt,
697 const bool lift, const bool isModified,
698 [[maybe_unused]] const unsigned int *NEK_RESTRICT index0,
699 const TData *NEK_RESTRICT basis0, const TData *NEK_RESTRICT basis1,
700 const TData *NEK_RESTRICT nbasis0, const TData *NEK_RESTRICT nbasis1,
701 const TData *NEK_RESTRICT tbasis0, const TData *NEK_RESTRICT tbasis1,
702 const TData *NEK_RESTRICT tw00, const TData *NEK_RESTRICT tw10,
703 const TData *NEK_RESTRICT tjac, const bool isCollocated0,
704 const bool isCollocated1, const bool endPtsCollocated0,
705 const bool endPtsCollocated1, const TData *in,
706 const TData *NEK_RESTRICT trace, TData *NEK_RESTRICT coef, TData *vol,
707 TData *NEK_RESTRICT wsp0, TData *NEK_RESTRICT lift0,
708 [[maybe_unused]] unsigned char *shmemptr,
709 const TthreadBlock &threadBlock)
710{
711 const unsigned int nm0 = sizeParam2D.nm0();
712 const unsigned int nm1 = sizeParam2D.nm1();
713 const unsigned int nmTot = sizeParam2D.nmTot();
714 const unsigned int nq0 = sizeParam2D.nq0();
715 const unsigned int nq1 = sizeParam2D.nq1();
716 const unsigned int nqTot = nq0 * nq1;
717
718 const unsigned int tnq00 = traceSizeParam2D.nq00();
719 const unsigned int tnq10 = traceSizeParam2D.nq10();
720 const unsigned int nqTotTrace =
721 traceSizeParam2D.template nqTotTrace<SHAPE_TYPE>();
722 const unsigned int numDataJac =
724
725 const unsigned int wsp0Size =
726 PhysLiftProjectStage0Size<SHAPE_TYPE, Implementation>(sizeParam2D);
727 const unsigned int lift0Size =
728 2u * IProductWRTPhysTraceEdgeModeBlockSize(traceSizeParam2D);
729
730 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
731
732 size_t e = getGlobalIdx<0>(threadBlock);
733 const unsigned int c = getBlockIdx<1>(threadBlock);
734 while (e < nelmt)
735 {
736 const size_t ilane = e % warpsize;
737 const size_t iwarp = e / warpsize;
738 const size_t slot = nelmt * c + warpsize * iwarp;
739 const TData *inptr = in + nqTot * slot;
740 TData *coefptr = coef + nmTot * slot;
741
742 TData *volptr = vol + nqTot * slot;
743 PhysLiftProjectCopyInKernel(ilane, nqTot, inptr, volptr);
744 if (lift)
745 {
746 IProductWRTPhysTrace2DKernel<SHAPE_TYPE, false, true>(
747 ilane, nq0, nq1, nbasis0, nbasis1, tnq00, tnq10, tbasis0,
748 tbasis1, tw00, tw10, tjac + numDataJac * warpsize * iwarp,
749 lift0 + lift0Size * slot, trace + nqTotTrace * slot, volptr,
750 isCollocated0, isCollocated1, endPtsCollocated0,
751 endPtsCollocated1);
752 }
753 IProductWRTBase2DSumFacKernel<SHAPE_TYPE, false, false>(
754 ilane, nm0, nm1, nq0, nq1, isModified, basis0, basis1, volptr,
755 coefptr, wsp0 + wsp0Size * slot, TData(1.0));
756
757 e += getGlobalRange<0>(threadBlock);
758 }
759}
760
761/**
762 * @brief The StdInvMass form with a dense standard inverse mass, before
763 * the product, of a block of three-dimensional affine elements in one
764 * launch: each thread copies its element's inner products into @p vol,
765 * lifts the trace onto them and applies the basis transpose into @p coef,
766 * at warpSize. The arguments are those of PhysLiftProjectKernelLauncher().
767 */
768template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
769 typename TSizeParameter3D, typename TTraceSizeParameter3D,
770 typename TthreadBlock, typename TData,
771 std::enable_if_t<std::is_same_v<Implementation, SumFac>, bool>
772 Enable = true>
774 (GetMaxThreadPerBlock<Implementation, TSizeParameter3D>()))
775 PhysLiftProjectLiftBasisTransposeKernelLauncher(
776 const TSizeParameter3D sizeParam3D,
777 const TTraceSizeParameter3D traceSizeParam3D, const size_t nelmt,
778 const bool lift, const bool isModified,
779 [[maybe_unused]] const unsigned int *NEK_RESTRICT index0,
780 [[maybe_unused]] const unsigned int *NEK_RESTRICT index1,
781 [[maybe_unused]] const unsigned int *NEK_RESTRICT index2,
782 [[maybe_unused]] const unsigned int *NEK_RESTRICT index3,
783 const TData *NEK_RESTRICT basis0, const TData *NEK_RESTRICT basis1,
784 const TData *NEK_RESTRICT basis2, const TData *NEK_RESTRICT nbasis0,
785 const TData *NEK_RESTRICT nbasis1, const TData *NEK_RESTRICT nbasis2,
786 const TData *NEK_RESTRICT tbasis00, const TData *NEK_RESTRICT tbasis01,
787 const TData *NEK_RESTRICT tbasis10, const TData *NEK_RESTRICT tbasis11,
788 const TData *NEK_RESTRICT tbasis20, const TData *NEK_RESTRICT tbasis21,
789 const TData *NEK_RESTRICT tw00, const TData *NEK_RESTRICT tw01,
790 const TData *NEK_RESTRICT tw10, const TData *NEK_RESTRICT tw11,
791 const TData *NEK_RESTRICT tw20, const TData *NEK_RESTRICT tw21,
792 const TData *NEK_RESTRICT tjac, const bool isCollocated00,
793 const bool isCollocated01, const bool isCollocated10,
794 const bool isCollocated11, const bool isCollocated20,
795 const bool isCollocated21, const bool endPtsCollocated0,
796 const bool endPtsCollocated1, const bool endPtsCollocated2,
797 const TData *in, const TData *NEK_RESTRICT trace,
798 TData *NEK_RESTRICT coef, TData *vol, TData *NEK_RESTRICT wsp0,
799 TData *NEK_RESTRICT wsp1, TData *NEK_RESTRICT lift0,
800 TData *NEK_RESTRICT lift1, [[maybe_unused]] unsigned char *shmemptr,
801 const TthreadBlock &threadBlock)
802{
803 const unsigned int nm0 = sizeParam3D.nm0();
804 const unsigned int nm1 = sizeParam3D.nm1();
805 const unsigned int nm2 = sizeParam3D.nm2();
806 const unsigned int nmTot = sizeParam3D.nmTot();
807 const unsigned int nq0 = sizeParam3D.nq0();
808 const unsigned int nq1 = sizeParam3D.nq1();
809 const unsigned int nq2 = sizeParam3D.nq2();
810 const unsigned int nqTot = nq0 * nq1 * nq2;
811
812 const unsigned int tnq00 = traceSizeParam3D.nq00();
813 const unsigned int tnq01 = traceSizeParam3D.nq01();
814 const unsigned int tnq10 = traceSizeParam3D.nq10();
815 const unsigned int tnq11 = traceSizeParam3D.nq11();
816 const unsigned int tnq20 = traceSizeParam3D.nq20();
817 const unsigned int tnq21 = traceSizeParam3D.nq21();
818 const unsigned int nqTotTrace =
819 traceSizeParam3D.template nqTotTrace<SHAPE_TYPE>();
820 const unsigned int numDataJac =
822
823 const unsigned int wsp0Size =
824 PhysLiftProjectStage0Size<SHAPE_TYPE, Implementation>(sizeParam3D);
825 const unsigned int wsp1Size =
826 PhysLiftProjectStage1Size<SHAPE_TYPE, Implementation>(sizeParam3D);
827 const unsigned int lift0Size =
828 IProductWRTPhysTraceFaceModeBlockSize(traceSizeParam3D);
829 const unsigned int lift1Size =
830 IProductWRTPhysTraceFaceScratchSize(traceSizeParam3D);
831
832 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
833
834 size_t e = getGlobalIdx<0>(threadBlock);
835 const unsigned int c = getBlockIdx<1>(threadBlock);
836 while (e < nelmt)
837 {
838 const size_t ilane = e % warpsize;
839 const size_t iwarp = e / warpsize;
840 const size_t slot = nelmt * c + warpsize * iwarp;
841 const TData *inptr = in + nqTot * slot;
842 TData *coefptr = coef + nmTot * slot;
843
844 TData *volptr = vol + nqTot * slot;
845 PhysLiftProjectCopyInKernel(ilane, nqTot, inptr, volptr);
846 if (lift)
847 {
848 IProductWRTPhysTrace3DFaceKernel<SHAPE_TYPE, false, true>(
849 ilane, nq0, nq1, nq2, nbasis0, nbasis1, nbasis2, tnq00, tnq01,
852 tw21, tjac + numDataJac * warpsize * iwarp,
853 lift0 + lift0Size * slot, lift1 + lift1Size * slot,
854 trace + nqTotTrace * slot, volptr, isCollocated00,
855 isCollocated01, isCollocated10, isCollocated11, isCollocated20,
856 isCollocated21, endPtsCollocated0, endPtsCollocated1,
857 endPtsCollocated2);
858 }
859 IProductWRTBase3DSumFacKernel<SHAPE_TYPE, false, false>(
860 ilane, nm0, nm1, nm2, nq0, nq1, nq2, isModified, basis0, basis1,
861 basis2, volptr, coefptr, wsp0 + wsp0Size * slot,
862 wsp1 + wsp1Size * slot, TData(1.0));
863
864 e += getGlobalRange<0>(threadBlock);
865 }
866}
867
868/**
869 * @brief The StdInvMass form with a dense standard inverse mass, after
870 * the product: `coef *= scale / J` in place and the backward transform
871 * into @p out, appending when @p APPEND, in one launch, one thread per
872 * element at warpSize. One dimension; see the three-dimensional overload.
873 */
874template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
875 bool APPEND, typename TSizeParameter1D,
876 typename TTraceSizeParameter1D, typename TthreadBlock, typename TData,
877 std::enable_if_t<std::is_same_v<Implementation, SumFac>, bool>
878 Enable = true>
880 (GetMaxThreadPerBlock<Implementation, TSizeParameter1D>()))
881 PhysLiftProjectScaleBwdTransKernelLauncher(
882 const TSizeParameter1D sizeParam1D,
883 [[maybe_unused]] const TTraceSizeParameter1D traceSizeParam1D,
884 const size_t nelmt, const TData scale,
885 [[maybe_unused]] const bool isModified,
886 const TData *NEK_RESTRICT basis0, const TData *NEK_RESTRICT jac,
887 TData *NEK_RESTRICT coef, TData *NEK_RESTRICT out,
888 [[maybe_unused]] unsigned char *shmemptr,
889 const TthreadBlock &threadBlock)
890{
891 const unsigned int nm0 = sizeParam1D.nm0();
892 const unsigned int nq0 = sizeParam1D.nq0();
893
894 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
895
896 size_t e = getGlobalIdx<0>(threadBlock);
897 const unsigned int c = getBlockIdx<1>(threadBlock);
898 while (e < nelmt)
899 {
900 const size_t ilane = e % warpsize;
901 const size_t iwarp = e / warpsize;
902 const size_t slot = nelmt * c + warpsize * iwarp;
903 TData *coefptr = coef + nm0 * slot;
904 TData *outptr = out + nq0 * slot;
905
906 const TData factor = SafeDivide(scale, jac[e]);
907 for (unsigned int m = 0; m < nm0; ++m)
908 {
909 coefptr[warpsize * m + ilane] *= factor;
910 }
911 BwdTransSegSumFacKernel<APPEND>(ilane, nm0, nq0, basis0, coefptr,
912 outptr);
913
914 e += getGlobalRange<0>(threadBlock);
915 }
916}
917
918/// The dense StdInvMass form after the product in two dimensions; see the
919/// three-dimensional overload.
920template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
921 bool APPEND, typename TSizeParameter2D,
922 typename TTraceSizeParameter2D, typename TthreadBlock, typename TData,
923 std::enable_if_t<std::is_same_v<Implementation, SumFac>, bool>
924 Enable = true>
926 (GetMaxThreadPerBlock<Implementation, TSizeParameter2D>()))
927 PhysLiftProjectScaleBwdTransKernelLauncher(
928 const TSizeParameter2D sizeParam2D,
929 [[maybe_unused]] const TTraceSizeParameter2D traceSizeParam2D,
930 const size_t nelmt, const TData scale, const bool isModified,
931 [[maybe_unused]] const unsigned int *NEK_RESTRICT index0,
932 const TData *NEK_RESTRICT basis0, const TData *NEK_RESTRICT basis1,
933 const TData *NEK_RESTRICT jac, TData *NEK_RESTRICT coef,
934 TData *NEK_RESTRICT out, TData *NEK_RESTRICT wsp0,
935 [[maybe_unused]] unsigned char *shmemptr,
936 const TthreadBlock &threadBlock)
937{
938 const unsigned int nm0 = sizeParam2D.nm0();
939 const unsigned int nm1 = sizeParam2D.nm1();
940 const unsigned int nmTot = sizeParam2D.nmTot();
941 const unsigned int nq0 = sizeParam2D.nq0();
942 const unsigned int nq1 = sizeParam2D.nq1();
943 const unsigned int nqTot = nq0 * nq1;
944
945 const unsigned int wsp0Size =
946 PhysLiftProjectStage0Size<SHAPE_TYPE, Implementation>(sizeParam2D);
947
948 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
949
950 size_t e = getGlobalIdx<0>(threadBlock);
951 const unsigned int c = getBlockIdx<1>(threadBlock);
952 while (e < nelmt)
953 {
954 const size_t ilane = e % warpsize;
955 const size_t iwarp = e / warpsize;
956 const size_t slot = nelmt * c + warpsize * iwarp;
957 TData *coefptr = coef + nmTot * slot;
958 TData *outptr = out + nqTot * slot;
959
960 const TData factor = SafeDivide(scale, jac[e]);
961 for (unsigned int m = 0; m < nmTot; ++m)
962 {
963 coefptr[warpsize * m + ilane] *= factor;
964 }
965 BwdTrans2DSumFacKernel<SHAPE_TYPE, APPEND>(
966 ilane, nm0, nm1, nq0, nq1, isModified, basis0, basis1, coefptr,
967 outptr, wsp0 + wsp0Size * slot);
968
969 e += getGlobalRange<0>(threadBlock);
970 }
971}
972
973/**
974 * @brief The StdInvMass form with a dense standard inverse mass, after
975 * the product, of a block of three-dimensional affine elements: each
976 * thread scales its element's coefficients in @p coef by `scale / J` in
977 * place and applies the backward transform into @p out, appending when
978 * @p APPEND, at warpSize.
979 */
980template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
981 bool APPEND, typename TSizeParameter3D,
982 typename TTraceSizeParameter3D, typename TthreadBlock, typename TData,
983 std::enable_if_t<std::is_same_v<Implementation, SumFac>, bool>
984 Enable = true>
986 (GetMaxThreadPerBlock<Implementation, TSizeParameter3D>()))
987 PhysLiftProjectScaleBwdTransKernelLauncher(
988 const TSizeParameter3D sizeParam3D,
989 [[maybe_unused]] const TTraceSizeParameter3D traceSizeParam3D,
990 const size_t nelmt, const TData scale, const bool isModified,
991 [[maybe_unused]] const unsigned int *NEK_RESTRICT index0,
992 [[maybe_unused]] const unsigned int *NEK_RESTRICT index1,
993 [[maybe_unused]] const unsigned int *NEK_RESTRICT index2,
994 [[maybe_unused]] const unsigned int *NEK_RESTRICT index3,
995 const TData *NEK_RESTRICT basis0, const TData *NEK_RESTRICT basis1,
996 const TData *NEK_RESTRICT basis2, const TData *NEK_RESTRICT jac,
997 TData *NEK_RESTRICT coef, TData *NEK_RESTRICT out,
998 TData *NEK_RESTRICT wsp0, TData *NEK_RESTRICT wsp1,
999 [[maybe_unused]] unsigned char *shmemptr,
1000 const TthreadBlock &threadBlock)
1001{
1002 const unsigned int nm0 = sizeParam3D.nm0();
1003 const unsigned int nm1 = sizeParam3D.nm1();
1004 const unsigned int nm2 = sizeParam3D.nm2();
1005 const unsigned int nmTot = sizeParam3D.nmTot();
1006 const unsigned int nq0 = sizeParam3D.nq0();
1007 const unsigned int nq1 = sizeParam3D.nq1();
1008 const unsigned int nq2 = sizeParam3D.nq2();
1009 const unsigned int nqTot = nq0 * nq1 * nq2;
1010
1011 const unsigned int wsp0Size =
1012 PhysLiftProjectStage0Size<SHAPE_TYPE, Implementation>(sizeParam3D);
1013 const unsigned int wsp1Size =
1014 PhysLiftProjectStage1Size<SHAPE_TYPE, Implementation>(sizeParam3D);
1015
1016 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
1017
1018 size_t e = getGlobalIdx<0>(threadBlock);
1019 const unsigned int c = getBlockIdx<1>(threadBlock);
1020 while (e < nelmt)
1021 {
1022 const size_t ilane = e % warpsize;
1023 const size_t iwarp = e / warpsize;
1024 const size_t slot = nelmt * c + warpsize * iwarp;
1025 TData *coefptr = coef + nmTot * slot;
1026 TData *outptr = out + nqTot * slot;
1027
1028 const TData factor = SafeDivide(scale, jac[e]);
1029 for (unsigned int m = 0; m < nmTot; ++m)
1030 {
1031 coefptr[warpsize * m + ilane] *= factor;
1032 }
1033 BwdTrans3DSumFacKernel<SHAPE_TYPE, APPEND>(
1034 ilane, nm0, nm1, nm2, nq0, nq1, nq2, isModified, basis0, basis1,
1035 basis2, coefptr, outptr, wsp0 + wsp0Size * slot,
1036 wsp1 + wsp1Size * slot);
1037
1038 e += getGlobalRange<0>(threadBlock);
1039 }
1040}
1041
1042/**
1043 * @brief The factor `scale / (w J)` of the Pointwise form at point @p pt of
1044 * element @p e, whose point index is @p i; zero on the padding elements,
1045 * whose Jacobian is zero. The weight is read once per point, the same for
1046 * every lane.
1047 */
1048template <bool DEFORMED, typename TData>
1049NEK_DEVICE_INLINE static TData PhysLiftProjectDirectLiftFactorKernel(
1050 const size_t i, const size_t e, const unsigned int pt, const TData scale,
1051 const TData *NEK_RESTRICT weights, const TData *NEK_RESTRICT jac)
1052{
1053 TData jacobian;
1054 if constexpr (DEFORMED)
1055 {
1056 jacobian = jac[i];
1057 }
1058 else
1059 {
1060 jacobian = jac[e];
1061 }
1062 return SafeDivide(scale, weights[pt] * jacobian);
1063}
1064
1065/// `out[ientry] (+)= factor * val`.
1066template <bool APPEND, typename TData>
1067NEK_DEVICE_INLINE static void PhysLiftProjectDirectLiftStoreKernel(
1068 TData *out, const size_t ientry, const TData factor, const TData val)
1069{
1070 if constexpr (APPEND)
1071 {
1072 out[ientry] += factor * val;
1073 }
1074 else
1075 {
1076 out[ientry] = factor * val;
1077 }
1078}
1079
1080/**
1081 * @brief The lift of the traces of a one-point element onto its point: the
1082 * sum over its traces, in the packed order, of each trace's integral of the
1083 * trace values times its Jacobian, times the end-point interpolant of the
1084 * point along the trace's normal direction. A one-point direction's
1085 * interpolant onto the trace points is one, so no in-trace interpolant is
1086 * applied.
1087 *
1088 * @tparam SHAPE_TYPE Tri, Tet, Prism or Pyr.
1089 * @tparam DEFORMED The trace Jacobians are per trace point.
1090 *
1091 * @param tnq Trace points of a trace in each normal direction and
1092 * in-trace direction, `tnq[2 * d + t]` (`tnq[d]` in two
1093 * dimensions, one in-trace direction).
1094 * @param nbasis End-point interpolant of each direction, one row.
1095 * @param tw In-trace weights, in the order of @p tnq.
1096 * @param tjacptr The element's trace Jacobians, at its lane.
1097 * @param traceptr The element's trace values of the component, at its
1098 * lane.
1099 */
1100template <LibUtilities::ShapeType SHAPE_TYPE, bool DEFORMED, typename TData>
1101NEK_DEVICE_INLINE static TData PhysLiftProjectOnePointLiftKernel(
1102 const unsigned int *tnq, const TData *const *nbasis, const TData *const *tw,
1103 const TData *NEK_RESTRICT tjacptr, const TData *NEK_RESTRICT traceptr)
1104{
1105 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
1106 constexpr unsigned int dim = LibUtilities::ShapeTypeDimMap[SHAPE_TYPE];
1107 // The traces of each direction, taken at compile time: the host table
1108 // cannot be indexed at run time in device code.
1109 constexpr unsigned int nface0 =
1111 constexpr unsigned int nface1 =
1113 constexpr unsigned int nface2 =
1115 const unsigned int nfaces[3] = {nface0, nface1, nface2};
1116 TData lift = 0.0;
1117 unsigned int k = 0;
1118 unsigned int iface = 0;
1119#pragma unroll
1120 for (unsigned int d = 0; d < dim; ++d)
1121 {
1122 const unsigned int tnq0 = (dim == 3) ? tnq[2 * d] : tnq[d];
1123 const unsigned int tnq1 = (dim == 3) ? tnq[2 * d + 1] : 1u;
1124 const TData *tw0 = (dim == 3) ? tw[2 * d] : tw[d];
1125 const TData *tw1 = (dim == 3) ? tw[2 * d + 1] : nullptr;
1126#pragma unroll
1127 for (unsigned int f = 0; f < nfaces[d]; ++f, ++iface)
1128 {
1129 TData sum = 0.0;
1130 for (unsigned int j = 0; j < tnq1; ++j)
1131 {
1132 for (unsigned int i = 0; i < tnq0; ++i, ++k)
1133 {
1134 TData faceJac;
1135 if constexpr (DEFORMED)
1136 {
1137 faceJac = tjacptr[warpsize * k];
1138 }
1139 else
1140 {
1141 faceJac = tjacptr[warpsize * iface];
1142 }
1143 TData val = traceptr[warpsize * k] * faceJac * tw0[i];
1144 if (dim == 3)
1145 {
1146 val *= tw1[j];
1147 }
1148 sum += val;
1149 }
1150 }
1151 lift += sum * nbasis[d][f];
1152 }
1153 }
1154 return lift;
1155}
1156
1157/**
1158 * @brief The Pointwise form of a block of segments on SumFac, the trace
1159 * lifted directly onto every point: `out (+)= scale / (w J) * (in + h_0(p)
1160 * g_0 + h_1(p) g_1)`. See the three-dimensional launcher; a segment's
1161 * traces are points, with no Jacobian or weight, and @p tjac is not read.
1162 *
1163 * One thread per volume point of each element, over every component, the
1164 * block at warpSize: thread `i = warpSize * (nqTot * iwarp + pt) + ilane`
1165 * takes point @em pt of element `warpSize * iwarp + ilane`, so that
1166 * consecutive threads take the same point of consecutive elements. A thread
1167 * block is a warp, as in the other SumFac kernels.
1168 */
1169template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
1170 bool APPEND, bool DEFORMED, typename TTraceSizeParameter1D,
1171 typename TthreadBlock, typename TData,
1172 std::enable_if_t<std::is_same_v<Implementation, SumFac>, bool>
1173 Enable = true>
1175 (GetMaxThreadPerBlock<Implementation, TTraceSizeParameter1D>()))
1176 PhysLiftProjectDirectLiftKernelLauncher(
1177 const TTraceSizeParameter1D traceSizeParam1D, const size_t nelmt,
1178 const unsigned int ncomp, const TData scale, const bool lift,
1179 const TData *NEK_RESTRICT nbasis0,
1180 [[maybe_unused]] const TData *NEK_RESTRICT tjac,
1181 const TData *NEK_RESTRICT weights, const TData *NEK_RESTRICT jac,
1182 const TData *in, const TData *NEK_RESTRICT trace, TData *out,
1183 const TthreadBlock &threadBlock)
1184{
1185 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
1186 const unsigned int nqTot = traceSizeParam1D.nm0();
1187 const size_t compSize = static_cast<size_t>(nqTot) * nelmt;
1188 const size_t compTraceSize = 2u * nelmt;
1189
1190 for (size_t i = getGlobalIdx(threadBlock); i < compSize;
1191 i += getGlobalRange(threadBlock))
1192 {
1193 // Point index i = warpsize * (nqTot * iwarp + p) + ilane: point p of
1194 // element warpsize * iwarp + ilane, lanes first.
1195 const unsigned int ilane = i % warpsize;
1196 const size_t ipoint = i / warpsize;
1197 const size_t iwarp = ipoint / nqTot;
1198 const unsigned int p = ipoint % nqTot;
1199 const size_t e = warpsize * iwarp + ilane;
1200
1201 const TData factor = PhysLiftProjectDirectLiftFactorKernel<DEFORMED>(
1202 i, e, p, scale, weights, jac);
1203 const TData h0 = nbasis0[2u * p];
1204 const TData h1 = nbasis0[2u * p + 1u];
1205
1206 const size_t traceOffset = 2u * warpsize * iwarp + ilane;
1207 for (unsigned int c = 0; c < ncomp; ++c)
1208 {
1209 const size_t ientry = compSize * c + i;
1210 TData val = in[ientry];
1211 if (lift)
1212 {
1213 const TData *traceptr = trace + compTraceSize * c + traceOffset;
1214 val += h0 * traceptr[0] + h1 * traceptr[warpsize];
1215 }
1216 PhysLiftProjectDirectLiftStoreKernel<APPEND>(out, ientry, factor,
1217 val);
1218 }
1219 }
1220}
1221
1222/**
1223 * @brief The Pointwise form of a block of two-dimensional elements on SumFac,
1224 * the trace lifted directly onto every point. See the three-dimensional
1225 * launcher: quadrilaterals whose edges have the volume points, each point
1226 * adding its four edges' contributions (the two direction-0 edges, then the
1227 * two direction-1 edges), and triangles of one point.
1228 *
1229 * One thread per volume point of each element, over every component, the
1230 * block at warpSize: thread `i = warpSize * (nqTot * iwarp + pt) + ilane`
1231 * takes point @em pt of element `warpSize * iwarp + ilane`, so that
1232 * consecutive threads take the same point of consecutive elements. A thread
1233 * block is a warp, as in the other SumFac kernels.
1234 */
1235template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
1236 bool APPEND, bool DEFORMED, typename TTraceSizeParameter2D,
1237 typename TthreadBlock, typename TData,
1238 std::enable_if_t<std::is_same_v<Implementation, SumFac>, bool>
1239 Enable = true>
1241 (GetMaxThreadPerBlock<Implementation, TTraceSizeParameter2D>()))
1242 PhysLiftProjectDirectLiftKernelLauncher(
1243 const TTraceSizeParameter2D traceSizeParam2D, const size_t nelmt,
1244 const unsigned int ncomp, const TData scale, const bool lift,
1245 const TData *NEK_RESTRICT nbasis0, const TData *NEK_RESTRICT nbasis1,
1246 const TData *NEK_RESTRICT tw00, const TData *NEK_RESTRICT tw10,
1247 const TData *NEK_RESTRICT tjac, const TData *NEK_RESTRICT weights,
1248 const TData *NEK_RESTRICT jac, const TData *in,
1249 const TData *NEK_RESTRICT trace, TData *out,
1250 const TthreadBlock &threadBlock)
1251{
1252 static_assert(SHAPE_TYPE == LibUtilities::Quad ||
1253 SHAPE_TYPE == LibUtilities::Tri,
1254 "The direct lift takes quadrilaterals and triangles.");
1255
1256 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
1257 constexpr bool isCollapsed = SHAPE_TYPE != LibUtilities::Quad;
1258 constexpr unsigned int nedge = LibUtilities::ShapeTypeNumTraces[SHAPE_TYPE];
1259
1260 // The trace size parameter's nm0() and nm1() are the volume quadrature
1261 // point counts here (#m_nm), as in the trace operators.
1262 const unsigned int nq0 = traceSizeParam2D.nm0();
1263 const unsigned int nq1 = traceSizeParam2D.nm1();
1264 const unsigned int nqTot = nq0 * nq1;
1265 const unsigned int nqTotTrace =
1266 traceSizeParam2D.template nqTotTrace<SHAPE_TYPE>();
1267 const unsigned int numDataJac = DEFORMED ? nqTotTrace : nedge;
1268
1269 const size_t compSize = static_cast<size_t>(nqTot) * nelmt;
1270 const size_t compTraceSize = static_cast<size_t>(nqTotTrace) * nelmt;
1271
1272 for (size_t i = getGlobalIdx(threadBlock); i < compSize;
1273 i += getGlobalRange(threadBlock))
1274 {
1275 // Point index i = warpsize * (nqTot * iwarp + pt) + ilane: point pt of
1276 // element warpsize * iwarp + ilane, lanes first.
1277 const unsigned int ilane = i % warpsize;
1278 const size_t ipoint = i / warpsize;
1279 const size_t iwarp = ipoint / nqTot;
1280 const unsigned int pt = ipoint % nqTot;
1281 const size_t e = warpsize * iwarp + ilane;
1282
1283 const TData factor = PhysLiftProjectDirectLiftFactorKernel<DEFORMED>(
1284 i, e, pt, scale, weights, jac);
1285 const TData *tjacptr = tjac + numDataJac * warpsize * iwarp + ilane;
1286 const size_t traceOffset =
1287 static_cast<size_t>(nqTotTrace) * warpsize * iwarp + ilane;
1288
1289 if constexpr (!isCollapsed)
1290 {
1291 // The point of each edge beside this point, the edge's weight
1292 // there and the end-point interpolant along its normal.
1293 const unsigned int p = pt % nq0;
1294 const unsigned int q = pt / nq0;
1295 const unsigned int k[nedge] = {q, nq1 + q, 2u * nq1 + p,
1296 2u * nq1 + nq0 + p};
1297 const TData w[nedge] = {tw00[q], tw00[q], tw10[p], tw10[p]};
1298 const TData h[nedge] = {nbasis0[2u * p], nbasis0[2u * p + 1u],
1299 nbasis1[2u * q], nbasis1[2u * q + 1u]};
1300 // Each edge's factor, formed once for every component.
1301 TData coef[nedge];
1302#pragma unroll
1303 for (unsigned int iedge = 0; iedge < nedge; ++iedge)
1304 {
1305 TData edgeJac;
1306 if constexpr (DEFORMED)
1307 {
1308 edgeJac = tjacptr[warpsize * k[iedge]];
1309 }
1310 else
1311 {
1312 edgeJac = tjacptr[warpsize * iedge];
1313 }
1314 coef[iedge] = edgeJac * w[iedge] * h[iedge];
1315 }
1316 for (unsigned int c = 0; c < ncomp; ++c)
1317 {
1318 const size_t ientry = compSize * c + i;
1319 TData val = in[ientry];
1320 if (lift)
1321 {
1322 const TData *traceptr =
1323 trace + compTraceSize * c + traceOffset;
1324#pragma unroll
1325 for (unsigned int iedge = 0; iedge < nedge; ++iedge)
1326 {
1327 val += traceptr[warpsize * k[iedge]] * coef[iedge];
1328 }
1329 }
1330 PhysLiftProjectDirectLiftStoreKernel<APPEND>(out, ientry,
1331 factor, val);
1332 }
1333 }
1334 else
1335 {
1336 const unsigned int tnq[2] = {traceSizeParam2D.nq00(),
1337 traceSizeParam2D.nq10()};
1338 const TData *nbasis[2] = {nbasis0, nbasis1};
1339 const TData *tw[2] = {tw00, tw10};
1340 for (unsigned int c = 0; c < ncomp; ++c)
1341 {
1342 const size_t ientry = compSize * c + i;
1343 TData val = in[ientry];
1344 if (lift)
1345 {
1346 val +=
1347 PhysLiftProjectOnePointLiftKernel<SHAPE_TYPE, DEFORMED>(
1348 tnq, nbasis, tw, tjacptr,
1349 trace + compTraceSize * c + traceOffset);
1350 }
1351 PhysLiftProjectDirectLiftStoreKernel<APPEND>(out, ientry,
1352 factor, val);
1353 }
1354 }
1355 }
1356}
1357
1358/**
1359 * @brief The Pointwise form of a block of three-dimensional elements on SumFac,
1360 * the trace lifted directly onto every point, over every component: `out
1361 * (+)= scale / (w J) * (in + L g)`, zero on the padding elements, whose
1362 * Jacobian is zero.
1363 *
1364 * @details
1365 * Hexahedra whose faces have the volume points in both in-face directions:
1366 * the lift of face @em f onto volume point (p, q, r) is then the face's
1367 * value at the point beside it, times the face's Jacobian there, its two
1368 * in-face weights there and the end-point interpolant of the point along
1369 * the face's normal direction, \f$h(\pm 1)\f$, a delta where the rule has
1370 * its end points. Each point adds its six faces' contributions directly,
1371 * with no scratch and no zeroing of a volume field, in the packed trace
1372 * order (direction 0's low and high faces, then direction 1's and
1373 * direction 2's: the hexahedron's faces 4, 2, 1, 3, 0 and 5), each formed as
1374 * the face-by-face lift of IProductWRTPhysTrace forms it.
1375 *
1376 * Tetrahedra, prisms and pyramids of one point: every face contributes its
1377 * integral of the trace values times its Jacobian, times the one-point
1378 * end-point interpolant (PhysLiftProjectOnePointLiftKernel()).
1379 *
1380 * Element `e = warpSize * iwarp + ilane` has its point @em pt at
1381 * `nqTot * (nelmt * c + warpSize * iwarp) + warpSize * pt + ilane` in
1382 * component @em c, which is `nqTot * nelmt * c + i` for the point's index
1383 * `i = warpSize * (nqTot * iwarp + pt) + ilane`: consecutive threads take
1384 * the same point of consecutive elements, so every read of a point, a trace
1385 * value or a Jacobian is coalesced across the lanes. Its trace values are
1386 * at `nqTotTrace * (nelmt * c + warpSize * iwarp) + warpSize * k + ilane`
1387 * for trace point @em k, the faces packed as above and each face's points
1388 * in its in-face directions in the volume's order. A thread block is a
1389 * warp, as in the other SumFac kernels.
1390 *
1391 * @tparam SHAPE_TYPE Hex, Tet, Prism or Pyr.
1392 * @tparam APPEND Accumulate onto @p out.
1393 * @tparam DEFORMED The Jacobians are per point.
1394 *
1395 * @param traceSizeParam3D Volume point counts per direction (nm0(),
1396 * nm1(), nm2()) and trace point counts per face
1397 * pair.
1398 * @param nelmt Elements in the block, including padding.
1399 * @param ncomp Components (times homogeneous modes) of the block.
1400 * @param scale Factor the result is scaled by.
1401 * @param lift Lift @p trace; without it only the scale is applied.
1402 * @param nbasis0,nbasis1,nbasis2 End-point interpolant of each
1403 * direction, `nbasis[p * ntrace + side]`.
1404 * @param tw00,tw01,tw10,tw11,tw20,tw21 Weights of each face pair's
1405 * in-face directions (FetchTraceTables()).
1406 * @param tjac Trace Jacobians (JacobianLocTraceKey at warpSize), one
1407 * per face, or one per trace point when @p DEFORMED.
1408 * @param weights Quadrature weights at every point (WeightsKey at width
1409 * one), the same for every lane.
1410 * @param jac Jacobians (JacobianKey at warpSize), one per element,
1411 * or one per point when @p DEFORMED.
1412 * @param in Inner products; may be @p out.
1413 * @param trace Element-local trace values.
1414 * @param out Result.
1415 * @param threadBlock The thread block.
1416 */
1417template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
1418 bool APPEND, bool DEFORMED, typename TTraceSizeParameter3D,
1419 typename TthreadBlock, typename TData,
1420 std::enable_if_t<std::is_same_v<Implementation, SumFac>, bool>
1421 Enable = true>
1423 (GetMaxThreadPerBlock<Implementation, TTraceSizeParameter3D>()))
1424 PhysLiftProjectDirectLiftKernelLauncher(
1425 const TTraceSizeParameter3D traceSizeParam3D, const size_t nelmt,
1426 const unsigned int ncomp, const TData scale, const bool lift,
1427 const TData *NEK_RESTRICT nbasis0, const TData *NEK_RESTRICT nbasis1,
1428 const TData *NEK_RESTRICT nbasis2, const TData *NEK_RESTRICT tw00,
1429 const TData *NEK_RESTRICT tw01, const TData *NEK_RESTRICT tw10,
1430 const TData *NEK_RESTRICT tw11, const TData *NEK_RESTRICT tw20,
1431 const TData *NEK_RESTRICT tw21, const TData *NEK_RESTRICT tjac,
1432 const TData *NEK_RESTRICT weights, const TData *NEK_RESTRICT jac,
1433 const TData *in, const TData *NEK_RESTRICT trace, TData *out,
1434 const TthreadBlock &threadBlock)
1435{
1436 static_assert(SHAPE_TYPE == LibUtilities::Hex ||
1437 SHAPE_TYPE == LibUtilities::Tet ||
1438 SHAPE_TYPE == LibUtilities::Prism ||
1439 SHAPE_TYPE == LibUtilities::Pyr,
1440 "The direct lift takes hexahedra, tetrahedra, prisms and "
1441 "pyramids.");
1442
1443 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
1444 constexpr bool isCollapsed = SHAPE_TYPE != LibUtilities::Hex;
1445 constexpr unsigned int nface = LibUtilities::ShapeTypeNumTraces[SHAPE_TYPE];
1446
1447 // The trace size parameter's nm0()..nm2() are the volume quadrature
1448 // point counts here (#m_nm), as in the trace operators.
1449 const unsigned int nq0 = traceSizeParam3D.nm0();
1450 const unsigned int nq1 = traceSizeParam3D.nm1();
1451 const unsigned int nq2 = traceSizeParam3D.nm2();
1452 const unsigned int nq01 = nq0 * nq1;
1453 const unsigned int nqTot = nq01 * nq2;
1454 const unsigned int nqTotTrace =
1455 traceSizeParam3D.template nqTotTrace<SHAPE_TYPE>();
1456 const unsigned int numDataJac = DEFORMED ? nqTotTrace : nface;
1457
1458 const size_t compSize = static_cast<size_t>(nqTot) * nelmt;
1459 const size_t compTraceSize = static_cast<size_t>(nqTotTrace) * nelmt;
1460
1461 for (size_t i = getGlobalIdx(threadBlock); i < compSize;
1462 i += getGlobalRange(threadBlock))
1463 {
1464 // Point index i = warpsize * (nqTot * iwarp + pt) + ilane: point pt of
1465 // element warpsize * iwarp + ilane, lanes first.
1466 const unsigned int ilane = i % warpsize;
1467 const size_t ipoint = i / warpsize;
1468 const size_t iwarp = ipoint / nqTot;
1469 const unsigned int pt = ipoint % nqTot;
1470 const size_t e = warpsize * iwarp + ilane;
1471
1472 const TData factor = PhysLiftProjectDirectLiftFactorKernel<DEFORMED>(
1473 i, e, pt, scale, weights, jac);
1474 const TData *tjacptr = tjac + numDataJac * warpsize * iwarp + ilane;
1475 const size_t traceOffset =
1476 static_cast<size_t>(nqTotTrace) * warpsize * iwarp + ilane;
1477
1478 if constexpr (!isCollapsed)
1479 {
1480 const unsigned int p = pt % nq0;
1481 const unsigned int q = (pt / nq0) % nq1;
1482 const unsigned int r = pt / nq01;
1483
1484 // The point of each face beside this point, the face's in-face
1485 // weights there and the end-point interpolant along its normal.
1486 const unsigned int fsz0 = nq1 * nq2;
1487 const unsigned int fsz1 = nq0 * nq2;
1488 const unsigned int off1 = 2u * fsz0;
1489 const unsigned int off2 = off1 + 2u * fsz1;
1490 const unsigned int k[nface] = {
1491 r * nq1 + q, fsz0 + r * nq1 + q,
1492 off1 + r * nq0 + p, off1 + fsz1 + r * nq0 + p,
1493 off2 + q * nq0 + p, off2 + nq01 + q * nq0 + p};
1494 const TData w0[nface] = {tw00[q], tw00[q], tw10[p],
1495 tw10[p], tw20[p], tw20[p]};
1496 const TData w1[nface] = {tw01[r], tw01[r], tw11[r],
1497 tw11[r], tw21[q], tw21[q]};
1498 const TData h[nface] = {nbasis0[2u * p], nbasis0[2u * p + 1u],
1499 nbasis1[2u * q], nbasis1[2u * q + 1u],
1500 nbasis2[2u * r], nbasis2[2u * r + 1u]};
1501 // Each face's factor, formed once for every component.
1502 TData coef[nface];
1503#pragma unroll
1504 for (unsigned int iface = 0; iface < nface; ++iface)
1505 {
1506 TData faceJac;
1507 if constexpr (DEFORMED)
1508 {
1509 faceJac = tjacptr[warpsize * k[iface]];
1510 }
1511 else
1512 {
1513 faceJac = tjacptr[warpsize * iface];
1514 }
1515 coef[iface] = faceJac * w0[iface] * w1[iface] * h[iface];
1516 }
1517 for (unsigned int c = 0; c < ncomp; ++c)
1518 {
1519 const size_t ientry = compSize * c + i;
1520 TData val = in[ientry];
1521 if (lift)
1522 {
1523 const TData *traceptr =
1524 trace + compTraceSize * c + traceOffset;
1525#pragma unroll
1526 for (unsigned int iface = 0; iface < nface; ++iface)
1527 {
1528 val += traceptr[warpsize * k[iface]] * coef[iface];
1529 }
1530 }
1531 PhysLiftProjectDirectLiftStoreKernel<APPEND>(out, ientry,
1532 factor, val);
1533 }
1534 }
1535 else
1536 {
1537 const unsigned int tnq[6] = {
1538 traceSizeParam3D.nq00(), traceSizeParam3D.nq01(),
1539 traceSizeParam3D.nq10(), traceSizeParam3D.nq11(),
1540 traceSizeParam3D.nq20(), traceSizeParam3D.nq21()};
1541 const TData *nbasis[3] = {nbasis0, nbasis1, nbasis2};
1542 const TData *tw[6] = {tw00, tw01, tw10, tw11, tw20, tw21};
1543 for (unsigned int c = 0; c < ncomp; ++c)
1544 {
1545 const size_t ientry = compSize * c + i;
1546 TData val = in[ientry];
1547 if (lift)
1548 {
1549 val +=
1550 PhysLiftProjectOnePointLiftKernel<SHAPE_TYPE, DEFORMED>(
1551 tnq, nbasis, tw, tjacptr,
1552 trace + compTraceSize * c + traceOffset);
1553 }
1554 PhysLiftProjectDirectLiftStoreKernel<APPEND>(out, ientry,
1555 factor, val);
1556 }
1557 }
1558 }
1559}
1560
1561#endif
1562
1563} // namespace Nektar::MultiRegions::detail
#define NEK_RESTRICT
Definition Backends.hpp:254
#define NEK_DEVICE_INLINE
Definition Backends.hpp:283
#define NEK_HOSTDEVICE_INLINE
Definition Backends.hpp:268
#define NEK_DEVICE_KERNEL
Definition Backends.hpp:297
Device SumFac kernels of the backward transform: one element per thread, with the sum-factorisation i...
Block-level base class, implementation-strategy tags and device launch helpers shared by every elemen...
Device SumFac kernels of the inner product with the basis: one element per thread,...
Device kernels of the trace inner product: one element per warp lane.
Per-block interface of the PhysLiftProject element operator, and the choice of its form for a block.
std::map< int64_t, double > sum
constexpr unsigned int ShapeTypeNumTraceInDir[SIZE_ShapeType][3]
constexpr unsigned int ShapeTypeNumTraces[SIZE_ShapeType]
constexpr unsigned int ShapeTypeDimMap[SIZE_ShapeType]
Definition ShapeType.hpp:89
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 __LAUNCH_BOUNDS__((GetMaxThreadPerBlock< Implementation, TTraceSizeParameter1D >())) IProductWRTPhysNormalDerivTraceKernelLauncher(const TTraceSizeParameter1D sizeParam1D
The one-dimensional lift: over a segment's two vertices, one lane per element.
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT 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 TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT tw10
static NEK_FORCE_INLINE void PhysLiftProjectPointwiseKernel(const unsigned int nqTot, const simd_type *pointScale, const simd_type *vol, simd_type *out)
The Pointwise form of one element group: out (+)= pointScale * vol.
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT 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 tbasis00
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 numDataJac
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 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 TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT tw1
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT 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 TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT tw21
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT 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 TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT tw20
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 TData *NEK_RESTRICT const TData *NEK_RESTRICT 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 TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT tw11
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT 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 TData *NEK_RESTRICT tbasis10
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 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 tbasis1
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT 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 TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT tw00
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT nbasis1
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT 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 TData *NEK_RESTRICT const TData *NEK_RESTRICT tbasis11
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 endPtsCollocated0
PhysLiftProjectKernel
Which of the Device fused kernels of the StdInvMass form a shared-memory size is for.
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 jac
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT 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 tbasis01
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT 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 TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT tbasis20
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT 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 TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT tbasis21
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT 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 tbasis0
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 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 TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT tw0
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
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT 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 TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT tw01
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TData *NEK_RESTRICT nbasis2
std::vector< double > p(NPUPPER)
std::vector< double > d(NPUPPER *NPUPPER)
NEK_HOSTDEVICE_INLINE TData SafeDivide(const TData &num, const TData &den)
num / den, and zero where den is zero.
static constexpr unsigned int warpSize
Definition Backends.hpp:143