specialization_types.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023-2024, 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 
19 
20 #include <cstddef>
21 #include <cstdint>
22 #include <type_traits>
23 #include <variant>
24 
25 namespace ML {
26 namespace experimental {
27 namespace fil {
28 namespace detail {
29 
30 /*
31  * A template used solely to help manage the types which will be compiled in
32  * standard cuML FIL
33  *
34  * The relatively simple and human-readable template parameters of this
35  * template are translated into the specific types and values required
36  * to instantiate more complex templates and compile-time checks.
37  *
38  * @tparam layout_v The layout of trees within a model
39  * @tparam double_precision Whether this model should use double-precision
40  * for floating-point evaluation and 64-bit integers for indexes
41  * @tparam large_trees Whether this forest expects more than 2**(16 -3) - 1 =
42  * 8191 features or contains nodes whose child is offset more than 2**16 - 1 = 65535 nodes away.
43  */
44 template <tree_layout layout_v, bool double_precision, bool large_trees>
46  /* The node threshold type to be used based on the template parameters
47  */
48  using threshold_type = std::conditional_t<double_precision, double, float>;
49  /* The type required for specifying indexes to vector leaf outputs or
50  * non-local categorical data.
51  */
52  using index_type = std::conditional_t<double_precision, std::uint64_t, std::uint32_t>;
53  /* The type used to provide metadata storage for nodes */
54  using metadata_type = std::conditional_t<large_trees, std::uint32_t, std::uint16_t>;
55  /* The type used to provide metadata storage for nodes */
56  using offset_type = std::conditional_t<large_trees, std::uint32_t, std::uint16_t>;
57  /* The tree layout (alias for layout_v)*/
58  auto static constexpr const layout = layout_v;
59  /* Whether or not this tree requires double precision (alias for
60  * double_precision)
61  */
62  auto static constexpr const is_double_precision = double_precision;
63  /* Whether or not this forest contains large trees (alias for
64  * large_trees)
65  */
66  auto static constexpr const has_large_trees = large_trees;
67 };
68 
69 /* A variant holding information on all specialization types compiled
70  * in standard cuML FIL
71  */
73  std::variant<specialization_types<tree_layout::depth_first, false, false>,
81 
82 } // namespace detail
83 } // namespace fil
84 } // namespace experimental
85 } // 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_variant
Definition: specialization_types.hpp:80
Definition: dbscan.hpp:30
Definition: specialization_types.hpp:45
static constexpr auto const layout
Definition: specialization_types.hpp:58
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
static constexpr auto const is_double_precision
Definition: specialization_types.hpp:62
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
static constexpr auto const has_large_trees
Definition: specialization_types.hpp:66