Hedgehog  3.1.0
A library to generate hybrid pipeline workflow systems
Loading...
Searching...
No Matches
task_node_abstraction.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
20
21#ifndef HEDGEHOG_TASK_NODE_ABSTRACTION_H
22#define HEDGEHOG_TASK_NODE_ABSTRACTION_H
23
24#include <ostream>
25#include "node_abstraction.h"
26#include "../../../../api/memory_manager/manager/abstract_memory_manager.h"
27#include "../../../../tools/nvtx_profiler.h"
28#include "../printable_abstraction.h"
29
31namespace hh {
33namespace core {
35namespace abstraction {
36
40 private:
42 bool
43 isActive_ = false,
45
46 std::chrono::nanoseconds
47 perElementExecutionDuration_ = std::chrono::nanoseconds::zero(),
48 waitDuration_ = std::chrono::nanoseconds::zero(),
49 memoryWaitDuration_ = std::chrono::nanoseconds::zero();
50
51 std::shared_ptr<NvtxProfiler>
52 nvtxProfiler_ = nullptr;
53
55 node_ = nullptr;
56
57 public:
62 nvtxProfiler_ = std::make_shared<NvtxProfiler>(name);
63 }
64
66 ~TaskNodeAbstraction() override = default;
67
70 [[nodiscard]] bool isActive() const { return isActive_; }
71
74 [[nodiscard]] bool isInitialized() const {
75 return isInitialized_;
76 }
77
80 [[nodiscard]] size_t numberReceivedElements() const { return numberReceivedElements_; }
81
84 [[nodiscard]] std::chrono::nanoseconds const &waitDuration() const { return waitDuration_; }
85
88 [[nodiscard]] std::chrono::nanoseconds const &memoryWaitDuration() const { return memoryWaitDuration_; }
89
92 [[nodiscard]] std::shared_ptr<NvtxProfiler> const &nvtxProfiler() const { return nvtxProfiler_; }
93
96 [[nodiscard]] std::chrono::nanoseconds perElementExecutionDuration() const {
97 return
98 this->numberReceivedElements() == 0 ?
99 std::chrono::nanoseconds::zero() :
100 (std::chrono::nanoseconds) (perElementExecutionDuration_ / this->numberReceivedElements());
101 }
102
106
109
112 void incrementWaitDuration(std::chrono::nanoseconds const &wait) { this->waitDuration_ += wait; }
113
116 void incrementMemoryWaitDuration(std::chrono::nanoseconds const &wait) { this->memoryWaitDuration_ += wait; }
117
120 void incrementPerElementExecutionDuration(std::chrono::nanoseconds const &exec) {
121 this->perElementExecutionDuration_ += exec;
122 }
123
125 virtual void preRun() = 0;
126
128 virtual void run() = 0;
129
131 virtual void postRun() = 0;
132
135 [[nodiscard]] virtual std::string extraPrintingInformation() const = 0;
136
139 [[nodiscard]] virtual bool hasMemoryManagerAttached() const = 0;
140
143 [[nodiscard]] virtual std::shared_ptr<AbstractMemoryManager> memoryManager() const = 0;
144
147 [[nodiscard]] behavior::Node *node() const override { return node_; }
148
149 protected:
152};
153}
154}
155}
156#endif //HEDGEHOG_TASK_NODE_ABSTRACTION_H
Hedgehog main namespace.
Behavior abstraction for the base node.
Definition: node.h:32
std::string const & name() const
Accessor to the core's name.
Task core abstraction used to define some method for task-like behaving cores like CoreExecutionPipel...
size_t numberReceivedElements_
Number of elements received.
void incrementNumberReceivedElements()
Increment the number of elements received.
void incrementWaitDuration(std::chrono::nanoseconds const &wait)
Increment the wait duration.
std::chrono::nanoseconds const & memoryWaitDuration() const
Accessor to the duration the node was in a memory wait state.
void setInitialized()
Set the task as initialized.
behavior::Node * node() const override
Node accessor.
TaskNodeAbstraction(std::string const &name, behavior::Node *node)
Create the abstraction with the node's name.
virtual std::string extraPrintingInformation() const =0
Abstraction to add user-defined message for the printers.
std::chrono::nanoseconds waitDuration_
Node wait duration.
behavior::Node * node_
Node attache to this task-like core.
virtual std::shared_ptr< AbstractMemoryManager > memoryManager() const =0
Accessor to the attached memory manager.
std::shared_ptr< NvtxProfiler > nvtxProfiler_
Store hedgehog nvtx profiler for the task.
virtual void preRun()=0
Pre run method, called only once.
~TaskNodeAbstraction() override=default
Default destructor.
std::chrono::nanoseconds perElementExecutionDuration() const
Accessor to the duration the average duration of processing an input data.
bool isInitialized() const
Accessor to initialized flag.
void isActive(bool isActive)
Setter to the task status.
virtual void run()=0
Run method, called when thread is attached.
std::chrono::nanoseconds perElementExecutionDuration_
Node per element duration.
std::shared_ptr< NvtxProfiler > const & nvtxProfiler() const
Accessor to the NVTX profiler attached to the node.
bool isActive() const
Accessor to task status.
void incrementPerElementExecutionDuration(std::chrono::nanoseconds const &exec)
Increase the execution time per elements.
virtual bool hasMemoryManagerAttached() const =0
Flag accessor to the presence of memory manager attached.
std::chrono::nanoseconds memoryWaitDuration_
Node memory wait duration.
std::chrono::nanoseconds const & waitDuration() const
Accessor to the duration the node was in a wait state.
void incrementMemoryWaitDuration(std::chrono::nanoseconds const &wait)
Increase the memory wait duration.
size_t numberReceivedElements() const
Accessor to the number of received elements.
virtual void postRun()=0
Post run method, called only once.
PrintAbstraction, used to determine if the node should be visited by the printer and colored.