Commit 927b7781d935f4953351e0436717bc3d124040a3

Authored by Josh Klontz
1 parent da2c7725

exposed jitcv Matrix class

sdk/jitcv/jitcv.cpp 0 → 100644
  1 +#include "jitcv.h"
sdk/jitcv/jitcv.h 0 → 100644
  1 +#ifndef __JITCV_H
  2 +#define __JITCV_H
  3 +
  4 +#include <stddef.h>
  5 +#include <stdint.h>
  6 +
  7 +namespace jitcv
  8 +{
  9 +
  10 +/*!
  11 + * \brief jitcv matrix
  12 + * \author Josh Klontz \cite jklontz
  13 + * \note Not part of the core SDK
  14 + */
  15 +struct Matrix
  16 +{
  17 + uint8_t *data; /*!< Data */
  18 + uint32_t channels; /*!< Channels */
  19 + uint32_t columns; /*!< Columns */
  20 + uint32_t rows; /*!< Rows */
  21 + uint32_t frames; /*!< Frames */
  22 + uint16_t hash; /*!< Bits : 8
  23 + Floating : 1
  24 + Signed : 1
  25 + (Reserved) : 2
  26 + Single-channel : 1
  27 + Single-column : 1
  28 + Single-row : 1
  29 + Single-frame : 1 */
  30 +
  31 + enum Hash { Bits = 0x00FF,
  32 + Floating = 0x0100,
  33 + Signed = 0x0200,
  34 + SingleChannel = 0x1000,
  35 + SingleColumn = 0x2000,
  36 + SingleRow = 0x4000,
  37 + SingleFrame = 0x8000,
  38 + u1 = 1,
  39 + u8 = 8,
  40 + u16 = 16,
  41 + u32 = 32,
  42 + u64 = 64,
  43 + s8 = 8 + Signed,
  44 + s16 = 16 + Signed,
  45 + s32 = 32 + Signed,
  46 + s64 = 64 + Signed,
  47 + f16 = 16 + Floating + Signed,
  48 + f32 = 32 + Floating + Signed,
  49 + f64 = 64 + Floating + Signed };
  50 +
  51 + Matrix() : data(NULL), channels(0), columns(0), rows(0), frames(0), hash(0) {}
  52 +
  53 + Matrix(uint32_t _channels, uint32_t _columns, uint32_t _rows, uint32_t _frames, uint16_t _hash)
  54 + : data(NULL), channels(_channels), columns(_columns), rows(_rows), frames(_frames), hash(_hash)
  55 + {
  56 + setSingleChannel(channels == 1);
  57 + setSingleColumn(columns == 1);
  58 + setSingleRow(rows == 1);
  59 + setSingleFrame(frames == 1);
  60 + }
  61 +
  62 + inline void copyHeader(const Matrix &other) { channels = other.channels; columns = other.columns; rows = other.rows; frames = other.frames; hash = other.hash; }
  63 + inline void allocate() { deallocate(); data = new uint8_t[bytes()]; }
  64 + inline void deallocate() { delete[] data; data = NULL; }
  65 +
  66 + inline int bits() const { return hash & Bits; }
  67 + inline void setBits(int bits) { hash &= ~Bits; hash |= bits & Bits; }
  68 + inline bool isFloating() const { return hash & Floating; }
  69 + inline void setFloating(bool isFloating) { isFloating ? setSigned(true), hash |= Floating : hash &= ~Floating; }
  70 + inline bool isSigned() const { return hash & Signed; }
  71 + inline void setSigned(bool isSigned) { isSigned ? hash |= Signed : hash &= ~Signed; }
  72 + inline int type() const { return hash & (Bits + Floating + Signed); }
  73 + inline void setType(int type) { hash &= ~(Bits + Floating + Signed); hash |= type & (Bits + Floating + Signed); }
  74 + inline bool singleChannel() const { return hash & SingleChannel; }
  75 + inline void setSingleChannel(bool singleChannel) { singleChannel ? hash |= SingleChannel : hash &= ~SingleChannel; }
  76 + inline bool singleColumn() const { return hash & SingleColumn; }
  77 + inline void setSingleColumn(bool singleColumn) { singleColumn ? hash |= SingleColumn : hash &= ~SingleColumn; }
  78 + inline bool singleRow() const { return hash & SingleRow; }
  79 + inline void setSingleRow(bool singleRow) { singleRow ? hash |= SingleRow : hash &= ~SingleRow; }
  80 + inline bool singleFrame() const { return hash & SingleFrame; }
  81 + inline void setSingleFrame(bool singleFrame) { singleFrame ? hash |= SingleFrame : hash &= ~SingleFrame; }
  82 + inline uint32_t elements() const { return channels * columns * rows * frames; }
  83 + inline uint32_t bytes() const { return bits() / 8 * elements(); }
  84 +};
  85 +
  86 +} // namespace jitcv
  87 +
  88 +#endif // __JITCV_H
sdk/plugins/llvm.cmake
@@ -21,6 +21,8 @@ if(${BR_WITH_LLVM}) @@ -21,6 +21,8 @@ if(${BR_WITH_LLVM})
21 # Let's suppose we want to build a JIT compiler with support for binary code: 21 # Let's suppose we want to build a JIT compiler with support for binary code:
22 llvm_map_components_to_libraries(REQ_LLVM_LIBRARIES jit native) 22 llvm_map_components_to_libraries(REQ_LLVM_LIBRARIES jit native)
23 23
  24 + set(BR_THIRDPARTY_SRC ${BR_THIRDPARTY_SRC}
  25 + ${CMAKE_SOURCE_DIR}/sdk/plugins/llvm.cpp
  26 + ${CMAKE_SOURCE_DIR}/sdk/jitcv/jitcv.cpp)
24 set(BR_THIRDPARTY_LIBS ${BR_THIRDPARTY_LIBS} ${REQ_LLVM_LIBRARIES}) 27 set(BR_THIRDPARTY_LIBS ${BR_THIRDPARTY_LIBS} ${REQ_LLVM_LIBRARIES})
25 - set(BR_THIRDPARTY_SRC ${BR_THIRDPARTY_SRC} ${CMAKE_SOURCE_DIR}/sdk/plugins/llvm.cpp)  
26 endif() 28 endif()
sdk/plugins/llvm.cpp
@@ -21,9 +21,11 @@ @@ -21,9 +21,11 @@
21 #include <openbr_plugin.h> 21 #include <openbr_plugin.h>
22 22
23 #include "core/opencvutils.h" 23 #include "core/opencvutils.h"
  24 +#include "jitcv/jitcv.h"
24 25
25 using namespace br; 26 using namespace br;
26 using namespace cv; 27 using namespace cv;
  28 +using namespace jitcv;
27 using namespace llvm; 29 using namespace llvm;
28 30
29 static Module *TheModule = NULL; 31 static Module *TheModule = NULL;
@@ -32,124 +34,59 @@ static FunctionPassManager *TheFunctionPassManager = NULL; @@ -32,124 +34,59 @@ static FunctionPassManager *TheFunctionPassManager = NULL;
32 static FunctionPassManager *TheExtraFunctionPassManager = NULL; 34 static FunctionPassManager *TheExtraFunctionPassManager = NULL;
33 static StructType *TheMatrixStruct = NULL; 35 static StructType *TheMatrixStruct = NULL;
34 36
35 -/*!  
36 - * \brief LLVM matrix  
37 - * \author Josh Klontz \cite jklontz  
38 - * \note Not part of the core SDK  
39 - */  
40 -struct Matrix 37 +static QString MatrixToString(const Matrix &m)
41 { 38 {
42 - quint8 *data; /*!< Data */  
43 - quint32 channels; /*!< Channels */  
44 - quint32 columns; /*!< Columns */  
45 - quint32 rows; /*!< Rows */  
46 - quint32 frames; /*!< Frames */  
47 - quint16 hash; /*!< Bits : 8  
48 - Floating : 1  
49 - Signed : 1  
50 - Single-channel : 1  
51 - Single-column : 1  
52 - Single-row : 1  
53 - Single-frame : 1 */  
54 -  
55 - enum Hash { Bits = 0x00FF,  
56 - Floating = 0x0100,  
57 - Signed = 0x0200,  
58 - SingleChannel = 0x1000,  
59 - SingleColumn = 0x2000,  
60 - SingleRow = 0x4000,  
61 - SingleFrame = 0x8000,  
62 - u1 = 1,  
63 - u8 = 8,  
64 - u16 = 16,  
65 - u32 = 32,  
66 - u64 = 64,  
67 - s8 = 8 + Signed,  
68 - s16 = 16 + Signed,  
69 - s32 = 32 + Signed,  
70 - s64 = 64 + Signed,  
71 - f16 = 16 + Floating + Signed,  
72 - f32 = 32 + Floating + Signed,  
73 - f64 = 64 + Floating + Signed };  
74 -  
75 - Matrix() : data(NULL), channels(0), columns(0), rows(0), frames(0), hash(0) {}  
76 -  
77 - Matrix(quint32 _channels, quint32 _columns, quint32 _rows, quint32 _frames, quint16 _hash)  
78 - : data(NULL), channels(_channels), columns(_columns), rows(_rows), frames(_frames), hash(_hash)  
79 - {  
80 - setSingleChannel(channels == 1);  
81 - setSingleColumn(columns == 1);  
82 - setSingleRow(rows == 1);  
83 - setSingleFrame(frames == 1);  
84 - } 39 + return QString("%1%2%3%4%5%6%7").arg(QString::number(m.bits()), (m.isSigned() ? "s" : "u"), (m.isFloating() ? "f" : "i"),
  40 + QString::number(m.singleChannel()), QString::number(m.singleColumn()), QString::number(m.singleRow()), QString::number(m.singleFrame()));
  41 +}
85 42
86 - Matrix(const cv::Mat &mat)  
87 - {  
88 - if (!mat.isContinuous()) qFatal("Matrix requires continuous data.");  
89 - channels = mat.channels();  
90 - columns = mat.cols;  
91 - rows = mat.rows;  
92 - frames = 1;  
93 -  
94 - switch (mat.depth()) {  
95 - case CV_8U: hash = Matrix::u8; break;  
96 - case CV_8S: hash = Matrix::s8; break;  
97 - case CV_16U: hash = Matrix::u16; break;  
98 - case CV_16S: hash = Matrix::s16; break;  
99 - case CV_32S: hash = Matrix::s32; break;  
100 - case CV_32F: hash = Matrix::f32; break;  
101 - case CV_64F: hash = Matrix::f64; break;  
102 - default: qFatal("Unrecognized matrix depth.");  
103 - } 43 +static Matrix MatrixFromMat(const cv::Mat &mat)
  44 +{
  45 + Matrix m;
  46 +
  47 + if (!mat.isContinuous()) qFatal("Matrix requires continuous data.");
  48 + m.channels = mat.channels();
  49 + m.columns = mat.cols;
  50 + m.rows = mat.rows;
  51 + m.frames = 1;
  52 +
  53 + switch (mat.depth()) {
  54 + case CV_8U: m.hash = Matrix::u8; break;
  55 + case CV_8S: m.hash = Matrix::s8; break;
  56 + case CV_16U: m.hash = Matrix::u16; break;
  57 + case CV_16S: m.hash = Matrix::s16; break;
  58 + case CV_32S: m.hash = Matrix::s32; break;
  59 + case CV_32F: m.hash = Matrix::f32; break;
  60 + case CV_64F: m.hash = Matrix::f64; break;
  61 + default: qFatal("Unrecognized matrix depth.");
  62 + }
  63 +
  64 + m.data = mat.data;
  65 + return m;
  66 +}
104 67
105 - data = mat.data;  
106 - }  
107 -  
108 - void copyHeader(const Matrix &other) { channels = other.channels; columns = other.columns; rows = other.rows; frames = other.frames; hash = other.hash; }  
109 - void allocate() { deallocate(); data = new quint8[bytes()]; }  
110 - void allocate(Mat &m) { deallocate(); m = Mat(rows, columns, CV_MAKETYPE(getOpenCVDepth(), channels)); data = m.data; }  
111 - void deallocate() { delete[] data; data = NULL; }  
112 -  
113 - inline int bits() const { return hash & Bits; }  
114 - inline void setBits(int bits) { hash &= ~Bits; hash |= bits & Bits; }  
115 - inline bool isFloating() const { return hash & Floating; }  
116 - inline void setFloating(bool isFloating) { isFloating ? setSigned(true), hash |= Floating : hash &= ~Floating; }  
117 - inline bool isSigned() const { return hash & Signed; }  
118 - inline void setSigned(bool isSigned) { isSigned ? hash |= Signed : hash &= ~Signed; }  
119 - inline int type() const { return hash & (Bits + Floating + Signed); }  
120 - inline void setType(int type) { hash &= ~(Bits + Floating + Signed); hash |= type & (Bits + Floating + Signed); }  
121 - inline bool singleChannel() const { return hash & SingleChannel; }  
122 - inline void setSingleChannel(bool singleChannel) { singleChannel ? hash |= SingleChannel : hash &= ~SingleChannel; }  
123 - inline bool singleColumn() const { return hash & SingleColumn; }  
124 - inline void setSingleColumn(bool singleColumn) { singleColumn ? hash |= SingleColumn : hash &= ~SingleColumn; }  
125 - inline bool singleRow() const { return hash & SingleRow; }  
126 - inline void setSingleRow(bool singleRow) { singleRow ? hash |= SingleRow : hash &= ~SingleRow; }  
127 - inline bool singleFrame() const { return hash & SingleFrame; }  
128 - inline void setSingleFrame(bool singleFrame) { singleFrame ? hash |= SingleFrame : hash &= ~SingleFrame; }  
129 - inline quint32 elements() const { return channels * columns * rows * frames; }  
130 - inline quint32 bytes() const { return bits() / 8 * elements(); }  
131 -  
132 - QString toString() const { return QString("%1%2%3%4%5%6%7").arg(QString::number(bits()), (isSigned() ? "s" : "u"), (isFloating() ? "f" : "i"),  
133 - QString::number(singleChannel()), QString::number(singleColumn()), QString::number(singleRow()), QString::number(singleFrame())); }  
134 -  
135 - int getOpenCVDepth() const {  
136 - switch (type()) {  
137 - case u8: return CV_8U;  
138 - case s8: return CV_8S;  
139 - case u16: return CV_16U;  
140 - case s16: return CV_16S;  
141 - case s32: return CV_32S;  
142 - case f32: return CV_32F;  
143 - case f64: return CV_64F;  
144 - default: qFatal("OpenCV does not support Matrix format: %s", qPrintable(toString()));  
145 - }  
146 - return -1;  
147 - }  
148 -}; 68 +static void AllocateMatrixFromMat(Matrix &m, cv::Mat &mat)
  69 +{
  70 + int cvType = -1;
  71 + switch (m.type()) {
  72 + case Matrix::u8: cvType = CV_8U; break;
  73 + case Matrix::s8: cvType = CV_8S; break;
  74 + case Matrix::u16: cvType = CV_16U; break;
  75 + case Matrix::s16: cvType = CV_16S; break;
  76 + case Matrix::s32: cvType = CV_32S; break;
  77 + case Matrix::f32: cvType = CV_32F; break;
  78 + case Matrix::f64: cvType = CV_64F; break;
  79 + default: qFatal("OpenCV does not support Matrix format: %s", qPrintable(MatrixToString(m)));
  80 + }
  81 +
  82 + m.deallocate();
  83 + mat = Mat(m.rows, m.columns, CV_MAKETYPE(cvType, m.channels));
  84 + m.data = mat.data;
  85 +}
149 86
150 QDebug operator<<(QDebug dbg, const Matrix &m) 87 QDebug operator<<(QDebug dbg, const Matrix &m)
151 { 88 {
152 - dbg.nospace() << m.toString(); 89 + dbg.nospace() << MatrixToString(m);
153 return dbg; 90 return dbg;
154 } 91 }
155 92
@@ -307,10 +244,10 @@ namespace br @@ -307,10 +244,10 @@ namespace br
307 { 244 {
308 245
309 /*! 246 /*!
310 - * \brief LLVM Kernel 247 + * \brief LLVM Unary Kernel
311 * \author Josh Klontz \cite jklontz 248 * \author Josh Klontz \cite jklontz
312 */ 249 */
313 -class Kernel : public UntrainableMetaTransform 250 +class UnaryKernel : public UntrainableMetaTransform
314 { 251 {
315 Q_OBJECT 252 Q_OBJECT
316 253
@@ -319,17 +256,18 @@ class Kernel : public UntrainableMetaTransform @@ -319,17 +256,18 @@ class Kernel : public UntrainableMetaTransform
319 quint16 hash; 256 quint16 hash;
320 257
321 public: 258 public:
322 - Kernel() : kernel(NULL), hash(0) {} 259 + UnaryKernel() : kernel(NULL), hash(0) {}
323 virtual int preallocate(const Matrix &src, Matrix &dst) const = 0; /*!< Preallocate destintation matrix based on source matrix. */ 260 virtual int preallocate(const Matrix &src, Matrix &dst) const = 0; /*!< Preallocate destintation matrix based on source matrix. */
324 virtual void build(const MatrixBuilder &src, const MatrixBuilder &dst, PHINode *i) const = 0; /*!< Build the kernel. */ 261 virtual void build(const MatrixBuilder &src, const MatrixBuilder &dst, PHINode *i) const = 0; /*!< Build the kernel. */
325 262
326 private: 263 private:
327 - QString mangledName(const Matrix &m) const { 264 + QString mangledName(const Matrix &src) const
  265 + {
328 static QHash<QString, int> argsLUT; 266 static QHash<QString, int> argsLUT;
329 const QString args = arguments().join(","); 267 const QString args = arguments().join(",");
330 if (!argsLUT.contains(args)) argsLUT.insert(args, argsLUT.size()); 268 if (!argsLUT.contains(args)) argsLUT.insert(args, argsLUT.size());
331 int uid = argsLUT.value(args); 269 int uid = argsLUT.value(args);
332 - return "jitcv_" + name().remove("Transform") + QString::number(uid) + "_" + m.toString(); 270 + return "jitcv_" + name().remove("Transform") + (args.isEmpty() ? QString() : QString::number(uid)) + "_" + MatrixToString(src);
333 } 271 }
334 272
335 Function *compile(const Matrix &m) const 273 Function *compile(const Matrix &m) const
@@ -370,32 +308,125 @@ private: @@ -370,32 +308,125 @@ private:
370 308
371 void project(const Template &src, Template &dst) const 309 void project(const Template &src, Template &dst) const
372 { 310 {
373 - const Matrix m(src.m()); 311 + const Matrix m(MatrixFromMat(src));
374 Matrix n; 312 Matrix n;
375 const int size = preallocate(m, n); 313 const int size = preallocate(m, n);
376 - n.allocate(dst.m()); 314 + AllocateMatrixFromMat(n, dst);
  315 + invoke(m, n, size);
  316 + }
  317 +
  318 + void invoke(const Matrix &src, Matrix &dst, int size) const
  319 + {
  320 + if (src.hash != hash) {
  321 + static QMutex compilerLock;
  322 + QMutexLocker locker(&compilerLock);
  323 +
  324 + if (src.hash != hash) {
  325 + const QString functionName = mangledName(src);
  326 +
  327 + Function *function = TheModule->getFunction(qPrintable(functionName));
  328 + if (function == NULL) {
  329 + function = compile(src);
  330 + while (TheFunctionPassManager->run(*function));
  331 + TheExtraFunctionPassManager->run(*function);
  332 + function = TheModule->getFunction(qPrintable(functionName));
  333 + }
  334 +
  335 + const_cast<UnaryKernel*>(this)->kernel = (kernel_t)TheExecutionEngine->getPointerToFunction(function);
  336 + const_cast<UnaryKernel*>(this)->hash = src.hash;
  337 + }
  338 + }
  339 +
  340 + kernel(&src, &dst, size);
  341 + }
  342 +};
  343 +
  344 +/*!
  345 + * \brief LLVM Binary Kernel
  346 + * \author Josh Klontz \cite jklontz
  347 + */
  348 +class BinaryKernel: public UntrainableMetaTransform
  349 +{
  350 + Q_OBJECT
  351 +
  352 + typedef void (*kernel_t)(const Matrix*, const Matrix*, Matrix*, quint32);
  353 + kernel_t kernel;
  354 + quint16 hashA, hashB;
  355 +
  356 +public:
  357 + BinaryKernel() : kernel(NULL), hashA(0), hashB(0) {}
  358 + virtual int preallocate(const Matrix &srcA, const Matrix &srcB, Matrix &dst) const = 0; /*!< Preallocate destintation matrix based on source matrix. */
  359 + virtual void build(const MatrixBuilder &srcA, const MatrixBuilder &srcB, const MatrixBuilder &dst, PHINode *i) const = 0; /*!< Build the kernel. */
  360 +
  361 +private:
  362 + QString mangledName(const Matrix &srcA, const Matrix &srcB) const
  363 + {
  364 + return "jitcv_" + name().remove("Transform") + "_" + MatrixToString(srcA) + "_" + MatrixToString(srcB);
  365 + }
  366 +
  367 + Function *compile(const Matrix &m, const Matrix &n) const
  368 + {
  369 + Constant *c = TheModule->getOrInsertFunction(qPrintable(mangledName(m, n)),
  370 + Type::getVoidTy(getGlobalContext()),
  371 + PointerType::getUnqual(TheMatrixStruct),
  372 + PointerType::getUnqual(TheMatrixStruct),
  373 + PointerType::getUnqual(TheMatrixStruct),
  374 + Type::getInt32Ty(getGlobalContext()),
  375 + NULL);
  376 +
  377 + Function *function = cast<Function>(c);
  378 + function->setCallingConv(CallingConv::C);
377 379
378 - if (m.hash != hash) { 380 + Function::arg_iterator args = function->arg_begin();
  381 + Value *srcA = args++;
  382 + srcA->setName("srcA");
  383 + Value *srcB = args++;
  384 + srcB->setName("srcB");
  385 + Value *dst = args++;
  386 + dst->setName("dst");
  387 + Value *len = args++;
  388 + len->setName("len");
  389 +
  390 + BasicBlock *entry = BasicBlock::Create(getGlobalContext(), "entry", function);
  391 + IRBuilder<> builder(entry);
  392 +
  393 + BasicBlock *kernel;
  394 + PHINode *i = MatrixBuilder::beginLoop(builder, function, entry, &kernel, "i");
  395 +
  396 + Matrix o;
  397 + preallocate(m, n, o);
  398 + build(MatrixBuilder(m, srcA, &builder, function, "srcA"), MatrixBuilder(n, srcB, &builder, function, "srcB"), MatrixBuilder(o, dst, &builder, function, "dst"), i);
  399 +
  400 + MatrixBuilder::endLoop(builder, function, kernel, i, len, "i");
  401 +
  402 + builder.CreateRetVoid();
  403 + return function;
  404 + }
  405 +
  406 + void invoke(const Matrix &srcA, const Matrix &srcB, Matrix &dst, int size) const
  407 + {
  408 + if ((srcA.hash != hashA) || (srcB.hash != hashB)) {
379 static QMutex compilerLock; 409 static QMutex compilerLock;
380 QMutexLocker locker(&compilerLock); 410 QMutexLocker locker(&compilerLock);
381 411
382 - if (m.hash != hash) {  
383 - const QString functionName = mangledName(m); 412 + if ((srcA.hash != hashA) || (srcB.hash != hashB)) {
  413 + const QString functionName = mangledName(srcA, srcB);
384 414
385 Function *function = TheModule->getFunction(qPrintable(functionName)); 415 Function *function = TheModule->getFunction(qPrintable(functionName));
386 if (function == NULL) { 416 if (function == NULL) {
387 - function = compile(m); 417 + function = compile(srcA, srcB);
388 while (TheFunctionPassManager->run(*function)); 418 while (TheFunctionPassManager->run(*function));
389 TheExtraFunctionPassManager->run(*function); 419 TheExtraFunctionPassManager->run(*function);
390 function = TheModule->getFunction(qPrintable(functionName)); 420 function = TheModule->getFunction(qPrintable(functionName));
391 } 421 }
392 422
393 - const_cast<Kernel*>(this)->kernel = (kernel_t)TheExecutionEngine->getPointerToFunction(function);  
394 - const_cast<Kernel*>(this)->hash = m.hash; 423 + const_cast<BinaryKernel*>(this)->kernel = (kernel_t)TheExecutionEngine->getPointerToFunction(function);
  424 + const_cast<BinaryKernel*>(this)->hashA = srcA.hash;
  425 + const_cast<BinaryKernel*>(this)->hashB = srcB.hash;
395 } 426 }
396 } 427 }
397 428
398 - kernel(&m, &n, size); 429 + kernel(&srcA, &srcB, &dst, size);
399 } 430 }
400 }; 431 };
401 432
@@ -403,7 +434,7 @@ private: @@ -403,7 +434,7 @@ private:
403 * \brief LLVM Stitchable Kernel 434 * \brief LLVM Stitchable Kernel
404 * \author Josh Klontz \cite jklontz 435 * \author Josh Klontz \cite jklontz
405 */ 436 */
406 -class StitchableKernel : public Kernel 437 +class StitchableKernel : public UnaryKernel
407 { 438 {
408 Q_OBJECT 439 Q_OBJECT
409 440
@@ -430,7 +461,7 @@ private: @@ -430,7 +461,7 @@ private:
430 * \brief LLVM stitch transform 461 * \brief LLVM stitch transform
431 * \author Josh Klontz \cite jklontz 462 * \author Josh Klontz \cite jklontz
432 */ 463 */
433 -class stitchTransform : public Kernel 464 +class stitchTransform : public UnaryKernel
434 { 465 {
435 Q_OBJECT 466 Q_OBJECT
436 Q_PROPERTY(QList<br::Transform*> kernels READ get_kernels WRITE set_kernels RESET reset_kernels STORED false) 467 Q_PROPERTY(QList<br::Transform*> kernels READ get_kernels WRITE set_kernels RESET reset_kernels STORED false)
@@ -447,7 +478,7 @@ class stitchTransform : public Kernel @@ -447,7 +478,7 @@ class stitchTransform : public Kernel
447 { 478 {
448 Matrix tmp = src; 479 Matrix tmp = src;
449 foreach (const Transform *kernel, kernels) { 480 foreach (const Transform *kernel, kernels) {
450 - static_cast<const Kernel*>(kernel)->preallocate(tmp, dst); 481 + static_cast<const UnaryKernel*>(kernel)->preallocate(tmp, dst);
451 tmp = dst; 482 tmp = dst;
452 } 483 }
453 return dst.elements(); 484 return dst.elements();
@@ -459,7 +490,7 @@ class stitchTransform : public Kernel @@ -459,7 +490,7 @@ class stitchTransform : public Kernel
459 MatrixBuilder dst(dst_); 490 MatrixBuilder dst(dst_);
460 Value *val = src.load(i); 491 Value *val = src.load(i);
461 foreach (Transform *transform, kernels) { 492 foreach (Transform *transform, kernels) {
462 - static_cast<Kernel*>(transform)->preallocate(src, dst); 493 + static_cast<UnaryKernel*>(transform)->preallocate(src, dst);
463 val = static_cast<StitchableKernel*>(transform)->stitch(src, dst, val); 494 val = static_cast<StitchableKernel*>(transform)->stitch(src, dst, val);
464 src.copyHeader(dst); 495 src.copyHeader(dst);
465 src.m = dst.m; 496 src.m = dst.m;
@@ -532,7 +563,7 @@ BR_REGISTER(Transform, powTransform) @@ -532,7 +563,7 @@ BR_REGISTER(Transform, powTransform)
532 * \brief LLVM sum transform 563 * \brief LLVM sum transform
533 * \author Josh Klontz \cite jklontz 564 * \author Josh Klontz \cite jklontz
534 */ 565 */
535 -class sumTransform : public Kernel 566 +class sumTransform : public UnaryKernel
536 { 567 {
537 Q_OBJECT 568 Q_OBJECT
538 Q_PROPERTY(bool channels READ get_channels WRITE set_channels RESET reset_channels STORED false) 569 Q_PROPERTY(bool channels READ get_channels WRITE set_channels RESET reset_channels STORED false)
@@ -823,24 +854,24 @@ class LLVMInitializer : public Initializer @@ -823,24 +854,24 @@ class LLVMInitializer : public Initializer
823 Type::getInt16Ty(getGlobalContext()), // hash 854 Type::getInt16Ty(getGlobalContext()), // hash
824 NULL); 855 NULL);
825 856
826 -// QSharedPointer<Transform> kernel(Transform::make("abs", NULL)); 857 + QSharedPointer<Transform> kernel(Transform::make("abs", NULL));
827 858
828 -// Template src, dst;  
829 -// src.m() = (Mat_<qint8>(2,2) << -1, -2, 3, 4);  
830 -// kernel->project(src, dst);  
831 -// qDebug() << dst.m(); 859 + Template src, dst;
  860 + src.m() = (Mat_<qint8>(2,2) << -1, -2, 3, 4);
  861 + kernel->project(src, dst);
  862 + qDebug() << dst.m();
832 863
833 -// src.m() = (Mat_<qint32>(2,2) << -1, -3, 9, 27);  
834 -// kernel->project(src, dst);  
835 -// qDebug() << dst.m(); 864 + src.m() = (Mat_<qint32>(2,2) << -1, -3, 9, 27);
  865 + kernel->project(src, dst);
  866 + qDebug() << dst.m();
836 867
837 -// src.m() = (Mat_<float>(2,2) << -1.5, -2.5, 3.5, 4.5);  
838 -// kernel->project(src, dst);  
839 -// qDebug() << dst.m(); 868 + src.m() = (Mat_<float>(2,2) << -1.5, -2.5, 3.5, 4.5);
  869 + kernel->project(src, dst);
  870 + qDebug() << dst.m();
840 871
841 -// src.m() = (Mat_<double>(2,2) << 1.75, 2.75, -3.75, -4.75);  
842 -// kernel->project(src, dst);  
843 -// qDebug() << dst.m(); 872 + src.m() = (Mat_<double>(2,2) << 1.75, 2.75, -3.75, -4.75);
  873 + kernel->project(src, dst);
  874 + qDebug() << dst.m();
844 } 875 }
845 876
846 void finalize() const 877 void finalize() const
sdk/plugins/plugins.cmake
1 # Add source to BR_THIRDPARTY_SRC 1 # Add source to BR_THIRDPARTY_SRC
2 # Add libs to BR_THIRDPARTY_LIBS 2 # Add libs to BR_THIRDPARTY_LIBS
3 3
4 -include(ExternalProject)  
5 file(GLOB PLUGINS plugins/*.cpp) 4 file(GLOB PLUGINS plugins/*.cpp)
6 foreach(PLUGIN ${PLUGINS} ${BR_THIRDPARTY_PLUGINS}) 5 foreach(PLUGIN ${PLUGINS} ${BR_THIRDPARTY_PLUGINS})
7 get_filename_component(PLUGIN_BASENAME ${PLUGIN} NAME_WE) 6 get_filename_component(PLUGIN_BASENAME ${PLUGIN} NAME_WE)