Commit 819e7a30e6cb80a52a7df4f10716d16b5d546153
Merge branch 'master' of https://github.com/biometrics/openbr into stasm
Showing
3 changed files
with
75 additions
and
88 deletions
sdk/likely.h
| @@ -6,15 +6,15 @@ | @@ -6,15 +6,15 @@ | ||
| 6 | 6 | ||
| 7 | #if defined BR_LIBRARY | 7 | #if defined BR_LIBRARY |
| 8 | # if defined _WIN32 || defined __CYGWIN__ | 8 | # if defined _WIN32 || defined __CYGWIN__ |
| 9 | -# define BR_EXPORT __declspec(dllexport) | 9 | +# define LIKELY_EXPORT __declspec(dllexport) |
| 10 | # else | 10 | # else |
| 11 | -# define BR_EXPORT __attribute__((visibility("default"))) | 11 | +# define LIKELY_EXPORT __attribute__((visibility("default"))) |
| 12 | # endif | 12 | # endif |
| 13 | #else | 13 | #else |
| 14 | # if defined _WIN32 || defined __CYGWIN__ | 14 | # if defined _WIN32 || defined __CYGWIN__ |
| 15 | -# define BR_EXPORT __declspec(dllimport) | 15 | +# define LIKELY_EXPORT __declspec(dllimport) |
| 16 | # else | 16 | # else |
| 17 | -# define BR_EXPORT | 17 | +# define LIKELY_EXPORT |
| 18 | # endif | 18 | # endif |
| 19 | #endif | 19 | #endif |
| 20 | 20 | ||
| @@ -73,39 +73,29 @@ struct likely_matrix | @@ -73,39 +73,29 @@ struct likely_matrix | ||
| 73 | f64 = 64 + Floating + Signed }; | 73 | f64 = 64 + Floating + Signed }; |
| 74 | }; | 74 | }; |
| 75 | 75 | ||
| 76 | -BR_EXPORT int likely_bits(const likely_matrix *m); | ||
| 77 | -BR_EXPORT void likely_set_bits(likely_matrix *m, int bits); | ||
| 78 | -BR_EXPORT bool likely_is_floating(const likely_matrix *m); | ||
| 79 | -BR_EXPORT void likely_set_floating(likely_matrix *m, bool is_floating); | ||
| 80 | -BR_EXPORT bool likely_is_signed(const likely_matrix *m); | ||
| 81 | -BR_EXPORT void likely_set_signed(likely_matrix *m, bool is_signed); | ||
| 82 | -BR_EXPORT int likely_type(const likely_matrix *m); | ||
| 83 | -BR_EXPORT void likely_set_type(likely_matrix *m, int type); | ||
| 84 | -BR_EXPORT bool likely_is_single_channel(const likely_matrix *m); | ||
| 85 | -BR_EXPORT void likely_set_single_channel(likely_matrix *m, bool is_single_channel); | ||
| 86 | -BR_EXPORT bool likely_is_single_column(const likely_matrix *m); | ||
| 87 | -BR_EXPORT void likely_set_single_column(likely_matrix *m, bool is_single_column); | ||
| 88 | -BR_EXPORT bool likely_is_single_row(const likely_matrix *m); | ||
| 89 | -BR_EXPORT void likely_set_single_row(likely_matrix *m, bool is_single_row); | ||
| 90 | -BR_EXPORT bool likely_is_single_frame(const likely_matrix *m); | ||
| 91 | -BR_EXPORT void likely_set_single_frame(likely_matrix *m, bool is_single_frame); | ||
| 92 | -BR_EXPORT uint32_t likely_elements(const likely_matrix *m); | ||
| 93 | -BR_EXPORT uint32_t likely_bytes(const likely_matrix *m); | 76 | +LIKELY_EXPORT int likely_bits(const likely_matrix *m); |
| 77 | +LIKELY_EXPORT void likely_set_bits(likely_matrix *m, int bits); | ||
| 78 | +LIKELY_EXPORT bool likely_is_floating(const likely_matrix *m); | ||
| 79 | +LIKELY_EXPORT void likely_set_floating(likely_matrix *m, bool is_floating); | ||
| 80 | +LIKELY_EXPORT bool likely_is_signed(const likely_matrix *m); | ||
| 81 | +LIKELY_EXPORT void likely_set_signed(likely_matrix *m, bool is_signed); | ||
| 82 | +LIKELY_EXPORT int likely_type(const likely_matrix *m); | ||
| 83 | +LIKELY_EXPORT void likely_set_type(likely_matrix *m, int type); | ||
| 84 | +LIKELY_EXPORT bool likely_is_single_channel(const likely_matrix *m); | ||
| 85 | +LIKELY_EXPORT void likely_set_single_channel(likely_matrix *m, bool is_single_channel); | ||
| 86 | +LIKELY_EXPORT bool likely_is_single_column(const likely_matrix *m); | ||
| 87 | +LIKELY_EXPORT void likely_set_single_column(likely_matrix *m, bool is_single_column); | ||
| 88 | +LIKELY_EXPORT bool likely_is_single_row(const likely_matrix *m); | ||
| 89 | +LIKELY_EXPORT void likely_set_single_row(likely_matrix *m, bool is_single_row); | ||
| 90 | +LIKELY_EXPORT bool likely_is_single_frame(const likely_matrix *m); | ||
| 91 | +LIKELY_EXPORT void likely_set_single_frame(likely_matrix *m, bool is_single_frame); | ||
| 92 | +LIKELY_EXPORT uint32_t likely_elements(const likely_matrix *m); | ||
| 93 | +LIKELY_EXPORT uint32_t likely_bytes(const likely_matrix *m); | ||
| 94 | 94 | ||
| 95 | typedef void (*likely_unary_function)(const likely_matrix *src, likely_matrix *dst); | 95 | typedef void (*likely_unary_function)(const likely_matrix *src, likely_matrix *dst); |
| 96 | typedef void (*likely_binary_function)(const likely_matrix *srcA, const likely_matrix *srcB, likely_matrix *dst); | 96 | typedef void (*likely_binary_function)(const likely_matrix *srcA, const likely_matrix *srcB, likely_matrix *dst); |
| 97 | -BR_EXPORT likely_unary_function likely_make_unary_function(const char *description); | ||
| 98 | -BR_EXPORT likely_binary_function likely_make_binary_function(const char *description); | ||
| 99 | - | ||
| 100 | -typedef uint32_t (*likely_unary_allocation)(const likely_matrix *src, likely_matrix *dst); | ||
| 101 | -typedef uint32_t (*likely_binary_allocation)(const likely_matrix *srcA, const likely_matrix *srcB, likely_matrix *dst); | ||
| 102 | -BR_EXPORT likely_unary_allocation likely_make_unary_allocation(const char *description, const likely_matrix *src); | ||
| 103 | -BR_EXPORT likely_binary_allocation likely_make_binary_allocation(const char *description, const likely_matrix *src_a, const likely_matrix *src_b); | ||
| 104 | - | ||
| 105 | -typedef void (*likely_unary_kernel)(const likely_matrix *src, likely_matrix *dst, uint32_t size); | ||
| 106 | -typedef void (*likely_binary_kernel)(const likely_matrix *srcA, const likely_matrix *srcB, likely_matrix *dst, uint32_t size); | ||
| 107 | -BR_EXPORT likely_unary_kernel likely_make_unary_kernel(const char *description, const likely_matrix *src); | ||
| 108 | -BR_EXPORT likely_binary_kernel likely_make_binary_kernel(const char *description, const likely_matrix *src_a, const likely_matrix *src_b); | 97 | +LIKELY_EXPORT likely_unary_function likely_make_unary_function(const char *description); |
| 98 | +LIKELY_EXPORT likely_binary_function likely_make_binary_function(const char *description); | ||
| 109 | 99 | ||
| 110 | #ifdef __cplusplus | 100 | #ifdef __cplusplus |
| 111 | } | 101 | } |
| @@ -162,16 +152,6 @@ typedef likely_binary_function BinaryFunction; | @@ -162,16 +152,6 @@ typedef likely_binary_function BinaryFunction; | ||
| 162 | inline UnaryFunction makeUnaryFunction(const char *description) { return likely_make_unary_function(description); } | 152 | inline UnaryFunction makeUnaryFunction(const char *description) { return likely_make_unary_function(description); } |
| 163 | inline BinaryFunction makeBinaryFunction(const char *description) { return likely_make_binary_function(description); } | 153 | inline BinaryFunction makeBinaryFunction(const char *description) { return likely_make_binary_function(description); } |
| 164 | 154 | ||
| 165 | -typedef likely_unary_allocation UnaryAllocation; | ||
| 166 | -typedef likely_binary_allocation BinaryAllocation; | ||
| 167 | -inline UnaryAllocation makeUnaryAllocation(const char *description, const Matrix &src) { return likely_make_unary_allocation(description, &src); } | ||
| 168 | -inline BinaryAllocation makeBinaryAllocation(const char *description, const Matrix &srcA, const Matrix &srcB) { return likely_make_binary_allocation(description, &srcA, &srcB); } | ||
| 169 | - | ||
| 170 | -typedef likely_unary_kernel UnaryKernel; | ||
| 171 | -typedef likely_binary_kernel BinaryKernel; | ||
| 172 | -inline UnaryKernel makeUnaryKernel(const char *description, const Matrix &src) { return likely_make_unary_kernel(description, &src); } | ||
| 173 | -inline BinaryKernel makeBinaryKernel(const char *description, const Matrix &srcA, const Matrix &srcB) { return likely_make_binary_kernel(description, &srcA, &srcB); } | ||
| 174 | - | ||
| 175 | } // namespace likely | 155 | } // namespace likely |
| 176 | 156 | ||
| 177 | #endif // __cplusplus | 157 | #endif // __cplusplus |
sdk/plugins/llvm.cpp
| @@ -27,12 +27,50 @@ using namespace br; | @@ -27,12 +27,50 @@ using namespace br; | ||
| 27 | using namespace cv; | 27 | using namespace cv; |
| 28 | using namespace llvm; | 28 | using namespace llvm; |
| 29 | 29 | ||
| 30 | +typedef uint32_t (*likely_unary_allocation)(const likely_matrix *src, likely_matrix *dst); | ||
| 31 | +typedef uint32_t (*likely_binary_allocation)(const likely_matrix *srcA, const likely_matrix *srcB, likely_matrix *dst); | ||
| 32 | +typedef void (*likely_unary_kernel)(const likely_matrix *src, likely_matrix *dst, uint32_t size); | ||
| 33 | +typedef void (*likely_binary_kernel)(const likely_matrix *srcA, const likely_matrix *srcB, likely_matrix *dst, uint32_t size); | ||
| 34 | + | ||
| 30 | static Module *TheModule = NULL; | 35 | static Module *TheModule = NULL; |
| 31 | static ExecutionEngine *TheExecutionEngine = NULL; | 36 | static ExecutionEngine *TheExecutionEngine = NULL; |
| 32 | static FunctionPassManager *TheFunctionPassManager = NULL; | 37 | static FunctionPassManager *TheFunctionPassManager = NULL; |
| 33 | static FunctionPassManager *TheExtraFunctionPassManager = NULL; | 38 | static FunctionPassManager *TheExtraFunctionPassManager = NULL; |
| 34 | static StructType *TheMatrixStruct = NULL; | 39 | static StructType *TheMatrixStruct = NULL; |
| 35 | 40 | ||
| 41 | +static void likely_initialize() | ||
| 42 | +{ | ||
| 43 | + InitializeNativeTarget(); | ||
| 44 | + | ||
| 45 | + TheModule = new Module("likely", getGlobalContext()); | ||
| 46 | + | ||
| 47 | + std::string error; | ||
| 48 | + TheExecutionEngine = EngineBuilder(TheModule).setEngineKind(EngineKind::JIT).setErrorStr(&error).create(); | ||
| 49 | + if (TheExecutionEngine == NULL) | ||
| 50 | + qFatal("Failed to create LLVM ExecutionEngine with error: %s", error.c_str()); | ||
| 51 | + | ||
| 52 | + TheFunctionPassManager = new FunctionPassManager(TheModule); | ||
| 53 | + TheFunctionPassManager->add(createVerifierPass(PrintMessageAction)); | ||
| 54 | + TheFunctionPassManager->add(createEarlyCSEPass()); | ||
| 55 | + TheFunctionPassManager->add(createInstructionCombiningPass()); | ||
| 56 | + TheFunctionPassManager->add(createDeadCodeEliminationPass()); | ||
| 57 | + TheFunctionPassManager->add(createGVNPass()); | ||
| 58 | + TheFunctionPassManager->add(createDeadInstEliminationPass()); | ||
| 59 | + | ||
| 60 | + TheExtraFunctionPassManager = new FunctionPassManager(TheModule); | ||
| 61 | + TheExtraFunctionPassManager->add(createPrintFunctionPass("--------------------------------------------------------------------------------", &errs())); | ||
| 62 | +// TheExtraFunctionPassManager->add(createLoopUnrollPass(INT_MAX,8)); | ||
| 63 | + | ||
| 64 | + TheMatrixStruct = StructType::create("Matrix", | ||
| 65 | + Type::getInt8PtrTy(getGlobalContext()), // data | ||
| 66 | + Type::getInt32Ty(getGlobalContext()), // channels | ||
| 67 | + Type::getInt32Ty(getGlobalContext()), // columns | ||
| 68 | + Type::getInt32Ty(getGlobalContext()), // rows | ||
| 69 | + Type::getInt32Ty(getGlobalContext()), // frames | ||
| 70 | + Type::getInt16Ty(getGlobalContext()), // hash | ||
| 71 | + NULL); | ||
| 72 | +} | ||
| 73 | + | ||
| 36 | static QString MatrixToString(const likely_matrix *m) | 74 | static QString MatrixToString(const likely_matrix *m) |
| 37 | { | 75 | { |
| 38 | return QString("%1%2%3%4%5%6%7").arg(QString::number(likely_bits(m)), (likely_is_signed(m) ? "s" : "u"), (likely_is_floating(m) ? "f" : "i"), | 76 | return QString("%1%2%3%4%5%6%7").arg(QString::number(likely_bits(m)), (likely_is_signed(m) ? "s" : "u"), (likely_is_floating(m) ? "f" : "i"), |
| @@ -353,6 +391,8 @@ public: | @@ -353,6 +391,8 @@ public: | ||
| 353 | 391 | ||
| 354 | likely_unary_function getFunction() const | 392 | likely_unary_function getFunction() const |
| 355 | { | 393 | { |
| 394 | + if (TheModule == NULL) likely_initialize(); | ||
| 395 | + | ||
| 356 | const QString name = mangledName(); | 396 | const QString name = mangledName(); |
| 357 | Function *function = TheModule->getFunction(qPrintable(name)); | 397 | Function *function = TheModule->getFunction(qPrintable(name)); |
| 358 | 398 | ||
| @@ -537,7 +577,7 @@ private: | @@ -537,7 +577,7 @@ private: | ||
| 537 | const QString args = arguments().join(","); | 577 | const QString args = arguments().join(","); |
| 538 | if (!argsLUT.contains(args)) argsLUT.insert(args, argsLUT.size()); | 578 | if (!argsLUT.contains(args)) argsLUT.insert(args, argsLUT.size()); |
| 539 | int uid = argsLUT.value(args); | 579 | int uid = argsLUT.value(args); |
| 540 | - return "jitcv_" + objectName() + (args.isEmpty() ? QString() : QString::number(uid)); | 580 | + return "likely_" + objectName() + (args.isEmpty() ? QString() : QString::number(uid)); |
| 541 | } | 581 | } |
| 542 | 582 | ||
| 543 | QString mangledName(const likely_matrix &src) const | 583 | QString mangledName(const likely_matrix &src) const |
| @@ -583,7 +623,7 @@ QHash<uint32_t, File> UnaryTransform::fileTable; | @@ -583,7 +623,7 @@ QHash<uint32_t, File> UnaryTransform::fileTable; | ||
| 583 | //private: | 623 | //private: |
| 584 | // QString mangledName(const Matrix &srcA, const Matrix &srcB) const | 624 | // QString mangledName(const Matrix &srcA, const Matrix &srcB) const |
| 585 | // { | 625 | // { |
| 586 | -// return "jitcv_" + objectName() + "_" + MatrixToString(srcA) + "_" + MatrixToString(srcB); | 626 | +// return "likely_" + objectName() + "_" + MatrixToString(srcA) + "_" + MatrixToString(srcB); |
| 587 | // } | 627 | // } |
| 588 | 628 | ||
| 589 | // Function *compile(const Matrix &m, const Matrix &n) const | 629 | // Function *compile(const Matrix &m, const Matrix &n) const |
| @@ -1051,36 +1091,6 @@ class LLVMInitializer : public Initializer | @@ -1051,36 +1091,6 @@ class LLVMInitializer : public Initializer | ||
| 1051 | 1091 | ||
| 1052 | void initialize() const | 1092 | void initialize() const |
| 1053 | { | 1093 | { |
| 1054 | - InitializeNativeTarget(); | ||
| 1055 | - | ||
| 1056 | - TheModule = new Module("jitcv", getGlobalContext()); | ||
| 1057 | - | ||
| 1058 | - std::string error; | ||
| 1059 | - TheExecutionEngine = EngineBuilder(TheModule).setEngineKind(EngineKind::JIT).setErrorStr(&error).create(); | ||
| 1060 | - if (TheExecutionEngine == NULL) | ||
| 1061 | - qFatal("Failed to create LLVM ExecutionEngine with error: %s", error.c_str()); | ||
| 1062 | - | ||
| 1063 | - TheFunctionPassManager = new FunctionPassManager(TheModule); | ||
| 1064 | - TheFunctionPassManager->add(createVerifierPass(PrintMessageAction)); | ||
| 1065 | - TheFunctionPassManager->add(createEarlyCSEPass()); | ||
| 1066 | - TheFunctionPassManager->add(createInstructionCombiningPass()); | ||
| 1067 | - TheFunctionPassManager->add(createDeadCodeEliminationPass()); | ||
| 1068 | - TheFunctionPassManager->add(createGVNPass()); | ||
| 1069 | - TheFunctionPassManager->add(createDeadInstEliminationPass()); | ||
| 1070 | - | ||
| 1071 | - TheExtraFunctionPassManager = new FunctionPassManager(TheModule); | ||
| 1072 | - TheExtraFunctionPassManager->add(createPrintFunctionPass("--------------------------------------------------------------------------------", &errs())); | ||
| 1073 | -// TheExtraFunctionPassManager->add(createLoopUnrollPass(INT_MAX,8)); | ||
| 1074 | - | ||
| 1075 | - TheMatrixStruct = StructType::create("Matrix", | ||
| 1076 | - Type::getInt8PtrTy(getGlobalContext()), // data | ||
| 1077 | - Type::getInt32Ty(getGlobalContext()), // channels | ||
| 1078 | - Type::getInt32Ty(getGlobalContext()), // columns | ||
| 1079 | - Type::getInt32Ty(getGlobalContext()), // rows | ||
| 1080 | - Type::getInt32Ty(getGlobalContext()), // frames | ||
| 1081 | - Type::getInt16Ty(getGlobalContext()), // hash | ||
| 1082 | - NULL); | ||
| 1083 | - | ||
| 1084 | QSharedPointer<Transform> kernel(Transform::make("add(1)", NULL)); | 1094 | QSharedPointer<Transform> kernel(Transform::make("add(1)", NULL)); |
| 1085 | 1095 | ||
| 1086 | Template src, dst; | 1096 | Template src, dst; |
| @@ -1101,13 +1111,6 @@ class LLVMInitializer : public Initializer | @@ -1101,13 +1111,6 @@ class LLVMInitializer : public Initializer | ||
| 1101 | qDebug() << dst.m(); | 1111 | qDebug() << dst.m(); |
| 1102 | } | 1112 | } |
| 1103 | 1113 | ||
| 1104 | - void finalize() const | ||
| 1105 | - { | ||
| 1106 | - delete TheFunctionPassManager; | ||
| 1107 | - delete TheExecutionEngine; | ||
| 1108 | - llvm_shutdown(); | ||
| 1109 | - } | ||
| 1110 | - | ||
| 1111 | static void benchmark(const QString &transform) | 1114 | static void benchmark(const QString &transform) |
| 1112 | { | 1115 | { |
| 1113 | static Template src; | 1116 | static Template src; |
| @@ -1157,7 +1160,9 @@ likely_binary_function likely_make_binary_function(const char *description) | @@ -1157,7 +1160,9 @@ likely_binary_function likely_make_binary_function(const char *description) | ||
| 1157 | return NULL; | 1160 | return NULL; |
| 1158 | } | 1161 | } |
| 1159 | 1162 | ||
| 1160 | -likely_unary_allocation likely_make_unary_allocation(const char *description, const likely_matrix *src) | 1163 | +extern "C" { |
| 1164 | + | ||
| 1165 | +LIKELY_EXPORT likely_unary_allocation likely_make_unary_allocation(const char *description, const likely_matrix *src) | ||
| 1161 | { | 1166 | { |
| 1162 | if (description == NULL) qFatal("makeUnaryAllocation NULL description!"); | 1167 | if (description == NULL) qFatal("makeUnaryAllocation NULL description!"); |
| 1163 | const File f = long(description) < 1000 ? UnaryTransform::fileTable[long(description)] : File(description); | 1168 | const File f = long(description) < 1000 ? UnaryTransform::fileTable[long(description)] : File(description); |
| @@ -1166,7 +1171,7 @@ likely_unary_allocation likely_make_unary_allocation(const char *description, co | @@ -1166,7 +1171,7 @@ likely_unary_allocation likely_make_unary_allocation(const char *description, co | ||
| 1166 | return unaryTransform->getAllocation(src); | 1171 | return unaryTransform->getAllocation(src); |
| 1167 | } | 1172 | } |
| 1168 | 1173 | ||
| 1169 | -likely_binary_allocation likely_make_binary_allocation(const char *description, const likely_matrix *src_a, const likely_matrix *src_b) | 1174 | +LIKELY_EXPORT likely_binary_allocation likely_make_binary_allocation(const char *description, const likely_matrix *src_a, const likely_matrix *src_b) |
| 1170 | { | 1175 | { |
| 1171 | (void) description; | 1176 | (void) description; |
| 1172 | (void) src_a; | 1177 | (void) src_a; |
| @@ -1174,7 +1179,7 @@ likely_binary_allocation likely_make_binary_allocation(const char *description, | @@ -1174,7 +1179,7 @@ likely_binary_allocation likely_make_binary_allocation(const char *description, | ||
| 1174 | return NULL; | 1179 | return NULL; |
| 1175 | } | 1180 | } |
| 1176 | 1181 | ||
| 1177 | -likely_unary_kernel likely_make_unary_kernel(const char *description, const likely_matrix *src) | 1182 | +LIKELY_EXPORT likely_unary_kernel likely_make_unary_kernel(const char *description, const likely_matrix *src) |
| 1178 | { | 1183 | { |
| 1179 | if (description == NULL) qFatal("makeUnaryKernel NULL description!"); | 1184 | if (description == NULL) qFatal("makeUnaryKernel NULL description!"); |
| 1180 | const File f = long(description) < 1000 ? UnaryTransform::fileTable[long(description)] : File(description); | 1185 | const File f = long(description) < 1000 ? UnaryTransform::fileTable[long(description)] : File(description); |
| @@ -1183,7 +1188,7 @@ likely_unary_kernel likely_make_unary_kernel(const char *description, const like | @@ -1183,7 +1188,7 @@ likely_unary_kernel likely_make_unary_kernel(const char *description, const like | ||
| 1183 | return unaryTransform->getKernel(src); | 1188 | return unaryTransform->getKernel(src); |
| 1184 | } | 1189 | } |
| 1185 | 1190 | ||
| 1186 | -likely_binary_kernel likely_make_binary_kernel(const char *description, const likely_matrix *src_a, const likely_matrix *src_b) | 1191 | +LIKELY_EXPORT likely_binary_kernel likely_make_binary_kernel(const char *description, const likely_matrix *src_a, const likely_matrix *src_b) |
| 1187 | { | 1192 | { |
| 1188 | (void) description; | 1193 | (void) description; |
| 1189 | (void) src_a; | 1194 | (void) src_a; |
| @@ -1191,4 +1196,6 @@ likely_binary_kernel likely_make_binary_kernel(const char *description, const li | @@ -1191,4 +1196,6 @@ likely_binary_kernel likely_make_binary_kernel(const char *description, const li | ||
| 1191 | return NULL; | 1196 | return NULL; |
| 1192 | } | 1197 | } |
| 1193 | 1198 | ||
| 1199 | +} // extern "C" | ||
| 1200 | + | ||
| 1194 | #include "llvm.moc" | 1201 | #include "llvm.moc" |