Classes | Typedefs | Enumerations | Functions | Variables
ML::fil Namespace Reference

Classes

struct  forest
 
struct  treelite_params_t
 

Typedefs

template<typename real_t >
using forest_t = forest< real_t > *
 
using forest32_t = forest< float > *
 
using forest64_t = forest< double > *
 
using forest_variant = std::variant< forest_t< float >, forest_t< double > >
 

Enumerations

enum  algo_t { ALGO_AUTO , NAIVE , TREE_REORG , BATCH_TREE_REORG }
 
enum  storage_type_t { AUTO , DENSE , SPARSE , SPARSE8 }
 
enum  precision_t { PRECISION_NATIVE , PRECISION_FLOAT32 , PRECISION_FLOAT64 }
 

Functions

void from_treelite (const raft::handle_t &handle, forest_variant *pforest, TreeliteModelHandle model, const treelite_params_t *tl_params)
 
template<typename real_t >
void free (const raft::handle_t &h, forest_t< real_t > f)
 
template<typename real_t >
void predict (const raft::handle_t &h, forest_t< real_t > f, real_t *preds, const real_t *data, size_t num_rows, bool predict_proba=false)
 

Variables

constexpr int MAX_N_ITEMS = 4
 

Typedef Documentation

◆ forest32_t

using ML::fil::forest32_t = typedef forest<float>*

forest32_t and forest64_t are definitions required in Cython

◆ forest64_t

using ML::fil::forest64_t = typedef forest<double>*

◆ forest_t

template<typename real_t >
using ML::fil::forest_t = typedef forest<real_t>*

forest_t is the predictor handle

◆ forest_variant

using ML::fil::forest_variant = typedef std::variant<forest_t<float>, forest_t<double> >

forest_variant is used to get a forest represented with either float or double.

Enumeration Type Documentation

◆ algo_t

Note
FIL supports inference with both single and double precision. However, the floating-point type used in the data and model must be the same. Inference algorithm to use.
Enumerator
ALGO_AUTO 

choose the algorithm automatically; currently chooses NAIVE for sparse forests and BATCH_TREE_REORG for dense ones

NAIVE 

naive algorithm: 1 thread block predicts 1 row; the row is cached in shared memory, and the trees are distributed cyclically between threads

TREE_REORG 

tree reorg algorithm: same as naive, but the tree nodes are rearranged into a more coalescing-friendly layout: for every node position, nodes of all trees at that position are stored next to each other

BATCH_TREE_REORG 

batch tree reorg algorithm: same as tree reorg, but predictions multiple rows (up to 4) in a single thread block

◆ precision_t

precision_t defines the precision of the FIL model imported from a treelite model

Enumerator
PRECISION_NATIVE 

use the native precision of the treelite model, i.e. float64 if it has weights or thresholds of type float64, otherwise float32

PRECISION_FLOAT32 

always create a float32 FIL model; this may lead to loss of precision if the treelite model contains float64 parameters

PRECISION_FLOAT64 

always create a float64 FIL model

◆ storage_type_t

storage_type_t defines whether to import the forests as dense or sparse

Enumerator
AUTO 

decide automatically; currently always builds dense forests

DENSE 

import the forest as dense (8 or 16-bytes nodes, depending on model precision

SPARSE 

import the forest as sparse (currently always with 16-byte nodes)

SPARSE8 

(experimental) import the forest as sparse with 8-byte nodes; can fail if 8-byte nodes are not enough to store the forest, e.g. there are too many nodes in a tree or too many features or the thresholds are double precision; note that the number of bits used to store the child or feature index can change in the future; this can affect whether a particular forest can be imported as SPARSE8

Function Documentation

◆ free()

template<typename real_t >
void ML::fil::free ( const raft::handle_t &  h,
forest_t< real_t >  f 
)

free deletes forest and all resources held by it; after this, forest is no longer usable

Parameters
hcuML handle used by this function
fthe forest to free; not usable after the call to this function

◆ from_treelite()

void ML::fil::from_treelite ( const raft::handle_t &  handle,
forest_variant pforest,
TreeliteModelHandle  model,
const treelite_params_t tl_params 
)

from_treelite uses a treelite model to initialize the forest

Parameters
handlecuML handle used by this function
pforestpointer to where to store the newly created forest
modeltreelite model used to initialize the forest
tl_paramsadditional parameters for the forest

◆ predict()

template<typename real_t >
void ML::fil::predict ( const raft::handle_t &  h,
forest_t< real_t >  f,
real_t *  preds,
const real_t *  data,
size_t  num_rows,
bool  predict_proba = false 
)

predict predicts on data (with n rows) using forest and writes results into preds; the number of columns is stored in forest, and both preds and data point to GPU memory

Parameters
hcuML handle used by this function
fforest used for predictions
predsarray in GPU memory to store predictions into size = predict_proba ? (2*num_rows) : num_rows
dataarray of size n * cols (cols is the number of columns for the forest f) from which to predict
num_rowsnumber of data rows
predict_probafor classifier models, this forces to output both class probabilities instead of binary class prediction. format matches scikit-learn API

Variable Documentation

◆ MAX_N_ITEMS

constexpr int ML::fil::MAX_N_ITEMS = 4
constexpr

MAX_N_ITEMS determines the maximum allowed value for tl_params::n_items