SkePU  1.2
 All Classes Namespaces Files Functions Variables 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 #ifdef SKEPU_OPENCL
9 #include <string>
10 #include <vector>
11 #ifdef USE_MAC_OPENCL
12 #include <OpenCL/opencl.h>
13 #else
14 #include <CL/cl.h>
15 #endif
16 #include "src/device_cl.h"
17 #endif
18 
19 #include "src/environment.h"
20 
21 #include "skepu/vector.h"
22 #include "skepu/matrix.h"
23 #include "skepu/sparse_matrix.h"
24 
25 #include "src/operator_macros.h"
26 #include "src/exec_plan.h"
27 
28 namespace skepu
29 {
30 
51 template <typename MapFunc>
52 class Map
53 {
54 
55 public:
56 
57  Map(MapFunc* mapFunc);
58 
59  ~Map();
60 
64  template <typename U>
65  void setConstant(U constant1)
66  {
67  m_mapFunc->setConstant(constant1);
68  }
69 
73  void finishAll()
74  {
75  m_environment->finishAll();
76  }
77 
78  void setExecPlan(ExecPlan& plan)
79  {
80  m_execPlan = &plan;
81  }
82  void setExecPlan(ExecPlan *plan)
83  {
84  m_execPlanMulti = plan;
85  }
86 
87 private:
88  Environment<int>* m_environment;
89  MapFunc* m_mapFunc;
90 
92  ExecPlan *m_execPlanMulti;
93 
95  ExecPlan *m_execPlan;
96 
98  ExecPlan m_defPlan;
99 
100 public:
101  template <typename T>
102  void operator()(Vector<T>& input);
103 
104  template <typename T>
105  void operator()(Vector<T>& input, Vector<T>& output, int groupId = -1);
106 
107  template <typename T>
108  void operator()(Matrix<T>& input);
109 
110  template <typename T>
111  void operator()(Matrix<T>& input, Matrix<T>& output);
112 
113  template <typename InputIterator>
114  void operator()(InputIterator inputBegin, InputIterator inputEnd);
115 
116  template <typename InputIterator, typename OutputIterator>
117  void operator()(InputIterator inputBegin, InputIterator inputEnd, OutputIterator outputBegin);
118 
119  template <typename T>
120  void operator()(Vector<T>& input1, Vector<T>& input2, Vector<T>& output);
121 
122  template <typename T>
123  void operator()(Matrix<T>& input1, Matrix<T>& input2, Matrix<T>& output);
124 
125  template <typename Input1Iterator, typename Input2Iterator, typename OutputIterator>
126  void operator()(Input1Iterator input1Begin, Input1Iterator input1End, Input2Iterator input2Begin, Input2Iterator input2End, OutputIterator outputBegin);
127 
128  template <typename T>
129  void operator()(Vector<T>& input1, Vector<T>& input2, Vector<T>& input3, Vector<T>& output);
130 
131  template <typename T>
132  void operator()(Matrix<T>& input1, Matrix<T>& input2, Matrix<T>& input3, Matrix<T>& output);
133 
134  template <typename Input1Iterator, typename Input2Iterator, typename Input3Iterator, typename OutputIterator>
135  void operator()(Input1Iterator input1Begin, Input1Iterator input1End, Input2Iterator input2Begin, Input2Iterator input2End, Input3Iterator input3Begin, Input3Iterator input3End, OutputIterator outputBegin);
136 
137  template <typename T>
138  void operator()(SparseMatrix<T>& input);
139 
140  template <typename T>
141  void operator()(SparseMatrix<T>& input, SparseMatrix<T>& output);
142 
143  template <typename T>
144  void operator()(SparseMatrix<T>& input1, SparseMatrix<T>& input2, SparseMatrix<T>& output);
145 
146  template <typename T>
147  void operator()(SparseMatrix<T>& input1, SparseMatrix<T>& input2, SparseMatrix<T>& input3, SparseMatrix<T>& output);
148 
149 
150 public:
151  template <typename T>
152  void CPU(Vector<T>& input);
153 
154  template <typename T>
155  void CPU(Vector<T>& input, Vector<T>& output);
156 
157  template <typename T>
158  void CPU(Matrix<T>& input);
159 
160  template <typename T>
161  void CPU(Matrix<T>& input, Matrix<T>& output);
162 
163  template <typename InputIterator>
164  void CPU(InputIterator inputBegin, InputIterator inputEnd);
165 
166  template <typename InputIterator, typename OutputIterator>
167  void CPU(InputIterator inputBegin, InputIterator inputEnd, OutputIterator outputBegin);
168 
169  template <typename T>
170  void CPU(Vector<T>& input1, Vector<T>& input2, Vector<T>& output);
171 
172  template <typename T>
173  void CPU(Matrix<T>& input1, Matrix<T>& input2, Matrix<T>& output);
174 
175  template <typename Input1Iterator, typename Input2Iterator, typename OutputIterator>
176  void CPU(Input1Iterator input1Begin, Input1Iterator input1End, Input2Iterator input2Begin, Input2Iterator input2End, OutputIterator outputBegin);
177 
178  template <typename T>
179  void CPU(Vector<T>& input1, Vector<T>& input2, Vector<T>& input3, Vector<T>& output);
180 
181  template <typename T>
182  void CPU(Matrix<T>& input1, Matrix<T>& input2, Matrix<T>& input3, Matrix<T>& output);
183 
184  template <typename Input1Iterator, typename Input2Iterator, typename Input3Iterator, typename OutputIterator>
185  void CPU(Input1Iterator input1Begin, Input1Iterator input1End, Input2Iterator input2Begin, Input2Iterator input2End, Input3Iterator input3Begin, Input3Iterator input3End, OutputIterator outputBegin);
186 
187  template <typename T>
188  void CPU(SparseMatrix<T>& input);
189 
190  template <typename T>
191  void CPU(SparseMatrix<T>& input, SparseMatrix<T>& output);
192 
193  template <typename T>
194  void CPU(SparseMatrix<T>& input1, SparseMatrix<T>& input2, SparseMatrix<T>& output);
195 
196  template <typename T>
197  void CPU(SparseMatrix<T>& input1, SparseMatrix<T>& input2, SparseMatrix<T>& input3, SparseMatrix<T>& output);
198 
199 #ifdef SKEPU_OPENMP
200 public:
201  template <typename T>
202  void OMP(Vector<T>& input);
203 
204  template <typename T>
205  void OMP(Vector<T>& input, Vector<T>& output);
206 
207  template <typename T>
208  void OMP(Matrix<T>& input);
209 
210  template <typename T>
211  void OMP(Matrix<T>& input, Matrix<T>& output);
212 
213  template <typename InputIterator>
214  void OMP(InputIterator inputBegin, InputIterator inputEnd);
215 
216  template <typename InputIterator, typename OutputIterator>
217  void OMP(InputIterator inputBegin, InputIterator inputEnd, OutputIterator outputBegin);
218 
219  template <typename T>
220  void OMP(Vector<T>& input1, Vector<T>& input2, Vector<T>& output);
221 
222  template <typename T>
223  void OMP(Matrix<T>& input1, Matrix<T>& input2, Matrix<T>& output);
224 
225  template <typename Input1Iterator, typename Input2Iterator, typename OutputIterator>
226  void OMP(Input1Iterator input1Begin, Input1Iterator input1End, Input2Iterator input2Begin, Input2Iterator input2End, OutputIterator outputBegin);
227 
228  template <typename T>
229  void OMP(Vector<T>& input1, Vector<T>& input2, Vector<T>& input3, Vector<T>& output);
230 
231  template <typename T>
232  void OMP(Matrix<T>& input1, Matrix<T>& input2, Matrix<T>& input3, Matrix<T>& output);
233 
234  template <typename Input1Iterator, typename Input2Iterator, typename Input3Iterator, typename OutputIterator>
235  void OMP(Input1Iterator input1Begin, Input1Iterator input1End, Input2Iterator input2Begin, Input2Iterator input2End, Input3Iterator input3Begin, Input3Iterator input3End, OutputIterator outputBegin);
236 
237  template <typename T>
238  void OMP(SparseMatrix<T>& input);
239 
240  template <typename T>
241  void OMP(SparseMatrix<T>& input, SparseMatrix<T>& output);
242 
243  template <typename T>
244  void OMP(SparseMatrix<T>& input1, SparseMatrix<T>& input2, SparseMatrix<T>& output);
245 
246  template <typename T>
247  void OMP(SparseMatrix<T>& input1, SparseMatrix<T>& input2, SparseMatrix<T>& input3, SparseMatrix<T>& output);
248 #endif
249 
250 #ifdef SKEPU_CUDA
251 public:
252  template <typename T>
253  void CU(Vector<T>& input, int useNumGPU = 1);
254 
255  template <typename T>
256  void CU(Vector<T>& input, Vector<T>& output, int useNumGPU = 1);
257 
258  template <typename T>
259  void CU(Matrix<T>& input, int useNumGPU = 1);
260 
261  template <typename T>
262  void CU(Matrix<T>& input, Matrix<T>& output, int useNumGPU = 1);
263 
264  template <typename InputIterator>
265  void CU(InputIterator inputBegin, InputIterator inputEnd, int useNumGPU = 1);
266 
267  template <typename InputIterator, typename OutputIterator>
268  void CU(InputIterator inputBegin, InputIterator inputEnd, OutputIterator outputBegin, int useNumGPU = 1);
269 
270  template <typename InputIterator, typename OutputIterator>
271  void CU_2(InputIterator inputBegin, InputIterator inputEnd, OutputIterator outputBegin, int useNumGPU = 1);
272 
273  template <typename T>
274  void CU(Vector<T>& input1, Vector<T>& input2, Vector<T>& output, int useNumGPU = 1);
275 
276  template <typename T>
277  void CU(Matrix<T>& input1, Matrix<T>& input2, Matrix<T>& output, int useNumGPU = 1);
278 
279  template <typename Input1Iterator, typename Input2Iterator, typename OutputIterator>
280  void CU(Input1Iterator input1Begin, Input1Iterator input1End, Input2Iterator input2Begin, Input2Iterator input2End, OutputIterator outputBegin, int useNumGPU = 1);
281 
282  template <typename T>
283  void CU(Vector<T>& input1, Vector<T>& input2, Vector<T>& input3, Vector<T>& output, int useNumGPU = 1);
284 
285  template <typename T>
286  void CU(Matrix<T>& input1, Matrix<T>& input2, Matrix<T>& input3, Matrix<T>& output, int useNumGPU = 1);
287 
288  template <typename Input1Iterator, typename Input2Iterator, typename Input3Iterator, typename OutputIterator>
289  void CU(Input1Iterator input1Begin, Input1Iterator input1End, Input2Iterator input2Begin, Input2Iterator input2End, Input3Iterator input3Begin, Input3Iterator input3End, OutputIterator outputBegin, int useNumGPU = 1);
290 
291  template <typename T>
292  void CU(SparseMatrix<T>& input, int useNumGPU = 1);
293 
294  template <typename T>
295  void CU(SparseMatrix<T>& input, SparseMatrix<T>& output, int useNumGPU = 1);
296 
297  template <typename T>
298  void CU(SparseMatrix<T>& input1, SparseMatrix<T>& input2, SparseMatrix<T>& output, int useNumGPU = 1);
299 
300  template <typename T>
301  void CU(SparseMatrix<T>& input1, SparseMatrix<T>& input2, SparseMatrix<T>& input3, SparseMatrix<T>& output, int useNumGPU = 1);
302 
303 private:
304  unsigned int cudaDeviceID;
305 
306  template <typename T>
307  void mapSingleThread_CU(SparseMatrix<T> &input, SparseMatrix<T> &output, unsigned int deviceID);
308 
309  template <typename T>
310  void mapSingleThread_CU(SparseMatrix<T> &input1, SparseMatrix<T> &input2, SparseMatrix<T> &output, unsigned int deviceID);
311 
312  template <typename T>
313  void mapSingleThread_CU(SparseMatrix<T> &input1, SparseMatrix<T> &input2, SparseMatrix<T> &input3, SparseMatrix<T> &output, unsigned int deviceID);
314 
315  template <typename InputIterator, typename OutputIterator>
316  void mapSingleThread_CU(InputIterator inputBegin, InputIterator inputEnd, OutputIterator outputBegin, unsigned int deviceID);
317 
318  template <typename Input1Iterator, typename Input2Iterator, typename OutputIterator>
319  void mapSingleThread_CU(Input1Iterator input1Begin, Input1Iterator input1End, Input2Iterator input2Begin, Input2Iterator input2End, OutputIterator outputBegin, unsigned int deviceID);
320 
321  template <typename Input1Iterator, typename Input2Iterator, typename Input3Iterator, typename OutputIterator>
322  void mapSingleThread_CU(Input1Iterator input1Begin, Input1Iterator input1End, Input2Iterator input2Begin, Input2Iterator input2End, Input3Iterator input3Begin, Input3Iterator input3End, OutputIterator outputBegin, unsigned int deviceID);
323 
324  //MultiStream skeleton implementation headers
325  template <typename InputIterator, typename OutputIterator>
326  void mapMultiStream_CU(InputIterator inputBegin, InputIterator inputEnd, OutputIterator outputBegin, unsigned int deviceID);
327 
328  template <typename Input1Iterator, typename Input2Iterator, typename OutputIterator>
329  void mapMultiStream_CU(Input1Iterator input1Begin, Input1Iterator input1End, Input2Iterator input2Begin, Input2Iterator input2End, OutputIterator outputBegin, unsigned int deviceID);
330 
331  template <typename Input1Iterator, typename Input2Iterator, typename Input3Iterator, typename OutputIterator>
332  void mapMultiStream_CU(Input1Iterator input1Begin, Input1Iterator input1End, Input2Iterator input2Begin, Input2Iterator input2End, Input3Iterator input3Begin, Input3Iterator input3End, OutputIterator outputBegin, unsigned int deviceID);
333 
334  template <typename InputIterator, typename OutputIterator>
335  void mapMultiStreamMultiGPU_CU(InputIterator inputBegin, InputIterator inputEnd, OutputIterator outputBegin, int useNumGPU);
336 
337  template <typename Input1Iterator, typename Input2Iterator, typename OutputIterator>
338  void mapMultiStreamMultiGPU_CU(Input1Iterator input1Begin, Input1Iterator input1End, Input2Iterator input2Begin, Input2Iterator input2End, OutputIterator outputBegin, int useNumGPU);
339 
340  template <typename Input1Iterator, typename Input2Iterator, typename Input3Iterator, typename OutputIterator>
341  void mapMultiStreamMultiGPU_CU(Input1Iterator input1Begin, Input1Iterator input1End, Input2Iterator input2Begin, Input2Iterator input2End, Input3Iterator input3Begin, Input3Iterator input3End, OutputIterator outputBegin, int useNumGPU);
342 
343 #endif
344 
345 #ifdef SKEPU_OPENCL
346 public:
347  template <typename T>
348  void CL(Vector<T>& input, int useNumGPU = 1);
349 
350  template <typename T>
351  void CL(Vector<T>& input, Vector<T>& output, int useNumGPU = 1);
352 
353  template <typename T>
354  void CL(Matrix<T>& input, int useNumGPU = 1);
355 
356  template <typename T>
357  void CL(Matrix<T>& input, Matrix<T>& output, int useNumGPU = 1);
358 
359  template <typename InputIterator>
360  void CL(InputIterator inputBegin, InputIterator inputEnd, int useNumGPU = 1);
361 
362  template <typename InputIterator, typename OutputIterator>
363  void CL(InputIterator inputBegin, InputIterator inputEnd, OutputIterator outputBegin, int useNumGPU = 1);
364 
365  template <typename T>
366  void CL(Vector<T>& input1, Vector<T>& input2, Vector<T>& output, int useNumGPU = 1);
367 
368  template <typename T>
369  void CL(Matrix<T>& input1, Matrix<T>& input2, Matrix<T>& output, int useNumGPU = 1);
370 
371  template <typename Input1Iterator, typename Input2Iterator, typename OutputIterator>
372  void CL(Input1Iterator input1Begin, Input1Iterator input1End, Input2Iterator input2Begin, Input2Iterator input2End, OutputIterator outputBegin, int useNumGPU = 1);
373 
374  template <typename T>
375  void CL(Vector<T>& input1, Vector<T>& input2, Vector<T>& input3, Vector<T>& output, int useNumGPU = 1);
376 
377  template <typename T>
378  void CL(Matrix<T>& input1, Matrix<T>& input2, Matrix<T>& input3, Matrix<T>& output, int useNumGPU = 1);
379 
380  template <typename Input1Iterator, typename Input2Iterator, typename Input3Iterator, typename OutputIterator>
381  void CL(Input1Iterator input1Begin, Input1Iterator input1End, Input2Iterator input2Begin, Input2Iterator input2End, Input3Iterator input3Begin, Input3Iterator input3End, OutputIterator outputBegin, int useNumGPU = 1);
382 
383  template <typename T>
384  void CL(SparseMatrix<T>& input, int useNumGPU = 1);
385 
386  template <typename T>
387  void CL(SparseMatrix<T>& input, SparseMatrix<T>& output, int useNumGPU = 1);
388 
389  template <typename T>
390  void CL(SparseMatrix<T>& input1, SparseMatrix<T>& input2, SparseMatrix<T>& output, int useNumGPU = 1);
391 
392  template <typename T>
393  void CL(SparseMatrix<T>& input1, SparseMatrix<T>& input2, SparseMatrix<T>& input3, SparseMatrix<T>& output, int useNumGPU = 1);
394 
395 private:
396  template <typename InputIterator, typename OutputIterator>
397  void mapNumDevices_CL(InputIterator inputBegin, InputIterator inputEnd, OutputIterator outputBegin, size_t numDevices);
398 
399  template <typename Input1Iterator, typename Input2Iterator, typename OutputIterator>
400  void mapNumDevices_CL(Input1Iterator input1Begin, Input1Iterator input1End, Input2Iterator input2Begin, Input2Iterator input2End, OutputIterator outputBegin, size_t numDevices);
401 
402  template <typename Input1Iterator, typename Input2Iterator, typename Input3Iterator, typename OutputIterator>
403  void mapNumDevices_CL(Input1Iterator input1Begin, Input1Iterator input1End, Input2Iterator input2Begin, Input2Iterator input2End, Input3Iterator input3Begin, Input3Iterator input3End, OutputIterator outputBegin, size_t numDevices);
404 
405 private:
406  std::vector<std::pair<cl_kernel, Device_CL*> > m_kernels_CL;
407 
408  void createOpenCLProgram();
409 #endif
410 
411 };
412 
413 }
414 
415 #include "src/map.inl"
416 
417 #include "src/map_sparse.inl"
418 
419 #include "src/map_cpu.inl"
420 
421 #ifdef SKEPU_OPENMP
422 #include "src/map_omp.inl"
423 #endif
424 
425 #ifdef SKEPU_OPENCL
426 #include "src/map_cl.inl"
427 #endif
428 
429 #ifdef SKEPU_CUDA
430 #include "src/map_cu.inl"
431 #endif
432 
433 #endif
434 
435 
Contains the definitions of CPU specific member functions for the Map skeleton.
void CPU(Vector< T > &input)
Definition: map_cpu.inl:21
void setConstant(U constant1)
Definition: map.h:65
Contains the definitions of map methods for sparse matrices. All (CPU, OpenMP, CUDA,OpenCL) in one file.
Contains a class declaration for the SparseMatrix container.
Includes the macro files needed for the defined backends.
void finishAll()
Definition: environment.inl:575
Contains the definitions of OpenCL specific member functions for the Map skeleton.
void operator()(Vector< T > &input)
Definition: map.inl:100
Contains the definitions of non-backend specific member functions for the Map skeleton.
~Map()
Definition: map.inl:82
Map(MapFunc *mapFunc)
Definition: map.inl:20
Contains a class declaration for the object that represents an OpenCL device.
Contains the definitions of OpenMP specific member functions for the Map skeleton.
Contains a class declaration for the Matrix container.
Contains the definitions of CUDA specific member functions for the Map skeleton.
A class that describes an execution plan.
Definition: exec_plan.h:47
Contains a class declaration for the Vector container.
void finishAll()
Definition: map.h:73
Contains a class declaration for Environment class.
A class representing the column-wise iterator for the Matrix data-type.
void OMP(Vector< T > &input)
Definition: map_omp.inl:24
A class representing the Map skeleton.
Definition: map.h:52
void CU(Vector< T > &input, int useNumGPU=1)
Definition: map_cu.inl:418
void CL(Vector< T > &input, int useNumGPU=1)
Definition: map_cl.inl:234
Contains a class that stores information about which back ends to use when executing.