40 namespace experimental {
69 typename metadata_storage_t,
75 auto constexpr
static const layout = layout_v;
107 root_node_indexes_{},
110 categorical_storage_{},
114 has_categorical_nodes_{false},
164 bool has_categorical_nodes =
false,
165 std::optional<raft_proto::buffer<io_type>>&& vector_output = std::nullopt,
166 std::optional<raft_proto::buffer<typename node_type::index_type>>&&
167 categorical_storage = std::nullopt,
175 root_node_indexes_{root_node_indexes},
176 node_id_mapping_{node_id_mapping},
177 vector_output_{vector_output},
178 categorical_storage_{categorical_storage},
181 leaf_size_{leaf_size},
182 has_categorical_nodes_{has_categorical_nodes},
183 row_postproc_{row_postproc},
184 elem_postproc_{elem_postproc},
185 average_factor_{average_factor},
187 postproc_constant_{postproc_constant}
189 if (nodes.memory_type() != root_node_indexes.memory_type()) {
191 "Nodes and indexes of forest must both be stored on either host or device");
193 if (nodes.device_index() != root_node_indexes.device_index()) {
195 "Nodes and indexes of forest must both be stored on same device");
197 detail::initialize_device<forest_type>(nodes.device());
211 auto result = num_outputs_;
260 std::optional<index_type> specified_rows_per_block_iter = std::nullopt)
264 "Tried to use host I/O data with model on device or vice versa"};
269 auto* vector_output_data =
270 (vector_output_.has_value() ? vector_output_->data() :
static_cast<io_type*
>(
nullptr));
271 auto* categorical_storage_data =
272 (categorical_storage_.has_value() ? categorical_storage_->data()
274 switch (nodes_.
device().index()) {
277 get_postprocessor(predict_type),
283 has_categorical_nodes_,
285 categorical_storage_data,
287 specified_rows_per_block_iter,
288 std::get<0>(nodes_.
device()),
293 get_postprocessor(predict_type),
299 has_categorical_nodes_,
301 categorical_storage_data,
303 specified_rows_per_block_iter,
304 std::get<1>(nodes_.
device()),
318 std::optional<raft_proto::buffer<io_type>> vector_output_;
321 std::optional<raft_proto::buffer<categorical_storage_type>> categorical_storage_;
327 bool has_categorical_nodes_ =
false;
338 root_node_indexes_.
data(),
339 node_id_mapping_.
data(),
349 row_postproc_, elem_postproc_, average_factor_, bias_, postproc_constant_};
354 auto leaf_size()
const {
return leaf_size_; }
371 template <tree_layout layout,
bool double_precision,
bool large_trees>
384 std::variant_alternative_t<0, detail::specialization_variant>::layout,
385 std::variant_alternative_t<0, detail::specialization_variant>::is_double_precision,
386 std::variant_alternative_t<0, detail::specialization_variant>::has_large_trees>,
388 std::variant_alternative_t<1, detail::specialization_variant>::layout,
389 std::variant_alternative_t<1, detail::specialization_variant>::is_double_precision,
390 std::variant_alternative_t<1, detail::specialization_variant>::has_large_trees>,
392 std::variant_alternative_t<2, detail::specialization_variant>::layout,
393 std::variant_alternative_t<2, detail::specialization_variant>::is_double_precision,
394 std::variant_alternative_t<2, detail::specialization_variant>::has_large_trees>,
396 std::variant_alternative_t<3, detail::specialization_variant>::layout,
397 std::variant_alternative_t<3, detail::specialization_variant>::is_double_precision,
398 std::variant_alternative_t<3, detail::specialization_variant>::has_large_trees>,
400 std::variant_alternative_t<4, detail::specialization_variant>::layout,
401 std::variant_alternative_t<4, detail::specialization_variant>::is_double_precision,
402 std::variant_alternative_t<4, detail::specialization_variant>::has_large_trees>,
404 std::variant_alternative_t<5, detail::specialization_variant>::layout,
405 std::variant_alternative_t<5, detail::specialization_variant>::is_double_precision,
406 std::variant_alternative_t<5, detail::specialization_variant>::has_large_trees>,
408 std::variant_alternative_t<6, detail::specialization_variant>::layout,
409 std::variant_alternative_t<6, detail::specialization_variant>::is_double_precision,
410 std::variant_alternative_t<6, detail::specialization_variant>::has_large_trees>,
412 std::variant_alternative_t<7, detail::specialization_variant>::layout,
413 std::variant_alternative_t<7, detail::specialization_variant>::is_double_precision,
414 std::variant_alternative_t<7, detail::specialization_variant>::has_large_trees>>;
442 using small_index_t =
444 auto max_local_categories =
index_type(
sizeof(small_index_t) * 8);
449 auto double_indexes_required =
450 (max_num_categories > max_local_categories &&
451 ((
raft_proto::ceildiv(max_num_categories, max_local_categories) + 1 * num_categorical_nodes) >
455 auto double_precision = use_double_thresholds || double_indexes_required;
457 using small_metadata_t =
459 using small_offset_t =
466 auto layout_value =
static_cast<std::underlying_type_t<tree_layout>
>(layout);
math_t max(math_t a, math_t b)
Definition: learning_rate.h:26
void infer(forest_t const &forest, postprocessor< typename forest_t::io_type > const &postproc, typename forest_t::io_type *output, typename forest_t::io_type *input, index_type row_count, index_type col_count, index_type output_count, bool has_categorical_nodes, typename forest_t::io_type *vector_output=nullptr, typename forest_t::node_type::index_type *categorical_data=nullptr, infer_kind infer_type=infer_kind::default_kind, std::optional< index_type > specified_chunk_size=std::nullopt, raft_proto::device_id< D > device=raft_proto::device_id< D >{}, raft_proto::cuda_stream stream=raft_proto::cuda_stream{})
Definition: infer.hpp:66
tree_layout
Definition: tree_layout.hpp:20
element_op
Definition: postproc_ops.hpp:29
uint32_t index_type
Definition: index_type.hpp:21
infer_kind
Definition: infer_kind.hpp:20
auto get_forest_variant_index(bool use_double_thresholds, index_type max_node_offset, index_type num_features, index_type num_categorical_nodes=index_type{}, index_type max_num_categories=index_type{}, index_type num_vector_leaves=index_type{}, tree_layout layout=preferred_tree_layout)
Definition: decision_forest.hpp:434
std::variant< detail::preset_decision_forest< std::variant_alternative_t< 0, detail::specialization_variant >::layout, std::variant_alternative_t< 0, detail::specialization_variant >::is_double_precision, std::variant_alternative_t< 0, detail::specialization_variant >::has_large_trees >, detail::preset_decision_forest< std::variant_alternative_t< 1, detail::specialization_variant >::layout, std::variant_alternative_t< 1, detail::specialization_variant >::is_double_precision, std::variant_alternative_t< 1, detail::specialization_variant >::has_large_trees >, detail::preset_decision_forest< std::variant_alternative_t< 2, detail::specialization_variant >::layout, std::variant_alternative_t< 2, detail::specialization_variant >::is_double_precision, std::variant_alternative_t< 2, detail::specialization_variant >::has_large_trees >, detail::preset_decision_forest< std::variant_alternative_t< 3, detail::specialization_variant >::layout, std::variant_alternative_t< 3, detail::specialization_variant >::is_double_precision, std::variant_alternative_t< 3, detail::specialization_variant >::has_large_trees >, detail::preset_decision_forest< std::variant_alternative_t< 4, detail::specialization_variant >::layout, std::variant_alternative_t< 4, detail::specialization_variant >::is_double_precision, std::variant_alternative_t< 4, detail::specialization_variant >::has_large_trees >, detail::preset_decision_forest< std::variant_alternative_t< 5, detail::specialization_variant >::layout, std::variant_alternative_t< 5, detail::specialization_variant >::is_double_precision, std::variant_alternative_t< 5, detail::specialization_variant >::has_large_trees >, detail::preset_decision_forest< std::variant_alternative_t< 6, detail::specialization_variant >::layout, std::variant_alternative_t< 6, detail::specialization_variant >::is_double_precision, std::variant_alternative_t< 6, detail::specialization_variant >::has_large_trees >, detail::preset_decision_forest< std::variant_alternative_t< 7, detail::specialization_variant >::layout, std::variant_alternative_t< 7, detail::specialization_variant >::is_double_precision, std::variant_alternative_t< 7, detail::specialization_variant >::has_large_trees > > decision_forest_variant
Definition: decision_forest.hpp:414
row_op
Definition: postproc_ops.hpp:22
Definition: dbscan.hpp:27
HOST DEVICE constexpr auto ceildiv(T dividend, U divisor)
Definition: ceildiv.hpp:21
int cuda_stream
Definition: cuda_stream.hpp:25
Definition: decision_forest.hpp:71
typename forest_type::node_type node_type
Definition: decision_forest.hpp:84
auto row_postprocessing() const
Definition: decision_forest.hpp:222
auto device_index()
Definition: decision_forest.hpp:232
constexpr static auto const layout
Definition: decision_forest.hpp:75
auto has_vector_leaves() const
Definition: decision_forest.hpp:205
auto num_outputs(infer_kind inference_kind=infer_kind::default_kind) const
Definition: decision_forest.hpp:209
auto elem_postprocessing() const
Definition: decision_forest.hpp:227
postprocessor< io_type > postprocessor_type
Definition: decision_forest.hpp:96
forest< layout, threshold_t, index_t, metadata_storage_t, offset_t > forest_type
Definition: decision_forest.hpp:80
void predict(raft_proto::buffer< typename forest_type::io_type > &output, raft_proto::buffer< typename forest_type::io_type > const &input, raft_proto::cuda_stream stream=raft_proto::cuda_stream{}, infer_kind predict_type=infer_kind::default_kind, std::optional< index_type > specified_rows_per_block_iter=std::nullopt)
Definition: decision_forest.hpp:256
auto num_features() const
Definition: decision_forest.hpp:201
decision_forest(raft_proto::buffer< node_type > &&nodes, raft_proto::buffer< index_type > &&root_node_indexes, raft_proto::buffer< index_type > &&node_id_mapping, index_type num_features, index_type num_outputs=index_type{2}, bool has_categorical_nodes=false, std::optional< raft_proto::buffer< io_type >> &&vector_output=std::nullopt, std::optional< raft_proto::buffer< typename node_type::index_type >> &&categorical_storage=std::nullopt, index_type leaf_size=index_type{1}, row_op row_postproc=row_op::disable, element_op elem_postproc=element_op::disable, io_type average_factor=io_type{1}, io_type bias=io_type{0}, io_type postproc_constant=io_type{1})
Definition: decision_forest.hpp:159
typename forest_type::io_type io_type
Definition: decision_forest.hpp:88
void set_row_postprocessing(row_op val)
Definition: decision_forest.hpp:224
decision_forest()
Definition: decision_forest.hpp:105
auto num_trees() const
Definition: decision_forest.hpp:203
threshold_t threshold_type
Definition: decision_forest.hpp:92
typename node_type::index_type categorical_storage_type
Definition: decision_forest.hpp:100
auto memory_type()
Definition: decision_forest.hpp:230
std::conditional_t< large_trees, std::uint32_t, std::uint16_t > metadata_type
Definition: specialization_types.hpp:51
std::conditional_t< double_precision, std::uint64_t, std::uint32_t > index_type
Definition: specialization_types.hpp:49
std::conditional_t< double_precision, double, float > threshold_type
Definition: specialization_types.hpp:45
std::conditional_t< large_trees, std::uint32_t, std::uint16_t > offset_type
Definition: specialization_types.hpp:53
Definition: forest.hpp:34
threshold_t io_type
Definition: forest.hpp:36
node< layout_v, threshold_t, index_t, metadata_storage_t, offset_t > node_type
Definition: forest.hpp:35
Definition: postprocessor.hpp:137
auto size() const noexcept
Definition: buffer.hpp:291
HOST DEVICE auto * data() const noexcept
Definition: buffer.hpp:292
auto memory_type() const noexcept
Definition: buffer.hpp:293
auto device_index() const noexcept
Definition: buffer.hpp:306
auto device() const noexcept
Definition: buffer.hpp:304
Definition: exceptions.hpp:49
Definition: exceptions.hpp:38
Definition: exceptions.hpp:58