Compute Graph Framework SDK Reference  5.16
Pass.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) 2018-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_PASS_HPP_
32#define DW_FRAMEWORK_PASS_HPP_
33
34#include <dwcgf/Exception.hpp>
36#include <dwshared/dwfoundation/dw/core/container/StringView.hpp>
37#include <dwshared/dwfoundation/dw/core/container/HashContainer.hpp>
38#include <dwshared/dwfoundation/dw/core/language/Function.hpp>
39
40namespace dw
41{
42namespace framework
43{
44
46class Node;
47
49class Pass
50{
51public:
53 // coverity[autosar_cpp14_a0_1_1_violation] FP: nvbugs/2813925
54 // coverity[autosar_cpp14_a5_1_1_violation] FP: nvbugs/4020293
55 // coverity[autosar_cpp14_m0_1_4_violation] FP: nvbugs/2813925
56 static constexpr const size_t MAX_NAME_LEN{256U};
57
59 virtual ~Pass() = default;
61 Pass(Pass const&) = delete;
63 Pass(Pass&&) = delete;
65 Pass& operator=(Pass const&) & = delete;
67 Pass& operator=(Pass&&) & = delete;
68
70 const dw::core::StringView& getName() const;
71
73 virtual dwStatus run() = 0;
74
76 virtual void setRunnableId(dw::core::StringView const& runnableId) = 0;
78 virtual dw::core::FixedString<MAX_NAME_LEN> const& getRunnableId(bool isSubmitPass) const = 0;
80 dw::core::HeapHashMap<dwStatus, uint32_t> const& getPassReturnErrorMap();
81
83 virtual Node& getNode() const = 0;
84
86 dwProcessorType m_processor;
87
89 cudaStream_t m_cudaStream;
90
95
96protected:
98 Pass(const dw::core::StringView& name, dwProcessorType const processor,
99 std::initializer_list<std::pair<dwStatus, uint32_t>> const& returnMapping = {});
100
101private:
103 dw::core::StringView m_name;
104
106 dw::core::HeapHashMap<dwStatus, uint32_t> m_passReturnErrorMapping;
107};
108
110template <typename PassFunctionT>
111class PassImpl : public Pass
112{
113 static_assert(std::is_convertible<PassFunctionT, dw::core::Function<dwStatus()>>::value, "PassFunctionT must be callable without arguments and return dwStatus");
114
115public:
118 const dw::core::StringView& name,
119 PassFunctionT const passFunc,
120 dwProcessorType const processor,
121 std::initializer_list<std::pair<dwStatus, uint32_t>> const& returnMapping = {})
122 : Pass(name, processor, returnMapping)
123 , m_node(node)
124 , m_functionInt(passFunc)
125 {
126 }
127
129 dwStatus run() final
130 {
131 // TODO(DRIV-7184) - return code of the function shall not be ignored
132 // coverity[autosar_cpp14_a5_1_9_violation]
133 return ExceptionGuard::guard([&] {
134 m_functionInt();
135 },
136 dw::core::Logger::Verbosity::ERROR);
137 }
138
140 void setRunnableId(dw::core::StringView const& runnableId) final
141 {
142 // coverity[autosar_cpp14_a5_1_1_violation]
143 if (runnableId.size() >= MAX_NAME_LEN - 10U - 1U)
144 {
145 throw ExceptionWithStatus(DW_BUFFER_FULL, "setRunnableId() runnable id exceeds capacity: ", runnableId);
146 }
147 m_runnableId = dw::core::FixedString<MAX_NAME_LEN>(runnableId.data(), runnableId.size());
148 m_runnableIdSubmit = dw::core::FixedString<MAX_NAME_LEN>(runnableId.data(), runnableId.size());
149 m_runnableIdSubmit += dw::core::StringView{"_submittee"};
150 }
151
153 dw::core::FixedString<MAX_NAME_LEN> const& getRunnableId(bool isSubmitPass) const final
154 {
155 if (isSubmitPass)
156 {
157 return m_runnableIdSubmit;
158 }
159 return m_runnableId;
160 }
161
163 Node& getNode() const final
164 {
165 return m_node;
166 }
167
168private:
170 Node& m_node;
172 dw::core::Function<dwStatus()> m_functionInt;
174 dw::core::FixedString<MAX_NAME_LEN> m_runnableId;
176 dw::core::FixedString<MAX_NAME_LEN> m_runnableIdSubmit;
177};
178
179} // namespace framework
180} // namespace dw
181
182#endif // DW_FRAMEWORK_PASS_HPP_
static dwStatus guard(TryBlock const &tryBlock, ::dw::core::Logger::Verbosity verbosity=::dw::core::Logger::Verbosity::ERROR)
Definition: Exception.hpp:167
PassImpl contains the function to invoke on run().
Definition: Pass.hpp:112
dwStatus run() final
Definition: Pass.hpp:129
void setRunnableId(dw::core::StringView const &runnableId) final
Definition: Pass.hpp:140
Node & getNode() const final
Definition: Pass.hpp:163
dw::core::FixedString< MAX_NAME_LEN > const & getRunnableId(bool isSubmitPass) const final
Definition: Pass.hpp:153
PassImpl(Node &node, const dw::core::StringView &name, PassFunctionT const passFunc, dwProcessorType const processor, std::initializer_list< std::pair< dwStatus, uint32_t > > const &returnMapping={})
Constructor with a function running on the given processor type.
Definition: Pass.hpp:117
Pass is a runnable describes the metadata of a pass.
Definition: Pass.hpp:50
Pass(Pass const &)=delete
Copy constructor.
virtual Node & getNode() const =0
Get the node this pass belongs to.
bool m_isFirstIteration
Definition: Pass.hpp:94
cudaStream_t m_cudaStream
The cuda stream to use in case the processor type is GPU.
Definition: Pass.hpp:89
Pass(Pass &&)=delete
Move constructor.
virtual void setRunnableId(dw::core::StringView const &runnableId)=0
Set the runnable id.
dwProcessorType m_processor
The processor type this pass runs on.
Definition: Pass.hpp:86
dw::core::HeapHashMap< dwStatus, uint32_t > const & getPassReturnErrorMap()
Get the return status code to error map.
const dw::core::StringView & getName() const
Get the name of the pass.
Pass(const dw::core::StringView &name, dwProcessorType const processor, std::initializer_list< std::pair< dwStatus, uint32_t > > const &returnMapping={})
Constructor.
virtual dwStatus run()=0
Run the pass.
static constexpr const size_t MAX_NAME_LEN
The maximum length of the runnable id.
Definition: Pass.hpp:56
virtual ~Pass()=default
Destructor.
Pass & operator=(Pass const &) &=delete
Copy assignment operator.
Pass & operator=(Pass &&) &=delete
Move assignment operator.
virtual dw::core::FixedString< MAX_NAME_LEN > const & getRunnableId(bool isSubmitPass) const =0
Get the runnable id.
Definition: Buffer.hpp:40