Compute Graph Framework SDK Reference  5.16
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-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_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
40#include <dwcgf/pass/Pass.hpp>
41#include <dwshared/dwfoundation/dw/core/logger/Logger.hpp>
43#include <dwshared/dwfoundation/dw/core/container/VectorFixed.hpp>
44#include <dwshared/dwfoundation/dw/core/container/BaseString.hpp>
45#include <dwcgf/port/Port.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;
57// coverity[autosar_cpp14_a0_1_6_violation]
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 // coverity[autosar_cpp14_a0_1_1_violation] FP: nvbugs/2813925
68 // coverity[autosar_cpp14_a5_1_1_violation] FP: nvbugs/4020293
69 // coverity[autosar_cpp14_m0_1_4_violation] FP: nvbugs/2813925
70 static constexpr const size_t MAX_NAME_LEN{128U};
71
72 virtual ~Node() = default;
73
78 virtual dwStatus reset() = 0;
79
86 virtual dwStatus setInputChannel(ChannelObject* channel, size_t portID) = 0;
87
94 virtual dwStatus setOutputChannel(ChannelObject* channel, size_t portID) = 0;
95
105 virtual dwStatus validate() = 0;
106
111 virtual dwStatus run() = 0;
112
117 virtual size_t getPassCount() const noexcept = 0;
118
124 virtual dwStatus runPass(size_t passIndex) = 0;
125
134 virtual dwStatus getPass(Pass** pass, size_t index) = 0;
135
141 // coverity[autosar_cpp14_a2_10_5_violation] RFD Pending: TID-2053
142 virtual dwStatus getPasses(VectorFixed<Pass*>& passList) = 0;
143
149 virtual dwStatus setName(const char* name) = 0;
150
156 virtual dwStatus getName(const char** name) = 0;
157
165 virtual dwStatus collectErrorSignals(dwGraphErrorSignal*& errorSignal, bool updateFromModule = true) = 0;
166
172 virtual dwStatus getModuleErrorSignal(dwErrorSignal& errorSignal) = 0; // Will Be Deprecated upon completion of PRC2 refactor
173
179 virtual dwStatus getNodeErrorSignal(dwGraphErrorSignal& errorSignal) = 0; // Will Be Deprecated upon completion of PRC2 refactor
180
188 virtual dwStatus collectHealthSignals(dwGraphHealthSignal*& healthSignal, bool updateFromModule = false) = 0;
189
195 virtual dwStatus getModuleHealthSignal(dwHealthSignal& healthSignal) = 0; // Will Be Deprecated upon completion of PRC2 refactor
196
202 virtual dwStatus getNodeHealthSignal(dwGraphHealthSignal& healthSignal) = 0; // Will Be Deprecated upon completion of PRC2 refactor
203
208 virtual dwStatus clearErrorSignal() = 0;
209
214 virtual dwStatus clearHealthSignal() = 0;
215
224 virtual dwStatus updateCurrentErrorSignal(dwGraphErrorSignal& signal) = 0; // Will Be Deprecated upon completion of PRC2 refactor
225
234 virtual dwStatus updateCurrentHealthSignal(dwGraphHealthSignal& signal) = 0; // Will Be Deprecated upon completion of PRC2 refactor
235
242 virtual dwStatus addToErrorSignal(uint32_t error, dwTime_t timestamp = 0L) = 0;
243
250 virtual dwStatus addToHealthSignal(uint32_t error, dwTime_t timestamp = 0L) = 0;
251
257 virtual dwStatus setIterationCount(uint32_t iterationCount) = 0;
258
266 virtual dwStatus setState(const char* state) = 0;
267
273 virtual dwStatus setNodePeriod(uint32_t period) = 0;
274
278 virtual void resetPorts() = 0;
279
286 virtual dwStatus getInputChannel(const size_t portID, ChannelObject*& channel) const = 0;
287
294 virtual dwStatus getOutputChannel(const size_t portID, ChannelObject*& channel) const = 0;
295
302 virtual dwStatus getInputPort(const size_t portID, dw::framework::PortBase*& port) const = 0;
303
310 virtual dwStatus getOutputPort(const size_t portID, dw::framework::PortBase*& port) const = 0;
311};
312
314{
315public:
320 virtual dwStatus start() = 0;
321
326 virtual dwStatus stop() = 0;
327
332 virtual dwStatus setAffinityMask(uint) = 0;
333
338 virtual dwStatus setThreadPriority(int) = 0;
339
344 virtual dwStatus setStartTime(dwTime_t) = 0;
345
350 virtual dwStatus setEndTime(dwTime_t) = 0;
351
356 virtual dwStatus isVirtual(bool* isVirtualBool) = 0;
357
358 enum class DataEventType
359 {
360 PRODUCE, // sensor node produces data for a node-run
361 DROP, // sensor node drops data in the next node-run
362 NONE, // sensor node does not produce data for a node-run
363 };
364
369 {
381 dwStatus status;
386 dwTime_t timestamp;
387 };
388
389 using DataEventReadCallback = dw::core::Function<bool(DataEvent&)>;
397
398 using DataEventWriteCallback = dw::core::Function<void(DataEvent)>;
406
414 virtual dwStatus setLockstepDeterministicMode(bool enable) = 0;
415
421 virtual dwStatus getNextTimestamp(dwTime_t& nextTimestamp) = 0;
422
428 virtual dwStatus isEnabled(bool& isEnabled) = 0;
429};
430
432{
433public:
435 : m_node(node)
436 , m_sensorNode(dynamic_cast<ISensorNode*>(node))
437 {
438 if (nullptr != m_sensorNode)
439 {
440 throw ExceptionWithStatus(DW_INVALID_ARGUMENT, "Passed node pointer does not implement ISensorNode.");
441 }
442 }
443
445 {
446 return m_node;
447 }
448
449 Node const* getNode() const
450 {
451 return m_node;
452 }
453
455 {
456 return m_sensorNode;
457 }
458
460 {
461 return m_sensorNode;
462 }
463
464private:
465 Node* m_node{};
466 ISensorNode* m_sensorNode{};
467};
468
476// coverity[autosar_cpp14_a0_1_6_violation]
478{
479public:
480 virtual ~IContainsPreShutdownAction() = default;
481
486 virtual dwStatus preShutdown() = 0;
487};
488
493// coverity[autosar_cpp14_a0_1_6_violation]
495{
496public:
497 virtual ~IChannelsConnectedListener() = default;
498
502 virtual void onChannelsConnected() = 0;
503};
504
507
508} // namespace framework
509} // namespace dw
510
512
513#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 void onChannelsConnected()=0
Callback received after channels are connected.
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 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:389
virtual dwStatus isEnabled(bool &isEnabled)=0
Whether or not the node is enabled.
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:398
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 getModuleHealthSignal(dwHealthSignal &healthSignal)=0
Return a copy of health signals from module that is a member of node.
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 collectErrorSignals(dwGraphErrorSignal *&errorSignal, bool updateFromModule=true)=0
Collect error signals from node and module, combine and return the pointer to the error signal for th...
virtual dwStatus addToErrorSignal(uint32_t error, dwTime_t timestamp=0L)=0
A function the allows user to add an error to the error signal list.
virtual dwStatus collectHealthSignals(dwGraphHealthSignal *&healthSignal, bool updateFromModule=false)=0
Collect health signals from node and module, combine and return the pointer to the health signal for ...
virtual dwStatus runPass(size_t passIndex)=0
Run one pass by index as defined by the pass descriptors.
virtual dwStatus getOutputChannel(const size_t portID, ChannelObject *&channel) const =0
Gets the output channel associated with the output port.
virtual dwStatus run()=0
Runs all the passes in the node.
virtual ~Node()=default
virtual size_t getPassCount() const noexcept=0
Get number of passes in the node.
virtual dwStatus setIterationCount(uint32_t iterationCount)=0
Sets the node's iteration count.
virtual dwStatus getNodeErrorSignal(dwGraphErrorSignal &errorSignal)=0
Get a copy of the error signals for the node.
virtual dwStatus getPass(Pass **pass, size_t index)=0
Get a const pointer to the pass at a specific index.
virtual dwStatus getOutputPort(const size_t portID, dw::framework::PortBase *&port) const =0
Gets the output port associated with the port id.
virtual dwStatus getModuleErrorSignal(dwErrorSignal &errorSignal)=0
Get a copy of the error signals from the module that is a member of this node.
virtual dwStatus updateCurrentHealthSignal(dwGraphHealthSignal &signal)=0
A function that allows user override to update health signal It is automatically called by dwFramewor...
virtual void resetPorts()=0
Resets all the ports in the node.
virtual dwStatus addToHealthSignal(uint32_t error, dwTime_t timestamp=0L)=0
A function the allows user to add an error to the health signal list.
virtual dwStatus getPasses(VectorFixed< Pass * > &passList)=0
Get all the passes in the node.
virtual dwStatus setOutputChannel(ChannelObject *channel, size_t portID)=0
Sets an output channel for this node with an accompanying port.
virtual dwStatus setName(const char *name)=0
Set the name of the node.
virtual dwStatus getNodeHealthSignal(dwGraphHealthSignal &healthSignal)=0
Return a copy of graph health signals for the node.
virtual dwStatus getInputChannel(const size_t portID, ChannelObject *&channel) const =0
Gets the input channel associated with the input port.
virtual dwStatus getInputPort(const size_t portID, dw::framework::PortBase *&port) const =0
Gets the input port associated with the port id.
virtual dwStatus getName(const char **name)=0
Get the name of the node.
static constexpr const size_t MAX_NAME_LEN
Definition: Node.hpp:70
virtual dwStatus updateCurrentErrorSignal(dwGraphErrorSignal &signal)=0
A function that allows user override to update error signal It is automatically called by dwFramework...
virtual dwStatus clearHealthSignal()=0
Clear the health signal for this node.
virtual dwStatus setInputChannel(ChannelObject *channel, size_t portID)=0
Sets an input channel for this node with an accompanying port.
virtual dwStatus clearErrorSignal()=0
Clear the error signal for this node.
virtual dwStatus reset()=0
Resets the state of the node.
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:434
Node const * getNode() const
Definition: Node.hpp:449
ISensorNode * getSensorNode()
Definition: Node.hpp:454
ISensorNode const * getSensorNode() const
Definition: Node.hpp:459
constexpr size_t passIndex(dw::core::StringView identifier)
Get the the pass index for a pass identified by name.
Definition: Buffer.hpp:40