20 #ifndef HEDGEHOG_TASK_H 21 #define HEDGEHOG_TASK_H 23 #include "../behavior/io/multi_receivers.h" 24 #include "../behavior/io/sender.h" 25 #include "../behavior/execute.h" 26 #include "memory_manager/abstract_memory_manager.h" 27 #include "../core/node/core_node.h" 28 #include "../core/defaults/core_default_task.h" 75 template<
class TaskOutput,
class ...TaskInputs>
82 static_assert(traits::isUnique<TaskInputs...>,
"A Task can't accept multiple inputs with the same type.");
83 static_assert(
sizeof... (TaskInputs) >= 1,
"A node need to have one output type and at least one output type.");
86 std::shared_ptr<AbstractMemoryManager<TaskOutput>>
mm_ =
nullptr;
115 core::NodeType::Task,
189 std::shared_ptr<AbstractMemoryManager<TaskOutput>>
const &
memoryManager()
const {
return mm_; }
193 virtual std::shared_ptr<
AbstractTask<TaskOutput, TaskInputs...>>
copy() {
return nullptr; }
205 traits::is_managed_memory_v<TaskOutput>,
206 "The type given to the memory manager should inherit \"MemoryData\", and be default constructible!");
213 if (mm_ ==
nullptr) {
215 <<
"For the task:\"" << this->
name()
216 <<
"\"To get managed memory, you need first to connect a memory manager to the task via " 217 "\"connectMemoryManager()\"" 222 auto start = std::chrono::high_resolution_clock::now();
223 this->
taskCore_->nvtxProfiler()->startRangeWaitingForMemory();
224 auto data = mm_->getManagedMemory();
225 this->
taskCore_->nvtxProfiler()->endRangeWaitingForMem();
226 auto finish = std::chrono::high_resolution_clock::now();
228 this->
core()->incrementWaitForMemoryDuration(std::chrono::duration_cast<std::chrono::microseconds>(finish - start));
239 #endif //HEDGEHOG_TASK_H virtual void shutdown()
Shutdown method called after AbstractTask::Execute loop, when AbstractTask::canTerminate evaluates to...
Base node for computation.
AbstractTask(std::string_view const name, size_t numberThreads, core::NodeType nodeType, bool automaticStart)
Internal constructor needed to create nodes that derive from AbstractTask.
AbstractTask()
AbstractTask default constructor.
int deviceId()
Task's device ID accessor.
virtual void initialize()
Initialize method called before AbstractTask::Execute loop.
core::NodeType nodeType()
Task's node type accessor.
AbstractTask(std::string_view const &name, size_t numberThreads, bool automaticStart)
Create a task with a custom name, the task's cluster size, and the automatic start.
void addResult(std::shared_ptr< TaskOutput > output)
Add an output data.
AbstractTask(AbstractTask< TaskOutput, TaskInputs ... > *rhs)
Copy constructor.
Sender Behavior definition, node has an output type.
Abstract interface for Hedgehog's Memory manager.
bool canTerminate() override
Method called to test the task;s termination, by default, the test is: no input nodes connected and...
std::shared_ptr< core::CoreNode > core() final
Task's core accessor.
void connectMemoryManager(std::shared_ptr< AbstractMemoryManager< TaskOutput >> mm)
Connect a memory manager to the task.
Node Behavior definition.
Core of the default Task to be use.
int graphId()
Task's graph ID accessor.
std::shared_ptr< AbstractMemoryManager< TaskOutput > > mm_
Task's memory manager.
virtual std::shared_ptr< AbstractTask< TaskOutput, TaskInputs... > > copy()
Default copy overload, fail if cluster need to be copied.
NodeType
Hedgehog node's type.
MultiReceivers Behavior definition, node has a list of input types.
std::shared_ptr< TaskOutput > getManagedMemory()
Memory manager accessor.
AbstractTask(std::string_view const &name)
Create a task with a custom name.
virtual ~AbstractTask()=default
Default destructor.
std::shared_ptr< AbstractMemoryManager< TaskOutput > > const & memoryManager() const
Task's memory manager accessor.
std::shared_ptr< core::CoreTask< TaskOutput, TaskInputs... > > taskCore_
Task Core.
Execute Behavior definition, node that has an execution for an Input data type.
AbstractTask(std::string_view const &name, size_t numberThreads)
Create a task with a custom name and the task's cluster size.
std::string_view name()
Task's name accessor.
bool automaticStart()
Task's automatic start accessor.
size_t numberThreads()
Task's number of threads accessor.