42 namespace experimental {
71 typename metadata_storage_t,
77 auto constexpr
static const layout = layout_v;
109 root_node_indexes_{},
112 categorical_storage_{},
116 has_categorical_nodes_{false},
166 bool has_categorical_nodes =
false,
167 std::optional<raft_proto::buffer<io_type>>&& vector_output = std::nullopt,
168 std::optional<raft_proto::buffer<typename node_type::index_type>>&&
169 categorical_storage = std::nullopt,
177 root_node_indexes_{root_node_indexes},
178 node_id_mapping_{node_id_mapping},
179 vector_output_{vector_output},
180 categorical_storage_{categorical_storage},
183 leaf_size_{leaf_size},
184 has_categorical_nodes_{has_categorical_nodes},
185 row_postproc_{row_postproc},
186 elem_postproc_{elem_postproc},
187 average_factor_{average_factor},
189 postproc_constant_{postproc_constant}
191 if (nodes.memory_type() != root_node_indexes.memory_type()) {
193 "Nodes and indexes of forest must both be stored on either host or device");
195 if (nodes.device_index() != root_node_indexes.device_index()) {
197 "Nodes and indexes of forest must both be stored on same device");
199 detail::initialize_device<forest_type>(nodes.device());
213 auto result = num_outputs_;
262 std::optional<index_type> specified_rows_per_block_iter = std::nullopt)
266 "Tried to use host I/O data with model on device or vice versa"};
271 auto* vector_output_data =
272 (vector_output_.has_value() ? vector_output_->data() :
static_cast<io_type*
>(
nullptr));
273 auto* categorical_storage_data =
274 (categorical_storage_.has_value() ? categorical_storage_->data()
276 switch (nodes_.
device().index()) {
279 get_postprocessor(predict_type),
285 has_categorical_nodes_,
287 categorical_storage_data,
289 specified_rows_per_block_iter,
290 std::get<0>(nodes_.
device()),
295 get_postprocessor(predict_type),
301 has_categorical_nodes_,
303 categorical_storage_data,
305 specified_rows_per_block_iter,
306 std::get<1>(nodes_.
device()),
320 std::optional<raft_proto::buffer<io_type>> vector_output_;
323 std::optional<raft_proto::buffer<categorical_storage_type>> categorical_storage_;
329 bool has_categorical_nodes_ =
false;
340 root_node_indexes_.
data(),
341 node_id_mapping_.
data(),
351 row_postproc_, elem_postproc_, average_factor_, bias_, postproc_constant_};
356 auto leaf_size()
const {
return leaf_size_; }
373 template <tree_layout layout,
bool double_precision,
bool large_trees>
386 std::variant_alternative_t<0, detail::specialization_variant>::layout,
387 std::variant_alternative_t<0, detail::specialization_variant>::is_double_precision,
388 std::variant_alternative_t<0, detail::specialization_variant>::has_large_trees>,
390 std::variant_alternative_t<1, detail::specialization_variant>::layout,
391 std::variant_alternative_t<1, detail::specialization_variant>::is_double_precision,
392 std::variant_alternative_t<1, detail::specialization_variant>::has_large_trees>,
394 std::variant_alternative_t<2, detail::specialization_variant>::layout,
395 std::variant_alternative_t<2, detail::specialization_variant>::is_double_precision,
396 std::variant_alternative_t<2, detail::specialization_variant>::has_large_trees>,
398 std::variant_alternative_t<3, detail::specialization_variant>::layout,
399 std::variant_alternative_t<3, detail::specialization_variant>::is_double_precision,
400 std::variant_alternative_t<3, detail::specialization_variant>::has_large_trees>,
402 std::variant_alternative_t<4, detail::specialization_variant>::layout,
403 std::variant_alternative_t<4, detail::specialization_variant>::is_double_precision,
404 std::variant_alternative_t<4, detail::specialization_variant>::has_large_trees>,
406 std::variant_alternative_t<5, detail::specialization_variant>::layout,
407 std::variant_alternative_t<5, detail::specialization_variant>::is_double_precision,
408 std::variant_alternative_t<5, detail::specialization_variant>::has_large_trees>,
410 std::variant_alternative_t<6, detail::specialization_variant>::layout,
411 std::variant_alternative_t<6, detail::specialization_variant>::is_double_precision,
412 std::variant_alternative_t<6, detail::specialization_variant>::has_large_trees>,
414 std::variant_alternative_t<7, detail::specialization_variant>::layout,
415 std::variant_alternative_t<7, detail::specialization_variant>::is_double_precision,
416 std::variant_alternative_t<7, detail::specialization_variant>::has_large_trees>>;
444 using small_index_t =
446 auto max_local_categories =
index_type(
sizeof(small_index_t) * 8);
451 auto double_indexes_required =
452 (max_num_categories > max_local_categories &&
453 ((
raft_proto::ceildiv(max_num_categories, max_local_categories) + 1 * num_categorical_nodes) >
457 auto double_precision = use_double_thresholds || double_indexes_required;
459 using small_metadata_t =
461 using small_offset_t =
468 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:27
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:69
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:436
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:416
row_op
Definition: postproc_ops.hpp:22
Definition: dbscan.hpp:30
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:73
typename forest_type::node_type node_type
Definition: decision_forest.hpp:86
auto row_postprocessing() const
Definition: decision_forest.hpp:224
auto device_index()
Definition: decision_forest.hpp:234
constexpr static auto const layout
Definition: decision_forest.hpp:77
auto has_vector_leaves() const
Definition: decision_forest.hpp:207
auto num_outputs(infer_kind inference_kind=infer_kind::default_kind) const
Definition: decision_forest.hpp:211
auto elem_postprocessing() const
Definition: decision_forest.hpp:229
postprocessor< io_type > postprocessor_type
Definition: decision_forest.hpp:98
forest< layout, threshold_t, index_t, metadata_storage_t, offset_t > forest_type
Definition: decision_forest.hpp:82
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:258
auto num_features() const
Definition: decision_forest.hpp:203
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:161
typename forest_type::io_type io_type
Definition: decision_forest.hpp:90
void set_row_postprocessing(row_op val)
Definition: decision_forest.hpp:226
decision_forest()
Definition: decision_forest.hpp:107
auto num_trees() const
Definition: decision_forest.hpp:205
threshold_t threshold_type
Definition: decision_forest.hpp:94
typename node_type::index_type categorical_storage_type
Definition: decision_forest.hpp:102
auto memory_type()
Definition: decision_forest.hpp:232
std::conditional_t< large_trees, std::uint32_t, std::uint16_t > metadata_type
Definition: specialization_types.hpp:54
std::conditional_t< double_precision, std::uint64_t, std::uint32_t > index_type
Definition: specialization_types.hpp:52
std::conditional_t< double_precision, double, float > threshold_type
Definition: specialization_types.hpp:48
std::conditional_t< large_trees, std::uint32_t, std::uint16_t > offset_type
Definition: specialization_types.hpp:56
Definition: forest.hpp:36
threshold_t io_type
Definition: forest.hpp:38
node< layout_v, threshold_t, index_t, metadata_storage_t, offset_t > node_type
Definition: forest.hpp:37
Definition: postprocessor.hpp:141
auto size() const noexcept
Definition: buffer.hpp:293
HOST DEVICE auto * data() const noexcept
Definition: buffer.hpp:294
auto memory_type() const noexcept
Definition: buffer.hpp:295
auto device_index() const noexcept
Definition: buffer.hpp:308
auto device() const noexcept
Definition: buffer.hpp:306
Definition: exceptions.hpp:49
Definition: exceptions.hpp:38
Definition: exceptions.hpp:58