Blink API
Loading...
Searching...
No Matches
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
18namespace 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
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
115 private:
116 void setSource(const char* source);
117 friend class IKernel;
118 friend class Kernel;
119 };
120
127 {
128
129 Rect();
130
131 Rect(const Rect& r);
132
134 Rect(int x1, int y1, int x2, int y2);
135
136 int width() const;
137 int height() const;
138 };
139
144 {
145
146 KernelIterationController(const KernelIterationController& iterationController);
149 };
150
156 {
157
158 BufferDesc();
159
161 BufferDesc(unsigned int pixelStepBytes,
162 unsigned int rowStepBytes,
163 unsigned int componentStepBytes);
164 };
165
170 {
171
172 PixelInfo();
175 };
176
181 {
182
183 ImageInfo();
184
185 ImageInfo(const ImageInfo& info);
186
188 ImageInfo(const Rect& bounds, const PixelInfo& pixelInfo);
189
190 Rect bounds() const;
191 };
192
194 {
195 ImageAccessDesc(void) {}
196 ImageAccessDesc(BlinkImagePatternType type);
197 ImageAccessDesc(BlinkAxisType axis, int min, int max);
198 ImageAccessDesc(Rect Range);
199 };
200
202 class Image: protected RefHolder
203 {
204 public:
207
209 Image(const Image& src);
210
211
212 Image(const ImageInfo& info, ComputeDevice& device);
213
214
215 Image(const DeviceMemory& memory, const ImageInfo& info, const BufferDesc& desc, ComputeDevice& device);
216
217 Image& operator=(const Image& src);
218
224
229
231 void copyFrom(const Image& src);
232
235
237 void clear();
238
240 bool isEmpty() const;
241
243 void copyToBuffer(void* buffer, const BufferDesc& bufferDesc) const;
244
246 void copyFromBuffer(const void* buffer, const BufferDesc& bufferDesc) const;
247
248 Image(Ref ref);
249
250 private:
251 friend class Kernel;
252 //friend Image BlinkImageForRef(Ref);
253 };
254
259 {
260
261 KernelInfo();
262
263 KernelInfo(const KernelInfo& info);
264
265 KernelInfo(const std::string& name, KernelType type,
266 KernelGranularity granularity);
267
268 std::string getName() const;
269 KernelType getType() const;
270 KernelGranularity getGranularity() const;
271 };
272
277 {
278
280
281 KernelImageInfo(const KernelImageInfo& info);
282
283 KernelImageInfo(const std::string& name, ImageAccessType accessType,
284 ImagePatternType patternType, ImageEdgeType edgeType);
285
286 std::string getName() const;
287 ImageAccessType getAccessType() const;
288 ImagePatternType getPatternType() const;
289 ImageEdgeType getEdgeType() const;
290 };
291
296 {
297
299
301
302 KernelParameterInfo(const std::string& name, DataType type, unsigned nComponents,
303 unsigned nElements);
304
305 unsigned getNumParameters();
306
307 std::string getName() const;
308 DataType getDataType() const;
309 unsigned getNComponents() const;
310 unsigned getNElements() const;
311 };
312
314 class IKernel: protected RefHolder
315 {
316
317 public:
319 IKernel(const ProgramSource& programSource);
320
321 unsigned getNumImages() const;
322 unsigned getNumParameters() const;
323
324 KernelInfo getKernelInfo() const;
325
326 std::vector<KernelImageInfo> getImagesInfo() const;
327
328 std::vector<KernelParameterInfo> getParametersInfo() const;
329
330 protected:
331 IKernel();
332 };
333
335 class Kernel: public IKernel
336 {
337
338 public:
343 Kernel(const ProgramSource& programSource, ComputeDevice& dev, const std::vector<Image>& images, CodegenFlags flags = kBlinkCodegenDefault);
344
345 void setParamValue(const std::string& name, bool value);
346 void setParamValue(const std::string& name, float value);
347 void setParamValue(const std::string& name, int value);
348
350 void setParamValue(const std::string& name, const char* value, unsigned int count);
351 void setParamValue(const std::string& name, const float* value, unsigned int count);
352 void setParamValue(const std::string& name, const int* value, unsigned int count);
353
354 void getParamValue(const std::string& name, char* value, unsigned int count);
355 void getParamValue(const std::string& name, float* value, unsigned int count);
356 void getParamValue(const std::string& name, int* value, unsigned int count);
357
358 std::vector<Blink::ImageAccessDesc> getInputRanges(void);
359
360 //Iterate the kernel using the last image as the iteration bounds
361 void iterate();
362
363 //Iterate over the provided bounds
364 void iterate(const KernelIterationController& controller);
365 };
366
367
371 class Exception: protected RefHolder
372 {
373 public:
375 std::string userMessage() const;
376
377 protected:
378 Exception(Ref ref);
379 friend void TranslateBlinkError(ErrorCode errorCode, ErrorRef errorRef);
380 };
381
386 {
387 protected:
388 OutOfMemoryException(Ref ref);
389 friend void TranslateBlinkError(ErrorCode errorCode, ErrorRef errorRef);
390 };
391
392
395 {
396 protected:
397 ComputeException(Ref ref);
398 friend void TranslateBlinkError(ErrorCode errorCode, ErrorRef errorRef);
399 };
400
403 {
404 protected:
405 ImageSpecException(Ref ref);
406 friend void TranslateBlinkError(ErrorCode errorCode, ErrorRef errorRef);
407 };
408
409
412 {
413 protected:
414 CompilationException(Ref ref);
415 friend void TranslateBlinkError(ErrorCode errorCode, ErrorRef errorRef);
416 };
417
422 {
423 public:
427 int lineNumber() const;
428
430 std::string parseError() const;
431
432 protected:
433 ParseException(Ref ref);
434 friend void TranslateBlinkError(ErrorCode errorCode, ErrorRef errorRef);
435 };
436
439 {
440 protected:
441 DeviceException(Ref ref);
442 friend void TranslateBlinkError(ErrorCode errorCode, ErrorRef errorRef);
443 };
444
449 {
450 protected:
451 ParameterException(Ref ref);
452 friend void TranslateBlinkError(ErrorCode errorCode, ErrorRef errorRef);
453 };
454
457 {
458 protected:
460 friend void TranslateBlinkError(ErrorCode errorCode, ErrorRef errorRef);
461 };
462
464 {
465 protected:
467 friend void TranslateBlinkError(ErrorCode errorCode, ErrorRef errorRef);
468 };
469
470} // namespace Blink
471#include "BlinkImpl.h"
472#endif
Definitions required for building with the Blink API.
Defines some constants for use with the Blink API.
Defines some types used by the Blink API.
The main header file for Blink Library versioning.
Definition: BlinkTypes.h:89
Definition: BlinkTypes.h:96
Definition: BlinkTypes.h:151
Image description.
Definition: BlinkTypes.h:70
struct BlinkPixelInfo pixelInfo
Pixel format.
Definition: BlinkTypes.h:75
Definition: BlinkTypes.h:125
General information about a kernel.
Definition: BlinkTypes.h:111
Image iteration description.
Definition: BlinkTypes.h:80
struct BlinkRect bounds
Bounds of iteration.
Definition: BlinkTypes.h:83
Definition: BlinkTypes.h:140
Pixel information.
Definition: BlinkTypes.h:60
BlinkDataType dataType
Data type.
Definition: BlinkTypes.h:65
int nComponents
Number of components.
Definition: BlinkTypes.h:62
Rectangle.
Definition: BlinkTypes.h:51


©2026 The Foundry Visionmongers, Ltd. All Rights Reserved.
www.foundry.com