Nektar++
Loading...
Searching...
No Matches
LaplacianBlockOpDeviceSumFacKernels.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: LaplacianBlockOpDeviceSumFacKernels.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 sum-factorised (SumFac) kernels and launchers for
32// the weak Laplacian operator.
33///////////////////////////////////////////////////////////////////////////////
34
35/**
36 * @file LaplacianBlockOpDeviceSumFacKernels.hpp
37 * @brief Device sum-factorised (SumFac) kernels and launchers for the
38 * weak Laplacian operator.
39 *
40 * @details
41 * Element-parallel kernels for the weak Laplacian operator: each thread
42 * handles one element and walks its quadrature points. Strings
43 * together:
44 * 1. BwdTransSumFacKernel to evaluate physical values;
45 * 2. PhysDerivSumFacKernel to evaluate reference derivatives;
46 * 3. ApplyMetric{1,2,3}DSumFacKernel to apply the diffusion tensor and
47 * geometry metric;
48 * 4. SumDerivTensor to sum transposed derivatives;
49 * 5. IProductWRTBaseSumFacKernel to take the inner product with the basis.
50 *
51 * A null diffusion-tensor pointer selects the branch that contracts
52 * with the derivative factors alone, i.e. an identity tensor;
53 * LaplacianOp always supplies one.
54 */
55
56#pragma once
57
61
65
66// Coefficients are passed as raw pointers. Variable tensor components are
67// separated by varDiffCoeffSize scalars. The kernels select the plane and
68// element from the base pointer; point offsets follow the same interleaving
69// as the input and derivative-factor arrays.
70
72{
73
74#if defined(NEKTAR_ENABLE_DEVICE) && defined(DEVICE_COMPILE_ONLY)
75// Helper function
76/**
77 * @brief Compute required workspace size in elements for the sum-factorised
78 * Laplacian operator intermediates.
79 */
80template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
81 typename TSizeParameter1D,
82 std::enable_if_t<std::is_same_v<Implementation, SumFac> &&
83 IsSizeParameter1D_v<TSizeParameter1D>,
84 bool>
85 Enable = true>
86inline constexpr size_t LaplacianWorkSpaceSize(
87 const size_t nelmt, const unsigned int ncoord,
88 const TSizeParameter1D sizeParam1D)
89{
90 size_t wspsize = 0;
91
92 const unsigned int nq0 = sizeParam1D.nq0();
93
94 if constexpr (SHAPE_TYPE == LibUtilities::Seg)
95 {
96 wspsize = (1 + ncoord) * nq0 * nelmt;
97 }
98
99 return wspsize;
100}
101
102/// @brief Workspace of the 2D SumFac Laplacian, as the 1D overload.
103template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
104 typename TSizeParameter2D,
105 std::enable_if_t<std::is_same_v<Implementation, SumFac> &&
106 IsSizeParameter2D_v<TSizeParameter2D>,
107 bool>
108 Enable = true>
109inline constexpr size_t LaplacianWorkSpaceSize(
110 const size_t nelmt, const unsigned int ncoord,
111 const TSizeParameter2D sizeParam2D)
112{
113 size_t wspsize = 0;
114
115 const unsigned int nm0 = sizeParam2D.nm0();
116 const unsigned int nq1 = sizeParam2D.nq1();
117
118 if constexpr (SHAPE_TYPE == LibUtilities::Quad)
119 {
120 wspsize = ((1 + ncoord) * sizeParam2D.nqTot() + nq1) * nelmt;
121 }
122 else if constexpr (SHAPE_TYPE == LibUtilities::Tri)
123 {
124 wspsize =
125 ((1 + ncoord) * sizeParam2D.nqTot() + std::max(nq1, nm0)) * nelmt;
126 }
127 else if constexpr (SHAPE_TYPE == LibUtilities::NodalTri)
128 {
129 const unsigned int nmTot = sizeParam2D.nmTot();
130
131 wspsize =
132 ((1 + ncoord) * sizeParam2D.nqTot() + std::max(nq1, nm0) + nmTot) *
133 nelmt;
134 }
135
136 return wspsize;
137}
138
139/// @brief Workspace of the 3D SumFac Laplacian, as the 1D overload.
140template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
141 typename TSizeParameter3D,
142 std::enable_if_t<std::is_same_v<Implementation, SumFac> &&
143 IsSizeParameter3D_v<TSizeParameter3D>,
144 bool>
145 Enable = true>
146inline constexpr size_t LaplacianWorkSpaceSize(
147 const size_t nelmt, [[maybe_unused]] const unsigned int ncoord,
148 const TSizeParameter3D sizeParam3D)
149{
150 size_t wspsize = 0;
151
152 const unsigned int nm0 = sizeParam3D.nm0();
153 const unsigned int nm1 = sizeParam3D.nm1();
154 const unsigned int nq1 = sizeParam3D.nq1();
155 const unsigned int nq2 = sizeParam3D.nq2();
156
157 if constexpr (SHAPE_TYPE == LibUtilities::Hex)
158 {
159 wspsize = (4 * sizeParam3D.nqTot() + nq1 * nq2 + nq2) * nelmt;
160 }
161 else if constexpr (SHAPE_TYPE == LibUtilities::Tet)
162 {
163 wspsize =
164 (4 * sizeParam3D.nqTot() + nq1 * nq2 + std::max(nq2, nm0)) * nelmt;
165 }
166 else if constexpr (SHAPE_TYPE == LibUtilities::NodalTet)
167 {
168 const unsigned int nmTot = sizeParam3D.nmTot();
169
170 wspsize =
171 (4 * sizeParam3D.nqTot() + nq1 * nq2 + std::max(nq2, nm0) + nmTot) *
172 nelmt;
173 }
174 else if constexpr (SHAPE_TYPE == LibUtilities::Prism)
175 {
176 wspsize = (4 * sizeParam3D.nqTot() + std::max(nq1 * nq2, nm0 * nm1) +
177 std::max(nq2, nm0)) *
178 nelmt;
179 }
180 else if constexpr (SHAPE_TYPE == LibUtilities::NodalPrism)
181 {
182 const unsigned int nmTot = sizeParam3D.nmTot();
183
184 wspsize = (4 * sizeParam3D.nqTot() + std::max(nq1 * nq2, nm0 * nm1) +
185 std::max(nq2, nm0) + nmTot) *
186 nelmt;
187 }
188 else if constexpr (SHAPE_TYPE == LibUtilities::Pyr)
189 {
190 wspsize = (4 * sizeParam3D.nqTot() + std::max(nq1 * nq2, nm0 * nm1) +
191 std::max(nq2, nm0)) *
192 nelmt;
193 }
194 else if constexpr (SHAPE_TYPE == LibUtilities::NodalPyr)
195 {
196 const unsigned int nmTot = sizeParam3D.nmTot();
197
198 wspsize = (4 * sizeParam3D.nqTot() + std::max(nq1 * nq2, nm0 * nm1) +
199 std::max(nq2, nm0) + nmTot) *
200 nelmt;
201 }
202
203 return wspsize;
204}
205
206/**
207 * @brief Dynamic shared memory of the SumFac Laplacian, in TData values:
208 * the collapsed-coordinate factors of the shape, followed, with
209 * @p useSharedMemoryWsp, by the workspace of the thread block's
210 * @p elmtsPerBlock elements, laid out as LaplacianWorkSpaceSize gives for that
211 * many elements.
212 */
213template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
214 typename TData, typename TSizeParameter1D,
215 std::enable_if_t<std::is_same_v<Implementation, SumFac> &&
216 IsSizeParameter1D_v<TSizeParameter1D>,
217 bool>
218 Enable = true>
219inline constexpr unsigned int LaplacianSharedMemorySize(
220 const unsigned int ncoord, const TSizeParameter1D sizeParam1D,
221 const unsigned int elmtsPerBlock, const bool useSharedMemoryWsp)
222{
223 return useSharedMemoryWsp
224 ? static_cast<unsigned int>(
225 LaplacianWorkSpaceSize<SHAPE_TYPE, Implementation>(
226 elmtsPerBlock, ncoord, sizeParam1D))
227 : 0u;
228}
229
230/// @brief Dynamic shared memory of the 2D SumFac Laplacian, as the 1D
231/// overload.
232template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
233 typename TData, typename TSizeParameter2D,
234 std::enable_if_t<std::is_same_v<Implementation, SumFac> &&
235 IsSizeParameter2D_v<TSizeParameter2D>,
236 bool>
237 Enable = true>
238inline constexpr unsigned int LaplacianSharedMemorySize(
239 const unsigned int ncoord, const TSizeParameter2D sizeParam2D,
240 const unsigned int elmtsPerBlock, const bool useSharedMemoryWsp)
241{
242 unsigned int shmemsize = 0;
243
244 if constexpr (SHAPE_TYPE == LibUtilities::Tri ||
245 SHAPE_TYPE == LibUtilities::NodalTri)
246 {
247 const unsigned int nq0 = sizeParam2D.nq0();
248 const unsigned int nq1 = sizeParam2D.nq1();
249
250 shmemsize = nq0 + nq1;
251 }
252
254 {
255 shmemsize += static_cast<unsigned int>(
256 LaplacianWorkSpaceSize<SHAPE_TYPE, Implementation>(
257 elmtsPerBlock, ncoord, sizeParam2D));
258 }
259
260 return shmemsize;
261}
262
263/// @brief Dynamic shared memory of the 3D SumFac Laplacian, as the 1D
264/// overload.
265template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
266 typename TData, typename TSizeParameter3D,
267 std::enable_if_t<std::is_same_v<Implementation, SumFac> &&
268 IsSizeParameter3D_v<TSizeParameter3D>,
269 bool>
270 Enable = true>
271inline constexpr unsigned int LaplacianSharedMemorySize(
272 const unsigned int ncoord, const TSizeParameter3D sizeParam3D,
273 const unsigned int elmtsPerBlock, const bool useSharedMemoryWsp)
274{
275 const unsigned int nq0 = sizeParam3D.nq0();
276 const unsigned int nq1 = sizeParam3D.nq1();
277 const unsigned int nq2 = sizeParam3D.nq2();
278
279 unsigned int shmemsize = 0;
280
281 if constexpr (SHAPE_TYPE == LibUtilities::Tet ||
282 SHAPE_TYPE == LibUtilities::NodalTet)
283 {
284 shmemsize = nq0 + 2 * nq1 + nq2;
285 }
286 else if constexpr (SHAPE_TYPE == LibUtilities::Prism ||
287 SHAPE_TYPE == LibUtilities::NodalPrism)
288 {
289 shmemsize = nq0 + nq2;
290 }
291 else if constexpr (SHAPE_TYPE == LibUtilities::Pyr ||
292 SHAPE_TYPE == LibUtilities::NodalPyr)
293 {
294 shmemsize = nq0 + nq1 + nq2;
295 }
296
298 {
299 shmemsize += static_cast<unsigned int>(
300 LaplacianWorkSpaceSize<SHAPE_TYPE, Implementation>(
301 elmtsPerBlock, ncoord, sizeParam3D));
302 }
303
304 return shmemsize;
305}
306
307/**
308 * @brief 1D metric kernel applying diffusion tensor and metric terms.
309 */
310template <bool DEFORMED, bool VARCOEFF, typename TData>
311NEK_DEVICE_INLINE static void ApplyMetric1DSumFacKernel(
312 const unsigned int ilane, const unsigned int ncoord, const unsigned int nq0,
313 const size_t inoffset, const TData *NEK_RESTRICT w0,
314 const TData *NEK_RESTRICT df, const TData *NEK_RESTRICT jac,
315 const TData *NEK_RESTRICT diffCoeff, const size_t varDiffCoeffSize,
316 const TData *NEK_RESTRICT in, TData *out)
317{
318 const size_t diffCoeffStride = VARCOEFF ? varDiffCoeffSize : 1;
319 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
320
321 TData metric[3] = {0.0};
322 if constexpr (!DEFORMED && !VARCOEFF)
323 {
324 if (diffCoeff)
325 {
326 if (ncoord == 1)
327 {
328 metric[0] = diffCoeff[0] * df[ilane];
329 }
330 else if (ncoord == 2)
331 {
332 metric[0] = diffCoeff[0] * df[ilane] +
333 diffCoeff[1] * df[warpsize + ilane];
334 metric[1] = diffCoeff[1] * df[ilane] +
335 diffCoeff[2] * df[warpsize + ilane];
336 }
337 else if (ncoord == 3)
338 {
339 metric[0] = diffCoeff[0] * df[ilane] +
340 diffCoeff[1] * df[warpsize + ilane] +
341 diffCoeff[3] * df[2 * warpsize + ilane];
342 metric[1] = diffCoeff[1] * df[ilane] +
343 diffCoeff[2] * df[warpsize + ilane] +
344 diffCoeff[4] * df[2 * warpsize + ilane];
345 metric[2] = diffCoeff[3] * df[ilane] +
346 diffCoeff[4] * df[warpsize + ilane] +
347 diffCoeff[5] * df[2 * warpsize + ilane];
348 }
349 }
350 }
351
352 for (unsigned int i = 0u; i < nq0; ++i)
353 {
354 const unsigned int index = warpsize * i + ilane;
355 const unsigned int dfindex =
356 DEFORMED ? ncoord * warpsize * i + ilane : ilane;
357
358 if constexpr (DEFORMED || VARCOEFF)
359 {
360 const size_t diffCoeffIndex = VARCOEFF ? index : 0;
361 if (diffCoeff)
362 {
363 if (ncoord == 1)
364 {
365 metric[0] = diffCoeff[diffCoeffIndex] * df[dfindex];
366 }
367 else if (ncoord == 2)
368 {
369 metric[0] = diffCoeff[diffCoeffIndex] * df[dfindex] +
370 diffCoeff[diffCoeffStride + diffCoeffIndex] *
371 df[warpsize + dfindex];
372 metric[1] =
373 diffCoeff[diffCoeffStride + diffCoeffIndex] *
374 df[dfindex] +
375 diffCoeff[2 * diffCoeffStride + diffCoeffIndex] *
376 df[warpsize + dfindex];
377 }
378 else if (ncoord == 3)
379 {
380 metric[0] =
381 diffCoeff[diffCoeffIndex] * df[dfindex] +
382 diffCoeff[diffCoeffStride + diffCoeffIndex] *
383 df[warpsize + dfindex] +
384 diffCoeff[3 * diffCoeffStride + diffCoeffIndex] *
385 df[2 * warpsize + dfindex];
386 metric[1] =
387 diffCoeff[diffCoeffStride + diffCoeffIndex] *
388 df[dfindex] +
389 diffCoeff[2 * diffCoeffStride + diffCoeffIndex] *
390 df[warpsize + dfindex] +
391 diffCoeff[4 * diffCoeffStride + diffCoeffIndex] *
392 df[2 * warpsize + dfindex];
393 metric[2] =
394 diffCoeff[3 * diffCoeffStride + diffCoeffIndex] *
395 df[dfindex] +
396 diffCoeff[4 * diffCoeffStride + diffCoeffIndex] *
397 df[warpsize + dfindex] +
398 diffCoeff[5 * diffCoeffStride + diffCoeffIndex] *
399 df[2 * warpsize + dfindex];
400 }
401 }
402 }
403
404 TData sum = 0.0;
405 for (unsigned int k = 0u; k < ncoord; ++k)
406 {
407 if (diffCoeff)
408 {
409 sum += metric[k] * in[k * inoffset + index];
410 }
411 else
412 {
413 sum += df[k * warpsize + dfindex] * in[k * inoffset + index];
414 }
415 }
416
417 if constexpr (DEFORMED)
418 {
419 out[index] = sum * jac[index] * w0[i];
420 }
421 else
422 {
423 out[index] = sum * jac[0] * w0[i];
424 }
425 }
426}
427
428/**
429 * @brief 2D metric kernel applying diffusion tensor and metric terms.
430 */
431template <LibUtilities::ShapeType SHAPE_TYPE, bool DEFORMED, bool VARCOEFF,
432 typename TData>
433NEK_DEVICE_INLINE static void ApplyMetric2DSumFacKernel(
434 const unsigned int ilane, const unsigned int ncoord, const unsigned int nq0,
435 const unsigned int nq1, const size_t inoffset, const TData *NEK_RESTRICT w0,
436 const TData *NEK_RESTRICT w1, [[maybe_unused]] const TData *NEK_RESTRICT f0,
437 [[maybe_unused]] const TData *NEK_RESTRICT f1, const TData *NEK_RESTRICT df,
438 const TData *NEK_RESTRICT jac, const TData *NEK_RESTRICT diffCoeff,
439 const size_t varDiffCoeffSize, const TData *NEK_RESTRICT in,
440 TData *NEK_RESTRICT out0, TData *NEK_RESTRICT out1)
441{
442 const size_t diffCoeffStride = VARCOEFF ? varDiffCoeffSize : 1;
443 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
444
445 const unsigned int ndf = 2 * ncoord;
446
447 TData metric[6] = {0.0};
448 if constexpr (!DEFORMED && !VARCOEFF)
449 {
450 if (diffCoeff)
451 {
452 if (ncoord == 2)
453 {
454 metric[0] = diffCoeff[0] * df[ilane] +
455 diffCoeff[1] * df[2 * warpsize + ilane];
456 metric[1] = diffCoeff[0] * df[1 * warpsize + ilane] +
457 diffCoeff[1] * df[3 * warpsize + ilane];
458 metric[2] = diffCoeff[1] * df[ilane] +
459 diffCoeff[2] * df[2 * warpsize + ilane];
460 metric[3] = diffCoeff[1] * df[1 * warpsize + ilane] +
461 diffCoeff[2] * df[3 * warpsize + ilane];
462 }
463 else if (ncoord == 3)
464 {
465 metric[0] = diffCoeff[0] * df[ilane] +
466 diffCoeff[1] * df[2 * warpsize + ilane] +
467 diffCoeff[3] * df[4 * warpsize + ilane];
468 metric[1] = diffCoeff[0] * df[1 * warpsize + ilane] +
469 diffCoeff[1] * df[3 * warpsize + ilane] +
470 diffCoeff[3] * df[5 * warpsize + ilane];
471 metric[2] = diffCoeff[1] * df[ilane] +
472 diffCoeff[2] * df[2 * warpsize + ilane] +
473 diffCoeff[4] * df[4 * warpsize + ilane];
474 metric[3] = diffCoeff[1] * df[1 * warpsize + ilane] +
475 diffCoeff[2] * df[3 * warpsize + ilane] +
476 diffCoeff[4] * df[5 * warpsize + ilane];
477 metric[4] = diffCoeff[3] * df[ilane] +
478 diffCoeff[4] * df[2 * warpsize + ilane] +
479 diffCoeff[5] * df[4 * warpsize + ilane];
480 metric[5] = diffCoeff[3] * df[1 * warpsize + ilane] +
481 diffCoeff[4] * df[3 * warpsize + ilane] +
482 diffCoeff[5] * df[5 * warpsize + ilane];
483 }
484 }
485 }
486
487 for (unsigned int j = 0u, cnt_ji = 0u; j < nq1; ++j)
488 {
489 for (unsigned int i = 0u; i < nq0; ++i, ++cnt_ji)
490 {
491 const unsigned int index = warpsize * cnt_ji + ilane;
492 const unsigned int dfindex =
493 DEFORMED ? ndf * warpsize * cnt_ji + ilane : ilane;
494
495 if constexpr (DEFORMED || VARCOEFF)
496 {
497 const size_t diffCoeffIndex = VARCOEFF ? index : 0;
498 if (diffCoeff)
499 {
500 if (ncoord == 2)
501 {
502 metric[0] =
503 diffCoeff[diffCoeffIndex] * df[dfindex] +
504 diffCoeff[diffCoeffStride + diffCoeffIndex] *
505 df[2 * warpsize + dfindex];
506 metric[1] =
507 diffCoeff[diffCoeffIndex] *
508 df[1 * warpsize + dfindex] +
509 diffCoeff[diffCoeffStride + diffCoeffIndex] *
510 df[3 * warpsize + dfindex];
511 metric[2] =
512 diffCoeff[diffCoeffStride + diffCoeffIndex] *
513 df[dfindex] +
514 diffCoeff[2 * diffCoeffStride + diffCoeffIndex] *
515 df[2 * warpsize + dfindex];
516 metric[3] =
517 diffCoeff[diffCoeffStride + diffCoeffIndex] *
518 df[1 * warpsize + dfindex] +
519 diffCoeff[2 * diffCoeffStride + diffCoeffIndex] *
520 df[3 * warpsize + dfindex];
521 }
522 else if (ncoord == 3)
523 {
524 metric[0] =
525 diffCoeff[diffCoeffIndex] * df[dfindex] +
526 diffCoeff[diffCoeffStride + diffCoeffIndex] *
527 df[2 * warpsize + dfindex] +
528 diffCoeff[3 * diffCoeffStride + diffCoeffIndex] *
529 df[4 * warpsize + dfindex];
530 metric[1] =
531 diffCoeff[diffCoeffIndex] *
532 df[1 * warpsize + dfindex] +
533 diffCoeff[diffCoeffStride + diffCoeffIndex] *
534 df[3 * warpsize + dfindex] +
535 diffCoeff[3 * diffCoeffStride + diffCoeffIndex] *
536 df[5 * warpsize + dfindex];
537 metric[2] =
538 diffCoeff[diffCoeffStride + diffCoeffIndex] *
539 df[dfindex] +
540 diffCoeff[2 * diffCoeffStride + diffCoeffIndex] *
541 df[2 * warpsize + dfindex] +
542 diffCoeff[4 * diffCoeffStride + diffCoeffIndex] *
543 df[4 * warpsize + dfindex];
544 metric[3] =
545 diffCoeff[diffCoeffStride + diffCoeffIndex] *
546 df[1 * warpsize + dfindex] +
547 diffCoeff[2 * diffCoeffStride + diffCoeffIndex] *
548 df[3 * warpsize + dfindex] +
549 diffCoeff[4 * diffCoeffStride + diffCoeffIndex] *
550 df[5 * warpsize + dfindex];
551 metric[4] =
552 diffCoeff[3 * diffCoeffStride + diffCoeffIndex] *
553 df[dfindex] +
554 diffCoeff[4 * diffCoeffStride + diffCoeffIndex] *
555 df[2 * warpsize + dfindex] +
556 diffCoeff[5 * diffCoeffStride + diffCoeffIndex] *
557 df[4 * warpsize + dfindex];
558 metric[5] =
559 diffCoeff[3 * diffCoeffStride + diffCoeffIndex] *
560 df[1 * warpsize + dfindex] +
561 diffCoeff[4 * diffCoeffStride + diffCoeffIndex] *
562 df[3 * warpsize + dfindex] +
563 diffCoeff[5 * diffCoeffStride + diffCoeffIndex] *
564 df[5 * warpsize + dfindex];
565 }
566 }
567 }
568
569 TData sum1 = 0.0, sum2 = 0.0;
570 if (diffCoeff)
571 {
572 TData tmp = in[index];
573 sum1 += metric[0u] * tmp;
574 sum2 += metric[1u] * tmp;
575 tmp = in[inoffset + index];
576 sum1 += metric[2u] * tmp;
577 sum2 += metric[3u] * tmp;
578 if (ncoord == 3u)
579 {
580 tmp = in[2u * inoffset + index];
581 sum1 += metric[4u] * tmp;
582 sum2 += metric[5u] * tmp;
583 }
584 }
585 else
586 {
587 TData tmp = in[index];
588 sum1 += df[0u * warpsize + dfindex] * tmp;
589 sum2 += df[1u * warpsize + dfindex] * tmp;
590 tmp = in[inoffset + index];
591 sum1 += df[2u * warpsize + dfindex] * tmp;
592 sum2 += df[3u * warpsize + dfindex] * tmp;
593 if (ncoord == 3u)
594 {
595 tmp = in[2u * inoffset + index];
596 sum1 += df[4u * warpsize + dfindex] * tmp;
597 sum2 += df[5u * warpsize + dfindex] * tmp;
598 }
599 }
600
601 TData tmpQ = w0[i] * w1[j];
602 if constexpr (DEFORMED)
603 {
604 tmpQ *= jac[index];
605 }
606 else
607 {
608 tmpQ *= jac[0];
609 }
610
611 // Moving from standard to collapsed coordinates.
612 if constexpr (SHAPE_TYPE == LibUtilities::Quad)
613 {
614 out0[index] = sum1 * tmpQ;
615 out1[index] = sum2 * tmpQ;
616 }
617 else if constexpr (SHAPE_TYPE == LibUtilities::Tri ||
618 SHAPE_TYPE == LibUtilities::NodalTri)
619 {
620 out0[index] = (sum1 + sum2 * f0[i]) * f1[j] * tmpQ;
621 out1[index] = sum2 * tmpQ;
622 }
623 }
624 }
625}
626
627/**
628 * @brief 3D metric kernel applying diffusion tensor and metric terms.
629 */
630template <LibUtilities::ShapeType SHAPE_TYPE, bool DEFORMED, bool VARCOEFF,
631 typename TData>
632NEK_DEVICE_INLINE static void ApplyMetric3DSumFacKernel(
633 const unsigned int ilane, const unsigned int nq0, const unsigned int nq1,
634 const unsigned int nq2, const size_t inoffset, const TData *NEK_RESTRICT w0,
635 const TData *NEK_RESTRICT w1, const TData *NEK_RESTRICT w2,
636 [[maybe_unused]] const TData *NEK_RESTRICT f0,
637 [[maybe_unused]] const TData *NEK_RESTRICT f1,
638 [[maybe_unused]] const TData *NEK_RESTRICT f1m,
639 [[maybe_unused]] const TData *NEK_RESTRICT f2, const TData *NEK_RESTRICT df,
640 const TData *NEK_RESTRICT jac, const TData *NEK_RESTRICT diffCoeff,
641 const size_t varDiffCoeffSize, const TData *NEK_RESTRICT in,
642 TData *NEK_RESTRICT out0, TData *NEK_RESTRICT out1,
643 TData *NEK_RESTRICT out2)
644{
645 const size_t diffCoeffStride = VARCOEFF ? varDiffCoeffSize : 1;
646 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
647
648 constexpr unsigned int ndf = 9u;
649
650 TData metric[9] = {0.0};
651 if constexpr (!DEFORMED && !VARCOEFF)
652 {
653 if (diffCoeff)
654 {
655 metric[0] = diffCoeff[0] * df[ilane] +
656 diffCoeff[1] * df[3 * warpsize + ilane] +
657 diffCoeff[3] * df[6 * warpsize + ilane];
658 metric[1] = diffCoeff[0] * df[1 * warpsize + ilane] +
659 diffCoeff[1] * df[4 * warpsize + ilane] +
660 diffCoeff[3] * df[7 * warpsize + ilane];
661 metric[2] = diffCoeff[0] * df[2 * warpsize + ilane] +
662 diffCoeff[1] * df[5 * warpsize + ilane] +
663 diffCoeff[3] * df[8 * warpsize + ilane];
664 metric[3] = diffCoeff[1] * df[ilane] +
665 diffCoeff[2] * df[3 * warpsize + ilane] +
666 diffCoeff[4] * df[6 * warpsize + ilane];
667 metric[4] = diffCoeff[1] * df[1 * warpsize + ilane] +
668 diffCoeff[2] * df[4 * warpsize + ilane] +
669 diffCoeff[4] * df[7 * warpsize + ilane];
670 metric[5] = diffCoeff[1] * df[2 * warpsize + ilane] +
671 diffCoeff[2] * df[5 * warpsize + ilane] +
672 diffCoeff[4] * df[8 * warpsize + ilane];
673 metric[6] = diffCoeff[3] * df[ilane] +
674 diffCoeff[4] * df[3 * warpsize + ilane] +
675 diffCoeff[5] * df[6 * warpsize + ilane];
676 metric[7] = diffCoeff[3] * df[1 * warpsize + ilane] +
677 diffCoeff[4] * df[4 * warpsize + ilane] +
678 diffCoeff[5] * df[7 * warpsize + ilane];
679 metric[8] = diffCoeff[3] * df[2 * warpsize + ilane] +
680 diffCoeff[4] * df[5 * warpsize + ilane] +
681 diffCoeff[5] * df[8 * warpsize + ilane];
682 }
683 }
684
685 for (unsigned int k = 0u, cnt_kji = 0u; k < nq2; ++k)
686 {
687 for (unsigned int j = 0u; j < nq1; ++j)
688 {
689 for (unsigned int i = 0u; i < nq0; ++i, ++cnt_kji)
690 {
691 const unsigned int index = warpsize * cnt_kji + ilane;
692 const unsigned int dfindex =
693 DEFORMED ? ndf * warpsize * cnt_kji + ilane : ilane;
694
695 if constexpr (DEFORMED || VARCOEFF)
696 {
697 const size_t diffCoeffIndex = VARCOEFF ? index : 0;
698 if (diffCoeff)
699 {
700 metric[0] =
701 diffCoeff[diffCoeffIndex] * df[dfindex] +
702 diffCoeff[diffCoeffStride + diffCoeffIndex] *
703 df[3 * warpsize + dfindex] +
704 diffCoeff[3 * diffCoeffStride + diffCoeffIndex] *
705 df[6 * warpsize + dfindex];
706 metric[1] =
707 diffCoeff[diffCoeffIndex] *
708 df[1 * warpsize + dfindex] +
709 diffCoeff[diffCoeffStride + diffCoeffIndex] *
710 df[4 * warpsize + dfindex] +
711 diffCoeff[3 * diffCoeffStride + diffCoeffIndex] *
712 df[7 * warpsize + dfindex];
713 metric[2] =
714 diffCoeff[diffCoeffIndex] *
715 df[2 * warpsize + dfindex] +
716 diffCoeff[diffCoeffStride + diffCoeffIndex] *
717 df[5 * warpsize + dfindex] +
718 diffCoeff[3 * diffCoeffStride + diffCoeffIndex] *
719 df[8 * warpsize + dfindex];
720 metric[3] =
721 diffCoeff[diffCoeffStride + diffCoeffIndex] *
722 df[dfindex] +
723 diffCoeff[2 * diffCoeffStride + diffCoeffIndex] *
724 df[3 * warpsize + dfindex] +
725 diffCoeff[4 * diffCoeffStride + diffCoeffIndex] *
726 df[6 * warpsize + dfindex];
727 metric[4] =
728 diffCoeff[diffCoeffStride + diffCoeffIndex] *
729 df[1 * warpsize + dfindex] +
730 diffCoeff[2 * diffCoeffStride + diffCoeffIndex] *
731 df[4 * warpsize + dfindex] +
732 diffCoeff[4 * diffCoeffStride + diffCoeffIndex] *
733 df[7 * warpsize + dfindex];
734 metric[5] =
735 diffCoeff[diffCoeffStride + diffCoeffIndex] *
736 df[2 * warpsize + dfindex] +
737 diffCoeff[2 * diffCoeffStride + diffCoeffIndex] *
738 df[5 * warpsize + dfindex] +
739 diffCoeff[4 * diffCoeffStride + diffCoeffIndex] *
740 df[8 * warpsize + dfindex];
741 metric[6] =
742 diffCoeff[3 * diffCoeffStride + diffCoeffIndex] *
743 df[dfindex] +
744 diffCoeff[4 * diffCoeffStride + diffCoeffIndex] *
745 df[3 * warpsize + dfindex] +
746 diffCoeff[5 * diffCoeffStride + diffCoeffIndex] *
747 df[6 * warpsize + dfindex];
748 metric[7] =
749 diffCoeff[3 * diffCoeffStride + diffCoeffIndex] *
750 df[1 * warpsize + dfindex] +
751 diffCoeff[4 * diffCoeffStride + diffCoeffIndex] *
752 df[4 * warpsize + dfindex] +
753 diffCoeff[5 * diffCoeffStride + diffCoeffIndex] *
754 df[7 * warpsize + dfindex];
755 metric[8] =
756 diffCoeff[3 * diffCoeffStride + diffCoeffIndex] *
757 df[2 * warpsize + dfindex] +
758 diffCoeff[4 * diffCoeffStride + diffCoeffIndex] *
759 df[5 * warpsize + dfindex] +
760 diffCoeff[5 * diffCoeffStride + diffCoeffIndex] *
761 df[8 * warpsize + dfindex];
762 }
763 }
764
765 TData sum1 = 0.0, sum2 = 0.0, sum3 = 0.0;
766 if (diffCoeff)
767 {
768 TData tmp = in[index];
769 sum1 += metric[0u] * tmp;
770 sum2 += metric[1u] * tmp;
771 sum3 += metric[2u] * tmp;
772 tmp = in[inoffset + index];
773 sum1 += metric[3u] * tmp;
774 sum2 += metric[4u] * tmp;
775 sum3 += metric[5u] * tmp;
776 tmp = in[2u * inoffset + index];
777 sum1 += metric[6u] * tmp;
778 sum2 += metric[7u] * tmp;
779 sum3 += metric[8u] * tmp;
780 }
781 else
782 {
783 TData tmp = in[index];
784 sum1 += df[0u * warpsize + dfindex] * tmp;
785 sum2 += df[1u * warpsize + dfindex] * tmp;
786 sum3 += df[2u * warpsize + dfindex] * tmp;
787 tmp = in[inoffset + index];
788 sum1 += df[3u * warpsize + dfindex] * tmp;
789 sum2 += df[4u * warpsize + dfindex] * tmp;
790 sum3 += df[5u * warpsize + dfindex] * tmp;
791 tmp = in[2u * inoffset + index];
792 sum1 += df[6u * warpsize + dfindex] * tmp;
793 sum2 += df[7u * warpsize + dfindex] * tmp;
794 sum3 += df[8u * warpsize + dfindex] * tmp;
795 }
796
797 TData tmpQ = w0[i] * w1[j] * w2[k];
798 if constexpr (DEFORMED)
799 {
800 tmpQ *= jac[index];
801 }
802 else
803 {
804 tmpQ *= jac[0];
805 }
806
807 if constexpr (SHAPE_TYPE == LibUtilities::Hex)
808 {
809 out0[index] = sum1 * tmpQ;
810 out1[index] = sum2 * tmpQ;
811 out2[index] = sum3 * tmpQ;
812 }
813 else if constexpr (SHAPE_TYPE == LibUtilities::Tet ||
814 SHAPE_TYPE == LibUtilities::NodalTet)
815 {
816 TData tmp = f2[k] * tmpQ;
817 out0[index] = (sum1 + (sum2 + sum3) * f0[i]) * f1m[j] * tmp;
818 out1[index] = (sum2 + sum3 * f1[j]) * tmp;
819 out2[index] = sum3 * tmpQ;
820 }
821 else if constexpr (SHAPE_TYPE == LibUtilities::Prism ||
822 SHAPE_TYPE == LibUtilities::NodalPrism)
823 {
824 out0[index] = (sum1 + sum3 * f0[i]) * f2[k] * tmpQ;
825 out1[index] = sum2 * tmpQ;
826 out2[index] = sum3 * tmpQ;
827 }
828 else if constexpr (SHAPE_TYPE == LibUtilities::Pyr ||
829 SHAPE_TYPE == LibUtilities::NodalPyr)
830 {
831 TData tmp = f2[k] * tmpQ;
832 out0[index] = (sum1 + sum3 * f0[i]) * tmp;
833 out1[index] = (sum2 + sum3 * f1[j]) * tmp;
834 out2[index] = sum3 * tmpQ;
835 }
836 }
837 }
838 }
839}
840
841/**
842 * @brief 1D launcher stringing together the five sum-factorised stages
843 * on device.
844 */
845template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
846 bool DEFORMED, bool VARCOEFF, typename TSizeParameter1D,
847 typename TthreadBlock, typename TData, typename TUseSharedWsp,
848 std::enable_if_t<std::is_same_v<Implementation, SumFac>, bool>
849 Enable = true>
851 (GetMaxThreadPerBlock<Implementation, TSizeParameter1D>()))
853 const TSizeParameter1D sizeParam1D, const unsigned int ncoord,
854 const size_t nelmt, [[maybe_unused]] const unsigned int elmtsPerBlock,
855 [[maybe_unused]] const bool isModified,
856 const TUseSharedWsp useSharedMemoryWsp,
857 const TData *NEK_RESTRICT basis0, const TData *NEK_RESTRICT D0,
858 const TData *NEK_RESTRICT w0,
859 [[maybe_unused]] const TData *NEK_RESTRICT nodToMod,
860 const TData *NEK_RESTRICT df, const TData *NEK_RESTRICT jac,
861 const TData *NEK_RESTRICT diffCoeff, const size_t varDiffCoeffSize,
862 const unsigned int nhomo, const TData *NEK_RESTRICT in,
863 TData *NEK_RESTRICT out, TData *NEK_RESTRICT wsp,
864 unsigned char *shmemptr, const TthreadBlock &threadBlock)
865{
866 static_assert(IsSizeParameter1D_v<TSizeParameter1D>,
867 "Template argument must be either of type "
868 "NonTemplatedSizeParameter1D or TemplatedSizeParameter1D.");
869
871
872 const unsigned int nm0 = sizeParam1D.nm0();
873 const unsigned int nq0 = sizeParam1D.nq0();
874
875 const unsigned int ndf = ncoord;
876 const unsigned int dfsize = DEFORMED ? nq0 : 1u;
877 const unsigned int jacsize = DEFORMED ? nq0 : 1u;
878
879 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
880
881 size_t e = getGlobalIdx<0>(threadBlock);
882 const unsigned int c = getBlockIdx<1>(threadBlock);
883 const unsigned int ncomp = getBlockRange<1>(threadBlock);
884
885 DispatchWorkSpace(useSharedMemoryWsp, [&](const auto isShared) {
886 // Workspace extent: the whole launch, or the thread block's warp.
887 TData *wspbase = isShared ? (TData *)shmemptr : wsp;
888 const size_t wspNelmt = isShared ? warpsize : nelmt * ncomp;
889 const size_t derivNelmt = isShared ? warpsize : nelmt;
890 while (e < nelmt)
891 {
892 const size_t ilane = e % warpsize;
893 const size_t iwarp = e / warpsize;
894 const TData *diffCoeffPtr =
895 VARCOEFF
896 ? diffCoeff + nq0 * (nelmt * (c % nhomo) + warpsize * iwarp)
897 : diffCoeff;
898 const TData *dfptr = df + ndf * dfsize * warpsize * iwarp;
899 const TData *jacptr =
900 DEFORMED ? jac + jacsize * warpsize * iwarp : jac + e;
901 const TData *inptr = in + nm0 * (nelmt * c + warpsize * iwarp);
902 TData *outptr = out + nm0 * (nelmt * c + warpsize * iwarp);
903
904 const size_t wspOffset =
905 isShared ? 0 : nelmt * c + warpsize * iwarp;
906 const size_t derivOffset =
907 isShared ? 0 : ncoord * nelmt * c + warpsize * iwarp;
908 TData *bwd = wspbase + nq0 * wspOffset;
909 TData *deriv = wspbase + nq0 * wspNelmt + nq0 * derivOffset;
910 BwdTransSegSumFacKernel<false>(ilane, nm0, nq0, basis0, inptr, bwd);
911 PhysDeriv1DSumFacKernel<DEFORMED>(
912 ilane, ncoord, nq0, derivNelmt * nq0, D0, dfptr, bwd, deriv);
913 ApplyMetric1DSumFacKernel<DEFORMED, VARCOEFF>(
914 ilane, ncoord, nq0, derivNelmt * nq0, w0, dfptr, jacptr,
915 diffCoeffPtr, varDiffCoeffSize, deriv, deriv);
916 SumDerivTensor1DKernel<false, false>(ilane, nq0, D0, deriv, bwd,
917 (TData)1.0);
918 IProductWRTBaseSegSumFacKernel<false, false>(
919 ilane, nm0, nq0, basis0, bwd, outptr, (TData)1.0);
920
921 e += getGlobalRange<0>(threadBlock);
922 }
923 });
924}
925
926/**
927 * @brief 2D launcher stringing together the five sum-factorised stages
928 * on device.
929 */
930template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
931 bool DEFORMED, bool VARCOEFF, typename TSizeParameter2D,
932 typename TthreadBlock, typename TData, typename TUseSharedWsp,
933 std::enable_if_t<std::is_same_v<Implementation, SumFac>, bool>
934 Enable = true>
936 (GetMaxThreadPerBlock<Implementation, TSizeParameter2D>()))
938 const TSizeParameter2D sizeParam2D, const unsigned int ncoord,
939 const size_t nelmt, [[maybe_unused]] const unsigned int elmtsPerBlock,
940 const bool isModified, const TUseSharedWsp useSharedMemoryWsp,
941 [[maybe_unused]] const unsigned int *NEK_RESTRICT index0,
942 const TData *NEK_RESTRICT basis0, const TData *NEK_RESTRICT basis1,
943 const TData *NEK_RESTRICT D0, const TData *NEK_RESTRICT D1,
944 const TData *NEK_RESTRICT w0, const TData *NEK_RESTRICT w1,
945 const TData *NEK_RESTRICT f0, const TData *NEK_RESTRICT f1,
946 const TData *NEK_RESTRICT nodToMod, const TData *NEK_RESTRICT df,
947 const TData *NEK_RESTRICT jac, const TData *NEK_RESTRICT diffCoeff,
948 const size_t varDiffCoeffSize, const unsigned int nhomo,
949 const TData *NEK_RESTRICT in, TData *NEK_RESTRICT out,
950 TData *NEK_RESTRICT wsp, unsigned char *shmemptr,
951 const TthreadBlock &threadBlock)
952{
953 static_assert(IsSizeParameter2D_v<TSizeParameter2D>,
954 "Template argument must be either of type "
955 "NonTemplatedSizeParameter2D or TemplatedSizeParameter2D.");
956
958
959 constexpr bool isNodal = SHAPE_TYPE == LibUtilities::NodalTri;
960
961 const unsigned int nm0 = sizeParam2D.nm0();
962 const unsigned int nm1 = sizeParam2D.nm1();
963 const unsigned int nmTot = sizeParam2D.nmTot();
964 const unsigned int nq0 = sizeParam2D.nq0();
965 const unsigned int nq1 = sizeParam2D.nq1();
966 const unsigned int nqTot = sizeParam2D.nqTot();
967
968 const unsigned int ndf = 2 * ncoord;
969 const unsigned int dfsize = DEFORMED ? nqTot : 1u;
970 const unsigned int jacsize = DEFORMED ? nqTot : 1u;
971
972 unsigned int wsp0Size = 0;
973 if constexpr (SHAPE_TYPE == LibUtilities::Quad)
974 {
975 wsp0Size = nq1;
976 }
977 else if constexpr (SHAPE_TYPE == LibUtilities::Tri ||
978 SHAPE_TYPE == LibUtilities::NodalTri)
979 {
980 wsp0Size = std::max(nq1, nm0);
981 }
982
983 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
984
985 TData *s_f0 = nullptr;
986 TData *s_f1 = nullptr;
987 TData *s_wsp = (TData *)shmemptr;
988
989 // Pre-compute factor.
990 if constexpr (SHAPE_TYPE == LibUtilities::Tri ||
991 SHAPE_TYPE == LibUtilities::NodalTri)
992 {
993 s_f0 = (TData *)shmemptr;
994 s_f1 = s_f0 + nq0;
995 s_wsp = s_f1 + nq1;
996
997 // Copy to shared memory.
998 LoadToSharedMemory(nq0, f0, s_f0, threadBlock);
999 LoadToSharedMemory(nq1, f1, s_f1, threadBlock);
1000
1001 localBarrier(threadBlock);
1002 }
1003
1004 size_t e = getGlobalIdx<0>(threadBlock);
1005 const unsigned int c = getBlockIdx<1>(threadBlock);
1006 const unsigned int ncomp = getBlockRange<1>(threadBlock);
1007
1008 DispatchWorkSpace(useSharedMemoryWsp, [&](const auto isShared) {
1009 // Workspace extent: the whole launch, or the thread block's warp
1010 // past the factors.
1011 TData *wspbase = isShared ? s_wsp : wsp;
1012 const size_t wspNelmt = isShared ? warpsize : nelmt * ncomp;
1013 const size_t derivNelmt = isShared ? warpsize : nelmt;
1014 while (e < nelmt)
1015 {
1016 const size_t ilane = e % warpsize;
1017 const size_t iwarp = e / warpsize;
1018 const TData *diffCoeffPtr =
1019 VARCOEFF ? diffCoeff +
1020 nqTot * (nelmt * (c % nhomo) + warpsize * iwarp)
1021 : diffCoeff;
1022 const TData *dfptr = df + ndf * dfsize * warpsize * iwarp;
1023 const TData *jacptr =
1024 DEFORMED ? jac + jacsize * warpsize * iwarp : jac + e;
1025 const TData *inptr = in + nmTot * (nelmt * c + warpsize * iwarp);
1026 TData *outptr = out + nmTot * (nelmt * c + warpsize * iwarp);
1027
1028 const size_t wspOffset =
1029 isShared ? 0 : nelmt * c + warpsize * iwarp;
1030 const size_t derivOffset =
1031 isShared ? 0 : ncoord * nelmt * c + warpsize * iwarp;
1032 TData *bwd = wspbase + nqTot * wspOffset;
1033 TData *deriv = wspbase + nqTot * wspNelmt + nqTot * derivOffset;
1034 TData *deriv0 = deriv;
1035 TData *deriv1 = deriv + nqTot * derivNelmt;
1036
1037 TData *modal =
1038 wspbase + (1 + ncoord) * nqTot * wspNelmt + nmTot * wspOffset;
1039 TData *wsp0 =
1040 wspbase +
1041 ((1 + ncoord) * nqTot + (isNodal ? nmTot : 0u)) * wspNelmt +
1042 wsp0Size * wspOffset;
1043
1044 if constexpr (isNodal)
1045 {
1046 MatVecKernel(ilane, nmTot, nodToMod, inptr, modal);
1047 }
1048
1049 BwdTrans2DSumFacKernel<SHAPE_TYPE, false>(
1050 ilane, nm0, nm1, nq0, nq1, isModified, basis0, basis1,
1051 isNodal ? modal : inptr, bwd, wsp0);
1052
1053 PhysDeriv2DSumFacKernel<SHAPE_TYPE, DEFORMED>(
1054 ilane, ncoord, nq0, nq1, derivNelmt * nqTot, D0, D1, s_f0, s_f1,
1055 dfptr, bwd, deriv);
1056 ApplyMetric2DSumFacKernel<SHAPE_TYPE, DEFORMED, VARCOEFF>(
1057 ilane, ncoord, nq0, nq1, derivNelmt * nqTot, w0, w1, s_f0, s_f1,
1058 dfptr, jacptr, diffCoeffPtr, varDiffCoeffSize, deriv, deriv0,
1059 deriv1);
1060 SumDerivTensor2DKernel<false, false>(ilane, nq0, nq1, D0, D1,
1061 deriv0, deriv1, bwd);
1062 IProductWRTBase2DSumFacKernel<SHAPE_TYPE, false, false>(
1063 ilane, nm0, nm1, nq0, nq1, isModified, basis0, basis1, bwd,
1064 isNodal ? modal : outptr, wsp0, (TData)1.0);
1065
1066 if constexpr (isNodal)
1067 {
1068 // Multiply by transpose nodToMod to transform coeffs.
1069 MatVecKernel<false, true>(ilane, nmTot, nodToMod, modal,
1070 outptr);
1071 }
1072
1073 e += getGlobalRange<0>(threadBlock);
1074 }
1075 });
1076}
1077
1078/**
1079 * @brief 3D launcher stringing together the five sum-factorised stages
1080 * on device.
1081 */
1082template <LibUtilities::ShapeType SHAPE_TYPE, typename Implementation,
1083 bool DEFORMED, bool VARCOEFF, typename TSizeParameter3D,
1084 typename TthreadBlock, typename TData, typename TUseSharedWsp,
1085 std::enable_if_t<std::is_same_v<Implementation, SumFac>, bool>
1086 Enable = true>
1088 (GetMaxThreadPerBlock<Implementation, TSizeParameter3D>()))
1090 const TSizeParameter3D sizeParam3D,
1091 [[maybe_unused]] const unsigned int ncoord, const size_t nelmt,
1092 [[maybe_unused]] const unsigned int elmtsPerBlock,
1093 const bool isModified, const TUseSharedWsp useSharedMemoryWsp,
1094 [[maybe_unused]] const unsigned int *NEK_RESTRICT index0,
1095 [[maybe_unused]] const unsigned int *NEK_RESTRICT index1,
1096 [[maybe_unused]] const unsigned int *NEK_RESTRICT index2,
1097 [[maybe_unused]] const unsigned int *NEK_RESTRICT index3,
1098 const TData *NEK_RESTRICT basis0, const TData *NEK_RESTRICT basis1,
1099 const TData *NEK_RESTRICT basis2, const TData *NEK_RESTRICT D0,
1100 const TData *NEK_RESTRICT D1, const TData *NEK_RESTRICT D2,
1101 const TData *NEK_RESTRICT w0, const TData *NEK_RESTRICT w1,
1102 const TData *NEK_RESTRICT w2, const TData *NEK_RESTRICT f0,
1103 const TData *NEK_RESTRICT f1, const TData *NEK_RESTRICT f1m,
1104 const TData *NEK_RESTRICT f2, const TData *NEK_RESTRICT nodToMod,
1105 const TData *NEK_RESTRICT df, const TData *NEK_RESTRICT jac,
1106 const TData *NEK_RESTRICT diffCoeff, const size_t varDiffCoeffSize,
1107 const unsigned int nhomo, const TData *NEK_RESTRICT in,
1108 TData *NEK_RESTRICT out, TData *NEK_RESTRICT wsp,
1109 unsigned char *shmemptr, const TthreadBlock &threadBlock)
1110{
1111 static_assert(IsSizeParameter3D_v<TSizeParameter3D>,
1112 "Template argument must be either of type "
1113 "NonTemplatedSizeParameter3D or TemplatedSizeParameter3D.");
1114
1116
1117 constexpr bool isNodal = SHAPE_TYPE == LibUtilities::NodalTet ||
1118 SHAPE_TYPE == LibUtilities::NodalPrism ||
1119 SHAPE_TYPE == LibUtilities::NodalPyr;
1120
1121 const unsigned int nm0 = sizeParam3D.nm0();
1122 const unsigned int nm1 = sizeParam3D.nm1();
1123 const unsigned int nm2 = sizeParam3D.nm2();
1124 const unsigned int nmTot = sizeParam3D.nmTot();
1125 const unsigned int nq0 = sizeParam3D.nq0();
1126 const unsigned int nq1 = sizeParam3D.nq1();
1127 const unsigned int nq2 = sizeParam3D.nq2();
1128 const unsigned int nqTot = sizeParam3D.nqTot();
1129
1130 constexpr unsigned int ndf = 9u;
1131 const unsigned int dfsize = DEFORMED ? nqTot : 1u;
1132 const unsigned int jacsize = DEFORMED ? nqTot : 1u;
1133
1134 unsigned int wsp0Size = 0, wsp1Size = 0;
1135 if constexpr (SHAPE_TYPE == LibUtilities::Hex)
1136 {
1137 wsp0Size = nq1 * nq2;
1138 wsp1Size = nq2;
1139 }
1140 else if constexpr (SHAPE_TYPE == LibUtilities::Tet ||
1141 SHAPE_TYPE == LibUtilities::NodalTet)
1142 {
1143 wsp0Size = nq1 * nq2;
1144 wsp1Size = std::max(nq2, nm0);
1145 }
1146 else if constexpr (SHAPE_TYPE == LibUtilities::Prism ||
1147 SHAPE_TYPE == LibUtilities::NodalPrism ||
1148 SHAPE_TYPE == LibUtilities::Pyr ||
1149 SHAPE_TYPE == LibUtilities::NodalPyr)
1150 {
1151 wsp0Size = std::max(nq1 * nq2, nm0 * nm1);
1152 wsp1Size = std::max(nq2, nm0);
1153 }
1154
1155 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
1156
1157 TData *s_f0 = nullptr;
1158 TData *s_f1 = nullptr;
1159 TData *s_f1m = nullptr;
1160 TData *s_f2 = nullptr;
1161 TData *s_wsp = (TData *)shmemptr;
1162
1163 // Pre-compute factor.
1164 if constexpr (SHAPE_TYPE == LibUtilities::Tet ||
1165 SHAPE_TYPE == LibUtilities::NodalTet)
1166 {
1167 s_f0 = (TData *)shmemptr;
1168 s_f1 = s_f0 + nq0;
1169 s_f1m = s_f1 + nq1;
1170 s_f2 = s_f1m + nq1;
1171 s_wsp = s_f2 + nq2;
1172
1173 // Copy to shared memory.
1174 LoadToSharedMemory(nq0, f0, s_f0, threadBlock);
1175 LoadToSharedMemory(nq1, f1, s_f1, threadBlock);
1176 LoadToSharedMemory(nq1, f1m, s_f1m, threadBlock);
1177 LoadToSharedMemory(nq2, f2, s_f2, threadBlock);
1178
1179 localBarrier(threadBlock);
1180 }
1181 else if constexpr (SHAPE_TYPE == LibUtilities::Prism ||
1182 SHAPE_TYPE == LibUtilities::NodalPrism)
1183 {
1184 s_f0 = (TData *)shmemptr;
1185 s_f2 = s_f0 + nq0;
1186 s_wsp = s_f2 + nq2;
1187
1188 // Copy to shared memory.
1189 LoadToSharedMemory(nq0, f0, s_f0, threadBlock);
1190 LoadToSharedMemory(nq2, f2, s_f2, threadBlock);
1191
1192 localBarrier(threadBlock);
1193 }
1194 else if constexpr (SHAPE_TYPE == LibUtilities::Pyr ||
1195 SHAPE_TYPE == LibUtilities::NodalPyr)
1196 {
1197 s_f0 = (TData *)shmemptr;
1198 s_f1 = s_f0 + nq0;
1199 s_f2 = s_f1 + nq1;
1200 s_wsp = s_f2 + nq2;
1201
1202 // Copy to shared memory.
1203 LoadToSharedMemory(nq0, f0, s_f0, threadBlock);
1204 LoadToSharedMemory(nq1, f1, s_f1, threadBlock);
1205 LoadToSharedMemory(nq2, f2, s_f2, threadBlock);
1206
1207 localBarrier(threadBlock);
1208 }
1209
1210 size_t e = getGlobalIdx<0>(threadBlock); // use size_t to prevent overflow
1211 const unsigned int c = getBlockIdx<1>(threadBlock);
1212 const unsigned int ncomp = getBlockRange<1>(threadBlock);
1213
1214 DispatchWorkSpace(useSharedMemoryWsp, [&](const auto isShared) {
1215 // Workspace extent: the whole launch, or the thread block's warp
1216 // past the factors.
1217 TData *wspbase = isShared ? s_wsp : wsp;
1218 const size_t wspNelmt = isShared ? warpsize : nelmt * ncomp;
1219 const size_t derivNelmt = isShared ? warpsize : nelmt;
1220 while (e < nelmt)
1221 {
1222 const size_t ilane = e % warpsize;
1223 const size_t iwarp = e / warpsize;
1224 const TData *diffCoeffPtr =
1225 VARCOEFF ? diffCoeff +
1226 nqTot * (nelmt * (c % nhomo) + warpsize * iwarp)
1227 : diffCoeff;
1228 const TData *dfptr = df + ndf * dfsize * warpsize * iwarp;
1229 const TData *jacptr =
1230 DEFORMED ? jac + jacsize * warpsize * iwarp : jac + e;
1231 const TData *inptr = in + nmTot * (nelmt * c + warpsize * iwarp);
1232 TData *outptr = out + nmTot * (nelmt * c + warpsize * iwarp);
1233
1234 const size_t wspOffset =
1235 isShared ? 0 : nelmt * c + warpsize * iwarp;
1236 const size_t derivOffset =
1237 isShared ? 0 : 3 * nelmt * c + warpsize * iwarp;
1238 TData *bwd = wspbase + nqTot * wspOffset;
1239 TData *deriv = wspbase + nqTot * wspNelmt + nqTot * derivOffset;
1240 TData *deriv0 = deriv;
1241 TData *deriv1 = deriv + nqTot * derivNelmt;
1242 TData *deriv2 = deriv + 2 * nqTot * derivNelmt;
1243
1244 TData *modal = wspbase + 4 * nqTot * wspNelmt + nmTot * wspOffset;
1245 TData *wsp0 = wspbase +
1246 (4 * nqTot + (isNodal ? nmTot : 0u)) * wspNelmt +
1247 wsp0Size * wspOffset;
1248 TData *wsp1 =
1249 wspbase +
1250 (4 * nqTot + (isNodal ? nmTot : 0u) + wsp0Size) * wspNelmt +
1251 wsp1Size * wspOffset;
1252
1253 if constexpr (isNodal)
1254 {
1255 MatVecKernel(ilane, nmTot, nodToMod, inptr, modal);
1256 }
1257
1258 BwdTrans3DSumFacKernel<SHAPE_TYPE, false>(
1259 ilane, nm0, nm1, nm2, nq0, nq1, nq2, isModified, basis0, basis1,
1260 basis2, isNodal ? modal : inptr, bwd, wsp0, wsp1);
1261 PhysDeriv3DSumFacKernel<SHAPE_TYPE, DEFORMED>(
1262 ilane, nq0, nq1, nq2, derivNelmt * nqTot, D0, D1, D2, s_f0,
1263 s_f1, s_f1m, s_f2, dfptr, bwd, deriv);
1264 ApplyMetric3DSumFacKernel<SHAPE_TYPE, DEFORMED, VARCOEFF>(
1265 ilane, nq0, nq1, nq2, derivNelmt * nqTot, w0, w1, w2, s_f0,
1266 s_f1, s_f1m, s_f2, dfptr, jacptr, diffCoeffPtr,
1267 varDiffCoeffSize, deriv, deriv0, deriv1, deriv2);
1268 SumDerivTensor3DKernel<false, false>(
1269 ilane, nq0, nq1, nq2, D0, D1, D2, deriv0, deriv1, deriv2, bwd);
1270 IProductWRTBase3DSumFacKernel<SHAPE_TYPE, false, false>(
1271 ilane, nm0, nm1, nm2, nq0, nq1, nq2, isModified, basis0, basis1,
1272 basis2, bwd, isNodal ? modal : outptr, wsp0, wsp1, (TData)1.0);
1273
1274 if constexpr (isNodal)
1275 {
1276 // Multiply by transpose nodToMod to transform coeffs.
1277 MatVecKernel<false, true>(ilane, nmTot, nodToMod, modal,
1278 outptr);
1279 }
1280
1281 e += getGlobalRange<0>(threadBlock);
1282 }
1283 });
1284}
1285
1286#endif
1287
1288} // namespace Nektar::MultiRegions::detail
#define NEK_RESTRICT
Definition Backends.hpp:254
#define NEK_DEVICE_INLINE
Definition Backends.hpp:283
#define NEK_DEVICE_KERNEL
Definition Backends.hpp:297
Device SumFac kernels of the backward transform: one element per thread, with the sum-factorisation i...
Device SumFac kernels of the inner product with the basis: one element per thread,...
Device SumFac kernels of the physical derivative: one element per warp lane.
std::map< int64_t, double > sum
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 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
static NEK_FORCE_INLINE void LaplacianKernelLauncher(const TSizeParameter1D sizeParam1D, const bool isModified, const unsigned int ncoord, const bool useDiffCoeff, const typename simd_type::scalarType *diffCoeff, const simd_type *varDiffCoeff, const size_t varDiffCoeffSize, const typename simd_type::scalarType *basis0, const typename simd_type::scalarType *D0, const typename simd_type::scalarType *w0, const simd_type *NtoM, const simd_type *NtoMTrans, const simd_type *jac, const simd_type *df, simd_type *deriv0, simd_type *bwd, const simd_type *in, simd_type *out)
1D launcher stringing together the five sum-factorised stages for one element group.
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 size_t nelmt
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const size_t const unsigned int const unsigned int const unsigned int const unsigned int const size_t const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TUseSharedWsp TData *NEK_RESTRICT const TData *NEK_RESTRICT TData *NEK_RESTRICT out
static NEK_FORCE_INLINE void MatVecKernel(const unsigned int n, const simd_type *Mat, const simd_type *in, simd_type *out)
static constexpr unsigned int warpSize
Definition Backends.hpp:143