Compute Graph Framework SDK Reference
5.4.5418 Release
For Test and Development only

Pass.hpp
Go to the documentation of this file.
1 //
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-2021 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 #include <dw/trace/Trace.hpp>
39 
40 namespace dw
41 {
42 namespace framework
43 {
44 
46 class Node;
47 
49 class Pass
50 {
51 public:
53  // coverity[autosar_cpp14_a0_1_1_violation]
54  // coverity[autosar_cpp14_m0_1_4_violation]
55  static constexpr size_t MAX_NAME_LEN{256U};
56 
58  virtual ~Pass() = default;
60  Pass(Pass const&) = delete;
62  Pass(Pass&&) = delete;
64  Pass& operator=(Pass const&) = delete;
66  Pass& operator=(Pass&&) = delete;
67 
69  virtual dwStatus run() = 0;
70 
72  virtual void setRunnableId(dw::core::StringView const& runnableId) = 0;
74  virtual dw::core::FixedString<MAX_NAME_LEN> const& getRunnableId(bool isSubmitPass) const = 0;
75 
77  virtual Node* getNode() const = 0;
78 
80  // coverity[autosar_cpp14_m11_0_1_violation]
81  dwProcessorType m_processor;
83  // coverity[autosar_cpp14_m11_0_1_violation]
84  dwProcessType m_processType;
85 
87  // coverity[autosar_cpp14_m11_0_1_violation]
88  dwTime_t m_minTime;
90  // coverity[autosar_cpp14_m11_0_1_violation]
91  dwTime_t m_avgTime;
93  // coverity[autosar_cpp14_m11_0_1_violation]
94  dwTime_t m_maxTime;
95 
97  // coverity[autosar_cpp14_m11_0_1_violation]
98  cudaStream_t m_cudaStream;
100  // coverity[autosar_cpp14_m11_0_1_violation]
101  NvMediaDla* m_dlaEngine;
102 
103 protected:
105  Pass(dwProcessorType const processor,
106  dwProcessType const processType,
107  dwTime_t const minTime, dwTime_t const avgTime, dwTime_t const maxTime) noexcept
108  : m_processor(processor)
109  , m_processType(processType)
110  , m_minTime(minTime)
111  , m_avgTime(avgTime)
112  , m_maxTime(maxTime)
113  , m_cudaStream(DW_NULL_HANDLE)
114  , m_dlaEngine(nullptr)
115  {
116  }
117 };
118 
120 template <typename PassFunctionT>
121 class PassImpl : public Pass
122 {
123 public:
125  // coverity[autosar_cpp14_a8_4_8_violation]
126  PassImpl(Node* node,
127  PassFunctionT const passFunc,
128  dwProcessorType const processor,
129  dwProcessType const processType,
130  dwTime_t const minTime, dwTime_t const avgTime, dwTime_t const maxTime)
131  : Pass(processor, processType, minTime, avgTime, maxTime)
132  , m_node(node)
133  , m_functionInt(passFunc)
134  {
135  }
136 
138  // coverity[autosar_cpp14_a8_4_8_violation]
139  PassImpl(Node* node,
140  PassFunctionT const passFunc,
141  dwProcessorType const processor,
142  dwProcessType const processType,
143  dwTime_t const minTime, dwTime_t const avgTime, dwTime_t const maxTime,
144  cudaStream_t const cudaStream)
145  : Pass(processor, processType, minTime, avgTime, maxTime)
146  , m_node(node)
147  , m_functionInt(passFunc)
148  {
149  if (processor == DW_PROCESSOR_TYPE_GPU)
150  {
151  m_cudaStream = cudaStream;
152  }
153  else
154  {
155  throw Exception(DW_NOT_SUPPORTED, "PassImpl: Only GPU passes can use a cuda stream");
156  }
157  }
158 
160  // coverity[autosar_cpp14_a8_4_8_violation]
161  PassImpl(Node* node,
162  PassFunctionT const passFunc,
163  dwProcessorType const processor,
164  dwProcessType const processType,
165  dwTime_t const minTime, dwTime_t const avgTime, dwTime_t const maxTime,
166  NvMediaDla* const dlaEngine)
167  : Pass(processor, processType, minTime, avgTime, maxTime)
168  , m_node(node)
169  , m_functionInt(passFunc)
170  {
171  if (processor == DW_PROCESSOR_TYPE_DLA_0 || processor == DW_PROCESSOR_TYPE_DLA_1)
172  {
173  m_dlaEngine = dlaEngine;
174  }
175  else
176  {
177  throw Exception(DW_NOT_SUPPORTED, "PassImpl: Only DLA passes can use a DLA handle");
178  }
179  }
180 
182  dwStatus run() final
183  {
184  // TODO(DRIV-7184) - return code of the function shall not be ignored
185  return Exception::guard([&] {
186  m_functionInt();
187  });
188  }
189 
191  void setRunnableId(dw::core::StringView const& runnableId) final
192  {
193  if (runnableId.size() >= 128 - 10 - 1)
194  {
195  throw Exception(DW_BUFFER_FULL, "setRunnableId() runnable id exceeds capacity: ", runnableId);
196  }
197  m_runnableId = dw::core::FixedString<128>(runnableId.data(), runnableId.size());
198  m_runnableIdSubmit = dw::core::FixedString<128>(runnableId.data(), runnableId.size());
199  m_runnableIdSubmit += "_submittee";
200  }
201 
203  dw::core::FixedString<MAX_NAME_LEN> const& getRunnableId(bool isSubmitPass) const final
204  {
205  if (isSubmitPass)
206  {
207  return m_runnableIdSubmit;
208  }
209  return m_runnableId;
210  }
211 
213  Node* getNode() const final
214  {
215  return m_node;
216  }
217 
218 private:
220  Node* m_node;
222  PassFunctionT m_functionInt;
224  dw::core::FixedString<MAX_NAME_LEN> m_runnableId;
226  dw::core::FixedString<MAX_NAME_LEN> m_runnableIdSubmit;
227 };
228 
229 } // namespace framework
230 } // namespace dw
231 
232 #endif // DW_FRAMEWORK_PASS_HPP_
virtual void setRunnableId(dw::core::StringView const &runnableId)=0
Set the runnable id.
dw::core::FixedString< MAX_NAME_LEN > const & getRunnableId(bool isSubmitPass) const final
Definition: Pass.hpp:203
static constexpr size_t MAX_NAME_LEN
The maximum length of the runnable id.
Definition: Pass.hpp:55
NvMediaDla * m_dlaEngine
The dla engine to run on in case the processor type is GPU.
Definition: Pass.hpp:101
void setRunnableId(dw::core::StringView const &runnableId) final
Definition: Pass.hpp:191
dwProcessType m_processType
The process type this pass runs with.
Definition: Pass.hpp:84
virtual ~Pass()=default
Destructor.
static dwStatus guard(TryBlock tryBlock)
Same as previous guard but with a simpler tryBlock with signature &#39;void tryBlock()&#39; Always returns DW...
Definition: Exception.hpp:228
dwStatus run() final
Definition: Pass.hpp:182
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:139
dwTime_t m_avgTime
Definition: Pass.hpp:91
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:126
Pass is a runnable describes the metadata of a pass.
Definition: Pass.hpp:49
virtual Node * getNode() const =0
Get the node this pass belongs to.
dwTime_t m_maxTime
Definition: Pass.hpp:94
dwProcessorType m_processor
The processor type this pass runs on.
Definition: Pass.hpp:81
virtual dwStatus run()=0
Run the pass.
Definition: Exception.hpp:46
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:161
PassImpl contains the function to invoke on run().
Definition: Pass.hpp:121
dwTime_t m_minTime
Definition: Pass.hpp:88
cudaStream_t m_cudaStream
The cuda stream to use in case the processor type is GPU.
Definition: Pass.hpp:98
Pass(dwProcessorType const processor, dwProcessType const processType, dwTime_t const minTime, dwTime_t const avgTime, dwTime_t const maxTime) noexcept
Constructor.
Definition: Pass.hpp:105
Pass(Pass const &)=delete
Copy constructor.
virtual dw::core::FixedString< MAX_NAME_LEN > const & getRunnableId(bool isSubmitPass) const =0
Get the runnable id.
Node * getNode() const final
Definition: Pass.hpp:213
Pass & operator=(Pass const &)=delete
Copy assignment operator.