Proto  3.2
Proto_Forall.H
Go to the documentation of this file.
1 #pragma once
2 #ifndef _PROTO_FORALL_H_
3 #define _PROTO_FORALL_H_
4 
5 #include "Proto_MemType.H"
6 #include "Proto_Point.H"
7 #include "Proto_Box.H"
8 #include "Proto_BoxData.H"
9 
10 namespace Proto {
11 
12 /** @name Pointwise Operators
13 
14  The suite of forall functions facilitate writing functions that operate pointwise on BoxData.
15  To this end, the user must write a function with one of the following structures:
16  @code
17  PROTO_KERNEL_START
18  void F_temp(Var<T,C,MEMTYPE,D,E>&, Args...)
19  { ... }
20  PROTO_KERNEL_END(F_temp, F)
21  // OR
22  PROTO_KERNEL_START
23  void F_p_temp(Point&, Var<T,C,MEMTYPE,D,E>&, Args...)
24  { ... }
25  PROTO_KERNEL_END(F_p_temp, F_p)
26  @endcode
27  - PROTO_KERNEL_START and PROTO_KERNEL_END are required for cross-platform code.
28  - The "#_temp" symbols are temporaries; the actual function symbol is the one without "_temp"
29  - The template arguments of the first Var argument must match the output BoxData
30  - The Point argument in the second signature corresponds to the Point of function application
31  - Args... may include any number of Var& or read-only scalars (including Point or Box).
32  - The elements of Args... may have arbitrary tensor structure and const-ness
33  - non-const objects in Args... have input-output semantics
34  - The order and template arguments of the Vars in Args... must match the BoxData inputs of forall
35  - If F is a member function of a class F MUST BE DECLARED STATIC
36  - F or F_p may be an anonymous (lambda) function defined using the PROTO_LAMBDA macro
37 
38  Refer to the following code snippet for some sample valid forall input functions:
39  \snippet Snippets.cpp proto_forall_func
40 */
41 ///@{
42  /// Pointwise Operator
43  /**
44  Computes the function <code> a_F </code> at each Point of this BoxData.
45  This version of forall returns a new BoxData corresponding to the first argument of
46  <code> a_F </code> which must be a <code> Var </code>.
47  The domain of the created output is equal to the intersection of all other BoxData inputs
48  (the function will fail if there are no other inputs).
49  This function MUST specify the template parameters of the output BoxData.
50  See the example code snippet below.
51 
52  Example Usage:
53  Input Function:
54  \snippet Snippets.cpp proto_forall_constoprim
55  Calling forall:
56  \snippet Snippets.cpp proto_forall_1
57 
58  \param a_F Pointwise function
59  \param a_srcs Inputs (BoxData and primitive data)
60  \tparam T (Mandatory!) Data type of return BoxData
61  \tparam C (Optional) Size of first component axis of return BoxData. Defaults to 1
62  \tparam D (Optional) Size of second component axis of return BoxData. Defaults to 1
63  \tparam E (Optional) Size of third component axis of return BoxData. Defaults to 1
64 
65  */
66  template<typename T, unsigned int C=1, MemType MEMTYPE=MEMTYPE_DEFAULT,unsigned int D=1, unsigned int E=1,
67  typename Func, typename... Srcs>
68  inline BoxData<T,C,MEMTYPE,D,E> forall(const Func& a_F, Srcs&&... a_srcs);
69 
70  /// Pointwise Operator (Instrumented)
71  /**
72  Overload of the pointwise operator with additional instrumentation inputs
73 
74  \param a_num_flops_point Number of flops used to compute a_F at each Point
75  \param a_timername The name of a timer
76  \param a_F Pointwise function
77  \param a_srcs Inputs (BoxData and primitive data)
78  \tparam T (Mandatory!) Data type of return BoxData
79  \tparam C (Optional) Size of first component axis of return BoxData. Defaults to 1
80  \tparam D (Optional) Size of second component axis of return BoxData. Defaults to 1
81  \tparam E (Optional) Size of third component axis of return BoxData. Defaults to 1
82  */
83  template<typename T, unsigned int C=1, MemType MEMTYPE=MEMTYPE_DEFAULT, unsigned int D=1, unsigned int E=1,
84  typename Func, typename... Srcs>
85  inline BoxData<T,C,MEMTYPE,D,E> forallOp(
86  unsigned long long int a_num_flops_point,
87  const char* a_timername,
88  const Func& a_F, Srcs&&... a_srcs);
89 
90  /// Pointwise Operator (Explicit Range Box)
91  /**
92  Computes the function <code> a_F </code> at each Point of this BoxData.
93  This version of forall returns a new BoxData corresponding to the first argument of
94  <code> a_F </code> which must be a <code> Var </code>.
95  This function MUST specify the template parameters of the output BoxData.
96  See the example code snippet below.
97 
98  In general, this function should not be used unless absolutely necessary.
99  Some valid use cases are:
100  - Creating and initializing a BoxData without any BoxData inputs
101  - Evaluating a pointwise function on a Box that is a proper subset of the intersection
102  of all input BoxData
103  <code>a_box</code> must be a subset of the union of all input BoxData domains.
104 
105  Example Usage:
106  Input Function:
107  \snippet Snippets.cpp proto_forall_constoprim
108  Calling forall:
109  \snippet Snippets.cpp proto_forall_2
110 
111  \param a_F Pointwise function
112  \param a_box Range on which a_F will be evaluated
113  \param a_srcs Inputs (BoxData and primitive data)
114  \tparam T (Mandatory!) Data type of return BoxData
115  \tparam C (Optional) Size of first component axis of return BoxData. Defaults to 1
116  \tparam D (Optional) Size of second component axis of return BoxData. Defaults to 1
117  \tparam E (Optional) Size of third component axis of return BoxData. Defaults to 1
118  */
119  template<typename T, unsigned int C=1, MemType MEMTYPE=MEMTYPE_DEFAULT, unsigned int D=1, unsigned int E=1,
120  typename Func, typename... Srcs>
121  inline BoxData<T,C,MEMTYPE,D,E> forall(const Func& a_F, Box a_box, Srcs&&... a_srcs);
122 
123  /// Pointwise Operator (Explicit Range Box, Instrumented)
124  /**
125  Overload of the pointwise operator with additional instrumentation inputs
126 
127  \param a_num_flops_point Number of flops used to compute a_F at each Point
128  \param a_timername The name of a timer
129  \param a_F Pointwise function
130  \param a_box Range on which a_F will be evaluated
131  \param a_srcs Inputs (BoxData and primitive data)
132  \tparam T (Mandatory!) Data type of return BoxData
133  \tparam C (Optional) Size of first component axis of return BoxData. Defaults to 1
134  \tparam D (Optional) Size of second component axis of return BoxData. Defaults to 1
135  \tparam E (Optional) Size of third component axis of return BoxData. Defaults to 1
136  */
137  template<typename T, unsigned int C=1, MemType MEMTYPE=MEMTYPE_DEFAULT, unsigned int D=1, unsigned int E=1,
138  typename Func, typename... Srcs>
139  inline BoxData<T,C,MEMTYPE,D,E> forallOp(
140  unsigned long long int a_num_flops_point,
141  const char* a_timername,
142  const Func& a_F, Box a_box, Srcs&&... a_srcs);
143 
144  /// Pointwise Operator (Pointwise Dependence)
145  /**
146  Computes the function <code> a_F </code> at each Point of this BoxData.
147  This version of forall allows the input function to be dependent on the Point
148  at which it is applied. Hence, the first argument of a_F is a Point&, followed by
149  the Var corresponding to the output BoxData.
150  This function MUST specify the template parameters of the output BoxData.
151  See the example code snippet below.
152 
153  Example Usage:
154  Input Function:
155  \snippet Snippets.cpp proto_forall_pointwise
156  Calling forall:
157  \snippet Snippets.cpp proto_forall_3
158 
159  \param a_F Pointwise function
160  \param a_srcs Inputs (BoxData and primitive data)
161  \tparam T (Mandatory!) Data type of return BoxData
162  \tparam C (Optional) Size of first component axis of return BoxData. Defaults to 1
163  \tparam D (Optional) Size of second component axis of return BoxData. Defaults to 1
164  \tparam E (Optional) Size of third component axis of return BoxData. Defaults to 1
165  */
166  template<typename T, unsigned int C=1, MemType MEMTYPE=MEMTYPE_DEFAULT,unsigned int D=1, unsigned int E=1,
167  typename Func, typename... Srcs>
168  inline BoxData<T,C,MEMTYPE,D,E> forall_p(const Func& a_F, Srcs&&... a_srcs);
169 
170  /// Pointwise Operator (Pointwise Dependence, Instrumented)
171  /**
172  Overload of the pointwise operator with additional instrumentation inputs
173 
174  \param a_num_flops_point Number of flops used to compute a_F at each Point
175  \param a_timername The name of a timer
176  \param a_F Pointwise function
177  \param a_srcs Inputs (BoxData and primitive data)
178  \tparam T (Mandatory!) Data type of return BoxData
179  \tparam C (Optional) Size of first component axis of return BoxData. Defaults to 1
180  \tparam D (Optional) Size of second component axis of return BoxData. Defaults to 1
181  \tparam E (Optional) Size of third component axis of return BoxData. Defaults to 1
182  */
183  template<typename T, unsigned int C=1, MemType MEMTYPE=MEMTYPE_DEFAULT, unsigned int D=1, unsigned int E=1,
184  typename Func, typename... Srcs>
185  inline BoxData<T,C,MEMTYPE,D,E> forallOp_p(
186  unsigned long long int a_num_flops_point,
187  const char* a_timername,
188  const Func& a_F, Srcs&&... a_srcs);
189 
190  /// Pointwise Operator (Pointwise Dependence, Explicit Range Box)
191  /**
192  Computes the function <code> a_F </code> at each Point of this BoxData.
193  This version of forall allows the input function to be dependent on the
194  Point at which it is applied. Hence, the first argument of a_F is a Point&,
195  followed by the Var corresponding to the output BoxData.
196  This function MUST specify the template parameters of the output BoxData.
197  See the example code snippet below.
198 
199  In general, this function should not be used unless absolutely necessary.
200  <code>a_box</code> must be a subset of the union of all input BoxData domains.
201 
202  Example Usage:
203  Input Function:
204  \snippet Snippets.cpp proto_forall_pointwise
205  Calling forall:
206  \snippet Snippets.cpp proto_forall_4
207 
208  \param a_F Pointwise function
209  \param a_srcs Inputs (BoxData and primitive data)
210  \param a_box Range on which a_F will be evaluated
211  \tparam T (Mandatory!) Data type of return BoxData
212  \tparam C (Optional) Size of first component axis of return BoxData. Defaults to 1
213  \tparam D (Optional) Size of second component axis of return BoxData. Defaults to 1
214  \tparam E (Optional) Size of third component axis of return BoxData. Defaults to 1
215  */
216  template<typename T, unsigned int C=1, MemType MEMTYPE=MEMTYPE_DEFAULT, unsigned int D=1, unsigned int E=1,
217  typename Func, typename... Srcs>
218  inline BoxData<T,C,MEMTYPE,D,E> forall_p(const Func& a_F, Box a_box, Srcs&&... a_srcs);
219 
220  /// Pointwise Operator (Pointwise Dependence, Explicit Range Box, Instrumented)
221  /**
222  Overload of the pointwise operator with additional instrumentation inputs
223 
224  \param a_num_flops_point Number of flops used to compute a_F at each Point
225  \param a_timername The name of a timer
226  \param a_F Pointwise function
227  \param a_box Range on which a_F will be evaluated
228  \param a_srcs Inputs (BoxData and primitive data)
229  \tparam T (Mandatory!) Data type of return BoxData
230  \tparam C (Optional) Size of first component axis of return BoxData. Defaults to 1
231  \tparam D (Optional) Size of second component axis of return BoxData. Defaults to 1
232  \tparam E (Optional) Size of third component axis of return BoxData. Defaults to 1
233  */
234  template<typename T, unsigned int C=1, MemType MEMTYPE=MEMTYPE_DEFAULT, unsigned int D=1, unsigned int E=1,
235  typename Func, typename... Srcs>
236  inline BoxData<T,C,MEMTYPE,D,E> forallOp_p(
237  unsigned long long int a_num_flops_point,
238  const char* a_timername,
239  const Func& a_F, Box a_box, Srcs&&... a_srcs);
240 
241  /// In-Place Pointwise Operator
242  /**
243  Computes the function <code> a_F </code> at each Point of this BoxData.
244  The "InPlace" versions of forall execute on existing BoxData and do not produce a new array.
245  The range of the function evaluation is equal to the intersection of all BoxData inputs.
246 
247  Example Usage:
248  Input Function:
249  \snippet Snippets.cpp proto_forall_constoprim
250  Calling forall:
251  \snippet Snippets.cpp proto_forall_5
252 
253  \param a_F Pointwise function
254  \param a_srcs Inputs (BoxData and primitive data)
255  */
256  template<typename Func, typename... Srcs>
257  inline void forallInPlace(const Func& a_F, Srcs&&... a_srcs);
258 
259  /// In-Place Pointwise Operator (Instrumented)
260  /**
261  Overload of the pointwise operator with additional instrumentation inputs
262 
263  \param a_num_flops_point Number of flops used to compute a_F at each Point
264  \param a_timername The name of a timer
265  \param a_F Pointwise function
266  \param a_srcs Inputs (BoxData and primitive data)
267  */
268  template<typename Func, typename... Srcs>
269  inline void forallInPlaceOp(
270  unsigned long long int a_num_flops_point,
271  const char* a_timername,
272  const Func& a_F, Srcs&&... a_srcs);
273 
274  /// In-Place Pointwise Operator (Explicit Range Box)
275  /**
276  Computes the function <code> a_F </code> at each Point of this BoxData.
277  The "InPlace" versions of forall execute on existing BoxData and do not produce a new array.
278  <code> a_F </code> will be applied at all points of the input <code> a_box </code>.
279 
280  In general, this function should not be used unless you want to restrict the range of
281  a_F's application to be something smaller than the intersection of all the inputs.
282  <code>a_box</code> must be a subset of the union of all input BoxData domains.
283 
284  Example Usage:
285  Input Function:
286  \snippet Snippets.cpp proto_forall_constoprim
287  Calling forall:
288  \snippet Snippets.cpp proto_forall_6
289 
290  \param a_F Pointwise function
291  \param a_box Range of computation.
292  \param a_srcs Inputs (BoxData and primitive data)
293  */
294  template<typename Func, typename... Srcs>
295  inline void forallInPlace(const Func& a_F, Box a_box, Srcs&&... a_srcs);
296 
297  /// In-Place Pointwise Operator (Explicit Range Box, Instrumented)
298  /**
299  Overload of the pointwise operator with additional instrumentation inputs
300 
301  \param a_num_flops_point Number of flops used to compute a_F at each Point
302  \param a_timername The name of a timer
303  \param a_F Pointwise function
304  \param a_box Range of computation.
305  \param a_srcs Inputs (BoxData and primitive data)
306  */
307  template<typename Func, typename... Srcs>
308  inline void forallInPlaceOp(
309  unsigned long long int a_num_flops_point,
310  const char* a_timername,
311  const Func& a_F, Box a_box, Srcs&&... a_srcs);
312 
313  /// In-Place Pointwise Operator (Pointwise Dependence)
314  /**
315  Computes the function <code> a_F </code> at each Point of this BoxData.
316  This version of forall allows the input function to be dependent on the
317  Point at which it is applied. Hence, the first argument of <code> a_F </code>
318  is a <code> Point& </code>, followed by the normal <code> Var </code> inputs
319 
320  Example Usage:
321  Input Function:
322  \snippet Snippets.cpp proto_forall_pointwise
323  Calling forall:
324  \snippet Snippets.cpp proto_forall_7
325 
326  \param a_F Pointwise function
327  \param a_srcs Inputs (BoxData and primitive data)
328  */
329  template<typename Func, typename... Srcs>
330  inline void forallInPlace_p(const Func& a_F, Srcs&&... a_srcs);
331 
332  /// In-Place Pointwise Operator (Pointwise Dependence, Instrumented)
333  /**
334  Overload of the pointwise operator with additional instrumentation inputs
335 
336  \param a_num_flops_point Number of flops used to compute a_F at each Point
337  \param a_timername The name of a timer
338  \param a_F Pointwise function
339  \param a_srcs Inputs (BoxData and primitive data)
340  */
341  template<typename Func, typename... Srcs>
342  inline void forallInPlaceOp_p(
343  unsigned long long int a_num_flops_point,
344  const char* a_timername,
345  const Func& a_F, Srcs&&... a_srcs);
346 
347  /// In-Place Pointwise Operator (Pointwise Dependence, Explicit Box Range)
348  /**
349  Computes the function <code> a_F </code> at each Point of this BoxData.
350  This version of forall allows the input function to be dependent on the
351  Point at which it is applied. Hence, the first argument of <code> a_F </code>
352  is a <code> Point& </code>, followed by the normal <code> Var </code> inputs
353 
354  In general, this function should not be used unless you want to restrict the
355  domain of a_F's application to be something smaller than the intersection of all the inputs.
356  <code>a_box</code> must be a subset of the union of all input BoxData domains.
357 
358  Example Usage:
359  Input Function:
360  \snippet Snippets.cpp proto_forall_pointwise
361  Calling forall:
362  \snippet Snippets.cpp proto_forall_8
363 
364  \param a_F Pointwise function
365  \param a_srcs Inputs (BoxData and primitive data)
366  \param a_box Range of computation
367  */
368  template<typename Func, typename... Srcs>
369  inline void forallInPlace_p(const Func& a_F, Box a_box, Srcs&&... a_srcs);
370 
371  /// In-Place Pointwise Operator (Pointwise Dependence, Explicit Box Range, Instrumented)
372  /**
373  Overload of the pointwise operator with additional instrumentation inputs
374 
375  \param a_num_flops_point Number of flops used to compute a_F at each Point
376  \param a_timername The name of a timer
377  \param a_F Pointwise function
378  \param a_box Range of computation.
379  \param a_srcs Inputs (BoxData and primitive data)
380  */
381  template<typename Func, typename... Srcs>
382  inline void forallInPlaceOp_p(
383  unsigned long long int a_num_flops_point,
384  const char* a_timername,
385  const Func& a_F, Box a_box, Srcs&&... a_srcs);
386 
387  // End of BoxData Doxygen Module
388  /*@}*/
389 
390  //========================================================================
391  // Accelerator API ||
392  //==========++
393 #ifdef PROTO_ACCEL
394  template<typename Func, typename... Srcs>
395  inline void protoForall(const Func& a_F, Box a_box, Srcs&&... a_srcs);
396 
397  template<typename Func, typename... Srcs>
398  inline void protoForallStream(
399  protoStream_t& a_stream,
400  const Func& a_F, Box a_box, Srcs&&... a_srcs);
401 
402  template<typename Func, typename... Srcs>
403  inline void protoForall_p(const Func& a_F, Box a_box, Srcs&&... a_srcs);
404 #endif
405 } // end namespace Proto
406 #endif // end include guard
MemType
Definition: Proto_MemType.H:7
BoxData< T, C, MEMTYPE, D, E > forall_p(const Func &a_F, Srcs &&... a_srcs)
Pointwise Operator (Pointwise Dependence)
void forallInPlace(const Func &a_F, Srcs &&... a_srcs)
In-Place Pointwise Operator.
void forallInPlace_p(const Func &a_F, Srcs &&... a_srcs)
In-Place Pointwise Operator (Pointwise Dependence)
BoxData< T, C, MEMTYPE, D, E > forallOp(unsigned long long int a_num_flops_point, const char *a_timername, const Func &a_F, Srcs &&... a_srcs)
Pointwise Operator (Instrumented)
BoxData< T, C, MEMTYPE, D, E > forall(const Func &a_F, Srcs &&... a_srcs)
Pointwise Operator.
Definition: Proto_Array.H:17
#define MEMTYPE_DEFAULT
Definition: Proto_MemType.H:24
#define protoStream_t
Definition: Proto_Macros.H:18