14 #ifndef HTGS_TASKGRAPHRUNTIME_HPP 15 #define HTGS_TASKGRAPHRUNTIME_HPP 95 #if defined (USE_NVTX) && defined (USE_MINIMAL_NVTX) 96 domainInitialize = nvtxDomainCreateA(
"Initialize");
97 domainExecute = nvtxDomainCreateA(
"Execute");
98 domainWait = nvtxDomainCreateA(
"Wait");
99 domainWaitForMem = nvtxDomainCreateA(
"Wait for Memory");
100 domainReleaseMem = nvtxDomainCreateA(
"Release Memory");
101 domainShutdown = nvtxDomainCreateA(
"Shutdown");
102 #elif defined (USE_NVTX) 103 domainInitialize =
nullptr;
104 domainExecute =
nullptr;
105 domainWait =
nullptr;
106 domainWaitForMem =
nullptr;
107 domainReleaseMem =
nullptr;
108 domainShutdown =
nullptr;
118 HTGS_DEBUG_VERBOSE(
"TaskGraphRuntime: " <<
this <<
" Freeing memory for TaskManagerThread: " << t);
125 for (std::thread *t :
threads) {
129 HTGS_ASSERT(!t->joinable(),
"Trying to delete thread that has not been joined. You must call 'waitForRuntime' prior to deleting the TaskGraphRuntime. (see https://pages.nist.gov/HTGS/doxygen/classhtgs_1_1_task_graph_runtime.html#a8f2eaf040695178b6f61db7b0ee16c89)");
143 #if defined (USE_NVTX) && (USE_MINIMAL_NVTX) 144 nvtxDomainDestroy(domainInitialize);
145 nvtxDomainDestroy(domainExecute);
146 nvtxDomainDestroy(domainWait);
147 nvtxDomainDestroy(domainWaitForMem);
148 nvtxDomainDestroy(domainReleaseMem);
149 nvtxDomainDestroy(domainShutdown);
158 for (std::thread *t :
threads) {
196 std::list<AnyTaskManager *> newVertices;
202 size_t numThreads = task->getNumThreads();
204 HTGS_DEBUG_VERBOSE(
"Spawning " << numThreads <<
" threads for task " << task->getName());
206 if (numThreads > 0) {
207 std::list<AnyTaskManager *> taskList;
208 std::shared_ptr<std::atomic_size_t>
209 atomicNumThreads = std::shared_ptr<std::atomic_size_t>(
new std::atomic_size_t(numThreads));
210 taskList.push_back(task);
212 for (
size_t i = 1; i < numThreads; i++) {
218 graph->sendProfileData(producerData);
223 graph->sendProfileData(connectorConsumerData);
224 graph->sendProfileData(producerConnectorData);
230 taskList.push_back(taskCopy);
231 newVertices.push_back(taskCopy);
235 #if defined (USE_NVTX) && defined (USE_MINIMAL_NVTX) 236 nvtxDomainHandle_t taskDomain =
nullptr;
237 #elif defined (USE_NVTX) 238 nvtxDomainHandle_t taskDomain = nvtxDomainCreateA(task->getName().c_str());
242 #if defined (USE_NVTX) && defined (USE_MINIMAL_NVTX) 243 NVTXProfiler *profiler =
new NVTXProfiler(std::to_string(threadId) +
":" + taskItem->getName(), taskDomain, domainInitialize, domainExecute, domainWait, domainWaitForMem, domainReleaseMem, domainShutdown);
244 taskItem->setProfiler(profiler);
245 #elif defined (USE_NVTX) 246 NVTXProfiler *profiler =
new NVTXProfiler(std::to_string(threadId), taskDomain, domainInitialize, domainExecute, domainWait, domainWaitForMem, domainReleaseMem, domainShutdown);
247 taskItem->setProfiler(profiler);
254 this->
threads.push_back(thread);
260 std::cerr << task->getName() <<
" has no threads specified." << std::endl;
266 std::shared_ptr<ProfileData> graphCreationComplete(
new GraphCompleteProfile(
graph));
267 graph->sendProfileData(graphCreationComplete);
287 nvtxDomainHandle_t domainInitialize;
288 nvtxDomainHandle_t domainExecute;
289 nvtxDomainHandle_t domainWait;
290 nvtxDomainHandle_t domainWaitForMem;
291 nvtxDomainHandle_t domainReleaseMem;
292 nvtxDomainHandle_t domainShutdown;
298 #endif //HTGS_TASKGRAPHRUNTIME_HPP bool executed
Whether the Runtime has been executed.
Definition: TaskGraphRuntime.hpp:284
Implements the parent class for a Task to remove the template arguments and the TaskManagerThread to ...
std::list< std::thread * > threads
A list of all threads spawned for the Runtime.
Definition: TaskGraphRuntime.hpp:281
virtual AnyTaskManager * copy(bool deep)=0
Copies the TaskManager.
Implements the task graph configuration class responsible for managing ITask connections.
void addTaskManager(AnyTaskManager *taskManager)
Adds a task manager to the task graph.
Definition: AnyTaskGraphConf.hpp:396
void terminateAll()
Terminates the Runtime.
Definition: TaskGraphRuntime.hpp:179
void executeAndWaitForRuntime()
Executes the Runtime and then waits for it to finish processing.
Definition: TaskGraphRuntime.hpp:169
void shutdown()
Called when all the threads in this graph have finished executing.
Definition: AnyTaskGraphConf.hpp:262
#define HTGS_DEBUG_VERBOSE(msg)
Prints a debug message to std:cerr with VERBOSE level.
Definition: debug_message.hpp:75
int run()
Executes the task until the underlying Task has been terminated.
Definition: AnyTaskManager.hpp:607
Spawns threads and binds them to the appropriate ITask within a TaskGraph.
Definition: TaskGraphRuntime.hpp:84
void executeRuntime()
Executes the Runtime.
Definition: TaskGraphRuntime.hpp:188
virtual AnyITask * getTaskFunction()=0
Gets the ITask function associated with the TaskManager.
std::string getName()
Gets the name of the ITask.
Definition: AnyTaskManager.hpp:390
std::list< TaskManagerThread * > runtimeThreads
The list of TaskManagers bound to each thread.
Definition: TaskGraphRuntime.hpp:283
void initialize()
Initializes the task graph just prior to spawning threads.
Definition: AnyTaskGraphConf.hpp:238
std::list< AnyTaskManager * > * getTaskManagers()
Virtual function that initiates updating the task graph communicator.
Definition: AnyTaskGraphConf.hpp:180
virtual std::shared_ptr< AnyConnector > getInputConnector()=0
Gets the input Connector.
TaskGraphRuntime(AnyTaskGraphConf *graph)
Constructs a Runtime for a TaskGraph.
Definition: TaskGraphRuntime.hpp:92
virtual void finishedSetup()
Called when the task graph has finished setting up its tasks and launched all threads for the graph...
Definition: AnyTaskGraphConf.hpp:257
The parent class for a Task that removes the template arguments.
Definition: AnyTaskManager.hpp:45
Manages a TaskManager that is bound to a thread for execution.
Definition: AnyTaskManager.hpp:573
std::mutex * getInitializationMutex()
Gets the initialization mutex, used for signaling when initialization is done.
Definition: AnyTaskGraphConf.hpp:305
AnyTaskGraphConf * graph
The TaskGraph associated with the Runtime.
Definition: TaskGraphRuntime.hpp:282
~TaskGraphRuntime()
Destructor.
Definition: TaskGraphRuntime.hpp:115
Implements the base class for the TaskGraphConf class, removing the template arguments and providing ...
Definition: AnyTaskGraphConf.hpp:66
#define HTGS_ASSERT(condition, message)
Prints a more meaningful assertion message and terminates if the condition fails. ...
Definition: debug_message.hpp:25
virtual std::shared_ptr< AnyConnector > getOutputConnector()=0
Gets the output Connector.
void waitForRuntime()
Waits for the Runtime to finish executing.
Definition: TaskGraphRuntime.hpp:157
Definition: Bookkeeper.hpp:23
std::condition_variable * getInitializationCondition()
Notifies the task graph to check if all task managers have been initialized or not.
Definition: AnyTaskGraphConf.hpp:297