Compute Graph Framework SDK Reference  5.12
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-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_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
63#define NODE_INIT_INPUT_ARRAY_PORT(identifier, ...) \
64 this->template initInputArrayPort<NodeT, dw::framework::portIndex<NodeT, dw::framework::PortDirection::INPUT>(identifier)>(__VA_ARGS__)
66
70#define NODE_INIT_OUTPUT_PORT(identifier, ...) \
71 this->template initOutputPort<NodeT, dw::framework::portIndex<NodeT, dw::framework::PortDirection::OUTPUT>(identifier)>(__VA_ARGS__)
73
77#define NODE_INIT_OUTPUT_ARRAY_PORT(identifier, ...) \
78 this->template initOutputArrayPort<NodeT, dw::framework::portIndex<NodeT, dw::framework::PortDirection::OUTPUT>(identifier)>(__VA_ARGS__)
79
81
84#define NODE_GET_INPUT_PORT(identifier) this->template getInputPort<NodeT, NODE_GET_INPUT_PORT_INDEX(identifier)>()
86
89#define NODE_GET_INPUT_ARRAY_PORT(identifier, index) this->template getInputPort<NodeT, NODE_GET_INPUT_PORT_INDEX(identifier)>(index)
91
94#define NODE_GET_OUTPUT_PORT(identifier) this->template getOutputPort<NodeT, NODE_GET_OUTPUT_PORT_INDEX(identifier)>()
96
99#define NODE_GET_OUTPUT_ARRAY_PORT(identifier, index) this->template getOutputPort<NodeT, NODE_GET_OUTPUT_PORT_INDEX(identifier)>(index)
100
101namespace dw
102{
103namespace framework
104{
105
106// coverity[autosar_cpp14_a14_1_1_violation]
107template <typename T>
108// coverity[autosar_cpp14_a12_1_6_violation]
110{
111public:
112 // coverity[autosar_cpp14_a0_1_6_violation]
113 using NodeT = T;
114
118 {
119 initialize();
120 }
121
123 : SimpleNode(params)
124 {
125 initialize();
126 }
127
128 // TODO(chale): make final virtual once other users of this class are migrated.
130 std::unique_ptr<Pass> createSetupPass() override
131 {
132 throw ExceptionWithStatus(DW_CALL_NOT_ALLOWED, "Not meant to be called");
133 }
134
135 // TODO(chale): make final virtual once other users of this class are migrated.
137 std::unique_ptr<Pass> createTeardownPass() override
138 {
139 throw ExceptionWithStatus(DW_CALL_NOT_ALLOWED, "Not meant to be called");
140 }
141
143 virtual dwStatus setupImpl()
144 {
145 return this->setup();
146 }
147
149 virtual dwStatus teardownImpl()
150 {
151 return this->teardown();
152 }
153
155 dwStatus reset() override
156 {
157 this->resetPorts();
158 return DW_SUCCESS;
159 }
160
162 dwStatus validate() override
163 {
164 if (getRegisteredInputPorts().empty() && getRegisteredOutputPorts().empty())
165 {
166 throw ExceptionWithStatus(DW_NOT_IMPLEMENTED, "Not implemented");
167 }
168
169 // coverity[autosar_cpp14_a18_5_8_violation]
170 const PortCollectionDescriptor inputPortDescs{createPortCollectionDescriptor<NodeT, PortDirection::INPUT>()};
171 // coverity[autosar_cpp14_a5_1_1_violation]
172 dwStatus status{SimpleNode::validate("input", inputPortDescs,
173 [&](size_t portIdx) -> bool {
174 const dw::core::HeapHashMap<size_t, std::shared_ptr<ManagedPortInputBase>>& registeredPorts{getRegisteredInputPorts()};
175 dw::core::HeapHashMap<size_t, std::shared_ptr<ManagedPortInputBase>>::const_iterator it{registeredPorts.find(portIdx)};
176 if (it == registeredPorts.end())
177 {
178 throw ExceptionWithStatus(DW_NOT_IMPLEMENTED, "Input port was not registered");
179 }
180 if (it->second.get() == nullptr)
181 {
182 throw ExceptionWithStatus(DW_NOT_INITIALIZED, "Input port was not initialized");
183 }
184 return it->second->isBound();
185 })};
186 if (status != DW_SUCCESS)
187 {
188 return status;
189 }
190 const PortCollectionDescriptor outputPortDescs{createPortCollectionDescriptor<NodeT, PortDirection::OUTPUT>()};
191 size_t outputPortOffset{inputPortDescs.getPortSize()};
192 // coverity[autosar_cpp14_a5_1_1_violation]
193 return SimpleNode::validate("output", outputPortDescs,
194 [&](size_t portIdx) -> bool {
195 const dw::core::HeapHashMap<size_t, std::shared_ptr<ManagedPortOutputBase>>& registeredPorts{getRegisteredOutputPorts()};
196 dw::core::HeapHashMap<size_t, std::shared_ptr<ManagedPortOutputBase>>::const_iterator it{registeredPorts.find(portIdx + outputPortOffset)};
197 if (it == registeredPorts.end())
198 {
199 throw ExceptionWithStatus(DW_NOT_IMPLEMENTED, "Output port was not registered");
200 }
201 if (it->second.get() == nullptr)
202 {
203 throw ExceptionWithStatus(DW_NOT_INITIALIZED, "Output port was not initialized");
204 }
205 return it->second->isBound();
206 });
207 }
208
209private:
210 void initialize()
211 {
212 NODE_REGISTER_PASS("SETUP"_sv, [this]() -> dwStatus {
213 return setupImpl();
214 });
215 NODE_REGISTER_PASS("TEARDOWN"_sv, [this]() -> dwStatus {
216 return teardownImpl();
217 });
218 }
219};
220
222// coverity[autosar_cpp14_a14_1_1_violation]
223template <typename T>
225{
226};
227
228} // namespace framework
229} // namespace dw
230
231#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.
std::unique_ptr< Pass > createTeardownPass() override
std::unique_ptr< Pass > createSetupPass() override
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:112
const dw::core::HeapHashMap< size_t, std::shared_ptr< ManagedPortOutputBase > > & getRegisteredOutputPorts() const
Definition: SimpleNode.hpp:580
const dw::core::HeapHashMap< size_t, std::shared_ptr< ManagedPortInputBase > > & getRegisteredInputPorts() const
Definition: SimpleNode.hpp:575
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:67
Definition: Buffer.hpp:40