Neko 1.99.7
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
dudxyz_kernel.h
Go to the documentation of this file.
1#ifndef __MATH_DUDXYZ_KERNEL_H__
2#define __MATH_DUDXYZ_KERNEL_H__
3
4#include "elem_block.h"
5/*
6 Copyright (c) 2021-2023, The Neko Authors
7 All rights reserved.
8
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions
11 are met:
12
13 * Redistributions of source code must retain the above copyright
14 notice, this list of conditions and the following disclaimer.
15
16 * Redistributions in binary form must reproduce the above
17 copyright notice, this list of conditions and the following
18 disclaimer in the documentation and/or other materials provided
19 with the distribution.
20
21 * Neither the name of the authors nor the names of its
22 contributors may be used to endorse or promote products derived
23 from this software without specific prior written permission.
24
25 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 POSSIBILITY OF SUCH DAMAGE.
37*/
38
43template< typename T, const int LX, const int CHUNKS >
45 const T * __restrict__ u,
46 const T * __restrict__ dr,
47 const T * __restrict__ ds,
48 const T * __restrict__ dt,
49 const T * __restrict__ dx,
50 const T * __restrict__ dy,
51 const T * __restrict__ dz,
52 const T * __restrict__ jacinv) {
53
54 __shared__ T shu[LX * LX * LX];
55 __shared__ T shdr[LX * LX * LX];
56 __shared__ T shds[LX * LX * LX];
57 __shared__ T shdt[LX * LX * LX];
58
62
64
65 const int e = blockIdx.x;
66 const int iii = threadIdx.x;
67 const int nchunks = (LX * LX * LX - 1) / CHUNKS + 1;
68
69 if (iii < (LX * LX)) {
70 shdx[iii] = dx[iii];
71 shdy[iii] = dy[iii];
72 shdz[iii] = dz[iii];
73 }
74
75 int l = iii;
76 while(l < (LX * LX * LX)) {
77 shu[l] = u[l + e * LX * LX * LX];
78 shdr[l] = dr[l + e * LX * LX * LX];
79 shds[l] = ds[l + e * LX * LX * LX];
80 shdt[l] = dt[l + e * LX * LX * LX];
81 shjacinv[l] = jacinv[l + e * LX * LX * LX];
82 l = l + CHUNKS;
83 }
84
86
87 for (int n = 0; n < nchunks; n++) {
88 const int ijk = iii + n * CHUNKS;
89 const int jk = ijk / LX;
90 const int i = ijk - jk * LX;
91 const int k = jk / LX;
92 const int j = jk - k * LX;
93 if ( i < LX && j < LX && k < LX) {
94 T rtmp = 0.0;
95 T stmp = 0.0;
96 T ttmp = 0.0;
97 for (int l = 0; l < LX; l++) {
98 rtmp += shdx[i + l * LX] * shu[l + j * LX + k * LX * LX];
99 stmp += shdy[j + l * LX] * shu[i + l * LX + k * LX * LX];
100 ttmp += shdz[k + l * LX] * shu[i + j * LX + l * LX * LX];
101 }
102 du[ijk + e * LX * LX * LX] = ((rtmp * shdr[ijk])
103 + (stmp * shds[ijk])
104 + (ttmp * shdt[ijk]))
105 * shjacinv[ijk];
106
107 }
108 }
109}
110
111template< typename T, const int LX, const int EB >
114 const T * __restrict__ u,
122 const int nelv) {
123
124 __shared__ T shu[EB * LX * LX];
125
129
130 static_assert(sizeof(shu) +
131 sizeof(shdx) +
132 sizeof(shdy) +
133 sizeof(shdz)
135 "kstep block exceeds the shared memory budget");
136
137 const int eb = (EB == 1) ? 0 : threadIdx.z;
138 const int e_blk = blockIdx.x * EB + eb;
139 /* Threads past the last element still have to reach the barriers in
140 the k loop, so clamp their reads and drop their stores rather than
141 returning early. At EB == 1 this all constant folds away */
142 const bool active = (EB == 1) ? true : (e_blk < nelv);
143 const int e = active ? e_blk : (nelv - 1);
144 const int sh = eb * LX * LX;
145 const int j = threadIdx.y;
146 const int i = threadIdx.x;
147 const int ij = i + j * LX;
148 const int ele = e*LX*LX*LX;
149
150 if (eb == 0) {
151 shdx[ij] = dx[ij];
152 shdy[ij] = dy[ij];
153 shdz[ij] = dz[ij];
154 }
155
161
162 #pragma unroll LX
163 for (int k = 0; k < LX; ++k) {
164 ru[k] = u[ij + k*LX*LX + ele];
165 rdr[k] = dr[ij + k*LX*LX + ele];
166 rds[k] = ds[ij + k*LX*LX + ele];
167 rdt[k] = dt[ij + k*LX*LX + ele];
168 rjacinv[k] = jacinv[ij + k*LX*LX + ele];
169 }
170
172
173 #pragma unroll
174 for (int k = 0; k < LX; ++k) {
175 const int ijk = ij + k*LX*LX;
176 T ttmp = 0.0;
177 shu[sh + ij] = ru[k];
178#pragma unroll
179 for (int l = 0; l < LX; l++) {
180 ttmp += shdz[k+l*LX] * ru[l];
181 }
183
184 T rtmp = 0.0;
185 T stmp = 0.0;
186#pragma unroll
187 for (int l = 0; l < LX; l++) {
188 rtmp += shdx[i+l*LX] * shu[sh + l+j*LX];
189 stmp += shdy[j+l*LX] * shu[sh + i+l*LX];
190 }
191
192 if (active) {
193 du[ijk + ele] = rjacinv[k] * ((rtmp * rdr[k])
194 + (stmp * rds[k])
195 + (ttmp * rdt[k]));
196 }
198 }
199}
200
201#endif // __MATH_DUDXYZ_KERNEL_H__
__global__ void ale_add_kinematics_kernel(const int n, T *__restrict__ wx, T *__restrict__ wy, T *__restrict__ wz, const T *__restrict__ x_ref, const T *__restrict__ y_ref, const T *__restrict__ z_ref, const T *__restrict__ phi, const T *__restrict__ x, const T *__restrict__ y, const T *__restrict__ z, const kinematics_params_t kin_params)
__shared__ T shu[LX *LX]
const bool active
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dz
__global__ void const T *__restrict__ const T *__restrict__ dr
const int sh
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dy
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ ds
T ru[LX]
const int eb
__shared__ T shdy[LX *LX]
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dt
T rdt[LX]
const int i
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dx
const int ij
T rjacinv[LX]
__shared__ T shdx[LX *LX]
const int e
T rds[LX]
__shared__ T shdz[LX *LX]
const int e_blk
__global__ void dudxyz_kernel_1d(T *__restrict__ du, const T *__restrict__ u, const T *__restrict__ dr, const T *__restrict__ ds, const T *__restrict__ dt, const T *__restrict__ dx, const T *__restrict__ dy, const T *__restrict__ dz, const T *__restrict__ jacinv)
const int ele
__global__ void const T *__restrict__ u
__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__ const int nelv
const int j
T rdr[LX]
__syncthreads()
__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__ jacinv
#define NEKO_EB_MAX_SMEM
Definition elem_block.h:60
#define NEKO_EB_BOUNDS(NT)
Definition elem_block.h:95