SST/macro
lib_compute_loops.h
Go to the documentation of this file.
1 /*
2  * This file is part of SST/macroscale:
3  * The macroscale architecture simulator from the SST suite.
4  * Copyright (c) 2009 Sandia Corporation.
5  * This software is distributed under the BSD License.
6  * Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
7  * the U.S. Government retains certain rights in this software.
8  * For more information, see the LICENSE file in the top
9  * SST/macroscale directory.
10  */
11 
12 #ifndef SSTMAC_SOFTWARE_LIBRARIES_COMPUTE_LIB_COMPUTE_LOOPS_H_INCLUDED
13 #define SSTMAC_SOFTWARE_LIBRARIES_COMPUTE_LIB_COMPUTE_LOOPS_H_INCLUDED
14 
17 
18 namespace sstmac {
19 namespace sw {
20 
22  public lib_compute_memmove
23 {
24  // ------- constructor / boost stuff -------------//
25 
26  public:
27 
28  public:
29  virtual
31 
33 
34  template<typename Type>
35  void
36  compute_array_init(long arraysize) {
37  doing_memory_ = true;
38  lib_compute_memmove::read(arraysize * sizeof(Type));
39  doing_memory_ = false;
40  }
41 
42  /**
43  * compute_loop - compute and schedule a for loop's costs as
44  * moving Nm bytes and doing Nf flops, where
45  * Nm = loop_trips*numlines*mem_line_ratio*mem_op_size
46  * Nf = loop_trips*numlines*flop_line_ratio
47  * where mem_line_ratio and flop_line_ratio may appear as
48  * global simulation parameters or will default (0.8, 0.8) and
49  * mem_op_size is currently fixed internally at 16.
50  * loop_trips = Product-N(toI-fromI+1 over all N range pairs I in the argument list)
51  * Given pipeline, vectorization, and other execution features,
52  * numlines is essentially a fudge factor that must be determined
53  * by experimental comparison; reasonable initial guesses for the numlines are
54  * (a) the number of executable statements in the loop
55  * (b) the number of values read from or written to main data memory at the
56  * innermost loop level.
57  * For all versions of this function, loop_trips is product of the
58  * (to-from+1) differences in the argument list.
59  * @param from loop counter range begin
60  * @param to loop counter range end (assuming step size 1)
61  * @param numlines number of lines equivalent of code (>0) tuning parameter
62  */
63  template<typename T>
64  void
65  compute_loop(long long from1, long long to1, T numlines) {
66  if (do_loops_) {
67  long long loop = to1 - from1 + 1; //+1 for fortran loops
68 
69  compute_loop_work(loop, (double) numlines);
70  }
71  }
72 
73  /**
74  * compute_loop2 - compute for one loop nested in an outer one
75  * @param from1
76  * @param to1
77  * @param from2
78  * @param to2
79  * @param numlines
80  */
81  template<typename T>
82  void
83  compute_loop2(long long from1, long long to1, long long from2,
84  long long to2, T numlines) {
85  if (do_loops_) {
86  long long loop1 = to1 - from1 + 1; //+1 for fortran loops
87  long long loop2 = to2 - from2 + 1;
88  long long loop = loop1 * loop2;
89 
90  compute_loop_work(loop, (double) numlines);
91  }
92  }
93 
94  /**
95  * compute_loop3 - compute for one loop nested in loop nested in an outer one
96  * @param from1
97  * @param to1
98  * @param from2
99  * @param to2
100  * @param from3
101  * @param to3
102  * @param numlines
103  */
104  template<typename T>
105  void
106  compute_loop3(long long from1, long long to1, long long from2,
107  long long to2, long long from3, long long to3, T numlines) {
108  if (do_loops_) {
109  long long loop1 = to1 - from1 + 1; //+1 for fortran loops
110  long long loop2 = to2 - from2 + 1;
111  long long loop3 = to3 - from3 + 1;
112  long long loop = loop1 * loop2 * loop3;
113 
114  compute_loop_work(loop, (double) numlines);
115  }
116  }
117 
118  /**
119  * compute_loop4 - compute for quadruple nested loop
120 
121  * @param numlines
122  */
123  template<typename T>
124  void
125  compute_loop4(long long from1, long long to1, long long from2,
126  long long to2, long long from3, long long to3, long long from4,
127  long long to4, T numlines) {
128  if (do_loops_) {
129  long long loop1 = to1 - from1 + 1; //+1 for fortran loops
130  long long loop2 = to2 - from2 + 1;
131  long long loop3 = to3 - from3 + 1;
132  long long loop4 = to4 - from4 + 1;
133  long long loop = loop1 * loop2 * loop3 * loop4;
134  ;
135 
136  compute_loop_work(loop, (double) numlines);
137  }
138  }
139 
140  /**
141  * compute_loop5 - compute for 5-nested loop
142  * @param from1 see compute_loop for parameters explanation.
143  * @param to1
144  * @param from2
145  * @param to2
146  * @param from3
147  * @param to3
148  * @param from4
149  * @param to4
150  * @param from5
151  * @param to5
152  * @param numlines
153  */
154  template<typename T>
155  void
156  compute_loop5(long long from1, long long to1, long long from2,
157  long long to2, long long from3, long long to3, long long from4,
158  long long to4, long long from5, long long to5, T numlines) {
159  if (do_loops_) {
160  long long loop1 = to1 - from1 + 1; //+1 for fortran loops
161  long long loop2 = to2 - from2 + 1;
162  long long loop3 = to3 - from3 + 1;
163  long long loop4 = to4 - from4 + 1;
164  long long loop5 = to5 - from5 + 1;
165  long long loop = loop1 * loop2 * loop3 * loop4 * loop5;
166 
167  compute_loop_work(loop, (double) numlines);
168  }
169  }
170 
171  /**
172  * compute_loop6 - compute for 6-nested loop
173  * @param from1 see compute_loop for parameters explanation.
174  * @param to1
175  * @param from2
176  * @param to2
177  * @param from3
178  * @param to3
179  * @param from4
180  * @param to4
181  * @param from5
182  * @param to5
183  * @param from6
184  * @param to6
185  * @param numlines
186  */
187  template<typename T>
188  void
189  compute_loop6(long long from1, long long to1, long long from2,
190  long long to2, long long from3, long long to3, long long from4,
191  long long to4, long long from5, long long to5, long long from6,
192  long long to6, T numlines) {
193  if (do_loops_) {
194  long long loop1 = to1 - from1 + 1; //+1 for fortran loops
195  long long loop2 = to2 - from2 + 1;
196  long long loop3 = to3 - from3 + 1;
197  long long loop4 = to4 - from4 + 1;
198  long long loop5 = to5 - from5 + 1;
199  long long loop6 = to6 - from6 + 1;
200  long loop = loop1 * loop2 * loop3 * loop4 * loop5 * loop6;
201 
202  compute_loop_work(loop, (double) numlines);
203  }
204  }
205 
206  /**
207  * compute_loop6 - compute for 6-nested loop
208  * @param from1 see compute_loop for parameters explanation.
209  * @param to1
210  * @param from2
211  * @param to2
212  * @param from3
213  * @param to3
214  * @param from4
215  * @param to4
216  * @param from5
217  * @param to5
218  * @param from6
219  * @param to6
220  * @param from7
221  * @param to7
222  * @param numlines
223  */
224  template<typename T>
225  void
226  compute_loop7(long long from1, long long to1, long long from2,
227  long long to2, long long from3, long long to3, long long from4,
228  long long to4, long long from5, long long to5, long long from6,
229  long long to6, long long from7, long long to7, T numlines) {
230  if (do_loops_) {
231  long long loop1 = to1 - from1 + 1; //+1 for fortran loops
232  long long loop2 = to2 - from2 + 1;
233  long long loop3 = to3 - from3 + 1;
234  long long loop4 = to4 - from4 + 1;
235  long long loop5 = to5 - from5 + 1;
236  long long loop6 = to6 - from6 + 1;
237  long long loop7 = to7 - from7 + 1;
238  long long loop = loop1 * loop2 * loop3 * loop4 * loop5 * loop6
239  * loop7;
240 
241  compute_loop_work(loop, (double) numlines);
242  }
243  }
244 
245  void
246  compute_fft();
247 
248  static int mem_op_size_;
249  static double mem_line_ratio_;
250  static double flop_line_ratio_;
251  static bool do_loops_;
252 
253  protected:
254  void consume_params(sprockit::sim_parameters *params);
255 
256  void
257  compute_loop_work(long long loop, double numlines);
258 
259  protected:
261 
262 };
263 
264 } //end of namespace sstmac
265 }
266 
267 #endif
268 
void compute_loop4(long long from1, long long to1, long long from2, long long to2, long long from3, long long to3, long long from4, long long to4, T numlines)
compute_loop4 - compute for quadruple nested loop
void compute_array_init(long arraysize)
void compute_loop2(long long from1, long long to1, long long from2, long long to2, T numlines)
compute_loop2 - compute for one loop nested in an outer one
lib_compute_loops(software_id id)
void compute_loop5(long long from1, long long to1, long long from2, long long to2, long long from3, long long to3, long long from4, long long to4, long long from5, long long to5, T numlines)
compute_loop5 - compute for 5-nested loop
void compute_loop_work(long long loop, double numlines)
void compute_loop(long long from1, long long to1, T numlines)
compute_loop - compute and schedule a for loop&#39;s costs as moving Nm bytes and doing Nf flops...
SUMI = Simulator unified messagine interface It is also the name for a solid ink in Japanese - i...
void compute_loop3(long long from1, long long to1, long long from2, long long to2, long long from3, long long to3, T numlines)
compute_loop3 - compute for one loop nested in loop nested in an outer one
void consume_params(sprockit::sim_parameters *params)
void compute_loop7(long long from1, long long to1, long long from2, long long to2, long long from3, long long to3, long long from4, long long to4, long long from5, long long to5, long long from6, long long to6, long long from7, long long to7, T numlines)
compute_loop6 - compute for 6-nested loop
void compute_loop6(long long from1, long long to1, long long from2, long long to2, long long from3, long long to3, long long from4, long long to4, long long from5, long long to5, long long from6, long long to6, T numlines)
compute_loop6 - compute for 6-nested loop
A wrapper for an appid, taskid pair.
Definition: software_id.h:28