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;
244 int facet_offset = 0;
246 facet_offset = bo[nb - 1] + b[nb - 1];
249 for (
int i = (facet_offset + idx);
i < m;
i += str) {
250 u[gd[
i] - 1] =
v[dg[
i] - 1];
255template<
typename T >
257 T * __restrict__ buf,
258 const int32_t * __restrict__ dof,
261 const int j = threadIdx.x + blockDim.x * blockIdx.x;
266 buf[
j] =
u[dof[
j]-1];
270template<
typename T >
272 const T * __restrict__ buf,
273 const int32_t * __restrict__ dof,
276 const int j = threadIdx.x + blockDim.x * blockIdx.x;
281 const int32_t idx = dof[
j];
282 const T val = buf[
j];
284#if __CUDA_ARCH__ >= 600
285 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#if __CUDA_ARCH__ >= 600
308 old = !signbit(val) ? __longlong_as_double(atomicMin((
unsigned long long*)address,
309 __double_as_longlong(val))) :
310 __longlong_as_double(atomicMax((
unsigned long long*)address,
311 __double_as_longlong(val)));
316template<
typename T >
318 const T * __restrict__ buf,
319 const int32_t * __restrict__ dof,
322 const int j = threadIdx.x + blockDim.x * blockIdx.x;
327 const int32_t idx = dof[
j];
328 const T val = buf[
j];
335 u[idx-1] = min(
u[idx-1], val);
345 old = !signbit(val) ? __int_as_float(atomicMax((
int*)address, __float_as_int(val))) :
346 __uint_as_float(atomicMin((
unsigned int*)address, __float_as_uint(val)));
353#if __CUDA_ARCH__ >= 600
354 old = !signbit(val) ? __longlong_as_double(atomicMax((
unsigned long long*)address,
355 __double_as_longlong(val))) :
356 __longlong_as_double(atomicMin((
unsigned long long*)address,
357 __double_as_longlong(val)));
362template<
typename T >
364 const T * __restrict__ buf,
365 const int32_t * __restrict__ dof,
368 const int j = threadIdx.x + blockDim.x * blockIdx.x;
373 const int32_t idx = dof[
j];
374 const T val = buf[
j];
381 u[idx-1] =
max(
u[idx-1], val);
392template<
typename T >
394 T * __restrict__ buf,
395 const int32_t * __restrict__ dof,
396 const int n,
const int nc,
const int ns) {
398 const int j = threadIdx.x + blockDim.x * blockIdx.x;
403 const int idx = dof[
j] - 1;
404 for (
int c = 0; c < nc; c++)
405 buf[nc*
j + c] =
u[c*ns + idx];
408template<
typename T >
410 const T * __restrict__ buf,
411 const int32_t * __restrict__ dof,
412 const int n,
const int nc,
415 const int j = threadIdx.x + blockDim.x * blockIdx.x;
420 const int32_t idx = dof[
j];
422#if __CUDA_ARCH__ >= 600
423 for (
int c = 0; c < nc; c++)
424 atomicAdd(&
u[c*ns + (-idx-1)], buf[nc*
j + c]);
427 for (
int c = 0; c < nc; c++)
428 u[c*ns + (idx-1)] += buf[nc*
j + c];
432template<
typename T >
434 const T * __restrict__ buf,
435 const int32_t * __restrict__ dof,
436 const int n,
const int nc,
439 const int j = threadIdx.x + blockDim.x * blockIdx.x;
444 const int32_t idx = dof[
j];
446 for (
int c = 0; c < nc; c++)
449 for (
int c = 0; c < nc; c++)
450 u[c*ns + (idx-1)] = min(
u[c*ns + (idx-1)], buf[nc*
j + c]);
454template<
typename T >
456 const T * __restrict__ buf,
457 const int32_t * __restrict__ dof,
458 const int n,
const int nc,
461 const int j = threadIdx.x + blockDim.x * blockIdx.x;
466 const int32_t idx = dof[
j];
468 for (
int c = 0; c < nc; c++)
471 for (
int c = 0; c < nc; c++)
472 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)