48#if defined(NEKTAR_ENABLE_DEVICE) && defined(DEVICE_COMPILE_ONLY)
57 typename TPhysSizeParameter1D,
58 std::enable_if_t<std::is_same_v<Implementation, SumFac> &&
59 IsPhysSizeParameter1D_v<TPhysSizeParameter1D>,
63 const size_t nelmt,
const unsigned int ncoord,
const unsigned int ncomp,
64 const TPhysSizeParameter1D sizeParam1D,
65 [[maybe_unused]]
const bool localPipeline)
67 const unsigned int nq0 = sizeParam1D.nq0();
68 const unsigned int nq0Fine = 3u * nq0 / 2u;
70 return (ncomp * ncoord * nq0 +
71 (ncoord + ncomp * ncoord + ncomp) * nq0Fine) *
76 typename TPhysSizeParameter2D,
77 std::enable_if_t<std::is_same_v<Implementation, SumFac> &&
78 IsPhysSizeParameter2D_v<TPhysSizeParameter2D>,
82 const size_t nelmt,
const unsigned int ncoord,
const unsigned int ncomp,
83 const TPhysSizeParameter2D sizeParam2D,
84 [[maybe_unused]]
const bool localPipeline)
86 const unsigned int nq0 = sizeParam2D.nq0();
87 const unsigned int nq0Fine = 3u * nq0 / 2u;
89 const unsigned int nq1 = sizeParam2D.nq1();
90 const unsigned int nq1Fine =
91 (nq0 - nq1 == 1u) ? nq0Fine - 1u : 3u * nq1 / 2u;
93 return (ncomp * ncoord * sizeParam2D.nqTot() +
94 (ncoord + ncomp * ncoord + ncomp) * nq0Fine * nq1Fine +
100 typename TPhysSizeParameter3D,
101 std::enable_if_t<std::is_same_v<Implementation, SumFac> &&
102 IsPhysSizeParameter3D_v<TPhysSizeParameter3D>,
106 const size_t nelmt,
const unsigned int ncoord,
const unsigned int ncomp,
107 const TPhysSizeParameter3D sizeParam3D,
108 [[maybe_unused]]
const bool localPipeline)
110 const unsigned int nq0 = sizeParam3D.nq0();
111 const unsigned int nq0Fine = 3u * nq0 / 2u;
113 const unsigned int nq1 = sizeParam3D.nq1();
114 const unsigned int nq2 = sizeParam3D.nq2();
115 const unsigned int nq1Fine =
116 (nq0 - nq1 == 1u) ? nq0Fine - 1u : 3u * nq1 / 2u;
117 const unsigned int nq2Fine =
118 (nq0 - nq2 == 1u) ? nq0Fine - 1u : 3u * nq2 / 2u;
120 return (ncomp * ncoord * sizeParam3D.nqTot() +
121 (ncoord + ncomp * ncoord + ncomp) * nq0Fine * nq1Fine * nq2Fine +
122 (nq1 * nq2 + nq1Fine * nq2Fine) + (nq2 + nq2Fine)) *
130 typename TPhysSizeParameter,
131 std::enable_if_t<std::is_same_v<Implementation, SumFac>,
bool>
134 [[maybe_unused]]
const TPhysSizeParameter sizeParam,
135 [[maybe_unused]]
const bool localPipeline,
136 [[maybe_unused]]
const bool sharedScratch)
146 typename TPhysSizeParameter,
147 std::enable_if_t<std::is_same_v<Implementation, SumFac>,
bool>
149inline constexpr unsigned int AdvectionDealiasSharedMemorySize(
150 const unsigned int ncoord,
const unsigned int ncomp,
151 const TPhysSizeParameter sizeParam,
const unsigned int elmtsPerBlock,
152 const bool localPipeline, [[maybe_unused]]
const bool sharedScratch,
155 const unsigned int wspSize =
157 ?
static_cast<unsigned int>(
158 AdvectionDealiasWorkSpaceSize<SHAPE_TYPE, Implementation>(
162 return PhysDerivSharedMemorySize<SHAPE_TYPE, Implementation>(
169template <
bool APPEND,
typename TData>
171 const unsigned int ilane,
const unsigned int nqTot,
172 const unsigned int coordDim,
const TData *
NEK_RESTRICT advVel,
178 for (
unsigned int j = 0u; j < nqTot; ++j)
182 for (
unsigned int d = 1u;
d < coordDim; ++
d)
188 tmp += advVel[
d * advVelOffset +
warpsize * j + ilane] *
192 if constexpr (APPEND)
204 bool APPEND,
bool DEFORMED,
bool LOCAL_PIPELINE,
bool SHARED_SCRATCH,
205 typename TPhysSizeParameter1D,
typename TthreadBlock,
typename TData,
206 typename TUseSharedWsp,
207 std::enable_if_t<std::is_same_v<Implementation, SumFac>,
bool>
210 const TPhysSizeParameter1D sizeParam1D,
const size_t nelmt,
211 [[maybe_unused]]
const unsigned int elmtsPerBlock,
const unsigned int ncomp,
215 const TData scale,
const TData *
NEK_RESTRICT in,
const size_t inCompStride,
216 const TData *
NEK_RESTRICT advVel,
const size_t advVelPlaneStride,
222 IsPhysSizeParameter1D_v<TPhysSizeParameter1D>,
223 "Template argument must be either of type "
224 "NonTemplatedPhysSizeParameter1D or TemplatedPhysSizeParameter1D.");
228 const unsigned int coordDim = sizeParam1D.ncoord();
229 const unsigned int nq0 = sizeParam1D.nq0();
230 const unsigned int nqTot = sizeParam1D.nqTot();
231 const unsigned int nq0Fine = 3u * nq0 / 2u;
234 const unsigned int nqTotFine = nq0Fine;
235 const unsigned int dfsize = DEFORMED ? nqTot : 1u;
237 const size_t advVelCompStride = advVelPlaneStride * nhomo;
240 const unsigned int wspSize =
static_cast<unsigned int>(
241 AdvectionDealiasWorkSpaceSize<SHAPE_TYPE, Implementation>(
242 1u, coordDim, ncomp, sizeParam1D, LOCAL_PIPELINE));
246 TData *wspbase = isShared ? (TData *)
shmemptr : elmtWsp;
255 const TData *dfptr = df + coordDim * dfsize *
warpsize * iwarp;
256 const TData *inGroup =
in + nqTot *
warpsize * iwarp;
257 const TData *advVelGroup =
258 advVel +
p * advVelPlaneStride + nqTot *
warpsize * iwarp;
264 const size_t wspOffset =
266 TData *
wsp = wspbase + wspSize * wspOffset;
267 TData *derivGroup =
wsp;
268 TData *fineGroup = derivGroup + ncomp * coordDim * nqTot *
warpsize;
269 TData *combinedGroup = fineGroup + (coordDim + ncomp * coordDim) *
272 for (
unsigned int d = 0u;
d < coordDim; ++
d)
274 BwdTransSegSumFacKernel<false>(
275 ilane, nq0, nq0Fine, Binterp0,
276 advVelGroup + d * advVelCompStride,
277 fineGroup + d * nqTotFine *
warpsize);
283 for (
unsigned int c = 0u;
c < ncomp; ++
c)
285 TData *derivOut = derivGroup +
c * coordDim * nqTot *
warpsize;
286 TData *gradFine = fineGroup + (coordDim +
c * coordDim) *
288 TData *combinedOut = combinedGroup +
c * nqTotFine *
warpsize;
290 PhysDeriv1DSumFacKernel<DEFORMED>(
291 ilane, coordDim, nq0, nqTot *
warpsize, D0, dfptr,
292 inGroup + (
c * nhomo + p) * inCompStride, derivOut);
294 for (
unsigned int d = 0u;
d < coordDim; ++
d)
296 BwdTransSegSumFacKernel<false>(
297 ilane, nq0, nq0Fine, Binterp0,
299 gradFine + d * nqTotFine *
warpsize);
302 AdvectionDealiasCombineSumFacKernel<false>(
303 ilane, nqTotFine, coordDim, fineGroup, nqTotFine *
warpsize,
304 gradFine, nqTotFine *
warpsize, combinedOut, scale);
306 TData *outptr = outGroup + (
c * nhomo +
p) * outCompStride;
307 if constexpr (APPEND)
309 BwdTransSegSumFacKernel<true>(
310 ilane, nq0Fine, nq0, Bproject0, combinedOut, outptr);
314 BwdTransSegSumFacKernel<false>(
315 ilane, nq0Fine, nq0, Bproject0, combinedOut, outptr);
325 bool APPEND,
bool DEFORMED,
bool LOCAL_PIPELINE,
bool SHARED_SCRATCH,
326 typename TPhysSizeParameter2D,
typename TthreadBlock,
typename TData,
327 typename TUseSharedWsp,
328 std::enable_if_t<std::is_same_v<Implementation, SumFac>,
bool>
331 const TPhysSizeParameter2D sizeParam2D,
const size_t nelmt,
332 [[maybe_unused]]
const unsigned int elmtsPerBlock,
const unsigned int ncomp,
340 const TData *
NEK_RESTRICT advVel,
const size_t advVelPlaneStride,
346 IsPhysSizeParameter2D_v<TPhysSizeParameter2D>,
347 "Template argument must be either of type "
348 "NonTemplatedPhysSizeParameter2D or TemplatedPhysSizeParameter2D.");
352 const unsigned int coordDim = sizeParam2D.ncoord();
353 const unsigned int nq0 = sizeParam2D.nq0();
354 const unsigned int nq1 = sizeParam2D.nq1();
355 const unsigned int nqTot = sizeParam2D.nqTot();
356 const unsigned int nq0Fine = 3u * nq0 / 2u;
357 const unsigned int nq1Fine =
358 (nq0 - nq1 == 1u) ? nq0Fine - 1u : 3u * nq1 / 2u;
360 const unsigned int nqTotFine = nq0Fine * nq1Fine;
361 const unsigned int ndf = 2u * coordDim;
362 const unsigned int dfsize = DEFORMED ? nqTot : 1u;
364 TData *s_f0 =
nullptr;
365 TData *s_f1 =
nullptr;
383 const size_t advVelCompStride = advVelPlaneStride * nhomo;
386 const unsigned int wspSize =
static_cast<unsigned int>(
387 AdvectionDealiasWorkSpaceSize<SHAPE_TYPE, Implementation>(
388 1u, coordDim, ncomp, sizeParam2D, LOCAL_PIPELINE));
392 TData *wspbase = isShared ?
s_wsp : elmtWsp;
401 const TData *dfptr = df + ndf * dfsize *
warpsize * iwarp;
402 const TData *inGroup =
in + nqTot *
warpsize * iwarp;
403 const TData *advVelGroup =
404 advVel +
p * advVelPlaneStride + nqTot *
warpsize * iwarp;
410 const size_t wspOffset =
412 TData *
wsp = wspbase + wspSize * wspOffset;
413 TData *derivGroup =
wsp;
414 TData *fineGroup = derivGroup + ncomp * coordDim * nqTot *
warpsize;
415 TData *combinedGroup = fineGroup + (coordDim + ncomp * coordDim) *
417 TData *wsp0 = combinedGroup + ncomp * nqTotFine *
warpsize;
419 for (
unsigned int d = 0u;
d < coordDim; ++
d)
421 BwdTransQuadSumFacKernel<false>(
422 ilane, nq0, nq1, nq0Fine, nq1Fine, Binterp0, Binterp1,
423 advVelGroup + d * advVelCompStride,
424 fineGroup + d * nqTotFine *
warpsize, wsp0);
430 for (
unsigned int c = 0u;
c < ncomp; ++
c)
432 TData *derivOut = derivGroup +
c * coordDim * nqTot *
warpsize;
433 TData *gradFine = fineGroup + (coordDim +
c * coordDim) *
435 TData *combinedOut = combinedGroup +
c * nqTotFine *
warpsize;
437 PhysDeriv2DSumFacKernel<SHAPE_TYPE, DEFORMED>(
438 ilane, coordDim, nq0, nq1, nqTot *
warpsize, D0, D1, s_f0,
439 s_f1, dfptr, inGroup + (
c * nhomo + p) * inCompStride,
442 for (
unsigned int d = 0u;
d < coordDim; ++
d)
444 BwdTransQuadSumFacKernel<false>(
445 ilane, nq0, nq1, nq0Fine, nq1Fine, Binterp0, Binterp1,
447 gradFine + d * nqTotFine *
warpsize, wsp0);
450 AdvectionDealiasCombineSumFacKernel<false>(
451 ilane, nqTotFine, coordDim, fineGroup, nqTotFine *
warpsize,
452 gradFine, nqTotFine *
warpsize, combinedOut, scale);
454 TData *outptr = outGroup + (
c * nhomo +
p) * outCompStride;
455 if constexpr (APPEND)
457 BwdTransQuadSumFacKernel<true>(ilane, nq0Fine, nq1Fine, nq0,
458 nq1, Bproject0, Bproject1,
459 combinedOut, outptr, wsp0);
463 BwdTransQuadSumFacKernel<false>(
464 ilane, nq0Fine, nq1Fine, nq0, nq1, Bproject0, Bproject1,
465 combinedOut, outptr, wsp0);
475 bool APPEND,
bool DEFORMED,
bool LOCAL_PIPELINE,
bool SHARED_SCRATCH,
476 typename TPhysSizeParameter3D,
typename TthreadBlock,
typename TData,
477 typename TUseSharedWsp,
478 std::enable_if_t<std::is_same_v<Implementation, SumFac>,
bool>
481 const TPhysSizeParameter3D sizeParam3D,
const size_t nelmt,
482 [[maybe_unused]]
const unsigned int elmtsPerBlock,
const unsigned int ncomp,
491 const TData scale,
const TData *
NEK_RESTRICT in,
const size_t inCompStride,
492 const TData *
NEK_RESTRICT advVel,
const size_t advVelPlaneStride,
498 IsPhysSizeParameter3D_v<TPhysSizeParameter3D>,
499 "Template argument must be either of type "
500 "NonTemplatedPhysSizeParameter3D or TemplatedPhysSizeParameter3D.");
504 const unsigned int nq0 = sizeParam3D.nq0();
505 const unsigned int nq1 = sizeParam3D.nq1();
506 const unsigned int nq2 = sizeParam3D.nq2();
507 const unsigned int nqTot = sizeParam3D.nqTot();
508 const unsigned int nq0Fine = 3u * nq0 / 2u;
509 const unsigned int nq1Fine =
510 (nq0 - nq1 == 1u) ? nq0Fine - 1u : 3u * nq1 / 2u;
511 const unsigned int nq2Fine =
512 (nq0 - nq2 == 1u) ? nq0Fine - 1u : 3u * nq2 / 2u;
514 constexpr unsigned int coordDim3D = 3u;
515 const unsigned int nqTotFine = nq0Fine * nq1Fine * nq2Fine;
516 constexpr unsigned int ndf = 9u;
517 const unsigned int dfsize = DEFORMED ? nqTot : 1u;
519 TData *s_f0 =
nullptr;
520 TData *s_f1 =
nullptr;
521 TData *s_f1m =
nullptr;
522 TData *s_f2 =
nullptr;
572 const size_t advVelCompStride = advVelPlaneStride * nhomo;
575 const unsigned int wspSize =
static_cast<unsigned int>(
576 AdvectionDealiasWorkSpaceSize<SHAPE_TYPE, Implementation>(
577 1u, coordDim3D, ncomp, sizeParam3D, LOCAL_PIPELINE));
581 TData *wspbase = isShared ?
s_wsp : elmtWsp;
590 const TData *dfptr = df + ndf * dfsize *
warpsize * iwarp;
591 const TData *inGroup =
in + nqTot *
warpsize * iwarp;
592 const TData *advVelGroup =
593 advVel +
p * advVelPlaneStride + nqTot *
warpsize * iwarp;
599 const size_t wspOffset =
601 TData *
wsp = wspbase + wspSize * wspOffset;
602 TData *derivGroup =
wsp;
604 derivGroup + ncomp * coordDim3D * nqTot *
warpsize;
605 TData *combinedGroup =
607 (coordDim3D + ncomp * coordDim3D) * nqTotFine *
warpsize;
608 TData *wsp0 = combinedGroup + ncomp * nqTotFine *
warpsize;
609 TData *wsp1 = wsp0 + (nq1 * nq2 + nq1Fine * nq2Fine) *
warpsize;
614 for (
unsigned int d = 0u;
d < coordDim3D; ++
d)
616 BwdTransHexSumFacKernel<false>(
617 ilane, nq0, nq1, nq2, nq0Fine, nq1Fine, nq2Fine, Binterp0,
618 Binterp1, Binterp2, advVelGroup + d * advVelCompStride,
619 fineGroup + d * nqTotFine *
warpsize, wsp0, wsp1);
625 for (
unsigned int c = 0u;
c < ncomp; ++
c)
628 derivGroup +
c * coordDim3D * nqTot *
warpsize;
629 TData *gradFine = fineGroup + (coordDim3D +
c * coordDim3D) *
631 TData *combinedOut = combinedGroup +
c * nqTotFine *
warpsize;
633 PhysDeriv3DSumFacKernel<SHAPE_TYPE, DEFORMED>(
634 ilane, nq0, nq1, nq2, nqTot *
warpsize, D0, D1, D2, s_f0,
635 s_f1, s_f1m, s_f2, dfptr,
636 inGroup + (
c * nhomo + p) * inCompStride, derivOut);
639 for (
unsigned int d = 0u;
d < coordDim3D; ++
d)
641 BwdTransHexSumFacKernel<false>(
642 ilane, nq0, nq1, nq2, nq0Fine, nq1Fine, nq2Fine,
643 Binterp0, Binterp1, Binterp2,
645 gradFine + d * nqTotFine *
warpsize, wsp0, wsp1);
648 AdvectionDealiasCombineSumFacKernel<false>(
649 ilane, nqTotFine, coordDim3D, fineGroup,
653 TData *outptr = outGroup + (
c * nhomo +
p) * outCompStride;
654 if constexpr (APPEND)
656 BwdTransHexSumFacKernel<true>(
657 ilane, nq0Fine, nq1Fine, nq2Fine, nq0, nq1, nq2,
658 Bproject0, Bproject1, Bproject2, combinedOut, outptr,
663 BwdTransHexSumFacKernel<false>(
664 ilane, nq0Fine, nq1Fine, nq2Fine, nq0, nq1, nq2,
665 Bproject0, Bproject1, Bproject2, combinedOut, outptr,
#define NEK_DEVICE_INLINE
#define NEK_HOSTDEVICE_INLINE
#define NEK_DEVICE_KERNEL
Device SumFac kernels of the backward transform: one element per thread, with the sum-factorisation i...
Device SumFac kernels of the physical derivative: one element per warp lane.
std::vector< NekDouble > grad
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
constexpr unsigned int warpsize
FETCH_SHARED_MEMORY(shmemptr)
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);} })
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
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
std::vector< double > p(NPUPPER)
std::vector< double > d(NPUPPER *NPUPPER)
static constexpr unsigned int warpSize