Compute Graph Framework SDK Reference  5.10
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/context/ObjectExtra.h>
38
39#include <dwcgf/Types.hpp>
41#include <dwcgf/pass/Pass.hpp>
42#include <dw/core/logger/Logger.hpp>
44#include <dw/core/container/VectorFixed.hpp>
45#include <dw/core/container/BaseString.hpp>
46#include <dwcgf/port/Port.hpp>
47
48#include <string>
49#include <memory>
50#include <atomic>
51
52namespace dw
53{
54namespace framework
55{
56using dw::core::FixedString;
57using dw::core::VectorFixed;
58class ParameterProvider;
59
60#define _DW_CGF_STRINGIFY(x) #x
61// std::char_traits<char8_t>::length() is not constexpr before C++17, use "sizeof() - 1" as WAR
62#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)
63
64class Node
65{
66public:
67 static constexpr size_t MAX_NAME_LEN = 128;
68 using Name_t = FixedString<MAX_NAME_LEN>;
69
70 static constexpr uint32_t MAX_PORT_COUNT = 256;
71
72 static constexpr uint32_t MAX_PASS_COUNT = 256;
73
74 virtual ~Node() = default;
75
80 virtual dwStatus reset() = 0;
81
88 virtual dwStatus setInputChannel(ChannelObject* channel, uint8_t portID) = 0;
89
97 virtual dwStatus setInputChannel(ChannelObject* channel, uint8_t portID, dwSerializationType dataType) = 0;
98
105 virtual dwStatus setOutputChannel(ChannelObject* channel, uint8_t portID) = 0;
106
116 virtual dwStatus validate() = 0;
117
122 virtual dwStatus run() = 0;
123
128 virtual size_t getPassCount() const noexcept = 0;
129
135 virtual dwStatus runPass(size_t passIndex) = 0;
136
145 virtual dwStatus getPass(Pass** pass, uint8_t index) = 0;
146
152 virtual dwStatus getPasses(VectorFixed<Pass*>& passList) = 0;
153
161 virtual dwStatus getPasses(VectorFixed<Pass*>& passList,
162 dwProcessorType processorType,
163 dwProcessType processType) = 0;
164
170 virtual dwStatus setName(const char* name) = 0;
171
177 virtual dwStatus getName(const char** name) = 0;
178
184 virtual dwStatus getErrorSignal(dwGraphErrorSignal*& errorSignal) = 0;
185
192 virtual dwStatus getHealthSignal(dwGraphHealthSignal*& healthSignals, bool updateFromModule = false) = 0;
193
202 virtual dwStatus reportCurrentErrorSignal(dwGraphErrorSignal& signal) = 0;
203
212 virtual dwStatus reportCurrentHealthSignal(dwGraphHealthSignal& signal) = 0;
213
219 virtual dwStatus setIterationCount(uint32_t iterationCount) = 0;
220
228 virtual dwStatus setState(const char* state) = 0;
229
235 virtual dwStatus setNodePeriod(uint32_t period) = 0;
236
240 virtual void resetPorts() = 0;
241
248 virtual dwStatus getInputChannel(const uint8_t portID, ChannelObject*& channel) const = 0;
249
256 virtual dwStatus getOutputChannel(const uint8_t portID, ChannelObject*& channel) const = 0;
257
265 virtual dwStatus getInputPort(const uint8_t portID, dw::framework::PortBase*& port) const = 0;
266
274 virtual dwStatus getOutputPort(const uint8_t portID, dw::framework::PortBase*& port) const = 0;
275};
276
278{
279public:
284 virtual dwStatus start() = 0;
285
290 virtual dwStatus stop() = 0;
291
296 virtual dwStatus setAffinityMask(uint) = 0;
297
302 virtual dwStatus setThreadPriority(int) = 0;
303
308 virtual dwStatus setStartTime(dwTime_t) = 0;
309
314 virtual dwStatus setEndTime(dwTime_t) = 0;
315
320 virtual dwStatus isVirtual(bool* isVirtualBool) = 0;
321
322 enum class DataEventType
323 {
324 PRODUCE, // sensor node produces data for a node-run
325 DROP, // sensor node drops data in the next node-run
326 NONE, // sensor node does not produce data for a node-run
327 };
328
333 {
345 dwStatus status;
350 dwTime_t timestamp;
351 };
352
353 using DataEventReadCallback = dw::core::Function<bool(DataEvent&)>;
361
362 using DataEventWriteCallback = dw::core::Function<void(DataEvent)>;
370
378 virtual dwStatus setLockstepDeterministicMode(bool enable) = 0;
379
385 virtual dwStatus getNextTimestamp(dwTime_t& nextTimestamp) = 0;
386};
387
389{
390public:
393
396
399
402
404 : m_node(node)
405 , m_sensorNode(dynamic_cast<ISensorNode*>(node))
406 {
407 if (m_sensorNode != nullptr)
408 {
409 throw ExceptionWithStatus(DW_INVALID_ARGUMENT, "Passed node pointer does not implement ISensorNode.");
410 }
411 }
412
414 {
415 return m_node;
416 }
417
418 Node const* getNode() const
419 {
420 return m_node;
421 }
422
424 {
425 return m_sensorNode;
426 }
427
429 {
430 return m_sensorNode;
431 }
432
433private:
434 Node* m_node{};
435 ISensorNode* m_sensorNode{};
436};
437
446{
447public:
448 virtual ~IContainsPreShutdownAction() = default;
449
454 virtual dwStatus preShutdown() = 0;
455};
456
457// TODO(ajayawardane) WAR: When there is a single SSM pass in the graph, reset could potentially
458// be called while node passes are running. Until STM schedule re-entry is supported, we reset the
459// supported nodes in the setup pass.
460// deprecated and Replaced by IResetable, which has an improved reset interface
462{
463public:
464 virtual ~IAsyncResetable() = default;
465
470 virtual dwStatus setAsyncReset() = 0;
475 virtual dwStatus executeAsyncReset() = 0;
476};
477
483{
484public:
485 virtual ~IChannelsConnectedListener() = default;
486
490 virtual void onChannelsConnected() = 0;
491};
492
498{
499public:
500 virtual ~IResetable() = default;
501
506 virtual dwStatus reset() = 0;
507};
508
511
512} // namespace framework
513} // namespace dw
514
516
517#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 void onChannelsConnected()=0
Callback received after channels are connected.
virtual dwStatus preShutdown()=0
actions to be taken before node shutdown
virtual dwStatus reset()=0
Executes reset of the node.
virtual ~IResetable()=default
virtual dwStatus setAffinityMask(uint)=0
Sets the affinity mask of the sensor.
virtual dwStatus setLockstepDeterministicMode(bool enable)=0
Set whether replay is running in lockstep deterministic mode.
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:353
virtual dwStatus stop()=0
Stop the sensor.
virtual dwStatus isVirtual(bool *isVirtualBool)=0
distinguishes between a live and virtual sensor
virtual dwStatus getNextTimestamp(dwTime_t &nextTimestamp)=0
Get the next timestamp of the sensor.
dw::core::Function< void(DataEvent)> DataEventWriteCallback
Definition: Node.hpp:362
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 setNodePeriod(uint32_t period)=0
Set the node's period.
virtual dwStatus setOutputChannel(ChannelObject *channel, uint8_t portID)=0
Sets an output channel for this node with an accompanying port.
virtual dwStatus getInputPort(const uint8_t portID, dw::framework::PortBase *&port) const =0
Gets the input port associated with the port id.
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.
virtual dwStatus getInputChannel(const uint8_t portID, ChannelObject *&channel) const =0
Gets the input channel associated with the input port.
virtual dwStatus run()=0
Runs all the passes in the node.
virtual ~Node()=default
FixedString< MAX_NAME_LEN > Name_t
Definition: Node.hpp:68
virtual dwStatus getErrorSignal(dwGraphErrorSignal *&errorSignal)=0
Get the pointer to the error signal for this node.
virtual dwStatus getPass(Pass **pass, uint8_t index)=0
Get a const pointer to the pass at a specific index.
static constexpr uint32_t MAX_PORT_COUNT
Definition: Node.hpp:70
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:72
virtual void resetPorts()=0
Resets all the ports in the node.
virtual dwStatus getPasses(VectorFixed< Pass * > &passList)=0
Get all the passes in the node.
static constexpr size_t MAX_NAME_LEN
Definition: Node.hpp:67
virtual dwStatus setName(const char *name)=0
Set the name of the node.
virtual dwStatus getOutputPort(const uint8_t portID, dw::framework::PortBase *&port) const =0
Gets the output port associated with the port id.
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 getOutputChannel(const uint8_t portID, ChannelObject *&channel) const =0
Gets the output channel associated with the output 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:49
SensorNode(Node *node)
Definition: Node.hpp:403
ISensorNode::DataEventReadCallback DataEventReadCallback
Definition: Node.hpp:398
Node const * getNode() const
Definition: Node.hpp:418
ISensorNode * getSensorNode()
Definition: Node.hpp:423
ISensorNode const * getSensorNode() const
Definition: Node.hpp:428
ISensorNode::DataEventWriteCallback DataEventWriteCallback
Definition: Node.hpp:401
constexpr size_t passIndex(dw::core::StringView identifier)
Get the the pass index for a pass identified by name.
dwSerializationType
Definition: Types.hpp:42
dwTrivialDataType dataType
Number of levels in the pyramid.
Definition: Buffer.hpp:40