9 #include <rapidjson/document.h> 18 if (name ==
"ast_native") {
20 }
else if (name ==
"failsafe") {
23 TREELITE_LOG(FATAL) <<
"Unrecognized compiler '" << name <<
"'";
31 CompilerParam::ParseFromJSON(
const char* param_json_str) {
34 param.annotate_in =
"NULL";
36 param.parallel_comp = 0;
38 param.native_lib_name =
"predictor";
39 param.code_folding_req = std::numeric_limits<double>::infinity();
40 param.dump_array_as_elf = 0;
42 rapidjson::Document doc;
43 doc.Parse(param_json_str);
44 TREELITE_CHECK(doc.IsObject()) <<
"Got an invalid JSON string:\n" << param_json_str;
45 for (
const auto& e : doc.GetObject()) {
46 const std::string key = e.name.GetString();
47 if (key ==
"annotate_in") {
48 TREELITE_CHECK(e.value.IsString()) <<
"Expected a string for 'annotate_in'";
49 param.annotate_in = e.value.GetString();
50 }
else if (key ==
"quantize") {
51 TREELITE_CHECK(e.value.IsInt()) <<
"Expected an integer for 'quantize'";
52 param.quantize = e.value.GetInt();
53 TREELITE_CHECK_GE(param.quantize, 0) <<
"'quantize' must be 0 or greater";
54 }
else if (key ==
"parallel_comp") {
55 TREELITE_CHECK(e.value.IsInt()) <<
"Expected an integer for 'parallel_comp'";
56 param.parallel_comp = e.value.GetInt();
57 TREELITE_CHECK_GE(param.parallel_comp, 0) <<
"'parallel_comp' must be 0 or greater";
58 }
else if (key ==
"verbose") {
59 TREELITE_CHECK(e.value.IsInt()) <<
"Expected an integer for 'verbose'";
60 param.verbose = e.value.GetInt();
61 }
else if (key ==
"native_lib_name") {
62 TREELITE_CHECK(e.value.IsString()) <<
"Expected a string for 'native_lib_name'";
63 param.native_lib_name = e.value.GetString();
64 }
else if (key ==
"code_folding_req") {
65 TREELITE_CHECK(e.value.IsDouble())
66 <<
"Expected a floating-point decimal for 'code_folding_req'";
67 param.code_folding_req = e.value.GetDouble();
68 TREELITE_CHECK_GE(param.code_folding_req, 0) <<
"'code_folding_req' must be 0 or greater";
69 }
else if (key ==
"dump_array_as_elf") {
70 TREELITE_CHECK(e.value.IsInt()) <<
"Expected an integer for 'dump_array_as_elf'";
71 param.dump_array_as_elf = e.value.GetInt();
72 TREELITE_CHECK_GE(param.dump_array_as_elf, 0) <<
"'dump_array_as_elf' must be 0 or greater";
74 TREELITE_LOG(FATAL) <<
"Unrecognized key '" << key <<
"' in JSON";
Parameters for tree compiler.
parameters for tree compiler
logging facility for Treelite
Interface of compiler that compiles a tree ensemble model.
C code generator (fail-safe). The generated code will mimic prediction logic found in XGBoost...
static Compiler * Create(const std::string &name, const char *param_json_str)
create a compiler from given name