SkePU(integratedwithStarPU)  0.8.1
 All Classes Namespaces Files Functions Enumerations Friends Macros Groups Pages
maparray.h
Go to the documentation of this file.
1 
5 #ifndef MAP_ARRAY_H
6 #define MAP_ARRAY_H
7 
8 
9 
10 #include <starpu.h>
11 #ifdef SKEPU_OPENCL
12  #include <starpu_opencl.h>
13 #endif
14 
15 
16 #ifdef SKEPU_OPENCL
17 #include <string>
18 #include <vector>
19 #ifdef USE_MAC_OPENCL
20 #include <OpenCL/opencl.h>
21 #else
22 #include <CL/cl.h>
23 #endif
24 #include "src/device_cl.h"
25 #endif
26 
27 #include "src/environment.h"
28 #include "skepu/task.h"
29 #include "skepu/vector.h"
30 #include "skepu/matrix.h"
31 #include "skepu/sparse_matrix.h"
32 #include "src/operator_macros.h"
33 #include "src/exec_plan.h"
34 
35 namespace skepu
36 {
37 
61 template <typename MapArrayFunc, typename T, skepu_container_type c_type=VECTOR>
62 class MapArray: public Task
63 {
64 
65 typedef struct
66 {
68  bool parts;
69  bool binaryOperand;
70 }ArgumentBuffer;
71 
72 
73 
74 public:
75 
76  bool binaryOperand;
77 
78  MapArray(MapArrayFunc* mapArrayFunc);
79 
80  MapArray(MapArrayFunc* mapArrayFunc, Vector<T> *in1, Vector<T> *in2, Vector<T> *out, int _parts=1);
81 
82  ~MapArray();
83 
84  Vector<T>& getOutput()
85  {
86  return *output;
87  }
88 
89  void *get_result()
90  {
91  return output;
92  }
93 
94 
95  void setInput1(Vector<T> *in)
96  {
97  input1 = in;
98  }
99 
100  void setInput2(Vector<T> *in)
101  {
102  input2 = in;
103  }
104 
105  void setOutput(Vector<T> *out)
106  {
107  output = out;
108  }
109 
110  void setPartitions(int _parts)
111  {
112  parts = _parts;
113  }
114 
115 // template <typename U>
116 // void setConstant(U constant) { m_mapArrayFunc->setConstant(constant); }
117 
118  void run_async();
119 
120  void finishAll() {m_environment->finishAll();}
121  void setExecPlan(ExecPlan& plan) {m_execPlan = plan;}
122 
123 private:
124  Environment<int>* m_environment;
125  MapArrayFunc* m_mapArrayFunc;
126  ExecPlan m_execPlan;
127 
128 #ifdef USE_STARPU_HISTORY_MODEL
129  starpu_perfmodel *maparr1_perf_model;
130  starpu_perfmodel *maparr2_perf_model;
131 #endif
132 
133  struct starpu_codelet *sameIOCodelet;
134  struct starpu_codelet *diffIOCodelet;
135 
136  #ifdef UNEVEN_PART
137  struct starpu_codelet *sameIOCodelet2;
138  struct starpu_codelet *diffIOCodelet2;
139  #endif
140 
141 public:
142  void operator()(Vector<T>& input1, Vector<T>& input2, Vector<T>& output);
143 
144  void operator()(Vector<T>& input1, Vector<T>& input2, Vector<T>& output, int parts);
145 
146 public:
147  static void cpu_func(void *buffers[], void *arg);
148 
149 #ifdef SKEPU_OPENMP
150 public:
151  static void omp_func(void *buffers[], void *arg);
152 #endif
153 
154 #ifdef SKEPU_CUDA
155 public:
156  static void cuda_func(void *buffers[], void *arg);
157 #endif
158 
159 #ifdef SKEPU_OPENCL
160 public:
161  static void opencl_func(void *buffers[], void *arg);
162 
163 public:
164  struct starpu_opencl_program opencl_codelet;
165  char kernelNameArray[1024];
166 
167  void replaceText(std::string& text, std::string find, std::string replace);
168  void createOpenCLProgram();
169 
170 #endif
171 
172 private:
173  std::string perfmodel1_str;
174  std::string perfmodel2_str;
175 
176  Vector<T> *input1;
177  Vector<T> *input2;
178  Vector<T> *output;
179  int parts;
180 
181 };
182 
183 
184 
185 
186 
187 
188 
189 
190 
191 
192 
193 
194 
195 
196 
197 
198 
199 
219 template <typename MapArrayFunc, typename T>
220 class MapArray<MapArrayFunc, T, MATRIX>: public Task
221 {
222 
223 typedef struct
224 {
226  bool parts;
227  bool binaryOperand;
228 }ArgumentBuffer;
229 
230 
231 public:
232  bool binaryOperand;
233 
234 public:
235 
236  MapArray(MapArrayFunc* mapArrayFunc);
237 
238  MapArray(MapArrayFunc* mapArrayFunc, Vector<T> *in1, Matrix<T> *in2, Matrix<T> *out, int _parts=1);
239 
240  MapArray(MapArrayFunc* mapArrayFunc, Vector<T> *in1, Matrix<T> *in2, Vector<T> *out, int _parts=1);
241 
242  ~MapArray();
243 
244  void finishAll() {m_environment->finishAll();}
245  void setExecPlan(ExecPlan& plan) {m_execPlan = plan;}
246 
247 private:
248  Environment<int>* m_environment;
249  MapArrayFunc* m_mapArrayFunc;
250  ExecPlan m_execPlan;
251 
252 #ifdef USE_STARPU_HISTORY_MODEL
253  starpu_perfmodel *maparr1_matr_perf_model;
254  starpu_perfmodel *maparr2_matr_perf_model;
255 #endif
256 
257 public:
258  struct starpu_codelet *sameIOCodelet;
259  struct starpu_codelet *diffIOCodelet;
260 
261  #ifdef UNEVEN_PART
262  struct starpu_codelet *sameIOCodelet2;
263  struct starpu_codelet *diffIOCodelet2;
264  #endif
265 
266 
267  Matrix<T>& getOutput()
268  {
269  return *output;
270  }
271 
272  void *get_result()
273  {
274  return output;
275  }
276 
277 
278  void setInput1(Vector<T> *in)
279  {
280  input1 = in;
281  }
282 
283  void setInput2(Matrix<T> *in)
284  {
285  input2 = in;
286  }
287 
288  void setOutput(Matrix<T> *out)
289  {
290  output = out;
291  }
292 
293  void setPartitions(int _parts)
294  {
295  parts = _parts;
296  }
297 
298  void run_async();
299 
300  template <typename U>
301  void setConstant(U constant) { m_mapArrayFunc->setConstant(constant); }
302 
303 
304 
305 public:
306  void operator()(Vector<T>& input1, Matrix<T>& input2, Matrix<T>& output, int parts=1);
307 
308  void operator()(Vector<T>& input1, Matrix<T>& input2, Vector<T>& output, int parts=1);
309 
310 public:
311  static void cpu_func(void *buffers[], void *arg);
312 
313  static void cpu_func_blockwise(void *buffers[], void *arg);
314 
315 #ifdef SKEPU_OPENMP
316 public:
317  static void omp_func(void *buffers[], void *arg);
318 
319  static void omp_func_blockwise(void *buffers[], void *arg);
320 #endif
321 
322 #ifdef SKEPU_CUDA
323 public:
324  static void cuda_func(void *buffers[], void *arg);
325 
326  static void cuda_func_blockwise(void *buffers[], void *arg);
327 #endif
328 
329 #ifdef SKEPU_OPENCL
330 public:
331  static void opencl_func(void *buffers[], void *arg);
332 
333  static void opencl_func_blockwise(void *buffers[], void *arg);
334 
335 public:
336  struct starpu_opencl_program opencl_codelet;
337 // struct starpu_opencl_program opencl_codelet_blockwise;
338  char kernelNameArray[1024];
339 
340  void replaceText(std::string& text, std::string find, std::string replace);
341  void createOpenCLProgram();
342 
343 #endif
344 
345 private:
346  std::string perfmodel1_str;
347  std::string perfmodel2_str;
348 // std::string perfmodel_str_blockwise;
349 
350  Vector<T> *input1;
351  Matrix<T> *input2;
352  Matrix<T> *output;
353  Vector<T> *output_blockwise;
354  int parts;
355 };
356 
357 
358 
359 
360 
361 
362 
363 
364 
365 
366 
367 
368 
369 
370 
391 //template <typename MapArrayFunc, typename T>
392 //class MapArray<MapArrayFunc, T, SPARSE_MATRIX>: public Task
393 //{
394 //
395 //public:
396 //
397 // MapArray(MapArrayFunc* mapArrayFunc);
398 //
399 // MapArray(MapArrayFunc* mapArrayFunc, Vector<T> *in1, SparseMatrix<T> *in2, Vector<T> *out, int _parts=1);
400 //
401 // ~MapArray();
402 //
403 // void finishAll() {m_environment->finishAll();}
404 // void setExecPlan(ExecPlan& plan) {m_execPlan = plan;}
405 //
406 //private:
407 // Environment<int>* m_environment;
408 // MapArrayFunc* m_mapArrayFunc;
409 // ExecPlan m_execPlan;
410 //
411 //#ifdef USE_STARPU_HISTORY_MODEL
412 // starpu_perfmodel *maparr_matr_perf_model;
413 //#endif
414 //
415 // Vector<T>& getOutput()
416 // {
417 // return *output;
418 // }
419 //
420 // void *get_result()
421 // {
422 // return output;
423 // }
424 //
425 //
426 // void setInput1(Vector<T> *in)
427 // {
428 // input1 = in;
429 // }
430 //
431 // void setInput2(SparseMatrix<T> *in)
432 // {
433 // input2 = in;
434 // }
435 //
436 // void setOutput(Vector<T> *out)
437 // {
438 // output = out;
439 // }
440 //
441 // void setPartitions(int _parts)
442 // {
443 // parts = _parts;
444 // }
445 //
446 // void run_async();
447 //
448 // template <typename U>
449 // void setConstant(U constant) { m_mapArrayFunc->setConstant(constant); }
450 //
451 // struct starpu_codelet *codelet;
452 //
453 //public:
454 // void operator()(Vector<T>& input1, SparseMatrix<T>& input2, Vector<T>& output, int parts=1);
455 //
456 //public:
457 // static void cpu_func(void *buffers[], void *arg);
458 //
459 //#ifdef SKEPU_OPENMP
460 //public:
461 // static void omp_func(void *buffers[], void *arg);
462 //#endif
463 //
464 //#ifdef SKEPU_CUDA
465 //public:
466 // static void cuda_func(void *buffers[], void *arg);
467 //#endif
468 //
469 //#ifdef SKEPU_OPENCL
470 //public:
471 // static void opencl_func(void *buffers[], void *arg);
472 //
473 //public:
474 // struct starpu_opencl_program opencl_codelet;
475 // char kernelNameArray[1024];
476 //
477 // void replaceText(std::string& text, std::string find, std::string replace);
478 // void createOpenCLProgram();
479 //
480 //#endif
481 //
482 //private:
483 // std::string perfmodel_str;
484 //
485 // Vector<T> *input1;
486 // SparseMatrix<T> *input2;
487 // Vector<T> *output;
488 //
489 // int parts;
490 //};
491 
492 
493 
494 }
495 
496 #include "src/maparray.inl"
497 
498 #include "src/maparray_cpu.inl"
499 
500 #ifdef SKEPU_OPENMP
501 #include "src/maparray_omp.inl"
502 #endif
503 
504 #ifdef SKEPU_OPENCL
505 #include "src/maparray_cl.inl"
506 #endif
507 
508 #ifdef SKEPU_CUDA
509 #include "src/maparray_cu.inl"
510 #endif
511 
512 #endif
513 
Contains the definitions of CUDA specific functions for the MapArray skeleton.
Contains a class declaration for the SparseMatrix container.
Contains the definitions of non-backend specific member functions for the MapArray skeleton...
A class representing the MapArray skeleton.
Definition: maparray.h:62
Includes the macro files needed for the defined backends.
void finishAll()
Definition: environment.inl:119
Contains the definitions of OpenCL specific functions for the MapArray skeleton.
Contains the definitions of CPU specific functions for the MapArray skeleton.
static void omp_func(void *buffers[], void *arg)
Definition: maparray_omp.inl:25
Contains a class declaration for the object that represents an OpenCL device.
static void cuda_func(void *buffers[], void *arg)
Definition: maparray_cu.inl:27
void operator()(Vector< T > &input1, Vector< T > &input2, Vector< T > &output)
Definition: maparray.inl:310
A vector container class, implemented as a wrapper for std::vector. It is configured to use StarPU DS...
Definition: vector.h:40
~MapArray()
Definition: maparray.inl:259
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
Contains a class declaration for the Vector container.
Contains a class declaration for Environment class.
void replaceText(std::string &text, std::string find, std::string replace)
Definition: maparray_cl.inl:25
void run_async()
Definition: maparray.inl:283
static void cpu_func(void *buffers[], void *arg)
Definition: maparray_cpu.inl:22
Contains the definitions of OpenMP specific member functions for the MapArray skeleton.
MapArray(MapArrayFunc *mapArrayFunc)
Definition: maparray.inl:21
Contains a class that stores information about which back ends to use when executing.
static void opencl_func(void *buffers[], void *arg)
Definition: maparray_cl.inl:95
void createOpenCLProgram()
Definition: maparray_cl.inl:47