Compute Graph Framework SDK Reference  5.12
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
39namespace dw
40{
41namespace framework
42{
43
45class Node;
46
48class Pass
49{
50public:
52 // coverity[autosar_cpp14_a0_1_1_violation] FP: nvbugs/2813925
53 // coverity[autosar_cpp14_a5_1_1_violation]
54 // coverity[autosar_cpp14_m0_1_4_violation] RFD Pending: TID-2055
55 static constexpr const 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;
76 dw::core::HeapHashMap<dwStatus, uint32_t> const& getPassReturnErrorMap() { return m_passReturnErrorMapping; }
77
79 virtual Node& getNode() const = 0;
80
82 dwProcessorType m_processor;
83
85 cudaStream_t m_cudaStream;
86
91
92protected:
94 Pass(dwProcessorType const processor,
95 std::initializer_list<std::pair<dwStatus, uint32_t>> const& returnMapping = {});
96
97private:
99 dw::core::HeapHashMap<dwStatus, uint32_t> m_passReturnErrorMapping;
100};
101
103template <typename PassFunctionT>
104class PassImpl : public Pass
105{
106 static_assert(std::is_convertible<PassFunctionT, std::function<dwStatus()>>::value, "PassFunctionT must be callable without arguments and return dwStatus");
107
108public:
111 PassFunctionT const passFunc,
112 dwProcessorType const processor,
113 std::initializer_list<std::pair<dwStatus, uint32_t>> const& returnMapping = {})
114 : Pass(processor, returnMapping)
115 , m_node(node)
116 , m_functionInt(passFunc)
117 {
118 }
119
123 PassFunctionT const passFunc,
124 dwProcessorType const processor,
125 cudaStream_t const cudaStream,
126 std::initializer_list<std::pair<dwStatus, uint32_t>> const& returnMapping = {})
127 : Pass(processor, returnMapping)
128 , m_node(node)
129 , m_functionInt(passFunc)
130 {
131 if (processor == DW_PROCESSOR_TYPE_GPU)
132 {
134 }
135 else
136 {
137 throw ExceptionWithStatus(DW_NOT_SUPPORTED, "PassImpl: Only GPU passes can use a cuda stream");
138 }
139 }
140
142 dwStatus run() final
143 {
144 // TODO(DRIV-7184) - return code of the function shall not be ignored
145 return ExceptionGuard::guard([&] {
146 m_functionInt();
147 },
148 dw::core::Logger::Verbosity::WARN);
149 }
150
152 void setRunnableId(dw::core::StringView const& runnableId) final
153 {
154 // coverity[autosar_cpp14_a5_1_1_violation]
155 if (runnableId.size() >= 128U - 10U - 1U)
156 {
157 throw ExceptionWithStatus(DW_BUFFER_FULL, "setRunnableId() runnable id exceeds capacity: ", runnableId);
158 }
159 m_runnableId = dw::core::FixedString<128>(runnableId.data(), runnableId.size());
160 m_runnableIdSubmit = dw::core::FixedString<128>(runnableId.data(), runnableId.size());
161 // coverity[autosar_cpp14_a5_1_1_violation]
162 m_runnableIdSubmit += "_submittee";
163 }
164
166 dw::core::FixedString<MAX_NAME_LEN> const& getRunnableId(bool isSubmitPass) const final
167 {
168 if (isSubmitPass)
169 {
170 return m_runnableIdSubmit;
171 }
172 return m_runnableId;
173 }
174
176 Node& getNode() const final
177 {
178 return m_node;
179 }
180
181private:
183 Node& m_node;
185 PassFunctionT m_functionInt;
187 dw::core::FixedString<MAX_NAME_LEN> m_runnableId;
189 dw::core::FixedString<MAX_NAME_LEN> m_runnableIdSubmit;
190};
191
192} // namespace framework
193} // namespace dw
194
195#endif // DW_FRAMEWORK_PASS_HPP_
static dwStatus guard(TryBlock const &tryBlock, ::dw::core::Logger::Verbosity verbosity=::dw::core::Logger::Verbosity::ERROR)
Definition: Exception.hpp:177
PassImpl contains the function to invoke on run().
Definition: Pass.hpp:105
dwStatus run() final
Definition: Pass.hpp:142
PassImpl(Node &node, PassFunctionT const passFunc, dwProcessorType const processor, cudaStream_t const cudaStream, std::initializer_list< std::pair< dwStatus, uint32_t > > const &returnMapping={})
Definition: Pass.hpp:122
void setRunnableId(dw::core::StringView const &runnableId) final
Definition: Pass.hpp:152
Node & getNode() const final
Definition: Pass.hpp:176
dw::core::FixedString< MAX_NAME_LEN > const & getRunnableId(bool isSubmitPass) const final
Definition: Pass.hpp:166
PassImpl(Node &node, 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:110
Pass is a runnable describes the metadata of a pass.
Definition: Pass.hpp:49
Pass(Pass const &)=delete
Copy constructor.
virtual Node & getNode() const =0
Get the node this pass belongs to.
bool m_isFirstIteration
Definition: Pass.hpp:90
cudaStream_t m_cudaStream
The cuda stream to use in case the processor type is GPU.
Definition: Pass.hpp:85
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:82
Pass(dwProcessorType const processor, std::initializer_list< std::pair< dwStatus, uint32_t > > const &returnMapping={})
Constructor.
dw::core::HeapHashMap< dwStatus, uint32_t > const & getPassReturnErrorMap()
Get the return status code to error map.
Definition: Pass.hpp:76
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:55
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