specialization_types.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023-2025, NVIDIA CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 
18 #include <cuml/fil/tree_layout.hpp>
19 
20 #include <cstddef>
21 #include <cstdint>
22 #include <type_traits>
23 #include <variant>
24 
25 namespace ML {
26 namespace fil {
27 namespace detail {
28 
29 /*
30  * A template used solely to help manage the types which will be compiled in
31  * standard cuML FIL
32  *
33  * The relatively simple and human-readable template parameters of this
34  * template are translated into the specific types and values required
35  * to instantiate more complex templates and compile-time checks.
36  *
37  * @tparam layout_v The layout of trees within a model
38  * @tparam double_precision Whether this model should use double-precision
39  * for floating-point evaluation and 64-bit integers for indexes
40  * @tparam large_trees Whether this forest expects more than 2**(16 -3) - 1 =
41  * 8191 features or contains nodes whose child is offset more than 2**16 - 1 = 65535 nodes away.
42  */
43 template <tree_layout layout_v, bool double_precision, bool large_trees>
45  /* The node threshold type to be used based on the template parameters
46  */
47  using threshold_type = std::conditional_t<double_precision, double, float>;
48  /* The type required for specifying indexes to vector leaf outputs or
49  * non-local categorical data.
50  */
51  using index_type = std::conditional_t<double_precision, std::uint64_t, std::uint32_t>;
52  /* The type used to provide metadata storage for nodes */
53  using metadata_type = std::conditional_t<large_trees, std::uint32_t, std::uint16_t>;
54  /* The type used to provide metadata storage for nodes */
55  using offset_type = std::conditional_t<large_trees, std::uint32_t, std::uint16_t>;
56  /* The tree layout (alias for layout_v)*/
57  auto static constexpr const layout = layout_v;
58  /* Whether or not this tree requires double precision (alias for
59  * double_precision)
60  */
61  auto static constexpr const is_double_precision = double_precision;
62  /* Whether or not this forest contains large trees (alias for
63  * large_trees)
64  */
65  auto static constexpr const has_large_trees = large_trees;
66 };
67 
68 /* A variant holding information on all specialization types compiled
69  * in standard cuML FIL
70  */
72  std::variant<specialization_types<tree_layout::depth_first, false, false>,
84 
85 } // namespace detail
86 } // namespace fil
87 } // namespace ML
std::variant< specialization_types< tree_layout::depth_first, false, false >, specialization_types< tree_layout::depth_first, false, true >, specialization_types< tree_layout::depth_first, true, false >, specialization_types< tree_layout::depth_first, true, true >, specialization_types< tree_layout::breadth_first, false, false >, specialization_types< tree_layout::breadth_first, false, true >, specialization_types< tree_layout::breadth_first, true, false >, specialization_types< tree_layout::breadth_first, true, true >, specialization_types< tree_layout::layered_children_together, false, false >, specialization_types< tree_layout::layered_children_together, false, true >, specialization_types< tree_layout::layered_children_together, true, false >, specialization_types< tree_layout::layered_children_together, true, true > > specialization_variant
Definition: specialization_types.hpp:83
Definition: dbscan.hpp:29
Definition: specialization_types.hpp:44
static constexpr auto const has_large_trees
Definition: specialization_types.hpp:65
std::conditional_t< double_precision, double, float > threshold_type
Definition: specialization_types.hpp:47
std::conditional_t< large_trees, std::uint32_t, std::uint16_t > metadata_type
Definition: specialization_types.hpp:53
std::conditional_t< double_precision, std::uint64_t, std::uint32_t > index_type
Definition: specialization_types.hpp:51
std::conditional_t< large_trees, std::uint32_t, std::uint16_t > offset_type
Definition: specialization_types.hpp:55
static constexpr auto const layout
Definition: specialization_types.hpp:57
static constexpr auto const is_double_precision
Definition: specialization_types.hpp:61