Neko 1.99.9
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
bicgstab_kernel.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2026, The Neko Authors
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8
9 * Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above
13 copyright notice, this list of conditions and the following
14 disclaimer in the documentation and/or other materials provided
15 with the distribution.
16
17 * Neither the name of the authors nor the names of its
18 contributors may be used to endorse or promote products derived
19 from this software without specific prior written permission.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 POSSIBILITY OF SUCH DAMAGE.
33*/
34
35#ifndef __KRYLOV_BICGSTAB_KERNEL_H__
36#define __KRYLOV_BICGSTAB_KERNEL_H__
37
39
44template< typename T >
46 const T * __restrict__ r,
47 const T * __restrict__ v,
48 const T beta,
49 const T omega,
50 const int n) {
51
52 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
53 const int str = blockDim.x * gridDim.x;
54
55 for (int i = idx; i < n; i += str) {
56 p[i] = r[i] + beta * (p[i] - omega * v[i]);
57 }
58}
59
67template< typename T, typename T_acc >
69 const T * __restrict__ b,
70 const T * __restrict__ mult,
72 const int n) {
73
74 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
75 const int str = blockDim.x * gridDim.x;
76
77 const unsigned int lane = threadIdx.x % NEKO_WAVE_SIZE;
78 const unsigned int wid = threadIdx.x / NEKO_WAVE_SIZE;
79
82 T_acc prod = 0.0;
83 T_acc nrm = 0.0;
84 for (int i = idx; i < n; i += str) {
85 const T_acc w = static_cast<T_acc>(mult[i] * b[i]);
86 prod += static_cast<T_acc>(a[i]) * w;
87 nrm += static_cast<T_acc>(b[i]) * w;
88 }
89
92 if (lane == 0) {
95 }
97
100 if (wid == 0) {
103 }
104
105 if (threadIdx.x == 0) {
106 buf_h[blockIdx.x * 2] = prod;
107 buf_h[blockIdx.x * 2 + 1] = nrm;
108 }
109}
110
115template< typename T, typename T_acc >
117 const T * __restrict__ r,
118 const T * __restrict__ v,
119 const T * __restrict__ mult,
121 const T alpha,
122 const int n) {
123
124 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
125 const int str = blockDim.x * gridDim.x;
126
127 const unsigned int lane = threadIdx.x % NEKO_WAVE_SIZE;
128 const unsigned int wid = threadIdx.x / NEKO_WAVE_SIZE;
129
131 T_acc sum = 0.0;
132 for (int i = idx; i < n; i += str) {
133 const T si = r[i] - alpha * v[i];
134 s[i] = si;
135 sum += static_cast<T_acc>(si * mult[i] * si);
136 }
137
139 if (lane == 0)
140 shared[wid] = sum;
142
143 sum = (threadIdx.x < blockDim.x / NEKO_WAVE_SIZE) ? shared[lane] : 0.0;
144 if (wid == 0)
146
147 if (threadIdx.x == 0)
148 buf_h[blockIdx.x] = sum;
149}
150
159template< typename T, typename T_acc >
161 T * __restrict__ r,
162 const T * __restrict__ p_hat,
163 const T * __restrict__ s_hat,
164 const T * __restrict__ s,
165 const T * __restrict__ t,
166 const T * __restrict__ f,
167 const T * __restrict__ mult,
169 const T alpha,
170 const T omega,
171 const int n) {
172
173 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
174 const int str = blockDim.x * gridDim.x;
175
176 const unsigned int lane = threadIdx.x % NEKO_WAVE_SIZE;
177 const unsigned int wid = threadIdx.x / NEKO_WAVE_SIZE;
178
181 T_acc rtr = 0.0;
182 T_acc ftr = 0.0;
183 for (int i = idx; i < n; i += str) {
184 x[i] = x[i] + alpha * p_hat[i] + omega * s_hat[i];
185 const T ri = s[i] - omega * t[i];
186 r[i] = ri;
187 const T_acc w = static_cast<T_acc>(mult[i] * ri);
188 rtr += static_cast<T_acc>(ri) * w;
189 ftr += static_cast<T_acc>(f[i]) * w;
190 }
191
194 if (lane == 0) {
195 shared_rtr[wid] = rtr;
196 shared_ftr[wid] = ftr;
197 }
199
200 rtr = (threadIdx.x < blockDim.x / NEKO_WAVE_SIZE) ? shared_rtr[lane] : 0.0;
201 ftr = (threadIdx.x < blockDim.x / NEKO_WAVE_SIZE) ? shared_ftr[lane] : 0.0;
202 if (wid == 0) {
205 }
206
207 if (threadIdx.x == 0) {
208 buf_h[blockIdx.x * 2] = rtr;
209 buf_h[blockIdx.x * 2 + 1] = ftr;
210 }
211}
212
213#endif // __KRYLOV_BICGSTAB_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__ w
const int i
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ v
__syncthreads()
__global__ void bicgstab_update_p_kernel(T *__restrict__ p, const T *__restrict__ r, const T *__restrict__ v, const T beta, const T omega, const int n)
__global__ void bicgstab_product_and_norm_kernel(const T *__restrict__ a, const T *__restrict__ b, const T *__restrict__ mult, T_acc *__restrict__ buf_h, const int n)
__global__ void bicgstab_part1_kernel(T *__restrict__ s, const T *__restrict__ r, const T *__restrict__ v, const T *__restrict__ mult, T_acc *__restrict__ buf_h, const T alpha, const int n)
__global__ void bicgstab_part2_kernel(T *__restrict__ x, T *__restrict__ r, const T *__restrict__ p_hat, const T *__restrict__ s_hat, const T *__restrict__ s, const T *__restrict__ t, const T *__restrict__ f, const T *__restrict__ mult, T_acc *__restrict__ buf_h, const T alpha, const T omega, const int n)
__global__ void const T *__restrict__ x
#define NEKO_WAVE_SIZE
Definition wave.h:119