1#ifndef __MATH_MATH_KERNEL_H__
2#define __MATH_MATH_KERNEL_H__
47 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
48 const int str = blockDim.x * gridDim.x;
50 for (
int i = idx;
i < n;
i += str) {
61 int * __restrict__
mask,
65 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
66 const int str = blockDim.x * gridDim.x;
68 for (
int i = idx;
i < n_mask;
i += str) {
80 int * __restrict__
mask,
84 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
85 const int str = blockDim.x * gridDim.x;
87 for (
int i = idx;
i < n_mask;
i += str) {
92__device__ __forceinline__
94 const int ly,
const int lz) {
95 const int idx2 = idx - 1;
96 index[3] = idx2 / (lx * ly * lz);
97 index[2] = (idx2 - (lx * ly * lz) * index[3]) / (lx * ly);
98 index[1] = (idx2 - (lx * ly * lz) * index[3] - (lx * ly) * index[2]) / lx;
99 index[0] = (idx2 - (lx * ly * lz) * index[3] - (lx * ly) * index[2]) -
107__device__ __forceinline__
109 const int n1,
const int n2,
const int nf) {
110 return ((
i) + (n1) * (((
j) - 1) + (n2) * (((k) - 1) + (nf) * (((l) - 1))))) - 1;
116template<
typename T >
118 const T * __restrict__ b,
119 const int * __restrict__
mask,
120 const int * __restrict__ facet,
129 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
130 const int str = blockDim.x * gridDim.x;
132 for (
int m = idx; m < n_mask; m += str) {
133 const int f = facet[m + 1];
157template<
typename T >
160 int * __restrict__
mask,
164 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
165 const int str = blockDim.x * gridDim.x;
167 for (
int i = idx;
i < n_mask;
i += str) {
175template<
typename T >
178 int * __restrict__
mask,
182 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
183 const int str = blockDim.x * gridDim.x;
185 for (
int i = idx;
i < n_mask;
i += str) {
190#if __CUDA_ARCH__ < 600
198#define MASKED_ATOMIC_RED_BLOCK 256
203template<
typename T >
206 int * __restrict__
mask,
210#if __CUDA_ARCH__ >= 600
212 __shared__
int bins_base;
214 const int lane = threadIdx.x % 32;
217 bins[threadIdx.x] = 0.0;
224 if (threadIdx.x == 0)
227 const int kbase = bins_base;
229 const int i = base + threadIdx.x;
233 key =
mask[
i + 1] - 1;
239 const int key_prev = __shfl_up_sync(0xffffffff, key, 1);
240 const bool head = (lane == 0) || (key != key_prev);
241 const unsigned int heads = __ballot_sync(0xffffffff, head);
243 if (heads == 0xffffffff) {
248 atomicAdd(&a[key], val);
251 const unsigned int next = heads & ~((2u << lane) - 1u);
252 const int run_end = next ? __ffs(next) - 2 : 31;
256 for (
int off = 1; off < 32; off *= 2) {
257 const T tmp = __shfl_down_sync(0xffffffff, val, off);
258 if (lane + off <= run_end)
262 if (head && key >= 0) {
263 const int s = key - kbase;
265 atomicAdd(&bins[s], val);
267 atomicAdd(&a[key], val);
274 const T sum = bins[threadIdx.x];
275 if (sum != (T) 0.0) {
276 atomicAdd(&a[kbase + threadIdx.x], sum);
277 bins[threadIdx.x] = 0.0;
281 if (blockIdx.x * blockDim.x + threadIdx.x == 0)
282 assert(0 &&
"masked_atomic_reduction_kernel requires compute capability 6.0 or higher.");
289template<
typename T >
292 int * __restrict__
mask,
296 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
297 const int str = blockDim.x * gridDim.x;
299 for (
int i = idx;
i < n_mask;
i += str) {
307template<
typename T >
310 int * __restrict__
mask,
314 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
315 const int str = blockDim.x * gridDim.x;
317 for (
int i = idx;
i < n_mask;
i += str) {
329 int* __restrict__
mask,
330 const int mask_size) {
332 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
333 const int str = blockDim.x * gridDim.x;
335 for (
int i = idx;
i < mask_size;
i += str) { a[
mask[
i]] = c; }
341template<
typename T >
347 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
348 const int str = blockDim.x * gridDim.x;
350 for (
int i = idx;
i < n;
i += str) {
358template<
typename T >
363 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
364 const int str = blockDim.x * gridDim.x;
366 for (
int i = idx;
i < n;
i += str) {
374template<
typename T >
380 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
381 const int str = blockDim.x * gridDim.x;
383 for (
int i = idx;
i < n;
i += str) {
391template<
typename T >
396 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
397 const int str = blockDim.x * gridDim.x;
399 for (
int i = idx;
i < n;
i += str) {
407template<
typename T >
413 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
414 const int str = blockDim.x * gridDim.x;
416 for (
int i = idx;
i < n;
i += str) {
424template<
typename T >
430 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
431 const int str = blockDim.x * gridDim.x;
432 const T l = max_val - min_val;
434 for (
int i = idx;
i < n;
i += str) {
435 a[
i] = min_val + fmod(fmod(a[
i] - min_val, l) + l, l);
442template<
typename T >
446 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
447 const int str = blockDim.x * gridDim.x;
449 for (
int i = idx;
i < n;
i += str) {
457template<
typename T >
459 const T * __restrict__ a,
463 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
464 const int str = blockDim.x * gridDim.x;
466 for (
int i = idx;
i < n;
i += str) {
467 ap[
i] = pow(a[
i], p);
474template<
typename T >
479 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
480 const int str = blockDim.x * gridDim.x;
482 for (
int i = idx;
i < n;
i += str) {
490template<
typename T >
492 const T * __restrict__ b,
495 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
496 const int str = blockDim.x * gridDim.x;
498 for (
int i = idx;
i < n;
i += str) {
506template<
typename T >
508 const T * __restrict__ b,
509 const T * __restrict__ c,
512 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
513 const int str = blockDim.x * gridDim.x;
515 for (
int i = idx;
i < n;
i += str) {
523template<
typename T >
525 const T * __restrict__ b,
526 const T * __restrict__ c,
527 const T * __restrict__ d,
530 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
531 const int str = blockDim.x * gridDim.x;
533 for (
int i = idx;
i < n;
i += str) {
534 a[
i] = b[
i] + c[
i] + d[
i];
541template<
typename T >
543 const T * __restrict__ b,
547 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
548 const int str = blockDim.x * gridDim.x;
550 for (
int i = idx;
i < n;
i += str) {
551 a[
i] = c1 * a[
i] + b[
i];
558template<
typename T >
565 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
566 const int str = blockDim.x * gridDim.x;
569 for (
int i = idx;
i < n;
i+= str) {
571 for (
int j = 0;
j < p_cur;
j ++) {
572 tmp += p[
j][
i]*alpha[
j];
581template<
typename T >
583 const T * __restrict__ b,
587 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
588 const int str = blockDim.x * gridDim.x;
590 for (
int i = idx;
i < n;
i += str) {
591 a[
i] = a[
i] + c1 * b[
i];
598template<
typename T >
600 const T * __restrict__ b,
604 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
605 const int str = blockDim.x * gridDim.x;
607 for (
int i = idx;
i < n;
i += str) {
608 a[
i] = a[
i] + c1 * (b[
i] * b[
i]);
615template<
typename T >
617 const T * __restrict__ b,
618 const T * __restrict__ c,
623 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
624 const int str = blockDim.x * gridDim.x;
626 for (
int i = idx;
i < n;
i += str) {
627 a[
i] = c1 * b[
i] + c2 * c[
i];
634template<
typename T >
636 const T * __restrict__ b,
637 const T * __restrict__ c,
638 const T * __restrict__ d,
644 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
645 const int str = blockDim.x * gridDim.x;
647 for (
int i = idx;
i < n;
i += str) {
648 a[
i] = c1 * b[
i] + c2 * c[
i] + c3 * d[
i];
655template<
typename T >
657 const T * __restrict__ b,
658 const T * __restrict__ c,
659 const T * __restrict__ d,
660 const T * __restrict__
e,
667 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
668 const int str = blockDim.x * gridDim.x;
670 for (
int i = idx;
i < n;
i += str) {
671 a[
i] = a[
i] + c1 * b[
i] + c2 * c[
i] + c3 * d[
i] + c4 *
e[
i];
678template<
typename T >
682 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
683 const int str = blockDim.x * gridDim.x;
686 for (
int i = idx;
i < n;
i += str) {
694template<
typename T >
696 const T * __restrict__ b,
699 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
700 const int str = blockDim.x * gridDim.x;
702 for (
int i = idx;
i < n;
i += str) {
710template<
typename T >
712 const T * __restrict__ b,
713 const T * __restrict__ c,
716 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
717 const int str = blockDim.x * gridDim.x;
719 for (
int i = idx;
i < n;
i += str) {
727template<
typename T >
729 const T * __restrict__ b,
732 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
733 const int str = blockDim.x * gridDim.x;
735 for (
int i = idx;
i < n;
i += str) {
743template<
typename T >
745 const T * __restrict__ b,
746 const T * __restrict__ c,
749 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
750 const int str = blockDim.x * gridDim.x;
752 for (
int i = idx;
i < n;
i += str) {
760template<
typename T >
762 const T * __restrict__ b,
763 const T * __restrict__ c,
766 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
767 const int str = blockDim.x * gridDim.x;
769 for (
int i = idx;
i < n;
i += str) {
770 a[
i] = a[
i] - b[
i] * c[
i];
777template<
typename T >
779 const T * __restrict__ b,
782 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
783 const int str = blockDim.x * gridDim.x;
785 for (
int i = idx;
i < n;
i += str) {
793template<
typename T >
795 const T * __restrict__ b,
796 const T * __restrict__ c,
799 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
800 const int str = blockDim.x * gridDim.x;
802 for (
int i = idx;
i < n;
i += str) {
810template<
typename T >
812 const T * __restrict__ b,
813 const T * __restrict__ c,
816 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
817 const int str = blockDim.x * gridDim.x;
819 for (
int i = idx;
i < n;
i += str) {
820 a[
i] = a[
i] + b[
i] * c[
i];
828template<
typename T >
830 const T * __restrict__ b,
831 const T * __restrict__ c,
832 const T * __restrict__ d,
835 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
836 const int str = blockDim.x * gridDim.x;
838 for (
int i = idx;
i < n;
i += str) {
839 a[
i] = a[
i] + b[
i] * c[
i] * d[
i];
847template<
typename T >
849 const T * __restrict__ b,
850 const T * __restrict__ c,
854 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
855 const int str = blockDim.x * gridDim.x;
857 for (
int i = idx;
i < n;
i += str) {
858 a[
i] = a[
i] + s * b[
i] * c[
i];
866template<
typename T >
868 const T * __restrict__ u1,
869 const T * __restrict__ u2,
870 const T * __restrict__ u3,
871 const T * __restrict__ v1,
872 const T * __restrict__ v2,
873 const T * __restrict__ v3,
876 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
877 const int str = blockDim.x * gridDim.x;
879 for (
int i = idx;
i < n;
i += str) {
880 dot[
i] = u1[
i] * v1[
i] + u2[
i] * v2[
i] + u3[
i] * v3[
i];
888template<
typename T >
892 const T * __restrict__ v1,
893 const T * __restrict__ v2,
894 const T * __restrict__ v3,
895 const T * __restrict__ w1,
896 const T * __restrict__ w2,
897 const T * __restrict__
w3,
900 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
901 const int str = blockDim.x * gridDim.x;
903 for (
int i = idx;
i < n;
i += str) {
904 u1[
i] = v2[
i]*
w3[
i] - v3[
i]*w2[
i];
905 u2[
i] = v3[
i]*w1[
i] - v1[
i]*
w3[
i];
906 u3[
i] = v1[
i]*w2[
i] - v2[
i]*w1[
i];
917 val += __shfl_down_sync(0xffffffff, val, 16);
918 val += __shfl_down_sync(0xffffffff, val, 8);
919 val += __shfl_down_sync(0xffffffff, val, 4);
920 val += __shfl_down_sync(0xffffffff, val, 2);
921 val += __shfl_down_sync(0xffffffff, val, 1);
930 val =
max(val, __shfl_down_sync(0xffffffff, val, 16));
931 val =
max(val, __shfl_down_sync(0xffffffff, val, 8));
932 val =
max(val, __shfl_down_sync(0xffffffff, val, 4));
933 val =
max(val, __shfl_down_sync(0xffffffff, val, 2));
934 val =
max(val, __shfl_down_sync(0xffffffff, val, 1));
943 val = min(val, __shfl_down_sync(0xffffffff, val, 16));
944 val = min(val, __shfl_down_sync(0xffffffff, val, 8));
945 val = min(val, __shfl_down_sync(0xffffffff, val, 4));
946 val = min(val, __shfl_down_sync(0xffffffff, val, 2));
947 val = min(val, __shfl_down_sync(0xffffffff, val, 1));
954template<
typename T >
958 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
959 const int str = blockDim.x * gridDim.x;
960 for (
int i = idx;
i<n ;
i += str)
965 __shared__ T shared[32];
966 unsigned int lane = threadIdx.x % warpSize;
967 unsigned int wid = threadIdx.x / warpSize;
974 sum = (threadIdx.x < blockDim.x / warpSize) ? shared[lane] : 0;
978 if (threadIdx.x == 0)
979 bufred[blockIdx.x] = sum;
985template<
typename T >
989 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
990 const int str = blockDim.x * gridDim.x;
991 for (
int i = idx;
i<n ;
i += str)
993 max_val =
max(max_val, bufred[
i]);
996 __shared__ T shared[32];
997 unsigned int lane = threadIdx.x % warpSize;
998 unsigned int wid = threadIdx.x / warpSize;
1002 shared[wid] = max_val;
1005 max_val = (threadIdx.x < blockDim.x / warpSize) ? shared[lane] : ninf;
1009 if (threadIdx.x == 0)
1010 bufred[blockIdx.x] = max_val;
1016template<
typename T >
1020 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
1021 const int str = blockDim.x * gridDim.x;
1022 for (
int i = idx;
i<n ;
i += str)
1024 min_val = min(min_val, bufred[
i]);
1027 __shared__ T shared[32];
1028 unsigned int lane = threadIdx.x % warpSize;
1029 unsigned int wid = threadIdx.x / warpSize;
1033 shared[wid] = min_val;
1036 min_val = (threadIdx.x < blockDim.x / warpSize) ? shared[lane] : pinf;
1040 if (threadIdx.x == 0)
1041 bufred[blockIdx.x] = min_val;
1048template<
typename T_acc >
1053 __shared__ T_acc buf[1024] ;
1054 const int idx = threadIdx.x;
1055 const int y= blockIdx.x;
1056 const int step = blockDim.x;
1059 for (
int i=idx ;
i<n ;
i+=step)
1061 buf[idx] += bufred[
i*
j + y];
1068 if(threadIdx.x <
i && (threadIdx.x +
i) < n )
1070 buf[threadIdx.x] += buf[threadIdx.x +
i] ;
1083template<
typename T >
1090 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
1091 const int str = blockDim.x * gridDim.x;
1093 const unsigned int lane = threadIdx.x % warpSize;
1094 const unsigned int wid = threadIdx.x / warpSize;
1096 __shared__ T shared[32];
1098 for (
int i = idx;
i < n;
i+= str) {
1099 sum += a[
i] * b[
i] * c[
i];
1107 sum = (threadIdx.x < blockDim.x / warpSize) ? shared[lane] : 0;
1111 if (threadIdx.x == 0)
1112 buf_h[blockIdx.x] = sum;
1118template<
typename T,
typename T_acc >
1125 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
1126 const int str = blockDim.x * gridDim.x;
1128 const unsigned int lane = threadIdx.x % warpSize;
1129 const unsigned int wid = threadIdx.x / warpSize;
1131 __shared__ T_acc shared[32];
1133 for (
int i = idx;
i < n;
i+= str) {
1134 sum +=
static_cast<T_acc
>(a[
i] * b[
i] * c[
i]);
1142 sum = (threadIdx.x < blockDim.x / warpSize) ? shared[lane] : 0;
1146 if (threadIdx.x == 0)
1147 buf_h[blockIdx.x] = sum;
1153template<
typename T,
typename T_acc >
1161 const int idx = blockIdx.x * blockDim.y + threadIdx.y;
1162 const int str = blockDim.y * gridDim.x;
1163 const int y = threadIdx.x;
1165 __shared__ T_acc buf[1024];
1168 for (
int i = idx;
i < n;
i+= str) {
1169 tmp +=
static_cast<T_acc
>(a[
i] * b[threadIdx.x][
i] * c[
i]);
1173 buf[threadIdx.y*blockDim.x+y] = tmp;
1176 int i = blockDim.y>>1;
1178 if (threadIdx.y <
i) {
1179 buf[threadIdx.y*blockDim.x +y] += buf[(threadIdx.y +
i)*blockDim.x+y];
1184 if (threadIdx.y == 0) {
1186 buf_h[
j*blockIdx.x+y] = buf[y];
1194template<
typename T,
typename T_acc >
1200 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
1201 const int str = blockDim.x * gridDim.x;
1203 const unsigned int lane = threadIdx.x % warpSize;
1204 const unsigned int wid = threadIdx.x / warpSize;
1206 __shared__ T_acc shared[32];
1208 for (
int i = idx;
i < n;
i+= str) {
1209 sum +=
static_cast<T_acc
>(a[
i] * b[
i]);
1217 sum = (threadIdx.x < blockDim.x / warpSize) ? shared[lane] : 0;
1221 if (threadIdx.x == 0)
1222 buf_h[blockIdx.x] = sum;
1229template<
typename T,
typename T_acc >
1235 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
1236 const int str = blockDim.x * gridDim.x;
1238 const unsigned int lane = threadIdx.x % warpSize;
1239 const unsigned int wid = threadIdx.x / warpSize;
1241 __shared__ T_acc shared[32];
1243 for (
int i = idx;
i < n;
i+= str) {
1244 sum +=
static_cast<T_acc
>(pow(a[
i] - b[
i], 2.0));
1252 sum = (threadIdx.x < blockDim.x / warpSize) ? shared[lane] : 0;
1256 if (threadIdx.x == 0)
1257 buf_h[blockIdx.x] = sum;
1264template<
typename T,
typename T_acc >
1269 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
1270 const int str = blockDim.x * gridDim.x;
1272 const unsigned int lane = threadIdx.x % warpSize;
1273 const unsigned int wid = threadIdx.x / warpSize;
1275 __shared__ T_acc shared[32];
1277 for (
int i = idx;
i<n ;
i += str)
1279 sum +=
static_cast<T_acc
>(a[
i]);
1287 sum = (threadIdx.x < blockDim.x / warpSize) ? shared[lane] : 0;
1291 if (threadIdx.x == 0)
1292 buf_h[blockIdx.x] = sum;
1299template<
typename T >
1305 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
1306 const int str = blockDim.x * gridDim.x;
1308 const unsigned int lane = threadIdx.x % warpSize;
1309 const unsigned int wid = threadIdx.x / warpSize;
1311 __shared__ T shared[32];
1313 for (
int i = idx;
i<n ;
i += str)
1315 max_val =
max(max_val, a[
i]);
1320 shared[wid] = max_val;
1323 max_val = (threadIdx.x < blockDim.x / warpSize) ? shared[lane] : ninf;
1327 if (threadIdx.x == 0)
1328 buf_h[blockIdx.x] = max_val;
1336template<
typename T >
1341 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
1342 const int str = blockDim.x * gridDim.x;
1344 const unsigned int lane = threadIdx.x % warpSize;
1345 const unsigned int wid = threadIdx.x / warpSize;
1347 __shared__ T shared[32];
1349 for (
int i = idx;
i<n ;
i += str)
1351 max_val =
max(max_val, fabs(a[
i]));
1356 shared[wid] = max_val;
1359 max_val = (threadIdx.x < blockDim.x / warpSize) ? shared[lane] : T(0);
1363 if (threadIdx.x == 0)
1364 buf_h[blockIdx.x] = max_val;
1371template<
typename T >
1377 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
1378 const int str = blockDim.x * gridDim.x;
1380 const unsigned int lane = threadIdx.x % warpSize;
1381 const unsigned int wid = threadIdx.x / warpSize;
1383 __shared__ T shared[32];
1385 for (
int i = idx;
i<n ;
i += str)
1387 min_val = min(min_val, a[
i]);
1392 shared[wid] = min_val;
1395 min_val = (threadIdx.x < blockDim.x / warpSize) ? shared[lane] : pinf;
1399 if (threadIdx.x == 0)
1400 buf_h[blockIdx.x] = min_val;
1407template<
typename T >
1411 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
1412 const int str = blockDim.x * gridDim.x;
1414 for (
int i = idx;
i < n;
i += str) {
1426template <
typename T>
1430 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
1431 const int str = blockDim.x * gridDim.x;
1433 for (
int i = idx;
i < n;
i += str) a[
i] =
max(a[
i], b[
i]);
1440template <
typename T>
1442 T* __restrict__ a,
const T* __restrict__ b,
const T* __restrict__ c,
1445 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
1446 const int str = blockDim.x * gridDim.x;
1448 for (
int i = idx;
i < n;
i += str) a[
i] =
max(b[
i], c[
i]);
1455template <
typename T>
1458 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
1459 const int str = blockDim.x * gridDim.x;
1461 for (
int i = idx;
i < n;
i += str) a[
i] =
max(a[
i], c);
1468template <
typename T>
1470 T* __restrict__ a,
const T* __restrict b,
const T c,
const int n) {
1472 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
1473 const int str = blockDim.x * gridDim.x;
1475 for (
int i = idx;
i < n;
i += str) a[
i] =
max(b[
i], c);
1482template <
typename T>
1486 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
1487 const int str = blockDim.x * gridDim.x;
1489 for (
int i = idx;
i < n;
i += str) a[
i] = min(a[
i], b[
i]);
1496template <
typename T>
1498 T* __restrict__ a,
const T* __restrict__ b,
const T* __restrict__ c,
1501 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
1502 const int str = blockDim.x * gridDim.x;
1504 for (
int i = idx;
i < n;
i += str) a[
i] = min(b[
i], c[
i]);
1511template <
typename T>
1514 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
1515 const int str = blockDim.x * gridDim.x;
1517 for (
int i = idx;
i < n;
i += str) a[
i] = min(a[
i], c);
1524template <
typename T>
1526 T* __restrict__ a,
const T* __restrict b,
const T c,
const int n) {
1528 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
1529 const int str = blockDim.x * gridDim.x;
1531 for (
int i = idx;
i < n;
i += str) a[
i] = min(b[
i], c);
__global__ void const T *__restrict__ x
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ w3
__global__ void addcol4_kernel(T *__restrict__ a, const T *__restrict__ b, const T *__restrict__ c, const T *__restrict__ d, const int n)
__global__ void cwrap_kernel(T *__restrict__ a, const T min_val, const T max_val, const int n)
__global__ void pwmin_vec3_kernel(T *__restrict__ a, const T *__restrict__ b, const T *__restrict__ c, const int n)
__global__ void reduce_kernel(T *bufred, const int n)
__global__ void cdiv2_kernel(T *__restrict__ a, T *__restrict__ b, const T c, const int n)
__global__ void invcol2_kernel(T *__restrict__ a, const T *__restrict__ b, const int n)
__global__ void add2_kernel(T *__restrict__ a, const T *__restrict__ b, const int n)
__global__ void add4s3_kernel(T *__restrict__ a, const T *__restrict__ b, const T *__restrict__ c, const T *__restrict__ d, const T c1, const T c2, const T c3, const int n)
__inline__ __device__ T reduce_warp(T val)
__global__ void masked_scatter_copy_aligned_kernel(T *__restrict__ a, T *__restrict__ b, int *__restrict__ mask, const int n, const int n_mask)
__global__ void masked_atomic_reduction_kernel(T *__restrict__ a, T *__restrict__ b, int *__restrict__ mask, const int n, const int m)
__global__ void pwmax_vec3_kernel(T *__restrict__ a, const T *__restrict__ b, const T *__restrict__ c, const int n)
__global__ void glsc2_kernel(const T *a, const T *b, T_acc *buf_h, const int n)
__global__ void addcol3s2_kernel(T *__restrict__ a, const T *__restrict__ b, const T *__restrict__ c, const T s, const int n)
__global__ void cfill_mask_kernel(T *__restrict__ a, const T c, const int size, int *__restrict__ mask, const int mask_size)
__global__ void cdiv_kernel(T *__restrict__ a, const T c, const int n)
__global__ void masked_copy_kernel_aligned(T *__restrict__ a, T *__restrict__ b, int *__restrict__ mask, const int n, const int n_mask)
__global__ void face_masked_gather_copy_kernel(T *__restrict__ a, const T *__restrict__ b, const int *__restrict__ mask, const int *__restrict__ facet, const int n1, const int n2, const int lx, const int ly, const int lz, const int n_mask)
__global__ void masked_gather_copy_aligned_kernel(T *__restrict__ a, T *__restrict__ b, int *__restrict__ mask, const int n, const int n_mask)
__global__ void pwmax_sca2_kernel(T *__restrict__ a, const T c, const int n)
__device__ __forceinline__ void face_gather_nonlinear_index(int *index, const int idx, const int lx, const int ly, const int lz)
__global__ void reduce_max_kernel(T *bufred, const T ninf, const int n)
__global__ void pwmin_vec2_kernel(T *__restrict__ a, const T *__restrict__ b, const int n)
__global__ void add3s2_kernel(T *__restrict__ a, const T *__restrict__ b, const T *__restrict__ c, const T c1, const T c2, const int n)
__inline__ __device__ T reduce_max_warp(T val)
__global__ void glsum_kernel(const T *a, T_acc *buf_h, const int n)
__global__ void add2s1_kernel(T *__restrict__ a, const T *__restrict__ b, const T c1, const int n)
__device__ __forceinline__ int face_gather_idx(const int i, const int j, const int k, const int l, const int n1, const int n2, const int nf)
__global__ void add5s4_kernel(T *__restrict__ a, const T *__restrict__ b, const T *__restrict__ c, const T *__restrict__ d, const T *__restrict__ e, const T c1, const T c2, const T c3, const T c4, const int n)
#define MASKED_ATOMIC_RED_BLOCK
__global__ void masked_gather_copy_kernel(T *__restrict__ a, T *__restrict__ b, int *__restrict__ mask, const int n, const int n_mask)
__global__ void add2s2_many_kernel(T *__restrict__ x, const T **p, const T *alpha, const int p_cur, const int n)
__global__ void glsc3_many_kernel(const T *a, const T **b, const T *c, T_acc *buf_h, const int j, const int n)
__global__ void pwmax_vec2_kernel(T *__restrict__ a, const T *__restrict__ b, const int n)
__global__ void cmult_kernel(T *__restrict__ a, const T c, const int n)
__global__ void addcol3_kernel(T *__restrict__ a, const T *__restrict__ b, const T *__restrict__ c, const int n)
__global__ void pwmin_sca3_kernel(T *__restrict__ a, const T *__restrict b, const T c, const int n)
__global__ void pwmax_sca3_kernel(T *__restrict__ a, const T *__restrict b, const T c, const int n)
__global__ void power_kernel(T *__restrict__ ap, const T *__restrict__ a, const T p, const int n)
__global__ void col2_kernel(T *__restrict__ a, const T *__restrict__ b, const int n)
__global__ void masked_copy_kernel_0(T *__restrict__ a, T *__restrict__ b, int *__restrict__ mask, const int n, const int n_mask)
__global__ void sqrt_inplace_kernel(T *__restrict__ a, const int n)
__global__ void col3_kernel(T *__restrict__ a, const T *__restrict__ b, const T *__restrict__ c, const int n)
__global__ void sub2_kernel(T *__restrict__ a, const T *__restrict__ b, const int n)
__global__ void glmin_kernel(const T *a, const T pinf, T *buf_h, const int n)
__global__ void cmult2_kernel(T *__restrict__ a, T *__restrict__ b, const T c, const int n)
__global__ void pwmin_sca2_kernel(T *__restrict__ a, const T c, const int n)
__global__ void sub3_kernel(T *__restrict__ a, const T *__restrict__ b, const T *__restrict__ c, const int n)
__global__ void glsubnorm2_kernel(const T *a, const T *b, T_acc *buf_h, const int n)
__global__ void glsc3_reduce_kernel(T_acc *bufred, const int n, const int j)
__global__ void add2s2_kernel(T *__restrict__ a, const T *__restrict__ b, const T c1, const int n)
__global__ void vdot3_kernel(T *__restrict__ dot, const T *__restrict__ u1, const T *__restrict__ u2, const T *__restrict__ u3, const T *__restrict__ v1, const T *__restrict__ v2, const T *__restrict__ v3, const int n)
__global__ void invcol1_kernel(T *__restrict__ a, const int n)
__global__ void add3_kernel(T *__restrict__ a, const T *__restrict__ b, const T *__restrict__ c, const int n)
__global__ void glmax_kernel(const T *a, const T ninf, T *buf_h, const int n)
__global__ void vlsc3_kernel(const T *a, const T *b, const T *c, T *buf_h, const int n)
__global__ void add4_kernel(T *__restrict__ a, const T *__restrict__ b, const T *__restrict__ c, const T *__restrict__ d, const int n)
__global__ void cfill_kernel(T *__restrict__ a, const T c, const int n)
__global__ void masked_scatter_copy_kernel(T *__restrict__ a, T *__restrict__ b, int *__restrict__ mask, const int n, const int n_mask)
__global__ void glsc3_kernel(const T *a, const T *b, const T *c, T_acc *buf_h, const int n)
__global__ void reduce_min_kernel(T *bufred, const T pinf, const int n)
__global__ void vcross_kernel(T *__restrict__ u1, T *__restrict__ u2, T *__restrict__ u3, const T *__restrict__ v1, const T *__restrict__ v2, const T *__restrict__ v3, const T *__restrict__ w1, const T *__restrict__ w2, const T *__restrict__ w3, const int n)
__global__ void addsqr2s2_kernel(T *__restrict__ a, const T *__restrict__ b, const T c1, const int n)
__global__ void cadd2_kernel(T *__restrict__ a, T *__restrict__ b, const T c, const int n)
__global__ void absval_kernel(T *__restrict__ a, const int n)
__global__ void invcol3_kernel(T *__restrict__ a, const T *__restrict__ b, const T *__restrict__ c, const int n)
__global__ void subcol3_kernel(T *__restrict__ a, const T *__restrict__ b, const T *__restrict__ c, const int n)
__global__ void cadd_kernel(T *__restrict__ a, const T c, const int n)
__global__ void glamax_kernel(const T *a, T *buf_h, const int n)
__inline__ __device__ T reduce_min_warp(T val)
Object for handling masks in Neko.