Neko 1.99.7
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
cdtp_kernel.h
Go to the documentation of this file.
1#ifndef __MATH_CDTP_KERNEL_H__
2#define __MATH_CDTP_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__ x,
46 const T * __restrict__ dr,
47 const T * __restrict__ ds,
48 const T * __restrict__ dt,
49 const T * __restrict__ dxt,
50 const T * __restrict__ dyt,
51 const T * __restrict__ dzt,
52 const T * __restrict__ w3) {
53
57
58 __shared__ T shtar[LX * LX * LX];
59 __shared__ T shtas[LX * LX * LX];
60 __shared__ T shtat[LX * LX * LX];
61
62 const int e = blockIdx.x;
63 const int iii = threadIdx.x;
64 const int nchunks = (LX * LX * LX - 1) / CHUNKS + 1;
65
66 if (iii < (LX * LX)) {
67 shdxt[iii] = dxt[iii];
68 shdyt[iii] = dyt[iii];
69 shdzt[iii] = dzt[iii];
70 }
71
72 int l = iii;
73 while(l < (LX * LX * LX)) {
74 T wx = x[l + e * LX * LX * LX] * w3[l];
75
76 shtar[l] = wx*dr[l + e * LX * LX * LX];
77 shtas[l] = wx*ds[l + e * LX * LX * LX];
78 shtat[l] = wx*dt[l + e * LX * LX * LX];
79
80 l = l + CHUNKS;
81 }
82
84 for (int n = 0; n < nchunks; n++) {
85 const int ijk = iii + n * CHUNKS;
86 const int jk = ijk / LX;
87 const int i = ijk - jk * LX;
88 const int k = jk / LX;
89 const int j = jk - k * LX;
90 if ( i < LX && j < LX && k < LX && ijk < LX*LX*LX) {
91 T rtmp = 0.0;
92 T stmp = 0.0;
93 T ttmp = 0.0;
94 for (int l = 0; l < LX; l++) {
95 rtmp += shdxt[i + l * LX] * shtar[l+j*LX+k*LX*LX];
96 stmp += shdyt[j + l * LX] * shtas[i+l*LX + k*LX*LX];
97 ttmp += shdzt[k + l * LX] * shtat[i + j*LX + l*LX*LX];
98 }
99 dtx[ijk + e * LX * LX * LX] = ( rtmp + stmp + ttmp );
100
101 }
102 }
103}
104
105template< typename T, const int LX, const int EB >
108 const T * __restrict__ x,
116 const int nelv) {
117
121
124
125 static_assert(sizeof(shdxt) +
126 sizeof(shdyt) +
127 sizeof(shdzt) +
128 sizeof(shtar) +
129 sizeof(shtas)
131 "kstep block exceeds the shared memory budget");
132
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 shdxt[ij] = dxt[ij];
152 shdyt[ij] = dyt[ij];
153 shdzt[ij] = dzt[ij];
154 }
155
156
157#pragma unroll LX
158 for (int k = 0; k < LX; ++k) {
159 T wx = x[ij + k*LX*LX + ele] * w3[ij + k*LX*LX];
160
161 rtar[k] = wx *dr[ij + k*LX*LX + ele];
162 rtas[k] = wx *ds[ij + k*LX*LX + ele];
163 rtat[k] = wx *dt[ij + k*LX*LX + ele];
164 }
165
167
168#pragma unroll
169 for (int k = 0; k < LX; ++k) {
170 const int ijk = ij + k*LX*LX;
171 T ttmp = 0.0;
172 shtar[sh + ij] = rtar[k];
173 shtas[sh + ij] = rtas[k];
174#pragma unroll
175 for (int l = 0; l < LX; l++) {
176 ttmp += shdzt[k+l*LX] * rtat[l];
177 }
179
180 T rtmp = 0.0;
181 T stmp = 0.0;
182#pragma unroll
183 for (int l = 0; l < LX; l++) {
184 rtmp += shdxt[i+l*LX] * shtar[sh + l+j*LX];
185 stmp += shdyt[j+l*LX] * shtas[sh + i+l*LX];
186 }
187
188 if (active) {
189 dtx[ijk + ele] = ( rtmp + stmp + ttmp );
190 }
191
193 }
194}
195
196
197#endif // __MATH_CDTP_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)
const bool active
__global__ void const T *__restrict__ const T *__restrict__ dr
T rtas[LX]
const int sh
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ ds
const int eb
__global__ void const T *__restrict__ x
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dt
__shared__ T shdzt[LX *LX]
const int i
T rtat[LX]
const int ij
const int e
T rtar[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 T *__restrict__ w3
const int e_blk
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dzt
const int ele
__shared__ T shtar[EB *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 T *__restrict__ const int nelv
const int j
__shared__ T shtas[EB *LX *LX]
__global__ void cdtp_kernel_1d(T *__restrict__ dtx, const T *__restrict__ x, const T *__restrict__ dr, const T *__restrict__ ds, const T *__restrict__ dt, const T *__restrict__ dxt, const T *__restrict__ dyt, const T *__restrict__ dzt, const T *__restrict__ w3)
Definition cdtp_kernel.h:44
__shared__ T shdyt[LX *LX]
__syncthreads()
__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__ dxt
#define NEKO_EB_MAX_SMEM
Definition elem_block.h:60
#define NEKO_EB_BOUNDS(NT)
Definition elem_block.h:95