Hedgehog  3.1.0
A library to generate hybrid pipeline workflow systems
Loading...
Searching...
No Matches
task_node.h
Go to the documentation of this file.
1// NIST-developed software is provided by NIST as a public service. You may use, copy and distribute copies of the
2// software in any medium, provided that you keep intact this entire notice. You may improve, modify and create
3// derivative works of the software or any portion of the software, and you may copy and distribute such modifications
4// or works. Modified works should carry a notice stating that you changed the software and should note the date and
5// nature of any such change. Please explicitly acknowledge the National Institute of Standards and Technology as the
6// source of the software. NIST-developed software is expressly provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND,
7// EXPRESS, IMPLIED, IN FACT OR ARISING BY OPERATION OF LAW, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
8// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT AND DATA ACCURACY. NIST NEITHER REPRESENTS NOR
9// WARRANTS THAT THE OPERATION OF THE SOFTWARE WILL BE UNINTERRUPTED OR ERROR-FREE, OR THAT ANY DEFECTS WILL BE
10// CORRECTED. NIST DOES NOT WARRANT OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF THE SOFTWARE OR THE RESULTS
11// THEREOF, INCLUDING BUT NOT LIMITED TO THE CORRECTNESS, ACCURACY, RELIABILITY, OR USEFULNESS OF THE SOFTWARE. You
12// are solely responsible for determining the appropriateness of using and distributing the software and you assume
13// all risks associated with its use, including but not limited to the risks and costs of program errors, compliance
14// with applicable laws, damage to or loss of data, programs or equipment, and the unavailability or interruption of
15// operation. This software is not intended to be used in any situation where a failure could cause risk of injury or
16// damage to property. The software developed by NIST employees is not subject to copyright protection within the
17// United States.
18
19#ifndef HEDGEHOG_TASK_NODE_H_
20#define HEDGEHOG_TASK_NODE_H_
21
22#include "node.h"
23
24#include "../api/memory_manager/manager/abstract_memory_manager.h"
25#include "../core/abstractions/base/node/task_node_abstraction.h"
26
28namespace hh {
30namespace behavior {
31
35class TaskNode : public Node {
36 private:
37 std::shared_ptr<AbstractMemoryManager>
38 mm_ = nullptr;
39 std::shared_ptr<hh::core::abstraction::TaskNodeAbstraction> const
41 public:
44 explicit TaskNode(std::shared_ptr<hh::core::abstraction::TaskNodeAbstraction> core)
45 : Node(std::move(core)),
46 taskNodeAbstraction_(std::dynamic_pointer_cast<core::abstraction::TaskNodeAbstraction>(this->core())) {}
47
49 ~TaskNode() override = default;
50
53 [[nodiscard]] std::shared_ptr<AbstractMemoryManager> const &memoryManager() const { return mm_; }
54
57 void connectMemoryManager(std::shared_ptr<AbstractMemoryManager> mm) { mm_ = std::move(mm); }
58
63 std::shared_ptr<ManagedMemory> getManagedMemory() {
64 if (mm_ == nullptr) {
65 std::ostringstream oss;
66 oss << "For the node:\"" << this->name()
67 << "\"in order to get managed memory, you need first to connect a memory manager to the task via "
68 "\"connectMemoryManager()\""
69 << std::endl;
70 throw std::runtime_error(oss.str());
71 }
72 auto start = std::chrono::system_clock::now();
73 this->taskNodeAbstraction_->nvtxProfiler()->startRangeWaitingForMemory();
74 auto data = mm_->getManagedMemory();
75 this->taskNodeAbstraction_->nvtxProfiler()->endRangeWaitingForMem();
76 auto finish = std::chrono::system_clock::now();
77 this->taskNodeAbstraction_->incrementMemoryWaitDuration(finish - start);
78 return data;
79 }
80
82 virtual void initialize() {}
83
85 virtual void shutdown() {}
86
89 [[nodiscard]] virtual std::string extraPrintingInformation() const { return ""; }
90};
91}
92}
93#endif //HEDGEHOG_TASK_NODE_H_
Hedgehog main namespace.
Behavior abstraction for the base node.
Definition: node.h:32
std::string name() const
Node's name accessor.
Definition: node.h:53
std::shared_ptr< hh::core::abstraction::NodeAbstraction > const & core() const
Core accessor.
Definition: node.h:49
Behavior abstraction for TaskNode.
Definition: task_node.h:35
std::shared_ptr< ManagedMemory > getManagedMemory()
Get a managed memory for the memory manager attached to the task, can block if none are available at ...
Definition: task_node.h:63
~TaskNode() override=default
Default destructor.
void connectMemoryManager(std::shared_ptr< AbstractMemoryManager > mm)
Connect a memory manager to a task.
Definition: task_node.h:57
virtual std::string extraPrintingInformation() const
Print extra information for the task.
Definition: task_node.h:89
virtual void initialize()
initialize step for the task
Definition: task_node.h:82
std::shared_ptr< hh::core::abstraction::TaskNodeAbstraction > const taskNodeAbstraction_
Core abstraction for the task.
Definition: task_node.h:40
TaskNode(std::shared_ptr< hh::core::abstraction::TaskNodeAbstraction > core)
Constructor using a core.
Definition: task_node.h:44
std::shared_ptr< AbstractMemoryManager > mm_
Memory manager attached to the task.
Definition: task_node.h:38
virtual void shutdown()
shutdown step for the task
Definition: task_node.h:85
std::shared_ptr< AbstractMemoryManager > const & memoryManager() const
Memory manager accessor.
Definition: task_node.h:53