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

SimpleNode.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) 2019-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_SIMPLENODE_HPP_
32 #define DW_FRAMEWORK_SIMPLENODE_HPP_
33 
34 #include <dw/core/base/Types.h>
35 #include <dwcgf/Exception.hpp>
36 #include <dwcgf/Types.hpp>
38 #include <dwcgf/pass/Pass.hpp>
39 #include <dwcgf/node/Node.hpp>
45 
46 #include <dw/core/container/VectorFixed.hpp>
47 #include <dw/core/container/BaseString.hpp>
48 
49 #include <functional>
50 #include <map>
51 
52 namespace dw
53 {
54 namespace framework
55 {
56 
57 class SimpleProcessNode;
58 class SimpleSensorNode;
59 
61 {
65 };
66 
67 template <typename NodeT>
69 {
70  NodeAllocationParams params;
71  params.maxInputPortCount = portSize<NodeT, PortDirection::INPUT>();
72  params.maxOutputPortCount = portSize<NodeT, PortDirection::OUTPUT>();
73  params.maxPassCount = passSize<NodeT>();
74  return params;
75 }
76 
77 class SimpleNode : public Node
78 {
79 public:
80  static constexpr const char* PASS_SETUP_NAME = "SETUP";
81  static constexpr const char* PASS_TEARDOWN_NAME = "TEARDOWN";
82 
83  SimpleNode();
86  virtual ~SimpleNode();
87 
88  dwStatus reset() override
89  {
90  throw Exception(DW_NOT_IMPLEMENTED, "Not implemented");
91  }
92 
94 
97  dwStatus setInputChannel(ChannelObject* channel, uint8_t portID) override;
98 
99  dwStatus setInputChannel(ChannelObject*, uint8_t, dwSerializationType) override
100  {
101  throw Exception(DW_NOT_IMPLEMENTED, "Not implemented");
102  }
103 
105 
108  dwStatus setOutputChannel(ChannelObject* channel, uint8_t portID) override;
109 
110  dwStatus validate() override
111  {
112  throw Exception(DW_NOT_IMPLEMENTED, "Not implemented");
113  }
114 
116 
119  dwStatus validate(const char* direction, const PortCollectionDescriptor& collection, const dw::core::HeapHashMap<size_t, std::shared_ptr<PortBase>>& ports, size_t indexOffset = 0);
120 
121  dwStatus run() override;
122  size_t getPassCount() const noexcept override;
123  dwStatus runPassByID(uint8_t passID) override;
124  dwStatus runPass(size_t passIndex) override;
125  dwStatus getPasses(VectorFixed<Pass*>& passList) override;
126  dwStatus getPasses(VectorFixed<Pass*>& passList, dwProcessorType processorType, dwProcessType processType) override;
127 
128  dwStatus setName(const char* name) final;
129  dwStatus getName(const char** name) override;
130 
131  dwStatus getHealthSignals(dwGraphHealthSignalArray*& healthSignals) override;
132 
133  template <typename Func, typename PortList>
134  void iteratePorts(PortList& portList, Func func)
135  {
136  for (auto elem : portList)
137  {
138  func(elem);
139  }
140  }
141 
142  template <typename Func>
143  void iterateManagedInputPorts(Func func)
144  {
145  iteratePorts(m_inputPorts, [&func, this](decltype(m_inputPorts)::TElement& elem) {
146  if (auto managedPort = dynamic_cast<ManagedPortInputBase*>(elem.second.get()))
147  {
148  func(*managedPort);
149  }
150  else
151  {
152  const char* nodeName = nullptr;
153  this->getName(&nodeName);
154  throw Exception(DW_BAD_CAST, "SimpleNode: ports are wrong class, node ", nodeName);
155  }
156  });
157  }
158 
159  template <typename Func>
161  {
162  iteratePorts(m_outputPorts, [&func, this](decltype(m_outputPorts)::TElement& elem) {
163  if (auto managedPort = dynamic_cast<ManagedPortOutputBase*>(elem.second.get()))
164  {
165  func(*managedPort);
166  }
167  else
168  {
169  const char* nodeName = nullptr;
170  this->getName(&nodeName);
171  throw Exception(DW_BAD_CAST, "SimpleNode: ports are wrong class node ", nodeName);
172  }
173  });
174  }
175 
176  template <typename ModuleHandle_t>
177  dwStatus setModuleHandle(ModuleHandle_t handle, dwContextHandle_t context)
178  {
179  dwModuleHandle_t moduleHandle;
180 
181  if (DW_NULL_HANDLE == handle)
182  {
183  return DW_INVALID_ARGUMENT;
184  }
185 
186  dwStatus ret = getModuleHandle(&moduleHandle, handle, context);
187  if (DW_SUCCESS != ret)
188  {
189  return ret;
190  }
191 
192  return setObjectHandle(moduleHandle);
193  }
194 
195  virtual dwStatus setObjectHandle(dwModuleHandle_t handle);
196 
197 protected:
198  dwStatus getModuleHandle(dwModuleHandle_t* moduleHandle, void* handle, dwContextHandle_t context);
199 
200  virtual std::unique_ptr<Pass> createSetupPass()
201  {
202  throw Exception(DW_NOT_IMPLEMENTED, "Not implemented");
203  }
204 
205  virtual std::unique_ptr<Pass> createTeardownPass()
206  {
207  throw Exception(DW_NOT_IMPLEMENTED, "Not implemented");
208  }
209 
232  template <typename PassFunctionT, typename... Args>
233  std::unique_ptr<PassImpl<PassFunctionT>> make_pass(PassFunctionT func, Args&&... args)
234  {
235  return make_pass_with_node(this, func, std::forward<Args>(args)...);
236  }
237 
239 
242  template <
243  typename NodeT, size_t PassIndex, typename PassFunctionT>
244  void registerPass(PassFunctionT func, NvMediaDla* dlaEngine = nullptr)
245  {
246  registerPassWithNode<NodeT, PassIndex>(this, func, dlaEngine);
247  }
248 
249 public:
251 
254  template <typename PassFunctionT, typename... Args>
255  std::unique_ptr<PassImpl<PassFunctionT>> make_pass_with_node(Node* node, PassFunctionT func, Args&&... args)
256  {
257  return std::make_unique<PassImpl<PassFunctionT>>(node, func, std::forward<Args>(args)...);
258  }
259 
263 
266  template <
267  typename NodeT, size_t PassIndex, typename PassFunctionT>
268  void registerPassWithNode(Node* node, PassFunctionT func, NvMediaDla* dlaEngine = nullptr)
269  {
270  if (!isValidPass<NodeT>(PassIndex))
271  {
272  throw Exception(DW_INVALID_ARGUMENT, "registerPassWithNode called with an invalid pass id: ", PassIndex);
273  }
274  if (m_passList.size() == 0 || m_passList.size() - 1 < PassIndex)
275  {
276  m_passList.resize(PassIndex + 1);
277  m_passOwnershipList.resize(PassIndex + 1);
278  }
279  if (m_passList[PassIndex] != nullptr)
280  {
281  throw Exception(DW_INVALID_ARGUMENT, "registerPassWithNode called with a pass id which has been added before: ", PassIndex);
282  }
283  dwProcessorType processorType = passProcessorType<NodeT, PassIndex>();
284  dwProcessType processType = determineProcessType(processorType);
285  if (dlaEngine == nullptr)
286  {
287  m_passList[PassIndex] = std::make_unique<PassImpl<PassFunctionT>>(node, func, processorType, processType, -1, -1, -1);
288  }
289  else if (processorType == DW_PROCESSOR_TYPE_DLA_0)
290  {
291  m_passList[PassIndex] = std::make_unique<PassImpl<PassFunctionT>>(node, func, processorType, processType, -1, -1, -1, dlaEngine);
292  }
293  else
294  {
295  throw Exception(DW_INVALID_ARGUMENT, "registerPassWithNode called with a pass which has dlaEngine but not a DLA pass: ", PassIndex);
296  }
297  m_passOwnershipList[PassIndex] = true;
298  }
299 
301  void addPass(std::function<std::unique_ptr<Pass>(void)> createSetup, std::function<std::unique_ptr<Pass>(void)> createTeardown, Pass* pass);
302 
303  /*
304  * @brief Clears the current Health Signals from the Health Signal Array
305  * @param None
306  * @return DW_SUCCESS
307  */
308  dwStatus clearHealthSignals();
309 
310  /*
311  * @brief Adds the provided Health Signal to the Health Signal Array. If the array is full, the new signal will not be added.
312  * @param signal The Health Signal to add
313  * @return DW_SUCCESS, or DW_BUFFER_FULL if the array is currently full.
314  */
315  dwStatus addHealthSignal(const dwGraphHealthSignal& signal);
316 
317 private:
318  inline dwProcessType determineProcessType(dwProcessorType processorType)
319  {
320  if (processorType == DW_PROCESSOR_TYPE_GPU ||
321  processorType == DW_PROCESSOR_TYPE_DLA_0)
322  {
323  return DW_PROCESS_TYPE_ASYNC;
324  }
325  return DW_PROCESS_TYPE_SYNC;
326  }
327 
328  VectorFixed<std::unique_ptr<Pass>> m_passList;
329  // tracking ownership is only necessary until addPass(..., Pass* pass) is removed
330  VectorFixed<bool> m_passOwnershipList;
331  FixedString<MAX_NAME_LEN> m_name{};
332  bool m_setupTeardownCreated = false;
333 
334  /* An array of health signals generated by this node. By default this will contain a single signal with fields set to UNKNOWN.
335  * User should overwrite this value with their own health signals. These signals will be collected whenever a pass returns
336  * a non-successful return code.
337  */
338  dwGraphHealthSignalArray m_healthSignals{};
339 
340  dwModuleHandle_t m_object{};
341  uint32_t m_iterationCount{};
342 
343 public:
345  template <typename TPort, typename... Args>
346  std::unique_ptr<TPort> make_port(Args&&... args)
347  {
348  auto port = std::make_unique<TPort>(std::forward<Args>(args)...);
349  port->setSyncRetriever(std::bind(&SimpleNode::getIterationCount, this));
350  return port;
351  }
352 
354 
357  template <typename NodeT, size_t PortIndex, typename... Args>
358  void initInputPort(Args&&... args)
359  {
360  using DataType = decltype(portType<NodeT, PortDirection::INPUT, PortIndex>());
361  auto port = std::make_shared<ManagedPortInput<DataType>>(std::forward<Args>(args)...);
362  if (m_inputPorts.find(PortIndex) != m_inputPorts.end())
363  {
364  throw Exception(DW_INVALID_ARGUMENT, "Input port with the following id registered multiple times: ", PortIndex);
365  }
366  m_inputPorts[PortIndex] = port;
367  }
368 
370 
373  template <typename NodeT, size_t PortIndex, typename... Args>
374  void initInputArrayPort(Args&&... args)
375  {
376  using DataType = decltype(portType<NodeT, PortDirection::INPUT, PortIndex>());
377  constexpr size_t descriptor_index = descriptorIndex<NodeT, PortDirection::INPUT, PortIndex>();
378  constexpr size_t arraySize = descriptorPortSize<NodeT, PortDirection::INPUT, descriptor_index>();
379  for (size_t i = 0; i < arraySize; ++i)
380  {
381  auto port = std::make_shared<ManagedPortInput<DataType>>(std::forward<Args>(args)...);
382  if (m_inputPorts.find(PortIndex + i) != m_inputPorts.end())
383  {
384  throw Exception(DW_INVALID_ARGUMENT, "Input port with the following id registered multiple times: ", PortIndex + i);
385  }
386  m_inputPorts[PortIndex + i] = port;
387  }
388  }
389 
391 
394  template <typename NodeT, size_t PortIndex, typename... Args>
395  void initOutputPort(Args&&... args)
396  {
397  using DataType = decltype(portType<NodeT, PortDirection::OUTPUT, PortIndex>());
398  auto port = std::make_shared<ManagedPortOutput<DataType>>(std::forward<Args>(args)...);
399  if (m_outputPorts.find(PortIndex) != m_outputPorts.end())
400  {
401  throw Exception(DW_INVALID_ARGUMENT, "Output port with the following id registered multiple times: ", PortIndex);
402  }
403  m_outputPorts[PortIndex] = port;
404  }
405 
407 
410  template <typename NodeT, size_t PortIndex, typename... Args>
411  void initOutputArrayPort(Args&&... args)
412  {
413  using DataType = decltype(portType<NodeT, PortDirection::OUTPUT, PortIndex>());
414  constexpr size_t descriptor_index = descriptorIndex<NodeT, PortDirection::OUTPUT, PortIndex>();
415  constexpr size_t arraySize = descriptorPortSize<NodeT, PortDirection::OUTPUT, descriptor_index>();
416  for (size_t i = 0; i < arraySize; ++i)
417  {
418  auto port = std::make_shared<ManagedPortOutput<DataType>>(std::forward<Args>(args)...);
419  if (m_outputPorts.find(PortIndex + i) != m_outputPorts.end())
420  {
421  throw Exception(DW_INVALID_ARGUMENT, "Output port with the following id registered multiple times: ", PortIndex + i);
422  }
423  m_outputPorts[PortIndex + i] = port;
424  }
425  }
426 
428  template <typename NodeT, size_t PortIndex>
430  {
431  constexpr bool isArray = descriptorPortArray<
432  NodeT, PortDirection::INPUT, descriptorIndex<NodeT, PortDirection::INPUT, PortIndex>()>();
433  static_assert(!isArray, "Input port is an array, must pass an array index");
434  if (m_inputPorts.find(PortIndex) == m_inputPorts.end())
435  {
436  throw Exception(DW_INVALID_ARGUMENT, "Input port with the following id not registered: ", PortIndex);
437  }
438  using DataType = decltype(portType<NodeT, PortDirection::INPUT, PortIndex>());
439  using PointerType = ManagedPortInput<DataType>;
440  using ReturnType = std::shared_ptr<PointerType>;
441  ReturnType port = std::dynamic_pointer_cast<PointerType>(m_inputPorts[PortIndex]);
442  if (!port)
443  {
444  throw Exception(DW_BAD_CAST, "Failed to cast the following input port to its declared type: ", PortIndex);
445  }
446  return *port;
447  }
448 
450  template <typename NodeT, size_t PortIndex>
452  {
453  constexpr bool isArray = descriptorPortArray<NodeT, PortDirection::INPUT, descriptorIndex<NodeT, PortDirection::INPUT, PortIndex>()>();
454  static_assert(isArray, "Input port is not an array, must not pass an array index");
455  constexpr size_t arraySize = descriptorPortSize<NodeT, PortDirection::INPUT, descriptorIndex<NodeT, PortDirection::INPUT, PortIndex>()>();
456  if (arrayIndex >= arraySize)
457  {
458  throw Exception(DW_INVALID_ARGUMENT, "The array index is out of bound: ", arrayIndex);
459  }
460  if (m_inputPorts.find(PortIndex + arrayIndex) == m_inputPorts.end())
461  {
462  throw Exception(DW_INVALID_ARGUMENT, "Input port with the following id not registered: ", PortIndex + arrayIndex);
463  }
464  using DataType = decltype(portType<NodeT, PortDirection::INPUT, PortIndex>());
465  using PointerType = ManagedPortInput<DataType>;
466  using ReturnType = std::shared_ptr<PointerType>;
467  ReturnType port = std::dynamic_pointer_cast<PointerType>(m_inputPorts[PortIndex + arrayIndex]);
468  if (!port)
469  {
470  throw Exception(DW_BAD_CAST, "Failed to cast the following input port to its declared type: ", PortIndex + arrayIndex);
471  }
472  return *port;
473  }
474 
476  template <typename NodeT, size_t PortIndex>
478  {
479  constexpr bool isArray = descriptorPortArray<
480  NodeT, PortDirection::OUTPUT, descriptorIndex<NodeT, PortDirection::OUTPUT, PortIndex>()>();
481  static_assert(!isArray, "Output port is an array, must pass an array index");
482  if (m_outputPorts.find(PortIndex) == m_outputPorts.end())
483  {
484  throw Exception(DW_INVALID_ARGUMENT, "Output port with the following id not registered: ", PortIndex);
485  }
486  using DataType = decltype(portType<NodeT, PortDirection::OUTPUT, PortIndex>());
487  using PointerType = ManagedPortOutput<DataType>;
488  using ReturnType = std::shared_ptr<PointerType>;
489  ReturnType port = std::dynamic_pointer_cast<PointerType>(m_outputPorts[PortIndex]);
490  if (!port)
491  {
492  throw Exception(DW_BAD_CAST, "Failed to cast the following output port to its declared type: ", PortIndex);
493  }
494  return *port;
495  }
496 
498  template <typename NodeT, size_t PortIndex>
500  {
501  constexpr bool isArray = descriptorPortArray<NodeT, PortDirection::OUTPUT, descriptorIndex<NodeT, PortDirection::OUTPUT, PortIndex>()>();
502  static_assert(isArray, "Output port is not an array, must not pass an array index");
503  constexpr size_t arraySize = descriptorPortSize<NodeT, PortDirection::OUTPUT, descriptorIndex<NodeT, PortDirection::OUTPUT, PortIndex>()>();
504  if (arrayIndex >= arraySize)
505  {
506  throw Exception(DW_INVALID_ARGUMENT, "The array index is out of bound: ", arrayIndex);
507  }
508  if (m_outputPorts.find(PortIndex + arrayIndex) == m_outputPorts.end())
509  {
510  throw Exception(DW_INVALID_ARGUMENT, "Output port with the following id not registered: ", PortIndex + arrayIndex);
511  }
512  using DataType = decltype(portType<NodeT, PortDirection::OUTPUT, PortIndex>());
513  using PointerType = ManagedPortOutput<DataType>;
514  using ReturnType = std::shared_ptr<PointerType>;
515  ReturnType port = std::dynamic_pointer_cast<PointerType>(m_outputPorts[PortIndex + arrayIndex]);
516  if (!port)
517  {
518  throw Exception(DW_BAD_CAST, "Failed to cast the following output port to its declared type: ", PortIndex + arrayIndex);
519  }
520  return *port;
521  }
522 
524 
528  dwStatus setup();
529 
531 
535  dwStatus teardown();
536 
538 
542  void resetPorts();
543 
548  dwStatus setIterationCount(uint32_t iterationCount) override;
549 
550  const dw::core::HeapHashMap<size_t, std::shared_ptr<PortBase>>& getRegisteredInputPorts() const
551  {
552  return m_inputPorts;
553  }
554 
555  const dw::core::HeapHashMap<size_t, std::shared_ptr<PortBase>>& getRegisteredOutputPorts() const
556  {
557  return m_outputPorts;
558  }
559 
560  uint32_t getIterationCount() const;
561 
562 protected:
563  dw::core::HeapHashMap<size_t, std::shared_ptr<PortBase>> m_inputPorts;
564  dw::core::HeapHashMap<size_t, std::shared_ptr<PortBase>> m_outputPorts;
565 };
566 
568 {
569 public:
570  static constexpr char LOG_TAG[] = "SimpleSensorNode";
571 
574  ~SimpleSensorNode() override = default;
575 
576  dwStatus run() override;
577  size_t getPassCount() const noexcept override;
578  dwStatus runPassByID(uint8_t passID) override;
579  dwStatus runPass(size_t passIndex) override;
580  dwStatus getPasses(VectorFixed<Pass*>& passList) override;
581  dwStatus getPasses(VectorFixed<Pass*>& passList, dwProcessorType processorType, dwProcessType processType) override;
582 
583  dwStatus setName(const char* name) override;
584  dwStatus getName(const char** name) override;
585 
586  dwStatus getHealthSignals(dwGraphHealthSignalArray*& healthSignals) override;
587 
588  dwStatus start() override
589  {
590  throw Exception(DW_NOT_IMPLEMENTED, "Not implemented");
591  }
592 
593  dwStatus stop() override
594  {
595  throw Exception(DW_NOT_IMPLEMENTED, "Not implemented");
596  }
597 
598  dwStatus reset() override
599  {
600  throw Exception(DW_NOT_IMPLEMENTED, "Not implemented");
601  }
602 
603  dwStatus isVirtual(bool*) override
604  {
605  throw Exception(DW_NOT_IMPLEMENTED, "Not implemented");
606  }
607 
609  {
610  throw Exception(DW_NOT_IMPLEMENTED, "Not implemented");
611  }
612 
614  {
615  throw Exception(DW_NOT_IMPLEMENTED, "Not implemented");
616  }
617 
618  dwStatus setInputChannel(ChannelObject* channel, uint8_t portID) override;
619 
620  dwStatus setInputChannel(ChannelObject* channel, uint8_t portID, dwSerializationType serialType) override;
621 
622  dwStatus setOutputChannel(ChannelObject* channel, uint8_t portID) override;
623 
624  dwStatus validate() override
625  {
626  throw Exception(DW_NOT_IMPLEMENTED, "Not implemented");
627  }
628 
629  dwStatus validate(const char* direction, const PortCollectionDescriptor& collection, const dw::core::HeapHashMap<size_t, std::shared_ptr<PortBase>>& ports, size_t indexOffset = 0)
630  {
631  return m_simpleNode->validate(direction, collection, ports, indexOffset);
632  }
633 
634 protected:
635  virtual std::unique_ptr<Pass> createSetupPass()
636  {
637  throw Exception(DW_NOT_IMPLEMENTED, "Not implemented");
638  }
639 
640  virtual std::unique_ptr<Pass> createTeardownPass()
641  {
642  throw Exception(DW_NOT_IMPLEMENTED, "Not implemented");
643  }
644 
645  dwStatus setup()
646  {
647  return m_simpleNode->setup();
648  }
649 
650  dwStatus teardown()
651  {
652  return m_simpleNode->teardown();
653  }
654 
655  void resetPorts()
656  {
657  m_simpleNode->resetPorts();
658  }
659 
660  template <typename ModuleHandle_t>
661  dwStatus setModuleHandle(ModuleHandle_t handle, dwContextHandle_t context)
662  {
663  return m_simpleNode->template setModuleHandle<>(handle, context);
664  }
665 
666  dwStatus setObjectHandle(dwModuleHandle_t handle);
667 
668  template <typename PassFunctionT, typename... Args>
669  std::unique_ptr<PassImpl<PassFunctionT>> make_pass(PassFunctionT func, Args&&... args)
670  {
671  return m_simpleNode->make_pass_with_node(this, func, std::forward<Args>(args)...);
672  }
673 
674  template <
675  typename NodeT, size_t PassIndex, typename PassFunctionT>
676  void registerPass(PassFunctionT func, NvMediaDla* dlaEngine = nullptr)
677  {
678  m_simpleNode->registerPassWithNode<NodeT, PassIndex>(this, func, dlaEngine);
679  }
680 
681  void addPass(Pass* pass);
682 
683  dwStatus clearHealthSignals();
684 
685  dwStatus addHealthSignal(const dwGraphHealthSignal& signal);
686 
687  std::atomic<bool> m_asyncResetFlag;
688 
689 private:
690  std::unique_ptr<SimpleNode> m_simpleNode;
691 
692 public:
693  template <typename TPort, typename... Args>
694  auto make_port(Args&&... args)
695  {
696  return m_simpleNode->make_port<TPort>(std::forward<Args>(args)...);
697  }
698 
699  template <typename NodeT, size_t PortIndex, typename... Args>
700  void initInputPort(Args&&... args)
701  {
702  m_simpleNode->initInputPort<NodeT, PortIndex>(std::forward<Args>(args)...);
703  }
704 
705  template <typename NodeT, size_t PortIndex, typename... Args>
706  void initInputArrayPort(Args&&... args)
707  {
708  m_simpleNode->initInputArrayPort<NodeT, PortIndex>(std::forward<Args>(args)...);
709  }
710 
711  template <typename NodeT, size_t PortIndex, typename... Args>
712  void initOutputPort(Args&&... args)
713  {
714  m_simpleNode->initOutputPort<NodeT, PortIndex>(std::forward<Args>(args)...);
715  }
716 
717  template <typename NodeT, size_t PortIndex, typename... Args>
718  void initOutputArrayPort(Args&&... args)
719  {
720  m_simpleNode->initOutputArrayPort<NodeT, PortIndex>(std::forward<Args>(args)...);
721  }
722 
723  template <typename NodeT, size_t PortIndex>
724  auto& getInputPort()
725  {
726  return m_simpleNode->getInputPort<NodeT, PortIndex>();
727  }
728 
729  template <typename NodeT, size_t PortIndex>
730  auto& getInputPort(size_t arrayIndex)
731  {
732  return m_simpleNode->getInputPort<NodeT, PortIndex>(arrayIndex);
733  }
734 
735  template <typename NodeT, size_t PortIndex>
737  {
738  return m_simpleNode->getOutputPort<NodeT, PortIndex>();
739  }
740 
741  template <typename NodeT, size_t PortIndex>
742  auto& getOutputPort(size_t arrayIndex)
743  {
744  return m_simpleNode->getOutputPort<NodeT, PortIndex>(arrayIndex);
745  }
746 
747  const dw::core::HeapHashMap<size_t, std::shared_ptr<PortBase>>& getRegisteredInputPorts() const
748  {
749  return m_simpleNode->getRegisteredInputPorts();
750  }
751 
752  const dw::core::HeapHashMap<size_t, std::shared_ptr<PortBase>>& getRegisteredOutputPorts() const
753  {
754  return m_simpleNode->getRegisteredOutputPorts();
755  }
756 
757  dwStatus setIterationCount(uint32_t iterationCount) override
758  {
759  return m_simpleNode->setIterationCount(iterationCount);
760  }
761 
762  uint32_t getIterationCount() const
763  {
764  return m_simpleNode->getIterationCount();
765  }
766 };
767 
769 {
770 public:
771  static constexpr char LOG_TAG[] = "SimpleProcessNode";
772 
775  ~SimpleProcessNode() override = default;
776 
777  dwStatus run() override;
778  size_t getPassCount() const noexcept override;
779  dwStatus runPassByID(uint8_t passID) override;
780  dwStatus runPass(size_t passIndex) override;
781  dwStatus getPasses(VectorFixed<Pass*>& passList) override;
782  dwStatus getPasses(VectorFixed<Pass*>& passList, dwProcessorType processorType, dwProcessType processType) override;
783 
784  dwStatus setName(const char* name) override;
785  dwStatus getName(const char** name) override;
786 
787  dwStatus getHealthSignals(dwGraphHealthSignalArray*& healthSignals) override;
788 
789  dwStatus reset() override
790  {
791  throw Exception(DW_NOT_IMPLEMENTED, "Not implemented");
792  }
793 
794  dwStatus setInputChannel(ChannelObject* channel, uint8_t portID) override;
795 
796  dwStatus setInputChannel(ChannelObject* channel, uint8_t portID, dwSerializationType serialType) override;
797 
798  dwStatus setOutputChannel(ChannelObject* channel, uint8_t portID) override;
799 
800  dwStatus validate() override
801  {
802  throw Exception(DW_NOT_IMPLEMENTED, "Not implemented");
803  }
804 
805  dwStatus validate(const char* direction, const PortCollectionDescriptor& collection, const dw::core::HeapHashMap<size_t, std::shared_ptr<PortBase>>& ports, size_t indexOffset = 0)
806  {
807  return m_simpleNode->validate(direction, collection, ports, indexOffset);
808  }
809 
810 protected:
811  virtual std::unique_ptr<Pass> createSetupPass()
812  {
813  throw Exception(DW_NOT_IMPLEMENTED, "Not implemented");
814  }
815 
816  virtual std::unique_ptr<Pass> createTeardownPass()
817  {
818  throw Exception(DW_NOT_IMPLEMENTED, "Not implemented");
819  }
820 
821  dwStatus setup()
822  {
823  return m_simpleNode->setup();
824  }
825 
826  dwStatus teardown()
827  {
828  return m_simpleNode->teardown();
829  }
830 
831  void resetPorts()
832  {
833  m_simpleNode->resetPorts();
834  }
835 
836  template <typename ModuleHandle_t>
837  dwStatus setModuleHandle(ModuleHandle_t handle, dwContextHandle_t context)
838  {
839  return m_simpleNode->template setModuleHandle<>(handle, context);
840  }
841 
842  dwStatus setObjectHandle(dwModuleHandle_t handle);
843 
844  template <typename PassFunctionT, typename... Args>
845  std::unique_ptr<PassImpl<PassFunctionT>> make_pass(PassFunctionT func, Args&&... args)
846  {
847  return m_simpleNode->make_pass_with_node(this, func, std::forward<Args>(args)...);
848  }
849 
850  template <
851  typename NodeT, size_t PassIndex, typename PassFunctionT>
852  void registerPass(PassFunctionT func, NvMediaDla* dlaEngine = nullptr)
853  {
854  m_simpleNode->registerPassWithNode<NodeT, PassIndex>(this, func, dlaEngine);
855  }
856 
857  void addPass(Pass* pass);
858 
859  dwStatus clearHealthSignals();
860 
861  dwStatus addHealthSignal(const dwGraphHealthSignal& signal);
862 
863  std::atomic<bool> m_asyncResetFlag;
864 
865 private:
866  std::shared_ptr<SimpleNode> m_simpleNode;
867 
868 public:
869  template <typename TPort, typename... Args>
870  auto make_port(Args&&... args)
871  {
872  return m_simpleNode->make_port<TPort>(std::forward<Args>(args)...);
873  }
874 
875  template <typename NodeT, size_t PortIndex, typename... Args>
876  void initInputPort(Args&&... args)
877  {
878  m_simpleNode->initInputPort<NodeT, PortIndex>(std::forward<Args>(args)...);
879  }
880 
881  template <typename NodeT, size_t PortIndex, typename... Args>
882  void initInputArrayPort(Args&&... args)
883  {
884  m_simpleNode->initInputArrayPort<NodeT, PortIndex>(std::forward<Args>(args)...);
885  }
886 
887  template <typename NodeT, size_t PortIndex, typename... Args>
888  void initOutputPort(Args&&... args)
889  {
890  m_simpleNode->initOutputPort<NodeT, PortIndex>(std::forward<Args>(args)...);
891  }
892 
893  template <typename NodeT, size_t PortIndex, typename... Args>
894  void initOutputArrayPort(Args&&... args)
895  {
896  m_simpleNode->initOutputArrayPort<NodeT, PortIndex>(std::forward<Args>(args)...);
897  }
898 
899  template <typename NodeT, size_t PortIndex>
900  auto& getInputPort()
901  {
902  return m_simpleNode->getInputPort<NodeT, PortIndex>();
903  }
904 
905  template <typename NodeT, size_t PortIndex>
906  auto& getInputPort(size_t arrayIndex)
907  {
908  return m_simpleNode->getInputPort<NodeT, PortIndex>(arrayIndex);
909  }
910 
911  template <typename NodeT, size_t PortIndex>
913  {
914  return m_simpleNode->getOutputPort<NodeT, PortIndex>();
915  }
916 
917  template <typename NodeT, size_t PortIndex>
918  auto& getOutputPort(size_t arrayIndex)
919  {
920  return m_simpleNode->getOutputPort<NodeT, PortIndex>(arrayIndex);
921  }
922 
923  const dw::core::HeapHashMap<size_t, std::shared_ptr<PortBase>>& getRegisteredInputPorts() const
924  {
925  return m_simpleNode->getRegisteredInputPorts();
926  }
927 
928  const dw::core::HeapHashMap<size_t, std::shared_ptr<PortBase>>& getRegisteredOutputPorts() const
929  {
930  return m_simpleNode->getRegisteredOutputPorts();
931  }
932 
933  dwStatus setIterationCount(uint32_t iterationCount) override
934  {
935  return m_simpleNode->setIterationCount(iterationCount);
936  }
937 
938  uint32_t getIterationCount() const
939  {
940  return m_simpleNode->getIterationCount();
941  }
942 };
943 
944 } // namespace framework
945 } // namespace dw
946 
947 #endif // DW_FRAMEWORK_SIMPLENODE_HPP_
dw::core::Function< void(DataEvent)> DataEventWriteCallback
Definition: Node.hpp:285
dwStatus setModuleHandle(ModuleHandle_t handle, dwContextHandle_t context)
Definition: SimpleNode.hpp:661
uint32_t getIterationCount() const
auto make_port(Args &&... args)
Definition: SimpleNode.hpp:870
void registerPass(PassFunctionT func, NvMediaDla *dlaEngine=nullptr)
Definition: SimpleNode.hpp:676
void initOutputArrayPort(Args &&... args)
Definition: SimpleNode.hpp:718
void initInputArrayPort(Args &&... args)
Definition: SimpleNode.hpp:882
dwStatus validate(const char *direction, const PortCollectionDescriptor &collection, const dw::core::HeapHashMap< size_t, std::shared_ptr< PortBase >> &ports, size_t indexOffset=0)
Definition: SimpleNode.hpp:805
ManagedPortInput< decltype(portType< NodeT, PortDirection::INPUT, PortIndex >))> & getInputPort()
Get a previously initialized non-array ManagedPortInput.
Definition: SimpleNode.hpp:429
dwStatus setDataEventWriteCallback(DataEventWriteCallback) override
Definition: SimpleNode.hpp:613
Basic health signal that describes the health status of the graph.
virtual std::unique_ptr< Pass > createSetupPass()
Definition: SimpleNode.hpp:635
static constexpr uint32_t MAX_PORT_COUNT
Definition: Node.hpp:69
void initInputPort(Args &&... args)
Initialize a ManagedPortInput which will be owned by the base class and can be retrieved using getInp...
Definition: SimpleNode.hpp:358
const dw::core::HeapHashMap< size_t, std::shared_ptr< PortBase > > & getRegisteredOutputPorts() const
Definition: SimpleNode.hpp:555
void initOutputPort(Args &&... args)
Definition: SimpleNode.hpp:712
virtual std::unique_ptr< Pass > createTeardownPass()
Definition: SimpleNode.hpp:205
const dw::core::HeapHashMap< size_t, std::shared_ptr< PortBase > > & getRegisteredInputPorts() const
Definition: SimpleNode.hpp:747
dwStatus isVirtual(bool *) override
Definition: SimpleNode.hpp:603
void initInputArrayPort(Args &&... args)
Definition: SimpleNode.hpp:706
constexpr bool descriptorPortArray()
void iteratePorts(PortList &portList, Func func)
Definition: SimpleNode.hpp:134
void initInputPort(Args &&... args)
Definition: SimpleNode.hpp:700
void registerPassWithNode(Node *node, PassFunctionT func, NvMediaDla *dlaEngine=nullptr)
Register a pass function with the node base class.
Definition: SimpleNode.hpp:268
dwStatus validate() override
Definition: SimpleNode.hpp:624
ManagedPortInput< decltype(portType< NodeT, PortDirection::INPUT, PortIndex >))> & getInputPort(size_t arrayIndex)
Get one specific ManagedPortInput from a previously initialized input array port. ...
Definition: SimpleNode.hpp:451
dw::core::HeapHashMap< size_t, std::shared_ptr< PortBase > > m_inputPorts
Definition: SimpleNode.hpp:563
const dw::core::HeapHashMap< size_t, std::shared_ptr< PortBase > > & getRegisteredOutputPorts() const
Definition: SimpleNode.hpp:752
dwStatus validate() override
Definition: SimpleNode.hpp:110
Derived ManagedPortInput<T> provides type-specific interfaces for accessing buffers.
const dw::core::HeapHashMap< size_t, std::shared_ptr< PortBase > > & getRegisteredInputPorts() const
Definition: SimpleNode.hpp:550
void initInputPort(Args &&... args)
Definition: SimpleNode.hpp:876
dwStatus validate() override
Definition: SimpleNode.hpp:800
void iterateManagedOutputPorts(Func func)
Definition: SimpleNode.hpp:160
dwStatus setInputChannel(ChannelObject *, uint8_t, dwSerializationType) override
Definition: SimpleNode.hpp:99
dwStatus setDataEventReadCallback(DataEventReadCallback) override
Definition: SimpleNode.hpp:608
void initOutputArrayPort(Args &&... args)
Initialize an array of ManagedPortOutput which will be owned by the base class and can be retrieved u...
Definition: SimpleNode.hpp:411
dwStatus setIterationCount(uint32_t iterationCount) override
Definition: SimpleNode.hpp:757
std::unique_ptr< PassImpl< PassFunctionT > > make_pass(PassFunctionT func, Args &&... args)
Simple helper to create a pass with any function implementing operator()
Definition: SimpleNode.hpp:233
dwStatus validate(const char *direction, const PortCollectionDescriptor &collection, const dw::core::HeapHashMap< size_t, std::shared_ptr< PortBase >> &ports, size_t indexOffset=0)
Definition: SimpleNode.hpp:629
NodeAllocationParams createAllocationParams()
Definition: SimpleNode.hpp:68
virtual std::unique_ptr< Pass > createTeardownPass()
Definition: SimpleNode.hpp:640
virtual std::unique_ptr< Pass > createSetupPass()
Definition: SimpleNode.hpp:200
std::unique_ptr< PassImpl< PassFunctionT > > make_pass(PassFunctionT func, Args &&... args)
Definition: SimpleNode.hpp:669
Pass is a runnable describes the metadata of a pass.
Definition: Pass.hpp:49
static constexpr uint32_t MAX_PASS_COUNT
Definition: Node.hpp:71
void initInputArrayPort(Args &&... args)
Initialize an array of ManagedPortInput which will be owned by the base class and can be retrieved us...
Definition: SimpleNode.hpp:374
std::atomic< bool > m_asyncResetFlag
Definition: SimpleNode.hpp:863
auto & getInputPort(size_t arrayIndex)
Definition: SimpleNode.hpp:730
dwStatus setIterationCount(uint32_t iterationCount) override
Definition: SimpleNode.hpp:933
void initOutputArrayPort(Args &&... args)
Definition: SimpleNode.hpp:894
std::unique_ptr< TPort > make_port(Args &&... args)
Definition: SimpleNode.hpp:346
uint32_t getIterationCount() const
Definition: SimpleNode.hpp:762
std::unique_ptr< PassImpl< PassFunctionT > > make_pass_with_node(Node *node, PassFunctionT func, Args &&... args)
Register a pass function with the node base class.
Definition: SimpleNode.hpp:255
uint32_t getIterationCount() const
Definition: SimpleNode.hpp:938
virtual std::unique_ptr< Pass > createSetupPass()
Definition: SimpleNode.hpp:811
dwStatus setModuleHandle(ModuleHandle_t handle, dwContextHandle_t context)
Definition: SimpleNode.hpp:177
dw::core::Function< bool(DataEvent &)> DataEventReadCallback
Definition: Node.hpp:276
virtual std::unique_ptr< Pass > createTeardownPass()
Definition: SimpleNode.hpp:816
void initOutputPort(Args &&... args)
Definition: SimpleNode.hpp:888
auto & getOutputPort(size_t arrayIndex)
Definition: SimpleNode.hpp:742
constexpr size_t passIndex(dw::core::StringView identifier)
Get the the pass index for a pass identified by name.
void registerPass(PassFunctionT func, NvMediaDla *dlaEngine=nullptr)
Register a pass function with the node base class.
Definition: SimpleNode.hpp:244
Definition: Exception.hpp:46
void registerPass(PassFunctionT func, NvMediaDla *dlaEngine=nullptr)
Definition: SimpleNode.hpp:852
void iterateManagedInputPorts(Func func)
Definition: SimpleNode.hpp:143
const PassCollectionDescriptor & getPasses(const dw::core::StringView &className)
std::atomic< bool > m_asyncResetFlag
Definition: SimpleNode.hpp:687
Derived ManagedPortOutput<T> provides type-specific interfaces for accessing buffers.
dwStatus reset() override
Definition: SimpleNode.hpp:88
std::unique_ptr< PassImpl< PassFunctionT > > make_pass(PassFunctionT func, Args &&... args)
Definition: SimpleNode.hpp:845
auto & getInputPort(size_t arrayIndex)
Definition: SimpleNode.hpp:906
ManagedPortOutput< decltype(portType< NodeT, PortDirection::OUTPUT, PortIndex >))> & getOutputPort()
Get a previously initialized non-array ManagedPortOutput.
Definition: SimpleNode.hpp:477
void initOutputPort(Args &&... args)
Initialize a ManagedPortOutput which will be owned by the base class and can be retrieved using getOu...
Definition: SimpleNode.hpp:395
const dw::core::HeapHashMap< size_t, std::shared_ptr< PortBase > > & getRegisteredOutputPorts() const
Definition: SimpleNode.hpp:928
auto & getOutputPort(size_t arrayIndex)
Definition: SimpleNode.hpp:918
dwStatus setModuleHandle(ModuleHandle_t handle, dwContextHandle_t context)
Definition: SimpleNode.hpp:837
ManagedPortOutput< decltype(portType< NodeT, PortDirection::OUTPUT, PortIndex >))> & getOutputPort(size_t arrayIndex)
Get one specific ManagedPortOutput from a previously initialized output array port.
Definition: SimpleNode.hpp:499
const dw::core::HeapHashMap< size_t, std::shared_ptr< PortBase > > & getRegisteredInputPorts() const
Definition: SimpleNode.hpp:923
auto make_port(Args &&... args)
Definition: SimpleNode.hpp:694
dw::core::HeapHashMap< size_t, std::shared_ptr< PortBase > > m_outputPorts
Definition: SimpleNode.hpp:564