docs/classtf_1_1Pipeline.html
class to create a pipeline scheduling framework
| Template parameters |
|---|
| Ps |
A tf::Pipeline is a composable graph object that allows users to parallelize an application using pipeline parallelism. Unlike conventional pipeline programming frameworks (e.g., Intel TBB), tf::Pipeline does not provide any data abstraction but a task-parallel framework for users to customize their data layout when leveraging pipeline parallelism. The following code creates a pipeline with four parallel lines that schedule five tokens through three pipes of a serial-parallel-serial direction:
tf::Taskflow taskflow;tf::Executor executor;const size\_t num\_lines = 4;const size\_t num\_pipes = 3;// create a custom data bufferstd::array\<std::array\<int, num\_pipes\>, num\_lines\> buffer;// create a pipeline graph of four concurrent lines and three serial pipestf::Pipeline pipeline(num\_lines,// first pipe must define a serial directiontf::Pipe{tf::PipeType::SERIAL, [&buffer](tf::Pipeflow& pf) {// generate only 5 scheduling tokensif(pf.token() == 5) {pf.stop();}// save the token id into the bufferelse {buffer[pf.line()][pf.pipe()] = pf.token();}}},tf::Pipe{tf::PipeType::PARALLEL, [&buffer] (tf::Pipeflow& pf) {// propagate the previous result to this pipe by adding onebuffer[pf.line()][pf.pipe()] = buffer[pf.line()][pf.pipe()-1] + 1;}},tf::Pipe{tf::PipeType::SERIAL, [&buffer](tf::Pipeflow& pf){// propagate the previous result to this pipe by adding onebuffer[pf.line()][pf.pipe()] = buffer[pf.line()][pf.pipe()-1] + 1;}});// build the pipeline graph using compositiontf::Task init = taskflow.emplace([](){ std::cout \<\< "ready\n"; }).name("starting pipeline");tf::Task task = taskflow.composed\_of(pipeline).name("pipeline");tf::Task stop = taskflow.emplace([](){ std::cout \<\< "stopped\n"; }).name("pipeline stopped");// create task dependencyinit.precede(task);task.precede(stop);// run the pipelineexecutor.run(taskflow).wait();
The five tokens will be scheduled across four parallel lines in a circular fashion, as depicted below:
Taskflowcluster0line 0cluster1line 1cluster2line 2cluster3line 3p00pipe-0p10pipe-0p00->p10p01pipe-1p00->p01p20pipe-0p10->p20p11pipe-1p10->p11p30pipe-0p20->p30p21pipe-1p20->p21p31pipe-1p30->p31p02pipe-2p01->p02p12pipe-2p11->p12p22pipe-2p21->p22p32pipe-2p31->p32p02->p12p12->p22p22->p32
At each pipe stage, the program propagates the result to the next pipe by adding one to the result stored in a custom data storage, buffer. The pipeline scheduler will generate five scheduling tokens and then stop.
Internally, tf::Pipeline uses std::tuple to store the given sequence of pipes. The definition of each pipe can be different, completely decided by the compiler to optimize the object layout. After a pipeline is constructed, it is not possible to change its pipes. If applications need to change these pipes, please use tf::ScalablePipeline.
Pipeline(size_t num_lines, Ps && ... ps)constructs a pipeline objectPipeline(size_t num_lines, std::tuple<Ps...>&& ps)constructs a pipeline object
auto num_lines() const -> size_t noexceptqueries the number of parallel linesauto num_pipes() const -> size_t constexprqueries the number of pipesvoid reset()resets the pipelineauto num_tokens() const -> size_t noexceptqueries the number of generated tokens in the pipelineauto graph() -> Graph&obtains the graph object associated with the pipeline construct
constructs a pipeline object
| Parameters |
|---|
| num_lines |
| ps |
Constructs a pipeline of up to num_lines parallel lines to schedule tokens through the given linear chain of pipes. The first pipe must define a serial direction (tf::PipeType::SERIAL) or an exception will be thrown.
constructs a pipeline object
| Parameters |
|---|
| num_lines |
| ps |
Constructs a pipeline of up to num_lines parallel lines to schedule tokens through the given linear chain of pipes. The first pipe must define a serial direction (tf::PipeType::SERIAL) or an exception will be thrown.
queries the number of parallel lines
The function returns the number of parallel lines given by the user upon the construction of the pipeline. The number of lines represents the maximum parallelism this pipeline can achieve.
queries the number of pipes
The Function returns the number of pipes given by the user upon the construction of the pipeline.
resets the pipeline
Resetting the pipeline to the initial state. After resetting a pipeline, its token identifier will start from zero as if the pipeline was just constructed.
queries the number of generated tokens in the pipeline
The number represents the total scheduling tokens that has been generated by the pipeline so far.
obtains the graph object associated with the pipeline construct
This method is primarily used as an opaque data structure for creating a module task of the this pipeline.