SkePU(integratedwithStarPU)  0.8.1
 All Classes Namespaces Files Functions Enumerations Friends Macros Groups Pages
map.h
Go to the documentation of this file.
1 
5 #ifndef MAP_H
6 #define MAP_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 
29 #include "skepu/vector.h"
30 #include "skepu/matrix.h"
31 #include "skepu/sparse_matrix.h"
32 
33 #include "src/operator_macros.h"
34 #include "src/exec_plan.h"
35 #include "src/debug.h"
36 
37 #include "skepu/task.h"
38 
39 namespace skepu
40 {
41 
64 template <typename MapFunc, typename T, skepu::FuncType c_type=UNARY, skepu_container_type cont_type=VECTOR>
65 class Map: public Task
66 {
67 
68 typedef struct
69 {
71  typename MapFunc::CONST_TYPE constant;
72  bool parts;
73  bool unaryOperand;
74 }ArgumentBuffer;
75 
76 public:
77 
78  Map(MapFunc* mapFunc);
79 
80  Map(MapFunc* mapFunc, Vector<T> *input, Vector<T> *output, int parts=1);
81 
82 
83  ~Map();
84 
85 
86  Vector<T>& getOutput()
87  {
88  return *output;
89  }
90 
91  void *get_result()
92  {
93  return output;
94  }
95 
96 
97  void setInput(Vector<T> *in)
98  {
99  input = in;
100  }
101 
102  void setOutput(Vector<T> *out)
103  {
104  output = out;
105  }
106 
107  void setPartitions(int _parts)
108  {
109  parts = _parts;
110  }
111 
112 
113  void run_async();
114 
118  template <typename U>
119  void setConstant(U constant1) {m_mapFunc->setConstant(constant1);}
120 
124  void finishAll() {m_environment->finishAll();}
125  void setExecPlan(ExecPlan& plan) {m_execPlan = plan;}
126 
127 public:
128  Environment<int>* m_environment;
129  MapFunc* m_mapFunc;
130  ExecPlan m_execPlan;
131 
132 #ifdef USE_STARPU_HISTORY_MODEL
133  starpu_perfmodel *map1_perf_model;
134  starpu_perfmodel *map2_perf_model;
135 #endif
136 
137  struct starpu_codelet *sameIOCodelet;
138  struct starpu_codelet *diffIOCodelet;
139 
140  bool unaryOperand;
141 
142 public:
143  void operator()(Vector<T>& input);
144 
145  void operator()(Vector<T>& input, Vector<T>& output); // , unsigned int *tagId=0
146 
147  void operator()(Vector<T>& input, int parts);
148 
149  void operator()(Vector<T>& input, Vector<T>& output, int parts);
150 
151 public:
152  static void cpu_func(void *buffers[], void *arg);
153 
154 #ifdef SKEPU_OPENMP
155 public:
156  static void omp_func(void *buffer[], void *arg);
157 #endif
158 
159 #ifdef SKEPU_CUDA
160 public:
161  static void cuda_func(void *buffer[], void *arg);
162 #endif
163 
164 #ifdef SKEPU_OPENCL
165 public:
166  static void opencl_func(void *buffer[], void *arg);
167 
168 public:
169  struct starpu_opencl_program opencl_codelet;
170  char kernelNameArray[1024];
171 
172  void replaceText(std::string& text, std::string find, std::string replace);
173  void createOpenCLProgram();
174 #endif
175 
176 private:
177  std::string perfmodel1_str;
178  std::string perfmodel2_str;
179 
180  Vector<T> *input;
181 
182  Vector<T> *output;
183 
184  int parts;
185 
186 
187 };
188 
189 
190 
191 
192 
193 
212 template <typename MapFunc, typename T>
213 class Map<MapFunc, T, BINARY, VECTOR>: public Task
214 {
215 
216 typedef struct
217 {
218  Map<MapFunc, T, BINARY, VECTOR> *pMap;
219  typename MapFunc::CONST_TYPE constant;
220  bool parts;
221  int bufferIndex[3];
222 }ArgumentBuffer;
223 
224 
225 public:
226  int bufferIndex[3];
227 
228  Map(MapFunc* mapFunc);
229 
230  Map(MapFunc* mapFunc, Vector<T> *in1, Vector<T> *in2, Vector<T> *out, int parts=1);
231 
232  ~Map();
233 
234  Vector<T>& getOutput()
235  {
236  return *output;
237  }
238 
239  void *get_result()
240  {
241  return output;
242  }
243 
244  void setInput1(Vector<T> *in)
245  {
246  input1 = in;
247  }
248 
249  void setInput2(Vector<T> *in)
250  {
251  input2 = in;
252  }
253 
254  void setOutput(Vector<T> *out)
255  {
256  output = out;
257  }
258 
259  void setPartitions(int _parts)
260  {
261  parts = _parts;
262  }
263 
264  void run_async();
265 
269  template <typename U>
270  void setConstant(U constant1) {m_mapFunc->setConstant(constant1);}
271 
275  void finishAll() {m_environment->finishAll();}
276  void setExecPlan(ExecPlan& plan) {m_execPlan = plan;}
277 
278 public:
279  Environment<int>* m_environment;
280  MapFunc* m_mapFunc;
281  ExecPlan m_execPlan;
282 
283  struct starpu_codelet *singleBuffCodelet;
284  struct starpu_codelet *doubleBuffCodelet;
285  struct starpu_codelet *tripleBuffCodelet;
286 
287 #ifdef UNEVEN_PART
288  struct starpu_codelet *singleBuffCodelet2;
289  struct starpu_codelet *doubleBuffCodelet2;
290  struct starpu_codelet *tripleBuffCodelet2;
291 #endif
292 
293 
294 #ifdef USE_STARPU_HISTORY_MODEL
295  starpu_perfmodel *map1_perf_model;
296  starpu_perfmodel *map2_perf_model;
297  starpu_perfmodel *map3_perf_model;
298 #endif
299 
300 public:
301  void operator()(Vector<T>& input1, Vector<T>& input2, Vector<T>& output);
302 
303  void operator()(Vector<T>& input1, Vector<T>& input2, Vector<T>& output, int parts);
304 
305 public:
306  static void cpu_func(void *buffers[], void *arg);
307 
308 #ifdef SKEPU_OPENMP
309 public:
310  static void omp_func(void *buffer[], void *arg);
311 #endif
312 
313 #ifdef SKEPU_CUDA
314 public:
315  static void cuda_func(void *buffer[], void *arg);
316 #endif
317 
318 #ifdef SKEPU_OPENCL
319 public:
320  static void opencl_func(void *buffer[], void *arg);
321 
322 public:
323  struct starpu_opencl_program opencl_codelet;
324  char kernelNameArray[1024];
325 
326  void replaceText(std::string& text, std::string find, std::string replace);
327  void createOpenCLProgram();
328 #endif
329 
330 private:
331  std::string perfmodel1_str;
332  std::string perfmodel2_str;
333  std::string perfmodel3_str;
334 
335  Vector<T> *input1;
336  Vector<T> *input2;
337  Vector<T> *output;
338 
339  int parts;
340 };
341 
342 
343 
344 
345 
346 
347 
366 template <typename MapFunc, typename T>
367 class Map<MapFunc, T, TERNARY, VECTOR>: public Task
368 {
369 
370 typedef struct
371 {
372  Map<MapFunc, T, TERNARY, VECTOR> *pMap;
373  typename MapFunc::CONST_TYPE constant;
374  bool parts;
375  int bufferIndex[4];
376 }ArgumentBuffer;
377 
378 public:
379  int bufferIndex[4];
380 
381  Map(MapFunc* mapFunc);
382 
383  Map(MapFunc* mapFunc, Vector<T> *in1, Vector<T> *in2, Vector<T> *in3, Vector<T> *out, int parts=1);
384 
385  ~Map();
386 
387 
388  Vector<T>& getOutput()
389  {
390  return *output;
391  }
392 
393  void *get_result()
394  {
395  return output;
396  }
397 
398  void setInput1(Vector<T> *in)
399  {
400  input1 = in;
401  }
402 
403  void setInput2(Vector<T> *in)
404  {
405  input2 = in;
406  }
407 
408  void setInput3(Vector<T> *in)
409  {
410  input3 = in;
411  }
412 
413  void setOutput(Vector<T> *out)
414  {
415  output = out;
416  }
417 
418  void setPartitions(int _parts)
419  {
420  parts = _parts;
421  }
422 
423  void run_async();
424 
425 
429  template <typename U>
430  void setConstant(U constant1) {m_mapFunc->setConstant(constant1);}
431 
435  void finishAll() {m_environment->finishAll();}
436  void setExecPlan(ExecPlan& plan) {m_execPlan = plan;}
437 
438 public:
439  Environment<int>* m_environment;
440  MapFunc* m_mapFunc;
441  ExecPlan m_execPlan;
442 
443  struct starpu_codelet *singleBuffCodelet;
444  struct starpu_codelet *doubleBuffCodelet;
445  struct starpu_codelet *tripleBuffCodelet;
446  struct starpu_codelet *fourBuffCodelet;
447 
448 #ifdef USE_STARPU_HISTORY_MODEL
449  starpu_perfmodel *map1_perf_model;
450  starpu_perfmodel *map2_perf_model;
451  starpu_perfmodel *map3_perf_model;
452  starpu_perfmodel *map4_perf_model;
453 #endif
454 
455 
456 public:
457  void operator()(Vector<T>& input1, Vector<T>& input2, Vector<T>& input3, Vector<T>& output);
458 
459  void operator()(Vector<T>& input1, Vector<T>& input2, Vector<T>& input3, Vector<T>& output, int parts);
460 
461 
462 public:
463  static void cpu_func(void *buffers[], void *arg);
464 
465 #ifdef SKEPU_OPENMP
466 public:
467  static void omp_func(void *buffer[], void *arg);
468 #endif
469 
470 #ifdef SKEPU_CUDA
471 public:
472  static void cuda_func(void *buffer[], void *arg);
473 #endif
474 
475 #ifdef SKEPU_OPENCL
476 public:
477  static void opencl_func(void *buffer[], void *arg);
478 
479 public:
480  struct starpu_opencl_program opencl_codelet;
481  char kernelNameArray[1024];
482 
483  void replaceText(std::string& text, std::string find, std::string replace);
484  void createOpenCLProgram();
485 #endif
486 
487 private:
488  std::string perfmodel1_str;
489  std::string perfmodel2_str;
490  std::string perfmodel3_str;
491  std::string perfmodel4_str;
492 
493  Vector<T> *input1;
494  Vector<T> *input2;
495  Vector<T> *input3;
496 
497  Vector<T> *output;
498 
499  int parts;
500 
501 };
502 
503 
504 
505 
506 
507 //#########
508 //#########
509 //#########
510 //#########
511 //#########
512 //#########
513 //#########
514 //#########
515 
516 
535 template <typename MapFunc, typename T>
536 class Map<MapFunc, T, UNARY, MATRIX>: public Task
537 {
538 
539 typedef struct
540 {
541  Map<MapFunc, T, UNARY, MATRIX> *pMap;
542  typename MapFunc::CONST_TYPE constant;
543  bool parts;
544  bool unaryOperand;
545 }ArgumentBuffer;
546 
547 public:
548 
549  Map(MapFunc* mapFunc);
550 
551  Map(MapFunc* mapFunc, Matrix<T> *input, Matrix<T> *output, int parts=1);
552 
553 
554  ~Map();
555 
556 
557  Matrix<T>& getOutput()
558  {
559  return *output;
560  }
561 
562  void *get_result()
563  {
564  return output;
565  }
566 
567 
568  void setInput(Matrix<T> *in)
569  {
570  input = in;
571  }
572 
573  void setOutput(Matrix<T> *out)
574  {
575  output = out;
576  }
577 
578  void setPartitions(int _parts)
579  {
580  parts = _parts;
581  }
582 
583 
584  void run_async();
585 
589  template <typename U>
590  void setConstant(U constant1) {m_mapFunc->setConstant(constant1);}
591 
595  void finishAll() {m_environment->finishAll();}
596  void setExecPlan(ExecPlan& plan) {m_execPlan = plan;}
597 
598 public:
599  Environment<int>* m_environment;
600  MapFunc* m_mapFunc;
601  ExecPlan m_execPlan;
602 
603 #ifdef USE_STARPU_HISTORY_MODEL
604  starpu_perfmodel *map1_perf_model;
605  starpu_perfmodel *map2_perf_model;
606 #endif
607 
608  struct starpu_codelet *sameIOCodelet;
609  struct starpu_codelet *diffIOCodelet;
610 
611  bool unaryOperand;
612 
613 public:
614  void operator()(Matrix<T>& input);
615 
616  void operator()(Matrix<T>& input, Matrix<T>& output); // , unsigned int *tagId=0
617 
618  void operator()(Matrix<T>& input, int parts);
619 
620  void operator()(Matrix<T>& input, Matrix<T>& output, int parts);
621 
622 public:
623  static void cpu_func(void *buffers[], void *arg);
624 
625 #ifdef SKEPU_OPENMP
626 public:
627  static void omp_func(void *buffer[], void *arg);
628 #endif
629 
630 #ifdef SKEPU_CUDA
631 public:
632  static void cuda_func(void *buffer[], void *arg);
633 #endif
634 
635 #ifdef SKEPU_OPENCL
636 public:
637  static void opencl_func(void *buffer[], void *arg);
638 
639  struct starpu_opencl_program opencl_codelet;
640  char kernelNameArray[1024];
641 
642  void replaceText(std::string& text, std::string find, std::string replace);
643  void createOpenCLProgram();
644 #endif
645 
646 private:
647  std::string perfmodel1_str;
648  std::string perfmodel2_str;
649 
650  Matrix<T> *input;
651 
652  Matrix<T> *output;
653 
654  int parts;
655 
656 
657 };
658 
659 
677 template <typename MapFunc, typename T>
678 class Map<MapFunc, T, BINARY, MATRIX>: public Task
679 {
680 
681 typedef struct
682 {
683  Map<MapFunc, T, BINARY, MATRIX> *pMap;
684  typename MapFunc::CONST_TYPE constant;
685  bool parts;
686  int bufferIndex[3];
687 }ArgumentBuffer;
688 
689 
690 public:
691  int bufferIndex[3];
692 
693  Map(MapFunc* mapFunc);
694 
695  Map(MapFunc* mapFunc, Matrix<T> *in1, Matrix<T> *in2, Matrix<T> *out, int _parts=1);
696 
697 
698  Matrix<T>& getOutput()
699  {
700  return *output;
701  }
702 
703  void *get_result()
704  {
705  return output;
706  }
707 
708  void setInput1(Matrix<T> *in)
709  {
710  input1 = in;
711  }
712 
713  void setInput2(Matrix<T> *in)
714  {
715  input2 = in;
716  }
717 
718  void setOutput(Matrix<T> *out)
719  {
720  output = out;
721  }
722 
723  void setPartitions(int _parts)
724  {
725  parts = _parts;
726  }
727 
728  void run_async();
729 
730 
731  ~Map();
732 
736  template <typename U>
737  void setConstant(U constant1) {m_mapFunc->setConstant(constant1);}
738 
742  void finishAll() {m_environment->finishAll();}
743  void setExecPlan(ExecPlan& plan) {m_execPlan = plan;}
744 
745 public:
746  Environment<int>* m_environment;
747  MapFunc* m_mapFunc;
748  ExecPlan m_execPlan;
749 
750  struct starpu_codelet *singleBuffCodelet;
751  struct starpu_codelet *doubleBuffCodelet;
752  struct starpu_codelet *tripleBuffCodelet;
753 
754 #ifdef USE_STARPU_HISTORY_MODEL
755  starpu_perfmodel *map1_perf_model;
756  starpu_perfmodel *map2_perf_model;
757  starpu_perfmodel *map3_perf_model;
758 #endif
759 
760 public:
761  void operator()(Matrix<T>& input1, Matrix<T>& input2, Matrix<T>& output);
762 
763  void operator()(Matrix<T>& input1, Matrix<T>& input2, Matrix<T>& output, int xparts);
764 
765  void operator()(Matrix<T>& input1, Matrix<T>& input2, Matrix<T>& output, int xparts, int yparts);
766 
767 
768 public:
769  static void cpu_func(void *buffers[], void *arg);
770 
771 #ifdef SKEPU_OPENMP
772 public:
773  static void omp_func(void *buffer[], void *arg);
774 #endif
775 
776 #ifdef SKEPU_CUDA
777 public:
778  static void cuda_func(void *buffer[], void *arg);
779 #endif
780 
781 #ifdef SKEPU_OPENCL
782 public:
783  static void opencl_func(void *buffer[], void *arg);
784 
785 public:
786  struct starpu_opencl_program opencl_codelet;
787  char kernelNameArray[1024];
788 
789  void replaceText(std::string& text, std::string find, std::string replace);
790  void createOpenCLProgram();
791 #endif
792 
793 private:
794  std::string perfmodel1_str;
795  std::string perfmodel2_str;
796  std::string perfmodel3_str;
797 
798  Matrix<T> *input1;
799  Matrix<T> *input2;
800 
801  Matrix<T> *output;
802 
803  int parts;
804 };
805 
806 
807 
808 
809 
810 
811 
812 
831 template <typename MapFunc, typename T>
832 class Map<MapFunc, T, TERNARY, MATRIX>: public Task
833 {
834 
835 typedef struct
836 {
837  Map<MapFunc, T, TERNARY, MATRIX> *pMap;
838  typename MapFunc::CONST_TYPE constant;
839  bool parts;
840  int bufferIndex[4];
841 }ArgumentBuffer;
842 
843 public:
844  int bufferIndex[4];
845 
846  Map(MapFunc* mapFunc);
847 
848  Map(MapFunc* mapFunc, Matrix<T> *in1, Matrix<T> *in2, Matrix<T> *in3, Matrix<T> *out, int parts=1);
849 
850  ~Map();
851 
852 
853  Matrix<T>& getOutput()
854  {
855  return *output;
856  }
857 
858  void *get_result()
859  {
860  return output;
861  }
862 
863  void setInput1(Matrix<T> *in)
864  {
865  input1 = in;
866  }
867 
868  void setInput2(Matrix<T> *in)
869  {
870  input2 = in;
871  }
872 
873  void setInput3(Matrix<T> *in)
874  {
875  input3 = in;
876  }
877 
878  void setOutput(Matrix<T> *out)
879  {
880  output = out;
881  }
882 
883  void setPartitions(int _parts)
884  {
885  parts = _parts;
886  }
887 
888  void run_async();
889 
890 
894  template <typename U>
895  void setConstant(U constant1) {m_mapFunc->setConstant(constant1);}
896 
900  void finishAll() {m_environment->finishAll();}
901  void setExecPlan(ExecPlan& plan) {m_execPlan = plan;}
902 
903 public:
904  Environment<int>* m_environment;
905  MapFunc* m_mapFunc;
906  ExecPlan m_execPlan;
907 
908  struct starpu_codelet *singleBuffCodelet;
909  struct starpu_codelet *doubleBuffCodelet;
910  struct starpu_codelet *tripleBuffCodelet;
911  struct starpu_codelet *fourBuffCodelet;
912 
913 #ifdef USE_STARPU_HISTORY_MODEL
914  starpu_perfmodel *map1_perf_model;
915  starpu_perfmodel *map2_perf_model;
916  starpu_perfmodel *map3_perf_model;
917  starpu_perfmodel *map4_perf_model;
918 #endif
919 
920 
921 public:
922  void operator()(Matrix<T>& input1, Matrix<T>& input2, Matrix<T>& input3, Matrix<T>& output);
923 
924  void operator()(Matrix<T>& input1, Matrix<T>& input2, Matrix<T>& input3, Matrix<T>& output, int parts);
925 
926 
927 public:
928  static void cpu_func(void *buffers[], void *arg);
929 
930 #ifdef SKEPU_OPENMP
931 public:
932  static void omp_func(void *buffer[], void *arg);
933 #endif
934 
935 #ifdef SKEPU_CUDA
936 public:
937  static void cuda_func(void *buffer[], void *arg);
938 #endif
939 
940 #ifdef SKEPU_OPENCL
941 public:
942  static void opencl_func(void *buffer[], void *arg);
943 
944 public:
945  struct starpu_opencl_program opencl_codelet;
946  char kernelNameArray[1024];
947 
948  void replaceText(std::string& text, std::string find, std::string replace);
949  void createOpenCLProgram();
950 #endif
951 
952 private:
953  std::string perfmodel1_str;
954  std::string perfmodel2_str;
955  std::string perfmodel3_str;
956  std::string perfmodel4_str;
957 
958  Matrix<T> *input1;
959  Matrix<T> *input2;
960  Matrix<T> *input3;
961 
962  Matrix<T> *output;
963 
964  int parts;
965 
966 };
967 
968 
969 
970 
971 
972 
973 
974 
975 
976 
977 
978 
979 
980 //#########
981 //#########
982 //#########
983 //#########
984 //#########
985 //#########
986 //#########
987 //#########
988 
989 
1008 template <typename MapFunc, typename T>
1009 class Map<MapFunc, T, UNARY, SPARSE_MATRIX>: public Task
1010 {
1011 
1012 typedef struct
1013 {
1014  Map<MapFunc, T, UNARY, SPARSE_MATRIX> *pMap;
1015  typename MapFunc::CONST_TYPE constant;
1016  bool parts;
1017  bool unaryOperand;
1018 }ArgumentBuffer;
1019 
1020 public:
1021 
1022  Map(MapFunc* mapFunc);
1023 
1024  Map(MapFunc* mapFunc, SparseMatrix<T> *input, SparseMatrix<T> *output, int parts=1);
1025 
1026 
1027  ~Map();
1028 
1029 
1030  SparseMatrix<T>& getOutput()
1031  {
1032  return *output;
1033  }
1034 
1035  void *get_result()
1036  {
1037  return output;
1038  }
1039 
1040 
1041  void setInput(SparseMatrix<T> *in)
1042  {
1043  input = in;
1044  }
1045 
1046  void setOutput(SparseMatrix<T> *out)
1047  {
1048  output = out;
1049  }
1050 
1051  void setPartitions(int _parts)
1052  {
1053  parts = _parts;
1054  }
1055 
1056 
1057  void run_async();
1058 
1062  template <typename U>
1063  void setConstant(U constant1) { m_mapFunc->setConstant(constant1); }
1064 
1068  void finishAll() {m_environment->finishAll();}
1069  void setExecPlan(ExecPlan& plan) {m_execPlan = plan;}
1070 
1071 public:
1072  Environment<int>* m_environment;
1073  MapFunc* m_mapFunc;
1074  ExecPlan m_execPlan;
1075 
1076 #ifdef USE_STARPU_HISTORY_MODEL
1077  starpu_perfmodel *map1_perf_model;
1078  starpu_perfmodel *map2_perf_model;
1079 #endif
1080 
1081  struct starpu_codelet *sameIOCodelet;
1082  struct starpu_codelet *diffIOCodelet;
1083 
1084  bool unaryOperand;
1085 
1086 public:
1087  void operator()(SparseMatrix<T>& input);
1088 
1089  void operator()(SparseMatrix<T>& input, SparseMatrix<T>& output); // , unsigned int *tagId=0
1090 
1091  void operator()(SparseMatrix<T>& input, int parts);
1092 
1093  void operator()(SparseMatrix<T>& input, SparseMatrix<T>& output, int parts);
1094 
1095 public:
1096  static void cpu_func(void *buffers[], void *arg);
1097 
1098 #ifdef SKEPU_OPENMP
1099 public:
1100  static void omp_func(void *buffer[], void *arg);
1101 #endif
1102 
1103 #ifdef SKEPU_CUDA
1104 public:
1105  static void cuda_func(void *buffer[], void *arg);
1106 #endif
1107 
1108 #ifdef SKEPU_OPENCL
1109 public:
1110  static void opencl_func(void *buffer[], void *arg);
1111 
1112 public:
1113  struct starpu_opencl_program opencl_codelet;
1114  char kernelNameArray[1024];
1115 
1116  void replaceText(std::string& text, std::string find, std::string replace);
1117  void createOpenCLProgram();
1118 #endif
1119 
1120 private:
1121  std::string perfmodel1_str;
1122  std::string perfmodel2_str;
1123 
1124  SparseMatrix<T> *input;
1125 
1126  SparseMatrix<T> *output;
1127 
1128  int parts;
1129 
1130 
1131 };
1132 
1133 
1151 template <typename MapFunc, typename T>
1152 class Map<MapFunc, T, BINARY, SPARSE_MATRIX>: public Task
1153 {
1154 
1155 typedef struct
1156 {
1157  Map<MapFunc, T, BINARY, SPARSE_MATRIX> *pMap;
1158  typename MapFunc::CONST_TYPE constant;
1159  bool parts;
1160  int bufferIndex[3];
1161 }ArgumentBuffer;
1162 
1163 
1164 public:
1165  int bufferIndex[3];
1166 
1167  Map(MapFunc* mapFunc);
1168 
1169  Map(MapFunc* mapFunc, SparseMatrix<T> *in1, SparseMatrix<T> *in2, SparseMatrix<T> *out, int _parts=1);
1170 
1171 
1172  SparseMatrix<T>& getOutput()
1173  {
1174  return *output;
1175  }
1176 
1177  void *get_result()
1178  {
1179  return output;
1180  }
1181 
1182  void setInput1(SparseMatrix<T> *in)
1183  {
1184  input1 = in;
1185  }
1186 
1187  void setInput2(SparseMatrix<T> *in)
1188  {
1189  input2 = in;
1190  }
1191 
1192  void setOutput(SparseMatrix<T> *out)
1193  {
1194  output = out;
1195  }
1196 
1197  void setPartitions(int _parts)
1198  {
1199  parts = _parts;
1200  }
1201 
1202  void run_async();
1203 
1204 
1205  ~Map();
1206 
1210  template <typename U>
1211  void setConstant(U constant1) {m_mapFunc->setConstant(constant1);}
1212 
1216  void finishAll() {m_environment->finishAll();}
1217  void setExecPlan(ExecPlan& plan) {m_execPlan = plan;}
1218 
1219 public:
1220  Environment<int>* m_environment;
1221  MapFunc* m_mapFunc;
1222  ExecPlan m_execPlan;
1223 
1224  struct starpu_codelet *singleBuffCodelet;
1225  struct starpu_codelet *doubleBuffCodelet;
1226  struct starpu_codelet *tripleBuffCodelet;
1227 
1228 #ifdef USE_STARPU_HISTORY_MODEL
1229  starpu_perfmodel *map1_perf_model;
1230  starpu_perfmodel *map2_perf_model;
1231  starpu_perfmodel *map3_perf_model;
1232 #endif
1233 
1234 public:
1235  void operator()(SparseMatrix<T>& input1, SparseMatrix<T>& input2, SparseMatrix<T>& output);
1236 
1237  void operator()(SparseMatrix<T>& input1, SparseMatrix<T>& input2, SparseMatrix<T>& output, int xparts);
1238 
1239 public:
1240  static void cpu_func(void *buffers[], void *arg);
1241 
1242 #ifdef SKEPU_OPENMP
1243 public:
1244  static void omp_func(void *buffer[], void *arg);
1245 #endif
1246 
1247 #ifdef SKEPU_CUDA
1248 public:
1249  static void cuda_func(void *buffer[], void *arg);
1250 #endif
1251 
1252 #ifdef SKEPU_OPENCL
1253 public:
1254  static void opencl_func(void *buffer[], void *arg);
1255 
1256 public:
1257  struct starpu_opencl_program opencl_codelet;
1258  char kernelNameArray[1024];
1259 
1260  void replaceText(std::string& text, std::string find, std::string replace);
1261  void createOpenCLProgram();
1262 #endif
1263 
1264 private:
1265  std::string perfmodel1_str;
1266  std::string perfmodel2_str;
1267  std::string perfmodel3_str;
1268 
1269  SparseMatrix<T> *input1;
1270  SparseMatrix<T> *input2;
1271 
1272  SparseMatrix<T> *output;
1273 
1274  int parts;
1275 };
1276 
1277 
1278 
1279 
1280 
1281 
1282 
1283 
1302 template <typename MapFunc, typename T>
1303 class Map<MapFunc, T, TERNARY, SPARSE_MATRIX>: public Task
1304 {
1305 
1306 typedef struct
1307 {
1308  Map<MapFunc, T, TERNARY, SPARSE_MATRIX> *pMap;
1309  typename MapFunc::CONST_TYPE constant;
1310  bool parts;
1311  int bufferIndex[4];
1312 }ArgumentBuffer;
1313 
1314 public:
1315  int bufferIndex[4];
1316 
1317  Map(MapFunc* mapFunc);
1318 
1319  Map(MapFunc* mapFunc, SparseMatrix<T> *in1, SparseMatrix<T> *in2, SparseMatrix<T> *in3, SparseMatrix<T> *out, int parts=1);
1320 
1321  ~Map();
1322 
1323 
1324  SparseMatrix<T>& getOutput()
1325  {
1326  return *output;
1327  }
1328 
1329  void *get_result()
1330  {
1331  return output;
1332  }
1333 
1334  void setInput1(SparseMatrix<T> *in)
1335  {
1336  input1 = in;
1337  }
1338 
1339  void setInput2(SparseMatrix<T> *in)
1340  {
1341  input2 = in;
1342  }
1343 
1344  void setInput3(SparseMatrix<T> *in)
1345  {
1346  input3 = in;
1347  }
1348 
1349  void setOutput(SparseMatrix<T> *out)
1350  {
1351  output = out;
1352  }
1353 
1354  void setPartitions(int _parts)
1355  {
1356  parts = _parts;
1357  }
1358 
1359  void run_async();
1360 
1361 
1365  template <typename U>
1366  void setConstant(U constant1) {m_mapFunc->setConstant(constant1);}
1367 
1371  void finishAll() {m_environment->finishAll();}
1372  void setExecPlan(ExecPlan& plan) {m_execPlan = plan;}
1373 
1374 public:
1375  Environment<int>* m_environment;
1376  MapFunc* m_mapFunc;
1377  ExecPlan m_execPlan;
1378 
1379  struct starpu_codelet *singleBuffCodelet;
1380  struct starpu_codelet *doubleBuffCodelet;
1381  struct starpu_codelet *tripleBuffCodelet;
1382  struct starpu_codelet *fourBuffCodelet;
1383 
1384 #ifdef USE_STARPU_HISTORY_MODEL
1385  starpu_perfmodel *map1_perf_model;
1386  starpu_perfmodel *map2_perf_model;
1387  starpu_perfmodel *map3_perf_model;
1388  starpu_perfmodel *map4_perf_model;
1389 #endif
1390 
1391 
1392 public:
1393  void operator()(SparseMatrix<T>& input1, SparseMatrix<T>& input2, SparseMatrix<T>& input3, SparseMatrix<T>& output);
1394 
1395  void operator()(SparseMatrix<T>& input1, SparseMatrix<T>& input2, SparseMatrix<T>& input3, SparseMatrix<T>& output, int parts);
1396 
1397 
1398 public:
1399  static void cpu_func(void *buffers[], void *arg);
1400 
1401 #ifdef SKEPU_OPENMP
1402 public:
1403  static void omp_func(void *buffer[], void *arg);
1404 #endif
1405 
1406 #ifdef SKEPU_CUDA
1407 public:
1408  static void cuda_func(void *buffer[], void *arg);
1409 #endif
1410 
1411 #ifdef SKEPU_OPENCL
1412 public:
1413  static void opencl_func(void *buffer[], void *arg);
1414 
1415 public:
1416  struct starpu_opencl_program opencl_codelet;
1417  char kernelNameArray[1024];
1418 
1419  void replaceText(std::string& text, std::string find, std::string replace);
1420  void createOpenCLProgram();
1421 #endif
1422 
1423 private:
1424  std::string perfmodel1_str;
1425  std::string perfmodel2_str;
1426  std::string perfmodel3_str;
1427  std::string perfmodel4_str;
1428 
1429  SparseMatrix<T> *input1;
1430  SparseMatrix<T> *input2;
1431  SparseMatrix<T> *input3;
1432 
1433  SparseMatrix<T> *output;
1434 
1435  int parts;
1436 
1437 };
1438 
1439 
1440 
1441 }
1442 
1443 #include "src/map.inl"
1444 #include "src/map_matrix.inl"
1445 #include "src/map_sparse_matrix.inl"
1446 
1447 #include "src/map_cpu.inl"
1448 #include "src/map_cpu_matrix.inl"
1450 
1451 #ifdef SKEPU_OPENMP
1452 #include "src/map_omp.inl"
1453 #include "src/map_omp_matrix.inl"
1455 #endif
1456 
1457 #ifdef SKEPU_OPENCL
1458 #include "src/map_cl.inl"
1459 #include "src/map_cl_matrix.inl"
1461 #endif
1462 
1463 #ifdef SKEPU_CUDA
1464 #include "src/map_cu.inl"
1465 #include "src/map_cu_matrix.inl"
1467 #endif
1468 
1469 #endif
1470 
void operator()(Vector< T > &input)
Definition: map.inl:291
Contains the definitions of CPU specific functions for the Map skeleton for vector operands...
void createOpenCLProgram()
Definition: map_cl.inl:50
Contains the definitions of OpenCL specific functions for the Map skeleton for sparse-matrix operands...
Defines a few macros that can be used to output text when debugging. The macros use std::cerr...
Contains the definitions of CUDA specific member functions for the Map skeleton for sparse-matrix ope...
Contains a class declaration for the SparseMatrix container.
static void cuda_func(void *buffer[], void *arg)
Definition: map_cu.inl:31
Contains the definitions of OpenCL specific functions for the Map skeleton for matrix operands...
static void omp_func(void *buffer[], void *arg)
Definition: map_omp.inl:25
void finishAll()
Definition: map.h:124
Includes the macro files needed for the defined backends.
~Map()
Definition: map.inl:227
Contains the definitions of CPU specific functions for the Map skeleton for matrix operands...
void finishAll()
Definition: environment.inl:119
Contains the definitions of OpenCL specific functions for the Map skeleton for vector operands...
Contains the definitions of non-backend specific member functions for the Map skeleton for sparse mat...
Map(MapFunc *mapFunc)
Definition: map.inl:18
Contains the definitions of non-backend specific member functions for the Map skeleton for vector ope...
Contains a class declaration for the object that represents an OpenCL device.
Contains the definitions of OpenMP specific member functions for the Map skeleton for vector operands...
Contains the definitions of non-backend specific member functions for the Map skeleton for dense matr...
Contains the definitions of OpenMP specific member functions for the Map skeleton for sparse-matrix o...
Contains the definitions of CUDA specific member functions for the Map skeleton for matrix operands...
A vector container class, implemented as a wrapper for std::vector. It is configured to use StarPU DS...
Definition: vector.h:40
void replaceText(std::string &text, std::string find, std::string replace)
Definition: map_cl.inl:28
void run_async()
Definition: map.inl:252
static void cpu_func(void *buffers[], void *arg)
Definition: map_cpu.inl:23
Contains the definitions of OpenMP specific member functions for the Map skeleton for matrix operands...
Contains the definitions of CUDA specific member functions for the Map skeleton for vector operands...
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 the definitions of CPU specific functions for the Map skeleton for SparseMatrix operands...
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.
static void opencl_func(void *buffer[], void *arg)
Definition: map_cl.inl:114
A class representing the Map skeleton.
Definition: map.h:65
void setConstant(U constant1)
Definition: map.h:119
Contains a class that stores information about which back ends to use when executing.