Loading...
Searching...
No Matches
tf::DataPipeline< Ps > Class Template Reference

class to create a data-parallel pipeline scheduling framework More...

#include <taskflow/algorithm/data_pipeline.hpp>

Public Types

using data_t
 internal storage type for each data token (default std::variant)
 

Public Member Functions

 DataPipeline (size_t num_lines, Ps &&... ps)
 constructs a data-parallel pipeline object
 
 DataPipeline (size_t num_lines, std::tuple< Ps... > &&ps)
 constructs a data-parallel pipeline object
 
size_t num_lines () const noexcept
 queries the number of parallel lines
 
constexpr size_t num_pipes () const noexcept
 queries the number of pipes
 
void reset ()
 resets the pipeline
 
size_t num_tokens () const noexcept
 queries the number of generated tokens in the pipeline
 
Graphgraph ()
 obtains the graph object associated with the pipeline construct
 

Detailed Description

template<typename... Ps>
class tf::DataPipeline< Ps >

class to create a data-parallel pipeline scheduling framework

Template Parameters
Psdata pipe types

Similar to tf::Pipeline, a tf::DataPipeline is a composable graph object for users to create a data-parallel pipeline scheduling framework using a module task in a taskflow. The only difference is that tf::DataPipeline provides a data abstraction for users to quickly express dataflow in a pipeline. The following example creates a data-parallel pipeline of three stages that generate dataflow from void to int, std::string, and void.

#include <taskflow/taskflow.hpp>
#include <taskflow/algorithm/data_pipeline.hpp>
int main() {
// data flow => void -> int -> std::string -> void
tf::Taskflow taskflow("pipeline");
tf::Executor executor;
const size_t num_lines = 4;
if(pf.token() == 5) {
pf.stop();
return 0;
}
else {
return pf.token();
}
}),
return std::to_string(input + 100);
}),
std::cout << input << std::endl;
})
);
// build the pipeline graph using composition
taskflow.composed_of(pl).name("pipeline");
// dump the pipeline graph structure (with composition)
taskflow.dump(std::cout);
// run the pipeline
executor.run(taskflow).wait();
return 0;
}
class to create a data-parallel pipeline scheduling framework
Definition data_pipeline.hpp:254
size_t num_lines() const noexcept
queries the number of parallel lines
Definition data_pipeline.hpp:428
class to create an executor
Definition executor.hpp:62
tf::Future< void > run(Taskflow &taskflow)
runs a taskflow once
class to create a pipeflow object used by the pipe callable
Definition pipeline.hpp:43
size_t token() const
queries the token identifier
Definition pipeline.hpp:78
void stop()
stops the pipeline scheduling
Definition pipeline.hpp:88
class to create a taskflow object
Definition taskflow.hpp:64
auto make_data_pipe(PipeType d, C &&callable)
function to construct a data pipe (tf::DataPipe)
Definition data_pipeline.hpp:171
@ SERIAL
serial type

The pipeline schedules five tokens over four parallel lines in a circular fashion, as depicted below:

o -> o -> o
| | |
v v v
o -> o -> o
| | |
v v v
o -> o -> o
| | |
v v v
o -> o -> o

Member Typedef Documentation

◆ data_t

template<typename... Ps>
using tf::DataPipeline< Ps >::data_t
Initial value:
unique_variant_t<std::variant<std::conditional_t<
std::is_void_v<typename Ps::output_t>,
std::monostate,
std::decay_t<typename Ps::output_t>>...
>>

internal storage type for each data token (default std::variant)

Constructor & Destructor Documentation

◆ DataPipeline() [1/2]

template<typename... Ps>
tf::DataPipeline< Ps >::DataPipeline ( size_t num_lines,
Ps &&... ps )

constructs a data-parallel pipeline object

Parameters
num_linesthe number of parallel lines
psa list of pipes

Constructs a data-parallel 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.

◆ DataPipeline() [2/2]

template<typename... Ps>
tf::DataPipeline< Ps >::DataPipeline ( size_t num_lines,
std::tuple< Ps... > && ps )

constructs a data-parallel pipeline object

Parameters
num_linesthe number of parallel lines
psa tuple of pipes

Constructs a data-parallel pipeline of up to num_lines parallel lines to schedule tokens through the given linear chain of pipes stored in a std::tuple. The first pipe must define a serial direction (tf::PipeType::SERIAL) or an exception will be thrown.

Member Function Documentation

◆ graph()

template<typename... Ps>
Graph & tf::DataPipeline< Ps >::graph ( )

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 this pipeline.

◆ num_lines()

template<typename... Ps>
size_t tf::DataPipeline< Ps >::num_lines ( ) const
noexcept

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.

◆ num_pipes()

template<typename... Ps>
size_t tf::DataPipeline< Ps >::num_pipes ( ) const
constexprnoexcept

queries the number of pipes

The Function returns the number of pipes given by the user upon the construction of the pipeline.

◆ num_tokens()

template<typename... Ps>
size_t tf::DataPipeline< Ps >::num_tokens ( ) const
noexcept

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.

◆ reset()

template<typename... Ps>
void tf::DataPipeline< Ps >::reset ( )

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.


The documentation for this class was generated from the following file: