Neko 1.99.9
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
cfl_kernel.h
Go to the documentation of this file.
1#ifndef __MATH_CFL_KERNEL_H__
2#define __MATH_CFL_KERNEL_H__
3/*
4 Copyright (c) 2022, The Neko Authors
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions
9 are met:
10
11 * Redistributions of source code must retain the above copyright
12 notice, this list of conditions and the following disclaimer.
13
14 * Redistributions in binary form must reproduce the above
15 copyright notice, this list of conditions and the following
16 disclaimer in the documentation and/or other materials provided
17 with the distribution.
18
19 * Neither the name of the authors nor the names of its
20 contributors may be used to endorse or promote products derived
21 from this software without specific prior written permission.
22
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 POSSIBILITY OF SUCH DAMAGE.
35*/
36
37#include "wave.h"
38
39
46template< typename T>
48#if NEKO_WAVE_SIZE == 64
49 val = fmax(val, __shfl_down(val, 32));
50#endif
51 val = fmax(val, __shfl_down(val, 16));
52 val = fmax(val, __shfl_down(val, 8));
53 val = fmax(val, __shfl_down(val, 4));
54 val = fmax(val, __shfl_down(val, 2));
55 val = fmax(val, __shfl_down(val, 1));
56 return val;
57}
58
62template< typename T >
63__global__ void cfl_reduce_kernel(T * bufred, const int n) {
64
65 T cfl = 0;
66 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
67 const int str = blockDim.x * gridDim.x;
68 for (int i = idx; i<n ; i += str)
69 {
70 cfl = fmax(cfl, bufred[i]);
71 }
72
74 unsigned int lane = threadIdx.x % NEKO_WAVE_SIZE;
75 unsigned int wid = threadIdx.x / NEKO_WAVE_SIZE;
76
77 cfl = cfl_reduce_warp<T>(cfl);
78 if (lane == 0)
79 shared[wid] = cfl;
81
82 cfl = (threadIdx.x < blockDim.x / NEKO_WAVE_SIZE) ? shared[lane] : 0;
83 if (wid == 0)
84 cfl = cfl_reduce_warp<T>(cfl);
85
86 if (threadIdx.x == 0)
87 bufred[blockIdx.x] = cfl;
88}
89
94template< typename D, typename T, const int LX, const int CHUNKS >
96 const T * __restrict__ u,
97 const T * __restrict__ v,
98 const T * __restrict__ w,
99 const T * __restrict__ drdx,
100 const T * __restrict__ dsdx,
101 const T * __restrict__ dtdx,
102 const T * __restrict__ drdy,
103 const T * __restrict__ dsdy,
104 const T * __restrict__ dtdy,
105 const T * __restrict__ drdz,
106 const T * __restrict__ dsdz,
107 const T * __restrict__ dtdz,
108 const T * __restrict__ dr_inv,
109 const T * __restrict__ ds_inv,
110 const T * __restrict__ dt_inv,
111 const T * __restrict__ jacinv,
112 D * __restrict__ cfl_h) {
113
114 int i,j,k;
115
116 const int e = blockIdx.x;
117 const int iii = threadIdx.x;
118 const int nchunks = (LX * LX * LX - 1) / CHUNKS + 1;
119 const unsigned int lane = threadIdx.x % NEKO_WAVE_SIZE;
120 const unsigned int wid = threadIdx.x / NEKO_WAVE_SIZE;
121
122 __shared__ T shu[LX * LX * LX];
123 __shared__ T shv[LX * LX * LX];
124 __shared__ T shw[LX * LX * LX];
125
129
131
132 __shared__ D shared[64];
133
134 if (iii < LX) {
135 shdr_inv[iii] = dr_inv[iii];
136 shds_inv[iii] = ds_inv[iii];
137 shdt_inv[iii] = dt_inv[iii];
138 }
139
140 j = iii;
141 while(j < (LX * LX * LX)) {
142 shu[j] = u[j + e * LX * LX * LX];
143 shv[j] = v[j + e * LX * LX * LX];
144 shw[j] = w[j + e * LX * LX * LX];
145
146 shjacinv[j] = jacinv[j + e * LX * LX * LX];
147
148 j = j + CHUNKS;
149 }
150
152
153 D cfl_tmp = 0.0;
154 for (int n = 0; n < nchunks; n++) {
155 const int ijk = iii + n * CHUNKS;
156 const int jk = ijk / LX;
157 i = ijk - jk * LX;
158 k = jk / LX;
159 j = jk - k * LX;
160 if ( i < LX && j < LX && k < LX) {
161 const D cflr = fabs( dt * ( ( shu[ijk] * drdx[ijk + e * LX * LX * LX]
162 + shv[ijk] * drdy[ijk + e * LX * LX * LX]
163 + shw[ijk] * drdz[ijk + e * LX * LX * LX]
164 ) * shjacinv[ijk]) * shdr_inv[i]);
165 const D cfls = fabs( dt * ( ( shu[ijk] * dsdx[ijk + e * LX * LX * LX]
166 + shv[ijk] * dsdy[ijk + e * LX * LX * LX]
167 + shw[ijk] * dsdz[ijk + e * LX * LX * LX]
168 ) * shjacinv[ijk]) * shds_inv[j]);
169 const D cflt = fabs( dt * ( ( shu[ijk] * dtdx[ijk + e * LX * LX * LX]
170 + shv[ijk] * dtdy[ijk + e * LX * LX * LX]
171 + shw[ijk] * dtdz[ijk + e * LX * LX * LX]
172 ) * shjacinv[ijk]) * shdt_inv[k]);
173
175
176 }
177 }
178
180 if (lane == 0)
181 shared[wid] = cfl_tmp;
183
185 if (wid == 0)
187
188 if (threadIdx.x == 0)
189 cfl_h[blockIdx.x] = cfl_tmp;
190}
191
192
193#endif // __MATH_CFL_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)
__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 T *__restrict__ dtdy
__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__ dtdx
__shared__ T shu[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__ 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
__shared__ T shw[LX *LX]
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ w
__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 T *__restrict__ const T *__restrict__ const T *__restrict__ jacinv
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__ 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__ u
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__ drdz
__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__ drdx
__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__ dsdx
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ v
const int j
__syncthreads()
__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__ dsdy
__shared__ T shv[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__ const T *__restrict__ drdy
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dt
__global__ void cfl_reduce_kernel(T *bufred, const int n)
Definition cfl_kernel.h:55
__global__ void cfl_kernel(const D dt, const T *__restrict__ u, const T *__restrict__ v, const T *__restrict__ w, 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__ dr_inv, const T *__restrict__ ds_inv, const T *__restrict__ dt_inv, const T *__restrict__ jacinv, D *__restrict__ cfl_h)
Definition cfl_kernel.h:87
__inline__ __device__ T cfl_reduce_warp(T val)
Definition cfl_kernel.h:42
#define NEKO_WAVE_SIZE
Definition wave.h:119