14 #ifndef HTGS_ITASK_HPP 15 #define HTGS_ITASK_HPP 20 #include <unordered_map> 29 #include <nvtx3/nvToolsExt.h> 32 #if defined( __GLIBCXX__ ) || defined( __GLIBCPP__ ) 38 template<
class T,
class U>
164 template<
class T,
class U>
166 static_assert(std::is_base_of<IData, T>::value,
"T must derive from IData");
167 static_assert(std::is_base_of<IData, U>::value,
"U must derive from IData");
200 virtual ~
ITask()
override {}
210 virtual void executeTask(std::shared_ptr<T> data) = 0;
215 virtual bool canTerminate(std::shared_ptr<AnyConnector> inputConnector)
override {
216 if (inputConnector ==
nullptr)
219 return inputConnector->isInputTerminated();
237 return "UnnamedITask";
292 virtual std::string genDotProducerEdgeToTask(std::map<std::shared_ptr<AnyConnector>,
AnyITask *> &inputConnectorDotMap,
int dotFlags)
override 294 auto connectorPair = inputConnectorDotMap.find(this->
ownerTask->getOutputConnector());
295 if (connectorPair != inputConnectorDotMap.end())
297 auto consumerIds = connectorPair->second->getConsumerDotIds();
298 if (consumerIds !=
"")
299 return this->
getDotId() +
" -> " + connectorPair->second->getConsumerDotIds() +
";\n";
306 virtual std::string genDotConsumerEdgeFromConnector(std::shared_ptr<AnyConnector> connector,
int flags)
override 308 if (this->
ownerTask->getInputConnector() !=
nullptr &&
309 connector !=
nullptr && this->
ownerTask->getInputConnector() == connector)
311 auto consumerIds = this->getConsumerDotIds();
312 if (consumerIds !=
"")
313 return connector->getDotId() +
" -> " + this->getConsumerDotIds() +
";\n";
318 virtual std::string genDotProducerEdgeFromConnector(std::shared_ptr<AnyConnector> connector,
int flags)
320 if (this->
ownerTask->getOutputConnector() !=
nullptr &&
321 connector !=
nullptr && this->
ownerTask->getOutputConnector() == connector)
324 return this->
getDotId() +
" -> " + connector->getDotId() +
";\n";
344 HTGS_ASSERT(iTaskCopy !=
nullptr,
"Copying Task '" << this->
getName() <<
"' resulted in nullptr. Make sure you have the 'copy' function implemented (see https://pages.nist.gov/HTGS/doxygen/classhtgs_1_1_i_task.html#acaedf1466b238036d880efcbf1feafe6)");
367 this->
ownerTask->addResult(std::shared_ptr<U>(result));
380 super::initialize(pipelineId, numPipeline);
400 return getMemory<V>(name, releaseRule, MMType::Static, 0);
420 return getMemory<V>(name, releaseRule, MMType::Dynamic, numElems);
430 [[gnu::deprecated(
"Replaced by calling 'releaseMemory' directory with htgs::MemoryData (or m_data_t)")]]
432 memory->releaseMemory();
468 return this->
ownerTask->getTaskComputeTime();
476 #if defined( __GLIBCXX__ ) || defined( __GLIBCPP__ ) 478 char *realName = abi::__cxa_demangle(
typeid(T).name(), 0, 0, &status);
479 std::string ret(realName);
485 return typeid(T).name();
494 #if defined( __GLIBCXX__ ) || defined( __GLIBCPP__ ) 496 char *realName = abi::__cxa_demangle(
typeid(U).name(), 0, 0, &status);
497 std::string ret(realName);
503 return typeid(U).name();
535 virtual void gatherProfileData(std::map<AnyTaskManager *, TaskManagerProfile *> *taskManagerProfiles) {}
550 sendWSProfileUpdate(StatusCode::WAITING_FOR_MEM);
554 nvtxRangeId_t rangeId = this->
getOwnerTaskManager()->getProfiler()->startRangeWaitingForMemory();
558 auto start = std::chrono::high_resolution_clock::now();
567 auto finish = std::chrono::high_resolution_clock::now();
568 this->
incMemoryWaitTime(std::chrono::duration_cast<std::chrono::microseconds>(finish - start).count());
572 sendWSProfileUpdate(StatusCode::EXECUTE);
577 memory->setMemoryReleaseRule(releaseRule);
579 if (memory->getType() != type) {
581 <<
"Error: Incorrect usage of getMemory. Dynamic memory managers use 'getDynamicMemory', Static memory managers use 'getMemory' for task '" 582 << this->
getName() <<
"' on memory edge " << name << std::endl;
586 if (type == MMType::Dynamic)
587 memory->memAlloc(nElem);
601 #endif //HTGS_ITASK_HPP virtual void printProfile() override
Prints the profile data to std::out.
Definition: ITask.hpp:279
virtual void executeTaskFinal() override
Virtual function that is called just before the task has shutdown.
Definition: ITask.hpp:230
Implements the parent ITask, which removes the template arguments of an ITask.
Definition: AnyITask.hpp:48
virtual std::string getDotShapeColor() override
Gets the color of the shape for graphviz dot.
Definition: ITask.hpp:250
std::string getDotId()
Gets the id used for dot nodes.
Definition: AnyITask.hpp:497
virtual void initialize() override
Virtual function that is called when an ITask is being initialized by it's owner thread.
Definition: ITask.hpp:202
virtual void shutdown() override
Virtual function that is called when an ITask is being shutdown by it's owner thread.
Definition: ITask.hpp:225
virtual bool canTerminate(std::shared_ptr< AnyConnector > inputConnector) override
Virtual function that is called when an ITask is checking if it can be terminated.
Definition: ITask.hpp:215
virtual std::string getDotShape() override
Gets the shape for graphviz dot.
Definition: ITask.hpp:264
MMType
The memory manager types.
Definition: MMType.hpp:38
TaskManager< T, U > * ownerTask
The owner task for this ITask.
Definition: ITask.hpp:594
Provides the Connector class for managing input/output of AbsData between Tasks.
void setTaskManager(TaskManager< T, U > *ownerTask)
Sets the owner task manager for this ITask.
Definition: ITask.hpp:519
void incMemoryWaitTime(unsigned long long int val)
Increments memory wait time.
Definition: AnyITask.hpp:574
size_t getThreadID()
Gets the thread ID associated with this task.
Definition: ITask.hpp:458
void addResult(std::shared_ptr< U > result)
Adds results to the output list to be sent to the next connected ITask in a TaskGraph.
Definition: ITask.hpp:357
Manages the input/output of IData between Tasks.
Definition: Connector.hpp:62
virtual void gatherProfileData(std::map< AnyTaskManager *, TaskManagerProfile *> *taskManagerProfiles)
Gathers profile data.
Definition: ITask.hpp:535
size_t numThreads
The number of threads to be used with this ITask (forms a thread pool) used when creating a TaskManag...
Definition: AnyITask.hpp:600
virtual void executeTask(std::shared_ptr< T > data)=0
Pure virtual function that is called when an ITask's thread is to execute on data.
m_data_t< V > getDynamicMemory(std::string name, IMemoryReleaseRule *releaseRule, size_t numElems)
Retrieves memory from a memory edge.
Definition: ITask.hpp:419
std::string outTypeName() override final
Gets the demangled output type name of the connector.
Definition: ITask.hpp:493
void initialize(size_t pipelineId, size_t numPipeline, TaskManager< T, U > *ownerTask)
Function that is called when an ITask is being initialized by it's owner thread.
Definition: ITask.hpp:378
ITask< T, U > * copyITask(bool deep) override
Copies the ITask (including a copy of all memory edges)
Definition: ITask.hpp:341
std::string getAddress() override final
Gets the address from the owner task, which is the address of the task graph.
Definition: ITask.hpp:511
Abstract class that describes when memory can be released/reused.
Definition: IMemoryReleaseRule.hpp:73
ITask(size_t numThreads)
Constructs an ITask with a specified number of threads.
Definition: ITask.hpp:180
virtual ITask< T, U > * copy()=0
Pure virtual function to copy an ITask.
ITask(size_t numThreads, bool isStartTask, bool poll, size_t microTimeoutTime)
Constructs an ITask with a specified number of threads as well as additional scheduling options...
Definition: ITask.hpp:190
bool isStartTask() const
Gets whether this ITask is a starting task.
Definition: AnyITask.hpp:422
TaskManager< T, U > * getOwnerTaskManager()
Gets the owner task manager for this ITask.
Definition: ITask.hpp:527
virtual size_t getNumGraphsSpawned()
Gets the number of graphs spawned by this ITask.
Definition: ITask.hpp:290
An interface to process input data and forward results within a TaskGraph.
Definition: ITask.hpp:165
ITask()
Creates an ITask with number of threads equal to 1.
Definition: ITask.hpp:174
const std::shared_ptr< ConnectorMap > & getMemoryEdges() const
Gets the memory edges for the task.
Definition: AnyITask.hpp:515
bool poll
Whether the ITask should poll for data used when creating a TaskManager.
Definition: AnyITask.hpp:602
Encapsulates an ITask to interact with an ITask's functionality.
Definition: ITask.hpp:39
size_t microTimeoutTime
The timeout time for polling in microseconds used when creating a TaskManager.
Definition: AnyITask.hpp:603
virtual std::string getDotLabelName() override
Virtual function to get the label name used for dot graph viz.
Definition: ITask.hpp:243
void copyMemoryEdges(AnyITask *iTaskCopy)
Copies the memory edges from this AnyITask to another AnyITask.
Definition: AnyITask.hpp:448
virtual std::string getDotCustomProfile() override
Adds the string text to the profiling of this task in the graphviz dot visualization.
Definition: ITask.hpp:272
Implements a TaskManager that interacts with an ITask and holds the input and output Connector for th...
#define HTGS_ASSERT(condition, message)
Prints a more meaningful assertion message and terminates if the condition fails. ...
Definition: debug_message.hpp:25
void addResult(U *result)
Adds results to the output list to be sent to the next connected ITask in a TaskGraph.
Definition: ITask.hpp:366
m_data_t< V > getMemory(std::string name, IMemoryReleaseRule *releaseRule)
Retrieves memory from a memory edge.
Definition: ITask.hpp:399
std::string inTypeName() override final
Gets the demangled input type name of the connector.
Definition: ITask.hpp:475
std::shared_ptr< MemoryData< V > > m_data_t
Defines a shared pointer to htgs::MemoryData.
Definition: Types.hpp:101
void resetProfile()
Resets profile data.
Definition: ITask.hpp:449
size_t pipelineId
The execution pipeline id for the ITask.
Definition: AnyITask.hpp:604
void releaseMemory(m_data_t< V > memory)
Releases memory onto a memory edge, which is transferred by the graph communicator.
Definition: ITask.hpp:431
unsigned long long int getTaskComputeTime() const
Gets the task's compute time.
Definition: ITask.hpp:467
Definition: Bookkeeper.hpp:23
virtual std::string getDotFillColor() override
Gets the color for filling the shape for graphviz dot.
Definition: ITask.hpp:257
virtual std::string getName() override
Virtual function to get the name of an ITask.
Definition: ITask.hpp:236