Hedgehog  3.1.0
A library to generate hybrid pipeline workflow systems
Loading...
Searching...
No Matches
task_inputs_management_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_INPUTS_MANAGEMENT_ABSTRACTION_H
22#define HEDGEHOG_TASK_INPUTS_MANAGEMENT_ABSTRACTION_H
23
24#include <mutex>
25#include <condition_variable>
26#include <ostream>
27
28#include "../base/node/node_abstraction.h"
29#include "../base/execute_abstraction.h"
30#include "../base/input_output/slot_abstraction.h"
31
32#include "../../../tools/concepts.h"
33#include "../../implementors/concrete_implementor/default_slot.h"
34#include "../../implementors/concrete_implementor/queue_receiver.h"
35#include "../../implementors/concrete_implementor/default_execute.h"
37namespace hh {
39namespace core {
41namespace abstraction {
42
45template<class ...Inputs>
47 public SlotAbstraction,
48 public ReceiverAbstraction<Inputs> ...,
49 public ExecuteAbstraction<Inputs> ... {
50 private:
51 TaskNodeAbstraction *const coreTask_ = nullptr;
52 public:
53 using inputs_t = std::tuple<Inputs...>;
54
59 template<class NodeType>
60 explicit TaskInputsManagementAbstraction(NodeType *const nodeTask, TaskNodeAbstraction *const coreTask)
61 : SlotAbstraction(std::make_shared<implementor::DefaultSlot>()),
62 ReceiverAbstraction<Inputs>(
63 std::make_shared<implementor::QueueReceiver<Inputs>>(), SlotAbstraction::mutex()
64 )...,
65 ExecuteAbstraction<Inputs>(std::make_shared<implementor::DefaultExecute<Inputs>>(
66 static_cast<behavior::Execute<Inputs>*>(nodeTask)))...,
67 coreTask_(coreTask) {}
68
76 template<
77 hh::tool::ConcreteMultiReceiverImplementation<Inputs...> ConcreteMultiReceivers,
78 hh::tool::ConcreteMultiExecuteImplementation<Inputs...> ConcreteMultiExecutes
79 >
81 TaskNodeAbstraction *const coreTask,
82 std::shared_ptr<implementor::ImplementorSlot> concreteSlot,
83 std::shared_ptr<ConcreteMultiReceivers> concreteMultiReceivers,
84 std::shared_ptr<ConcreteMultiExecutes> concreteMultiExecutes) :
85 SlotAbstraction(concreteSlot),
86 ReceiverAbstraction<Inputs>(concreteMultiReceivers,
88 ExecuteAbstraction<Inputs>(concreteMultiExecutes)
89 ...,
90 coreTask_(coreTask) {}
91
94
97 [[nodiscard]] bool receiversEmpty() const { return (ReceiverAbstraction<Inputs>::empty() && ...); }
98
99 protected:
100
103 [[nodiscard]] size_t totalNumberElementsReceived() const {
105 }
106
108 void operateReceivers() { (this->operateReceiver<Inputs>(), ...); }
109
112
114 void wakeUp() final { this->slotConditionVariable()->notify_one(); }
115
121 }
122
127 }
128
129 private:
132 template<tool::ContainsConcept<Inputs...> InputDataType>
134 this->lockSlotMutex();
135 auto typedReceiver = static_cast<ReceiverAbstraction<InputDataType> *>(this);
136 if (!typedReceiver->empty()) {
137 std::shared_ptr<InputDataType> data = typedReceiver->getInputData();
139 this->unlockSlotMutex();
140 std::chrono::time_point<std::chrono::system_clock> start = std::chrono::system_clock::now();
141 coreTask_->nvtxProfiler()->startRangeExecuting();
143 coreTask_->nvtxProfiler()->endRangeExecuting();
144 std::chrono::time_point<std::chrono::system_clock> finish = std::chrono::system_clock::now();
146 std::chrono::duration_cast<std::chrono::nanoseconds>(finish - start)
147 );
148 } else {
149 this->unlockSlotMutex();
150 }
151 }
152
153};
154}
155}
156}
157#endif //HEDGEHOG_TASK_INPUTS_MANAGEMENT_ABSTRACTION_H
Hedgehog main namespace.
Printer abstraction to get a snapshot of the metrics of the Hedgehog graph.
Definition: printer.h:52
Core execute abstraction, interface to user-defined execution.
void callExecute(std::shared_ptr< Input > data)
Interface for calling user-defined execution.
Core's abstraction to receive a piece of data.
void copyInnerStructure(ReceiverAbstraction< Input > *copyableCore)
Copy inner structure of the receiver to this one.
std::shared_ptr< Input > getInputData()
Get an input data from the concrete receiver implementation.
void printEdgeInformation(Printer *printer)
Add to the printer the edge information.
Core's abstraction to receive a signal.
std::shared_ptr< std::mutex > const & mutex() const
Protected accessor to mutex.
void copyInnerStructure(SlotAbstraction *copyableCore)
Copy the inner structure of copyableCore into this.
std::shared_ptr< std::condition_variable > const & slotConditionVariable() const
Protected accessor to condition variable.
Task core abstraction used to define some method for task-like behaving cores like CoreExecutionPipel...
void incrementNumberReceivedElements()
Increment the number of elements received.
std::shared_ptr< NvtxProfiler > const & nvtxProfiler() const
Accessor to the NVTX profiler attached to the node.
void incrementPerElementExecutionDuration(std::chrono::nanoseconds const &exec)
Increase the execution time per elements.
void copyInnerStructure(TaskInputsManagementAbstraction< Inputs... > *copyableCore)
Copy the task core inner structure to this.
void wakeUp() final
Wake up implementation (notify one node waiting on the condition variable)
bool receiversEmpty() const
Test if the receivers are empty for the task.
TaskNodeAbstraction *const coreTask_
Accessor to the core task.
~TaskInputsManagementAbstraction() override=default
Default destructor.
void printEdgesInformation(Printer *printer)
Add edge information to the printer.
TaskInputsManagementAbstraction(TaskNodeAbstraction *const coreTask, std::shared_ptr< implementor::ImplementorSlot > concreteSlot, std::shared_ptr< ConcreteMultiReceivers > concreteMultiReceivers, std::shared_ptr< ConcreteMultiExecutes > concreteMultiExecutes)
Constructor using a node and the concrete implementor.
void operateReceiver()
Access the ReceiverAbstraction of the type InputDataType to process an element.
size_t totalNumberElementsReceived() const
Accessor to the total number of elements received for all input types.
void operateReceivers()
Access all the task receivers to process an element.
void callAllExecuteWithNullptr()
Call for all types the user-defined execute method with nullptr as data.
TaskInputsManagementAbstraction(NodeType *const nodeTask, TaskNodeAbstraction *const coreTask)
Constructor using a node task and its core.
std::tuple< Inputs... > inputs_t
Accessor to the input types.
Concept verifying that a type is in a variadic.
Definition: concepts.h:86
Test if a type is a valid concrete implementation of the core::implementor::ImplementorReceiver for t...
Definition: concepts.h:263
Test if a type is a valid concrete implementation of the core::implementor::ImplementorExecute for th...
Definition: concepts.h:279