Compute Graph Framework SDK Reference  5.16
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
61template <size_t NumberOfDependencies>
63{
64 dw::core::StringView name;
65 dwProcessorType processorType;
67 std::array<dw::core::StringView, NumberOfDependencies> dependencies;
68
69 constexpr PassDescriptorT(dw::core::StringView&& name_, dwProcessorType processorType_)
70 : name{std::move(name_)}
71 , processorType{std::move(processorType_)}
72 , hasDependencies{false}
73 , dependencies{}
74 {
75 static_assert(NumberOfDependencies == 0, "PassDescriptorT constructor without dependencies only available with NumberOfDependencies == 0");
76 }
77
78 constexpr PassDescriptorT(dw::core::StringView&& name_, dwProcessorType processorType_, std::array<dw::core::StringView, NumberOfDependencies>&& dependencies_)
79 : name{std::move(name_)}
80 , processorType{std::move(processorType_)}
81 , hasDependencies{true}
82 , dependencies{std::move(dependencies_)}
83 {
84 }
85};
86
93 dw::core::StringView&& name, dwProcessorType processorType)
94{
95 return PassDescriptorT<0>(
96 std::move(name),
97 std::move(processorType));
98}
99
106// Overloaded functions are provided for ease of use
107template <typename DependenciesT>
108// coverity[autosar_cpp14_a2_10_5_violation]
109constexpr auto describePass(
110 dw::core::StringView&& name, dwProcessorType processorType, DependenciesT&& dependencies) -> PassDescriptorT<std::tuple_size<DependenciesT>::value>
111{
113 std::move(name),
114 std::move(processorType),
115 std::move(dependencies));
116}
117
123template <typename... Args>
124// coverity[autosar_cpp14_a2_10_5_violation] FP: nvbugs/3907242
125constexpr auto describePassDependencies(const Args&&... args) -> std::array<dw::core::StringView, sizeof...(Args)>
126{
127 return {std::forward<const Args>(args)...};
128}
129
131template <typename Node>
132// coverity[autosar_cpp14_a2_10_5_violation] FP: nvbugs/3907242
133// coverity[autosar_cpp14_a7_1_5_violation] RFD Pending: TID-2201
134constexpr auto describeNodePasses()
135{
136 return Node::describePasses();
137}
138
140template <typename Node>
141// coverity[autosar_cpp14_a2_10_5_violation] FP: nvbugs/3907242
142constexpr std::size_t passSize()
143{
144 return std::tuple_size<decltype(describeNodePasses<Node>())>::value;
145}
146
148// Overloaded functions provide the same functionality for different argument types
149template <typename Node>
150// coverity[autosar_cpp14_a2_10_5_violation]
151constexpr bool isValidPass(std::size_t passID)
152{
153 return passID < passSize<Node>();
154}
155
156namespace detail
157{
158
159// LCOV_EXCL_START no coverage data for compile time evaluated function
161template <
162 typename Node, size_t Index,
163 typename std::enable_if_t<Index == passSize<Node>(), void>* = nullptr>
164// coverity[autosar_cpp14_a2_10_5_violation] FP: nvbugs/3907242
165constexpr std::size_t passIndex(dw::core::StringView identifier)
166{
167 static_cast<void>(identifier);
168 // coverity[autosar_cpp14_a5_1_1_violation] RFD Accepted: TID-2056
169 return 0U;
170}
171// LCOV_EXCL_STOP
172
174template <
175 typename Node, size_t Index,
176 typename std::enable_if_t<Index<passSize<Node>(), void>* = nullptr>
177 // coverity[autosar_cpp14_a2_10_5_violation] FP: nvbugs/3907242
178 constexpr std::size_t passIndex(dw::core::StringView identifier)
179{
180 constexpr dw::core::StringView name{std::get<Index>(describeNodePasses<Node>()).name};
181 if (name == identifier)
182 {
183 // coverity[autosar_cpp14_a5_1_1_violation] RFD Accepted: TID-2056
184 return 0U;
185 }
186 // coverity[autosar_cpp14_a5_1_1_violation] RFD Accepted: TID-2056
187 return 1U + passIndex<Node, Index + 1>(identifier);
188}
189
190} // namespace detail
191
193template <typename Node>
194// coverity[autosar_cpp14_a2_10_5_violation] RFD Pending: TID-2053
195constexpr size_t passIndex(dw::core::StringView identifier)
196{
197 return detail::passIndex<Node, 0>(identifier);
198}
199
201template <typename Node>
202// coverity[autosar_cpp14_a2_10_5_violation] FP: nvbugs/3907242
203constexpr bool isValidPass(dw::core::StringView identifier)
204{
205 constexpr size_t index = passIndex<Node>(identifier);
206 return isValidPass<Node>(index);
207}
208
210template <typename Node, size_t Index>
211// coverity[autosar_cpp14_a2_10_5_violation] FP: nvbugs/3907242
212constexpr dw::core::StringView passName()
213{
214 return std::get<Index>(describeNodePasses<Node>()).name;
215}
216
218template <typename Node, size_t Index>
219// coverity[autosar_cpp14_a2_10_5_violation] FP: nvbugs/3907242
220constexpr dwProcessorType passProcessorType()
221{
222 return std::get<Index>(describeNodePasses<Node>()).processorType;
223}
224
226template <typename Node, size_t Index>
227// coverity[autosar_cpp14_a2_10_5_violation] FP: nvbugs/3907242
228constexpr bool hasPassDependencies()
229{
230 return std::get<Index>(describeNodePasses<Node>()).hasDependencies;
231}
232
234template <typename Node, size_t Index>
235// coverity[autosar_cpp14_a2_10_5_violation] FP: nvbugs/3907242
236// coverity[autosar_cpp14_a7_1_5_violation] RFD Pending: TID-2201
237constexpr auto passDependencies()
238{
239 return std::get<Index>(describeNodePasses<Node>()).dependencies;
240}
241
242} // namespace framework
243} // namespace dw
244
245#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 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 PassDescriptorT< 0 > describePass(dw::core::StringView &&name, dwProcessorType processorType)
constexpr bool hasPassDependencies()
Check if a pass specifies explicit dependencies.
constexpr auto describePassCollection(const Args &&... args) -> std::tuple< Args... >
constexpr auto passDependencies()
Get the dependencies of a pass (which returns an empty collection for passes without explicit depende...
constexpr auto describeNodePasses()
Get described passes for the passed node.
constexpr auto describePassDependencies(const Args &&... args) -> std::array< dw::core::StringView, sizeof...(Args)>
Definition: Buffer.hpp:40
std::array< dw::core::StringView, NumberOfDependencies > dependencies
constexpr PassDescriptorT(dw::core::StringView &&name_, dwProcessorType processorType_)
constexpr PassDescriptorT(dw::core::StringView &&name_, dwProcessorType processorType_, std::array< dw::core::StringView, NumberOfDependencies > &&dependencies_)