Astaroth  3.1
Scalable Multi-GPU Stencil Computations
Loading...
Searching...
No Matches
math_utils_base.h
Go to the documentation of this file.
1#pragma once
2
3#include "func_attributes.h"
4
5#ifdef __cplusplus
6
7template <class T>
8static HOST_DEVICE_INLINE const T
9min(const T& a, const T& b)
10{
11 return a < b ? a : b;
12}
13
14template <class T>
15static HOST_DEVICE_INLINE const T
16max(const T& a, const T& b)
17{
18 return a > b ? a : b;
19}
20
21static inline size_t
22max(const Volume& a)
23{
24 const size_t tmp= a.x > a.y ? a.x : a.y;
25 return tmp > a.z ? tmp: a.z;
26}
27
28static inline const Volume
29max(const Volume& a, const Volume& b)
30{
31 return (Volume){max(a.x, b.x), max(a.y, b.y), max(a.z, b.z)};
32}
33
34static inline const Volume
35min(const Volume& a, const Volume& b)
36{
37 return (Volume){min(a.x, b.x), min(a.y, b.y), min(a.z, b.z)};
38}
39
40/*
41 * lume
42 */
43template <class T>
44static Volume
45TO_VOLUME(const T a, const char* file, const int line)
46{
50 return (Volume){as_size_t(a.x), as_size_t(a.y), as_size_t(a.z)};
51}
52static Volume UNUSED
53TO_VOLUME(const dim3 a, const char* , const int)
54{
55 return (Volume){a.x, a.y, a.z};
56}
57
58static Volume UNUSED
59TO_VOLUME(const size3_t a, const char* , const int)
60{
61 return (Volume){a.x, a.y, a.z};
62}
63template <typename T>
64static HOST_DEVICE_INLINE Volume
65operator*(const Volume& a, const T& b)
66{
67 return (Volume){a.x / b, a.y / b, a.z / b};
68}
69
70#define to_volume(a) TO_VOLUME(a, __FILE__, __LINE__)
71
72static inline dim3
73to_dim3(const Volume v)
74{
75 return (dim3)
76 {
77 (unsigned int)v.x,
78 (unsigned int)v.y,
79 (unsigned int)v.z
80 };
81}
82
83static HOST_INLINE Volume
84operator-(const Volume& a, const Volume& b)
85{
86 int3 res =
87 {
88 (int)a.x - (int)b.x,
89 (int)a.y - (int)b.y,
90 (int)a.z - (int)b.z
91 };
92
93 return to_volume(res);
94}
95static HOST_INLINE Volume
96operator*(const Volume& a, const int& b)
97{
98 ERRCHK_ALWAYS(b >= 0);
99 return
100 {
101 a.x*(size_t)b,
102 a.y*(size_t)b,
103 a.z*(size_t)b
104 };
105
106}
107
108static HOST_INLINE Volume
109operator*(const int& a, const Volume& b)
110{
111 ERRCHK_ALWAYS(a >= 0);
112 return
113 {
114 b.x*(size_t)a,
115 b.y*(size_t)a,
116 b.z*(size_t)a
117 };
118
119}
120
121#endif /* __cplusplus */
#define as_size_t(i)
Definition errchk.h:101
#define ERRCHK_ALWAYS(retval)
Definition errchk.h:95
#define INDIRECT_ERRCHK_ALWAYS(retval, file, line)
Definition errchk.h:224
#define HOST_INLINE
Definition func_attributes.h:16
#define HOST_DEVICE_INLINE
Definition func_attributes.h:15
#define UNUSED
Definition func_attributes.h:4
Volume size3_t
Definition host_datatypes.h:76
static int FILE * file
Definition string_vec.h:120
char line[10000]
Definition string_vec.h:122