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/*
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__ x,
47 const T * __restrict__ dr,
48 const T * __restrict__ ds,
49 const T * __restrict__ dt,
50 const T * __restrict__ dxt,
51 const T * __restrict__ dyt,
52 const T * __restrict__ dzt,
53 const T * __restrict__ w3) {
54
58
59 __shared__ T shtar[LX * LX * LX];
60 __shared__ T shtas[LX * LX * LX];
61 __shared__ T shtat[LX * LX * LX];
62
63 const int e = blockIdx.x;
64 const int iii = threadIdx.x;
65 const int nchunks = (LX * LX * LX - 1) / CHUNKS + 1;
66
67 if (iii < (LX * LX)) {
68 shdxt[iii] = dxt[iii];
69 shdyt[iii] = dyt[iii];
70 shdzt[iii] = dzt[iii];
71 }
72
73 int l = iii;
74 while(l < (LX * LX * LX)) {
75 T wx = x[l + e * LX * LX * LX] * w3[l];
76
77 shtar[l] = wx*dr[l + e * LX * LX * LX];
78 shtas[l] = wx*ds[l + e * LX * LX * LX];
79 shtat[l] = wx*dt[l + e * LX * LX * LX];
80
81 l = l + CHUNKS;
82 }
83
85 for (int n = 0; n < nchunks; n++) {
86 const int ijk = iii + n * CHUNKS;
87 const int jk = ijk / LX;
88 const int i = ijk - jk * LX;
89 const int k = jk / LX;
90 const int j = jk - k * LX;
91 if ( i < LX && j < LX && k < LX && ijk < LX*LX*LX) {
92 T rtmp = 0.0;
93 T stmp = 0.0;
94 T ttmp = 0.0;
95 for (int l = 0; l < LX; l++) {
96 rtmp += shdxt[i + l * LX] * shtar[l+j*LX+k*LX*LX];
97 stmp += shdyt[j + l * LX] * shtas[i+l*LX + k*LX*LX];
98 ttmp += shdzt[k + l * LX] * shtat[i + j*LX + l*LX*LX];
99 }
100 dtx[ijk + e * LX * LX * LX] = ( rtmp + stmp + ttmp );
101
102 }
103 }
104}
105
106template< typename T, const int LX, const int EB >
109 const T * __restrict__ x,
117 const int nelv) {
118
122
125
126 static_assert(sizeof(shdxt) +
127 sizeof(shdyt) +
128 sizeof(shdzt) +
129 sizeof(shtar) +
130 sizeof(shtas)
132 "kstep block exceeds the LDS budget");
133
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 shdxt[ij] = dxt[ij];
153 shdyt[ij] = dyt[ij];
154 shdzt[ij] = dzt[ij];
155 }
156
157
158#pragma unroll LX
159 for (int k = 0; k < LX; ++k) {
160 T wx = x[ij + k*LX*LX + ele] * w3[ij + k*LX*LX];
161
162 rtar[k] = wx *dr[ij + k*LX*LX + ele];
163 rtas[k] = wx *ds[ij + k*LX*LX + ele];
164 rtat[k] = wx *dt[ij + k*LX*LX + ele];
165 }
166
168
169#pragma unroll
170 for (int k = 0; k < LX; ++k) {
171 const int ijk = ij + k*LX*LX;
172 T ttmp = 0.0;
173 shtar[sh + ij] = rtar[k];
174 shtas[sh + ij] = rtas[k];
175#pragma unroll
176 for (int l = 0; l < LX; l++) {
177 ttmp += shdzt[k+l*LX] * rtat[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 += shdxt[i+l*LX] * shtar[sh + l+j*LX];
186 stmp += shdyt[j+l*LX] * shtas[sh + i+l*LX];
187 }
188
189 if (active) {
190 dtx[ijk + ele] = ( rtmp + stmp + ttmp );
191 }
192
194 }
195}
196
197
198#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_BOUNDS(NT)
Definition elem_block.h:95
#define NEKO_EB_MAX_LDS
Definition elem_block.h:62