Compute Graph Framework SDK Reference  5.10
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-2022 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/Types.hpp>
35#include <dwcgf/Exception.hpp>
37#include <dw/core/container/StringView.hpp>
38
39namespace dw
40{
41namespace framework
42{
43
45class Node;
46
48class Pass
49{
50public:
52 // coverity[autosar_cpp14_a0_1_1_violation]
53 // coverity[autosar_cpp14_m0_1_4_violation]
54 static constexpr size_t MAX_NAME_LEN{256U};
55
57 virtual ~Pass() = default;
59 Pass(Pass const&) = delete;
61 Pass(Pass&&) = delete;
63 Pass& operator=(Pass const&) & = delete;
65 Pass& operator=(Pass&&) & = delete;
66
68 virtual dwStatus run() = 0;
69
71 virtual void setRunnableId(dw::core::StringView const& runnableId) = 0;
73 virtual dw::core::FixedString<MAX_NAME_LEN> const& getRunnableId(bool isSubmitPass) const = 0;
74
76 virtual Node& getNode() const = 0;
77
79 dwProcessorType m_processor;
81 dwProcessType m_processType;
82
84 dwTime_t m_minTime;
86 dwTime_t m_avgTime;
88 dwTime_t m_maxTime;
89
91 cudaStream_t m_cudaStream;
93 NvMediaDla* m_dlaEngine;
94
99
100protected:
102 // TODO(dwplc): FP -- This constructor is called by the PassImpl constructor below
103 // coverity[autosar_cpp14_m0_1_10_violation]
104 Pass(dwProcessorType const processor,
105 dwProcessType const processType,
106 dwTime_t const minTime, dwTime_t const avgTime, dwTime_t const maxTime) noexcept;
107};
108
110template <typename PassFunctionT>
111class PassImpl : public Pass
112{
113 static_assert(std::is_convertible<PassFunctionT, std::function<dwStatus()>>::value, "PassFunctionT must be callable without arguments and return dwStatus");
114
115public:
118 PassFunctionT const passFunc,
119 dwProcessorType const processor,
120 dwProcessType const processType,
121 dwTime_t const minTime, dwTime_t const avgTime, dwTime_t const maxTime)
122 : Pass(processor, processType, minTime, avgTime, maxTime)
123 , m_node(node)
124 , m_functionInt(passFunc)
125 {
126 }
127
130 PassFunctionT const passFunc,
131 dwProcessorType const processor,
132 dwProcessType const processType,
133 dwTime_t const minTime, dwTime_t const avgTime, dwTime_t const maxTime,
134 cudaStream_t const cudaStream)
135 : Pass(processor, processType, minTime, avgTime, maxTime)
136 , m_node(node)
137 , m_functionInt(passFunc)
138 {
139 if (processor == DW_PROCESSOR_TYPE_GPU)
140 {
142 }
143 else
144 {
145 throw ExceptionWithStatus(DW_NOT_SUPPORTED, "PassImpl: Only GPU passes can use a cuda stream");
146 }
147 }
148
151 PassFunctionT const passFunc,
152 dwProcessorType const processor,
153 dwProcessType const processType,
154 dwTime_t const minTime, dwTime_t const avgTime, dwTime_t const maxTime,
155 NvMediaDla* const dlaEngine)
156 : Pass(processor, processType, minTime, avgTime, maxTime)
157 , m_node(node)
158 , m_functionInt(passFunc)
159 {
160 if (processor == DW_PROCESSOR_TYPE_DLA_0 || processor == DW_PROCESSOR_TYPE_DLA_1)
161 {
162 m_dlaEngine = dlaEngine;
163 }
164 else
165 {
166 throw ExceptionWithStatus(DW_NOT_SUPPORTED, "PassImpl: Only DLA passes can use a DLA handle");
167 }
168 }
169
171 dwStatus run() final
172 {
173 // TODO(DRIV-7184) - return code of the function shall not be ignored
174 return Exception::guard([&] {
175 m_functionInt();
176 },
177 dw::core::Logger::Verbosity::WARN);
178 }
179
181 void setRunnableId(dw::core::StringView const& runnableId) final
182 {
183 if (runnableId.size() >= 128 - 10 - 1)
184 {
185 throw ExceptionWithStatus(DW_BUFFER_FULL, "setRunnableId() runnable id exceeds capacity: ", runnableId);
186 }
187 m_runnableId = dw::core::FixedString<128>(runnableId.data(), runnableId.size());
188 m_runnableIdSubmit = dw::core::FixedString<128>(runnableId.data(), runnableId.size());
189 m_runnableIdSubmit += "_submittee";
190 }
191
193 dw::core::FixedString<MAX_NAME_LEN> const& getRunnableId(bool isSubmitPass) const final
194 {
195 if (isSubmitPass)
196 {
197 return m_runnableIdSubmit;
198 }
199 return m_runnableId;
200 }
201
203 Node& getNode() const final
204 {
205 return m_node;
206 }
207
208private:
210 Node& m_node;
212 PassFunctionT m_functionInt;
214 dw::core::FixedString<MAX_NAME_LEN> m_runnableId;
216 dw::core::FixedString<MAX_NAME_LEN> m_runnableIdSubmit;
217};
218
219} // namespace framework
220} // namespace dw
221
222#endif // DW_FRAMEWORK_PASS_HPP_
PassImpl contains the function to invoke on run().
Definition: Pass.hpp:112
dwStatus run() final
Definition: Pass.hpp:171
PassImpl(Node &node, PassFunctionT const passFunc, dwProcessorType const processor, dwProcessType const processType, dwTime_t const minTime, dwTime_t const avgTime, dwTime_t const maxTime, cudaStream_t const cudaStream)
Constructor with a function running on a GPU.
Definition: Pass.hpp:129
void setRunnableId(dw::core::StringView const &runnableId) final
Definition: Pass.hpp:181
Node & getNode() const final
Definition: Pass.hpp:203
dw::core::FixedString< MAX_NAME_LEN > const & getRunnableId(bool isSubmitPass) const final
Definition: Pass.hpp:193
PassImpl(Node &node, PassFunctionT const passFunc, dwProcessorType const processor, dwProcessType const processType, dwTime_t const minTime, dwTime_t const avgTime, dwTime_t const maxTime)
Constructor with a function running on a CPU.
Definition: Pass.hpp:117
PassImpl(Node &node, PassFunctionT const passFunc, dwProcessorType const processor, dwProcessType const processType, dwTime_t const minTime, dwTime_t const avgTime, dwTime_t const maxTime, NvMediaDla *const dlaEngine)
Constructor with a function running on a DLA.
Definition: Pass.hpp:150
Pass is a runnable describes the metadata of a pass.
Definition: Pass.hpp:49
Pass(Pass const &)=delete
Copy constructor.
dwTime_t m_minTime
Definition: Pass.hpp:84
dwTime_t m_avgTime
Definition: Pass.hpp:86
virtual Node & getNode() const =0
Get the node this pass belongs to.
bool m_isFirstIteration
Definition: Pass.hpp:98
cudaStream_t m_cudaStream
The cuda stream to use in case the processor type is GPU.
Definition: Pass.hpp:91
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:79
Pass(dwProcessorType const processor, dwProcessType const processType, dwTime_t const minTime, dwTime_t const avgTime, dwTime_t const maxTime) noexcept
Constructor.
dwProcessType m_processType
The process type this pass runs with.
Definition: Pass.hpp:81
virtual dwStatus run()=0
Run the pass.
static constexpr size_t MAX_NAME_LEN
The maximum length of the runnable id.
Definition: Pass.hpp:54
dwTime_t m_maxTime
Definition: Pass.hpp:88
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.
NvMediaDla * m_dlaEngine
The dla engine to run on in case the processor type is GPU.
Definition: Pass.hpp:93
cudaStream_t cudaStream
Definition: dwIcpNode.hpp:60
Definition: Buffer.hpp:40