Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify dense and sparse tests #4417

Merged
merged 34 commits into from
Dec 18, 2021
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
701956e
unified tree2fil
levsnv Nov 4, 2021
97dc049
unified init_dense, init_sparse
levsnv Nov 10, 2021
84bdc1e
drafted tl2fil as class for from_treelite
levsnv Nov 11, 2021
e1219bb
Merge branch 'branch-21.12' of github.com:rapidsai/cuml into unify-de…
levsnv Nov 11, 2021
c1b5d54
fixed a bug
levsnv Nov 11, 2021
6e8e463
stray changes
levsnv Nov 11, 2021
d6d0ece
Apply suggestions from code review
levsnv Nov 12, 2021
42c1c2e
apply suggestions from code review
levsnv Nov 16, 2021
c002e26
Merge branch 'branch-21.12' of github.com:rapidsai/cuml into unify-de…
levsnv Nov 16, 2021
9d304e6
Merge branch 'unify-dense-sparse-import' of github.com:levsnv/cuml in…
levsnv Nov 16, 2021
6967714
style
levsnv Nov 17, 2021
dfdfff1
made tree2fil a method of tl2fil_t, misc comments
levsnv Nov 17, 2021
58044af
tl2fil_t:: init_object(), init_forest()
levsnv Nov 17, 2021
8377aee
tracking tokens
levsnv Nov 17, 2021
e170290
addressed review comments
levsnv Nov 18, 2021
06bba79
addressed review comments
levsnv Nov 19, 2021
0ef919f
Merge branch 'branch-21.12' of github.com:rapidsai/cuml into unify-de…
levsnv Nov 19, 2021
d52b896
fixed enum->bool bug
levsnv Nov 19, 2021
b495abb
Merge branch 'branch-21.12' of github.com:rapidsai/cuml into unify-de…
levsnv Nov 20, 2021
de1668c
Merge branch 'branch-22.02' of github.com:rapidsai/cuml into unify-de…
levsnv Nov 23, 2021
70cd427
style
levsnv Nov 23, 2021
5f5ce4e
typo
levsnv Nov 24, 2021
eea9bab
style
levsnv Nov 24, 2021
6e12723
unified dense adn sparse tests; test cases are almost entirely disjoint
levsnv Dec 2, 2021
32a5103
stray comment
levsnv Dec 2, 2021
e610175
Merge branch 'branch-22.02' of github.com:rapidsai/cuml into unify-de…
levsnv Dec 3, 2021
e4913ad
Merge branch 'branch-22.02' of github.com:rapidsai/cuml into unify-tests
levsnv Dec 16, 2021
fe38a39
addressed review comments
levsnv Dec 17, 2021
7ac36f2
Merge branch 'unify-dense-sparse-import' into unify-tests
levsnv Dec 17, 2021
d9d888f
moved node_traits from common.cuh to internal.cuh to use in fil_tests.cu
levsnv Dec 17, 2021
f36304d
types
levsnv Dec 17, 2021
8de22be
ref -> val
levsnv Dec 17, 2021
d200341
Merge branch 'branch-22.02' into unify-tests
levsnv Dec 17, 2021
5679fe1
fix conflict resolution
levsnv Dec 17, 2021
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
33 changes: 33 additions & 0 deletions cpp/src/fil/common.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@

#include "internal.cuh"

// needed for node_traits<...>
namespace treelite {
template <typename, typename>
struct ModelImpl;
}

namespace ML {
namespace fil {

Expand Down Expand Up @@ -114,6 +120,33 @@ struct sparse_storage : storage_base {
typedef sparse_storage<sparse_node16> sparse_storage16;
typedef sparse_storage<sparse_node8> sparse_storage8;

struct dense_forest;
template <typename node_t>
struct sparse_forest;

template <typename node_t>
struct node_traits {
using storage = sparse_storage<node_t>;
using forest = sparse_forest<node_t>;
static const bool IS_DENSE = false;
static const storage_type_t storage_type_enum =
std::is_same<sparse_node16, node_t>() ? SPARSE : SPARSE8;
template <typename threshold_t, typename leaf_t>
static void check(const treelite::ModelImpl<threshold_t, leaf_t>& model);
};

template <>
struct node_traits<dense_node> {
using storage = dense_storage;
using forest = dense_forest;
static const bool IS_DENSE = true;
static const storage_type_t storage_type_enum = DENSE;
template <typename threshold_t, typename leaf_t>
static void check(const treelite::ModelImpl<threshold_t, leaf_t>& model)
{
}
};

/// all model parameters mostly required to compute shared memory footprint,
/// also the footprint itself
struct shmem_size_params {
Expand Down
76 changes: 39 additions & 37 deletions cpp/src/fil/fil.cu
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,12 @@ struct dense_forest : forest {
}
}

/// const int* trees is ignored and only provided for compatibility with
/// sparse_forest<node_t>::init()
void init(const raft::handle_t& h,
const categorical_sets& cat_sets,
const std::vector<float>& vector_leaf,
const int* trees,
const dense_node* nodes,
const forest_params_t* params)
{
Expand Down Expand Up @@ -560,50 +563,49 @@ void check_params(const forest_params_t* params, bool dense)
FIL_TPB);
}

void init_dense(const raft::handle_t& h,
forest_t* pf,
const categorical_sets& cat_sets,
const std::vector<float>& vector_leaf,
const dense_node* nodes,
const forest_params_t* params)
{
check_params(params, true);
dense_forest* f = new dense_forest(h);
f->init(h, cat_sets, vector_leaf, nodes, params);
*pf = f;
}

/** initializes a forest of any type
* When fil_node_t == dense_node, const int* trees is ignored
*/
template <typename fil_node_t>
void init_sparse(const raft::handle_t& h,
forest_t* pf,
const categorical_sets& cat_sets,
const std::vector<float>& vector_leaf,
const int* trees,
const fil_node_t* nodes,
const forest_params_t* params)
void init(const raft::handle_t& h,
forest_t* pf,
const categorical_sets& cat_sets,
const std::vector<float>& vector_leaf,
const int* trees,
const fil_node_t* nodes,
const forest_params_t* params)
{
check_params(params, false);
sparse_forest<fil_node_t>* f = new sparse_forest<fil_node_t>(h);
check_params(params, node_traits<fil_node_t>::IS_DENSE);
using forest_type = typename node_traits<fil_node_t>::forest;
forest_type* f = new forest_type(h);
f->init(h, cat_sets, vector_leaf, trees, nodes, params);
*pf = f;
}

// explicit instantiations for init_sparse()
template void init_sparse<sparse_node16>(const raft::handle_t& h,
forest_t* pf,
const categorical_sets& cat_sets,
const std::vector<float>& vector_leaf,
const int* trees,
const sparse_node16* nodes,
const forest_params_t* params);

template void init_sparse<sparse_node8>(const raft::handle_t& h,
forest_t* pf,
const categorical_sets& cat_sets,
const std::vector<float>& vector_leaf,
const int* trees,
const sparse_node8* nodes,
const forest_params_t* params);
template void init<sparse_node16>(const raft::handle_t& h,
forest_t* pf,
const categorical_sets& cat_sets,
const std::vector<float>& vector_leaf,
const int* trees,
const sparse_node16* nodes,
const forest_params_t* params);

template void init<sparse_node8>(const raft::handle_t& h,
forest_t* pf,
const categorical_sets& cat_sets,
const std::vector<float>& vector_leaf,
const int* trees,
const sparse_node8* nodes,
const forest_params_t* params);

template void init<dense_node>(const raft::handle_t& h,
forest_t* pf,
const categorical_sets& cat_sets,
const std::vector<float>& vector_leaf,
const int* trees,
const dense_node* nodes,
const forest_params_t* params);

void free(const raft::handle_t& h, forest_t f)
{
Expand Down
52 changes: 23 additions & 29 deletions cpp/src/fil/internal.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,14 @@ __host__ __device__ __forceinline__ val_t base_node::output<val_t>() const
/** dense_node is a single node of a dense forest */
struct alignas(8) dense_node : base_node {
dense_node() = default;
dense_node(val_t output, val_t split, int fid, bool def_left, bool is_leaf, bool is_categorical)
/// ignoring left_index, this is useful to unify import from treelite
dense_node(val_t output,
val_t split,
int fid,
bool def_left,
bool is_leaf,
bool is_categorical,
int left_index = -1)
: base_node(output, split, fid, def_left, is_leaf, is_categorical)
{
}
Expand Down Expand Up @@ -492,40 +499,27 @@ struct cat_sets_device_owner {
}
};

/** init_dense uses params and nodes to initialize the dense forest stored in pf
/** init uses params, trees and nodes to initialize the forest
* with nodes stored in pf
* @tparam fil_node_t node type to use with the forest;
* must be sparse_node16, sparse_node8 or dense_node
* @param h cuML handle used by this function
* @param pf pointer to where to store the newly created forest
* @param nodes nodes for the forest, of length
(2**(params->depth + 1) - 1) * params->ntrees
* @param params pointer to parameters used to initialize the forest
* @param vector_leaf optional vector leaves
*/
void init_dense(const raft::handle_t& h,
forest_t* pf,
const categorical_sets& cat_sets,
const std::vector<float>& vector_leaf,
const dense_node* nodes,
const forest_params_t* params);

/** init_sparse uses params, trees and nodes to initialize the sparse forest
* with sparse nodes stored in pf
* @tparam fil_node_t node type to use with the sparse forest;
* must be sparse_node16 or sparse_node8
* @param h cuML handle used by this function
* @param pf pointer to where to store the newly created forest
* @param trees indices of tree roots in the nodes arrray, of length params->ntrees
* @param nodes nodes for the forest, of length params->num_nodes
* @param trees for sparse forests, indices of tree roots in the nodes arrray, of length
params->ntrees; ignored for dense forests
* @param nodes nodes for the forest, of length params->num_nodes for sparse
or (2**(params->depth + 1) - 1) * params->ntrees for dense forests
* @param params pointer to parameters used to initialize the forest
* @param vector_leaf optional vector leaves
*/
template <typename fil_node_t>
void init_sparse(const raft::handle_t& h,
forest_t* pf,
const categorical_sets& cat_sets,
const std::vector<float>& vector_leaf,
const int* trees,
const fil_node_t* nodes,
const forest_params_t* params);
void init(const raft::handle_t& h,
forest_t* pf,
const categorical_sets& cat_sets,
const std::vector<float>& vector_leaf,
const int* trees,
const fil_node_t* nodes,
const forest_params_t* params);

struct predict_params;

Expand Down
Loading