Blink API
Blink.h
Go to the documentation of this file.
1 // Copyright (c) 2013 The Foundry Visionmongers Ltd. All Rights Reserved.
2 
7 #ifndef Blink_Library_Blink_h
8 #define Blink_Library_Blink_h
9 
10 #include "BlinkBuild.h"
11 #include <string>
12 #include <vector>
13 
14 #include "BlinkTypes.h"
15 #include "BlinkConstants.h"
16 #include "BlinkVersion.h"
17 
18 namespace Blink
19 {
20 
21  typedef BlinkComputeDeviceID ComputeDeviceID;
22  typedef BlinkCodegenFlags CodegenFlags;
23  typedef BlinkDataType DataType;
24  typedef BlinkRef Ref;
25  typedef BlinkErrorCode ErrorCode;
26  typedef BlinkErrorRef ErrorRef;
27  typedef BlinkMemoryType MemoryType;
28 
29  typedef BlinkKernelType KernelType;
30  typedef BlinkKernelGranularity KernelGranularity;
31  typedef BlinkImageAccessType ImageAccessType;
32  typedef BlinkImagePatternType ImagePatternType;
33  typedef BlinkImageEdgeType ImageEdgeType;
34 
39  {
40  DeviceMemory() {}
41  DeviceMemory(const DeviceMemory& memory);
42  DeviceMemory(MemoryType type, void* memoryBasePtr, unsigned long long memoryBaseSize, unsigned long long offset);
43  };
44 
45  class RefHolder
46  {
47  public:
48  RefHolder();
49 
50  RefHolder(Ref ref, bool retain);
51  RefHolder(const RefHolder& holder);
52 
53  RefHolder& operator=(const RefHolder& holder);
54  void take(Ref ref);
55 
56  RefHolder& operator=(Ref ref);
57 
58  Ref ref() const;
59 
60  ~RefHolder();
61 
62  protected:
63  Ref _ref;
64  };
65 
66 
68  class ComputeDevice: protected RefHolder
69  {
70  public:
71  ComputeDevice(const ComputeDevice& dev);
72 
75 
78 
80  static ComputeDevice DeviceWithID(ComputeDeviceID id);
81 
83  bool available() const;
84 
86  std::string name() const;
87 
88  private:
89  ComputeDevice(Ref deviceRef);
90 
91  friend class ComputeDeviceBinder;
92  friend class Image;
93  friend class Kernel;
94  };
95 
101  {
102  public:
104  };
105 
109  class ProgramSource: protected RefHolder
110  {
111  public:
112  ProgramSource(const char* source);
113  ProgramSource(const std::string& source);
114  ProgramSource(const ProgramSource& foo);
115 
116  private:
117  void setSource(const char* source);
118  friend class IKernel;
119  friend class Kernel;
120  };
121 
127  struct Rect: BlinkRect
128  {
129 
130  Rect();
131 
132  Rect(const Rect& r);
133 
135  Rect(int x1, int y1, int x2, int y2);
136 
137  int width() const;
138  int height() const;
139  };
140 
145  {
146 
147  KernelIterationController(const KernelIterationController& iterationController);
150  };
151 
157  {
158 
159  BufferDesc();
160 
162  BufferDesc(unsigned int pixelStepBytes,
163  unsigned int rowStepBytes,
164  unsigned int componentStepBytes);
165  };
166 
171  {
172 
173  PixelInfo();
175  PixelInfo(int nComponents, DataType dataType);
176  };
177 
182  {
183 
184  ImageInfo();
185 
186  ImageInfo(const ImageInfo& info);
187 
189  ImageInfo(const Rect& bounds, const PixelInfo& pixelInfo);
190 
191  Rect bounds() const;
192  };
193 
195  {
196  ImageAccessDesc(void) {}
197  ImageAccessDesc(BlinkImagePatternType type);
198  ImageAccessDesc(BlinkAxisType axis, int min, int max);
199  ImageAccessDesc(Rect Range);
200  };
201 
203  class Image: protected RefHolder
204  {
205  public:
207  Image();
208 
210  Image(const Image& src);
211 
212 
213  Image(const ImageInfo& info, ComputeDevice& device);
214 
215 
216  Image(const DeviceMemory& memory, const ImageInfo& info, const BufferDesc& desc, ComputeDevice& device);
217 
218  Image& operator=(const Image& src);
219 
224  Image distributeTo(const ComputeDevice& dev);
225 
229  Image makeLike(const ComputeDevice& dev);
230 
232  void copyFrom(const Image& src);
233 
235  ImageInfo info() const;
236 
238  void clear();
239 
241  bool isEmpty() const;
242 
244  void copyToBuffer(void* buffer, const BufferDesc& bufferDesc) const;
245 
247  void copyFromBuffer(const void* buffer, const BufferDesc& bufferDesc) const;
248 
249  Image(Ref ref);
250 
251  private:
252  friend class Kernel;
253  //friend Image BlinkImageForRef(Ref);
254  };
255 
260  {
261 
262  KernelInfo();
263 
264  KernelInfo(const KernelInfo& info);
265 
266  KernelInfo(const std::string& name, KernelType type,
267  KernelGranularity granularity);
268 
269  std::string getName() const;
270  KernelType getType() const;
271  KernelGranularity getGranularity() const;
272  };
273 
278  {
279 
280  KernelImageInfo();
281 
282  KernelImageInfo(const KernelImageInfo& info);
283 
284  KernelImageInfo(const std::string& name, ImageAccessType accessType,
285  ImagePatternType patternType, ImageEdgeType edgeType);
286 
287  std::string getName() const;
288  ImageAccessType getAccessType() const;
289  ImagePatternType getPatternType() const;
290  ImageEdgeType getEdgeType() const;
291  };
292 
297  {
298 
300 
302 
303  KernelParameterInfo(const std::string& name, DataType type, unsigned nComponents,
304  unsigned nElements);
305 
306  unsigned getNumParameters();
307 
308  std::string getName() const;
309  DataType getDataType() const;
310  unsigned getNComponents() const;
311  unsigned getNElements() const;
312  };
313 
315  class IKernel: protected RefHolder
316  {
317 
318  public:
320  IKernel(const ProgramSource& programSource);
321 
322  unsigned getNumImages() const;
323  unsigned getNumParameters() const;
324 
325  KernelInfo getKernelInfo() const;
326 
327  std::vector<KernelImageInfo> getImagesInfo() const;
328 
329  std::vector<KernelParameterInfo> getParametersInfo() const;
330 
331  protected:
332  IKernel();
333  };
334 
336  class Kernel: public IKernel
337  {
338 
339  public:
344  Kernel(const ProgramSource& programSource, ComputeDevice& dev, const std::vector<Image>& images, CodegenFlags flags = kBlinkCodegenDefault);
345 
346  void setParamValue(const std::string& name, bool value);
347  void setParamValue(const std::string& name, float value);
348  void setParamValue(const std::string& name, int value);
349 
351  void setParamValue(const std::string& name, const char* value, unsigned int count);
352  void setParamValue(const std::string& name, const float* value, unsigned int count);
353  void setParamValue(const std::string& name, const int* value, unsigned int count);
354 
355  void getParamValue(const std::string& name, char* value, unsigned int count);
356  void getParamValue(const std::string& name, float* value, unsigned int count);
357  void getParamValue(const std::string& name, int* value, unsigned int count);
358 
359  std::vector<Blink::ImageAccessDesc> getInputRanges(void);
360 
361  //Iterate the kernel using the last image as the iteration bounds
362  void iterate();
363 
364  //Iterate over the provided bounds
365  void iterate(const KernelIterationController& controller);
366  };
367 
368 
372  class Exception: protected RefHolder
373  {
374  public:
376  std::string userMessage() const;
377 
378  protected:
379  Exception(Ref ref);
380  friend void TranslateBlinkError(ErrorCode errorCode, ErrorRef errorRef);
381  };
382 
387  {
388  protected:
389  OutOfMemoryException(Ref ref);
390  friend void TranslateBlinkError(ErrorCode errorCode, ErrorRef errorRef);
391  };
392 
393 
396  {
397  protected:
398  ComputeException(Ref ref);
399  friend void TranslateBlinkError(ErrorCode errorCode, ErrorRef errorRef);
400  };
401 
404  {
405  protected:
406  ImageSpecException(Ref ref);
407  friend void TranslateBlinkError(ErrorCode errorCode, ErrorRef errorRef);
408  };
409 
410 
413  {
414  protected:
415  CompilationException(Ref ref);
416  friend void TranslateBlinkError(ErrorCode errorCode, ErrorRef errorRef);
417  };
418 
423  {
424  public:
428  int lineNumber() const;
429 
431  std::string parseError() const;
432 
433  protected:
434  ParseException(Ref ref);
435  friend void TranslateBlinkError(ErrorCode errorCode, ErrorRef errorRef);
436  };
437 
440  {
441  protected:
442  DeviceException(Ref ref);
443  friend void TranslateBlinkError(ErrorCode errorCode, ErrorRef errorRef);
444  };
445 
450  {
451  protected:
452  ParameterException(Ref ref);
453  friend void TranslateBlinkError(ErrorCode errorCode, ErrorRef errorRef);
454  };
455 
458  {
459  protected:
461  friend void TranslateBlinkError(ErrorCode errorCode, ErrorRef errorRef);
462  };
463 
465  {
466  protected:
468  friend void TranslateBlinkError(ErrorCode errorCode, ErrorRef errorRef);
469  };
470 
471 } // namespace Blink
472 #include "BlinkImpl.h"
473 #endif
BlinkDataType dataType
Data type.
Definition: BlinkTypes.h:65
Definitions required for building with the Blink API.
int nComponents
Number of components.
Definition: BlinkTypes.h:62
Definition: BlinkTypes.h:88
Pixel information.
Definition: BlinkTypes.h:59
Definition: BlinkTypes.h:150
Rectangle.
Definition: BlinkTypes.h:50
Definition: BlinkTypes.h:124
General information about a kernel.
Definition: BlinkTypes.h:110
Defines some constants for use with the Blink API.
Definition: BlinkTypes.h:95
Image iteration description.
Definition: BlinkTypes.h:79
struct BlinkPixelInfo pixelInfo
Pixel format.
Definition: BlinkTypes.h:75
The main header file for Blink Library versioning.
Image description.
Definition: BlinkTypes.h:69
Definition: BlinkTypes.h:139
struct BlinkRect bounds
Bounds of iteration.
Definition: BlinkTypes.h:83
Defines some types used by the Blink API.


©2020 The Foundry Visionmongers, Ltd. All Rights Reserved.
www.thefoundry.co.uk