![]() |
Taskflow
3.2.0-Master-Branch
|
class to build a task dependency graph More...
#include <flow_builder.hpp>
Public Member Functions | |
FlowBuilder (Graph &graph) | |
constructs a flow builder with a graph | |
template<typename C , std::enable_if_t< is_static_task_v< C >, void > * = nullptr> | |
Task | emplace (C &&callable) |
creates a static task | |
template<typename C , std::enable_if_t< is_dynamic_task_v< C >, void > * = nullptr> | |
Task | emplace (C &&callable) |
creates a dynamic task | |
template<typename C , std::enable_if_t< is_condition_task_v< C >, void > * = nullptr> | |
Task | emplace (C &&callable) |
creates a condition task | |
template<typename C , std::enable_if_t< is_multi_condition_task_v< C >, void > * = nullptr> | |
Task | emplace (C &&callable) |
creates a multi-condition task | |
template<typename... C, std::enable_if_t<(sizeof...(C)>1), void > * = nullptr> | |
auto | emplace (C &&... callables) |
creates multiple tasks from a list of callable objects | |
void | erase (Task task) |
removes a task from a taskflow | |
template<typename T > | |
Task | composed_of (T &object) |
creates a module task for the target object | |
Task | placeholder () |
creates a placeholder task | |
template<typename C , std::enable_if_t< is_cudaflow_task_v< C >, void > * = nullptr> | |
Task | emplace (C &&callable) |
creates a cudaFlow task on the caller's GPU device context | |
template<typename C , typename D , std::enable_if_t< is_cudaflow_task_v< C >, void > * = nullptr> | |
Task | emplace_on (C &&callable, D &&device) |
creates a cudaFlow task on the given device | |
template<typename C , std::enable_if_t< is_syclflow_task_v< C >, void > * = nullptr> | |
Task | emplace (C &&callable) |
creates a syclFlow task on the default queue | |
template<typename C , typename Q , std::enable_if_t< is_syclflow_task_v< C >, void > * = nullptr> | |
Task | emplace_on (C &&callable, Q &&queue) |
creates a syclFlow task on the given queue | |
template<typename C , std::enable_if_t< is_runtime_task_v< C >, void > * = nullptr> | |
Task | emplace (C &&callable) |
creates a runtime task | |
void | linearize (std::vector< Task > &tasks) |
adds adjacent dependency links to a linear list of tasks | |
void | linearize (std::initializer_list< Task > tasks) |
adds adjacent dependency links to a linear list of tasks | |
template<typename B , typename E , typename C > | |
Task | for_each (B first, E last, C callable) |
constructs a STL-styled parallel-for task | |
template<typename B , typename E , typename S , typename C > | |
Task | for_each_index (B first, E last, S step, C callable) |
constructs a parallel-transform task | |
template<typename B , typename E , typename O , typename C > | |
Task | transform (B first1, E last1, O d_first, C c) |
constructs a parallel-transform task | |
template<typename B1 , typename E1 , typename B2 , typename O , typename C > | |
Task | transform (B1 first1, E1 last1, B2 first2, O d_first, C c) |
constructs a parallel-transform task | |
template<typename B , typename E , typename T , typename O > | |
Task | reduce (B first, E last, T &init, O bop) |
constructs a STL-styled parallel-reduce task | |
template<typename B , typename E , typename T , typename BOP , typename UOP > | |
Task | transform_reduce (B first, E last, T &init, BOP bop, UOP uop) |
constructs a STL-styled parallel transform-reduce task | |
template<typename B , typename E , typename C > | |
Task | sort (B first, E last, C cmp) |
constructs a dynamic task to perform STL-styled parallel sort | |
template<typename B , typename E > | |
Task | sort (B first, E last) |
constructs a dynamic task to perform STL-styled parallel sort using the std::less<T> comparator, where T is the element type | |
Protected Attributes | |
Graph & | _graph |
associated graph object | |
Friends | |
class | Executor |
class to build a task dependency graph
The class provides essential methods to construct a task dependency graph from which tf::Taskflow and tf::Subflow are derived.
Task tf::FlowBuilder::composed_of | ( | T & | object | ) |
creates a module task for the target object
T | target object type |
object | a custom object that defines the method T::graph() |
The example below demonstrates a taskflow composition using the composed_of
method.
The taskflow object t2
is composed of another taskflow object t1
, preceded by another static task init
. When taskflow t2
is submitted to an executor, init
will run first and then comp
which spwans its definition in taskflow t1
.
The target object
being composed must define the method T::graph()
that returns a reference to a graph object of type tf::Graph such that it can interact with the executor. For example:
Please refer to Composable Tasking for details.
auto tf::FlowBuilder::emplace | ( | C &&... | callables | ) |
creates multiple tasks from a list of callable objects
C | callable types |
callables | one or multiple callable objects constructible from each task category |
The method returns a tuple of tasks each corresponding to the given callable target. You can use structured binding to get the return tasks one by one. The following example creates four static tasks and assign them to A
, B
, C
, and D
using structured binding.
Task tf::FlowBuilder::emplace | ( | C && | callable | ) |
creates a static task
C | callable type constructible from std::function<void()> |
callable | callable to construct a static task |
The following example creates a static task.
Please refer to Static Tasking for details.
Task tf::FlowBuilder::emplace | ( | C && | callable | ) |
creates a dynamic task
C | callable type constructible from std::function<void(tf::Subflow&)> |
callable | callable to construct a dynamic task |
The following example creates a dynamic task (tf::Subflow) that spawns two static tasks.
Please refer to Dynamic Tasking for details.
Task tf::FlowBuilder::emplace | ( | C && | callable | ) |
creates a condition task
C | callable type constructible from std::function<int()> |
callable | callable to construct a condition task |
The following example creates an if-else block using one condition task and three static tasks.
Please refer to Conditional Tasking for details.
Task tf::FlowBuilder::emplace | ( | C && | callable | ) |
creates a multi-condition task
C | callable type constructible from std::function<tf::SmallVector<int>()> |
callable | callable to construct a multi-condition task |
The following example creates a multi-condition task that selectively jumps to two successor tasks.
Please refer to Conditional Tasking for details.
Task tf::FlowBuilder::emplace | ( | C && | callable | ) |
creates a cudaFlow task on the caller's GPU device context
C | callable type constructible from std::function<void(tf::cudaFlow&)> |
This method is equivalent to calling tf::FlowBuilder::emplace_on(callable, d) where d
is the caller's device context. The following example creates a cudaFlow of two kernel tasks, task1
and task2
, where task1
runs before task2
.
Please refer to GPU Tasking (cudaFlow) and GPU Tasking (cudaFlowCapturer) for details.
Task tf::FlowBuilder::emplace | ( | C && | callable | ) |
creates a syclFlow task on the default queue
C | callable type constructible from std::function<void(tf::syclFlow&)> |
callable | a callable that takes a referenced tf::syclFlow object |
The following example creates a syclFlow on the default queue to submit two kernel tasks, task1
and task2
, where task1
runs before task2
.
Task tf::FlowBuilder::emplace | ( | C && | callable | ) |
creates a runtime task
C | callable type constructible from std::function<void(tf::Runtime&)> |
callable | callable to construct a runtime task |
The following example creates a runtime task that enables in-task control over the running executor.
Please refer to Runtime Tasking for details.
Task tf::FlowBuilder::emplace_on | ( | C && | callable, |
D && | device | ||
) |
creates a cudaFlow task on the given device
C | callable type constructible from std::function<void(tf::cudaFlow&)> |
D | device type, either int or std::ref<int> (stateful) |
The following example creates a cudaFlow of two kernel tasks, task1
and task2
on GPU 2
, where task1
runs before task2
Task tf::FlowBuilder::emplace_on | ( | C && | callable, |
Q && | queue | ||
) |
creates a syclFlow task on the given queue
C | callable type constructible from std::function<void(tf::syclFlow&)> |
Q | queue type |
callable | a callable that takes a referenced tf::syclFlow object |
queue | a queue of type sycl::queue |
The following example creates a syclFlow on the given queue to submit two kernel tasks, task1
and task2
, where task1
runs before task2
.
|
inline |
removes a task from a taskflow
task | task to remove |
Removes a task and its input and output dependencies from the graph associated with the flow builder. If the task does not belong to the graph, nothing will happen.
Task tf::FlowBuilder::for_each | ( | B | first, |
E | last, | ||
C | callable | ||
) |
constructs a STL-styled parallel-for task
B | beginning iterator type |
E | ending iterator type |
C | callable type |
first | iterator to the beginning (inclusive) |
last | iterator to the end (exclusive) |
callable | a callable object to apply to the dereferenced iterator |
The task spawns a subflow that applies the callable object to each object obtained by dereferencing every iterator in the range [first, last)
. This method is equivalent to the parallel execution of the following loop:
Arguments templated to enable stateful range using std::reference_wrapper. The callable needs to take a single argument of the dereferenced iterator type.
Please refer to Parallel Iterations for details.
Task tf::FlowBuilder::for_each_index | ( | B | first, |
E | last, | ||
S | step, | ||
C | callable | ||
) |
constructs a parallel-transform task
B | beginning index type (must be integral) |
E | ending index type (must be integral) |
S | step type (must be integral) |
C | callable type |
first | index of the beginning (inclusive) |
last | index of the end (exclusive) |
step | step size |
callable | a callable object to apply to each valid index |
The task spawns a subflow that applies the callable object to each index in the range [first, last)
with the step size. This method is equivalent to the parallel execution of the following loop:
Arguments are templated to enable stateful range using std::reference_wrapper. The callable needs to take a single argument of the integral index type.
Please refer to Parallel Iterations for details.
|
inline |
adds adjacent dependency links to a linear list of tasks
tasks | an initializer list of tasks |
This member function creates linear dependencies over a list of tasks.
|
inline |
adds adjacent dependency links to a linear list of tasks
tasks | a vector of tasks |
This member function creates linear dependencies over a vector of tasks.
|
inline |
creates a placeholder task
A placeholder task maps to a node in the taskflow graph, but it does not have any callable work assigned yet. A placeholder task is different from an empty task handle that does not point to any node in a graph.
Task tf::FlowBuilder::reduce | ( | B | first, |
E | last, | ||
T & | init, | ||
O | bop | ||
) |
constructs a STL-styled parallel-reduce task
B | beginning iterator type |
E | ending iterator type |
T | result type |
O | binary reducer type |
first | iterator to the beginning (inclusive) |
last | iterator to the end (exclusive) |
init | initial value of the reduction and the storage for the reduced result |
bop | binary operator that will be applied |
The task spawns a subflow to perform parallel reduction over init
and the elements in the range [first, last)
. The reduced result is store in init
. This method is equivalent to the parallel execution of the following loop:
Arguments are templated to enable stateful range using std::reference_wrapper.
Please refer to Parallel Reduction for details.
Task tf::FlowBuilder::sort | ( | B | first, |
E | last | ||
) |
constructs a dynamic task to perform STL-styled parallel sort using the std::less<T>
comparator, where T
is the element type
B | beginning iterator type (random-accessible) |
E | ending iterator type (random-accessible) |
first | iterator to the beginning (inclusive) |
last | iterator to the end (exclusive) |
The task spawns a subflow to parallelly sort elements in the range [first, last)
using the std::less<T>
comparator, where T
is the dereferenced iterator type.
Arguments are templated to enable stateful range using std::reference_wrapper.
Please refer to Parallel Sort for details.
Task tf::FlowBuilder::sort | ( | B | first, |
E | last, | ||
C | cmp | ||
) |
constructs a dynamic task to perform STL-styled parallel sort
B | beginning iterator type (random-accessible) |
E | ending iterator type (random-accessible) |
C | comparator type |
first | iterator to the beginning (inclusive) |
last | iterator to the end (exclusive) |
cmp | comparison function object |
The task spawns a subflow to parallelly sort elements in the range [first, last)
.
Arguments are templated to enable stateful range using std::reference_wrapper.
Please refer to Parallel Sort for details.
Task tf::FlowBuilder::transform | ( | B | first1, |
E | last1, | ||
O | d_first, | ||
C | c | ||
) |
constructs a parallel-transform task
B | beginning input iterator type |
E | ending input iterator type |
O | output iterator type |
C | callable type |
first1 | iterator to the beginning of the first range |
last1 | iterator to the end of the first range |
d_first | iterator to the beginning of the output range |
c | an unary callable to apply to dereferenced input elements |
The task spawns a subflow that applies the callable object to an input range and stores the result in another output range. This method is equivalent to the parallel execution of the following loop:
Arguments are templated to enable stateful range using std::reference_wrapper. The callable needs to take a single argument of the dereferenced iterator type.
Task tf::FlowBuilder::transform | ( | B1 | first1, |
E1 | last1, | ||
B2 | first2, | ||
O | d_first, | ||
C | c | ||
) |
constructs a parallel-transform task
B1 | beginning input iterator type for the first input range |
E1 | ending input iterator type for the first input range |
B2 | beginning input iterator type for the first second range |
O | output iterator type |
C | callable type |
first1 | iterator to the beginning of the first input range |
last1 | iterator to the end of the first input range |
first2 | iterator to the beginning of the second input range |
d_first | iterator to the beginning of the output range |
c | a binary operator to apply to dereferenced input elements |
The task spawns a subflow that applies the callable object to two input ranges and stores the result in another output range. This method is equivalent to the parallel execution of the following loop:
Arguments are templated to enable stateful range using std::reference_wrapper. The callable needs to take two arguments of dereferenced elements from the two input ranges.
Task tf::FlowBuilder::transform_reduce | ( | B | first, |
E | last, | ||
T & | init, | ||
BOP | bop, | ||
UOP | uop | ||
) |
constructs a STL-styled parallel transform-reduce task
B | beginning iterator type |
E | ending iterator type |
T | result type |
BOP | binary reducer type |
UOP | unary transformion type |
first | iterator to the beginning (inclusive) |
last | iterator to the end (exclusive) |
init | initial value of the reduction and the storage for the reduced result |
bop | binary operator that will be applied in unspecified order to the results of uop |
uop | unary operator that will be applied to transform each element in the range to the result type |
The task spawns a subflow to perform parallel reduction over init
and the transformed elements in the range [first, last)
. The reduced result is store in init
. This method is equivalent to the parallel execution of the following loop:
Arguments are templated to enable stateful range using std::reference_wrapper.
Please refer to Parallel Reduction for details.