Compute Graph Framework SDK Reference  5.14
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 const&& 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 const&& name_, dwProcessorType processorType_, std::array<dw::core::StringView, NumberOfDependencies> const&& 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 const&& 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 const&& name, dwProcessorType processorType, DependenciesT const&& 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 Accepted: TID-1984
134constexpr auto describePasses()
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(describePasses<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
160template <
161 typename Node, size_t Index,
162 typename std::enable_if_t<Index == passSize<Node>(), void>* = nullptr>
163// coverity[autosar_cpp14_a2_10_5_violation] FP: nvbugs/3907242
164constexpr std::size_t passIndex(dw::core::StringView identifier)
165{
166 static_cast<void>(identifier);
167 // coverity[autosar_cpp14_a5_1_1_violation] RFD Accepted: TID-2056
168 return 0U;
169}
170
172template <
173 typename Node, size_t Index,
174 typename std::enable_if_t<Index<passSize<Node>(), void>* = nullptr>
175 // coverity[autosar_cpp14_a2_10_5_violation] FP: nvbugs/3907242
176 constexpr std::size_t passIndex(dw::core::StringView identifier)
177{
178 constexpr dw::core::StringView name{std::get<Index>(describePasses<Node>()).name};
179 if (name == identifier)
180 {
181 // coverity[autosar_cpp14_a5_1_1_violation] RFD Accepted: TID-2056
182 return 0U;
183 }
184 // coverity[autosar_cpp14_a5_1_1_violation] RFD Accepted: TID-2056
185 return 1U + passIndex<Node, Index + 1>(identifier);
186}
187
188} // namespace detail
189
191template <typename Node>
192// coverity[autosar_cpp14_a2_10_5_violation] RFD Pending: TID-2053
193constexpr size_t passIndex(dw::core::StringView identifier)
194{
195 return detail::passIndex<Node, 0>(identifier);
196}
197
199template <typename Node>
200// coverity[autosar_cpp14_a2_10_5_violation] FP: nvbugs/3907242
201constexpr bool isValidPass(dw::core::StringView identifier)
202{
203 constexpr size_t index = passIndex<Node>(identifier);
204 return isValidPass<Node>(index);
205}
206
208template <typename Node, size_t Index>
209// coverity[autosar_cpp14_a2_10_5_violation] FP: nvbugs/3907242
210constexpr dw::core::StringView passName()
211{
212 return std::get<Index>(describePasses<Node>()).name;
213}
214
216template <typename Node, size_t Index>
217// coverity[autosar_cpp14_a2_10_5_violation] FP: nvbugs/3907242
218constexpr dwProcessorType passProcessorType()
219{
220 return std::get<Index>(describePasses<Node>()).processorType;
221}
222
224template <typename Node, size_t Index>
225// coverity[autosar_cpp14_a2_10_5_violation] FP: nvbugs/3907242
226constexpr bool hasPassDependencies()
227{
228 return std::get<Index>(describePasses<Node>()).hasDependencies;
229}
230
232template <typename Node, size_t Index>
233// coverity[autosar_cpp14_a2_10_5_violation] FP: nvbugs/3907242
234// coverity[autosar_cpp14_a7_1_5_violation]
235constexpr auto passDependencies()
236{
237 return std::get<Index>(describePasses<Node>()).dependencies;
238}
239
240} // namespace framework
241} // namespace dw
242
243#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 auto describePasses()
Get described passes for the passed node.
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 PassDescriptorT< 0 > describePass(dw::core::StringView const &&name, dwProcessorType processorType)
constexpr auto describePassDependencies(const Args &&... args) -> std::array< dw::core::StringView, sizeof...(Args)>
Definition: Buffer.hpp:40
constexpr PassDescriptorT(dw::core::StringView const &&name_, dwProcessorType processorType_)
std::array< dw::core::StringView, NumberOfDependencies > dependencies
constexpr PassDescriptorT(dw::core::StringView const &&name_, dwProcessorType processorType_, std::array< dw::core::StringView, NumberOfDependencies > const &&dependencies_)