Compute Graph Framework SDK Reference
5.4.5418 Release
For Test and Development only

PassDescriptor.hpp
Go to the documentation of this file.
1 //
3 // Notice
4 // ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES
5 // NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
6 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT,
7 // MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 //
9 // NVIDIA CORPORATION & AFFILIATES assumes no responsibility for the consequences of use of such
10 // information or for any infringement of patents or other rights of third parties that may
11 // result from its use. No license is granted by implication or otherwise under any patent
12 // or patent rights of NVIDIA CORPORATION & AFFILIATES. No third party distribution is allowed unless
13 // expressly authorized by NVIDIA. Details are subject to change without notice.
14 // This code supersedes and replaces all information previously supplied.
15 // NVIDIA CORPORATION & AFFILIATES products are not authorized for use as critical
16 // components in life support devices or systems without express written approval of
17 // NVIDIA CORPORATION & AFFILIATES.
18 //
19 // SPDX-FileCopyrightText: Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
20 // SPDX-License-Identifier: LicenseRef-NvidiaProprietary
21 //
22 // NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
23 // property and proprietary rights in and to this material, related
24 // documentation and any modifications thereto. Any use, reproduction,
25 // disclosure or distribution of this material and related documentation
26 // without an express license agreement from NVIDIA CORPORATION or
27 // its affiliates is strictly prohibited.
28 //
30 
31 #ifndef DW_FRAMEWORK_PASSDESCRIPTOR_HPP_
32 #define DW_FRAMEWORK_PASSDESCRIPTOR_HPP_
33 
34 #include <dw/core/base/Types.h>
35 #include <dw/core/container/StringView.hpp>
36 
37 #include <array>
38 #include <cstddef>
39 #include <tuple>
40 #include <type_traits>
41 #include <utility>
42 
43 namespace dw
44 {
45 namespace framework
46 {
47 
54 template <typename... Args>
55 constexpr auto describePassCollection(const Args&&... args)
56 {
57  return std::make_tuple(std::forward<const Args>(args)...);
58 }
59 
60 // coverity[autosar_cpp14_a0_1_1_violation]
61 // coverity[autosar_cpp14_m0_1_4_violation]
62 static constexpr size_t PASS_NAME{0U};
63 // coverity[autosar_cpp14_a0_1_1_violation]
64 // coverity[autosar_cpp14_m0_1_4_violation]
65 static constexpr size_t PASS_PROCESSOR_TYPE{1U};
66 // coverity[autosar_cpp14_a0_1_1_violation]
67 // coverity[autosar_cpp14_m0_1_4_violation]
68 static constexpr size_t PASS_DEPENDENCIES{2U};
69 
75 constexpr std::tuple<dw::core::StringView, dwProcessorType> describePass(
76  dw::core::StringView const&& name, dwProcessorType processorType)
77 {
78  return std::make_tuple(
79  // TODO(dwplc): FP -- must use std::move for && parameter
80  // coverity[autosar_cpp14_a18_9_3_violation]
81  std::move(name),
82  std::move(processorType));
83 }
84 
91 template <typename DependenciesT>
92 constexpr auto describePass(
93  dw::core::StringView const&& name, dwProcessorType processorType, DependenciesT dependencies) -> std::tuple<dw::core::StringView, dwProcessorType, DependenciesT>
94 {
95  return std::make_tuple(
96  std::move(name),
97  std::move(processorType),
98  std::move(dependencies));
99 }
100 
106 template <typename... Args>
107 constexpr auto describePassDependencies(const Args&&... args) -> std::array<dw::core::StringView, sizeof...(Args)>
108 {
109  return {std::forward<const Args>(args)...};
110 }
111 
113 template <typename Node>
114 constexpr auto describePasses()
115 {
116  return Node::describePasses();
117 }
118 
120 template <typename Node>
121 constexpr std::size_t passSize()
122 {
123  return std::tuple_size<decltype(describePasses<Node>())>::value;
124 }
125 
127 template <typename Node>
128 constexpr bool isValidPass(std::size_t passID)
129 {
130  return passID < passSize<Node>();
131 }
132 
133 namespace detail
134 {
135 
137 template <
138  typename Node, size_t Index,
139  typename std::enable_if_t<Index == passSize<Node>(), void>* = nullptr>
140 constexpr std::size_t passIndex(dw::core::StringView identifier)
141 {
142  (void)identifier;
143  return 0;
144 }
145 
147 template <
148  typename Node, size_t Index,
149  typename std::enable_if_t<Index<passSize<Node>(), void>* = nullptr> constexpr std::size_t passIndex(dw::core::StringView identifier)
150 {
151  constexpr auto name = std::get<dw::framework::PASS_NAME>(std::get<Index>(describePasses<Node>()));
152  if (name == identifier)
153  {
154  return 0;
155  }
156  return 1 + passIndex<Node, Index + 1>(identifier);
157 }
158 
159 } // namespace detail
160 
162 template <typename Node>
163 constexpr size_t passIndex(dw::core::StringView identifier)
164 {
165  return detail::passIndex<Node, 0>(identifier);
166 }
167 
169 template <typename Node>
170 constexpr bool isValidPass(dw::core::StringView identifier)
171 {
172  constexpr size_t index = passIndex<Node>(identifier);
173  return isValidPass<Node>(index);
174 }
175 
177 template <typename Node, size_t Index>
178 constexpr dw::core::StringView passName()
179 {
180  return std::get<dw::framework::PASS_NAME>(std::get<Index>(describePasses<Node>()));
181 }
182 
184 template <typename Node, size_t Index>
185 constexpr dwProcessorType passProcessorType()
186 {
187  return std::get<dw::framework::PASS_PROCESSOR_TYPE>(std::get<Index>(describePasses<Node>()));
188 }
189 
191 template <typename Node, size_t Index>
192 constexpr bool hasPassDependencies()
193 {
194  constexpr auto pass = std::get<Index>(describePasses<Node>());
195  return std::tuple_size<decltype(pass)>() > PASS_DEPENDENCIES;
196 }
197 
199 template <
200  typename Node, size_t Index,
201  typename std::enable_if_t<hasPassDependencies<Node, Index>(), void>* = nullptr>
202 constexpr auto passDependencies()
203 {
204  return std::get<PASS_DEPENDENCIES>(std::get<Index>(describePasses<Node>()));
205 }
206 
208 template <
209  typename Node, size_t Index,
210  typename std::enable_if_t<!hasPassDependencies<Node, Index>(), void>* = nullptr>
211 constexpr auto passDependencies()
212 {
213  return std::array<dw::core::StringView, 0>();
214 }
215 
216 } // namespace framework
217 } // namespace dw
218 
219 #endif // DW_FRAMEWORK_PASSDESCRIPTOR_HPP_
constexpr auto describePasses()
Get described passes for the passed node.
static constexpr size_t PASS_PROCESSOR_TYPE
constexpr std::tuple< dw::core::StringView, dwProcessorType > describePass(dw::core::StringView const &&name, dwProcessorType processorType)
Describe a specific pass of a node.
constexpr auto passDependencies()
Get the dependencies of a pass.
constexpr auto describePassDependencies(const Args &&... args) -> std::array< dw::core::StringView, sizeof...(Args)>
Describe the custom inter-pass dependencies of a pass.
constexpr dw::core::StringView passName()
Get the name of a pass.
constexpr bool hasPassDependencies()
Check if a pass specifies explicit dependencies.
constexpr auto describePassCollection(const Args &&... args)
Describe the passes of a node.
static constexpr size_t PASS_NAME
constexpr bool isValidPass(std::size_t passID)
Check if pass index is valid.
constexpr size_t passIndex(dw::core::StringView identifier)
Get the the pass index for a pass identified by name.
Definition: Exception.hpp:46
constexpr dwProcessorType passProcessorType()
Get the processor type of a pass.
static constexpr size_t PASS_DEPENDENCIES
constexpr std::size_t passSize()
Get the number of passes of the passed node.