Commit 22b321b011ede56c7d64481327f0a10a8702e16f
1 parent
adbdffec
new llvm kernel syntax working
Showing
1 changed file
with
8 additions
and
48 deletions
sdk/plugins/llvm.cpp
| ... | ... | @@ -81,25 +81,6 @@ static Mat MatFromMatrix(const Matrix &m) |
| 81 | 81 | return Mat(m.rows, m.columns, CV_MAKETYPE(depth, m.channels), m.data).clone(); |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | -static void AllocateMatrixFromMat(Matrix &m, cv::Mat &mat) | |
| 85 | -{ | |
| 86 | - int cvType = -1; | |
| 87 | - switch (m.type()) { | |
| 88 | - case Matrix::u8: cvType = CV_8U; break; | |
| 89 | - case Matrix::s8: cvType = CV_8S; break; | |
| 90 | - case Matrix::u16: cvType = CV_16U; break; | |
| 91 | - case Matrix::s16: cvType = CV_16S; break; | |
| 92 | - case Matrix::s32: cvType = CV_32S; break; | |
| 93 | - case Matrix::f32: cvType = CV_32F; break; | |
| 94 | - case Matrix::f64: cvType = CV_64F; break; | |
| 95 | - default: qFatal("OpenCV does not support Matrix format: %s", qPrintable(MatrixToString(m))); | |
| 96 | - } | |
| 97 | - | |
| 98 | - m.deallocate(); | |
| 99 | - mat = Mat(m.rows, m.columns, CV_MAKETYPE(cvType, m.channels)); | |
| 100 | - m.data = mat.data; | |
| 101 | -} | |
| 102 | - | |
| 103 | 84 | QDebug operator<<(QDebug dbg, const Matrix &m) |
| 104 | 85 | { |
| 105 | 86 | dbg.nospace() << MatrixToString(m); |
| ... | ... | @@ -140,6 +121,7 @@ struct MatrixBuilder : public Matrix |
| 140 | 121 | |
| 141 | 122 | void copyHeaderCode(const MatrixBuilder &other) const { |
| 142 | 123 | setChannels(other.getChannels()); |
| 124 | + setColumns(other.getColumns()); | |
| 143 | 125 | setRows(other.getRows()); |
| 144 | 126 | setFrames(other.getFrames()); |
| 145 | 127 | setHash(other.getHash()); |
| ... | ... | @@ -333,25 +315,18 @@ public: |
| 333 | 315 | virtual Value *buildPreallocate(const MatrixBuilder &src, const MatrixBuilder &dst) const { (void) src; (void) dst; return MatrixBuilder::constant(0); } |
| 334 | 316 | virtual void build(const MatrixBuilder &src, const MatrixBuilder &dst, PHINode *i) const = 0; /*!< Build the kernel. */ |
| 335 | 317 | |
| 336 | - void apply(const Matrix &src, Matrix &dst) const | |
| 337 | - { | |
| 338 | - const int size = preallocate(src, dst); | |
| 339 | - dst.allocate(); | |
| 340 | - invoke(src, dst, size); | |
| 341 | - } | |
| 342 | - | |
| 343 | 318 | void optimize(Function *f) const |
| 344 | 319 | { |
| 345 | 320 | while (TheFunctionPassManager->run(*f)); |
| 346 | 321 | TheExtraFunctionPassManager->run(*f); |
| 347 | 322 | } |
| 348 | 323 | |
| 349 | - UnaryKernel_t getKernel(const Matrix *src) const | |
| 324 | + UnaryFunction_t getFunction(const Matrix *src) const | |
| 350 | 325 | { |
| 351 | - const QString functionName = mangledName(*src); | |
| 326 | + const QString functionName = mangledName(); | |
| 352 | 327 | Function *function = TheModule->getFunction(qPrintable(functionName)); |
| 353 | 328 | if (function == NULL) function = compile(*src); |
| 354 | - return (UnaryKernel_t)TheExecutionEngine->getPointerToFunction(function); | |
| 329 | + return (UnaryFunction_t)TheExecutionEngine->getPointerToFunction(function); | |
| 355 | 330 | } |
| 356 | 331 | |
| 357 | 332 | private: |
| ... | ... | @@ -433,7 +408,7 @@ private: |
| 433 | 408 | builder.CreateRetVoid(); |
| 434 | 409 | |
| 435 | 410 | optimize(function); |
| 436 | - return kernel; | |
| 411 | + return function; | |
| 437 | 412 | } |
| 438 | 413 | |
| 439 | 414 | Function *compileKernel(const Matrix &m) const |
| ... | ... | @@ -476,24 +451,9 @@ private: |
| 476 | 451 | { |
| 477 | 452 | const Matrix m(MatrixFromMat(src)); |
| 478 | 453 | Matrix n; |
| 479 | - const int size = preallocate(m, n); | |
| 480 | - AllocateMatrixFromMat(n, dst); | |
| 481 | - invoke(m, n, size); | |
| 482 | - } | |
| 483 | - | |
| 484 | - void invoke(const Matrix &src, Matrix &dst, int size) const | |
| 485 | - { | |
| 486 | - if (src.hash != hash) { | |
| 487 | - static QMutex compilerLock; | |
| 488 | - QMutexLocker locker(&compilerLock); | |
| 489 | - | |
| 490 | - if (src.hash != hash) { | |
| 491 | - const_cast<UnaryKernel*>(this)->kernel = getKernel(&src); | |
| 492 | - const_cast<UnaryKernel*>(this)->hash = src.hash; | |
| 493 | - } | |
| 494 | - } | |
| 495 | - | |
| 496 | - kernel(&src, &dst, size); | |
| 454 | + UnaryFunction_t function = getFunction(&m); | |
| 455 | + function(&m, &n); | |
| 456 | + dst.m() = MatFromMatrix(n); | |
| 497 | 457 | } |
| 498 | 458 | }; |
| 499 | 459 | ... | ... |