35#ifndef __KRYLOV_BICGSTAB_KERNEL_H__
36#define __KRYLOV_BICGSTAB_KERNEL_H__
46 const T * __restrict__ r,
47 const T * __restrict__
v,
52 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
53 const int str = blockDim.x * gridDim.x;
55 for (
int i = idx;
i < n;
i += str) {
56 p[
i] = r[
i] + beta * (p[
i] - omega *
v[
i]);
67template<
typename T,
typename T_acc >
69 const T * __restrict__ b,
70 const T * __restrict__ mult,
71 T_acc * __restrict__ buf_h,
74 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
75 const int str = blockDim.x * gridDim.x;
77 const unsigned int lane = threadIdx.x % warpSize;
78 const unsigned int wid = threadIdx.x / warpSize;
80 __shared__ T_acc shared_prod[32];
81 __shared__ T_acc shared_nrm[32];
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;
93 shared_prod[wid] = prod;
94 shared_nrm[wid] = nrm;
98 prod = (threadIdx.x < blockDim.x / warpSize) ? shared_prod[lane] : 0.0;
99 nrm = (threadIdx.x < blockDim.x / warpSize) ? shared_nrm[lane] : 0.0;
105 if (threadIdx.x == 0) {
106 buf_h[blockIdx.x * 2] = prod;
107 buf_h[blockIdx.x * 2 + 1] = nrm;
115template<
typename T,
typename T_acc >
117 const T * __restrict__ r,
118 const T * __restrict__
v,
119 const T * __restrict__ mult,
120 T_acc * __restrict__ buf_h,
124 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
125 const int str = blockDim.x * gridDim.x;
127 const unsigned int lane = threadIdx.x % warpSize;
128 const unsigned int wid = threadIdx.x / warpSize;
130 __shared__ T_acc shared[32];
132 for (
int i = idx;
i < n;
i += str) {
133 const T si = r[
i] - alpha *
v[
i];
135 sum +=
static_cast<T_acc
>(si * mult[
i] * si);
143 sum = (threadIdx.x < blockDim.x / warpSize) ? shared[lane] : 0.0;
147 if (threadIdx.x == 0)
148 buf_h[blockIdx.x] = sum;
159template<
typename T,
typename T_acc >
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,
168 T_acc * __restrict__ buf_h,
173 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
174 const int str = blockDim.x * gridDim.x;
176 const unsigned int lane = threadIdx.x % warpSize;
177 const unsigned int wid = threadIdx.x / warpSize;
179 __shared__ T_acc shared_rtr[32];
180 __shared__ T_acc shared_ftr[32];
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];
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;
195 shared_rtr[wid] = rtr;
196 shared_ftr[wid] = ftr;
200 rtr = (threadIdx.x < blockDim.x / warpSize) ? shared_rtr[lane] : 0.0;
201 ftr = (threadIdx.x < blockDim.x / warpSize) ? shared_ftr[lane] : 0.0;
207 if (threadIdx.x == 0) {
208 buf_h[blockIdx.x * 2] = rtr;
209 buf_h[blockIdx.x * 2 + 1] = ftr;
__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__ v
__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
__inline__ __device__ T reduce_warp(T val)