SkePU(integratedwithStarPU)  0.8.1
 All Classes Namespaces Files Functions Enumerations Friends Macros Groups Pages
exec_plan.h
Go to the documentation of this file.
1 
5 #ifndef EXEC_PLAN_H
6 #define EXEC_PLAN_H
7 
8 #include <map>
9 
10 
11 
12 namespace skepu
13 {
14 
15 enum BackEnd
16 {
17  CPU_BACKEND,
18  OMP_BACKEND,
19  CU_BACKEND,
20  CUM_BACKEND,
21  CL_BACKEND,
22  CLM_BACKEND
23 };
24 
25 
26 struct BackEndParams
27 {
28 
29  // this default constructor is the key hereā€¦.
30  BackEndParams() : backend(CPU_BACKEND) /* does not use it so it does not matter... */
31  {
32  #ifdef SKEPU_MAX_GPU_THREADS
33  maxThreads = SKEPU_MAX_GPU_THREADS;
34  #else
35  maxThreads = 64;
36  #endif
37 
38  #ifdef SKEPU_MAX_GPU_BLOCKS
39  maxBlocks = SKEPU_MAX_GPU_BLOCKS;
40  #else
41  maxBlocks = 65535;
42  #endif
43 
44  #ifdef SKEPU_OMP_MAX_THREADS
45  numOmpThreads = SKEPU_OMP_MAX_THREADS;
46  #else
47  numOmpThreads = 2;
48  #endif
49  }
50  BackEnd backend;
51  int maxThreads;
52  int maxBlocks;
53  int numOmpThreads;
54 };
55 
56 
75 class ExecPlan
76 {
77 public:
78 
79  void add(int lowBound, int highBound, BackEnd backend, unsigned gs, unsigned bs)
80  {
81  BackEndParams bp;
82  bp.backend=backend;
83  bp.maxThreads=bs;
84  bp.maxBlocks = gs;
85  sizePlan.insert(std::make_pair(std::make_pair(lowBound, highBound),bp));
86  }
87 
88  void add(int lowBound, int highBound, BackEnd backend, unsigned numOmpThreads)
89  {
90  BackEndParams bp;
91  bp.backend=backend;
92  bp.numOmpThreads = numOmpThreads;
93  sizePlan.insert(std::make_pair(std::make_pair(lowBound, highBound),bp));
94  }
95 
96  void add(int lowBound, int highBound, BackEndParams params)
97  {
98  sizePlan.insert(std::make_pair(std::make_pair(lowBound, highBound),params));
99  }
100 
101  void add(int lowBound, int highBound, BackEnd backend)
102  {
103  BackEndParams bp;
104  bp.backend=backend;
105  sizePlan.insert(std::make_pair(std::make_pair(lowBound, highBound),bp));
106  }
107 
108  void setMaxThreads(int size, int maxthreads)
109  {
110  std::map< std::pair<int, int>, BackEndParams >::iterator it;
111  for(it = sizePlan.begin(); it != sizePlan.end(); ++it)
112  {
113  if(size >= it->first.first && size <= it->first.second)
114  {
115  it->second.maxThreads=maxthreads;
116  return;
117  }
118  }
119 
120  (--it)->second.maxThreads= maxthreads;
121  }
122 
123  void setMaxBlocks(int size, int maxBlocks)
124  {
125  std::map< std::pair<int, int>, BackEndParams >::iterator it;
126  for(it = sizePlan.begin(); it != sizePlan.end(); ++it)
127  {
128  if(size >= it->first.first && size <= it->first.second)
129  {
130  it->second.maxBlocks=maxBlocks;
131  return;
132  }
133  }
134 
135  (--it)->second.maxBlocks= maxBlocks;
136  }
137 
138  void setNumOmpThreads(int size, int ompThreads)
139  {
140  std::map< std::pair<int, int>, BackEndParams >::iterator it;
141  for(it = sizePlan.begin(); it != sizePlan.end(); ++it)
142  {
143  if(size >= it->first.first && size <= it->first.second)
144  {
145  it->second.numOmpThreads = ompThreads;
146  return;
147  }
148  }
149 
150  (--it)->second.numOmpThreads = ompThreads;
151  }
152 
153  int numOmpThreads(int size)
154  {
155  if(sizePlan.empty())
156  return 1;
157 
158  std::map< std::pair<int, int>, BackEndParams >::iterator it;
159  for(it = sizePlan.begin(); it != sizePlan.end(); ++it)
160  {
161  if(size >= it->first.first && size <= it->first.second)
162  {
163  return it->second.numOmpThreads;
164  }
165  }
166 
167  return (--it)->second.numOmpThreads;
168  }
169 
170  int maxThreads(int size)
171  {
172  if(sizePlan.empty())
173  return 32;
174 
175  std::map< std::pair<int, int>, BackEndParams >::iterator it;
176  for(it = sizePlan.begin(); it != sizePlan.end(); ++it)
177  {
178  if(size >= it->first.first && size <= it->first.second)
179  {
180  return it->second.maxThreads;
181  }
182  }
183 
184  return (--it)->second.maxThreads;
185  }
186 
187  BackEnd find(int size)
188  {
189  if(sizePlan.empty())
190  return CPU_BACKEND;
191 
192  std::map< std::pair<int, int>, BackEndParams >::iterator it;
193  for(it = sizePlan.begin(); it != sizePlan.end(); ++it)
194  {
195  if(size >= it->first.first && size <= it->first.second)
196  {
197  return it->second.backend;
198  }
199  }
200 
201  return (--it)->second.backend;
202  }
203 
204  BackEndParams find_(int size)
205  {
206  if(sizePlan.empty())
207  return BackEndParams();
208 
209  std::map< std::pair<int, int>, BackEndParams >::iterator it;
210  for(it = sizePlan.begin(); it != sizePlan.end(); ++it)
211  {
212  if(size >= it->first.first && size <= it->first.second)
213  {
214  return it->second;
215  }
216  }
217 
218  return (--it)->second;
219  }
220 
221  void clear()
222  {
223  sizePlan.clear();
224  }
225 
226 private:
227  std::map< std::pair<int, int>, BackEndParams > sizePlan;
228 };
229 
230 }
231 
232 #endif
233 
A class that describes an execution plan, not used very much in this case as decision is mostly left ...
Definition: exec_plan.h:75