Neko 1.99.7
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
convect_scalar_kernel.h
Go to the documentation of this file.
1#ifndef __MATH_CONVECT_SCALAR_KERNEL_H__
2#define __MATH_CONVECT_SCALAR_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 >
46 const T * __restrict__ u,
47 const T * __restrict__ cr,
48 const T * __restrict__ cs,
49 const T * __restrict__ ct,
50 const T * __restrict__ dx,
51 const T * __restrict__ dy,
52 const T * __restrict__ dz) {
53
54 __shared__ T shu[LX * LX * LX];
55
56 __shared__ T shcr[LX * LX * LX];
57 __shared__ T shcs[LX * LX * LX];
58 __shared__ T shct[LX * LX * LX];
59
63
64 const int e = blockIdx.x;
65 const int iii = threadIdx.x;
66 const int nchunks = (LX * LX * LX - 1) / CHUNKS + 1;
67 const int ele = e*LX*LX*LX;
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 + ele];
78
79 shcr[l] = cr[l + ele];
80 shcs[l] = cs[l + ele];
81 shct[l] = ct[l + ele];
82
83 l = l + CHUNKS;
84 }
85
87
88 for (int n = 0; n < nchunks; n++) {
89 const int ijk = iii + n * CHUNKS;
90 const int jk = ijk / LX;
91 const int i = ijk - jk * LX;
92 const int k = jk / LX;
93 const int j = jk - k * LX;
94 if ( i < LX && j < LX && k < LX) {
95 T rtmp = 0.0;
96 T stmp = 0.0;
97 T ttmp = 0.0;
98 for (int l = 0; l < LX; l++) {
99 rtmp += shdx[i + l * LX] * shu[l + j * LX + k * LX * LX];
100 stmp += shdy[j + l * LX] * shu[i + l * LX + k * LX * LX];
101 ttmp += shdz[k + l * LX] * shu[i + j * LX + l * LX * LX];
102 }
103
104 du[ijk + e * LX * LX * LX] = shcr[ijk] * rtmp
105 + shcs[ijk] * stmp
106 + shct[ijk] * ttmp;
107 }
108 }
109}
110
111template< typename T, const int LX, const int EB >
114 const T * __restrict__ u,
121 const int nelv) {
122
123 __shared__ T shu[EB * LX * LX];
124
128
129 static_assert(sizeof(shu) +
130 sizeof(shdx) +
131 sizeof(shdy) +
132 sizeof(shdz)
134 "kstep block exceeds the LDS budget");
135
136 const int eb = (EB == 1) ? 0 : threadIdx.z;
137 const int e_blk = blockIdx.x * EB + eb;
138 /* Threads past the last element still have to reach the barriers in
139 the k loop, so clamp their reads and drop their stores rather than
140 returning early. At EB == 1 this all constant folds away */
141 const bool active = (EB == 1) ? true : (e_blk < nelv);
142 const int e = active ? e_blk : (nelv - 1);
143 const int sh = eb * LX * LX;
144 const int j = threadIdx.y;
145 const int i = threadIdx.x;
146 const int ij = i + j * LX;
147 const int ele = e*LX*LX*LX;
148
149 if (eb == 0) {
150 shdx[ij] = dx[ij];
151 shdy[ij] = dy[ij];
152 shdz[ij] = dz[ij];
153 }
154
159
160#pragma unroll LX
161 for (int k = 0; k < LX; ++k) {
162 ru[k] = u[ij + k*LX*LX + ele];
163 rcr[k] = cr[ij + k*LX*LX + ele];
164 rcs[k] = cs[ij + k*LX*LX + ele];
165 rct[k] = ct[ij + k*LX*LX + ele];
166 }
167
169
170#pragma unroll
171 for (int k = 0; k < LX; ++k) {
172 const int ijk = ij + k*LX*LX;
173 T ttmp = 0.0;
174 shu[sh + ij] = ru[k];
175#pragma unroll
176 for (int l = 0; l < LX; l++) {
177 ttmp += shdz[k+l*LX] * ru[l];
178 }
180
181 T rtmp = 0.0;
182 T stmp = 0.0;
183#pragma unroll
184 for (int l = 0; l < LX; l++) {
185 rtmp += shdx[i+l*LX] * shu[sh + l+j*LX];
186 stmp += shdy[j+l*LX] * shu[sh + i+l*LX];
187 }
188
189 if (active) {
190 du[ijk + ele] = rcr[k] * rtmp
191 + rcs[k] * stmp
192 + rct[k] * ttmp;
193 }
195 }
196}
197
198
199#endif // __MATH_CONVECT_SCALAR_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
const int sh
T rcr[LX]
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dy
const int eb
__shared__ T shdy[LX *LX]
__global__ void 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 i
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dx
const int ij
__shared__ T shdx[LX *LX]
__global__ void const T *__restrict__ const T *__restrict__ cr
const int e
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ cs
T rct[LX]
__shared__ T shdz[LX *LX]
const int e_blk
__global__ void convect_scalar_kernel_1d(T *__restrict__ du, const T *__restrict__ u, const T *__restrict__ cr, const T *__restrict__ cs, const T *__restrict__ ct, const T *__restrict__ dx, const T *__restrict__ dy, const T *__restrict__ dz)
const int ele
T rcs[LX]
__global__ void const T *__restrict__ u
const int j
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ ct
__syncthreads()
#define NEKO_EB_BOUNDS(NT)
Definition elem_block.h:95
#define NEKO_EB_MAX_LDS
Definition elem_block.h:62