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) {
79 int * __restrict__
mask,
83 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
84 const int str = blockDim.x * gridDim.x;
86 for (
int i = idx;
i < n_mask;
i += str) {
91__device__ __forceinline__
93 const int ly,
const int lz) {
94 const int idx2 = idx - 1;
95 index[3] = idx2 / (lx * ly * lz);
96 index[2] = (idx2 - (lx * ly * lz) * index[3]) / (lx * ly);
97 index[1] = (idx2 - (lx * ly * lz) * index[3] - (lx * ly) * index[2]) / lx;
98 index[0] = (idx2 - (lx * ly * lz) * index[3] - (lx * ly) * index[2]) -
106__device__ __forceinline__
108 const int n1,
const int n2,
const int nf) {
109 return ((
i) + (n1) * (((
j) - 1) + (n2) * (((k) - 1) + (nf) * (((l) - 1))))) - 1;
115template<
typename T >
117 const T * __restrict__ b,
118 const int * __restrict__
mask,
119 const int * __restrict__ facet,
128 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
129 const int str = blockDim.x * gridDim.x;
131 for (
int m = idx; m < n_mask; m += str) {
132 const int f = facet[m + 1];
155template<
typename T >
158 int * __restrict__
mask,
162 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
163 const int str = blockDim.x * gridDim.x;
165 for (
int i = idx;
i < n_mask;
i += str) {
173template<
typename T >
176 int * __restrict__
mask,
180 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
181 const int str = blockDim.x * gridDim.x;
183 for (
int i = idx;
i < n_mask;
i += str) {
192#define MASKED_ATOMIC_RED_BLOCK 256
197template<
typename T >
200 int * __restrict__
mask,
205 __shared__
int bins_base;
210 bins[threadIdx.x] = 0.0;
217 if (threadIdx.x == 0)
220 const int kbase = bins_base;
222 const int i = base + threadIdx.x;
226 key =
mask[
i + 1] - 1;
233 const int key_prev = __shfl_up(key, 1);
234 const bool head = (lane == 0) || (key != key_prev);
235 const unsigned long long heads = __ballot(head);
243 unsafeAtomicAdd(&a[key], val);
246 const unsigned long long next = heads & ~((2ull << lane) - 1ull);
247 const int run_end = next ? __ffsll(next) - 2 :
NEKO_WAVE_SIZE - 1;
252 const T tmp = __shfl_down(val, off);
253 if (lane + off <= run_end)
257 if (head && key >= 0) {
258 const int s = key - kbase;
260 atomicAdd(&bins[s], val);
262 unsafeAtomicAdd(&a[key], val);
269 const T sum = bins[threadIdx.x];
270 if (sum != (T) 0.0) {
271 unsafeAtomicAdd(&a[kbase + threadIdx.x], sum);
272 bins[threadIdx.x] = 0.0;
280template<
typename T >
283 int * __restrict__
mask,
287 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
288 const int str = blockDim.x * gridDim.x;
290 for (
int i = idx;
i < n_mask;
i += str) {
298template<
typename T >
301 int * __restrict__
mask,
305 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
306 const int str = blockDim.x * gridDim.x;
308 for (
int i = idx;
i < n_mask;
i += str) {
316template<
typename T >
320 int* __restrict__
mask,
323 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
324 const int str = blockDim.x * gridDim.x;
326 for (
int i = idx;
i < n_mask;
i += str) { a[
mask[
i]] = c; }
332template<
typename T >
338 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
339 const int str = blockDim.x * gridDim.x;
341 for (
int i = idx;
i < n;
i += str) {
349template<
typename T >
354 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
355 const int str = blockDim.x * gridDim.x;
357 for (
int i = idx;
i < n;
i += str) {
365template<
typename T >
371 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
372 const int str = blockDim.x * gridDim.x;
374 for (
int i = idx;
i < n;
i += str) {
382template<
typename T >
387 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
388 const int str = blockDim.x * gridDim.x;
390 for (
int i = idx;
i < n;
i += str) {
398template<
typename T >
404 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
405 const int str = blockDim.x * gridDim.x;
407 for (
int i = idx;
i < n;
i += str) {
415template<
typename T >
421 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
422 const int str = blockDim.x * gridDim.x;
423 const T l = max_val - min_val;
425 for (
int i = idx;
i < n;
i += str) {
426 a[
i] = min_val + fmod(fmod(a[
i] - min_val, l) + l, l);
433template<
typename T >
437 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
438 const int str = blockDim.x * gridDim.x;
440 for (
int i = idx;
i < n;
i += str) {
448template<
typename T >
450 const T * __restrict__ a,
454 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
455 const int str = blockDim.x * gridDim.x;
457 for (
int i = idx;
i < n;
i += str) {
458 ap[
i] = pow(a[
i], p);
465template<
typename T >
470 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
471 const int str = blockDim.x * gridDim.x;
473 for (
int i = idx;
i < n;
i += str) {
481template<
typename T >
483 const T * __restrict__ b,
486 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
487 const int str = blockDim.x * gridDim.x;
489 for (
int i = idx;
i < n;
i += str) {
497template<
typename T >
499 const T * __restrict__ b,
502 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
503 const int str = blockDim.x * gridDim.x;
505 for (
int i = idx;
i < n;
i += str) {
513template<
typename T >
515 const T * __restrict__ b,
516 const T * __restrict__ c,
519 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
520 const int str = blockDim.x * gridDim.x;
522 for (
int i = idx;
i < n;
i += str) {
530template<
typename T >
532 const T * __restrict__ b,
533 const T * __restrict__ c,
534 const T * __restrict__ d,
537 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
538 const int str = blockDim.x * gridDim.x;
540 for (
int i = idx;
i < n;
i += str) {
541 a[
i] = b[
i] + c[
i] + d[
i];
548template<
typename T >
550 const T * __restrict__ b,
554 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
555 const int str = blockDim.x * gridDim.x;
557 for (
int i = idx;
i < n;
i += str) {
558 a[
i] = c1 * a[
i] + b[
i];
565template<
typename T >
572 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
573 const int str = blockDim.x * gridDim.x;
576 for (
int i = idx;
i < n;
i+= str) {
578 for (
int j = 0;
j < p_cur;
j ++) {
579 tmp += p[
j][
i]*alpha[
j];
588template<
typename T >
590 const T * __restrict__ b,
594 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
595 const int str = blockDim.x * gridDim.x;
597 for (
int i = idx;
i < n;
i += str) {
598 a[
i] = a[
i] + c1 * b[
i];
605template<
typename T >
607 const T * __restrict__ b,
611 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
612 const int str = blockDim.x * gridDim.x;
614 for (
int i = idx;
i < n;
i += str) {
615 a[
i] = a[
i] + c1 * (b[
i] * b[
i]);
622template<
typename T >
624 const T * __restrict__ b,
625 const T * __restrict__ c,
630 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
631 const int str = blockDim.x * gridDim.x;
633 for (
int i = idx;
i < n;
i += str) {
634 a[
i] = c1 * b[
i] + c2 * c[
i];
641template<
typename T >
643 const T * __restrict__ b,
644 const T * __restrict__ c,
645 const T * __restrict__ d,
651 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
652 const int str = blockDim.x * gridDim.x;
654 for (
int i = idx;
i < n;
i += str) {
655 a[
i] = c1 * b[
i] + c2 * c[
i] + c3 * d[
i];
662template<
typename T >
664 const T * __restrict__ b,
665 const T * __restrict__ c,
666 const T * __restrict__ d,
667 const T * __restrict__
e,
674 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
675 const int str = blockDim.x * gridDim.x;
677 for (
int i = idx;
i < n;
i += str) {
678 a[
i] = a[
i] + c1 * b[
i] + c2 * c[
i] + c3 * d[
i] + c4 *
e[
i];
685template<
typename T >
689 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
690 const int str = blockDim.x * gridDim.x;
693 for (
int i = idx;
i < n;
i += str) {
701template<
typename T >
703 const T * __restrict__ b,
706 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
707 const int str = blockDim.x * gridDim.x;
709 for (
int i = idx;
i < n;
i += str) {
717template<
typename T >
719 const T * __restrict__ b,
720 const T * __restrict__ c,
723 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
724 const int str = blockDim.x * gridDim.x;
726 for (
int i = idx;
i < n;
i += str) {
734template<
typename T >
736 const T * __restrict__ b,
739 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
740 const int str = blockDim.x * gridDim.x;
742 for (
int i = idx;
i < n;
i += str) {
750template<
typename T >
752 const T * __restrict__ b,
753 const T * __restrict__ c,
756 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
757 const int str = blockDim.x * gridDim.x;
759 for (
int i = idx;
i < n;
i += str) {
767template<
typename T >
769 const T * __restrict__ b,
770 const T * __restrict__ c,
773 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
774 const int str = blockDim.x * gridDim.x;
776 for (
int i = idx;
i < n;
i += str) {
777 a[
i] = a[
i] - b[
i] * c[
i];
784template<
typename T >
786 const T * __restrict__ b,
789 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
790 const int str = blockDim.x * gridDim.x;
792 for (
int i = idx;
i < n;
i += str) {
800template<
typename T >
802 const T * __restrict__ b,
803 const T * __restrict__ c,
806 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
807 const int str = blockDim.x * gridDim.x;
809 for (
int i = idx;
i < n;
i += str) {
817template<
typename T >
819 const T * __restrict__ b,
820 const T * __restrict__ c,
823 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
824 const int str = blockDim.x * gridDim.x;
826 for (
int i = idx;
i < n;
i += str) {
827 a[
i] = a[
i] + b[
i] * c[
i];
835template<
typename T >
837 const T * __restrict__ b,
838 const T * __restrict__ c,
839 const T * __restrict__ d,
842 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
843 const int str = blockDim.x * gridDim.x;
845 for (
int i = idx;
i < n;
i += str) {
846 a[
i] = a[
i] + b[
i] * c[
i] * d[
i];
854template<
typename T >
856 const T * __restrict__ b,
857 const T * __restrict__ c,
861 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
862 const int str = blockDim.x * gridDim.x;
864 for (
int i = idx;
i < n;
i += str) {
865 a[
i] = a[
i] + s * b[
i] * c[
i];
873template<
typename T >
875 const T * __restrict__ u1,
876 const T * __restrict__ u2,
877 const T * __restrict__ u3,
878 const T * __restrict__ v1,
879 const T * __restrict__ v2,
880 const T * __restrict__ v3,
883 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
884 const int str = blockDim.x * gridDim.x;
886 for (
int i = idx;
i < n;
i += str) {
887 dot[
i] = u1[
i] * v1[
i] + u2[
i] * v2[
i] + u3[
i] * v3[
i];
895template<
typename T >
899 const T * __restrict__ v1,
900 const T * __restrict__ v2,
901 const T * __restrict__ v3,
902 const T * __restrict__ w1,
903 const T * __restrict__ w2,
904 const T * __restrict__
w3,
907 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
908 const int str = blockDim.x * gridDim.x;
910 for (
int i = idx;
i < n;
i += str) {
911 u1[
i] = v2[
i]*
w3[
i] - v3[
i]*w2[
i];
912 u2[
i] = v3[
i]*w1[
i] - v1[
i]*
w3[
i];
913 u3[
i] = v1[
i]*w2[
i] - v2[
i]*w1[
i];
928#if NEKO_WAVE_SIZE == 64
929 val += __shfl_down(val, 32);
931 val += __shfl_down(val, 16);
932 val += __shfl_down(val, 8);
933 val += __shfl_down(val, 4);
934 val += __shfl_down(val, 2);
935 val += __shfl_down(val, 1);
944#if NEKO_WAVE_SIZE == 64
945 val =
max(val, __shfl_down(val, 32));
947 val =
max(val, __shfl_down(val, 16));
948 val =
max(val, __shfl_down(val, 8));
949 val =
max(val, __shfl_down(val, 4));
950 val =
max(val, __shfl_down(val, 2));
951 val =
max(val, __shfl_down(val, 1));
960#if NEKO_WAVE_SIZE == 64
961 val = min(val, __shfl_down(val, 32));
963 val = min(val, __shfl_down(val, 16));
964 val = min(val, __shfl_down(val, 8));
965 val = min(val, __shfl_down(val, 4));
966 val = min(val, __shfl_down(val, 2));
967 val = min(val, __shfl_down(val, 1));
974template<
typename T >
978 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
979 const int str = blockDim.x * gridDim.x;
980 for (
int i = idx;
i<n ;
i += str)
985 __shared__ T shared[64];
994 sum = (threadIdx.x < blockDim.x /
NEKO_WAVE_SIZE) ? shared[lane] : 0;
998 if (threadIdx.x == 0)
999 bufred[blockIdx.x] = sum;
1005template<
typename T >
1009 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
1010 const int str = blockDim.x * gridDim.x;
1011 for (
int i = idx;
i<n ;
i += str)
1013 max_val =
max(max_val, bufred[
i]);
1016 __shared__ T shared[64];
1022 shared[wid] = max_val;
1025 max_val = (threadIdx.x < blockDim.x /
NEKO_WAVE_SIZE) ? shared[lane] : ninf;
1029 if (threadIdx.x == 0)
1030 bufred[blockIdx.x] = max_val;
1036template<
typename T >
1040 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
1041 const int str = blockDim.x * gridDim.x;
1042 for (
int i = idx;
i<n ;
i += str)
1044 min_val = min(min_val, bufred[
i]);
1047 __shared__ T shared[64];
1053 shared[wid] = min_val;
1056 min_val = (threadIdx.x < blockDim.x /
NEKO_WAVE_SIZE) ? shared[lane] : pinf;
1060 if (threadIdx.x == 0)
1061 bufred[blockIdx.x] = min_val;
1068template<
typename T_acc >
1073 __shared__ T_acc buf[1024] ;
1074 const int idx = threadIdx.x;
1075 const int y= blockIdx.x;
1076 const int step = blockDim.x;
1079 for (
int i=idx ;
i<n ;
i+=step)
1081 buf[idx] += bufred[
i*
j + y];
1088 if(threadIdx.x <
i && (threadIdx.x +
i) < n )
1090 buf[threadIdx.x] += buf[threadIdx.x +
i] ;
1102template<
typename T >
1109 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
1110 const int str = blockDim.x * gridDim.x;
1115 __shared__ T shared[64];
1117 for (
int i = idx;
i < n;
i+= str) {
1118 sum += a[
i] * b[
i] * c[
i];
1126 sum = (threadIdx.x < blockDim.x /
NEKO_WAVE_SIZE) ? shared[lane] : 0;
1130 if (threadIdx.x == 0)
1131 buf_h[blockIdx.x] = sum;
1137template<
typename T,
typename T_acc >
1144 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
1145 const int str = blockDim.x * gridDim.x;
1150 __shared__ T_acc shared[64];
1152 for (
int i = idx;
i < n;
i+= str) {
1153 sum +=
static_cast<T_acc
>(a[
i] * b[
i] * c[
i]);
1161 sum = (threadIdx.x < blockDim.x /
NEKO_WAVE_SIZE) ? shared[lane] : 0;
1165 if (threadIdx.x == 0)
1166 buf_h[blockIdx.x] = sum;
1172template<
typename T,
typename T_acc >
1180 const int idx = blockIdx.x * blockDim.y + threadIdx.y;
1181 const int str = blockDim.y * gridDim.x;
1182 const int y = threadIdx.x;
1184 __shared__ T_acc buf[1024];
1187 for (
int i = idx;
i < n;
i+= str) {
1188 tmp +=
static_cast<T_acc
>(a[
i] * b[threadIdx.x][
i] * c[
i]);
1192 buf[threadIdx.y*blockDim.x+y] = tmp;
1195 int i = blockDim.y>>1;
1197 if (threadIdx.y <
i) {
1198 buf[threadIdx.y*blockDim.x +y] += buf[(threadIdx.y +
i)*blockDim.x+y];
1203 if (threadIdx.y == 0) {
1205 buf_h[
j*blockIdx.x+y] = buf[y];
1213template<
typename T,
typename T_acc >
1219 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
1220 const int str = blockDim.x * gridDim.x;
1225 __shared__ T_acc shared[64];
1227 for (
int i = idx;
i < n;
i+= str) {
1228 sum +=
static_cast<T_acc
>(a[
i] * b[
i]);
1236 sum = (threadIdx.x < blockDim.x /
NEKO_WAVE_SIZE) ? shared[lane] : 0;
1240 if (threadIdx.x == 0)
1241 buf_h[blockIdx.x] = sum;
1248template<
typename T,
typename T_acc >
1254 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
1255 const int str = blockDim.x * gridDim.x;
1260 __shared__ T_acc shared[64];
1262 for (
int i = idx;
i < n;
i+= str) {
1263 sum +=
static_cast<T_acc
>(pow(a[
i] - b[
i], 2.0));
1271 sum = (threadIdx.x < blockDim.x /
NEKO_WAVE_SIZE) ? shared[lane] : 0;
1275 if (threadIdx.x == 0)
1276 buf_h[blockIdx.x] = sum;
1283template<
typename T,
typename T_acc >
1288 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
1289 const int str = blockDim.x * gridDim.x;
1294 __shared__ T_acc shared[64];
1296 for (
int i = idx;
i<n ;
i += str)
1298 sum +=
static_cast<T_acc
>(a[
i]);
1306 sum = (threadIdx.x < blockDim.x /
NEKO_WAVE_SIZE) ? shared[lane] : 0;
1310 if (threadIdx.x == 0)
1311 buf_h[blockIdx.x] = sum;
1318template<
typename T >
1324 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
1325 const int str = blockDim.x * gridDim.x;
1330 __shared__ T shared[64];
1332 for (
int i = idx;
i<n ;
i += str)
1334 max_val =
max(max_val, a[
i]);
1339 shared[wid] = max_val;
1342 max_val = (threadIdx.x < blockDim.x /
NEKO_WAVE_SIZE) ? shared[lane] : ninf;
1346 if (threadIdx.x == 0)
1347 buf_h[blockIdx.x] = max_val;
1355template<
typename T >
1360 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
1361 const int str = blockDim.x * gridDim.x;
1366 __shared__ T shared[64];
1368 for (
int i = idx;
i<n ;
i += str)
1370 max_val =
max(max_val, fabs(a[
i]));
1375 shared[wid] = max_val;
1378 max_val = (threadIdx.x < blockDim.x /
NEKO_WAVE_SIZE) ? shared[lane] : T(0);
1382 if (threadIdx.x == 0)
1383 buf_h[blockIdx.x] = max_val;
1390template<
typename T >
1396 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
1397 const int str = blockDim.x * gridDim.x;
1402 __shared__ T shared[64];
1404 for (
int i = idx;
i<n ;
i += str)
1406 min_val = min(min_val, a[
i]);
1411 shared[wid] = min_val;
1414 min_val = (threadIdx.x < blockDim.x /
NEKO_WAVE_SIZE) ? shared[lane] : pinf;
1418 if (threadIdx.x == 0)
1419 buf_h[blockIdx.x] = min_val;
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) {
1445template <
typename T>
1449 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
1450 const int str = blockDim.x * gridDim.x;
1452 for (
int i = idx;
i < n;
i += str) a[
i] =
max(a[
i], b[
i]);
1459template <
typename T>
1461 T* __restrict__ a,
const T* __restrict__ b,
const T* __restrict__ c,
1464 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
1465 const int str = blockDim.x * gridDim.x;
1467 for (
int i = idx;
i < n;
i += str) a[
i] =
max(b[
i], c[
i]);
1474template <
typename T>
1477 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
1478 const int str = blockDim.x * gridDim.x;
1480 for (
int i = idx;
i < n;
i += str) a[
i] =
max(a[
i], c);
1487template <
typename T>
1489 T* __restrict__ a,
const T* __restrict b,
const T c,
const int n) {
1491 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
1492 const int str = blockDim.x * gridDim.x;
1494 for (
int i = idx;
i < n;
i += str) a[
i] =
max(b[
i], c);
1501template <
typename T>
1505 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
1506 const int str = blockDim.x * gridDim.x;
1508 for (
int i = idx;
i < n;
i += str) a[
i] = min(a[
i], b[
i]);
1515template <
typename T>
1517 T* __restrict__ a,
const T* __restrict__ b,
const T* __restrict__ c,
1520 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
1521 const int str = blockDim.x * gridDim.x;
1523 for (
int i = idx;
i < n;
i += str) a[
i] = min(b[
i], c[
i]);
1530template <
typename T>
1533 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
1534 const int str = blockDim.x * gridDim.x;
1536 for (
int i = idx;
i < n;
i += str) a[
i] = min(a[
i], c);
1543template <
typename T>
1545 T* __restrict__ a,
const T* __restrict b,
const T c,
const int n) {
1547 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
1548 const int str = blockDim.x * gridDim.x;
1550 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)
__global__ void copy_kernel(T *__restrict__ a, const T *__restrict__ b, const int n)
Object for handling masks in Neko.