Compute Graph Framework SDK Reference  5.12
PassDescriptor.hpp
Go to the documentation of this file.
1
2//
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-2023 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 <dwshared/dwfoundation/dw/core/container/StringView.hpp>
36
37#include <array>
38#include <cstddef>
39#include <tuple>
40#include <type_traits>
41#include <utility>
42
43namespace dw
44{
45namespace framework
46{
47
54template <typename... Args>
55// coverity[autosar_cpp14_a2_10_5_violation] FP: nvbugs/3907242
56constexpr auto describePassCollection(const Args&&... args) -> std::tuple<Args...>
57{
58 return std::make_tuple(std::forward<const Args>(args)...);
59}
60
61// coverity[autosar_cpp14_a0_1_1_violation] FP: nvbugs/2813925
62// coverity[autosar_cpp14_m0_1_4_violation] RFD Pending: TID-2055
63static constexpr const size_t PASS_NAME{0U};
64// coverity[autosar_cpp14_a0_1_1_violation] FP: nvbugs/2813925
65// coverity[autosar_cpp14_m0_1_4_violation] FP: nvbugs/2813925
66static constexpr const size_t PASS_PROCESSOR_TYPE{1U};
67// coverity[autosar_cpp14_a0_1_1_violation] FP: nvbugs/2813925
68// coverity[autosar_cpp14_m0_1_4_violation] RFD Pending: TID-2055
69static constexpr const size_t PASS_DEPENDENCIES{2U};
70
76constexpr std::tuple<dw::core::StringView, dwProcessorType> describePass(
77 dw::core::StringView const&& name, dwProcessorType processorType)
78{
79 return std::make_tuple(
80 std::move(name),
81 std::move(processorType));
82}
83
90// Overloaded functions are provided for ease of use
91template <typename DependenciesT>
92// coverity[autosar_cpp14_a2_10_5_violation]
93constexpr auto describePass(
94 dw::core::StringView const&& name, dwProcessorType processorType, DependenciesT dependencies) -> std::tuple<dw::core::StringView, dwProcessorType, DependenciesT>
95{
96 return std::make_tuple(
97 std::move(name),
98 std::move(processorType),
99 std::move(dependencies));
100}
101
107template <typename... Args>
108// coverity[autosar_cpp14_a2_10_5_violation] FP: nvbugs/3907242
109constexpr auto describePassDependencies(const Args&&... args) -> std::array<dw::core::StringView, sizeof...(Args)>
110{
111 return {std::forward<const Args>(args)...};
112}
113
115template <typename Node>
116// coverity[autosar_cpp14_a2_10_5_violation] FP: nvbugs/3907242
117// coverity[autosar_cpp14_a7_1_5_violation] RFD Accepted: TID-1984
118constexpr auto describePasses()
119{
120 return Node::describePasses();
121}
122
124template <typename Node>
125// coverity[autosar_cpp14_a2_10_5_violation] FP: nvbugs/3907242
126constexpr std::size_t passSize()
127{
128 return std::tuple_size<decltype(describePasses<Node>())>::value;
129}
130
132// Overloaded functions provide the same functionality for different argument types
133template <typename Node>
134// coverity[autosar_cpp14_a2_10_5_violation]
135constexpr bool isValidPass(std::size_t passID)
136{
137 return passID < passSize<Node>();
138}
139
140namespace detail
141{
142
144template <
145 typename Node, size_t Index,
146 typename std::enable_if_t<Index == passSize<Node>(), void>* = nullptr>
147// coverity[autosar_cpp14_a2_10_5_violation] FP: nvbugs/3907242
148constexpr std::size_t passIndex(dw::core::StringView identifier)
149{
150 static_cast<void>(identifier);
151 // coverity[autosar_cpp14_a5_1_1_violation] RFD Accepted: TID-2056
152 return 0U;
153}
154
156template <
157 typename Node, size_t Index,
158 typename std::enable_if_t<Index<passSize<Node>(), void>* = nullptr>
159 // coverity[autosar_cpp14_a2_10_5_violation] FP: nvbugs/3907242
160 constexpr std::size_t passIndex(dw::core::StringView identifier)
161{
162 constexpr StringView name{std::get<dw::framework::PASS_NAME>(std::get<Index>(describePasses<Node>()))};
163 if (name == identifier)
164 {
165 // coverity[autosar_cpp14_a5_1_1_violation] RFD Accepted: TID-2056
166 return 0U;
167 }
168 // coverity[autosar_cpp14_a5_1_1_violation] RFD Accepted: TID-2056
169 return 1U + passIndex<Node, Index + 1>(identifier);
170}
171
172} // namespace detail
173
175template <typename Node>
176// coverity[autosar_cpp14_a2_10_5_violation] RFD Pending: TID-2053
177constexpr size_t passIndex(dw::core::StringView identifier)
178{
179 return detail::passIndex<Node, 0>(identifier);
180}
181
183template <typename Node>
184// coverity[autosar_cpp14_a2_10_5_violation] FP: nvbugs/3907242
185constexpr bool isValidPass(dw::core::StringView identifier)
186{
187 constexpr size_t index = passIndex<Node>(identifier);
188 return isValidPass<Node>(index);
189}
190
192template <typename Node, size_t Index>
193// coverity[autosar_cpp14_a2_10_5_violation] FP: nvbugs/3907242
194constexpr dw::core::StringView passName()
195{
196 return std::get<dw::framework::PASS_NAME>(std::get<Index>(describePasses<Node>()));
197}
198
200template <typename Node, size_t Index>
201// coverity[autosar_cpp14_a2_10_5_violation] FP: nvbugs/3907242
202constexpr dwProcessorType passProcessorType()
203{
204 return std::get<dw::framework::PASS_PROCESSOR_TYPE>(std::get<Index>(describePasses<Node>()));
205}
206
208template <typename Node, size_t Index>
209// coverity[autosar_cpp14_a2_10_5_violation] FP: nvbugs/3907242
210constexpr bool hasPassDependencies()
211{
212 // coverity[autosar_cpp14_a0_1_1_violation]
213 // coverity[autosar_cpp14_a8_5_3_violation]
214 constexpr auto pass{std::get<Index>(describePasses<Node>())};
215 // coverity[autosar_cpp14_a0_1_1_violation]
216 // coverity[autosar_cpp14_a13_5_3_violation]
217 return std::tuple_size<decltype(pass)>() > PASS_DEPENDENCIES;
218}
219
221template <
222 typename Node, size_t Index,
223 typename std::enable_if_t<hasPassDependencies<Node, Index>(), void>* = nullptr>
224// coverity[autosar_cpp14_a2_10_5_violation] FP: nvbugs/3907242
225// coverity[autosar_cpp14_a7_1_5_violation]
226constexpr auto passDependencies()
227{
228 return std::get<PASS_DEPENDENCIES>(std::get<Index>(describePasses<Node>()));
229}
230
232template <
233 typename Node, size_t Index,
234 typename std::enable_if_t<!hasPassDependencies<Node, Index>(), void>* = nullptr>
235// coverity[autosar_cpp14_a2_10_5_violation] FP: nvbugs/3907242
236constexpr auto passDependencies() -> std::array<dw::core::StringView, 0>
237{
238 return std::array<dw::core::StringView, 0>();
239}
240
241} // namespace framework
242} // namespace dw
243
244#endif // DW_FRAMEWORK_PASSDESCRIPTOR_HPP_
constexpr std::size_t passSize()
Get the number of passes of the passed node.
constexpr dwProcessorType passProcessorType()
Get the processor type of a pass.
constexpr bool isValidPass(std::size_t passID)
Check if pass index is valid.
constexpr auto passDependencies()
Get the dependencies of a pass.
static constexpr const size_t PASS_DEPENDENCIES
constexpr dw::core::StringView passName()
Get the name of a pass.
constexpr size_t passIndex(dw::core::StringView identifier)
Get the the pass index for a pass identified by name.
constexpr std::tuple< dw::core::StringView, dwProcessorType > describePass(dw::core::StringView const &&name, dwProcessorType processorType)
constexpr auto describePasses()
Get described passes for the passed node.
constexpr bool hasPassDependencies()
Check if a pass specifies explicit dependencies.
static constexpr const size_t PASS_PROCESSOR_TYPE
constexpr auto describePassCollection(const Args &&... args) -> std::tuple< Args... >
static constexpr const size_t PASS_NAME
constexpr auto describePassDependencies(const Args &&... args) -> std::array< dw::core::StringView, sizeof...(Args)>
Definition: Buffer.hpp:40