Nektar++
Loading...
Searching...
No Matches
PhysDerivBlockOpDeviceStdMatKernels.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: PhysDerivBlockOpDeviceStdMatKernels.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: Chain-rule kernels of the device StdMat physical
32// derivative.
33///////////////////////////////////////////////////////////////////////////////
34
35/**
36 * @file PhysDerivBlockOpDeviceStdMatKernels.hpp
37 * @brief Chain-rule kernels of the device StdMat physical derivative:
38 * contract standard-region derivatives with the element's geometric
39 * derivative factors, one work item per point of the block.
40 *
41 * @details
42 * These perform the chain rule
43 * \f[ \frac{\partial u}{\partial x_k}
44 * = \sum_{d} \frac{\partial \xi_d}{\partial x_k}
45 * \frac{\partial u}{\partial \xi_d}, \f]
46 * over the whole block at once: one work item per (element, point)
47 * pair on the first grid dimension, the homogeneous planes (and, for
48 * MultiplyByDerivFactorKernel, the components) on the further grid
49 * dimensions of the same launch.
50 *
51 * The derivative factors are laid out transposed (DerivFactorKey with
52 * `transpose = true`, see GeometricDataWarehouse.hpp): per element
53 * the `ndf = coordDim * dimension` factors form contiguous planes, of
54 * one value each for a regular element and of nqTot values each for a
55 * deformed one. Hence the two branches index differently, the deformed
56 * one reaching factor `k * dimension + d` of element @em e at
57 * `ndf * nqTot * e + nqTot * (k * dimension + d) + i` -- written as
58 * `(ndf - 1) * nqTot * e + ...` because the within-plane flat index
59 * added last, `idx`, already carries one `nqTot * e`.
60 *
61 * MultiplyByDerivFactorKernel produces all `coordDim` components at once
62 * and is used by PhysDeriv itself (and by the AdvectionDealias StdMat
63 * implementation).
64 */
65
66#pragma once
67
69
71{
72
73#if defined(NEKTAR_ENABLE_DEVICE) && defined(DEVICE_COMPILE_ONLY)
74/**
75 * @brief Contract the standard-region derivatives of a whole block into
76 * all @p ncoord Cartesian derivatives.
77 *
78 * Safe to run in place (@p out equal to @p in, as PhysDeriv does): every
79 * work item forms all @p ncoord results in registers before storing any
80 * of them.
81 *
82 * The second grid dimension picks the homogeneous plane and the third the
83 * component. Each component holds @p outDim slots of one plane per
84 * homogeneous plane, so the pair selects the slot
85 * `outDim * nhomo * c + m`, `nqTot * nelmt` values apart, in both @p in
86 * and @p out; the same geometry serves every plane.
87 *
88 * @tparam DEFORMED Derivative factors vary point by point.
89 * @tparam TthreadBlock Back-end thread-block handle type.
90 * @tparam TData Floating-point type of the field data.
91 *
92 * @param nqTot Quadrature points per element.
93 * @param ncoord Cartesian components to produce (coordDim); at
94 * most 3, the size of the per-point register
95 * buffer.
96 * @param dimension Standard directions to contract over.
97 * @param outDim Direction slots per component: coordDim, or 3 in
98 * 3DH1, the third left to the z-derivative.
99 * @param nelmt Elements in the block, including padding.
100 * @param inoffset Stride between the standard-direction planes of
101 * @p in.
102 * @param outoffset Stride between the Cartesian planes of @p out.
103 * @param dfptr Derivative factors of the block, transposed
104 * layout.
105 * @param in Standard-direction derivatives, plane @em d at
106 * `d * inoffset`.
107 * @param out Cartesian derivatives, plane @em k written at
108 * `k * outoffset`.
109 * @param threadBlock Thread-block handle supplied by the launcher macro.
110 */
111template <bool DEFORMED, typename TthreadBlock, typename TData>
113 const unsigned nqTot, const unsigned ncoord, const unsigned dimension,
114 const unsigned outDim, const size_t nelmt, const size_t inoffset,
115 const size_t outoffset, const TData *dfptr, const TData *in, TData *out,
116 const TthreadBlock &threadBlock)
117{
118 const auto ndf = ncoord * dimension;
119 const size_t nsize = nqTot * nelmt;
120
121 size_t idx = getGlobalIdx<0>(threadBlock);
122 const unsigned int m = getBlockIdx<1>(threadBlock);
123 const unsigned int c = getBlockIdx<2>(threadBlock);
124 const unsigned int nmode = getBlockRange<1>(threadBlock);
125 const TData *inptr = in + nsize * (outDim * nmode * c + m);
126 TData *outptr = out + nsize * (outDim * nmode * c + m);
127 while (idx < nsize)
128 {
129 const size_t e = idx / nqTot;
130
131 TData tmp[3];
132 if constexpr (DEFORMED)
133 {
134 for (unsigned int k = 0; k < ncoord; k++)
135 {
136 tmp[k] = dfptr[(ndf - 1) * nqTot * e + nqTot * (k * dimension) +
137 idx] *
138 inptr[idx];
139 for (unsigned int d = 1; d < dimension; d++)
140 {
141 tmp[k] += dfptr[(ndf - 1) * nqTot * e +
142 nqTot * (k * dimension + d) + idx] *
143 inptr[idx + d * inoffset];
144 }
145 }
146 }
147 else
148 {
149 for (unsigned int k = 0; k < ncoord; k++)
150 {
151 tmp[k] = dfptr[(ndf * e + k * dimension)] * inptr[idx];
152 for (unsigned int d = 1; d < dimension; d++)
153 {
154 tmp[k] += dfptr[(ndf * e + k * dimension + d)] *
155 inptr[idx + d * inoffset];
156 }
157 }
158 }
159
160 for (unsigned int k = 0; k < ncoord; k++)
161 {
162 outptr[k * outoffset + idx] = tmp[k];
163 }
164
165 idx += getGlobalRange<0>(threadBlock);
166 }
167}
168#endif
169
170} // namespace Nektar::MultiRegions::detail
#define NEK_DEVICE_KERNEL
Definition Backends.hpp:297
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const size_t const unsigned int const unsigned int const unsigned int const unsigned int const size_t const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TUseSharedWsp TData *NEK_RESTRICT const TData *NEK_RESTRICT TData *NEK_RESTRICT const bool const bool unsigned char const TthreadBlock & threadBlock
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const size_t const unsigned int const unsigned int const unsigned int const unsigned int const size_t const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TUseSharedWsp TData *NEK_RESTRICT const TData *NEK_RESTRICT in
static NEK_FORCE_INLINE void MultiplyByDerivFactorKernel(const unsigned int nqTot, const unsigned int ncoord, const unsigned int dimension, const size_t nelmt, const size_t inoffset, const size_t outoffset, const TData *dfptr, const TData *inptr, TData *outptr)
Contract the standard-region derivatives of a lane group into all ncoord Cartesian derivatives.
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 > d(NPUPPER *NPUPPER)