37#define __ac__max(a,b) (a > b ? a : b)
38#define __ac__min(a,b) (a < b ? a : b)
40#if AC_DOUBLE_PRECISION != 1
45#define sqrt(x) sqrtf(x)
46#define fabs(x) fabsf(x)
53operator/(
const int3& a,
const int& b)
64operator*(
const int3& a,
const int b)
66 return (int3){a.x * b, a.y * b, a.z * b};
72operator -=(int3& lhs,
const int3& rhs)
80operator*(
const int3& a,
const int3& b)
82 return (int3){a.x * b.x, a.y * b.y, a.z * b.z};
87operator*(
const dim3& a,
const dim3& b)
89 return (dim3){a.x * b.x, a.y * b.y, a.z * b.z};
93operator*(
const dim3& a,
const int3& b)
95 return (int3){(int)(a.x * b.x),(int)(a.y * b.y),(int)(a.z * b.z)};
99operator-(
const int3& a,
const uint3& b)
101 return (int3){(int)(a.x - b.x), (int)(a.y - b.y), (int)(a.z - b.z)};
104operator+(
const int3& a,
const uint3& b)
106 return (int3){(int)(a.x + b.x), (int)(a.y + b.y), (int)(a.z + b.z)};
111exp(
const AcComplex& val)
113 return (AcComplex){
exp(val.x) *
cos(val.y),
exp(val.x) *
sin(val.y)};
117operator*(
const AcComplex& a,
const AcComplex& b)
119 return (AcComplex){a.x*b.x - a.y*b.y,a.x*b.y + b.x*a.y};
122operator/(
const AcComplex& a,
const AcComplex& b)
124 const AcReal divisor = b.x*b.x + b.y*b.y;
125 return (AcComplex){(a.x*b.x + a.y*b.y)/(divisor),(a.y*b.x - a.x*b.y)/(divisor)};
129operator/(
const AcReal& a,
const AcComplex& b)
131 const AcReal divisor = b.x*b.x + b.y*b.y;
132 return (AcComplex){(a*b.x)/(divisor),(-a*b.y)/(divisor)};
136operator/(
const AcComplex& a,
const AcReal& b)
147operator-(
const AcReal& a,
const AcComplex& b)
157operator+(
const AcReal& a,
const AcComplex& b)
167operator-(
const AcComplex& a,
const AcReal& b)
177operator+(
const AcComplex& a,
const AcReal& b)
188sqrt(
const AcComplex& a)
195typedef struct uint3_64 {
197 uint3_64(
const int3& a):
198 x(static_cast<uint64_t>(a.x)), y(static_cast<uint64_t>(a.y)), z(static_cast<uint64_t>(a.z)) {}
199 uint3_64(
const uint64_t _x,
const uint64_t _y,
const uint64_t _z):
200 x(_x), y(_y), z(_z) {}
203 explicit inline constexpr operator int3()
const
205 return (int3){(int)x, (
int)y, (int)z};
218sum(
const T& a,
const T& b)
225max(
const T& a,
const T& b,
const T& c)
227 const auto tmp = a > b ? a : b;
228 return (tmp > c) ? tmp : c;
232max(
const T& a,
const T& b,
const T& c,
const T& d)
234 auto res = a > b ? a : b;
235 res = res > c ? res : c;
236 res = res > d ? res : d;
242max(
const T& a,
const T& b,
const T& c,
const T& d,
const T& e)
244 auto res = a > b ? a : b;
245 res = res > c ? res : c;
246 res = res > d ? res : d;
247 res = res > e ? res : e;
253max(
const T& a,
const T& b,
const T& c,
const T& d,
const T& e,
const T& f)
255 auto res = a > b ? a : b;
256 res = res > c ? res : c;
257 res = res > d ? res : d;
258 res = res > e ? res : e;
259 res = res > f ? res : f;
265max(
const T& a,
const T& b,
const T& c,
const T& d,
const T& e,
const T& f,
const T& g)
267 auto res = a > b ? a : b;
268 res = res > c ? res : c;
269 res = res > d ? res : d;
270 res = res > e ? res : e;
271 res = res > f ? res : f;
272 res = res > g ? res : g;
278max(
const T& a,
const T& b,
const T& c,
const T& d,
const T& e,
const T& f,
const T& g,
const T& h)
280 auto res = a > b ? a : b;
281 res = res > c ? res : c;
282 res = res > d ? res : d;
283 res = res > e ? res : e;
284 res = res > f ? res : f;
285 res = res > g ? res : g;
286 res = res > h ? res : h;
293min(
const T& a,
const T& b,
const T& c)
295 const auto tmp = a < b ? a : b;
296 return (tmp < c) ? tmp : c;
299static inline const int3
300max(
const int3& a,
const int3& b)
302 return (int3){max(a.x, b.x), max(a.y, b.y), max(a.z, b.z)};
307static inline const int3
308min(
const int3& a,
const int3& b)
310 return (int3){min(a.x, b.x), min(a.y, b.y), min(a.z, b.z)};
316clamp(
const T& val,
const T& min,
const T& max)
318 return val < min ? min : val > max ? max : val;
322mod(
const int a,
const int b)
324 return ((a%b) + b) % b;
329is_power_of_two(
const unsigned val)
331 return val && !(val & (val - 1));
338operator+(
const int3& a,
const int3& b)
340 return (int3){a.x + b.x, a.y + b.y, a.z + b.z};
344operator-(
const int3& a)
346 return (int3){-a.x, -a.y, -a.z};
350operator*(
const int3& a,
const AcReal3& b)
352 return (AcReal3){a.x * b.x, a.y * b.y, a.z * b.z};
356operator*(
const AcReal3& a,
const int3& b)
358 return (AcReal3){a.x * b.x, a.y * b.y, a.z * b.z};
362operator*(
const int& a,
const int3& b)
364 return (int3){a * b.x, a * b.y, a * b.z};
368operator+(
const int3& a,
const int& b)
370 return (int3){a.x + b, a.y + b, a.z + b};
374operator+(
const int3& a,
const AcBool3& b)
376 return (int3){a.x + b.x, a.y + b.y, a.z + b.z};
380operator+(
const AcBool3& a,
const int3& b)
382 return (int3){a.x + b.x, a.y + b.y, a.z + b.z};
386operator+(
const int& a,
const int3& b)
388 return (int3){a + b.x, a + b.y, a + b.z};
392operator-(
const int3& a,
const int3& b)
394 return (int3){a.x - b.x, a.y - b.y, a.z - b.z};
399operator-(
const int& a,
const int3& b)
401 return (int3){a - b.x, a - b.y, a - b.z};
405operator-(
const int3& a,
const int& b)
407 return (int3){a.x - b, a.y - b, a.z - b};
413operator>=(
const int3& a,
const int3& b)
415 return a.x >= b.x && a.y >= b.y && a.z >= b.z;
419operator>(
const int3& a,
const int3& b)
421 return a.x > b.x && a.y > b.y && a.z > b.z;
425operator<=(
const int3& a,
const int3& b)
427 return a.x <= b.x && a.y <= b.y && a.z <= b.z;
432operator>=(
const int3& a,
const int& b)
434 return a.x >= b && a.y >= b && a.z >= b;
438operator<=(
const int3& a,
const int& b)
440 return a.x <= b && a.y <= b && a.z <= b;
444operator<=(
const Volume& a,
const Volume& b)
446 return a.x <= b.x && a.y <= b.y && a.z <= b.z;
455operator+(
const uint3_64& a,
const uint3_64& b)
457 return (uint3_64){a.x + b.x, a.y + b.y, a.z + b.z};
461operator-(
const uint3_64& a,
const uint3_64& b)
463 return (uint3_64){a.x - b.x, a.y - b.y, a.z - b.z};
467operator*(
const uint3_64& a,
const uint3_64& b)
469 return (uint3_64){a.x * b.x, a.y * b.y, a.z * b.z};
472static inline uint3_64
473operator*(
const int& a,
const uint3_64& b)
478static inline uint3_64
479operator/(
const int3& a,
const uint3_64& b)
484static inline uint3_64
485operator/(
const uint3_64& a,
const int3& b)
491static inline uint3_64
492operator/(
const Volume& a,
const uint3_64& b)
494 return (uint3_64){a.x / b.x, a.y / b.y, a.z / b.z};
497static inline uint3_64
498operator+(
const uint3_64& a,
const Volume& b)
500 return (uint3_64){a.x + b.x, a.y + b.y, a.z + b.z};
503static inline uint3_64
504operator+(
const Volume& a,
const uint3_64& b)
506 return (uint3_64){a.x + b.x, a.y + b.y, a.z + b.z};
509static inline uint3_64
510operator/(
const uint3_64& a,
const Volume& b)
512 return (uint3_64){a.x / b.x, a.y / b.y, a.z / b.z};
516operator==(
const uint3_64& a,
const uint3_64& b)
518 return a.x == b.x && a.y == b.y && a.z == b.z;
524operator==(
const dim3& a,
const dim3& b)
534volume_size(
const T a)
545 return !isnan(a) && !isinf(a);
550AC_dot(
const AcReal2& a,
const AcReal2& b)
552 return a.x * b.x + a.y * b.y;
556is_valid(
const AcReal2& a)
558 return is_valid(a.x) && is_valid(a.y);
588max(
const AcReal3& v,
const AcReal& s)
599max(
const AcReal& s,
const AcReal3& v)
616AC_dot(
const AcReal3& a,
const AcReal3& b)
618 return a.x * b.x + a.y * b.y + a.z * b.z;
622AC_dot(
const int3& a,
const AcReal3& b)
624 return a.x * b.x + a.y * b.y + a.z * b.z;
628AC_dot(
const AcReal3& a,
const int3& b)
630 return a.x * b.x + a.y * b.y + a.z * b.z;
634AC_cross(
const AcReal3& a,
const AcReal3& b)
638 a.y * b.z - a.z * b.y,
639 a.z * b.x - a.x * b.z,
640 a.x * b.y - a.y * b.x,
645is_valid(
const AcReal3& a)
647 return is_valid(a.x) && is_valid(a.y) && is_valid(a.z);
655typedef struct AcMatrix {
677 return (AcReal3){data[row][0], data[row][1], data[row][2]};
681 return (AcReal3){data[0][col], data[1][col], data[2][col]};
695 return AcMatrix(-row(0), -row(1), -row(2));
716multm2_sym(
const AcMatrix m)
718 AcReal res = m.data[0][0]*m.data[0][0];
719 for(
int i = 1; i < 3; ++i)
721 res += m.data[i][i]*m.data[i][i];
722 for(
int j = 0; j < i; ++j)
724 res += 2*m.data[i][j]*m.data[i][j];
731operator*(
const AcReal& v,
const AcMatrix& m)
735 out.data[0][0] = v * m.data[0][0];
736 out.data[0][1] = v * m.data[0][1];
737 out.data[0][2] = v * m.data[0][2];
739 out.data[1][0] = v * m.data[1][0];
740 out.data[1][1] = v * m.data[1][1];
741 out.data[1][2] = v * m.data[1][2];
743 out.data[2][0] = v * m.data[2][0];
744 out.data[2][1] = v * m.data[2][1];
745 out.data[2][2] = v * m.data[2][2];
751operator/(
const AcMatrix& m,
const AcReal& v)
755 out.data[0][0] = m.data[0][0] / v;
756 out.data[0][1] = m.data[0][1] / v;
757 out.data[0][2] = m.data[0][2] / v;
759 out.data[1][0] = m.data[1][0] / v;
760 out.data[1][1] = m.data[1][1] / v;
761 out.data[1][2] = m.data[1][2] / v;
763 out.data[2][0] = m.data[2][0] / v;
764 out.data[2][1] = m.data[2][1] / v;
765 out.data[2][2] = m.data[2][2] / v;
771operator+(
const AcMatrix& a,
const AcMatrix& b)
775 out.data[0][0] = a.data[0][0] + b.data[0][0];
776 out.data[0][1] = a.data[0][1] + b.data[0][1];
777 out.data[0][2] = a.data[0][2] + b.data[0][2];
779 out.data[1][0] = a.data[1][0] + b.data[1][0];
780 out.data[1][1] = a.data[1][1] + b.data[1][1];
781 out.data[1][2] = a.data[1][2] + b.data[1][2];
783 out.data[2][0] = a.data[2][0] + b.data[2][0];
784 out.data[2][1] = a.data[2][1] + b.data[2][1];
785 out.data[2][2] = a.data[2][2] + b.data[2][2];
791operator-(
const AcMatrix& a,
const AcMatrix& b)
795 out.data[0][0] = a.data[0][0] - b.data[0][0];
796 out.data[0][1] = a.data[0][1] - b.data[0][1];
797 out.data[0][2] = a.data[0][2] - b.data[0][2];
799 out.data[1][0] = a.data[1][0] - b.data[1][0];
800 out.data[1][1] = a.data[1][1] - b.data[1][1];
801 out.data[1][2] = a.data[1][2] - b.data[1][2];
803 out.data[2][0] = a.data[2][0] - b.data[2][0];
804 out.data[2][1] = a.data[2][1] - b.data[2][1];
805 out.data[2][2] = a.data[2][2] - b.data[2][2];
811operator*(AcReal3 v,
const AcMatrix& m)
822operator*(AcMatrix a,
const AcMatrix& b)
826 out.data[0][0] = AC_dot(a.row(0),b.col(0));
827 out.data[0][1] = AC_dot(a.row(0),b.col(1));
828 out.data[0][2] = AC_dot(a.row(0),b.col(2));
830 out.data[1][0] = AC_dot(a.row(1),b.col(0));
831 out.data[1][1] = AC_dot(a.row(1),b.col(1));
832 out.data[1][2] = AC_dot(a.row(1),b.col(2));
834 out.data[2][0] = AC_dot(a.row(2),b.col(0));
835 out.data[2][1] = AC_dot(a.row(2),b.col(1));
836 out.data[2][2] = AC_dot(a.row(2),b.col(2));
919operator*(
const int3& a,
const Volume& b)
933operator+(
const int3& a,
const Volume& b)
947operator*(
const Volume& a,
const AcReal3& b)
958operator*(
const AcReal3& a,
const Volume& b)
970operator-=(Volume& a,
const int3& b)
981operator-=(Volume& a,
const Volume& b)
993operator==(
const Volume& a,
const Volume& b)
1002operator!=(
const Volume& a,
const Volume& b)
1010typedef struct AcTensor {
1018 data[0][0][0] = m0.data[0][0];
1019 data[0][1][0] = m0.data[0][1];
1020 data[0][2][0] = m0.data[0][2];
1022 data[1][0][0] = m0.data[1][0];
1023 data[1][1][0] = m0.data[1][1];
1024 data[1][2][0] = m0.data[1][2];
1026 data[2][0][0] = m0.data[2][0];
1027 data[2][1][0] = m0.data[2][1];
1028 data[2][2][0] = m0.data[2][2];
1030 data[0][0][1] = m1.data[0][0];
1031 data[0][1][1] = m1.data[0][1];
1032 data[0][2][1] = m1.data[0][2];
1034 data[1][0][1] = m1.data[1][0];
1035 data[1][1][1] = m1.data[1][1];
1036 data[1][2][1] = m1.data[1][2];
1038 data[2][0][1] = m1.data[2][0];
1039 data[2][1][1] = m1.data[2][1];
1040 data[2][2][1] = m1.data[2][2];
1042 data[0][0][2] = m2.data[0][0];
1043 data[0][1][2] = m2.data[0][1];
1044 data[0][2][2] = m2.data[0][2];
1046 data[1][0][2] = m2.data[1][0];
1047 data[1][1][2] = m2.data[1][1];
1048 data[1][2][2] = m2.data[1][2];
1050 data[2][0][2] = m2.data[2][0];
1051 data[2][1][2] = m2.data[2][1];
1052 data[2][2][2] = m2.data[2][2];
1059matmul_arr(
const AcReal* m,
const AcReal3& v)
1061 AcReal x = m[0 + 3*0]*v.x;
1062 x += m[0 + 3*1]*v.y;
1063 x += m[0 + 3*2]*v.z;
1065 AcReal y = m[1 + 3*0]*v.x;
1066 y += m[1 + 3*1]*v.y;
1067 y += m[1 + 3*2]*v.z;
1069 AcReal z = m[2 + 3*0]*v.x;
1070 z += m[2 + 3*1]*v.y;
1071 z += m[2 + 3*2]*v.z;
1072 return (AcReal3){x,y,z};
1075matmul_arr(
AcReal* m,
const AcReal3& v)
1077 AcReal x = m[0 + 3*0]*v.x;
1078 x += m[0 + 3*1]*v.y;
1079 x += m[0 + 3*2]*v.z;
1081 AcReal y = m[1 + 3*0]*v.x;
1082 y += m[1 + 3*1]*v.y;
1083 y += m[1 + 3*2]*v.z;
1085 AcReal z = m[2 + 3*0]*v.x;
1086 z += m[2 + 3*1]*v.y;
1087 z += m[2 + 3*2]*v.z;
1088 return (AcReal3){x,y,z};
1090template <
typename T>
1092broadcast_scalar(T& arr,
const AcReal& val)
1094 const size_t arr_len =
sizeof(arr)/
sizeof(arr[0]);
1095 for(
size_t i = 0; i < arr_len; ++i)
1098template <const
size_t N1, const
size_t N2>
1100broadcast_scalar_2d(
AcReal (&arr)[N1][N2],
const AcReal& val)
1102 for(
size_t i = 0; i < N1; ++i)
1103 for(
size_t j= 0; j < N2; ++j)
1106template <
typename T>
1108broadcast_scalar_to_vec(T& arr,
const AcReal& val)
1110 const size_t arr_len =
sizeof(arr)/
sizeof(arr[0]);
1111 for(
size_t i = 0; i < arr_len; ++i)
1112 arr[i] = (AcReal3){val,val,val};
1114template <
typename T1,
typename T2>
1116copy_arr(T1& a,
const T2& b)
1118 const size_t arr_len =
sizeof(a)/
sizeof(a[0]);
1119 for(
size_t i = 0; i < arr_len; ++i)
1123max(
const uint64_t& a,
const int& b)
1125 return a > (uint64_t)b ? a : (uint64_t)b;
1129AC_get_array_len(
const Field (&arr)[N])
1136to_int3(
const uint3_64 a)
1148#include "generated_comp_funcs.h"
1163AC_abs(
const int& x) {
return abs(x);}
float AcReal
Definition acreal.h:11
#define as_size_t(i)
Definition errchk.h:101
#define ERRCHK_ALWAYS(retval)
Definition errchk.h:95
#define HOST_INLINE
Definition func_attributes.h:16
#define HOST_DEVICE_INLINE
Definition func_attributes.h:15
#define sin(x)
Definition math_utils.h:43
#define cos(x)
Definition math_utils.h:44
#define __ac__max(a, b)
Definition math_utils.h:37
#define sqrt(x)
Definition math_utils.h:45
#define exp(x)
Definition math_utils.h:42
Definition host_datatypes.h:84
size3_t n0
Definition host_datatypes.h:85
size3_t m1
Definition host_datatypes.h:86
size3_t n1
Definition host_datatypes.h:85
size3_t reduction_tile
Definition host_datatypes.h:88
size3_t nn
Definition host_datatypes.h:87
size3_t m0
Definition host_datatypes.h:86