Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
13 changes: 0 additions & 13 deletions cmake/ExternalLibs.cmake
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
42 changes: 40 additions & 2 deletions include/treelite/predictor.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#ifndef TREELITE_PREDICTOR_H_
#define TREELITE_PREDICTOR_H_

#include <dmlc/common.h>
#include <treelite/logging.h>
#include <treelite/typeinfo.h>
#include <treelite/c_api_runtime.h>
Expand All @@ -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 <typename Function, typename... Parameters>
void Run(Function f, Parameters... params) {
try {
f(params...);
} catch (treelite::Error &ex) {
std::lock_guard<std::mutex> lock(mutex_);
if (!omp_exception_) {
omp_exception_ = std::current_exception();
}
} catch (std::exception &ex) {
std::lock_guard<std::mutex> 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
Expand Down Expand Up @@ -207,7 +245,7 @@ class Predictor {
TypeInfo threshold_type_;
TypeInfo leaf_output_type_;

mutable dmlc::OMPException exception_catcher_;
mutable OMPException exception_catcher_;
};

} // namespace predictor
Expand Down
3 changes: 1 addition & 2 deletions runtime/java/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions runtime/java/treelite4j/src/native/treelite4j.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
#include <treelite/c_api_error.h>
#include <treelite/predictor.h>
#include <treelite/typeinfo.h>
#include <dmlc/endian.h>
#include <dmlc/logging.h>
#include <dmlc/memory_io.h>
#include <algorithm>
#include <limits>
#include <vector>
Expand Down
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ foreach(lib objtreelite objtreelite_runtime objtreelite_common)
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>)
target_link_libraries(${lib} PUBLIC dmlc)
if(MSVC)
target_compile_options(${lib} PRIVATE /MP)
target_compile_definitions(${lib} PRIVATE -DNOMINMAX)
Expand Down
1 change: 0 additions & 1 deletion src/annotator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <rapidjson/ostreamwrapper.h>
#include <rapidjson/writer.h>
#include <rapidjson/document.h>
#include <dmlc/io.h>
#include <limits>
#include <cstdint>

Expand Down
1 change: 0 additions & 1 deletion src/c_api/c_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <treelite/math.h>
#include <treelite/gtil.h>
#include <treelite/logging.h>
#include <dmlc/io.h>
#include <memory>
#include <algorithm>
#include <fstream>
Expand Down
5 changes: 1 addition & 4 deletions src/compiler/ast/build.cc
Original file line number Diff line number Diff line change
@@ -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 <dmlc/registry.h>
#include "./builder.h"

namespace treelite {
namespace compiler {

DMLC_REGISTRY_FILE_TAG(build);

template <typename ThresholdType, typename LeafOutputType>
void
ASTBuilder<ThresholdType, LeafOutputType>::BuildAST(
Expand Down
5 changes: 1 addition & 4 deletions src/compiler/ast/dump.cc
Original file line number Diff line number Diff line change
@@ -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 <dmlc/registry.h>
#include <treelite/logging.h>
#include "./builder.h"

Expand All @@ -24,8 +23,6 @@ void get_dump_from_node(std::ostringstream* oss,
namespace treelite {
namespace compiler {

DMLC_REGISTRY_FILE_TAG(dump);

template <typename ThresholdType, typename LeafOutputType>
std::string
ASTBuilder<ThresholdType, LeafOutputType>::GetDump() const {
Expand Down
5 changes: 1 addition & 4 deletions src/compiler/ast/fold_code.cc
Original file line number Diff line number Diff line change
@@ -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 <dmlc/registry.h>
#include <treelite/logging.h>
#include <limits>
#include <cmath>
Expand All @@ -13,8 +12,6 @@
namespace treelite {
namespace compiler {

DMLC_REGISTRY_FILE_TAG(fold_code);

struct CodeFoldingContext {
double magnitude_req;
double log_root_data_count;
Expand Down
5 changes: 1 addition & 4 deletions src/compiler/ast/is_categorical_array.cc
Original file line number Diff line number Diff line change
@@ -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 <dmlc/registry.h>
#include "./builder.h"

namespace treelite {
namespace compiler {

DMLC_REGISTRY_FILE_TAG(is_categorical_array);

static void
scan_thresholds(ASTNode* node, std::vector<bool>* is_categorical) {
CategoricalConditionNode* cat_cond
Expand Down
3 changes: 0 additions & 3 deletions src/compiler/ast/load_data_counts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@
* \brief AST manipulation logic to load data counts
* \author Hyunsu Cho
*/
#include <dmlc/registry.h>
#include <cstdint>
#include "./builder.h"

namespace treelite {
namespace compiler {

DMLC_REGISTRY_FILE_TAG(load_data_counts);

static void load_data_counts(ASTNode* node, const std::vector<std::vector<uint64_t>>& counts) {
if (node->tree_id >= 0 && node->node_id >= 0) {
node->data_count = counts[node->tree_id][node->node_id];
Expand Down
5 changes: 1 addition & 4 deletions src/compiler/ast/quantize.cc
Original file line number Diff line number Diff line change
@@ -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 <treelite/math.h>
#include <dmlc/registry.h>
#include <treelite/logging.h>
#include <set>
#include <cmath>
Expand All @@ -13,8 +12,6 @@
namespace treelite {
namespace compiler {

DMLC_REGISTRY_FILE_TAG(quantize);

template <typename ThresholdType>
static void
scan_thresholds(ASTNode* node, std::vector<std::set<ThresholdType>>* cut_pts) {
Expand Down
5 changes: 1 addition & 4 deletions src/compiler/ast/split.cc
Original file line number Diff line number Diff line change
@@ -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 <dmlc/registry.h>
#include <treelite/logging.h>
#include "./builder.h"

namespace treelite {
namespace compiler {

DMLC_REGISTRY_FILE_TAG(split);

int count_tu_nodes(ASTNode* node) {
int accum = (dynamic_cast<TranslationUnitNode*>(node)) ? 1 : 0;
for (ASTNode* child : node->children) {
Expand Down
1 change: 0 additions & 1 deletion src/compiler/ast_native.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <treelite/compiler.h>
#include <treelite/compiler_param.h>
#include <treelite/annotator.h>
#include <dmlc/io.h>
#include <fmt/format.h>
#include <rapidjson/stringbuffer.h>
#include <rapidjson/writer.h>
Expand Down
1 change: 1 addition & 0 deletions src/compiler/compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
5 changes: 1 addition & 4 deletions src/compiler/elf/elf_formatter.cc
Original file line number Diff line number Diff line change
@@ -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 <treelite/logging.h>
#include <dmlc/registry.h>
#include <fstream>
#include <iterator>
#include <stdexcept>
Expand Down Expand Up @@ -41,8 +40,6 @@ void AppendToBuffer(std::vector<char>* dest, const void* src, size_t count) {
namespace treelite {
namespace compiler {

DMLC_REGISTRY_FILE_TAG(elf_formatter);

void AllocateELFHeader(std::vector<char>* elf_buffer) {
elf_buffer->resize(elf_buffer->size() + sizeof(Elf64_Ehdr));
}
Expand Down
1 change: 0 additions & 1 deletion src/data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* \brief Input data structure of Treelite
*/

#include <dmlc/logging.h>
#include <treelite/logging.h>
#include <treelite/data.h>
#include <memory>
Expand Down
5 changes: 1 addition & 4 deletions src/frontend/builder.cc
Original file line number Diff line number Diff line change
@@ -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 <dmlc/registry.h>
#include <treelite/frontend.h>
#include <treelite/tree.h>
#include <treelite/logging.h>
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion src/frontend/lightgbm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* \author Hyunsu Cho
*/

#include <dmlc/data.h>
#include <treelite/logging.h>
#include <treelite/frontend.h>
#include <treelite/tree.h>
Expand Down
3 changes: 0 additions & 3 deletions src/frontend/xgboost_json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "xgboost/xgboost_json.h"

#include <dmlc/registry.h>
#include <fmt/format.h>
#include <rapidjson/error/en.h>
#include <rapidjson/document.h>
Expand Down Expand Up @@ -40,8 +39,6 @@ std::unique_ptr<treelite::Model> ParseStream(std::unique_ptr<StreamType> input_s
namespace treelite {
namespace frontend {

DMLC_REGISTRY_FILE_TAG(xgboost_json);

std::unique_ptr<treelite::Model> LoadXGBoostJSONModel(const char* filename) {
char read_buffer[65536];

Expand Down
2 changes: 1 addition & 1 deletion src/json_serializer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

#include <treelite/tree.h>
#include <dmlc/logging.h>
#include <treelite/logging.h>
#include <rapidjson/ostreamwrapper.h>
#include <rapidjson/writer.h>
#include <ostream>
Expand Down
1 change: 0 additions & 1 deletion tests/cpp/test_compiler_param.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <gmock/gmock.h>
#include <treelite/compiler_param.h>
#include <treelite/logging.h>
#include <dmlc/logging.h>
#include <fmt/format.h>

using namespace testing;
Expand Down