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 typedef BlinkComputeDeviceID ComputeDeviceID;
21 typedef BlinkCodegenFlags CodegenFlags;
22 typedef BlinkDataType DataType;
23 typedef BlinkRef Ref;
24 typedef BlinkErrorCode ErrorCode;
25 typedef BlinkErrorRef ErrorRef;
26 typedef BlinkMemoryType MemoryType;
27 
28 typedef BlinkKernelType KernelType;
29 typedef BlinkKernelGranularity KernelGranularity;
30 typedef BlinkImageAccessType ImageAccessType;
31 typedef BlinkImagePatternType ImagePatternType;
32 typedef BlinkImageEdgeType ImageEdgeType;
33 
38  DeviceMemory() {}
39  DeviceMemory(const DeviceMemory& memory);
40  DeviceMemory(MemoryType type, void* memoryBasePtr, unsigned long long memoryBaseSize, unsigned long long offset);
41 };
42 
43 class RefHolder {
44 public:
45  RefHolder();
46 
47  RefHolder(Ref ref, bool retain);
48  RefHolder(const RefHolder& holder);
49 
50  RefHolder& operator=(const RefHolder& holder);
51  void take(Ref ref);
52 
53  RefHolder& operator=(Ref ref);
54 
55  Ref ref() const;
56 
57  ~RefHolder();
58 
59 protected:
60  Ref _ref;
61 };
62 
63 
65 class ComputeDevice : protected RefHolder {
66 public:
67 
68  ComputeDevice(const ComputeDevice& dev);
69 
72 
75 
77  static ComputeDevice DeviceWithID(ComputeDeviceID id);
78 
80  bool available() const;
81 
83  std::string name() const;
84 
85 private:
86  ComputeDevice(Ref deviceRef);
87 
88  friend class ComputeDeviceBinder;
89  friend class Image;
90  friend class Kernel;
91 };
92 
97 class ComputeDeviceBinder : protected RefHolder {
98 public:
100 };
101 
105 class ProgramSource : protected RefHolder {
106 public:
107  ProgramSource(const char* source);
108  ProgramSource(const std::string& source);
109  ProgramSource(const ProgramSource& foo);
110 private:
111  void setSource(const char* source);
112  friend class IKernel;
113  friend class Kernel;
114 };
115 
121 struct Rect : BlinkRect {
122 
123  Rect();
124 
125  Rect(const Rect& r);
126 
128  Rect(int x1, int y1, int x2, int y2);
129 
130  int width() const;
131  int height() const;
132 };
133 
138 
139  KernelIterationController(const KernelIterationController& iterationController);
142 };
143 
149 
150  BufferDesc();
151 
153  BufferDesc(unsigned int pixelStepBytes,
154  unsigned int rowStepBytes,
155  unsigned int componentStepBytes);
156 };
157 
162 
163  PixelInfo();
165  PixelInfo(int nComponents, DataType dataType);
166 };
167 
172 
173  ImageInfo();
174 
175  ImageInfo(const ImageInfo& info);
176 
178  ImageInfo(const Rect& bounds, const PixelInfo& pixelInfo);
179 
180  Rect bounds() const;
181 };
182 
184  ImageAccessDesc(void) {}
185  ImageAccessDesc(BlinkImagePatternType type);
186  ImageAccessDesc(BlinkAxisType axis, int min, int max);
187  ImageAccessDesc(Rect Range);
188 };
189 
191 class Image : protected RefHolder {
192 public:
193 
195  Image();
196 
198  Image(const Image& src);
199 
200 
201  Image(const ImageInfo& info, ComputeDevice& device);
202 
203 
204  Image(const DeviceMemory& memory, const ImageInfo &info, const BufferDesc& desc, ComputeDevice &device);
205 
206  Image& operator =(const Image&src);
207 
212  Image distributeTo(const ComputeDevice& dev);
213 
217  Image makeLike(const ComputeDevice& dev);
218 
220  void copyFrom(const Image& src);
221 
223  ImageInfo info() const;
224 
226  void clear();
227 
229  bool isEmpty() const;
230 
232  void copyToBuffer(void* buffer, const BufferDesc& bufferDesc) const;
233 
235  void copyFromBuffer(const void* buffer, const BufferDesc& bufferDesc) const;
236 
237  Image(Ref ref);
238 
239  private:
240 
241  friend class Kernel;
242  //friend Image BlinkImageForRef(Ref);
243 };
244 
249 
250  KernelInfo();
251 
252  KernelInfo(const KernelInfo& info);
253 
254  KernelInfo(const std::string& name, KernelType type,
255  KernelGranularity granularity);
256 
257  std::string getName() const;
258  KernelType getType() const;
259  KernelGranularity getGranularity() const;
260 };
261 
266 
267  KernelImageInfo();
268 
269  KernelImageInfo(const KernelImageInfo& info);
270 
271  KernelImageInfo(const std::string& name, ImageAccessType accessType,
272  ImagePatternType patternType, ImageEdgeType edgeType);
273 
274  std::string getName() const;
275  ImageAccessType getAccessType() const;
276  ImagePatternType getPatternType() const;
277  ImageEdgeType getEdgeType() const;
278 };
279 
284 
286 
288 
289  KernelParameterInfo(const std::string& name, DataType type, unsigned nComponents,
290  unsigned nElements);
291 
292  unsigned getNumParameters();
293 
294  std::string getName() const;
295  DataType getDataType() const;
296  unsigned getNComponents() const;
297  unsigned getNElements() const;
298 };
299 
301 class IKernel : protected RefHolder {
302 
303 public:
305  IKernel(const ProgramSource& programSource);
306 
307  unsigned getNumImages() const;
308  unsigned getNumParameters() const;
309 
310  KernelInfo getKernelInfo() const;
311 
312  std::vector<KernelImageInfo> getImagesInfo() const;
313 
314  std::vector<KernelParameterInfo> getParametersInfo() const;
315 
316 protected:
317  IKernel();
318 };
319 
321 class Kernel : public IKernel {
322 
323 public:
328  Kernel(const ProgramSource& programSource, ComputeDevice& dev, const std::vector<Image>& images, CodegenFlags flags = kBlinkCodegenDefault);
329 
330  void setParamValue(const std::string& name, bool value);
331  void setParamValue(const std::string& name, float value);
332  void setParamValue(const std::string& name, int value);
333 
335  void setParamValue(const std::string& name, const char* value, unsigned int count);
336  void setParamValue(const std::string& name, const float* value, unsigned int count);
337  void setParamValue(const std::string& name, const int* value, unsigned int count);
338 
339  void getParamValue(const std::string& name, char* value, unsigned int count);
340  void getParamValue(const std::string& name, float* value, unsigned int count);
341  void getParamValue(const std::string& name, int* value, unsigned int count);
342 
343  std::vector<Blink::ImageAccessDesc> getInputRanges(void);
344 
345  //Iterate the kernel using the last image as the iteration bounds
346  void iterate();
347 
348  //Iterate over the provided bounds
349  void iterate(const KernelIterationController& controller);
350 };
351 
352 
356 class Exception : protected RefHolder
357 {
358 public:
360  std::string userMessage() const;
361 
362 protected:
363  Exception(Ref ref);
364  friend void TranslateBlinkError(ErrorCode errorCode, ErrorRef errorRef);
365 };
366 
371 {
372 protected:
373  OutOfMemoryException(Ref ref);
374  friend void TranslateBlinkError(ErrorCode errorCode, ErrorRef errorRef);
375 };
376 
377 
380 {
381 protected:
382  ComputeException(Ref ref);
383  friend void TranslateBlinkError(ErrorCode errorCode, ErrorRef errorRef);
384 };
385 
388 {
389 protected:
390  ImageSpecException(Ref ref);
391  friend void TranslateBlinkError(ErrorCode errorCode, ErrorRef errorRef);
392 };
393 
394 
397 {
398 protected:
399  CompilationException(Ref ref);
400  friend void TranslateBlinkError(ErrorCode errorCode, ErrorRef errorRef);
401 };
402 
407 {
408 public:
412  int lineNumber() const;
413 
415  std::string parseError() const;
416 protected:
417  ParseException(Ref ref);
418  friend void TranslateBlinkError(ErrorCode errorCode, ErrorRef errorRef);
419 };
420 
423 {
424 protected:
425  DeviceException(Ref ref);
426  friend void TranslateBlinkError(ErrorCode errorCode, ErrorRef errorRef);
427 };
428 
433 {
434 protected:
435  ParameterException(Ref ref);
436  friend void TranslateBlinkError(ErrorCode errorCode, ErrorRef errorRef);
437 };
438 
441 {
442 protected:
444  friend void TranslateBlinkError(ErrorCode errorCode, ErrorRef errorRef);
445 };
446 
448 {
449 protected:
451  friend void TranslateBlinkError(ErrorCode errorCode, ErrorRef errorRef);
452 };
453 
454 }
455 #include "BlinkImpl.h"
456 #endif
BlinkDataType dataType
Data type.
Definition: BlinkTypes.h:63
Definitions required for building with the Blink API.
int nComponents
Number of components.
Definition: BlinkTypes.h:60
Definition: BlinkTypes.h:84
Pixel information.
Definition: BlinkTypes.h:58
Definition: BlinkTypes.h:141
Rectangle.
Definition: BlinkTypes.h:50
Definition: BlinkTypes.h:117
General information about a kernel.
Definition: BlinkTypes.h:104
Defines some constants for use with the Blink API.
Definition: BlinkTypes.h:90
Image iteration description.
Definition: BlinkTypes.h:76
struct BlinkPixelInfo pixelInfo
Pixel format.
Definition: BlinkTypes.h:72
The main header file for Blink Library versioning.
Image description.
Definition: BlinkTypes.h:67
Definition: BlinkTypes.h:131
struct BlinkRect bounds
Bounds of iteration.
Definition: BlinkTypes.h:79
Defines some types used by the Blink API.


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