Compute Graph Framework SDK Reference  5.6
Node.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) 2017-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_BASECLASS_NODE_HPP_
32#define DW_FRAMEWORK_BASECLASS_NODE_HPP_
33
34#include <map>
35
36#include <dw/core/base/Types.h>
37#include <dw/core/base/ObjectExtra.h>
38
39#include <dwcgf/Types.hpp>
41#include <dwcgf/pass/Pass.hpp>
44#include <dw/core/container/VectorFixed.hpp>
45#include <dw/core/container/BaseString.hpp>
46
47#include <string>
48#include <memory>
49#include <atomic>
50
51namespace dw
52{
53namespace framework
54{
55using dw::core::FixedString;
56using dw::core::VectorFixed;
57class ParameterProvider;
58
59#define _DW_CGF_STRINGIFY(x) #x
60// std::char_traits<char8_t>::length() is not constexpr before C++17, use "sizeof() - 1" as WAR
61#define STRING_VIEW_OF_FIXED_STRING_TEMPLATE_TYPE(x) dw::core::StringView("dw::core::FixedString<" _DW_CGF_STRINGIFY(x) ">", sizeof("dw::core::FixedString<" _DW_CGF_STRINGIFY(x) ">") - 1)
62
63class Node
64{
65public:
66 static constexpr size_t MAX_NAME_LEN = 128;
67 using Name_t = FixedString<MAX_NAME_LEN>;
68
69 static constexpr uint32_t MAX_PORT_COUNT = 256;
70
71 static constexpr uint32_t MAX_PASS_COUNT = 256;
72 static constexpr uint8_t PASS_SETUP = std::numeric_limits<uint8_t>::max() - 1;
73 static constexpr uint8_t PASS_TEARDOWN = std::numeric_limits<uint8_t>::max();
74
75 virtual ~Node() = default;
76
81 virtual dwStatus reset() = 0;
82
89 virtual dwStatus setInputChannel(ChannelObject* channel, uint8_t portID) = 0;
90
98 virtual dwStatus setInputChannel(ChannelObject* channel, uint8_t portID, dwSerializationType dataType) = 0;
99
106 virtual dwStatus setOutputChannel(ChannelObject* channel, uint8_t portID) = 0;
107
117 virtual dwStatus validate() = 0;
118
123 virtual dwStatus run() = 0;
124
129 virtual size_t getPassCount() const noexcept = 0;
130
136 virtual dwStatus runPassByID(uint8_t passID) = 0;
137
143 virtual dwStatus runPass(size_t passIndex) = 0;
144
150 virtual dwStatus getPasses(VectorFixed<Pass*>& passList) = 0;
151
159 virtual dwStatus getPasses(VectorFixed<Pass*>& passList,
160 dwProcessorType processorType,
161 dwProcessType processType) = 0;
162
168 virtual dwStatus setName(const char* name) = 0;
169
175 virtual dwStatus getName(const char** name) = 0;
176
182 virtual dwStatus getErrorSignal(dwGraphErrorSignal*& errorSignal) = 0;
183
190 virtual dwStatus getHealthSignal(dwGraphHealthSignal*& healthSignals, bool updateFromModule = false) = 0;
191
200 virtual dwStatus reportCurrentErrorSignal(dwGraphErrorSignal& signal) = 0;
201
210 virtual dwStatus reportCurrentHealthSignal(dwGraphHealthSignal& signal) = 0;
211
217 virtual dwStatus setIterationCount(uint32_t iterationCount) = 0;
218
226 virtual dwStatus setState(const char* state) = 0;
227};
228
230{
231public:
236 virtual dwStatus start() = 0;
237
242 virtual dwStatus stop() = 0;
243
248 virtual dwStatus setAffinityMask(uint) = 0;
249
254 virtual dwStatus setThreadPriority(int) = 0;
255
260 virtual dwStatus setStartTime(dwTime_t) = 0;
261
266 virtual dwStatus setEndTime(dwTime_t) = 0;
267
272 virtual dwStatus isVirtual(bool* isVirtualBool) = 0;
273
274 enum class DataEventType
275 {
276 PRODUCE, // sensor node produces data for a node-run
277 DROP, // sensor node drops data in the next node-run
278 NONE, // sensor node does not produce data for a node-run
279 };
280
285 {
297 dwStatus status;
302 dwTime_t timestamp;
303 };
304
305 using DataEventReadCallback = dw::core::Function<bool(DataEvent&)>;
313
314 using DataEventWriteCallback = dw::core::Function<void(DataEvent)>;
322};
323
325{
326public:
329
332
335
338
340 : m_node(node)
341 , m_sensorNode(dynamic_cast<ISensorNode*>(node))
342 {
343 if (m_sensorNode != nullptr)
344 {
345 throw Exception(DW_INVALID_ARGUMENT, "Passed node pointer does not implement ISensorNode.");
346 }
347 }
348
350 {
351 return m_node;
352 }
353
354 Node const* getNode() const
355 {
356 return m_node;
357 }
358
360 {
361 return m_sensorNode;
362 }
363
365 {
366 return m_sensorNode;
367 }
368
369private:
370 Node* m_node{};
371 ISensorNode* m_sensorNode{};
372};
373
382{
383public:
384 virtual ~IContainsPreShutdownAction() = default;
385
390 virtual dwStatus preShutdown() = 0;
391};
392
393// TODO(ajayawardane) WAR: When there is a single SSM pass in the graph, reset could potentially
394// be called while node passes are running. Until STM schedule re-entry is supported, we reset the
395// supported nodes in the setup pass.
397{
398public:
399 virtual ~IAsyncResetable() = default;
400
405 virtual dwStatus setAsyncReset() = 0;
410 virtual dwStatus executeAsyncReset() = 0;
411};
412
415
416} // namespace framework
417} // namespace dw
418
420
421#endif // DW_FRAMEWORK_BASECLASS_NODE_HPP_
Basic error signal that gets reported only when there is an error.
Basic health signal that describes the health status of the graph.
virtual dwStatus setAsyncReset()=0
Set the async reset flag.
virtual dwStatus executeAsyncReset()=0
Executes a reset if the async reset flag is set.
virtual ~IAsyncResetable()=default
virtual dwStatus preShutdown()=0
actions to be taken before node shutdown
virtual dwStatus setAffinityMask(uint)=0
Sets the affinity mask of the sensor.
virtual dwStatus setDataEventReadCallback(DataEventReadCallback cb)=0
Set read timestamp function for dataset replay. Timestamps not in the sequence returned by the callba...
virtual dwStatus setDataEventWriteCallback(DataEventWriteCallback cb)=0
Set write timestamp function for live case. Each timestamp of data output from the node will be passe...
virtual dwStatus start()=0
Start the sensor.
virtual dwStatus setEndTime(dwTime_t)=0
Set end timestamp for dataset replay.
dw::core::Function< bool(DataEvent &)> DataEventReadCallback
Definition: Node.hpp:305
virtual dwStatus stop()=0
Stop the sensor.
virtual dwStatus isVirtual(bool *isVirtualBool)=0
distinguishes between a live and virtual sensor
dw::core::Function< void(DataEvent)> DataEventWriteCallback
Definition: Node.hpp:314
virtual dwStatus setThreadPriority(int)=0
Sets the thread priority of the sensor.
virtual dwStatus setStartTime(dwTime_t)=0
Set start timestamp for dataset replay.
virtual dwStatus validate()=0
Checks that all mandatory ports are bound. The implementation should validate that all the ports are ...
virtual dwStatus setOutputChannel(ChannelObject *channel, uint8_t portID)=0
Sets an output channel for this node with an accompanying port.
virtual dwStatus runPass(size_t passIndex)=0
Run one pass by index as defined by the pass descriptors.
virtual dwStatus setInputChannel(ChannelObject *channel, uint8_t portID)=0
Sets an input channel for this node with an accompanying port.
static constexpr uint8_t PASS_TEARDOWN
Definition: Node.hpp:73
virtual dwStatus run()=0
Runs all the passes in the node.
virtual ~Node()=default
FixedString< MAX_NAME_LEN > Name_t
Definition: Node.hpp:67
static constexpr uint8_t PASS_SETUP
Definition: Node.hpp:72
virtual dwStatus getErrorSignal(dwGraphErrorSignal *&errorSignal)=0
Get the pointer to the error signal for this node.
static constexpr uint32_t MAX_PORT_COUNT
Definition: Node.hpp:69
virtual size_t getPassCount() const noexcept=0
Get number of passes in the node.
virtual dwStatus getHealthSignal(dwGraphHealthSignal *&healthSignals, bool updateFromModule=false)=0
Get the pointer to the health signal for this node.
virtual dwStatus setIterationCount(uint32_t iterationCount)=0
Sets the node's iteration count.
static constexpr uint32_t MAX_PASS_COUNT
Definition: Node.hpp:71
virtual dwStatus getPasses(VectorFixed< Pass * > &passList)=0
Get all the passes in the node.
static constexpr size_t MAX_NAME_LEN
Definition: Node.hpp:66
virtual dwStatus runPassByID(uint8_t passID)=0
Run one pass by ID as defined by the PassList enum class.
virtual dwStatus setName(const char *name)=0
Set the name of the node.
virtual dwStatus getName(const char **name)=0
Get the name of the node.
virtual dwStatus reportCurrentErrorSignal(dwGraphErrorSignal &signal)=0
A function that allows user override to update error signal It is automatically called by dwFramework...
virtual dwStatus reportCurrentHealthSignal(dwGraphHealthSignal &signal)=0
A function that allows user override to update health signal It is automatically called by dwFramewor...
virtual dwStatus reset()=0
Resets the state of the node.
virtual dwStatus setInputChannel(ChannelObject *channel, uint8_t portID, dwSerializationType dataType)=0
Sets an input channel for this node with an accompanying port.
virtual dwStatus setState(const char *state)=0
Set the current state in node. Node implementation of this API need to be thread-safe.
Pass is a runnable describes the metadata of a pass.
Definition: Pass.hpp:50
SensorNode(Node *node)
Definition: Node.hpp:339
ISensorNode::DataEventReadCallback DataEventReadCallback
Definition: Node.hpp:334
Node const * getNode() const
Definition: Node.hpp:354
ISensorNode * getSensorNode()
Definition: Node.hpp:359
ISensorNode const * getSensorNode() const
Definition: Node.hpp:364
ISensorNode::DataEventWriteCallback DataEventWriteCallback
Definition: Node.hpp:337
constexpr size_t passIndex(dw::core::StringView identifier)
Get the the pass index for a pass identified by name.
Definition: Exception.hpp:47