Compute Graph Framework SDK Reference  5.10
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-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_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
106template <typename T>
108{
109public:
110 using NodeT = T;
111
115 {
116 initialize();
117 }
118
120 : SimpleNode(params)
121 {
122 initialize();
123 }
124
125 // TODO(chale): make final virtual once other users of this class are migrated.
127 std::unique_ptr<Pass> createSetupPass() override
128 {
129 throw ExceptionWithStatus(DW_CALL_NOT_ALLOWED, "Not meant to be called");
130 }
131
132 // TODO(chale): make final virtual once other users of this class are migrated.
134 std::unique_ptr<Pass> createTeardownPass() override
135 {
136 throw ExceptionWithStatus(DW_CALL_NOT_ALLOWED, "Not meant to be called");
137 }
138
140 virtual dwStatus setupImpl()
141 {
142 return this->setup();
143 }
144
146 virtual dwStatus teardownImpl()
147 {
148 return this->teardown();
149 }
150
152 dwStatus reset() override
153 {
154 this->resetPorts();
155 return DW_SUCCESS;
156 }
157
159 dwStatus validate() override
160 {
161 if (getRegisteredInputPorts().empty() && getRegisteredOutputPorts().empty())
162 {
163 throw ExceptionWithStatus(DW_NOT_IMPLEMENTED, "Not implemented");
164 }
165
166 const PortCollectionDescriptor inputPorts = createPortCollectionDescriptor<NodeT, PortDirection::INPUT>();
167 dwStatus status = SimpleNode::validate("input", inputPorts, getRegisteredInputPorts());
168 if (status != DW_SUCCESS)
169 {
170 return status;
171 }
172 const PortCollectionDescriptor outputPorts = createPortCollectionDescriptor<NodeT, PortDirection::OUTPUT>();
173 return SimpleNode::validate("output", outputPorts, getRegisteredOutputPorts(), inputPorts.getPortSize());
174 }
175
176private:
177 void initialize()
178 {
179 NODE_REGISTER_PASS("SETUP"_sv, [this]() -> dwStatus {
180 return setupImpl();
181 });
182 NODE_REGISTER_PASS("TEARDOWN"_sv, [this]() -> dwStatus {
183 return teardownImpl();
184 });
185 }
186};
187
189template <typename T>
191{
192};
193
195template <typename T>
197{
198};
199
200} // namespace framework
201} // namespace dw
202
203#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:113
const dw::core::HeapHashMap< size_t, std::shared_ptr< PortBase > > & getRegisteredInputPorts() const
Definition: SimpleNode.hpp:584
const dw::core::HeapHashMap< size_t, std::shared_ptr< PortBase > > & getRegisteredOutputPorts() const
Definition: SimpleNode.hpp:589
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:65
Definition: Buffer.hpp:40