SkePU  1.2
 All Classes Namespaces Files Functions Variables Enumerations Friends Macros Groups Pages
scan.h
Go to the documentation of this file.
1 
5 #ifndef SCAN_H
6 #define SCAN_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 
36 {
37  INCLUSIVE,
38  EXCLUSIVE
39 };
40 
67 template <typename ScanFunc>
68 class Scan
69 {
70 
71 public:
72 
73  Scan(ScanFunc* scanFunc);
74 
75  ~Scan();
76 
77  void finishAll()
78  {
79  m_environment->finishAll();
80  }
81  void setExecPlan(ExecPlan& plan)
82  {
83  m_execPlan = &plan;
84  }
85  void setExecPlan(ExecPlan *plan)
86  {
87  m_execPlanMulti = plan;
88  }
89 
90 private:
91  Environment<int>* m_environment;
92  ScanFunc* m_scanFunc;
93 
95  ExecPlan *m_execPlanMulti;
96 
98  ExecPlan *m_execPlan;
99 
101  ExecPlan m_defPlan;
102 
103 public:
104  template <typename T>
105  void operator()(Vector<T>& input, ScanType type, T init = T());
106 
107  template <typename T>
108  void operator()(Matrix<T>& input, ScanType type, T init = T());
109 
110  template <typename InputIterator>
111  void operator()(InputIterator inputBegin, InputIterator inputEnd, ScanType type, typename InputIterator::value_type init = typename InputIterator::value_type());
112 
113  template <typename T>
114  void operator()(Vector<T>& input, Vector<T>& output, ScanType type, T init = T());
115 
116  template <typename T>
117  void operator()(Matrix<T>& input, Matrix<T>& output, ScanType type, T init = T());
118 
119  template <typename InputIterator, typename OutputIterator>
120  void operator()(InputIterator inputBegin, InputIterator inputEnd, OutputIterator outputBegin, ScanType type, typename InputIterator::value_type init = typename InputIterator::value_type());
121 
122 public:
123  template <typename T>
124  void CPU(Vector<T>& input, ScanType type = INCLUSIVE, T init = T());
125 
126  template <typename T>
127  void CPU(Matrix<T>& input, ScanType type, T init = T());
128 
129  template <typename InputIterator>
130  void CPU(InputIterator inputBegin, InputIterator inputEnd, ScanType type = INCLUSIVE, typename InputIterator::value_type init = typename InputIterator::value_type());
131 
132  template <typename T>
133  void CPU(Vector<T>& input, Vector<T>& output, ScanType type = INCLUSIVE, T init = T());
134 
135  template <typename T>
136  void CPU(Matrix<T>& input, Matrix<T>& output, ScanType type, T init = T());
137 
138  template <typename InputIterator, typename OutputIterator>
139  void CPU(InputIterator inputBegin, InputIterator inputEnd, OutputIterator outputBegin, ScanType type = INCLUSIVE, typename InputIterator::value_type init = typename InputIterator::value_type());
140 
141 #ifdef SKEPU_OPENMP
142 public:
143  template <typename T>
144  void OMP(Vector<T>& input, ScanType type = INCLUSIVE, T init = T());
145 
146  template <typename T>
147  void OMP(Matrix<T>& input, ScanType type, T init = T());
148 
149  template <typename InputIterator>
150  void OMP(InputIterator inputBegin, InputIterator inputEnd, ScanType type = INCLUSIVE, typename InputIterator::value_type init = typename InputIterator::value_type());
151 
152  template <typename T>
153  void OMP(Vector<T>& input, Vector<T>& output, ScanType type = INCLUSIVE, T init = T());
154 
155  template <typename T>
156  void OMP(Matrix<T>& input, Matrix<T>& output, ScanType type, T init = T());
157 
158  template <typename InputIterator, typename OutputIterator>
159  void OMP(InputIterator inputBegin, InputIterator inputEnd, OutputIterator outputBegin, ScanType type = INCLUSIVE, typename InputIterator::value_type init = typename InputIterator::value_type());
160 #endif
161 
162 #ifdef SKEPU_CUDA
163 public:
164  template <typename T>
165  void CU(Vector<T>& input, ScanType type = INCLUSIVE, T init = T(), int useNumGPU = 1);
166 
167 // template <typename T>
168 // void CU(Matrix<T>& input, ScanType type, T init = T(), int useNumGPU = 1);
169 
170  template <typename InputIterator>
171  void CU(InputIterator inputBegin, InputIterator inputEnd, ScanType type = INCLUSIVE, typename InputIterator::value_type init = typename InputIterator::value_type(), int useNumGPU = 1);
172 
173  template <typename T>
174  void CU(Vector<T>& input, Vector<T>& output, ScanType type = INCLUSIVE, T init = T(), int useNumGPU = 1);
175 
176 // template <typename T>
177 // void CU(Matrix<T>& input, Matrix<T>& output, ScanType type, T init = T(), int useNumGPU = 1);
178 
179  template <typename InputIterator, typename OutputIterator>
180  void CU(InputIterator inputBegin, InputIterator inputEnd, OutputIterator outputBegin, ScanType type = INCLUSIVE, typename InputIterator::value_type init = typename InputIterator::value_type(), int useNumGPU = 1);
181 
182 private:
183  unsigned int cudaDeviceID;
184 
185  template <typename InputIterator, typename OutputIterator>
186  void scanSingleThread_CU(InputIterator inputBegin, InputIterator inputEnd, OutputIterator outputBegin, ScanType type, typename InputIterator::value_type init, unsigned int deviceID);
187 
188  template <typename T>
189  T scanLargeVectorRecursively_CU(DeviceMemPointer_CU<T>* input, DeviceMemPointer_CU<T>* output, std::vector<DeviceMemPointer_CU<T>*>& blockSums, size_t numElements, unsigned int level, ScanType type, T init, unsigned int deviceID);
190 
191 #endif
192 
193 #ifdef SKEPU_OPENCL
194 public:
195  template <typename T>
196  void CL(Vector<T>& input, ScanType type = INCLUSIVE, T init = T(), int useNumGPU = 1);
197 
198 // template <typename T>
199 // void CL(Matrix<T>& input, ScanType type, T init = T(), int useNumGPU = 1);
200 
201  template <typename InputIterator>
202  void CL(InputIterator inputBegin, InputIterator inputEnd, ScanType type = INCLUSIVE, typename InputIterator::value_type init = typename InputIterator::value_type(), int useNumGPU = 1);
203 
204  template <typename T>
205  void CL(Vector<T>& input, Vector<T>& output, ScanType type = INCLUSIVE, T init = T(), int useNumGPU = 1);
206 
207 // template <typename T>
208 // void CL(Matrix<T>& input, Matrix<T>& output, ScanType type, T init = T(), int useNumGPU = 1);
209 
210  template <typename InputIterator, typename OutputIterator>
211  void CL(InputIterator inputBegin, InputIterator inputEnd, OutputIterator outputBegin, ScanType type = INCLUSIVE, typename InputIterator::value_type init = typename InputIterator::value_type(), int useNumGPU = 1);
212 
213 private:
214  template <typename InputIterator, typename OutputIterator>
215  void scanSingle_CL(InputIterator inputBegin, InputIterator inputEnd, OutputIterator outputBegin, ScanType type, typename InputIterator::value_type init, unsigned int deviceID);
216 
217  template <typename InputIterator, typename OutputIterator>
218  void scanNumDevices_CL(InputIterator inputBegin, InputIterator inputEnd, OutputIterator outputBegin, ScanType type, typename InputIterator::value_type init, size_t numDevices);
219 
220  template <typename T>
221  T scanLargeVectorRecursively_CL(DeviceMemPointer_CL<T>* input, DeviceMemPointer_CL<T>* output, std::vector<DeviceMemPointer_CL<T>*>& blockSums, size_t numElements, unsigned int level, ScanType type, T init, unsigned int deviceID);
222 
223 private:
224  std::vector<std::pair<cl_kernel, Device_CL*> > m_scanKernels_CL;
225  std::vector<std::pair<cl_kernel, Device_CL*> > m_scanUpdateKernels_CL;
226  std::vector<std::pair<cl_kernel, Device_CL*> > m_scanAddKernels_CL;
227 
228  void createOpenCLProgram();
229 #endif
230 
231 };
232 
233 }
234 
235 #include "src/scan.inl"
236 
237 #include "src/scan_cpu.inl"
238 
239 #ifdef SKEPU_OPENMP
240 #include "src/scan_omp.inl"
241 #endif
242 
243 #ifdef SKEPU_OPENCL
244 #include "src/scan_cl.inl"
245 #endif
246 
247 #ifdef SKEPU_CUDA
248 #include "src/scan_cu.inl"
249 #endif
250 
251 #endif
252 
253 
void CL(Vector< T > &input, ScanType type=INCLUSIVE, T init=T(), int useNumGPU=1)
Definition: scan_cl.inl:435
void OMP(Vector< T > &input, ScanType type=INCLUSIVE, T init=T())
Definition: scan_omp.inl:26
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 Scan skeleton.
A class representing an OpenCL device memory allocation for container.
Definition: device_mem_pointer_cl.h:38
~Scan()
Definition: scan.inl:88
Contains a class declaration for the object that represents an OpenCL device.
Scan(ScanFunc *scanFunc)
Definition: scan.inl:21
Contains the definitions of OpenMP specific member functions for the Scan skeleton.
Contains the definitions of non-backend specific member functions for the Scan skeleton.
void CPU(Vector< T > &input, ScanType type=INCLUSIVE, T init=T())
Definition: scan_cpu.inl:23
Contains a class declaration for the Matrix container.
A vector container class, implemented as a wrapper for std::vector.
Definition: vector.h:61
A class that describes an execution plan.
Definition: exec_plan.h:47
void operator()(Vector< T > &input, ScanType type, T init=T())
Definition: scan.inl:107
A class representing a CUDA device memory allocation for container.
Definition: device_mem_pointer_cu.h:58
Contains a class declaration for the Vector container.
Contains a class declaration for Environment class.
void CU(Vector< T > &input, ScanType type=INCLUSIVE, T init=T(), int useNumGPU=1)
Definition: scan_cu.inl:213
Contains the definitions of CUDA specific member functions for the Scan skeleton. ...
A class representing the column-wise iterator for the Matrix data-type.
A class representing the Scan skeleton.
Definition: scan.h:68
Contains a class that stores information about which back ends to use when executing.
Contains the definitions of CPU specific member functions for the Scan skeleton.
ScanType
Definition: scan.h:35