Go to the documentation of this file.00001
00002
00007 #ifndef Blink_Library_Blink_h
00008 #define Blink_Library_Blink_h
00009
00010 #include "BlinkBuild.h"
00011 #include <string>
00012 #include <vector>
00013
00014 #include "BlinkTypes.h"
00015 #include "BlinkConstants.h"
00016 #include "BlinkVersion.h"
00017
00018 namespace Blink {
00019
00020 typedef BlinkComputeDeviceID ComputeDeviceID;
00021 typedef BlinkCodegenFlags CodegenFlags;
00022 typedef BlinkDataType DataType;
00023 typedef BlinkRef Ref;
00024 typedef BlinkErrorCode ErrorCode;
00025 typedef BlinkErrorRef ErrorRef;
00026 typedef BlinkMemoryType MemoryType;
00027
00031 struct DeviceMemory : BlinkDeviceMemory {
00032 DeviceMemory() {}
00033 DeviceMemory(const DeviceMemory& memory);
00034 DeviceMemory(MemoryType type, void* memoryBasePtr, unsigned long long memoryBaseSize, unsigned long long offset);
00035 };
00036
00037 class RefHolder {
00038 public:
00039 RefHolder();
00040
00041 RefHolder(Ref ref, bool retain);
00042 RefHolder(const RefHolder& holder);
00043
00044 RefHolder& operator=(const RefHolder& holder);
00045 void take(Ref ref);
00046
00047 RefHolder& operator=(Ref ref);
00048
00049 Ref ref() const;
00050
00051 ~RefHolder();
00052
00053 protected:
00054 Ref _ref;
00055 };
00056
00057
00059 class ComputeDevice : protected RefHolder {
00060 public:
00061
00062 ComputeDevice(const ComputeDevice& dev);
00063
00065 static ComputeDevice CurrentCPUDevice();
00066
00068 static ComputeDevice CurrentGPUDevice();
00069
00071 static ComputeDevice DeviceWithID(ComputeDeviceID id);
00072
00074 bool available() const;
00075
00077 std::string name() const;
00078
00079 private:
00080 ComputeDevice(Ref deviceRef);
00081
00082 friend class ComputeDeviceBinder;
00083 friend class Image;
00084 friend class Kernel;
00085 };
00086
00091 class ComputeDeviceBinder : protected RefHolder {
00092 public:
00093 ComputeDeviceBinder(ComputeDevice& device);
00094 };
00095
00099 class ProgramSource : protected RefHolder {
00100 public:
00101 ProgramSource(const char* source);
00102 ProgramSource(const std::string& source);
00103
00104 private:
00105 void setSource(const char* source);
00106 friend class Kernel;
00107 };
00108
00114 struct Rect : BlinkRect {
00115
00116 Rect();
00117
00118 Rect(const Rect& r);
00119
00121 Rect(int x1, int y1, int x2, int y2);
00122
00123 int width() const;
00124 int height() const;
00125 };
00126
00130 struct KernelIterationController : BlinkKernelIterationController {
00131
00132 KernelIterationController(const KernelIterationController& iterationController);
00134 KernelIterationController(const Rect& bounds);
00135 };
00136
00141 struct BufferDesc : BlinkBufferDesc {
00142
00143 BufferDesc();
00144
00146 BufferDesc(unsigned int pixelStepBytes,
00147 unsigned int rowStepBytes,
00148 unsigned int componentStepBytes);
00149 };
00150
00154 struct PixelInfo : BlinkPixelInfo {
00155
00156 PixelInfo();
00158 PixelInfo(int nComponents, DataType dataType);
00159 };
00160
00164 struct ImageInfo : BlinkImageInfo {
00165
00166 ImageInfo();
00167
00168 ImageInfo(const ImageInfo& info);
00169
00171 ImageInfo(const Rect& bounds, const PixelInfo& pixelInfo);
00172
00173 Rect bounds() const;
00174 };
00175
00177 class Image : protected RefHolder {
00178 public:
00179
00181 Image();
00182
00184 Image(const Image& src);
00185
00186
00187 Image(const ImageInfo& info, ComputeDevice& device);
00188
00189
00190 Image(const DeviceMemory& memory, const ImageInfo &info, const BufferDesc& desc, ComputeDevice &device);
00191
00192 Image& operator =(const Image&src);
00193
00198 Image distributeTo(const ComputeDevice& dev);
00199
00203 Image makeLike(const ComputeDevice& dev);
00204
00206 void copyFrom(const Image& src);
00207
00209 ImageInfo info() const;
00210
00212 void clear();
00213
00215 bool isEmpty() const;
00216
00218 void copyToBuffer(void* buffer, const BufferDesc& bufferDesc) const;
00219
00221 void copyFromBuffer(const void* buffer, const BufferDesc& bufferDesc) const;
00222
00223 Image(Ref ref);
00224
00225 private:
00226
00227 friend class Kernel;
00228
00229 };
00230
00231
00232
00234 class Kernel : protected RefHolder {
00235
00236 public:
00241 Kernel(const ProgramSource& programSource, ComputeDevice& dev, const std::vector<Image>& images, CodegenFlags flags = kBlinkCodegenDefault);
00242
00243 void setParamValue(const std::string& name, bool value);
00244 void setParamValue(const std::string& name, float value);
00245 void setParamValue(const std::string& name, int value);
00246
00248 void setParamValue(const std::string& name, const char* value, unsigned int count);
00249 void setParamValue(const std::string& name, const float* value, unsigned int count);
00250 void setParamValue(const std::string& name, const int* value, unsigned int count);
00251
00252 void getParamValue(const std::string& name, float* value, unsigned int count);
00253 void getParamValue(const std::string& name, int* value, unsigned int count);
00254
00255
00256 void iterate();
00257
00258
00259 void iterate(const KernelIterationController& controller);
00260 };
00261
00262
00266 class Exception : protected RefHolder
00267 {
00268 public:
00270 std::string userMessage() const;
00271
00272 protected:
00273 Exception(Ref ref);
00274 friend void TranslateBlinkError(ErrorCode errorCode, ErrorRef errorRef);
00275 };
00276
00280 class OutOfMemoryException : public Exception
00281 {
00282 protected:
00283 OutOfMemoryException(Ref ref);
00284 friend void TranslateBlinkError(ErrorCode errorCode, ErrorRef errorRef);
00285 };
00286
00287
00289 class ComputeException : public Exception
00290 {
00291 protected:
00292 ComputeException(Ref ref);
00293 friend void TranslateBlinkError(ErrorCode errorCode, ErrorRef errorRef);
00294 };
00295
00297 class ImageSpecException : public Exception
00298 {
00299 protected:
00300 ImageSpecException(Ref ref);
00301 friend void TranslateBlinkError(ErrorCode errorCode, ErrorRef errorRef);
00302 };
00303
00304
00306 class CompilationException : public Exception
00307 {
00308 protected:
00309 CompilationException(Ref ref);
00310 friend void TranslateBlinkError(ErrorCode errorCode, ErrorRef errorRef);
00311 };
00312
00316 class ParseException : public CompilationException
00317 {
00318 public:
00322 int lineNumber() const;
00323
00325 std::string parseError() const;
00326 protected:
00327 ParseException(Ref ref);
00328 friend void TranslateBlinkError(ErrorCode errorCode, ErrorRef errorRef);
00329 };
00330
00332 class DeviceException : public Exception
00333 {
00334 protected:
00335 DeviceException(Ref ref);
00336 friend void TranslateBlinkError(ErrorCode errorCode, ErrorRef errorRef);
00337 };
00338
00342 class ParameterException: public Exception
00343 {
00344 protected:
00345 ParameterException(Ref ref);
00346 friend void TranslateBlinkError(ErrorCode errorCode, ErrorRef errorRef);
00347 };
00348
00350 class IncompatibleImagesException : public Exception
00351 {
00352 protected:
00353 IncompatibleImagesException(Ref ref);
00354 friend void TranslateBlinkError(ErrorCode errorCode, ErrorRef errorRef);
00355 };
00356
00357 }
00358 #include "BlinkImpl.h"
00359 #endif