SkePU  1.2
 All Classes Namespaces Files Functions Variables 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 namespace skepu
12 {
13 
14 
20 {
21  BackEndParams(): backend(CPU_BACKEND), maxThreads(256), maxBlocks(65535), numOmpThreads(1) {}
22  BackEnd backend;
23  size_t maxThreads;
24  size_t maxBlocks;
25  unsigned int numOmpThreads;
26 };
27 
28 
47 class ExecPlan
48 {
49 public:
50  ExecPlan()
51  {
52  m_cacheEntry.first = 0;
53  calibrated = false;
54  }
55 
57  bool calibrated;
58 
59  void add(size_t lowBound, size_t highBound, BackEnd backend, size_t gs, size_t bs)
60  {
61  BackEndParams bp;
62  bp.backend=backend;
63  bp.maxThreads=bs;
64  bp.maxBlocks = gs;
65  sizePlan.insert(std::make_pair(std::make_pair(lowBound, highBound),bp));
66  }
67 
68  void add(size_t lowBound, size_t highBound, BackEnd backend, unsigned int numOmpThreads)
69  {
70  BackEndParams bp;
71  bp.backend=backend;
72  bp.numOmpThreads = numOmpThreads;
73  sizePlan.insert(std::make_pair(std::make_pair(lowBound, highBound),bp));
74  }
75 
76  void add(size_t lowBound, size_t highBound, BackEndParams params)
77  {
78  sizePlan.insert(std::make_pair(std::make_pair(lowBound, highBound),params));
79  }
80 
81  void add(size_t lowBound, size_t highBound, BackEnd backend)
82  {
83  BackEndParams bp;
84  bp.backend=backend;
85  sizePlan.insert(std::make_pair(std::make_pair(lowBound, highBound),bp));
86  }
87 
88  void setMaxThreads(size_t size, size_t maxthreads)
89  {
90  std::map< std::pair<size_t, size_t>, BackEndParams >::iterator it;
91  for(it = sizePlan.begin(); it != sizePlan.end(); ++it)
92  {
93  if(size >= it->first.first && size <= it->first.second)
94  {
95  it->second.maxThreads=maxthreads;
96  return;
97  }
98  }
99 
100  (--it)->second.maxThreads= maxthreads;
101  }
102 
103  void setMaxBlocks(size_t size, size_t maxBlocks)
104  {
105  std::map< std::pair<size_t, size_t>, BackEndParams >::iterator it;
106  for(it = sizePlan.begin(); it != sizePlan.end(); ++it)
107  {
108  if(size >= it->first.first && size <= it->first.second)
109  {
110  it->second.maxBlocks=maxBlocks;
111  return;
112  }
113  }
114 
115  (--it)->second.maxBlocks= maxBlocks;
116  }
117 
118  void setNumOmpThreads(size_t size, unsigned int ompThreads)
119  {
120  std::map< std::pair<size_t, size_t>, BackEndParams >::iterator it;
121  for(it = sizePlan.begin(); it != sizePlan.end(); ++it)
122  {
123  if(size >= it->first.first && size <= it->first.second)
124  {
125  it->second.numOmpThreads = ompThreads;
126  return;
127  }
128  }
129 
130  (--it)->second.numOmpThreads = ompThreads;
131  }
132 
133  unsigned int numOmpThreads(size_t size)
134  {
135  if(sizePlan.empty())
136  return 1;
137 
138  std::map< std::pair<size_t, size_t>, BackEndParams >::iterator it;
139  for(it = sizePlan.begin(); it != sizePlan.end(); ++it)
140  {
141  if(size >= it->first.first && size <= it->first.second)
142  {
143  return it->second.numOmpThreads;
144  }
145  }
146 
147  return (--it)->second.numOmpThreads;
148  }
149 
150  size_t maxThreads(size_t size)
151  {
152  if(sizePlan.empty())
153  return 32;
154 
155  std::map< std::pair<size_t, size_t>, BackEndParams >::iterator it;
156  for(it = sizePlan.begin(); it != sizePlan.end(); ++it)
157  {
158  if(size >= it->first.first && size <= it->first.second)
159  {
160  return it->second.maxThreads;
161  }
162  }
163 
164  return (--it)->second.maxThreads;
165  }
166 
167  bool isTrainedFor(size_t size)
168  {
169  if(sizePlan.empty())
170  return false;
171 
172  std::map< std::pair<size_t, size_t>, BackEndParams >::iterator it;
173  for(it = sizePlan.begin(); it != sizePlan.end(); ++it)
174  {
175  if(size >= it->first.first && size <= it->first.second)
176  {
177  return true;
178  }
179  }
180 
181  return false;
182  }
183 
184  BackEnd find(size_t size)
185  {
186  if(sizePlan.empty())
187  return CPU_BACKEND;
188 
189  if(m_cacheEntry.first == size)
190  return m_cacheEntry.second.backend;
191 
192  std::map< std::pair<size_t, size_t>, 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  m_cacheEntry = std::make_pair(size, it->second);
198  return m_cacheEntry.second.backend;
199  }
200  }
201 
202  m_cacheEntry = std::make_pair(size, (--it)->second);
203  return m_cacheEntry.second.backend;
204  }
205 
206  BackEndParams find_(size_t size)
207  {
208  if(sizePlan.empty())
209  return BackEndParams();
210 
211  if(m_cacheEntry.first == size)
212  return m_cacheEntry.second;
213 
214  std::map< std::pair<size_t, size_t>, BackEndParams >::iterator it;
215  for(it = sizePlan.begin(); it != sizePlan.end(); ++it)
216  {
217  if(size >= it->first.first && size <= it->first.second)
218  {
219  m_cacheEntry = std::make_pair(size, it->second);
220  return m_cacheEntry.second;
221 // return it->second;
222  }
223  }
224 
225  m_cacheEntry = std::make_pair(size, (--it)->second);
226  return m_cacheEntry.second;
227 // return (--it)->second;
228  }
229 
230  void clear()
231  {
232  sizePlan.clear();
233  }
234 
235 
236 public:
237  std::pair<size_t, BackEndParams> m_cacheEntry;
238  std::map< std::pair<size_t, size_t>, BackEndParams > sizePlan;
239 };
240 
241 }
242 
243 #endif
244 
245 
bool calibrated
Definition: exec_plan.h:57
BackEnd
Can be used to specify which backend to use.
Definition: environment.h:34
A class that describes an execution plan.
Definition: exec_plan.h:47
Can be used to specify properties for a backend.
Definition: exec_plan.h:19