Neko 1.99.11
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
ax_helm_svv_factorized_full_kernel.h
Go to the documentation of this file.
1#ifndef __MATH_AX_HELM_SVV_FACTORIZED_FULL_KERNEL_H__
2#define __MATH_AX_HELM_SVV_FACTORIZED_FULL_KERNEL_H__
3/*
4 Copyright (c) 2026, The Neko Authors
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions
9 are met:
10
11 * Redistributions of source code must retain the above copyright
12 notice, this list of conditions and the following disclaimer.
13
14 * Redistributions in binary form must reproduce the above
15 copyright notice, this list of conditions and the following
16 disclaimer in the documentation and/or other materials provided
17 with the distribution.
18
19 * Neither the name of the authors nor the names of its
20 contributors may be used to endorse or promote products derived
21 from this software without specific prior written permission.
22
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 POSSIBILITY OF SUCH DAMAGE.
35*/
36
55
61template< typename T >
62__device__ __forceinline__ void
63ax_helm_svv_factorized_stress_flux(const T ur, const T us, const T ut,
64 const T vr, const T vs, const T vt,
65 const T wr, const T ws, const T wt,
66 const T drdx, const T drdy, const T drdz,
67 const T dsdx, const T dsdy, const T dsdz,
68 const T dtdx, const T dtdy, const T dtdz,
69 const T dj,
70 T & shur, T & shus,
71 T & shvr, T & shvs,
72 T & shwr, T & shws,
73 T & rut, T & rvt, T & rwt) {
74
75 const T u1 = ur * drdx + us * dsdx + ut * dtdx;
76 const T u2 = ur * drdy + us * dsdy + ut * dtdy;
77 const T u3 = ur * drdz + us * dsdz + ut * dtdz;
78
79 const T v1 = vr * drdx + vs * dsdx + vt * dtdx;
80 const T v2 = vr * drdy + vs * dsdy + vt * dtdy;
81 const T v3 = vr * drdz + vs * dsdz + vt * dtdz;
82
83 const T w1 = wr * drdx + ws * dsdx + wt * dtdx;
84 const T w2 = wr * drdy + ws * dsdy + wt * dtdy;
85 const T w3 = wr * drdz + ws * dsdz + wt * dtdz;
86
87 const T s11 = dj * (u1 + u1);
88 const T s22 = dj * (v2 + v2);
89 const T s33 = dj * (w3 + w3);
90 const T s12 = dj * (u2 + v1);
91 const T s13 = dj * (u3 + w1);
92 const T s23 = dj * (v3 + w2);
93
94 shur = drdx * s11 + drdy * s12 + drdz * s13;
95 shus = dsdx * s11 + dsdy * s12 + dsdz * s13;
96 rut = dtdx * s11 + dtdy * s12 + dtdz * s13;
97
98 shvr = drdx * s12 + drdy * s22 + drdz * s23;
99 shvs = dsdx * s12 + dsdy * s22 + dsdz * s23;
100 rvt = dtdx * s12 + dtdy * s22 + dtdz * s23;
101
102 shwr = drdx * s13 + drdy * s23 + drdz * s33;
103 shws = dsdx * s13 + dsdy * s23 + dsdz * s33;
104 rwt = dtdx * s13 + dtdy * s23 + dtdz * s33;
105}
106
107template< typename T, const int LX, const bool PAD >
108__global__ void __launch_bounds__(LX*LX,3)
109ax_helm_svv_factorized_full_kernel(T * __restrict__ au,
110 T * __restrict__ av,
111 T * __restrict__ aw,
112 const T * __restrict__ u,
113 const T * __restrict__ v,
114 const T * __restrict__ w,
115 const T * __restrict__ dx,
116 const T * __restrict__ dy,
117 const T * __restrict__ dz,
118 const T * __restrict__ h1,
119 const T * __restrict__ br,
120 const T * __restrict__ bs,
121 const T * __restrict__ bt,
122 const T * __restrict__ h1_svv,
123 const T * __restrict__ drdx,
124 const T * __restrict__ drdy,
125 const T * __restrict__ drdz,
126 const T * __restrict__ dsdx,
127 const T * __restrict__ dsdy,
128 const T * __restrict__ dsdz,
129 const T * __restrict__ dtdx,
130 const T * __restrict__ dtdy,
131 const T * __restrict__ dtdz,
132 const T * __restrict__ jacinv,
133 const T * __restrict__ weight3) {
134
135 constexpr int P = PAD ? LX + 1 : LX;
136
137 __shared__ T shdx[LX * P];
138 __shared__ T shdy[LX * P];
139 __shared__ T shdz[LX * P];
140 __shared__ T shbr[LX * P];
141 __shared__ T shbs[LX * P];
142 __shared__ T shbt[LX * P];
143
144 __shared__ T shu[LX * P];
145 __shared__ T shv[LX * P];
146 __shared__ T shw[LX * P];
147
148 /* r-fluxes are only accessed along the fastest dimension */
149 __shared__ T shur[LX * LX];
150 __shared__ T shus[LX * P];
151 __shared__ T shvr[LX * LX];
152 __shared__ T shvs[LX * P];
153 __shared__ T shwr[LX * LX];
154 __shared__ T shws[LX * P];
155
156 __shared__ T shur_svv[LX * LX];
157 __shared__ T shus_svv[LX * P];
158 __shared__ T shvr_svv[LX * LX];
159 __shared__ T shvs_svv[LX * P];
160 __shared__ T shwr_svv[LX * LX];
161 __shared__ T shws_svv[LX * P];
162
163 T ru[LX];
164 T rv[LX];
165 T rw[LX];
166
167 T ruw[LX];
168 T rvw[LX];
169 T rww[LX];
170
173
174 const int e = blockIdx.x;
175 const int j = threadIdx.y;
176 const int i = threadIdx.x;
177 const int ij = i + j*LX;
178 const int ij_p = i + j*P;
179 const int ele = e*LX*LX*LX;
180
181 shdx[ij_p] = dx[ij];
182 shdy[ij_p] = dy[ij];
183 shdz[ij_p] = dz[ij];
184 shbr[ij_p] = br[ij];
185 shbs[ij_p] = bs[ij];
186 shbt[ij_p] = bt[ij];
187
188#pragma unroll
189 for (int k = 0; k < LX; ++k) {
190 ru[k] = u[ij + k*LX*LX + ele];
191 ruw[k] = 0.0;
192
193 rv[k] = v[ij + k*LX*LX + ele];
194 rvw[k] = 0.0;
195
196 rw[k] = w[ij + k*LX*LX + ele];
197 rww[k] = 0.0;
198 }
199
201#pragma unroll
202 for (int k = 0; k < LX; ++k) {
203 const int ijk = ij + k*LX*LX;
204 const T drdx_local = drdx[ijk+ele];
205 const T drdy_local = drdy[ijk+ele];
206 const T drdz_local = drdz[ijk+ele];
207 const T dsdx_local = dsdx[ijk+ele];
208 const T dsdy_local = dsdy[ijk+ele];
209 const T dsdz_local = dsdz[ijk+ele];
210 const T dtdx_local = dtdx[ijk+ele];
211 const T dtdy_local = dtdy[ijk+ele];
212 const T dtdz_local = dtdz[ijk+ele];
213 const T wj = weight3[ijk] * jacinv[ijk+ele];
214
215 shu[ij_p] = ru[k];
216 shv[ij_p] = rv[k];
217 shw[ij_p] = rw[k];
219
220 /* Standard contribution */
221 {
222 T uttmp = 0.0;
223 T vttmp = 0.0;
224 T wttmp = 0.0;
225 T urtmp = 0.0;
226 T ustmp = 0.0;
227 T vrtmp = 0.0;
228 T vstmp = 0.0;
229 T wrtmp = 0.0;
230 T wstmp = 0.0;
231#pragma unroll
232 for (int l = 0; l < LX; l++) {
233 uttmp += shdz[k+l*P] * ru[l];
234 vttmp += shdz[k+l*P] * rv[l];
235 wttmp += shdz[k+l*P] * rw[l];
236
237 urtmp += shdx[i+l*P] * shu[l+j*P];
238 ustmp += shdy[j+l*P] * shu[i+l*P];
239 vrtmp += shdx[i+l*P] * shv[l+j*P];
240 vstmp += shdy[j+l*P] * shv[i+l*P];
241 wrtmp += shdx[i+l*P] * shw[l+j*P];
242 wstmp += shdy[j+l*P] * shw[i+l*P];
243 }
244
246 urtmp, ustmp, uttmp, vrtmp, vstmp, vttmp, wrtmp, wstmp, wttmp,
247 drdx_local, drdy_local, drdz_local,
248 dsdx_local, dsdy_local, dsdz_local,
249 dtdx_local, dtdy_local, dtdz_local,
250 h1[ijk+ele] * wj,
251 shur[ij], shus[ij_p], shvr[ij], shvs[ij_p], shwr[ij], shws[ij_p],
252 rut, rvt, rwt);
253 }
254
255 /* Factorized SVV contribution */
256 {
257 T uttmp = 0.0;
258 T vttmp = 0.0;
259 T wttmp = 0.0;
260 T urtmp = 0.0;
261 T ustmp = 0.0;
262 T vrtmp = 0.0;
263 T vstmp = 0.0;
264 T wrtmp = 0.0;
265 T wstmp = 0.0;
266#pragma unroll
267 for (int l = 0; l < LX; l++) {
268 uttmp += shbt[k+l*P] * ru[l];
269 vttmp += shbt[k+l*P] * rv[l];
270 wttmp += shbt[k+l*P] * rw[l];
271
272 urtmp += shbr[i+l*P] * shu[l+j*P];
273 ustmp += shbs[j+l*P] * shu[i+l*P];
274 vrtmp += shbr[i+l*P] * shv[l+j*P];
275 vstmp += shbs[j+l*P] * shv[i+l*P];
276 wrtmp += shbr[i+l*P] * shw[l+j*P];
277 wstmp += shbs[j+l*P] * shw[i+l*P];
278 }
279
281 urtmp, ustmp, uttmp, vrtmp, vstmp, vttmp, wrtmp, wstmp, wttmp,
282 drdx_local, drdy_local, drdz_local,
283 dsdx_local, dsdy_local, dsdz_local,
284 dtdx_local, dtdy_local, dtdz_local,
285 h1_svv[ijk+ele] * wj,
290 }
291
293
294 T uwijke = 0.0;
295 T vwijke = 0.0;
296 T wwijke = 0.0;
297#pragma unroll
298 for (int l = 0; l < LX; l++) {
299 const T dxt = shdx[l+i*P];
300 const T dyt = shdy[l+j*P];
301 const T brt = shbr[l+i*P];
302 const T bst = shbs[l+j*P];
303 const T dzt = shdz[k+l*P];
304 const T btt = shbt[k+l*P];
305
306 uwijke += shur[l+j*LX] * dxt + shur_svv[l+j*LX] * brt
307 + shus[i+l*P] * dyt + shus_svv[i+l*P] * bst;
308 ruw[l] += rut * dzt + rut_svv * btt;
309
310 vwijke += shvr[l+j*LX] * dxt + shvr_svv[l+j*LX] * brt
311 + shvs[i+l*P] * dyt + shvs_svv[i+l*P] * bst;
312 rvw[l] += rvt * dzt + rvt_svv * btt;
313
314 wwijke += shwr[l+j*LX] * dxt + shwr_svv[l+j*LX] * brt
315 + shws[i+l*P] * dyt + shws_svv[i+l*P] * bst;
316 rww[l] += rwt * dzt + rwt_svv * btt;
317 }
318 ruw[k] += uwijke;
319 rvw[k] += vwijke;
320 rww[k] += wwijke;
321 }
322
323#pragma unroll
324 for (int k = 0; k < LX; ++k) {
325 au[ij + k*LX*LX + ele] = ruw[k];
326 av[ij + k*LX*LX + ele] = rvw[k];
327 aw[ij + k*LX*LX + ele] = rww[k];
328 }
329}
330
331#endif // __MATH_AX_HELM_SVV_FACTORIZED_FULL_KERNEL_H__
__shared__ T shv[EB *LX *LX]
const int ij_p
__shared__ T shdy[LX *LX]
T rvw[LX]
__global__ void T *__restrict__ T *__restrict__ aw
__shared__ T shu[EB *LX *LX]
__shared__ T shdz[LX *LX]
T rww[LX]
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ w
const int i
const int ij
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dz
__global__ void const T *__restrict__ const T *__restrict__ dx
__global__ void const T *__restrict__ u
__shared__ T shus[EB *LX *LX]
const int e
__global__ void T *__restrict__ av
__shared__ T shur[EB *LX *LX]
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ dy
T ruw[LX]
__shared__ T shvs[EB *LX *LX]
T ru[LX]
__shared__ T shw[EB *LX *LX]
const int ele
__shared__ T shwr[EB *LX *LX]
T rw[LX]
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ v
const int j
__shared__ T shvr[EB *LX *LX]
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ h1
__shared__ T shws[EB *LX *LX]
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dtdy
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dtdx
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ weight3
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dtdz
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ jacinv
shdx[ij]
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dsdz
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ drdz
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ drdx
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dsdx
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dsdy
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ drdy
__shared__ T shvs_svv[LX *P]
__shared__ T shws_svv[LX *P]
__shared__ T shvr_svv[LX *LX]
__shared__ T shbt[LX *P]
__device__ __forceinline__ void ax_helm_svv_factorized_stress_flux(const T ur, const T us, const T ut, const T vr, const T vs, const T vt, const T wr, const T ws, const T wt, const T drdx, const T drdy, const T drdz, const T dsdx, const T dsdy, const T dsdz, const T dtdx, const T dtdy, const T dtdz, const T dj, T &shur, T &shus, T &shvr, T &shvs, T &shwr, T &shws, T &rut, T &rvt, T &rwt)
__shared__ T shwr_svv[LX *LX]
__global__ void __launch_bounds__(LX *LX, 3) ax_helm_svv_factorized_full_kernel(T *__restrict__ au
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ h1_svv
__shared__ T shbr[LX *P]
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ bt
__shared__ T shur_svv[LX *LX]
__syncthreads()
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ br
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ bs
__shared__ T shus_svv[LX *P]
__shared__ T shbs[LX *P]
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dyt
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dzt
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dxt
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ w3