Task Scheduler

Becaus of the high number of tasks to execute and their complex dependencies, Mirheo uses a mirheo::TaskScheduler that takes care of executing all these tasks on concurrent streams. The synchronization is therefore hidden in this class.

API

class TaskScheduler

CUDA-aware task scheduler.

Manages task dependencies and run them concurrently on different CUDA streams. This is designed to be run in a time stepping scheme, e.g. all the tasks of a single time step must be described here before calling the run() method repetitively.

Public Types

using TaskID = int

Represents the unique id of a task.

using Function = std::function<void(cudaStream_t)>

Represents the function performed by a task. Will be executed on the given stream.

Public Functions

TaskScheduler()

Default constructor.

TaskID createTask(const std::string &label)

Create and register an empty task named label.

This method will die if a task with the given label already exists.

Return
the task id associated with the new task
Parameters
  • label: The name of the task

TaskID getTaskId(const std::string &label)

Retrieve the task id of the task with a given label.

Return
the task id if it exists, or invalidTaskId if it doesn’t
Parameters
  • label: The name of the task

TaskID getTaskIdOrDie(const std::string &label)

Retrieve the task id of the task with a given label.

This method will die if no registered task has the given label

Return
the task id
Parameters
  • label: The name of the task

void addTask(TaskID id, Function task, int execEvery = 1)

Add a function to execute to the given task.

Multiple functions can be added in a single task. The order of execution of these functions is the order in which they were added. This method will fail if the required task does not exist.

Parameters
  • id: Task Id
  • task: The function to execute
  • execEvery: Execute his function every this number of calls of run().

void addDependency(TaskID id, std::vector<TaskID> before, std::vector<TaskID> after)

add dependencies around a given task

Parameters
  • id: The task that must be executed before before and after after
  • before: the list of tasks that must be executed after the task with id id
  • after: the list of tasks that must be executed before the task with id id

void setHighPriority(TaskID id)

Set the execution of a task to high priority.

Parameters
  • id: The task id

void compile()

Prepare the internal state so that the scheduler can perform execution of all tasks.

No other calls related to task creation / modification / dependencies must be performed after calling this function.

void run()

Execute the tasks in the order required by the given dependencies and priorities.

Must be called after compile().

void dumpGraphToGraphML(const std::string &fname) const

Dump a representation of the tasks and their dependencies in graphML format.

Parameters
  • fname: The file name to dump the graph to (without extension).

void forceExec(TaskID id, cudaStream_t stream)

Execute a given task on a given stream.

Parameters
  • id: the task to execute
  • stream: The stream to execute the task

Public Static Attributes

constexpr TaskID invalidTaskId = {static_cast<TaskID>(-1)}

Special task id value to represent invalid tasks.