ISAAC
Overview :: Library Doc :: Server Doc :: JSON Commands

In Situ Animation of Accelerated Computations

isaac_types.hpp
Go to the documentation of this file.
1 /* This file is part of ISAAC.
2  *
3  * ISAAC is free software: you can redistribute it and/or modify
4  * it under the terms of the GNU Lesser General Public License as
5  * published by the Free Software Foundation, either version 3 of the
6  * License, or (at your option) any later version.
7  *
8  * ISAAC is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with ISAAC. If not, see <www.gnu.org/licenses/>. */
15 
16 #pragma once
17 
18 #include <boost/preprocessor.hpp>
19 
20 #include "isaac_defines.hpp"
21 
22 namespace isaac
23 {
24 
25 typedef float isaac_float;
26 typedef int32_t isaac_int;
27 typedef uint32_t isaac_uint;
28 
29 #define ISAAC_COMPONENTS_SEQ_3 (x)(y)(z)(w)
30 #define ISAAC_COMPONENTS_SEQ_2 (x)(y)(z)
31 #define ISAAC_COMPONENTS_SEQ_1 (x)(y)
32 #define ISAAC_COMPONENTS_SEQ_0 (x)
33 
34 #ifndef __CUDACC__
35  //isaac_float4, isaac_float3, isaac_float2
36  #define ISAAC_FLOAT_DEF(Z, I, unused) \
37  struct BOOST_PP_CAT(isaac_float, BOOST_PP_INC(I) ) \
38  { \
39  isaac_float BOOST_PP_SEQ_ENUM( BOOST_PP_CAT( ISAAC_COMPONENTS_SEQ_ , I ) ); \
40  };
41  BOOST_PP_REPEAT(4, ISAAC_FLOAT_DEF, ~)
42  #undef ISAAC_FLOAT_DEF
43  //isaac_uint4, isaac_uint3, isaac_uint2
44  #define ISAAC_UINT_DEF(Z, I, unused) \
45  struct BOOST_PP_CAT(isaac_uint, BOOST_PP_INC(I) ) \
46  { \
47  isaac_uint BOOST_PP_SEQ_ENUM( BOOST_PP_CAT( ISAAC_COMPONENTS_SEQ_ , I ) ); \
48  };
49  BOOST_PP_REPEAT(4, ISAAC_UINT_DEF, ~)
50  #undef ISAAC_UINT_DEF
51  //isaac_int4, isaac_int3, isaac_int2
52  #define ISAAC_INT_DEF(Z, I, unused) \
53  struct BOOST_PP_CAT(isaac_int, BOOST_PP_INC(I) ) \
54  { \
55  isaac_int BOOST_PP_SEQ_ENUM( BOOST_PP_CAT( ISAAC_COMPONENTS_SEQ_ , I ) ); \
56  };
57  BOOST_PP_REPEAT(4, ISAAC_INT_DEF, ~)
58  #undef ISAAC_INT_DEF
59 #else
60  //same as above, but we use the builtin cuda variables
61  #define ISAAC_CUDA_DEF(Z, I, unused) \
62  typedef BOOST_PP_CAT(float, BOOST_PP_INC(I) ) BOOST_PP_CAT(isaac_float, BOOST_PP_INC(I) ); \
63  typedef BOOST_PP_CAT(uint, BOOST_PP_INC(I) ) BOOST_PP_CAT(isaac_uint, BOOST_PP_INC(I) ); \
64  typedef BOOST_PP_CAT(int, BOOST_PP_INC(I) ) BOOST_PP_CAT(isaac_int, BOOST_PP_INC(I) );
65  BOOST_PP_REPEAT(4, ISAAC_CUDA_DEF, ~)
66  #undef ISAAC_CUDA_DEF
67 #endif
68 
69 //isaac_size4, isaac_size3, isaac_size2, isaac_size1
70 #define ISAAC_SIZE_DEF(Z, I, unused) \
71  struct BOOST_PP_CAT(isaac_size, BOOST_PP_INC(I) ) \
72  { \
73  size_t BOOST_PP_SEQ_ENUM( BOOST_PP_CAT( ISAAC_COMPONENTS_SEQ_ , I ) ); \
74  };
75 BOOST_PP_REPEAT(4, ISAAC_SIZE_DEF, ~)
76 #undef ISAAC_SIZE_DEF
77 
78 //Overloading *, /, + and - for isaac_{type}[2,3,4]:
79 //macro for result.<I> = left.<I> <OP[1]> right.<I>, with I € {x,y,z,w}
80 #define ISAAC_OVERLOAD_OPERATOR_SUBDEF(Z, I, OP ) \
81  result. BOOST_PP_ARRAY_ELEM( I, BOOST_PP_SEQ_TO_ARRAY( ISAAC_COMPONENTS_SEQ_3 ) ) = \
82  left. BOOST_PP_ARRAY_ELEM( I, BOOST_PP_SEQ_TO_ARRAY( ISAAC_COMPONENTS_SEQ_3 ) ) BOOST_PP_ARRAY_ELEM( 1, OP ) \
83  right. BOOST_PP_ARRAY_ELEM( I, BOOST_PP_SEQ_TO_ARRAY( ISAAC_COMPONENTS_SEQ_3 ) );
84 
85 #define ISAAC_OVERLOAD_OPERATOR_SUBDEF_ROTHER(Z, I, OP ) \
86  result. BOOST_PP_ARRAY_ELEM( I, BOOST_PP_SEQ_TO_ARRAY( ISAAC_COMPONENTS_SEQ_3 ) ) = \
87  left. BOOST_PP_ARRAY_ELEM( I, BOOST_PP_SEQ_TO_ARRAY( ISAAC_COMPONENTS_SEQ_3 ) ) BOOST_PP_ARRAY_ELEM( 1, OP ) \
88  right;
89 
90 #define ISAAC_OVERLOAD_OPERATOR_SUBDEF_LOTHER(Z, I, OP ) \
91  result. BOOST_PP_ARRAY_ELEM( I, BOOST_PP_SEQ_TO_ARRAY( ISAAC_COMPONENTS_SEQ_3 ) ) = \
92  left BOOST_PP_ARRAY_ELEM( 1, OP ) \
93  right. BOOST_PP_ARRAY_ELEM( I, BOOST_PP_SEQ_TO_ARRAY( ISAAC_COMPONENTS_SEQ_3 ) );
94 
95 #define ISAAC_OVERLOAD_OPERATOR_SUBDEF_UNARY(Z, I, OP ) \
96  result. BOOST_PP_ARRAY_ELEM( I, BOOST_PP_SEQ_TO_ARRAY( ISAAC_COMPONENTS_SEQ_3 ) ) = BOOST_PP_ARRAY_ELEM( 1, OP ) \
97  left. BOOST_PP_ARRAY_ELEM( I, BOOST_PP_SEQ_TO_ARRAY( ISAAC_COMPONENTS_SEQ_3 ) );
98 
99 //macro for the any operator for isaac_{type}[2,3,4].
100 #define ISAAC_OVERLOAD_OPERATOR_DEF(Z, I, OP) \
101  ISAAC_HOST_DEVICE_INLINE BOOST_PP_CAT( BOOST_PP_CAT( isaac_ , BOOST_PP_ARRAY_ELEM( 0, OP ) ), BOOST_PP_INC(I) ) operator BOOST_PP_ARRAY_ELEM( 1, OP ) ( \
102  const BOOST_PP_CAT( BOOST_PP_CAT( isaac_ , BOOST_PP_ARRAY_ELEM( 0, OP ) ), BOOST_PP_INC(I) ) & left, \
103  const BOOST_PP_CAT( BOOST_PP_CAT( isaac_ , BOOST_PP_ARRAY_ELEM( 0, OP ) ), BOOST_PP_INC(I) ) & right) \
104  { \
105  BOOST_PP_CAT( BOOST_PP_CAT( isaac_ , BOOST_PP_ARRAY_ELEM( 0, OP ) ), BOOST_PP_INC(I) ) result; \
106  BOOST_PP_REPEAT( BOOST_PP_INC(I), ISAAC_OVERLOAD_OPERATOR_SUBDEF, OP ) \
107  return result; \
108  } \
109  ISAAC_HOST_DEVICE_INLINE BOOST_PP_CAT( BOOST_PP_CAT( isaac_ , BOOST_PP_ARRAY_ELEM( 0, OP ) ), BOOST_PP_INC(I) ) operator BOOST_PP_ARRAY_ELEM( 1, OP ) ( \
110  const BOOST_PP_CAT( BOOST_PP_CAT( isaac_ , BOOST_PP_ARRAY_ELEM( 0, OP ) ), BOOST_PP_INC(I) ) & left, \
111  const isaac_float & right) \
112  { \
113  BOOST_PP_CAT( BOOST_PP_CAT( isaac_ , BOOST_PP_ARRAY_ELEM( 0, OP ) ), BOOST_PP_INC(I) ) result; \
114  BOOST_PP_REPEAT( BOOST_PP_INC(I), ISAAC_OVERLOAD_OPERATOR_SUBDEF_ROTHER, OP ) \
115  return result; \
116  } \
117  ISAAC_HOST_DEVICE_INLINE BOOST_PP_CAT( BOOST_PP_CAT( isaac_ , BOOST_PP_ARRAY_ELEM( 0, OP ) ), BOOST_PP_INC(I) ) operator BOOST_PP_ARRAY_ELEM( 1, OP ) ( \
118  const isaac_float & left, \
119  const BOOST_PP_CAT( BOOST_PP_CAT( isaac_ , BOOST_PP_ARRAY_ELEM( 0, OP ) ), BOOST_PP_INC(I) ) & right ) \
120  { \
121  BOOST_PP_CAT( BOOST_PP_CAT( isaac_ , BOOST_PP_ARRAY_ELEM( 0, OP ) ), BOOST_PP_INC(I) ) result; \
122  BOOST_PP_REPEAT( BOOST_PP_INC(I), ISAAC_OVERLOAD_OPERATOR_SUBDEF_LOTHER, OP ) \
123  return result; \
124  }
125 
126 #define ISAAC_OVERLOAD_OPERATOR_DEF_UNARY(Z, I, OP) \
127  ISAAC_HOST_DEVICE_INLINE BOOST_PP_CAT( BOOST_PP_CAT( isaac_ , BOOST_PP_ARRAY_ELEM( 0, OP ) ), BOOST_PP_INC(I) ) operator BOOST_PP_ARRAY_ELEM( 1, OP ) ( \
128  const BOOST_PP_CAT( BOOST_PP_CAT( isaac_ , BOOST_PP_ARRAY_ELEM( 0, OP ) ), BOOST_PP_INC(I) ) & left ) \
129  { \
130  BOOST_PP_CAT( BOOST_PP_CAT( isaac_ , BOOST_PP_ARRAY_ELEM( 0, OP ) ), BOOST_PP_INC(I) ) result; \
131  BOOST_PP_REPEAT( BOOST_PP_INC(I), ISAAC_OVERLOAD_OPERATOR_SUBDEF_UNARY, OP ) \
132  return result; \
133  }
134 
135 #define ISAAC_OVERLOAD_OPERATOR_COUNT 4
136 #define ISAAC_OVERLOAD_OPERATORS (ISAAC_OVERLOAD_OPERATOR_COUNT, (+, -, *, / ) )
137 
138 #define ISAAC_OVERLOAD_ITERATOR(Z, I, TYPE) \
139  BOOST_PP_REPEAT( 4, ISAAC_OVERLOAD_OPERATOR_DEF, (2, (TYPE, BOOST_PP_ARRAY_ELEM( I, ISAAC_OVERLOAD_OPERATORS ) ) ) ) \
140 
141 #define ISAAC_OVERLOAD_OPERATOR_CREATE( TYPE ) \
142  BOOST_PP_REPEAT( ISAAC_OVERLOAD_OPERATOR_COUNT, ISAAC_OVERLOAD_ITERATOR, TYPE ) \
143  BOOST_PP_REPEAT( 4, ISAAC_OVERLOAD_OPERATOR_DEF_UNARY, (2, (TYPE, - ) ) )
144 
149 
150 #undef ISAAC_OVERLOAD_OPERATOR_SUBDEF_LOTHER
151 #undef ISAAC_OVERLOAD_OPERATOR_SUBDEF_ROTHER
152 #undef ISAAC_OVERLOAD_OPERATOR_COUNT
153 #undef ISAAC_OVERLOAD_OPERATORS
154 #undef ISAAC_OVERLOAD_ITERATOR
155 #undef ISAAC_OVERLOAD_OPERATOR_SUBDEF
156 #undef ISAAC_OVERLOAD_OPERATOR_SUBDEF_UNARY
157 #undef ISAAC_OVERLOAD_OPERATOR_DEF
158 #undef ISAAC_OVERLOAD_OPERATOR_DEF_UNARY
159 #undef ISAAC_OVERLOAD_OPERATOR_CREATE
160 
161 #define ISAAC_DIM_TYPES ( 4, ( size, float, int, uint ) )
162 #define ISAAC_DIM_TYPES_DIM ( 4, ( size_dim, float_dim, int_dim, uint_dim ) )
163 
164 #define ISAAC_DIM_SUBDEF(Z, J, I ) \
165  template <> \
166  struct BOOST_PP_CAT( isaac_, BOOST_PP_ARRAY_ELEM( I, ISAAC_DIM_TYPES_DIM ) ) \
167  < size_t( BOOST_PP_INC(J) ) > { \
168  BOOST_PP_CAT( isaac_, BOOST_PP_CAT( BOOST_PP_ARRAY_ELEM( I, ISAAC_DIM_TYPES ) , BOOST_PP_INC(J) ) ) value; };
169 
170 #define ISAAC_DIM_DEF(Z, I, unused) \
171  template < size_t > \
172  struct BOOST_PP_CAT( isaac_ , BOOST_PP_ARRAY_ELEM( I, ISAAC_DIM_TYPES_DIM ) ); \
173  BOOST_PP_REPEAT( 4, ISAAC_DIM_SUBDEF, I )
174 
175 BOOST_PP_REPEAT( 4, ISAAC_DIM_DEF, ~ )
176 
177 #undef ISAAC_DIM_SUBDEF
178 #undef ISAAC_DIM_DEF
179 #undef ISAAC_DIM_TYPES
180 #undef ISAAC_DIM_TYPES_DIM
181 
182 template < size_t simdim >
184 {
185  isaac_size_dim < simdim > global_size;
187  isaac_size_dim < simdim > position;
188  isaac_size_dim < simdim > local_size;
189  isaac_size_dim < simdim > global_size_scaled;
191  isaac_size_dim < simdim > position_scaled;
192  isaac_size_dim < simdim > local_size_scaled;
193 };
194 
195 
196 template< int N >
198 {
199  isaac_float4* pointer[ N ];
200 };
201 
202 template< int N >
204 {
205  isaac_float4* pointer[ N ];
206  std::map< isaac_uint, isaac_float4 > description[ N ];
207 };
208 
210 {
211  std::string source;
212  isaac_int bytecode[ISAAC_MAX_FUNCTORS];
213  isaac_int error_code;
214 };
215 
216 template< int N >
218 {
219  isaac_float value[ N ];
220 };
221 
222 template< int N >
224 {
225  void* pointer[ N ];
226 };
227 
229 {
230  isaac_float min;
231  isaac_float max;
232 };
233 
234 template< int N>
236 {
237  isaac_float min[ N ];
238  isaac_float max[ N ];
239 };
240 
242 {
244  count(0)
245  {}
246  isaac_uint count;
247  struct
248  {
249  isaac_float3 position;
250  isaac_float3 normal;
251  } elem[ ISAAC_MAX_CLIPPING ];
252 };
253 
254 
255 
256 typedef enum
257 {
261 
262 } //namespace isaac;
float isaac_float
Definition: isaac_types.hpp:25
isaac_size_dim< simdim > local_size
IsaacVisualizationMetaEnum
ISAAC_HOST_DEVICE_INLINE clipping_struct()
Definition: isaac.hpp:60
#define ISAAC_UINT_DEF(Z, I, unused)
Definition: isaac_types.hpp:44
isaac_size_dim< simdim > position_scaled
#define ISAAC_INT_DEF(Z, I, unused)
Definition: isaac_types.hpp:52
isaac_size_dim< simdim > local_size_scaled
isaac_size_dim< simdim > global_size_scaled
#define ISAAC_SIZE_DEF(Z, I, unused)
Definition: isaac_types.hpp:70
int32_t isaac_int
Definition: isaac_types.hpp:26
uint32_t isaac_uint
Definition: isaac_types.hpp:27
#define ISAAC_MAX_FUNCTORS
#define ISAAC_OVERLOAD_OPERATOR_CREATE(TYPE)
#define ISAAC_HOST_DEVICE_INLINE
#define ISAAC_FLOAT_DEF(Z, I, unused)
Definition: isaac_types.hpp:36
#define ISAAC_DIM_DEF(Z, I, unused)
#define ISAAC_MAX_CLIPPING
isaac_size_dim< simdim > global_size
isaac_size_dim< simdim > position