35#ifndef __GS_GS_KERNELS__
36#define __GS_GS_KERNELS__
46 const int * __restrict__ dg,
47 const T * __restrict__
u,
49 const int * __restrict__ gd,
51 const int * __restrict__ b,
52 const int * __restrict__ bo) {
54 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
55 const int str = blockDim.x * gridDim.x;
57 for (
int i = idx;
i < nb;
i += str) {
58 const int blk_len = b[
i];
61 for (
int j = 1;
j < blk_len;
j++) {
62 tmp +=
u[gd[k +
j] - 1];
68 for (
int i = ((abs(o) - 1) + idx);
i < m ;
i += str) {
69 v[dg[
i] - 1] =
u[gd[
i] - 1];
74 for (
int i = ((o - 1) + idx);
i < m ;
i += str) {
75 T tmp =
u[gd[
i] - 1] +
u[gd[
i+1] - 1];
91 const int * __restrict__ dg,
92 const T * __restrict__
u,
94 const int * __restrict__ gd,
96 const int * __restrict__ b,
97 const int * __restrict__ bo) {
99 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
100 const int str = blockDim.x * gridDim.x;
102 for (
int i = idx;
i < nb;
i += str) {
103 const int blk_len = b[
i];
105 T tmp =
u[gd[k] - 1];
106 for (
int j = 1;
j < blk_len;
j++) {
107 tmp *=
u[gd[k +
j] - 1];
113 for (
int i = ((abs(o) - 1) + idx);
i < m ;
i += str) {
114 v[dg[
i] - 1] =
u[gd[
i] - 1];
119 for (
int i = ((o - 1) + idx);
i < m ;
i += str) {
120 T tmp =
u[gd[
i] - 1] *
u[gd[
i+1] - 1];
132template<
typename T >
136 const int * __restrict__ dg,
137 const T * __restrict__
u,
139 const int * __restrict__ gd,
141 const int * __restrict__ b,
142 const int * __restrict__ bo) {
144 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
145 const int str = blockDim.x * gridDim.x;
147 for (
int i = idx;
i < nb;
i += str) {
148 const int blk_len = b[
i];
150 T tmp =
u[gd[k] - 1];
151 for (
int j = 1;
j < blk_len;
j++) {
152 tmp = min(
u[gd[k +
j] - 1], tmp);
158 for (
int i = ((abs(o) - 1) + idx);
i < m ;
i += str) {
159 v[dg[
i] - 1] =
u[gd[
i] - 1];
164 for (
int i = ((o - 1) + idx);
i < m ;
i += str) {
165 T tmp = min(
u[gd[
i] - 1],
u[gd[
i+1] - 1]);
177template<
typename T >
181 const int * __restrict__ dg,
182 const T * __restrict__
u,
184 const int * __restrict__ gd,
186 const int * __restrict__ b,
187 const int * __restrict__ bo) {
189 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
190 const int str = blockDim.x * gridDim.x;
192 for (
int i = idx;
i < nb;
i += str) {
193 const int blk_len = b[
i];
195 T tmp =
u[gd[k] - 1];
196 for (
int j = 1;
j < blk_len;
j++) {
197 tmp =
max(
u[gd[k +
j] - 1], tmp);
203 for (
int i = ((abs(o) - 1) + idx);
i < m ;
i += str) {
204 v[dg[
i] - 1] =
u[gd[
i] - 1];
209 for (
int i = ((o - 1) + idx);
i < m ;
i += str) {
210 T tmp =
max(
u[gd[
i] - 1],
u[gd[
i+1] - 1]);
222template<
typename T >
225 const int * __restrict__ dg,
228 const int * __restrict__ gd,
230 const int *__restrict__ b,
231 const int *__restrict__ bo) {
233 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
234 const int str = blockDim.x * gridDim.x;
236 for (
int i = idx;
i < nb;
i += str) {
237 const int blk_len = b[
i];
239 T tmp =
v[dg[k] - 1];
240 for (
int j = 0;
j < blk_len;
j++) {
241 u[gd[k +
j] - 1] = tmp;
245 int facet_offset = 0;
247 facet_offset = bo[nb - 1] + b[nb - 1];
251 for (
int i = (facet_offset + idx);
i < m;
i += str) {
252 u[gd[
i] - 1] =
v[dg[
i] - 1];
257template<
typename T >
259 T * __restrict__ buf,
260 const int32_t * __restrict__ dof,
263 const int j = threadIdx.x + blockDim.x * blockIdx.x;
268 buf[
j] =
u[dof[
j]-1];
272template<
typename T >
274 const T * __restrict__ buf,
275 const int32_t * __restrict__ dof,
278 const int j = threadIdx.x + blockDim.x * blockIdx.x;
283 const int32_t idx = dof[
j];
284 const T val = buf[
j];
286 atomicAdd(&
u[-idx-1], val);
298 old = !signbit(val) ? __int_as_float(atomicMin((
int*)address, __float_as_int(val))) :
299 __uint_as_float(atomicMax((
unsigned int*)address, __float_as_uint(val)));
307 old = !signbit(val) ? __longlong_as_double(atomicMin((
unsigned long long*)address,
308 __double_as_longlong(val))) :
309 __longlong_as_double(atomicMax((
unsigned long long*)address,
310 __double_as_longlong(val)));
314template<
typename T >
316 const T * __restrict__ buf,
317 const int32_t * __restrict__ dof,
320 const int j = threadIdx.x + blockDim.x * blockIdx.x;
325 const int32_t idx = dof[
j];
326 const T val = buf[
j];
333 u[idx-1] = min(
u[idx-1], val);
343 old = !signbit(val) ? __int_as_float(atomicMax((
int*)address, __float_as_int(val))) :
344 __uint_as_float(atomicMin((
unsigned int*)address, __float_as_uint(val)));
351 old = !signbit(val) ? __longlong_as_double(atomicMax((
unsigned long long*)address,
352 __double_as_longlong(val))) :
353 __longlong_as_double(atomicMin((
unsigned long long*)address,
354 __double_as_longlong(val)));
358template<
typename T >
360 const T * __restrict__ buf,
361 const int32_t * __restrict__ dof,
364 const int j = threadIdx.x + blockDim.x * blockIdx.x;
369 const int32_t idx = dof[
j];
370 const T val = buf[
j];
377 u[idx-1] =
max(
u[idx-1], val);
388template<
typename T >
390 T * __restrict__ buf,
391 const int32_t * __restrict__ dof,
392 const int n,
const int nc,
const int ns) {
394 const int j = threadIdx.x + blockDim.x * blockIdx.x;
399 const int idx = dof[
j] - 1;
400 for (
int c = 0; c < nc; c++)
401 buf[nc*
j + c] =
u[c*ns + idx];
404template<
typename T >
406 const T * __restrict__ buf,
407 const int32_t * __restrict__ dof,
408 const int n,
const int nc,
411 const int j = threadIdx.x + blockDim.x * blockIdx.x;
416 const int32_t idx = dof[
j];
418 for (
int c = 0; c < nc; c++)
419 atomicAdd(&
u[c*ns + (-idx-1)], buf[nc*
j + c]);
421 for (
int c = 0; c < nc; c++)
422 u[c*ns + (idx-1)] += buf[nc*
j + c];
426template<
typename T >
428 const T * __restrict__ buf,
429 const int32_t * __restrict__ dof,
430 const int n,
const int nc,
433 const int j = threadIdx.x + blockDim.x * blockIdx.x;
438 const int32_t idx = dof[
j];
440 for (
int c = 0; c < nc; c++)
443 for (
int c = 0; c < nc; c++)
444 u[c*ns + (idx-1)] = min(
u[c*ns + (idx-1)], buf[nc*
j + c]);
448template<
typename T >
450 const T * __restrict__ buf,
451 const int32_t * __restrict__ dof,
452 const int n,
const int nc,
455 const int j = threadIdx.x + blockDim.x * blockIdx.x;
460 const int32_t idx = dof[
j];
462 for (
int c = 0; c < nc; c++)
465 for (
int c = 0; c < nc; c++)
466 u[c*ns + (idx-1)] =
max(
u[c*ns + (idx-1)], buf[nc*
j + c]);
__global__ void const T *__restrict__ u
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ v
__device__ T atomicMaxFloat(T *address, T val)
__global__ void gs_unpack_max_kernel(T *__restrict__ u, const T *__restrict__ buf, const int32_t *__restrict__ dof, const int n)
__global__ void gather_kernel_min(T *__restrict__ v, const int m, const int o, const int *__restrict__ dg, const T *__restrict__ u, const int n, const int *__restrict__ gd, const int nb, const int *__restrict__ b, const int *__restrict__ bo)
__global__ void scatter_kernel(T *__restrict__ v, const int m, const int *__restrict__ dg, T *__restrict__ u, const int n, const int *__restrict__ gd, const int nb, const int *__restrict__ b, const int *__restrict__ bo)
__global__ void gs_unpack_add_vec_kernel(T *__restrict__ u, const T *__restrict__ buf, const int32_t *__restrict__ dof, const int n, const int nc, const int ns)
__global__ void gs_unpack_max_vec_kernel(T *__restrict__ u, const T *__restrict__ buf, const int32_t *__restrict__ dof, const int n, const int nc, const int ns)
__global__ void gather_kernel_mul(T *__restrict__ v, const int m, const int o, const int *__restrict__ dg, const T *__restrict__ u, const int n, const int *__restrict__ gd, const int nb, const int *__restrict__ b, const int *__restrict__ bo)
__device__ T atomicMinFloat(T *address, T val)
__global__ void gs_pack_kernel(const T *__restrict__ u, T *__restrict__ buf, const int32_t *__restrict__ dof, const int n)
__global__ void gs_unpack_min_kernel(T *__restrict__ u, const T *__restrict__ buf, const int32_t *__restrict__ dof, const int n)
__global__ void gather_kernel_add(T *__restrict__ v, const int m, const int o, const int *__restrict__ dg, const T *__restrict__ u, const int n, const int *__restrict__ gd, const int nb, const int *__restrict__ b, const int *__restrict__ bo)
__device__ double atomicMaxFloat< double >(double *address, double val)
__device__ float atomicMaxFloat< float >(float *address, float val)
__global__ void gs_unpack_add_kernel(T *__restrict__ u, const T *__restrict__ buf, const int32_t *__restrict__ dof, const int n)
__global__ void gather_kernel_max(T *__restrict__ v, const int m, const int o, const int *__restrict__ dg, const T *__restrict__ u, const int n, const int *__restrict__ gd, const int nb, const int *__restrict__ b, const int *__restrict__ bo)
__global__ void gs_unpack_min_vec_kernel(T *__restrict__ u, const T *__restrict__ buf, const int32_t *__restrict__ dof, const int n, const int nc, const int ns)
__device__ float atomicMinFloat< float >(float *address, float val)
__global__ void gs_pack_vec_kernel(const T *__restrict__ u, T *__restrict__ buf, const int32_t *__restrict__ dof, const int n, const int nc, const int ns)
__device__ double atomicMinFloat< double >(double *address, double val)