SkePU  1.2
 All Classes Namespaces Files Functions Variables 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 #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 
31 
32 /*
33  MultiVector struct definition
34 */
35 #define subvector( mv, i, type ) ((type)(mv).device_arr[i].device_el)
36 
37 struct Arr
38 {
39  void *host_el;
40  size_t size;
41  void *device_el;
42 };
43 
44 struct MultiVector
45 {
46  Arr *host_arr;
47  size_t size;
48  Arr *device_arr;
49 
50  Arr * allocData(int numinputs)
51  {
52  Arr *data = (Arr *) malloc(numinputs*sizeof(Arr));
53  host_arr = data;
54  size = numinputs;
55  return data;
56  }
57  void addData(int index, size_t size, void * data)
58  {
59  host_arr[index].host_el = data;
60  host_arr[index].size = size;
61  }
62  void freeData()
63  {
64  free(host_arr);
65  }
66 
67 };
68 
93 template <typename MapArrayFunc>
94 class MapArray
95 {
96 
97 public:
98 
99  MapArray(MapArrayFunc* mapArrayFunc);
100 
101  ~MapArray();
102 
106  template <typename U>
107  void setConstant(U constant1)
108  {
109  m_mapArrayFunc->setConstant(constant1);
110  }
111 
112  void finishAll()
113  {
114  m_environment->finishAll();
115  }
116 
117  void setExecPlan(ExecPlan& plan)
118  {
119  m_execPlan = &plan;
120  }
121  void setExecPlan(ExecPlan *plan)
122  {
123  m_execPlanMulti = plan;
124  }
125 
126 private:
127  Environment<int>* m_environment;
128  MapArrayFunc* m_mapArrayFunc;
129 
131  ExecPlan *m_execPlanMulti;
132 
134  ExecPlan *m_execPlan;
135 
137  ExecPlan m_defPlan;
138 
139 public:
140  template <typename T>
141  void operator()(Vector<T>& input1, Vector<T>& input2, Vector<T>& output, int groupId = -1);
142 
143  template <typename T>
144  void operator()(Vector<T>& input1, Matrix<T>& input2, Matrix<T>& output);
145 
146  template <typename T>
147  void operator()(Vector<T>& input1, Matrix<T>& input2, Vector<T>& output);
148 
149  template <typename T>
150  void operator()(Vector<T>& input1, SparseMatrix<T>& input2, Vector<T>& output);
151 
152  template <typename Input1Iterator, typename Input2Iterator, typename OutputIterator>
153  void operator()(Input1Iterator input1Begin, Input1Iterator input1End, Input2Iterator input2Begin, Input2Iterator input2End, OutputIterator outputBegin);
154 
155  template <typename in, typename out>
156  void operator()(Vector<in>& input, MultiVector P, Vector<out>& output);
157 
158  template<typename InputIterator, typename OutputIterator>
159  void operator()(InputIterator inputBegin, InputIterator inputEnd, MultiVector P, OutputIterator outputbegin);
160 
161 
162 public:
163  template <typename in, typename out>
164  void CPU(Vector<in>& input, MultiVector P, Vector<out>& output);
165 
166  template <typename T>
167  void CPU(Vector<T>& input1, Vector<T>& input2, Vector<T>& output);
168 
169  template <typename T>
170  void CPU(Vector<T>& input1, Matrix<T>& input2, Matrix<T>& output);
171 
172  template <typename T>
173  void CPU(Vector<T>& input1, Matrix<T>& input2, Vector<T>& output);
174 
175  template <typename T>
176  void CPU(Vector<T>& input1, SparseMatrix<T>& input2, Vector<T>& output);
177 
178  template <typename Input1Iterator, typename Input2Iterator, typename OutputIterator>
179  void CPU(Input1Iterator input1Begin, Input1Iterator input1End, Input2Iterator input2Begin, Input2Iterator input2End, OutputIterator outputBegin);
180 
181 #ifdef SKEPU_OPENMP
182 public:
183  template <typename in, typename out>
184  void OMP(Vector<in>& input, MultiVector P, Vector<out>& output);
185 
186  template<typename InputIterator, typename OutputIterator>
187  void OMP(InputIterator inputBegin, InputIterator inputEnd, MultiVector P, OutputIterator outputbegin);
188 
189  template <typename T>
190  void OMP(Vector<T>& input1, Vector<T>& input2, Vector<T>& output);
191 
192  template <typename T>
193  void OMP(Vector<T>& input1, Matrix<T>& input2, Matrix<T>& output);
194 
195  template <typename T>
196  void OMP(Vector<T>& input1, Matrix<T>& input2, Vector<T>& output);
197 
198  template <typename T>
199  void OMP(Vector<T>& input1, SparseMatrix<T>& input2, Vector<T>& output);
200 
201  template <typename Input1Iterator, typename Input2Iterator, typename OutputIterator>
202  void OMP(Input1Iterator input1Begin, Input1Iterator input1End, Input2Iterator input2Begin, Input2Iterator input2End, OutputIterator outputBegin);
203 #endif
204 
205 #ifdef SKEPU_CUDA
206 public:
207  template <typename in, typename out>
208  void CU(Vector<in>& input, MultiVector P, Vector<out>& output, int useNumGPU = 1);
209 
210  template<typename InputIterator, typename OutputIterator>
211  void CU(InputIterator inputBegin, InputIterator inputEnd, MultiVector P, OutputIterator outputbegin, int useNumGPU = 1);
212 
213  template <typename T>
214  void CU(Vector<T>& input1, Vector<T>& input2, Vector<T>& output, int useNumGPU = 1);
215 
216  template <typename T>
217  void CU(Vector<T>& input1, Matrix<T>& input2, Matrix<T>& output, int useNumGPU = 1);
218 
219  template <typename T>
220  void CU(Vector<T>& input1, Matrix<T>& input2, Vector<T>& output, int useNumGPU = 1);
221 
222  template <typename T>
223  void CU(Vector<T>& input1, SparseMatrix<T>& input2, Vector<T>& output, int useNumGPU = 1);
224 
225  template <typename Input1Iterator, typename Input2Iterator, typename OutputIterator>
226  void CU(Input1Iterator input1Begin, Input1Iterator input1End, Input2Iterator input2Begin, Input2Iterator input2End, OutputIterator outputBegin, int useNumGPU = 1);
227 
228 private:
229  unsigned int cudaDeviceID;
230 
231  template <typename Input1Iterator, typename Input2Iterator, typename OutputIterator>
232  void mapArraySingleThread_CU(Input1Iterator input1Begin, Input1Iterator input1End, Input2Iterator input2Begin, Input2Iterator input2End, OutputIterator outputBegin, unsigned int deviceID);
233 
234  template <typename Input1Iterator, typename Input2Iterator, typename OutputIterator>
235  void mapArrayMultiStream_CU(Input1Iterator input1Begin, Input1Iterator input1End, Input2Iterator input2Begin, Input2Iterator input2End, OutputIterator outputBegin, unsigned int deviceID);
236 
237  template <typename Input1Iterator, typename Input2Iterator, typename OutputIterator>
238  void mapArrayMultiStreamMultiGPU_CU(Input1Iterator input1Begin, Input1Iterator input1End, Input2Iterator input2Begin, Input2Iterator input2End, OutputIterator outputBegin, int useNumGPU);
239 #endif
240 
241 #ifdef SKEPU_OPENCL
242 public:
243  template <typename in, typename out>
244  void CL(Vector<in>& input, MultiVector P, Vector<out>& output, int useNumGPU = 1);
245 
246  template <typename T>
247  void CL(Vector<T>& input1, Vector<T>& input2, Vector<T>& output, int useNumGPU = 1);
248 
249  template <typename T>
250  void CL(Vector<T>& input1, Matrix<T>& input2, Matrix<T>& output, int useNumGPU = 1);
251 
252  template <typename T>
253  void CL(Vector<T>& input1, Matrix<T>& input2, Vector<T>& output, int useNumGPU = 1);
254 
255  template <typename T>
256  void CL(Vector<T>& input1, SparseMatrix<T>& input2, Vector<T>& output, int useNumGPU = 1);
257 
258  template <typename Input1Iterator, typename Input2Iterator, typename OutputIterator>
259  void CL(Input1Iterator input1Begin, Input1Iterator input1End, Input2Iterator input2Begin, Input2Iterator input2End, OutputIterator outputBegin, int useNumGPU = 1);
260 
261 private:
262  template <typename Input1Iterator, typename Input2Iterator, typename OutputIterator>
263  void mapArrayNumDevices_CL(Input1Iterator input1Begin, Input1Iterator input1End, Input2Iterator input2Begin, Input2Iterator input2End, OutputIterator outputBegin, size_t numDevices);
264 
265 private:
266  std::vector<std::pair<cl_kernel, Device_CL*> > m_kernels_CL;
267 
268  void createOpenCLProgram();
269 
270 #endif
271 
272 };
273 
274 
275 }
276 
277 #include "src/maparray.inl"
278 
279 #include "src/maparray_cpu.inl"
280 
281 #ifdef SKEPU_OPENMP
282 #include "src/maparray_omp.inl"
283 #endif
284 
285 #ifdef SKEPU_OPENCL
286 #include "src/maparray_cl.inl"
287 #endif
288 
289 #ifdef SKEPU_CUDA
290 #include "src/maparray_cu.inl"
291 #endif
292 
293 #endif
294 
295 
Contains the definitions of CUDA specific member 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:94
Includes the macro files needed for the defined backends.
void CU(Vector< in > &input, MultiVector P, Vector< out > &output, int useNumGPU=1)
Definition: maparray_cu.inl:155
MapArray(MapArrayFunc *mapArrayFunc)
Definition: maparray.inl:21
void OMP(Vector< in > &input, MultiVector P, Vector< out > &output)
Definition: maparray_omp.inl:54
void CPU(Vector< in > &input, MultiVector P, Vector< out > &output)
Definition: maparray_cpu.inl:21
void finishAll()
Definition: environment.inl:575
Contains the definitions of OpenCL specific member functions for the MapArray skeleton.
Contains the definitions of CPU specific member functions for the MapArray skeleton.
void operator()(Vector< T > &input1, Vector< T > &input2, Vector< T > &output, int groupId=-1)
Definition: maparray.inl:102
Contains a class declaration for the object that represents an OpenCL device.
Contains a class declaration for the Matrix container.
Contains a class declaration for the Vector container.
Contains a class declaration for Environment class.
A class representing the column-wise iterator for the Matrix data-type.
~MapArray()
Definition: maparray.inl:83
void setConstant(U constant1)
Definition: maparray.h:107
Contains the definitions of OpenMP specific member functions for the MapArray skeleton.
Contains a class that stores information about which back ends to use when executing.