Neko 1.99.7
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
opgrad_kernel.h
Go to the documentation of this file.
1#ifndef __MATH_OPGRAD_KERNEL_H__
2#define __MATH_OPGRAD_KERNEL_H__
3
4/*
5 Copyright (c) 2021-2023, The Neko Authors
6 All rights reserved.
7
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions
10 are met:
11
12 * Redistributions of source code must retain the above copyright
13 notice, this list of conditions and the following disclaimer.
14
15 * Redistributions in binary form must reproduce the above
16 copyright notice, this list of conditions and the following
17 disclaimer in the documentation and/or other materials provided
18 with the distribution.
19
20 * Neither the name of the authors nor the names of its
21 contributors may be used to endorse or promote products derived
22 from this software without specific prior written permission.
23
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 POSSIBILITY OF SUCH DAMAGE.
36*/
37
38#include "elem_block.h"
39
44template< typename T, const int LX, const int CHUNKS >
48 const T * __restrict__ u,
49 const T * __restrict__ dx,
50 const T * __restrict__ dy,
51 const T * __restrict__ dz,
52 const T * __restrict__ drdx,
53 const T * __restrict__ dsdx,
54 const T * __restrict__ dtdx,
55 const T * __restrict__ drdy,
56 const T * __restrict__ dsdy,
57 const T * __restrict__ dtdy,
58 const T * __restrict__ drdz,
59 const T * __restrict__ dsdz,
60 const T * __restrict__ dtdz,
61 const T * __restrict__ w3) {
62
63 __shared__ T shu[LX * LX * LX];
64
68
69
70 int i,j,k;
71
72 const int e = blockIdx.x;
73 const int iii = threadIdx.x;
74 const int nchunks = (LX * LX * LX - 1) / CHUNKS + 1;
75
76 if (iii < (LX * LX)) {
77 shdx[iii] = dx[iii];
78 shdy[iii] = dy[iii];
79 shdz[iii] = dz[iii];
80 }
81
82 j = iii;
83 while(j < (LX * LX * LX)) {
84 shu[j] = u[j + e * LX * LX * LX];
85 j = j + CHUNKS;
86 }
87
89
90 for (int n = 0; n < nchunks; n++) {
91 const int ijk = iii + n * CHUNKS;
92 const int jk = ijk / LX;
93 i = ijk - jk * LX;
94 k = jk / LX;
95 j = jk - k * LX;
96 if ( i < LX && j < LX && k < LX ) {
97 T rtmp = 0.0;
98 T stmp = 0.0;
99 T ttmp = 0.0;
100 for (int l = 0; l < LX; l++) {
101 rtmp += shdx[i + l * LX] * shu[l + j * LX + k * LX * LX];
102 stmp += shdy[j + l * LX] * shu[i + l * LX + k * LX * LX];
103 ttmp += shdz[k + l * LX] * shu[i + j * LX + l * LX * LX];
104 }
105
106 ux[ijk + e * LX * LX * LX] = w3[ijk]
107 * (drdx[ijk + e * LX * LX * LX] * rtmp
108 + dsdx[ijk + e * LX * LX * LX] * stmp
109 + dtdx[ijk + e * LX * LX * LX] * ttmp);
110
111 uy[ijk + e * LX * LX * LX] = w3[ijk]
112 * (drdy[ijk + e * LX * LX * LX] * rtmp
113 + dsdy[ijk + e * LX * LX * LX] * stmp
114 + dtdy[ijk + e * LX * LX * LX] * ttmp);
115
116 uz[ijk + e * LX * LX * LX] = w3[ijk]
117 * (drdz[ijk + e * LX * LX * LX] * rtmp
118 + dsdz[ijk + e * LX * LX * LX] * stmp
119 + dtdz[ijk + e * LX * LX * LX] * ttmp);
120
121 }
122 }
123
124}
125
126template< typename T, const int LX, const int EB >
131 const T * __restrict__ u,
145 const int nelv) {
146
147 /* One slice per element in the block */
148 __shared__ T shu[EB * LX * LX];
149
150 /* Element independent, one copy per block */
154
155 static_assert(sizeof(shu) + sizeof(shdx) + sizeof(shdy) + sizeof(shdz)
157 "kstep block exceeds the LDS budget");
158
159 /* Threads past the last element still have to reach the barriers in the k
160 loop, so clamp their reads and drop their stores rather than returning
161 early. At EB == 1 all of this is constant folded away */
162 const int eb = (EB == 1) ? 0 : threadIdx.z;
163 const int e_blk = blockIdx.x * EB + eb;
164 const bool active = (EB == 1) ? true : (e_blk < nelv);
165 const int e = active ? e_blk : (nelv - 1);
166 const int j = threadIdx.y;
167 const int i = threadIdx.x;
168 const int ij = i + j * LX;
169 const int sh = eb * LX * LX;
170 const int ele = e*LX*LX*LX;
171
172 if (eb == 0) {
173 shdx[ij] = dx[ij];
174 shdy[ij] = dy[ij];
175 shdz[ij] = dz[ij];
176 }
177
179
180#pragma unroll LX
181 for (int k = 0; k < LX; ++k) {
182 ru[k] = u[ij + k*LX*LX + ele];
183 }
184
186
187 #pragma unroll
188 for (int k = 0; k < LX; ++k) {
189 const int ijk = ij + k*LX*LX;
190 const T W3 = w3[ijk];
191 T ttmp = 0.0;
192 shu[sh + ij] = ru[k];
193#pragma unroll
194 for (int l = 0; l < LX; l++) {
195 ttmp += shdz[k+l*LX] * ru[l];
196 }
198
199 T rtmp = 0.0;
200 T stmp = 0.0;
201#pragma unroll
202 for (int l = 0; l < LX; l++) {
203 rtmp += shdx[i+l*LX] * shu[sh + l+j*LX];
204 stmp += shdy[j+l*LX] * shu[sh + i+l*LX];
205 }
206
207 if (active) {
208 ux[ijk + ele] = W3 * (drdx[ijk + ele] * rtmp
209 + dsdx[ijk + ele] * stmp
210 + dtdx[ijk + ele] * ttmp);
211
212 uy[ijk + ele] = W3 * (drdy[ijk + ele] * rtmp
213 + dsdy[ijk + ele] * stmp
214 + dtdy[ijk + ele] * ttmp);
215
216 uz[ijk + ele] = W3 * (drdz[ijk + ele] * rtmp
217 + dsdz[ijk + ele] * stmp
218 + dtdz[ijk + ele] * ttmp);
219 }
221 }
222}
223
224
225#endif // __MATH_OPGRAD_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]
#define NEKO_EB_BOUNDS(NT)
Definition elem_block.h:95
const bool active
__global__ void T *__restrict__ 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__ const T *__restrict__ dtdz
__global__ void T *__restrict__ uy
__global__ void opgrad_kernel_1d(T *__restrict__ ux, T *__restrict__ uy, T *__restrict__ uz, const T *__restrict__ u, const T *__restrict__ dx, const T *__restrict__ dy, const T *__restrict__ dz, const T *__restrict__ drdx, const T *__restrict__ dsdx, const T *__restrict__ dtdx, const T *__restrict__ drdy, const T *__restrict__ dsdy, const T *__restrict__ dtdy, const T *__restrict__ drdz, const T *__restrict__ dsdz, const T *__restrict__ dtdz, const T *__restrict__ w3)
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ dx
const int sh
__global__ void T *__restrict__ T *__restrict__ uz
__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__ 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__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const int nelv
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dz
T ru[LX]
const int eb
__shared__ T shdy[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__ drdy
__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__ drdz
const int i
__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__ dtdx
const int ij
__shared__ T shdx[LX *LX]
const int e
__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__ dtdy
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ drdx
__shared__ T shdz[LX *LX]
const int e_blk
__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__ dsdy
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dy
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ u
const int ele
__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__ w3
const int j
__syncthreads()
#define NEKO_EB_MAX_LDS
Definition elem_block.h:62