-
Notifications
You must be signed in to change notification settings - Fork 0
Task Parallelism
Kokkos has support for lightweight task-based programming, which is currently pretty limited but we plan to substantially expand in the future.
Not all task-based problems are a good fit for the current Kokkos approach to tasking. Currently, the tasking interface in Kokkos is targetted at problems with kernels far too small to overcome the inherent overhead of top-level Kokkos data parallel launches—that is, small but plentiful data parallel tasks with a non-trivial dependency structure. For tasks that fit this general scale model but have (very) trivial dependency structures, it may be easier to use hierarchical parallelism, potentially with a Kokkos::Schedule<Dynamic>
scheduling policy (see, for instance, this page) for load balancing if necessary.
Fundamentally, task parallelism is just another form of parallelism in Kokkos. The same general idiom of pattern, policy, and functor applies as for ordinary parallel dispatch:
Similarly, for tasking, we have:
In most ways, the functor portion of the task parallelism idiom in Kokkos is similar to that for data parallelism. Task functors haeve the additional requirement that the task output type needs to be provided by the user by giving a nested type (a.k.a. "typedef") named value_type
:
struct MyTask {
using value_type = double;
template <class TeamMember>
KOKKOS_INLINE_FUNCTION
void operator()(TeamMember& member, double& result);
};
Similar to team parallelism, the first parameter is the team handle, which has all of the same functionality as the one produced by a Kokkos::TeamPolicy
, with a few extras. Like with Kokkos::parallel_reduce()
, the output is expressed through the second parameter. Note that there is currently no lambda interface to Kokkos Tasking.
The primary analogs of Kokkos::parallel_for()
and friends for tasking are Kokkos::task_spawn()
and Kokkos::host_spawn()
. They both return a Kokkos::Future
associated with the appropriate Scheduler
, but host_spawn
can only be called from outside of a task functor, while task_spawn
can only be called from inside of one.
There are currently two task policies in Kokkos Tasking: TaskSingle
and TaskTeam
. The former tells Kokkos to launch the associated task functor with a single worker when its predecessors are done (more on this below), while the latter tells Kokkos to launch with a team of workers, similar to a single team from a Kokkos::TeamPolicy
launch in data parallelism.
Dependency relationships in Kokkos are represented by instances of the Kokkos::Future
class template.
TODO
Home:
- Introduction
- Machine Model
- Programming Model
- Compiling
- Initialization
- View
- Parallel Dispatch
- Hierarchical Parallelism
- Custom Reductions
- Atomic Operations
- Subviews
- Interoperability
- Kokkos and Virtual Functions
- Initialization and Finalization
- View
- Data Parallelism
- Execution Policies
- Spaces
- Task Parallelism
- Utilities
- STL Compatibility
- Numerics
- Detection Idiom