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

SimpleNodeT.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) 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_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)
41 #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__)
58 
63 #define NODE_INIT_INPUT_ARRAY_PORT(identifier, ...) \
64  this->template initInputArrayPort<NodeT, dw::framework::portIndex<NodeT, dw::framework::PortDirection::INPUT>(identifier)>(__VA_ARGS__)
65 
70 #define NODE_INIT_OUTPUT_PORT(identifier, ...) \
71  this->template initOutputPort<NodeT, dw::framework::portIndex<NodeT, dw::framework::PortDirection::OUTPUT>(identifier)>(__VA_ARGS__)
72 
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)>()
85 
89 #define NODE_GET_INPUT_ARRAY_PORT(identifier, index) this->template getInputPort<NodeT, NODE_GET_INPUT_PORT_INDEX(identifier)>(index)
90 
94 #define NODE_GET_OUTPUT_PORT(identifier) this->template getOutputPort<NodeT, NODE_GET_OUTPUT_PORT_INDEX(identifier)>()
95 
99 #define NODE_GET_OUTPUT_ARRAY_PORT(identifier, index) this->template getOutputPort<NodeT, NODE_GET_OUTPUT_PORT_INDEX(identifier)>(index)
100 
101 namespace dw
102 {
103 namespace framework
104 {
105 
106 template <typename T>
108 {
109 public:
110  using NodeT = T;
111 };
112 
113 template <typename T>
115 {
116 public:
117  using NodeT = T;
118 
122  {
123  initialize();
124  }
125 
127  : SimpleSensorNode(params)
128  {
129  initialize();
130  }
131 
132  // TODO(chale): make final virtual once other users of this class are migrated.
134  std::unique_ptr<Pass> createSetupPass() override
135  {
136  throw Exception(DW_CALL_NOT_ALLOWED, "Not meant to be called");
137  }
138 
139  // TODO(chale): make final virtual once other users of this class are migrated.
141  std::unique_ptr<Pass> createTeardownPass() override
142  {
143  throw Exception(DW_CALL_NOT_ALLOWED, "Not meant to be called");
144  }
145 
147  virtual dwStatus setupImpl()
148  {
149  return this->setup();
150  }
151 
153  virtual dwStatus teardownImpl()
154  {
155  return this->teardown();
156  }
157 
159  dwStatus reset() override
160  {
161  this->resetPorts();
162  return DW_SUCCESS;
163  }
164 
166  dwStatus validate() override
167  {
168  if (getRegisteredInputPorts().empty() && getRegisteredOutputPorts().empty())
169  {
170  throw Exception(DW_NOT_IMPLEMENTED, "Not implemented");
171  }
172 
173  const PortCollectionDescriptor inputPorts = createPortCollectionDescriptor<NodeT, PortDirection::INPUT>();
174  dwStatus status = SimpleSensorNode::validate("input", inputPorts, getRegisteredInputPorts());
175  if (status != DW_SUCCESS)
176  {
177  return status;
178  }
179  const PortCollectionDescriptor outputPorts = createPortCollectionDescriptor<NodeT, PortDirection::OUTPUT>();
180  return SimpleSensorNode::validate("output", outputPorts, getRegisteredOutputPorts(), inputPorts.getPortSize());
181  }
182 
183 private:
184  void initialize()
185  {
186  NODE_REGISTER_PASS("SETUP"_sv, [this]() -> dwStatus {
187  return setupImpl();
188  });
189  NODE_REGISTER_PASS("TEARDOWN"_sv, [this]() -> dwStatus {
190  return teardownImpl();
191  });
192  }
193 };
194 
195 template <typename T>
197 {
198 public:
199  using NodeT = T;
200 
204  {
205  NODE_REGISTER_PASS("SETUP"_sv, [this]() -> dwStatus {
206  return setupImpl();
207  });
208  NODE_REGISTER_PASS("TEARDOWN"_sv, [this]() -> dwStatus {
209  return teardownImpl();
210  });
211  }
212 
213  // TODO(chale): make final virtual once other users of this class are migrated.
215  std::unique_ptr<Pass> createSetupPass() override
216  {
217  throw Exception(DW_CALL_NOT_ALLOWED, "Not meant to be called");
218  }
219 
220  // TODO(chale): make final virtual once other users of this class are migrated.
222  std::unique_ptr<Pass> createTeardownPass() override
223  {
224  throw Exception(DW_CALL_NOT_ALLOWED, "Not meant to be called");
225  }
226 
228  virtual dwStatus setupImpl()
229  {
230  return this->setup();
231  }
232 
234  virtual dwStatus teardownImpl()
235  {
236  return this->teardown();
237  }
238 
240  dwStatus reset() override
241  {
242  this->resetPorts();
243  return DW_SUCCESS;
244  }
245 
247  dwStatus validate() override
248  {
249  if (getRegisteredInputPorts().empty() && getRegisteredOutputPorts().empty())
250  {
251  throw Exception(DW_NOT_IMPLEMENTED, "Not implemented");
252  }
253 
254  const PortCollectionDescriptor inputPorts = createPortCollectionDescriptor<NodeT, PortDirection::INPUT>();
255  dwStatus status = SimpleProcessNode::validate("input", inputPorts, getRegisteredInputPorts());
256  if (status != DW_SUCCESS)
257  {
258  return status;
259  }
260  const PortCollectionDescriptor outputPorts = createPortCollectionDescriptor<NodeT, PortDirection::OUTPUT>();
261  return SimpleProcessNode::validate("output", outputPorts, getRegisteredOutputPorts(), inputPorts.getPortSize());
262  }
263 };
264 
265 } // namespace framework
266 } // namespace dw
267 
268 #endif // DW_FRAMEWORK_SIMPLENODET_HPP_
virtual dwStatus teardownImpl()
The default implementation calls SimpleNode::teardown.
virtual dwStatus teardownImpl()
The default implementation calls SimpleNode::teardown.
dwStatus validate() override
Validate that all registered ports which have the flag binding-required are bound to a channel...
virtual dwStatus setupImpl()
The default implementation calls SimpleNode::setup.
dwStatus validate() override
Definition: SimpleNode.hpp:624
std::unique_ptr< Pass > createTeardownPass() override
dwStatus validate() override
Definition: SimpleNode.hpp:800
std::unique_ptr< Pass > createSetupPass() override
std::unique_ptr< Pass > createSetupPass() override
NodeAllocationParams createAllocationParams()
Definition: SimpleNode.hpp:68
SimpleSensorNodeT(NodeAllocationParams params)
SimpleSensorNodeT()
Default constructor registering the setup and teardown passes.
virtual dwStatus setupImpl()
The default implementation calls SimpleNode::setup.
dwStatus reset() override
The default implementation calls SimpleNode::resetPorts.
dwStatus validate() override
Validate that all registered ports which have the flag binding-required are bound to a channel...
Definition: Exception.hpp:46
#define NODE_REGISTER_PASS(identifier,...)
Register a pass function with the node base class.
Definition: SimpleNodeT.hpp:49
std::unique_ptr< Pass > createTeardownPass() override
SimpleProcessNodeT()
Default constructor registering the setup and teardown passes.
dwStatus reset() override
The default implementation calls SimpleNode::resetPorts.