Image Component Library (ICL)
CLKernel.h
Go to the documentation of this file.
1 /********************************************************************
2  ** Image Component Library (ICL) **
3  ** **
4  ** Copyright (C) 2006-2013 CITEC, University of Bielefeld **
5  ** Neuroinformatics Group **
6  ** Website: www.iclcv.org and **
7  ** http://opensource.cit-ec.de/projects/icl **
8  ** **
9  ** File : ICLUtils/src/ICLUtils/CLKernel.h **
10  ** Module : ICLUtils **
11  ** Authors: Viktor Losing **
12  ** **
13  ** **
14  ** GNU LESSER GENERAL PUBLIC LICENSE **
15  ** This file may be used under the terms of the GNU Lesser General **
16  ** Public License version 3.0 as published by the **
17  ** **
18  ** Free Software Foundation and appearing in the file LICENSE.GPL **
19  ** included in the packaging of this file. Please review the **
20  ** following information to ensure the license requirements will **
21  ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt **
22  ** **
23  ** The development of this software was supported by the **
24  ** Excellence Cluster EXC 277 Cognitive Interaction Technology. **
25  ** The Excellence Cluster EXC 277 is a grant of the Deutsche **
26  ** Forschungsgemeinschaft (DFG) in the context of the German **
27  ** Excellence Initiative. **
28  ** **
29  ********************************************************************/
30 
31 #pragma once
32 
33 #ifdef ICL_HAVE_OPENCL
34 
35 #include <ICLUtils/CompatMacros.h>
36 #include <ICLUtils/CLBuffer.h>
37 #include <ICLUtils/CLImage2D.h>
38 #include <ICLUtils/CLException.h>
39 #include <ICLUtils/FixedArray.h>
40 #include <string>
41 
43 namespace cl{
44  class CommandQueue;
45  class Program;
46 }
49 namespace icl {
50  namespace utils {
52 
73  struct Impl;
74  Impl *impl;
75 
77  CLKernel(const string &id, cl::Program & program,
78  cl::CommandQueue& cmdQueue) ;
79 
80  public:
81 
83  struct LocalMemory {
84  size_t size;
85 
87  LocalMemory(size_t size) : size(size) { }
88  };
89 
91  CLKernel();
92 
94  CLKernel(const CLKernel &other);
95 
97  CLKernel const& operator=(CLKernel const& other);
98 
100  ~CLKernel();
101 
103 
104  void apply(int gloW, int gloH = 0, int gloC = 0,
105  int locW = 0, int locH = 0, int locC = 0) ;
106 
108  void finish() ;
109 
111  friend class CLProgram;
112  friend class CLDeviceContext;
113 
115  void setArg(const unsigned idx, const unsigned int &value) ;
116 
118  void setArg(const unsigned idx, const int &value) ;
119 
121  void setArg(const unsigned idx, const short &value) ;
122 
124  void setArg(const unsigned idx, const long &value) ;
125 
127  void setArg(const unsigned idx, const unsigned long &value) ;
128 
130  void setArg(const unsigned idx, const float &value) ;
131 
133  void setArg(const unsigned idx, const double &value) ;
134 
136  void setArg(const unsigned idx, const char &value) ;
137 
139  void setArg(const unsigned idx, const unsigned char &value) ;
140 
142  void setArg(const unsigned idx, const FixedArray<float,4> &value) ;
143 
145  void setArg(const unsigned idx, const FixedArray<float,3> &value) ;
146 
148  void setArg(const unsigned idx, const CLBuffer &value) ;
149 
151  void setArg(const unsigned idx, const CLImage2D &value) ;
152 
154  void setArg(const unsigned idx, const LocalMemory &value) ;
155 
157  template<typename A>
158  void setArgs(const A &value) {
159  setArg(0, value);
160  }
161 
163  template<typename A, typename B>
164  void setArgs(const A &valueA, const B &valueB) {
165  setArgs(valueA);
166  setArg(1, valueB);
167  }
168 
170  template<typename A, typename B, typename C>
171  void setArgs(const A &valueA, const B &valueB, const C &valueC) {
172  setArgs(valueA, valueB);
173  setArg(2, valueC);
174  }
175 
177  template<typename A, typename B, typename C, typename D>
178  void setArgs(const A &valueA, const B &valueB, const C &valueC, const D &valueD) {
179  setArgs(valueA, valueB, valueC);
180  setArg(3, valueD);
181  }
182 
184  template<typename A, typename B, typename C, typename D, typename E>
185  void setArgs(const A &valueA, const B &valueB, const C &valueC, const D &valueD,
186  const E &valueE) {
187  setArgs(valueA, valueB, valueC, valueD);
188  setArg(4, valueE);
189  }
190 
192  template<typename A, typename B, typename C, typename D, typename E, typename F>
193  void setArgs(const A &valueA, const B &valueB, const C &valueC, const D &valueD,
194  const E &valueE, const F &valueF) {
195  setArgs(valueA, valueB, valueC, valueD, valueE);
196  setArg(5, valueF);
197  }
198 
200  template<typename A, typename B, typename C, typename D, typename E, typename F,
201  typename G>
202  void setArgs(const A &valueA, const B &valueB, const C &valueC, const D &valueD,
203  const E &valueE, const F &valueF, const G &valueG)
204  {
205  setArgs(valueA, valueB, valueC, valueD, valueE, valueF);
206  setArg(6, valueG);
207  }
208 
210  template<typename A, typename B, typename C, typename D, typename E, typename F,
211  typename G, typename H>
212  void setArgs(const A &valueA, const B &valueB, const C &valueC, const D &valueD,
213  const E &valueE, const F &valueF, const G &valueG, const H &valueH)
214  {
215  setArgs(valueA, valueB, valueC, valueD, valueE, valueF, valueG);
216  setArg(7, valueH);
217  }
218 
220  template<typename A, typename B, typename C, typename D, typename E, typename F,
221  typename G, typename H, typename I>
222  void setArgs(const A &valueA, const B &valueB, const C &valueC, const D &valueD,
223  const E &valueE, const F &valueF, const G &valueG, const H &valueH,
224  const I &valueI) {
225  setArgs(valueA, valueB, valueC, valueD, valueE, valueF, valueG, valueH);
226  setArg(8, valueI);
227  }
228 
230  template<typename A, typename B, typename C, typename D, typename E, typename F,
231  typename G, typename H, typename I, typename J>
232  void setArgs(const A &valueA, const B &valueB, const C &valueC, const D &valueD,
233  const E &valueE, const F &valueF, const G &valueG, const H &valueH,
234  const I &valueI, const J &valueJ) {
235  setArgs(valueA, valueB, valueC, valueD, valueE, valueF, valueG, valueH, valueI);
236  setArg(9, valueJ);
237  }
238 
240  template<typename A, typename B, typename C, typename D, typename E, typename F,
241  typename G, typename H, typename I, typename J, typename K>
242  void setArgs(const A &valueA, const B &valueB, const C &valueC, const D &valueD,
243  const E &valueE, const F &valueF, const G &valueG, const H &valueH,
244  const I &valueI, const J &valueJ, const K &valueK)
245  {
246  setArgs(valueA, valueB, valueC, valueD, valueE, valueF, valueG, valueH, valueI,
247  valueJ);
248  setArg(10, valueK);
249  }
251  template<typename A, typename B, typename C, typename D, typename E, typename F,
252  typename G, typename H, typename I, typename J, typename K, typename L>
253  void setArgs(const A &valueA, const B &valueB, const C &valueC, const D &valueD,
254  const E &valueE, const F &valueF, const G &valueG, const H &valueH,
255  const I &valueI, const J &valueJ, const K &valueK, const L &valueL)
256  {
257  setArgs(valueA, valueB, valueC, valueD, valueE, valueF, valueG, valueH, valueI,
258  valueJ, valueK);
259  setArg(11, valueL);
260  }
261 
263  template<typename A, typename B, typename C, typename D, typename E, typename F,
264  typename G, typename H, typename I, typename J, typename K, typename L,
265  typename M>
266  void setArgs(const A &valueA, const B &valueB, const C &valueC, const D &valueD,
267  const E &valueE, const F &valueF, const G &valueG, const H &valueH,
268  const I &valueI, const J &valueJ, const K &valueK, const L &valueL,
269  const M &valueM) {
270  setArgs(valueA, valueB, valueC, valueD, valueE, valueF, valueG, valueH, valueI,
271  valueJ, valueK, valueL);
272  setArg(12, valueM);
273  }
274 
276  template<typename A, typename B, typename C, typename D, typename E, typename F,
277  typename G, typename H, typename I, typename J, typename K, typename L,
278  typename M, typename N>
279  void setArgs(const A &valueA, const B &valueB, const C &valueC, const D &valueD,
280  const E &valueE, const F &valueF, const G &valueG, const H &valueH,
281  const I &valueI, const J &valueJ, const K &valueK, const L &valueL,
282  const M &valueM, const N &valueN) {
283  setArgs(valueA, valueB, valueC, valueD, valueE, valueF, valueG, valueH, valueI,
284  valueJ, valueK, valueL, valueM);
285  setArg(13, valueN);
286  }
287 
289  template<typename A, typename B, typename C, typename D, typename E, typename F,
290  typename G, typename H, typename I, typename J, typename K, typename L,
291  typename M, typename N, typename O>
292  void setArgs(const A &valueA, const B &valueB, const C &valueC, const D &valueD,
293  const E &valueE, const F &valueF, const G &valueG, const H &valueH,
294  const I &valueI, const J &valueJ, const K &valueK, const L &valueL,
295  const M &valueM, const N &valueN, const O &valueO)
296  {
297  setArgs(valueA, valueB, valueC, valueD, valueE, valueF, valueG, valueH, valueI,
298  valueJ, valueK, valueL, valueM, valueN);
299  setArg(14, valueO);
300  }
301 
303  template<typename A, typename B, typename C, typename D, typename E, typename F,
304  typename G, typename H, typename I, typename J, typename K, typename L,
305  typename M, typename N, typename O, typename P>
306  void setArgs(const A &valueA, const B &valueB, const C &valueC, const D &valueD,
307  const E &valueE, const F &valueF, const G &valueG, const H &valueH,
308  const I &valueI, const J &valueJ, const K &valueK, const L &valueL,
309  const M &valueM, const N &valueN, const O &valueO, const P &valueP)
310  {
311  setArgs(valueA, valueB, valueC, valueD, valueE, valueF, valueG, valueH, valueI,
312  valueJ, valueK, valueL, valueM, valueN, valueP);
313  setArg(15, valueP);
314  }
315 
317  template<typename A, typename B, typename C, typename D, typename E, typename F,
318  typename G, typename H, typename I, typename J, typename K, typename L,
319  typename M, typename N, typename O, typename P, typename Q>
320  void setArgs(const A &valueA, const B &valueB, const C &valueC, const D &valueD,
321  const E &valueE, const F &valueF, const G &valueG, const H &valueH,
322  const I &valueI, const J &valueJ, const K &valueK, const L &valueL,
323  const M &valueM, const N &valueN, const O &valueO, const P &valueP,
324  const Q &valueQ)
325  {
326  setArgs(valueA, valueB, valueC, valueD, valueE, valueF, valueG, valueH, valueI,
327  valueJ, valueK, valueL, valueM, valueN, valueP, valueQ);
328  setArg(16, valueQ);
329  }
330 
332  struct Arg {
334  int idx;
335 
337  Arg(CLKernel &k, int idx):k(k),idx(idx) {}
338 
340  template<class T>
341  inline void operator=(const T &t) {
342  k.setArg(idx,t);
343  }
344  };
345 
347  inline Arg operator[](int idx) { return Arg(*this,idx); }
348 
349  };
350  }
351 }
352 
353 #endif
void setArgs(const A &valueA, const B &valueB, const C &valueC, const D &valueD, const E &valueE, const F &valueF, const G &valueG, const H &valueH, const I &valueI, const J &valueJ)
sets mutiple kernel arguments at once
Definition: CLKernel.h:232
void setArgs(const A &valueA, const B &valueB, const C &valueC, const D &valueD, const E &valueE, const F &valueF, const G &valueG, const H &valueH, const I &valueI)
sets mutiple kernel arguments at once
Definition: CLKernel.h:222
undocument this line if you encounter any issues!
Definition: Any.h:37
LocalMemory(size_t size)
constructor
Definition: CLKernel.h:87
Definition: CLDeviceContext.h:43
Fixed C++-array wrapper class for data handling.
Definition: FixedArray.h:45
#define ICLUtils_API
this macros are important for creating dll's
Definition: CompatMacros.h:171
Arg operator[](int idx)
for index operator-based setting of kernel arguments
Definition: CLKernel.h:347
Wrapper for an OpenCL Kernel.
Definition: CLKernel.h:72
int idx
Argument index.
Definition: CLKernel.h:334
void operator=(const T &t)
template-based assigment (calls the parent kernel's setArg method)
Definition: CLKernel.h:341
void setArgs(const A &valueA, const B &valueB, const C &valueC, const D &valueD, const E &valueE, const F &valueF, const G &valueG, const H &valueH, const I &valueI, const J &valueJ, const K &valueK, const L &valueL, const M &valueM, const N &valueN, const O &valueO, const P &valueP, const Q &valueQ)
sets mutiple kernel arguments at once
Definition: CLKernel.h:320
size_t size
size of the dynamic local memory
Definition: CLKernel.h:84
void setArgs(const A &valueA, const B &valueB)
sets mutiple kernel arguments at once
Definition: CLKernel.h:164
Wrapper for an OpenCL Buffer.
Definition: CLBuffer.h:52
void setArgs(const A &valueA, const B &valueB, const C &valueC, const D &valueD, const E &valueE, const F &valueF, const G &valueG)
sets mutiple kernel arguments at once
Definition: CLKernel.h:202
void setArgs(const A &valueA, const B &valueB, const C &valueC, const D &valueD, const E &valueE, const F &valueF, const G &valueG, const H &valueH, const I &valueI, const J &valueJ, const K &valueK, const L &valueL, const M &valueM, const N &valueN, const O &valueO)
sets mutiple kernel arguments at once
Definition: CLKernel.h:292
CLKernel & k
parent CLKernel
Definition: CLKernel.h:333
struct that represents the dynamic local memory for a kernel
Definition: CLKernel.h:83
void setArgs(const A &value)
sets mutiple kernel arguments at once
Definition: CLKernel.h:158
void setArgs(const A &valueA, const B &valueB, const C &valueC, const D &valueD, const E &valueE, const F &valueF, const G &valueG, const H &valueH)
sets mutiple kernel arguments at once
Definition: CLKernel.h:212
void setArgs(const A &valueA, const B &valueB, const C &valueC, const D &valueD, const E &valueE, const F &valueF, const G &valueG, const H &valueH, const I &valueI, const J &valueJ, const K &valueK, const L &valueL, const M &valueM, const N &valueN, const O &valueO, const P &valueP)
sets mutiple kernel arguments at once
Definition: CLKernel.h:306
void setArgs(const A &valueA, const B &valueB, const C &valueC, const D &valueD, const E &valueE, const F &valueF, const G &valueG, const H &valueH, const I &valueI, const J &valueJ, const K &valueK, const L &valueL, const M &valueM, const N &valueN)
sets mutiple kernel arguments at once
Definition: CLKernel.h:279
Utility structure for the CLKernel's index operator.
Definition: CLKernel.h:332
void setArgs(const A &valueA, const B &valueB, const C &valueC, const D &valueD, const E &valueE, const F &valueF, const G &valueG, const H &valueH, const I &valueI, const J &valueJ, const K &valueK)
sets mutiple kernel arguments at once
Definition: CLKernel.h:242
The CLDeviceContext class allows preparation of the device used for CLPrograms.
Definition: CLDeviceContext.h:61
void setArgs(const A &valueA, const B &valueB, const C &valueC, const D &valueD, const E &valueE, const F &valueF, const G &valueG, const H &valueH, const I &valueI, const J &valueJ, const K &valueK, const L &valueL)
sets mutiple kernel arguments at once
Definition: CLKernel.h:253
Wrapper for an OpenCL Image2D.
Definition: CLImage2D.h:57
Impl * impl
internal implementation
Definition: CLKernel.h:73
void setArgs(const A &valueA, const B &valueB, const C &valueC, const D &valueD)
sets mutiple kernel arguments at once
Definition: CLKernel.h:178
void setArgs(const A &valueA, const B &valueB, const C &valueC)
sets mutiple kernel arguments at once
Definition: CLKernel.h:171
void setArgs(const A &valueA, const B &valueB, const C &valueC, const D &valueD, const E &valueE, const F &valueF, const G &valueG, const H &valueH, const I &valueI, const J &valueJ, const K &valueK, const L &valueL, const M &valueM)
sets mutiple kernel arguments at once
Definition: CLKernel.h:266
void setArgs(const A &valueA, const B &valueB, const C &valueC, const D &valueD, const E &valueE)
sets mutiple kernel arguments at once
Definition: CLKernel.h:185
void setArg(const unsigned idx, const unsigned int &value)
Overloaded Kernel argument setter for unsigned int values.
void setArgs(const A &valueA, const B &valueB, const C &valueC, const D &valueD, const E &valueE, const F &valueF)
sets mutiple kernel arguments at once
Definition: CLKernel.h:193
Main class for OpenCL based accelleration.
Definition: CLProgram.h:259
Arg(CLKernel &k, int idx)
constructor
Definition: CLKernel.h:337