diff --git a/CMakeLists.txt b/CMakeLists.txt index b179baca..79e59cec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,14 +68,13 @@ endif() foreach(lib ${TREELITE_TARGETS}) set_output_directory(${lib} ${PROJECT_BINARY_DIR}) - target_link_libraries(${lib} INTERFACE dmlc) endforeach() # Export install targets include(GNUInstallDirs) include(CMakePackageConfigHelpers) set(INSTALL_TARGETS ${TREELITE_TARGETS} - objtreelite objtreelite_common objtreelite_runtime dmlc rapidjson) + objtreelite objtreelite_common objtreelite_runtime rapidjson) if(NOT FMTLIB_FROM_SYSTEM_ROOT) list(APPEND INSTALL_TARGETS fmt-header-only) endif() diff --git a/cmake/ExternalLibs.cmake b/cmake/ExternalLibs.cmake index c331462b..9612759c 100644 --- a/cmake/ExternalLibs.cmake +++ b/cmake/ExternalLibs.cmake @@ -1,19 +1,6 @@ include(FetchContent) include(cmake/FetchContentMakeAvailable.cmake) -FetchContent_Declare( - dmlccore - GIT_REPOSITORY https://github.com/dmlc/dmlc-core - GIT_TAG v0.5 -) -FetchContent_MakeAvailable(dmlccore) -target_compile_options(dmlc PRIVATE - -D_CRT_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE) -if (TARGET dmlc_unit_tests) - target_compile_options(dmlc_unit_tests PRIVATE - -D_CRT_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE) -endif (TARGET dmlc_unit_tests) - # fmtlib find_package(fmt) if(fmt_FOUND) diff --git a/include/treelite/predictor.h b/include/treelite/predictor.h index 4fde1091..38f9a552 100644 --- a/include/treelite/predictor.h +++ b/include/treelite/predictor.h @@ -7,7 +7,6 @@ #ifndef TREELITE_PREDICTOR_H_ #define TREELITE_PREDICTOR_H_ -#include #include #include #include @@ -20,6 +19,45 @@ namespace treelite { namespace predictor { +/*! + * \brief OMP Exception class catches, saves and rethrows exception from OMP blocks + */ +class OMPException { + private: + // exception_ptr member to store the exception + std::exception_ptr omp_exception_; + // mutex to be acquired during catch to set the exception_ptr + std::mutex mutex_; + + public: + /*! + * \brief Parallel OMP blocks should be placed within Run to save exception + */ + template + void Run(Function f, Parameters... params) { + try { + f(params...); + } catch (treelite::Error &ex) { + std::lock_guard lock(mutex_); + if (!omp_exception_) { + omp_exception_ = std::current_exception(); + } + } catch (std::exception &ex) { + std::lock_guard lock(mutex_); + if (!omp_exception_) { + omp_exception_ = std::current_exception(); + } + } + } + + /*! + * \brief should be called from the main thread to rethrow the exception + */ + void Rethrow() { + if (this->omp_exception_) std::rethrow_exception(this->omp_exception_); + } +}; + /*! \brief data layout. The value -1 signifies the missing value. When the "missing" field is set to -1, the "fvalue" field is set to NaN (Not a Number), so there is no danger for mistaking between @@ -207,7 +245,7 @@ class Predictor { TypeInfo threshold_type_; TypeInfo leaf_output_type_; - mutable dmlc::OMPException exception_catcher_; + mutable OMPException exception_catcher_; }; } // namespace predictor diff --git a/runtime/java/CMakeLists.txt b/runtime/java/CMakeLists.txt index f656ba19..41c7a722 100644 --- a/runtime/java/CMakeLists.txt +++ b/runtime/java/CMakeLists.txt @@ -2,8 +2,7 @@ find_package(JNI REQUIRED) add_library(treelite4j SHARED treelite4j/src/native/treelite4j.cpp) target_link_libraries(treelite4j - PRIVATE objtreelite_runtime objtreelite_common - PUBLIC ${JAVA_JVM_LIBRARY} dmlc) + PRIVATE objtreelite_runtime objtreelite_common) target_include_directories(treelite4j PUBLIC ${JNI_INCLUDE_DIRS}) set_target_properties(treelite4j PROPERTIES diff --git a/runtime/java/treelite4j/src/native/treelite4j.cpp b/runtime/java/treelite4j/src/native/treelite4j.cpp index dcb192fd..bc0d5c25 100644 --- a/runtime/java/treelite4j/src/native/treelite4j.cpp +++ b/runtime/java/treelite4j/src/native/treelite4j.cpp @@ -3,9 +3,6 @@ #include #include #include -#include -#include -#include #include #include #include diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b0857613..cee954ff 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -33,7 +33,6 @@ foreach(lib objtreelite objtreelite_runtime objtreelite_common) $ $ $/include>) - target_link_libraries(${lib} PUBLIC dmlc) if(MSVC) target_compile_options(${lib} PRIVATE /MP) target_compile_definitions(${lib} PRIVATE -DNOMINMAX) diff --git a/src/annotator.cc b/src/annotator.cc index ae4f8d9d..668f7a69 100644 --- a/src/annotator.cc +++ b/src/annotator.cc @@ -13,7 +13,6 @@ #include #include #include -#include #include #include diff --git a/src/c_api/c_api.cc b/src/c_api/c_api.cc index 9fa7df89..795f1107 100644 --- a/src/c_api/c_api.cc +++ b/src/c_api/c_api.cc @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include diff --git a/src/compiler/ast/build.cc b/src/compiler/ast/build.cc index 62eac7a0..e4bc6cd2 100644 --- a/src/compiler/ast/build.cc +++ b/src/compiler/ast/build.cc @@ -1,16 +1,13 @@ /*! - * Copyright (c) 2017-2020 by Contributors + * Copyright (c) 2017-2021 by Contributors * \file build.cc * \brief Build AST from a given model */ -#include #include "./builder.h" namespace treelite { namespace compiler { -DMLC_REGISTRY_FILE_TAG(build); - template void ASTBuilder::BuildAST( diff --git a/src/compiler/ast/dump.cc b/src/compiler/ast/dump.cc index 3cb521cd..c2f7c317 100644 --- a/src/compiler/ast/dump.cc +++ b/src/compiler/ast/dump.cc @@ -1,9 +1,8 @@ /*! - * Copyright (c) 2019-2020 by Contributors + * Copyright (c) 2019-2021 by Contributors * \file dump.cc * \brief Generate text representation of AST */ -#include #include #include "./builder.h" @@ -24,8 +23,6 @@ void get_dump_from_node(std::ostringstream* oss, namespace treelite { namespace compiler { -DMLC_REGISTRY_FILE_TAG(dump); - template std::string ASTBuilder::GetDump() const { diff --git a/src/compiler/ast/fold_code.cc b/src/compiler/ast/fold_code.cc index f896d85a..71a89e9c 100644 --- a/src/compiler/ast/fold_code.cc +++ b/src/compiler/ast/fold_code.cc @@ -1,10 +1,9 @@ /*! - * Copyright (c) 2017-2020 by Contributors + * Copyright (c) 2017-2021 by Contributors * \file fold_code.h * \brief AST manipulation logic for code folding * \author Hyunsu Cho */ -#include #include #include #include @@ -13,8 +12,6 @@ namespace treelite { namespace compiler { -DMLC_REGISTRY_FILE_TAG(fold_code); - struct CodeFoldingContext { double magnitude_req; double log_root_data_count; diff --git a/src/compiler/ast/is_categorical_array.cc b/src/compiler/ast/is_categorical_array.cc index 38df8488..50c6e29d 100644 --- a/src/compiler/ast/is_categorical_array.cc +++ b/src/compiler/ast/is_categorical_array.cc @@ -1,17 +1,14 @@ /*! - * Copyright (c) 2017-2020 by Contributors + * Copyright (c) 2017-2021 by Contributors * \file is_categorical_array.cc * \brief AST manipulation logic to determine whether each feature is categorical or not * \author Hyunsu Cho */ -#include #include "./builder.h" namespace treelite { namespace compiler { -DMLC_REGISTRY_FILE_TAG(is_categorical_array); - static void scan_thresholds(ASTNode* node, std::vector* is_categorical) { CategoricalConditionNode* cat_cond diff --git a/src/compiler/ast/load_data_counts.cc b/src/compiler/ast/load_data_counts.cc index 61c79195..d45b78f5 100644 --- a/src/compiler/ast/load_data_counts.cc +++ b/src/compiler/ast/load_data_counts.cc @@ -4,15 +4,12 @@ * \brief AST manipulation logic to load data counts * \author Hyunsu Cho */ -#include #include #include "./builder.h" namespace treelite { namespace compiler { -DMLC_REGISTRY_FILE_TAG(load_data_counts); - static void load_data_counts(ASTNode* node, const std::vector>& counts) { if (node->tree_id >= 0 && node->node_id >= 0) { node->data_count = counts[node->tree_id][node->node_id]; diff --git a/src/compiler/ast/quantize.cc b/src/compiler/ast/quantize.cc index b29c3f79..f39a7d9c 100644 --- a/src/compiler/ast/quantize.cc +++ b/src/compiler/ast/quantize.cc @@ -1,10 +1,9 @@ /*! - * Copyright (c) 2017-2020 by Contributors + * Copyright (c) 2017-2021 by Contributors * \file quantize.cc * \brief Quantize thresholds in condition nodes */ #include -#include #include #include #include @@ -13,8 +12,6 @@ namespace treelite { namespace compiler { -DMLC_REGISTRY_FILE_TAG(quantize); - template static void scan_thresholds(ASTNode* node, std::vector>* cut_pts) { diff --git a/src/compiler/ast/split.cc b/src/compiler/ast/split.cc index f0203d24..a7358417 100644 --- a/src/compiler/ast/split.cc +++ b/src/compiler/ast/split.cc @@ -1,17 +1,14 @@ /*! - * Copyright (c) 2017-2020 by Contributors + * Copyright (c) 2017-2021 by Contributors * \file split.cc * \brief Split prediction subroutine into multiple translation units (files) */ -#include #include #include "./builder.h" namespace treelite { namespace compiler { -DMLC_REGISTRY_FILE_TAG(split); - int count_tu_nodes(ASTNode* node) { int accum = (dynamic_cast(node)) ? 1 : 0; for (ASTNode* child : node->children) { diff --git a/src/compiler/ast_native.cc b/src/compiler/ast_native.cc index b26c37e9..a35d32e4 100644 --- a/src/compiler/ast_native.cc +++ b/src/compiler/ast_native.cc @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include diff --git a/src/compiler/compiler.cc b/src/compiler/compiler.cc index 74d5541d..03d8abb6 100644 --- a/src/compiler/compiler.cc +++ b/src/compiler/compiler.cc @@ -12,6 +12,7 @@ #include "./failsafe.h" namespace treelite { + Compiler* Compiler::Create(const std::string& name, const char* param_json_str) { compiler::CompilerParam param = compiler::CompilerParam::ParseFromJSON(param_json_str); if (name == "ast_native") { diff --git a/src/compiler/elf/elf_formatter.cc b/src/compiler/elf/elf_formatter.cc index d6739d6c..fe457c10 100644 --- a/src/compiler/elf/elf_formatter.cc +++ b/src/compiler/elf/elf_formatter.cc @@ -1,11 +1,10 @@ /*! - * Copyright (c) 2019-2020 by Contributors + * Copyright (c) 2019-2021 by Contributors * \file elf_formatter.cc * \author Hyunsu Cho * \brief Generate a relocatable object file containing a constant, read-only array */ #include -#include #include #include #include @@ -41,8 +40,6 @@ void AppendToBuffer(std::vector* dest, const void* src, size_t count) { namespace treelite { namespace compiler { -DMLC_REGISTRY_FILE_TAG(elf_formatter); - void AllocateELFHeader(std::vector* elf_buffer) { elf_buffer->resize(elf_buffer->size() + sizeof(Elf64_Ehdr)); } diff --git a/src/data.cc b/src/data.cc index 2f265982..e2346fea 100644 --- a/src/data.cc +++ b/src/data.cc @@ -5,7 +5,6 @@ * \brief Input data structure of Treelite */ -#include #include #include #include diff --git a/src/frontend/builder.cc b/src/frontend/builder.cc index 58ec9fbd..f94095fc 100644 --- a/src/frontend/builder.cc +++ b/src/frontend/builder.cc @@ -1,11 +1,10 @@ /*! - * Copyright (c) 2017-2020 by Contributors + * Copyright (c) 2017-2021 by Contributors * \file builder.cc * \brief model builder frontend * \author Hyunsu Cho */ -#include #include #include #include @@ -66,8 +65,6 @@ struct TreeDraft { namespace treelite { namespace frontend { -DMLC_REGISTRY_FILE_TAG(builder); - struct TreeBuilderImpl { TreeDraft tree; inline TreeBuilderImpl(TypeInfo threshold_type, TypeInfo leaf_output_type) diff --git a/src/frontend/lightgbm.cc b/src/frontend/lightgbm.cc index 76c2533d..3af3a0e7 100644 --- a/src/frontend/lightgbm.cc +++ b/src/frontend/lightgbm.cc @@ -5,7 +5,6 @@ * \author Hyunsu Cho */ -#include #include #include #include diff --git a/src/frontend/xgboost_json.cc b/src/frontend/xgboost_json.cc index b7b1524a..cec943a0 100644 --- a/src/frontend/xgboost_json.cc +++ b/src/frontend/xgboost_json.cc @@ -8,7 +8,6 @@ #include "xgboost/xgboost_json.h" -#include #include #include #include @@ -40,8 +39,6 @@ std::unique_ptr ParseStream(std::unique_ptr input_s namespace treelite { namespace frontend { -DMLC_REGISTRY_FILE_TAG(xgboost_json); - std::unique_ptr LoadXGBoostJSONModel(const char* filename) { char read_buffer[65536]; diff --git a/src/json_serializer.cc b/src/json_serializer.cc index 05bc9911..f93739ba 100644 --- a/src/json_serializer.cc +++ b/src/json_serializer.cc @@ -7,7 +7,7 @@ */ #include -#include +#include #include #include #include diff --git a/tests/cpp/test_compiler_param.cc b/tests/cpp/test_compiler_param.cc index 76426e9a..74972965 100644 --- a/tests/cpp/test_compiler_param.cc +++ b/tests/cpp/test_compiler_param.cc @@ -8,7 +8,6 @@ #include #include #include -#include #include using namespace testing;