20 struct TreeliteRuntimeAPIThreadLocalEntry {
32 auto predictor = std::make_unique<predictor::Predictor>(num_worker_thread);
33 predictor->Load(library_path);
43 const auto* dmat =
static_cast<const DMatrix*
>(batch);
44 const size_t num_feature = predictor->QueryNumFeature();
45 const std::string err_msg
46 = std::string(
"Too many columns (features) in the given batch. " 47 "Number of features must not exceed ") + std::to_string(num_feature);
48 TREELITE_CHECK_LE(dmat->GetNumCol(), num_feature) << err_msg;
49 *out_result_size = predictor->PredictBatch(dmat, verbose, (pred_margin != 0), out_result);
57 const auto* dmat =
static_cast<const DMatrix*
>(batch);
58 *out_output_vector = predictor->CreateOutputVector(dmat);
73 const auto* dmat =
static_cast<const DMatrix*
>(batch);
74 *out = predictor->QueryResultSize(dmat);
96 std::string& ret_str = TreeliteRuntimeAPIThreadLocalStore::Get()->ret_str;
97 ret_str = pred_transform;
98 *out = ret_str.c_str();
116 int TreelitePredictorQueryThresholdType(
PredictorHandle handle,
const char** out) {
119 std::string& ret_str = TreeliteRuntimeAPIThreadLocalStore::Get()->ret_str;
121 *out = ret_str.c_str();
125 int TreelitePredictorQueryLeafOutputType(
PredictorHandle handle,
const char** out) {
128 std::string& ret_str = TreeliteRuntimeAPIThreadLocalStore::Get()->ret_str;
130 *out = ret_str.c_str();
Load prediction function exported as a shared library.
std::string QueryPredTransform() const
Get name of post prediction transformation used to train the loaded model.
#define API_BEGIN()
macro to guard beginning and end section of all functions
int TreeliteCreatePredictorOutputVector(PredictorHandle handle, DMatrixHandle batch, PredictorOutputHandle *out_output_vector)
Convenience function to allocate an output vector that is able to hold the prediction result for a gi...
int TreelitePredictorPredictBatch(PredictorHandle handle, DMatrixHandle batch, int verbose, int pred_margin, PredictorOutputHandle out_result, size_t *out_result_size)
Make predictions on a batch of data rows (synchronously). This function internally divides the worklo...
C API of Treelite, used for interfacing with other languages This header is used exclusively by the r...
void * PredictorOutputHandle
handle to output from predictor
size_t QueryNumFeature() const
Get the width (number of features) of each instance used to train the loaded model.
int TreelitePredictorQueryPredTransform(PredictorHandle handle, const char **out)
Get name of post prediction transformation used to train the loaded model.
void DeleteOutputVector(PredictorOutputHandle output_vector) const
Free an output vector from memory.
int TreelitePredictorQueryNumFeature(PredictorHandle handle, size_t *out)
Get the width (number of features) of each instance used to train the loaded model.
void * DMatrixHandle
handle to a data matrix
Helper class for thread-local storage.
Error handling for C API.
int TreelitePredictorLoad(const char *library_path, int num_worker_thread, PredictorHandle *out)
load prediction code into memory. This function assumes that the prediction code has been already com...
float QuerySigmoidAlpha() const
Get alpha value in sigmoid transformation used to train the loaded model.
std::string TypeInfoToString(treelite::TypeInfo type)
Get string representation of type info.
void * PredictorHandle
handle to predictor class
int TreeliteDeletePredictorOutputVector(PredictorHandle handle, PredictorOutputHandle output_vector)
De-allocate an output vector.
float QueryGlobalBias() const
Get global bias which adjusting predicted margin scores.
predictor class: wrapper for optimized prediction code
int TreelitePredictorFree(PredictorHandle handle)
delete predictor from memory
int TreelitePredictorQueryNumClass(PredictorHandle handle, size_t *out)
Get the number classes in the loaded model The number is 1 for most tasks; it is greater than 1 for m...
int TreelitePredictorQueryResultSize(PredictorHandle handle, DMatrixHandle batch, size_t *out)
Given a batch of data rows, query the necessary size of array to hold predictions for all data points...
size_t QueryNumClass() const
Get the number of classes in the loaded model The number is 1 for most tasks; it is greater than 1 fo...
int TreelitePredictorQuerySigmoidAlpha(PredictorHandle handle, float *out)
Get alpha value of sigmoid transformation used to train the loaded model.
#define API_END()
every function starts with API_BEGIN(); and finishes with API_END() or API_END_HANDLE_ERROR ...
int TreelitePredictorQueryGlobalBias(PredictorHandle handle, float *out)
Get global bias which adjusting predicted margin scores.