Compute Graph Framework SDK Reference  5.22
SimpleNodeT.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-2024 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_SIMPLENODET_HPP_
32#define DW_FRAMEWORK_SIMPLENODET_HPP_
33
38
40#define NODE_GET_INPUT_PORT_INDEX(identifier) dw::framework::portIndex<NodeT, dw::framework::PortDirection::INPUT>(identifier)
42#define NODE_GET_OUTPUT_PORT_INDEX(identifier) dw::framework::portIndex<NodeT, dw::framework::PortDirection::OUTPUT>(identifier)
43
45
49#define NODE_REGISTER_PASS(identifier, ...) this->template registerPass<NodeT, dw::framework::passIndex<NodeT>(identifier)>(__VA_ARGS__)
50
52
56#define NODE_INIT_INPUT_PORT(identifier, ...) \
57 this->template initInputPort<NodeT, dw::framework::portIndex<NodeT, dw::framework::PortDirection::INPUT>(identifier)>(__VA_ARGS__)
59
65#define NODE_INIT_INPUT_ARRAY_PORTS(identifier, ...) \
66 this->template initInputArrayPorts<NodeT, dw::framework::portIndex<NodeT, dw::framework::PortDirection::INPUT>(identifier)>(__VA_ARGS__)
68
72#define NODE_INIT_INPUT_ARRAY_PORT(identifier, arrayIndex, ...) \
73 this->template initInputArrayPort<NodeT, dw::framework::portIndex<NodeT, dw::framework::PortDirection::INPUT>(identifier)>(arrayIndex, ##__VA_ARGS__)
75
79#define NODE_INIT_OUTPUT_PORT(identifier, ...) \
80 this->template initOutputPort<NodeT, dw::framework::portIndex<NodeT, dw::framework::PortDirection::OUTPUT>(identifier)>(__VA_ARGS__)
82
88#define NODE_INIT_OUTPUT_ARRAY_PORTS(identifier, ...) \
89 this->template initOutputArrayPorts<NodeT, dw::framework::portIndex<NodeT, dw::framework::PortDirection::OUTPUT>(identifier)>(__VA_ARGS__)
91
95#define NODE_INIT_OUTPUT_ARRAY_PORT(identifier, arrayIndex, ...) \
96 this->template initOutputArrayPort<NodeT, dw::framework::portIndex<NodeT, dw::framework::PortDirection::OUTPUT>(identifier)>(arrayIndex, ##__VA_ARGS__)
97
99
102#define NODE_GET_INPUT_PORT(identifier) this->template getInputPort<NodeT, NODE_GET_INPUT_PORT_INDEX(identifier)>()
104
107#define NODE_GET_INPUT_ARRAY_PORT(identifier, index) this->template getInputPort<NodeT, NODE_GET_INPUT_PORT_INDEX(identifier)>(index)
109
112#define NODE_GET_OUTPUT_PORT(identifier) this->template getOutputPort<NodeT, NODE_GET_OUTPUT_PORT_INDEX(identifier)>()
114
117#define NODE_GET_OUTPUT_ARRAY_PORT(identifier, index) this->template getOutputPort<NodeT, NODE_GET_OUTPUT_PORT_INDEX(identifier)>(index)
118
119namespace dw
120{
121namespace framework
122{
123
124// coverity[autosar_cpp14_a14_1_1_violation] FP: nvbugs/4356873
125template <typename T>
126// coverity[autosar_cpp14_a12_1_6_violation] FP: nvbugs/4016780
128{
129public:
130 // coverity[autosar_cpp14_a0_1_6_violation]
131 using NodeT = T;
132
136 {
137 }
138
140 : SimpleNode(params)
141 {
142 initialize();
143 }
144
145 // coverity[autosar_cpp14_a12_7_1_violation] FP: nvbugs/4356873
147 {
148 // can't be checked within class scope since
149 // a concrete class MyClass might want to inherit from SimpleNodeT<MyClass>
150 // at which point T is an incomplete type in the class scope
151 static_assert(std::is_base_of<Node, T>::value, "T must inherit from Node");
152 }
153
155 virtual dwStatus setupImpl()
156 {
157 return this->setup();
158 }
159
161 virtual dwStatus teardownImpl()
162 {
163 return this->teardown();
164 }
165
167 dwStatus reset() override
168 {
169 this->resetPorts();
170 return DW_SUCCESS;
171 }
172
174 dwStatus validate() override
175 {
176 if (getRegisteredInputPorts().empty() && getRegisteredOutputPorts().empty())
177 {
178 throw ExceptionWithStatus(DW_NOT_IMPLEMENTED, "Not implemented");
179 }
180
181 const char* INPUT_DIRECTION{"input"};
182 // coverity[autosar_cpp14_a18_5_8_violation] FP: nvbugs/3498833
183 const PortCollectionDescriptor inputPortDescs{createPortCollectionDescriptor<NodeT, PortDirection::INPUT>()};
184 dwStatus status{SimpleNode::validate(
185 INPUT_DIRECTION, inputPortDescs,
186 [&](size_t portIdx) -> bool {
187 const dw::core::HeapHashMap<size_t, std::shared_ptr<ManagedPortInputBase>>& registeredPorts{getRegisteredInputPorts()};
188 dw::core::HeapHashMap<size_t, std::shared_ptr<ManagedPortInputBase>>::const_iterator it{registeredPorts.find(portIdx)};
189 if (it == registeredPorts.end())
190 {
191 throw ExceptionWithStatus(DW_NOT_IMPLEMENTED, "Input port was not registered");
192 }
193 if (nullptr == it->second.get())
194 {
195 throw ExceptionWithStatus(DW_NOT_INITIALIZED, "Input port was not initialized");
196 }
197 return it->second->isBound();
198 })};
199 // LCOV_EXCL_START defensive code can't be triggered since SimpleNode::validate() always returns success or throws
200 if (DW_SUCCESS != status)
201 {
202 return status;
203 }
204 // LCOV_EXCL_STOP
205 const char* OUTPUT_DIRECTION{"output"};
206 const PortCollectionDescriptor outputPortDescs{createPortCollectionDescriptor<NodeT, PortDirection::OUTPUT>()};
207 size_t outputPortOffset{inputPortDescs.getPortSize()};
209 OUTPUT_DIRECTION, outputPortDescs,
210 [&](size_t portIdx) -> bool {
211 const dw::core::HeapHashMap<size_t, std::shared_ptr<ManagedPortOutputBase>>& registeredPorts{getRegisteredOutputPorts()};
212 dw::core::HeapHashMap<size_t, std::shared_ptr<ManagedPortOutputBase>>::const_iterator it{registeredPorts.find(portIdx + outputPortOffset)};
213 if (it == registeredPorts.end())
214 {
215 throw ExceptionWithStatus(DW_NOT_IMPLEMENTED, "Output port was not registered");
216 }
217 if (nullptr == it->second.get())
218 {
219 throw ExceptionWithStatus(DW_NOT_INITIALIZED, "Output port was not initialized");
220 }
221 return it->second->isBound();
222 });
223 }
224
225private:
226 void initialize()
227 {
228 NODE_REGISTER_PASS("SETUP"_sv, [this]() -> dwStatus {
229 return setupImpl();
230 },
231 {{DW_NOT_AVAILABLE, 0U}});
232 NODE_REGISTER_PASS("TEARDOWN"_sv, [this]() -> dwStatus {
233 return teardownImpl();
234 });
235 }
236};
237
238} // namespace framework
239} // namespace dw
240
241#endif // DW_FRAMEWORK_SIMPLENODET_HPP_
#define NODE_REGISTER_PASS(identifier,...)
Register a pass function with the node base class.
Definition: SimpleNodeT.hpp:49
dwStatus validate() override
Validate that all registered ports which have the flag binding-required are bound to a channel.
SimpleNodeT()
Default constructor registering the setup and teardown passes.
virtual dwStatus setupImpl()
The default implementation calls SimpleNode::setup.
SimpleNodeT(NodeAllocationParams params)
virtual dwStatus teardownImpl()
The default implementation calls SimpleNode::teardown.
dwStatus reset() override
The default implementation calls SimpleNode::resetPorts.
dwStatus validate() override
Definition: SimpleNode.hpp:114
const dw::core::HeapHashMap< size_t, std::shared_ptr< ManagedPortOutputBase > > & getRegisteredOutputPorts() const
Definition: SimpleNode.hpp:571
const dw::core::HeapHashMap< size_t, std::shared_ptr< ManagedPortInputBase > > & getRegisteredInputPorts() const
Definition: SimpleNode.hpp:566
void resetPorts() override
Default implementation to reset ports managed by the base class.
dwStatus setup()
Default implementation of the setup pass.
dwStatus teardown()
Default implementation of the teardown pass.
NodeAllocationParams createAllocationParams()
Definition: SimpleNode.hpp:76
Definition: Buffer.hpp:41