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
00017 namespace Blink {
00018
00019 class BlinkRefHolder {
00020 public:
00021 BlinkRefHolder();
00022
00023 BlinkRefHolder(BlinkRef ref, bool retain);
00024 BlinkRefHolder(const BlinkRefHolder& holder);
00025
00026 BlinkRefHolder& operator=(const BlinkRefHolder& holder);
00027 void take(BlinkRef ref);
00028
00029 BlinkRefHolder& operator=(BlinkRef ref);
00030
00031 BlinkRef ref() const;
00032
00033 ~BlinkRefHolder();
00034
00035 protected:
00036 BlinkRef _ref;
00037 };
00038
00039
00041 class ComputeDevice : protected BlinkRefHolder {
00042 public:
00043
00045 static ComputeDevice CurrentCPUDevice();
00046
00048 static ComputeDevice CurrentGPUDevice();
00049
00051 bool available() const;
00052
00054 std::string name() const;
00055
00056 private:
00057 ComputeDevice(BlinkRef deviceRef);
00058
00059 friend class ComputeDeviceBinder;
00060 friend class Image;
00061 friend class Kernel;
00062 };
00063
00068 class ComputeDeviceBinder : protected BlinkRefHolder {
00069 public:
00070 ComputeDeviceBinder(ComputeDevice& device);
00071 };
00072
00073
00075 class Image : protected BlinkRefHolder {
00076 public:
00077
00079 Image();
00080
00082 Image(const Image& src);
00083
00084
00085 Image(const BlinkImageInfo& info, ComputeDevice& device);
00086
00087 Image& operator =(const Image&src);
00088
00093 Image distributeTo(const ComputeDevice& dev);
00094
00098 Image makeLike(const ComputeDevice& dev);
00099
00101 void copyFrom(const Image& src);
00102
00104 BlinkImageInfo info() const;
00105
00107 void clear();
00108
00110 bool isEmpty() const;
00111
00113 void copyToBuffer(void* buffer, const BlinkBufferDesc& bufferDesc) const;
00114
00116 void copyFromBuffer(const void* buffer, const BlinkBufferDesc& bufferDesc) const;
00117
00118 Image(BlinkRef ref);
00119
00120 private:
00121
00122 friend class Kernel;
00123 friend Image BlinkImageForBlinkRef(BlinkRef);
00124 };
00125
00129 class ProgramSource : protected BlinkRefHolder {
00130 public:
00131 ProgramSource(const char* source);
00132 ProgramSource(const std::string& source);
00133
00134 private:
00135 void setSource(const char* source);
00136 friend class Kernel;
00137 };
00138
00140 class Kernel : protected BlinkRefHolder {
00141
00142 public:
00147 Kernel(const ProgramSource& programSource, ComputeDevice& dev, const std::vector<Image>& images, BlinkCodegenFlags flags = kBlinkCodegenDefault);
00148
00149 void setParamValue(const std::string& name, bool value);
00150 void setParamValue(const std::string& name, float value);
00151 void setParamValue(const std::string& name, int value);
00152
00154 void setParamValue(const std::string& name, const char* value, unsigned int count);
00155 void setParamValue(const std::string& name, const float* value, unsigned int count);
00156 void setParamValue(const std::string& name, const int* value, unsigned int count);
00157
00158 void getParamValue(const std::string& name, float* value, unsigned int count);
00159 void getParamValue(const std::string& name, int* value, unsigned int count);
00160
00161
00162 void iterate();
00163
00164
00165 void iterate(const BlinkKernelIterationController& controller);
00166 };
00167
00172 struct BufferDesc : BlinkBufferDesc {
00173
00175 BufferDesc(unsigned int pixelStepBytes,
00176 unsigned int rowStepBytes,
00177 unsigned int componentStepBytes)
00178 {
00179 this->pixelStepBytes = pixelStepBytes;
00180 this->rowStepBytes = rowStepBytes;
00181 this->componentStepBytes = componentStepBytes;
00182 }
00183 };
00184
00190 struct Rect : BlinkRect {
00191
00193 Rect(int x1, int y1, int x2, int y2)
00194 {
00195 this->x1 = x1;
00196 this->y1 = y1;
00197 this->x2 = x2;
00198 this->y2 = y2;
00199 }
00200 };
00201
00205 struct PixelInfo : BlinkPixelInfo {
00206
00208 PixelInfo(int nComponents, BlinkDataType dataType)
00209 {
00210 this->nComponents = nComponents;
00211 this->dataType = dataType;
00212 }
00213 };
00214
00218 struct ImageInfo : BlinkImageInfo {
00219
00221 ImageInfo(const BlinkRect& bounds, const BlinkPixelInfo& pixelInfo)
00222 {
00223 this->bounds = bounds;
00224 this->pixelInfo = pixelInfo;
00225 }
00226 };
00227
00231 class Exception : protected BlinkRefHolder
00232 {
00233 public:
00235 std::string userMessage() const;
00236
00237 protected:
00238 Exception(BlinkRef ref);
00239 friend void TranslateBlinkError(BlinkErrorCode errorCode, BlinkErrorRef errorRef);
00240 };
00241
00245 class OutOfMemoryException : public Exception
00246 {
00247 protected:
00248 OutOfMemoryException(BlinkRef ref);
00249 friend void TranslateBlinkError(BlinkErrorCode errorCode, BlinkErrorRef errorRef);
00250 };
00251
00252
00254 class ComputeException : public Exception
00255 {
00256 protected:
00257 ComputeException(BlinkRef ref);
00258 friend void TranslateBlinkError(BlinkErrorCode errorCode, BlinkErrorRef errorRef);
00259 };
00260
00262 class ImageSpecException : public Exception
00263 {
00264 protected:
00265 ImageSpecException(BlinkRef ref);
00266 friend void TranslateBlinkError(BlinkErrorCode errorCode, BlinkErrorRef errorRef);
00267 };
00268
00269
00271 class CompilationException : public Exception
00272 {
00273 protected:
00274 CompilationException(BlinkRef ref);
00275 friend void TranslateBlinkError(BlinkErrorCode errorCode, BlinkErrorRef errorRef);
00276 };
00277
00281 class ParseException : public CompilationException
00282 {
00283 public:
00287 int lineNumber() const;
00288
00290 std::string parseError() const;
00291 protected:
00292 ParseException(BlinkRef ref);
00293 friend void TranslateBlinkError(BlinkErrorCode errorCode, BlinkErrorRef errorRef);
00294 };
00295
00297 class DeviceException : public Exception
00298 {
00299 protected:
00300 DeviceException(BlinkRef ref);
00301 friend void TranslateBlinkError(BlinkErrorCode errorCode, BlinkErrorRef errorRef);
00302 };
00303
00307 class ParameterException: public Exception
00308 {
00309 protected:
00310 ParameterException(BlinkRef ref);
00311 friend void TranslateBlinkError(BlinkErrorCode errorCode, BlinkErrorRef errorRef);
00312 };
00313
00315 class IncompatibleImagesException : public Exception
00316 {
00317 protected:
00318 IncompatibleImagesException(BlinkRef ref);
00319 friend void TranslateBlinkError(BlinkErrorCode errorCode, BlinkErrorRef errorRef);
00320 };
00321
00322 }
00323 #include "BlinkImpl.h"
00324 #endif