SkePU(integratedwithStarPU)  0.8.1
 All Classes Namespaces Files Functions Enumerations Friends Macros Groups Pages
mapoverlap.h
Go to the documentation of this file.
1 
5 #ifndef MAPOVERLAP_H
6 #define MAPOVERLAP_H
7 
8 
9 #include <starpu.h>
10 #ifdef SKEPU_OPENCL
11  #include <starpu_opencl.h>
12 #endif
13 
14 
15 #ifdef SKEPU_OPENCL
16 #include <string>
17 #include <vector>
18 #ifdef USE_MAC_OPENCL
19 #include <OpenCL/opencl.h>
20 #else
21 #include <CL/cl.h>
22 #endif
23 #include "src/device_cl.h"
24 #endif
25 
26 
27 
28 #include "src/environment.h"
29 
30 #include "skepu/task.h"
31 #include "src/operator_macros.h"
32 #include "src/exec_plan.h"
33 
34 #include "skepu/vector.h"
35 #include "skepu/matrix.h"
36 
37 namespace skepu
38 {
39 
40 
45 {
46  OVERLAP_ROW_WISE,
47  OVERLAP_COL_WISE,
48  OVERLAP_ROW_COL_WISE,
49  OVERLAP_CONVOL_WISE
50 };
51 
52 
57 {
58  CONSTANT,
59  CYCLIC,
60  DUPLICATE
61 };
62 
87 template <typename MapOverlapFunc, typename T, skepu_container_type c_type=VECTOR>
88 class MapOverlap: public Task
89 {
90 
91 typedef struct
92 {
94  EdgePolicy poly;
95  bool unaryOperand;
96  T pad;
97 }ArgumentBuffer;
98 
99 public:
100 
101  EdgePolicy poly;
102  T pad;
103  Vector<T> *input;
104  Vector<T> *output;
105 
106 
107  MapOverlap(MapOverlapFunc* mapOverlapFunc);
108 
109  MapOverlap(MapOverlapFunc* mapOverlapFunc, Vector<T> *in, Vector<T> *out, EdgePolicy poly, T pad=T());
110 
111  ~MapOverlap();
112 
113 
114  Vector<T>& getOutput()
115  {
116  if(!temp_output.empty())
117  {
118  typename Vector<T>::iterator outputBegin = output->begin();
119  for(typename Vector<T>::iterator it = temp_output.begin(); outputBegin != output->end(); ++outputBegin, ++it)
120  {
121  *outputBegin = *it;
122  }
123  temp_output.clear();
124  }
125  return *output;
126  }
127 
128  void *get_result()
129  {
130  if(!temp_output.empty())
131  {
132  typename Vector<T>::iterator outputBegin = output->begin();
133  for(typename Vector<T>::iterator it = temp_output.begin(); outputBegin != output->end(); ++outputBegin, ++it)
134  {
135  *outputBegin = *it;
136  }
137  temp_output.clear();
138  }
139  return output;
140  }
141 
142  void setInput(Vector<T> *in)
143  {
144  input = in;
145  }
146 
147  void setOutput(Vector<T> *out)
148  {
149  output = out;
150  }
151 
152  void setPad(T _pad)
153  {
154  pad = _pad;
155  }
156 
157  void setEdgePolicy(EdgePolicy _poly)
158  {
159  poly = _poly;
160  }
161 
162  void run_async();
163 
164  void finishAll() {m_environment->finishAll();}
165  void setExecPlan(ExecPlan& plan) {m_execPlan = plan;}
166 
167 public:
168  Environment<int>* m_environment;
169  MapOverlapFunc* m_mapOverlapFunc;
170  ExecPlan m_execPlan;
171 
172  struct starpu_codelet *codelet;
173  struct starpu_codelet *codelet_three;
174 
175 #ifdef USE_STARPU_HISTORY_MODEL
176  starpu_perfmodel *mapoverlap_perf_model;
177 #endif
178 
179 // bool unaryOperand;
180 
181 public:
182  void operator()(Vector<T>& input, EdgePolicy poly = CONSTANT, T pad = T());
183 
184  void operator()(Vector<T>& input, Vector<T>& output, EdgePolicy poly = CONSTANT, T pad = T());
185 
186 public:
187  static void cpu_func(void *buffers[], void *arg);
188 
189 #ifdef SKEPU_OPENMP
190 public:
191  static void omp_func(void *buffers[], void *arg);
192 #endif
193 
194 #ifdef SKEPU_CUDA
195 public:
196  static void cuda_func(void *buffers[], void *arg);
197 #endif
198 
199 #ifdef SKEPU_OPENCL
200 public:
201  static void opencl_func(void *buffers[], void *arg);
202 
203 public:
204  struct starpu_opencl_program opencl_codelet;
205  char kernelNameArray[1024];
206 
207  void replaceText(std::string& text, std::string find, std::string replace);
208  void createOpenCLProgram();
209 #endif
210 
211 private:
212  std::string perfmodel_str;
213 
214  Vector<T> temp_output;
215 
216 };
217 
218 
219 
220 
221 
222 
223 
224 
225 
226 
227 
228 
229 
230 
231 
232 
252 template <typename MapOverlapFunc, typename T>
253 class MapOverlap<MapOverlapFunc, T, MATRIX>: public Task
254 {
255 typedef struct
256 {
258  EdgePolicy poly;
259  bool parts;
260  T pad;
261 }ArgumentBuffer;
262 
263 
264 typedef struct
265 {
266  MapOverlap<MapOverlapFunc, T, MATRIX> *pMapOverlap;
267  int filter_rows;
268  int filter_cols;
269 }ArgumentBufferConvol;
270 
271 
272 private:
273 Matrix<T> temp_output;
274 Matrix<T> *input;
275 Matrix<T> *output;
276 Matrix<T> *filter;
277 OverlapPolicy overlapType;
278 EdgePolicy poly;
279 T pad;
280 int xblocks;
281 int yblocks;
282 int filter_rows;
283 int filter_cols;
284 
285 public:
286 
287 
288  MapOverlap(MapOverlapFunc* mapOverlapFunc);
289 
290  MapOverlap(MapOverlapFunc* mapOverlapFunc, Matrix<T> *input, Matrix<T> *output, OverlapPolicy overlapPolicy=OVERLAP_ROW_WISE, EdgePolicy poly=CONSTANT, T pad = T(),int xblocks=1, int yblocks=1);
291 
292  ~MapOverlap();
293 
294 
295  Matrix<T>& getOutput()
296  {
297  if(!temp_output.empty())
298  {
299  typename Matrix<T>::iterator outputBegin = output->begin();
300  for(typename Matrix<T>::iterator it = temp_output.begin(); outputBegin != output->end(); ++outputBegin, ++it)
301  {
302  *outputBegin = *it;
303  }
304  temp_output.clear();
305  }
306  return *output;
307  }
308 
309  void *get_result()
310  {
311  if(!temp_output.empty())
312  {
313  typename Matrix<T>::iterator outputBegin = output->begin();
314  for(typename Matrix<T>::iterator it = temp_output.begin(); outputBegin != output->end(); ++outputBegin, ++it)
315  {
316  *outputBegin = *it;
317  }
318  temp_output.clear();
319  }
320  return output;
321  }
322 
323  void setInput(Matrix<T> *in)
324  {
325  input = in;
326  }
327 
328  void setOutput(Matrix<T> *out)
329  {
330  output = out;
331  }
332 
333  void setFilter(Matrix<T> *fil)
334  {
335  filter = fil;
336  }
337 
338  void setFilterSize(int rows, int cols)
339  {
340  filter_rows= rows;
341  filter_cols= cols;
342  }
343 
344  void setPad(T _pad)
345  {
346  pad = _pad;
347  }
348 
349  void setOverlapType(OverlapPolicy _overlapType)
350  {
351  overlapType = _overlapType;
352  }
353 
354  void run_async();
355 
356  void finishAll() {m_environment->finishAll();}
357  void setExecPlan(ExecPlan& plan) {m_execPlan = plan;}
358 
359 private:
360  Environment<int>* m_environment;
361  MapOverlapFunc* m_mapOverlapFunc;
362  ExecPlan m_execPlan;
363 
364  struct starpu_codelet *codelet_row;
365  struct starpu_codelet *codelet_col;
366  struct starpu_codelet *codelet_convol;
367  struct starpu_codelet *codelet_convol_filter;
368 
369 #ifdef USE_STARPU_HISTORY_MODEL
370  starpu_perfmodel *mapoverlap_perf_model_row;
371  starpu_perfmodel *mapoverlap_perf_model_col;
372  starpu_perfmodel *mapoverlap_perf_model_convol;
373  starpu_perfmodel *mapoverlap_perf_model_convol_filter;
374 #endif
375 
376 private:
377  void mapoverlap_matrix(Matrix<T>& input, EdgePolicy poly = CONSTANT, T pad = T(), OverlapPolicy overlapPolicy=OVERLAP_ROW_WISE,int xblocks=1, int yblocks=1);
378 
379  void mapoverlap_matrix(Matrix<T>& input, Matrix<T>& output, EdgePolicy poly = CONSTANT, T pad = T(), OverlapPolicy overlapPolicy=OVERLAP_ROW_WISE,int xblocks=1, int yblocks=1);
380 
381 public:
382  void operator()(Matrix<T>& input, EdgePolicy poly = CONSTANT, T pad = T(), OverlapPolicy overlapPolicy=OVERLAP_ROW_WISE, int xblocks=1, int yblocks=1);
383 
384  void operator()(Matrix<T>& input, Matrix<T>& output, EdgePolicy poly = CONSTANT, T pad = T(), OverlapPolicy overlapPolicy=OVERLAP_ROW_WISE, int xblocks=1, int yblocks=1);
385 
386  void operator()(Matrix<T>& input, Matrix<T>& output, Matrix<T>& filter);
387 
388  void operator()(Matrix<T>& input, Matrix<T>& output, unsigned int filter_rows, unsigned int filter_cols);
389 
390 public:
391  static void cpu_func_row(void *buffers[], void *arg);
392 
393  static void cpu_func_col(void *buffers[], void *arg);
394 
395  static void cpu_func_convol_filter(void *buffers[], void *arg);
396 
397  static void cpu_func_convol(void *buffers[], void *arg);
398 
399 #ifdef SKEPU_OPENMP
400 public:
401  static void omp_func_row(void *buffers[], void *arg);
402 
403  static void omp_func_col(void *buffers[], void *arg);
404 
405  static void omp_func_convol_filter(void *buffers[], void *arg);
406 
407  static void omp_func_convol(void *buffers[], void *arg);
408 
409 #endif
410 
411 #ifdef SKEPU_CUDA
412 public:
413  static void cuda_func_row(void *buffers[], void *arg);
414 
415  static void cuda_func_col(void *buffers[], void *arg);
416 
417  static void cuda_func_convol_filter(void *buffers[], void *arg);
418 
419  static void cuda_func_convol(void *buffers[], void *arg);
420 #endif
421 
422 #ifdef SKEPU_OPENCL
423 public:
424  static void opencl_func_row(void *buffers[], void *arg);
425 
426  static void opencl_func_col(void *buffers[], void *arg);
427 
428  static void opencl_func_convol_filter(void *buffers[], void *arg);
429 
430  static void opencl_func_convol(void *buffers[], void *arg);
431 
432 public:
433  struct starpu_opencl_program opencl_codelet;
434 // struct starpu_opencl_program opencl_codelet_col;
435 // struct starpu_opencl_program opencl_codelet_convol;
436 // struct starpu_opencl_program opencl_codelet_convol_filter;
437 
438  char kernelNameArray_Row[1024];
439  char kernelNameArray_Col[1024];
440  char kernelNameArray_Convol[1024];
441  char kernelNameArray_ConvolFilter[1024];
442 // char kernelNameArray_Trans[1024];
443 
444  void replaceText(std::string& text, std::string find, std::string replace);
445  void createOpenCLProgram();
446 #endif
447 
448 private:
449  std::string perfmodel_str_row;
450  std::string perfmodel_str_col;
451  std::string perfmodel_str_convol_filter;
452  std::string perfmodel_str_convol;
453 
454 };
455 
456 
457 
458 
459 
460 
461 
462 
463 }
464 
465 #include "src/mapoverlap.inl"
466 
467 #include "src/mapoverlap_cpu.inl"
468 
469 #ifdef SKEPU_OPENMP
470 #include "src/mapoverlap_omp.inl"
471 #endif
472 
473 #ifdef SKEPU_OPENCL
474 #include "src/mapoverlap_cl.inl"
475 #endif
476 
477 #ifdef SKEPU_CUDA
478 #include "src/mapoverlap_cu.inl"
479 #endif
480 
481 #endif
482 
Contains the definitions of OpenCL specific functions for the MapOverlap skeleton.
static void omp_func(void *buffers[], void *arg)
Definition: mapoverlap_omp.inl:28
void createOpenCLProgram()
Definition: mapoverlap_cl.inl:51
Includes the macro files needed for the defined backends.
static void cuda_func(void *buffers[], void *arg)
Definition: mapoverlap_cu.inl:30
void finishAll()
Definition: environment.inl:119
Contains the definitions of CUDA specific functions for the MapOverlap skeleton.
Contains the definitions of non-backend specific functions for the MapOverlap skeleton.
Contains a class declaration for the object that represents an OpenCL device.
Contains the definitions of CPU specific functions for the MapOverlap skeleton.
A vector container class, implemented as a wrapper for std::vector. It is configured to use StarPU DS...
Definition: vector.h:40
void run_async()
Definition: mapoverlap.inl:230
EdgePolicy
Definition: mapoverlap.h:56
A class that describes an execution plan, not used very much in this case as decision is mostly left ...
Definition: exec_plan.h:75
Contains a class definition for Task.
A class representing a Task for the farm skeleton.
Definition: task.h:31
void operator()(Vector< T > &input, EdgePolicy poly=CONSTANT, T pad=T())
Definition: mapoverlap.inl:256
Contains a class declaration for the Vector container.
Contains the definitions of OpenMP specific functions for the MapOverlap skeleton.
Contains a class declaration for Environment class.
A class representing the MapOverlap skeleton.
Definition: mapoverlap.h:88
void replaceText(std::string &text, std::string find, std::string replace)
Definition: mapoverlap_cl.inl:30
static void opencl_func(void *buffers[], void *arg)
Definition: mapoverlap_cl.inl:102
An vector iterator class.
Definition: vector_iterator.inl:15
OverlapPolicy
Definition: mapoverlap.h:44
static void cpu_func(void *buffers[], void *arg)
Definition: mapoverlap_cpu.inl:21
MapOverlap(MapOverlapFunc *mapOverlapFunc)
Definition: mapoverlap.inl:23
~MapOverlap()
Definition: mapoverlap.inl:210
Contains a class that stores information about which back ends to use when executing.