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/*
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__ dr,
48 const T * __restrict__ ds,
49 const T * __restrict__ dt,
50 const T * __restrict__ dx,
51 const T * __restrict__ dy,
52 const T * __restrict__ dz,
53 const T * __restrict__ jacinv) {
54
55 __shared__ T shu[LX * LX * LX];
56 __shared__ T shdr[LX * LX * LX];
57 __shared__ T shds[LX * LX * LX];
58 __shared__ T shdt[LX * LX * LX];
59
63
65
66 const int e = blockIdx.x;
67 const int iii = threadIdx.x;
68 const int nchunks = (LX * LX * LX - 1) / CHUNKS + 1;
69
70 if (iii < (LX * LX)) {
71 shdx[iii] = dx[iii];
72 shdy[iii] = dy[iii];
73 shdz[iii] = dz[iii];
74 }
75
76 int l = iii;
77 while(l < (LX * LX * LX)) {
78 shu[l] = u[l + e * LX * LX * LX];
79 shdr[l] = dr[l + e * LX * LX * LX];
80 shds[l] = ds[l + e * LX * LX * LX];
81 shdt[l] = dt[l + e * LX * LX * LX];
82 shjacinv[l] = jacinv[l + e * LX * LX * LX];
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 du[ijk + e * LX * LX * LX] = ((rtmp * shdr[ijk])
104 + (stmp * shds[ijk])
105 + (ttmp * shdt[ijk]))
106 * shjacinv[ijk];
107
108 }
109 }
110}
111
112template< typename T, const int LX, const int EB >
115 const T * __restrict__ u,
123 const int nelv) {
124
125 __shared__ T shu[EB * LX * LX];
126
130
131 static_assert(sizeof(shu) +
132 sizeof(shdx) +
133 sizeof(shdy) +
134 sizeof(shdz)
136 "kstep block exceeds the LDS budget");
137
138 const int eb = (EB == 1) ? 0 : threadIdx.z;
139 const int e_blk = blockIdx.x * EB + eb;
140 /* Threads past the last element still have to reach the barriers in
141 the k loop, so clamp their reads and drop their stores rather than
142 returning early. At EB == 1 this all constant folds away */
143 const bool active = (EB == 1) ? true : (e_blk < nelv);
144 const int e = active ? e_blk : (nelv - 1);
145 const int sh = eb * LX * LX;
146 const int j = threadIdx.y;
147 const int i = threadIdx.x;
148 const int ij = i + j * LX;
149 const int ele = e*LX*LX*LX;
150
151 if (eb == 0) {
152 shdx[ij] = dx[ij];
153 shdy[ij] = dy[ij];
154 shdz[ij] = dz[ij];
155 }
156
162
163 #pragma unroll LX
164 for (int k = 0; k < LX; ++k) {
165 ru[k] = u[ij + k*LX*LX + ele];
166 rdr[k] = dr[ij + k*LX*LX + ele];
167 rds[k] = ds[ij + k*LX*LX + ele];
168 rdt[k] = dt[ij + k*LX*LX + ele];
169 rjacinv[k] = jacinv[ij + k*LX*LX + ele];
170 }
171
173
174 #pragma unroll
175 for (int k = 0; k < LX; ++k) {
176 const int ijk = ij + k*LX*LX;
177 T ttmp = 0.0;
178 shu[sh + ij] = ru[k];
179#pragma unroll
180 for (int l = 0; l < LX; l++) {
181 ttmp += shdz[k+l*LX] * ru[l];
182 }
184
185 T rtmp = 0.0;
186 T stmp = 0.0;
187#pragma unroll
188 for (int l = 0; l < LX; l++) {
189 rtmp += shdx[i+l*LX] * shu[sh + l+j*LX];
190 stmp += shdy[j+l*LX] * shu[sh + i+l*LX];
191 }
192
193 if (active) {
194 du[ijk + ele] = rjacinv[k] * ((rtmp * rdr[k])
195 + (stmp * rds[k])
196 + (ttmp * rdt[k]));
197 }
199 }
200}
201
202
203#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_BOUNDS(NT)
Definition elem_block.h:95
#define NEKO_EB_MAX_LDS
Definition elem_block.h:62