Commit c8d141023ce6de2105d7a5defde1a8ba724fcbc3

Authored by Josh Klontz
1 parent fb514f7e

renaming

sdk/jitcv/jitcv.h
... ... @@ -4,12 +4,15 @@
4 4 #include <stddef.h>
5 5 #include <stdint.h>
6 6  
  7 +namespace jitcv
  8 +{
  9 +
7 10 /*!
8 11 * \brief jitcv matrix
9 12 * \author Josh Klontz \cite jklontz
10 13 * \note Not part of the core SDK
11 14 */
12   -struct jit_matrix
  15 +struct Matrix
13 16 {
14 17 uint8_t *data; /*!< Data */
15 18 uint32_t channels; /*!< Channels */
... ... @@ -45,9 +48,9 @@ struct jit_matrix
45 48 f32 = 32 + Floating + Signed,
46 49 f64 = 64 + Floating + Signed };
47 50  
48   - jit_matrix() : data(NULL), channels(0), columns(0), rows(0), frames(0), hash(0) {}
  51 + Matrix() : data(NULL), channels(0), columns(0), rows(0), frames(0), hash(0) {}
49 52  
50   - jit_matrix(uint32_t _channels, uint32_t _columns, uint32_t _rows, uint32_t _frames, uint16_t _hash)
  53 + Matrix(uint32_t _channels, uint32_t _columns, uint32_t _rows, uint32_t _frames, uint16_t _hash)
51 54 : data(NULL), channels(_channels), columns(_columns), rows(_rows), frames(_frames), hash(_hash)
52 55 {
53 56 setSingleChannel(channels == 1);
... ... @@ -56,7 +59,7 @@ struct jit_matrix
56 59 setSingleFrame(frames == 1);
57 60 }
58 61  
59   - inline void copyHeader(const jit_matrix &other) { channels = other.channels; columns = other.columns; rows = other.rows; frames = other.frames; hash = other.hash; }
  62 + inline void copyHeader(const Matrix &other) { channels = other.channels; columns = other.columns; rows = other.rows; frames = other.frames; hash = other.hash; }
60 63 inline void allocate() { deallocate(); data = new uint8_t[bytes()]; }
61 64 inline void deallocate() { delete[] data; data = NULL; }
62 65  
... ... @@ -80,12 +83,14 @@ struct jit_matrix
80 83 inline uint32_t bytes() const { return bits() / 8 * elements(); }
81 84 };
82 85  
83   -typedef void (*jit_unary_function_t)(const jit_matrix *src, jit_matrix *dst);
84   -typedef void (*jit_binary_function_t)(const jit_matrix *srcA, const jit_matrix *srcB, jit_matrix *dst);
85   -typedef void (*jit_unary_kernel_t)(const jit_matrix *src, jit_matrix *dst, uint32_t size);
86   -typedef void (*jit_binary_kernel_t)(const jit_matrix *srcA, const jit_matrix *srcB, jit_matrix *dst, uint32_t size);
  86 +typedef void (*UnaryFunction_t)(const Matrix *src, Matrix *dst);
  87 +typedef void (*BinaryFunction_t)(const Matrix *srcA, const Matrix *srcB, Matrix *dst);
  88 +typedef void (*UnaryKernel_t)(const Matrix *src, Matrix *dst, uint32_t size);
  89 +typedef void (*BinaryKernel_t)(const Matrix *srcA, const Matrix *srcB, Matrix *dst, uint32_t size);
  90 +
  91 +UnaryFunction_t jit_unary_make(const char *description);
  92 +BinaryFunction_t jit_binary_make(const char *description);
87 93  
88   -jit_unary_function_t jit_unary_make(const char *description);
89   -jit_binary_function_t jit_binary_make(const char *description);
  94 +}
90 95  
91 96 #endif // __JITCV_H
... ...
sdk/plugins/llvm.cpp
... ... @@ -25,6 +25,7 @@
25 25  
26 26 using namespace br;
27 27 using namespace cv;
  28 +using namespace jitcv;
28 29 using namespace llvm;
29 30  
30 31 static Module *TheModule = NULL;
... ... @@ -33,15 +34,15 @@ static FunctionPassManager *TheFunctionPassManager = NULL;
33 34 static FunctionPassManager *TheExtraFunctionPassManager = NULL;
34 35 static StructType *TheMatrixStruct = NULL;
35 36  
36   -static QString MatrixToString(const jit_matrix &m)
  37 +static QString MatrixToString(const Matrix &m)
37 38 {
38 39 return QString("%1%2%3%4%5%6%7").arg(QString::number(m.bits()), (m.isSigned() ? "s" : "u"), (m.isFloating() ? "f" : "i"),
39 40 QString::number(m.singleChannel()), QString::number(m.singleColumn()), QString::number(m.singleRow()), QString::number(m.singleFrame()));
40 41 }
41 42  
42   -static jit_matrix MatrixFromMat(const cv::Mat &mat)
  43 +static Matrix MatrixFromMat(const cv::Mat &mat)
43 44 {
44   - jit_matrix m;
  45 + Matrix m;
45 46  
46 47 if (!mat.isContinuous()) qFatal("Matrix requires continuous data.");
47 48 m.channels = mat.channels();
... ... @@ -50,13 +51,13 @@ static jit_matrix MatrixFromMat(const cv::Mat &amp;mat)
50 51 m.frames = 1;
51 52  
52 53 switch (mat.depth()) {
53   - case CV_8U: m.hash = jit_matrix::u8; break;
54   - case CV_8S: m.hash = jit_matrix::s8; break;
55   - case CV_16U: m.hash = jit_matrix::u16; break;
56   - case CV_16S: m.hash = jit_matrix::s16; break;
57   - case CV_32S: m.hash = jit_matrix::s32; break;
58   - case CV_32F: m.hash = jit_matrix::f32; break;
59   - case CV_64F: m.hash = jit_matrix::f64; break;
  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;
60 61 default: qFatal("Unrecognized matrix depth.");
61 62 }
62 63  
... ... @@ -64,17 +65,17 @@ static jit_matrix MatrixFromMat(const cv::Mat &amp;mat)
64 65 return m;
65 66 }
66 67  
67   -static void AllocateMatrixFromMat(jit_matrix &m, cv::Mat &mat)
  68 +static void AllocateMatrixFromMat(Matrix &m, cv::Mat &mat)
68 69 {
69 70 int cvType = -1;
70 71 switch (m.type()) {
71   - case jit_matrix::u8: cvType = CV_8U; break;
72   - case jit_matrix::s8: cvType = CV_8S; break;
73   - case jit_matrix::u16: cvType = CV_16U; break;
74   - case jit_matrix::s16: cvType = CV_16S; break;
75   - case jit_matrix::s32: cvType = CV_32S; break;
76   - case jit_matrix::f32: cvType = CV_32F; break;
77   - case jit_matrix::f64: cvType = CV_64F; break;
  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;
78 79 default: qFatal("OpenCV does not support Matrix format: %s", qPrintable(MatrixToString(m)));
79 80 }
80 81  
... ... @@ -83,21 +84,21 @@ static void AllocateMatrixFromMat(jit_matrix &amp;m, cv::Mat &amp;mat)
83 84 m.data = mat.data;
84 85 }
85 86  
86   -QDebug operator<<(QDebug dbg, const jit_matrix &m)
  87 +QDebug operator<<(QDebug dbg, const Matrix &m)
87 88 {
88 89 dbg.nospace() << MatrixToString(m);
89 90 return dbg;
90 91 }
91 92  
92   -struct MatrixBuilder : public jit_matrix
  93 +struct MatrixBuilder : public Matrix
93 94 {
94 95 Value *m;
95 96 IRBuilder<> *b;
96 97 Function *f;
97 98 Twine name;
98 99  
99   - MatrixBuilder(const jit_matrix &matrix, Value *value, IRBuilder<> *builder, Function *function, const Twine &name_)
100   - : jit_matrix(matrix), m(value), b(builder), f(function), name(name_) {}
  100 + MatrixBuilder(const Matrix &matrix, Value *value, IRBuilder<> *builder, Function *function, const Twine &name_)
  101 + : Matrix(matrix), m(value), b(builder), f(function), name(name_) {}
101 102  
102 103 static Constant *zero() { return constant(0); }
103 104 static Constant *one() { return constant(1); }
... ... @@ -253,7 +254,7 @@ struct MatrixBuilder : public jit_matrix
253 254 template <typename T>
254 255 inline static std::vector<T> toVector(T value) { std::vector<T> vector; vector.push_back(value); return vector; }
255 256  
256   - static Type *ty(const jit_matrix &m)
  257 + static Type *ty(const Matrix &m)
257 258 {
258 259 const int bits = m.bits();
259 260 if (m.isFloating()) {
... ... @@ -273,7 +274,7 @@ struct MatrixBuilder : public jit_matrix
273 274 inline Type *ty() const { return ty(*this); }
274 275 inline std::vector<Type*> tys() const { return toVector<Type*>(ty()); }
275 276  
276   - static Type *ptrTy(const jit_matrix &m)
  277 + static Type *ptrTy(const Matrix &m)
277 278 {
278 279 const int bits = m.bits();
279 280 if (m.isFloating()) {
... ... @@ -304,16 +305,16 @@ class UnaryKernel : public UntrainableMetaTransform
304 305 {
305 306 Q_OBJECT
306 307  
307   - jit_unary_kernel_t kernel;
  308 + UnaryKernel_t kernel;
308 309 quint16 hash;
309 310  
310 311 public:
311 312 UnaryKernel() : kernel(NULL), hash(0) {}
312   - virtual int preallocate(const jit_matrix &src, jit_matrix &dst) const = 0; /*!< Preallocate destintation matrix based on source matrix. */
  313 + virtual int preallocate(const Matrix &src, Matrix &dst) const = 0; /*!< Preallocate destintation matrix based on source matrix. */
313 314 virtual Value *buildPreallocate(const MatrixBuilder &src, const MatrixBuilder &dst) const { (void) src; (void) dst; return MatrixBuilder::constant(0); }
314 315 virtual void build(const MatrixBuilder &src, const MatrixBuilder &dst, PHINode *i) const = 0; /*!< Build the kernel. */
315 316  
316   - void apply(const jit_matrix &src, jit_matrix &dst) const
  317 + void apply(const Matrix &src, Matrix &dst) const
317 318 {
318 319 const int size = preallocate(src, dst);
319 320 dst.allocate();
... ... @@ -326,12 +327,12 @@ public:
326 327 TheExtraFunctionPassManager->run(*f);
327 328 }
328 329  
329   - jit_unary_kernel_t getKernel(const jit_matrix *src) const
  330 + UnaryKernel_t getKernel(const Matrix *src) const
330 331 {
331 332 const QString functionName = mangledName(*src);
332 333 Function *function = TheModule->getFunction(qPrintable(functionName));
333 334 if (function == NULL) function = compile(*src);
334   - return (jit_unary_kernel_t)TheExecutionEngine->getPointerToFunction(function);
  335 + return (UnaryKernel_t)TheExecutionEngine->getPointerToFunction(function);
335 336 }
336 337  
337 338 private:
... ... @@ -344,12 +345,12 @@ private:
344 345 return "jitcv_" + name().remove("Transform") + (args.isEmpty() ? QString() : QString::number(uid));
345 346 }
346 347  
347   - QString mangledName(const jit_matrix &src) const
  348 + QString mangledName(const Matrix &src) const
348 349 {
349 350 return mangledName() + "_" + MatrixToString(src);
350 351 }
351 352  
352   - Function *compile(const jit_matrix &m) const
  353 + Function *compile(const Matrix &m) const
353 354 {
354 355 Function *kernel = compileKernel(m);
355 356 optimize(kernel);
... ... @@ -409,7 +410,7 @@ private:
409 410 return kernel;
410 411 }
411 412  
412   - Function *compileKernel(const jit_matrix &m) const
  413 + Function *compileKernel(const Matrix &m) const
413 414 {
414 415 Constant *c = TheModule->getOrInsertFunction(qPrintable(mangledName(m)),
415 416 Type::getVoidTy(getGlobalContext()),
... ... @@ -435,7 +436,7 @@ private:
435 436 BasicBlock *kernel;
436 437 PHINode *i = MatrixBuilder::beginLoop(builder, function, entry, &kernel, "i");
437 438  
438   - jit_matrix n;
  439 + Matrix n;
439 440 preallocate(m, n);
440 441 build(MatrixBuilder(m, src, &builder, function, "src"), MatrixBuilder(n, dst, &builder, function, "dst"), i);
441 442  
... ... @@ -447,14 +448,14 @@ private:
447 448  
448 449 void project(const Template &src, Template &dst) const
449 450 {
450   - const jit_matrix m(MatrixFromMat(src));
451   - jit_matrix n;
  451 + const Matrix m(MatrixFromMat(src));
  452 + Matrix n;
452 453 const int size = preallocate(m, n);
453 454 AllocateMatrixFromMat(n, dst);
454 455 invoke(m, n, size);
455 456 }
456 457  
457   - void invoke(const jit_matrix &src, jit_matrix &dst, int size) const
  458 + void invoke(const Matrix &src, Matrix &dst, int size) const
458 459 {
459 460 if (src.hash != hash) {
460 461 static QMutex compilerLock;
... ... @@ -478,15 +479,15 @@ class BinaryKernel: public UntrainableMetaTransform
478 479 {
479 480 Q_OBJECT
480 481  
481   - jit_binary_kernel_t kernel;
  482 + BinaryKernel_t kernel;
482 483 quint16 hashA, hashB;
483 484  
484 485 public:
485 486 BinaryKernel() : kernel(NULL), hashA(0), hashB(0) {}
486   - virtual int preallocate(const jit_matrix &srcA, const jit_matrix &srcB, jit_matrix &dst) const = 0; /*!< Preallocate destintation matrix based on source matrix. */
  487 + virtual int preallocate(const Matrix &srcA, const Matrix &srcB, Matrix &dst) const = 0; /*!< Preallocate destintation matrix based on source matrix. */
487 488 virtual void build(const MatrixBuilder &srcA, const MatrixBuilder &srcB, const MatrixBuilder &dst, PHINode *i) const = 0; /*!< Build the kernel. */
488 489  
489   - void apply(const jit_matrix &srcA, const jit_matrix &srcB, jit_matrix &dst) const
  490 + void apply(const Matrix &srcA, const Matrix &srcB, Matrix &dst) const
490 491 {
491 492 const int size = preallocate(srcA, srcB, dst);
492 493 dst.allocate();
... ... @@ -494,12 +495,12 @@ public:
494 495 }
495 496  
496 497 private:
497   - QString mangledName(const jit_matrix &srcA, const jit_matrix &srcB) const
  498 + QString mangledName(const Matrix &srcA, const Matrix &srcB) const
498 499 {
499 500 return "jitcv_" + name().remove("Transform") + "_" + MatrixToString(srcA) + "_" + MatrixToString(srcB);
500 501 }
501 502  
502   - Function *compile(const jit_matrix &m, const jit_matrix &n) const
  503 + Function *compile(const Matrix &m, const Matrix &n) const
503 504 {
504 505 Constant *c = TheModule->getOrInsertFunction(qPrintable(mangledName(m, n)),
505 506 Type::getVoidTy(getGlobalContext()),
... ... @@ -528,7 +529,7 @@ private:
528 529 BasicBlock *kernel;
529 530 PHINode *i = MatrixBuilder::beginLoop(builder, function, entry, &kernel, "i");
530 531  
531   - jit_matrix o;
  532 + Matrix o;
532 533 preallocate(m, n, o);
533 534 build(MatrixBuilder(m, srcA, &builder, function, "srcA"), MatrixBuilder(n, srcB, &builder, function, "srcB"), MatrixBuilder(o, dst, &builder, function, "dst"), i);
534 535  
... ... @@ -538,7 +539,7 @@ private:
538 539 return function;
539 540 }
540 541  
541   - void invoke(const jit_matrix &srcA, const jit_matrix &srcB, jit_matrix &dst, int size) const
  542 + void invoke(const Matrix &srcA, const Matrix &srcB, Matrix &dst, int size) const
542 543 {
543 544 if ((srcA.hash != hashA) || (srcB.hash != hashB)) {
544 545 static QMutex compilerLock;
... ... @@ -555,7 +556,7 @@ private:
555 556 function = TheModule->getFunction(qPrintable(functionName));
556 557 }
557 558  
558   - const_cast<BinaryKernel*>(this)->kernel = (jit_binary_kernel_t)TheExecutionEngine->getPointerToFunction(function);
  559 + const_cast<BinaryKernel*>(this)->kernel = (BinaryKernel_t)TheExecutionEngine->getPointerToFunction(function);
559 560 const_cast<BinaryKernel*>(this)->hashA = srcA.hash;
560 561 const_cast<BinaryKernel*>(this)->hashB = srcB.hash;
561 562 }
... ... @@ -576,7 +577,7 @@ class StitchableKernel : public UnaryKernel
576 577 public:
577 578 virtual Value *stitch(const MatrixBuilder &src, const MatrixBuilder &dst, Value *val) const = 0; /*!< A simplification of Kernel::build() for stitchable kernels. */
578 579  
579   - virtual int preallocate(const jit_matrix &src, jit_matrix &dst) const
  580 + virtual int preallocate(const Matrix &src, Matrix &dst) const
580 581 {
581 582 dst.copyHeader(src);
582 583 return dst.elements();
... ... @@ -615,9 +616,9 @@ class stitchTransform : public UnaryKernel
615 616 qFatal("%s is not a stitchable kernel!", qPrintable(transform->name()));
616 617 }
617 618  
618   - int preallocate(const jit_matrix &src, jit_matrix &dst) const
  619 + int preallocate(const Matrix &src, Matrix &dst) const
619 620 {
620   - jit_matrix tmp = src;
  621 + Matrix tmp = src;
621 622 foreach (const Transform *kernel, kernels) {
622 623 static_cast<const UnaryKernel*>(kernel)->preallocate(tmp, dst);
623 624 tmp = dst;
... ... @@ -671,7 +672,7 @@ class powTransform : public StitchableKernel
671 672 Q_PROPERTY(double exponent READ get_exponent WRITE set_exponent RESET reset_exponent STORED false)
672 673 BR_PROPERTY(double, exponent, 2)
673 674  
674   - int preallocate(const jit_matrix &src, jit_matrix &dst) const
  675 + int preallocate(const Matrix &src, Matrix &dst) const
675 676 {
676 677 dst.copyHeader(src);
677 678 dst.setFloating(true);
... ... @@ -716,9 +717,9 @@ class sumTransform : public UnaryKernel
716 717 BR_PROPERTY(bool, rows, true)
717 718 BR_PROPERTY(bool, frames, true)
718 719  
719   - int preallocate(const jit_matrix &src, jit_matrix &dst) const
  720 + int preallocate(const Matrix &src, Matrix &dst) const
720 721 {
721   - dst = jit_matrix(channels ? 1 : src.channels, columns ? 1 : src.columns, rows ? 1 : src.rows, frames ? 1 : src.frames, src.hash);
  722 + dst = Matrix(channels ? 1 : src.channels, columns ? 1 : src.columns, rows ? 1 : src.rows, frames ? 1 : src.frames, src.hash);
722 723 dst.setBits(std::min(2*dst.bits(), dst.isFloating() ? 64 : 32));
723 724 return dst.elements();
724 725 }
... ... @@ -803,23 +804,23 @@ class castTransform : public StitchableKernel
803 804  
804 805 public:
805 806 /*!< */
806   - enum Type { u1 = jit_matrix::u1,
807   - u8 = jit_matrix::u8,
808   - u16 = jit_matrix::u16,
809   - u32 = jit_matrix::u32,
810   - u64 = jit_matrix::u64,
811   - s8 = jit_matrix::s8,
812   - s16 = jit_matrix::s16,
813   - s32 = jit_matrix::s32,
814   - s64 = jit_matrix::s64,
815   - f16 = jit_matrix::f16,
816   - f32 = jit_matrix::f32,
817   - f64 = jit_matrix::f64 };
  807 + enum Type { u1 = Matrix::u1,
  808 + u8 = Matrix::u8,
  809 + u16 = Matrix::u16,
  810 + u32 = Matrix::u32,
  811 + u64 = Matrix::u64,
  812 + s8 = Matrix::s8,
  813 + s16 = Matrix::s16,
  814 + s32 = Matrix::s32,
  815 + s64 = Matrix::s64,
  816 + f16 = Matrix::f16,
  817 + f32 = Matrix::f32,
  818 + f64 = Matrix::f64 };
818 819  
819 820 private:
820 821 BR_PROPERTY(Type, type, f32)
821 822  
822   - int preallocate(const jit_matrix &src, jit_matrix &dst) const
  823 + int preallocate(const Matrix &src, Matrix &dst) const
823 824 {
824 825 dst.copyHeader(src);
825 826 dst.setType(type);
... ... @@ -1065,13 +1066,13 @@ class LLVMInitializer : public Initializer
1065 1066  
1066 1067 BR_REGISTER(Initializer, LLVMInitializer)
1067 1068  
1068   -jit_unary_function_t jit_unary_make(const char *description)
  1069 +UnaryFunction_t jit_unary_make(const char *description)
1069 1070 {
1070 1071 (void) description;
1071 1072 return NULL;
1072 1073 }
1073 1074  
1074   -jit_binary_function_t jit_binary_make(const char *description)
  1075 +BinaryFunction_t jit_binary_make(const char *description)
1075 1076 {
1076 1077 (void) description;
1077 1078 return NULL;
... ...