Neko 1.99.9
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
fusedcg_cpld_kernel.h
Go to the documentation of this file.
1#ifndef __KRYLOV_FUSEDCG_CPLD_KERNEL_H__
2#define __KRYLOV_FUSEDCG_CPLD_KERNEL_H__
3/*
4 Copyright (c) 2021-2024, 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
39
43template< typename T >
50 T * __restrict__ tmp,
51 const int n) {
52
53 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
54 const int str = blockDim.x * gridDim.x;
55
56 for (int i = idx; i < n; i+= str) {
57 tmp[i] = a1[i]*b1[i] + a2[i]*b2[i] + a3[i]*b3[i];
58 }
59
60}
61
65template< typename T >
67 T * __restrict__ p2,
68 T * __restrict__ p3,
69 const T * __restrict__ z1,
70 const T * __restrict__ z2,
71 const T * __restrict__ z3,
72 const T * __restrict__ po1,
73 const T * __restrict__ po2,
74 const T * __restrict__ po3,
75 const T beta,
76 const int n) {
77
78 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
79 const int str = blockDim.x * gridDim.x;
80
81 for (int i = idx; i < n; i+= str) {
82 p1[i] = beta*po1[i] + z1[i];
83 p2[i] = beta*po2[i] + z2[i];
84 p3[i] = beta*po3[i] + z3[i];
85 }
86
87}
88
92template< typename T >
96 const T ** p1,
97 const T ** p2,
98 const T ** p3,
99 const T * __restrict__ alpha,
100 const int p_cur,
101 const int n) {
102
103 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
104 const int str = blockDim.x * gridDim.x;
105
106 for (int i = idx; i < n; i+= str) {
107 T tmp1 = 0.0;
108 T tmp2 = 0.0;
109 T tmp3 = 0.0;
110 for (int j = 0; j < p_cur; j ++) {
111 tmp1 += p1[j][i] * alpha[j];
112 tmp2 += p2[j][i] * alpha[j];
113 tmp3 += p3[j][i] * alpha[j];
114 }
115 x1[i] += tmp1;
116 x2[i] += tmp2;
117 x3[i] += tmp3;
118 }
119
120}
121
125template< typename T>
127 T * __restrict__ a2,
128 T * __restrict__ a3,
129 const T * __restrict__ b,
130 const T * __restrict__ c1,
131 const T * __restrict__ c2,
132 const T * __restrict__ c3,
133 const T alpha,
134 T * buf_h,
135 const int n) {
136
137 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
138 const int str = blockDim.x * gridDim.x;
139
140 const unsigned int lane = threadIdx.x % NEKO_WAVE_SIZE;
141 const unsigned int wid = threadIdx.x / NEKO_WAVE_SIZE;
142
143 __shared__ T buf[32];
144 T tmp = 0.0;
145
146 for (int i = idx; i < n; i+= str) {
147 T rt1 = a1[i] - alpha * c1[i];
148 T rt2 = a2[i] - alpha * c2[i];
149 T rt3 = a3[i] - alpha * c3[i];
150 tmp = tmp + ((rt1*rt1 + rt2*rt2 + rt3*rt3) * b[i]);
151 a1[i] = rt1;
152 a2[i] = rt2;
153 a3[i] = rt3;
154 }
155
156 tmp = reduce_warp<T>(tmp);
157 if (lane == 0) {
158 buf[wid] = tmp;
159 }
161
162 tmp = (threadIdx.x < blockDim.x / NEKO_WAVE_SIZE) ? buf[lane] : 0;
163 if (wid == 0) {
164 tmp = reduce_warp<T>(tmp);
165 }
166
167 if (threadIdx.x == 0) {
168 buf_h[blockIdx.x] = tmp;
169 }
170}
171
172#endif // __KRYLOV_FUSEDCG_CPLD_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 int i
const int j
__syncthreads()
__global__ void fusedcg_cpld_update_p_kernel(T *__restrict__ p1, T *__restrict__ p2, T *__restrict__ p3, const T *__restrict__ z1, const T *__restrict__ z2, const T *__restrict__ z3, const T *__restrict__ po1, const T *__restrict__ po2, const T *__restrict__ po3, const T beta, const int n)
__global__ void fusedcg_cpld_part2_kernel(T *__restrict__ a1, T *__restrict__ a2, T *__restrict__ a3, const T *__restrict__ b, const T *__restrict__ c1, const T *__restrict__ c2, const T *__restrict__ c3, const T alpha, T *buf_h, const int n)
__global__ void fusedcg_cpld_update_x_kernel(T *__restrict__ x1, T *__restrict__ x2, T *__restrict__ x3, const T **p1, const T **p2, const T **p3, const T *__restrict__ alpha, const int p_cur, const int n)
__global__ void fusedcg_cpld_part1_kernel(T *__restrict__ a1, T *__restrict__ a2, T *__restrict__ a3, T *__restrict__ b1, T *__restrict__ b2, T *__restrict__ b3, T *__restrict__ tmp, const int n)
#define NEKO_WAVE_SIZE
Definition wave.h:119