23.08
|
A multi-input (tensors), multi-output (tensors) acyclic directed graph Represented as a doubly-linked adjacency list with the differentiation between source and destination. More...
#include <DependencyGraph.h>
Data Structures | |
struct | OpPack |
A pack of operator including its input and output tensors, used by traversing through the graph in topological order. More... | |
Public Types | |
using | Id = int32_t |
using | TensorId = Id |
using | OperatorId = Id |
using | AdjList = std::map< Id, std::vector< Id > > |
Adjacency list. More... | |
Public Member Functions | |
DependencyGraph ()=default | |
bool | try_add_operator_as_linear (OperatorId op, const std::vector< TensorId > &inputs, const std::vector< TensorId > &outputs, bool is_output=false) const |
Try adding an operator (without actually adding it), while keeping the graph as a "linear sequence" / list. More... | |
void | add_operator_as_linear (OperatorId op, const std::vector< TensorId > &inputs, const std::vector< TensorId > &outputs, bool is_output=false) |
Add an operator, while keeping the graph as a "linear sequence". More... | |
bool | add_operator (OperatorId op, const std::vector< TensorId > &inputs, const std::vector< TensorId > &outputs, bool is_output=false) |
Add a new operator Return invalid if it violates the DAG invariant Invalid operation will not change the graph. More... | |
std::vector< OpPack > | build_operators_sequence () const |
Build a sequence of operators from the acyclic graph of operators. More... | |
std::vector< OperatorId > | src_ops_from_tensor (TensorId tensor) const |
std::vector< OperatorId > | dst_ops_from_tensor (TensorId tensor) const |
std::vector< TensorId > | all_tensors () const |
Get all tensors. More... | |
std::vector< TensorId > | global_src_tensors () const |
Get source tensors of the whole graph. More... | |
std::vector< TensorId > | global_dst_tensors () const |
Get destination tensors of the whole graph. More... | |
std::vector< TensorId > | intermediate_tensors () const |
Get intermediate tensors of the whole graph. More... | |
std::vector< OperatorId > | get_root_ops () const |
Get all root ops. More... | |
Friends | |
std::ostream & | operator<< (std::ostream &os, const DependencyGraph &) |
bool | operator== (const DependencyGraph &g0, const DependencyGraph &g1) |
Strict equality comparison (all internal ids and order of insertion matter). More... | |
A multi-input (tensors), multi-output (tensors) acyclic directed graph Represented as a doubly-linked adjacency list with the differentiation between source and destination.
Definition at line 52 of file DependencyGraph.h.
Adjacency list.
Definition at line 61 of file DependencyGraph.h.
using Id = int32_t |
Definition at line 55 of file DependencyGraph.h.
using OperatorId = Id |
Definition at line 57 of file DependencyGraph.h.
Definition at line 56 of file DependencyGraph.h.
|
default |
|
inline |
Add a new operator Return invalid if it violates the DAG invariant Invalid operation will not change the graph.
[in] | op | Operator to add |
[in] | inputs | Input tensors to the operator |
[in] | outputs | Output tensors to the operator |
[in] | is_output | Whether this is an output operator |
Definition at line 186 of file DependencyGraph.h.
Referenced by GpuKernelComponentGraph::add_new_component(), and DependencyGraph::add_operator_as_linear().
|
inline |
Add an operator, while keeping the graph as a "linear sequence".
PRECONDITION: The current graph is already linear INVARIANT: The list can only grow from head to tail INVARIANT: POSTCONDITION: The graph is linear
Definition at line 171 of file DependencyGraph.h.
References DependencyGraph::add_operator(), ARM_COMPUTE_ERROR_ON, and ARM_COMPUTE_UNUSED.
Referenced by GpuOperatorGroup::add_operator().
|
inline |
Get all tensors.
Definition at line 280 of file DependencyGraph.h.
References arm_compute::mlgo::parser::end().
|
inline |
Build a sequence of operators from the acyclic graph of operators.
The graph will be visited in depth-first strategy. The operator can only be added to the sequence when all operators that supply the input tensors have been added. Otherwise, the operator will be ignored and later visited again. In other words, the dependency between operators will be preserved in the sequence.
Definition at line 230 of file DependencyGraph.h.
References DependencyGraph::global_src_tensors(), and tensor.
Referenced by GpuKernelComponentGraph::fuse().
|
inline |
Definition at line 272 of file DependencyGraph.h.
References tensor.
|
inline |
Get all root ops.
Root ops can also be referred to as "src ops" of the whole graph
Definition at line 352 of file DependencyGraph.h.
Referenced by GpuOperatorGroup::get_root_operator().
|
inline |
Get destination tensors of the whole graph.
Definition at line 309 of file DependencyGraph.h.
|
inline |
Get source tensors of the whole graph.
Definition at line 293 of file DependencyGraph.h.
Referenced by DependencyGraph::build_operators_sequence().
|
inline |
Get intermediate tensors of the whole graph.
Definition at line 325 of file DependencyGraph.h.
|
inline |
Definition at line 268 of file DependencyGraph.h.
References tensor.
|
inline |
Try adding an operator (without actually adding it), while keeping the graph as a "linear sequence" / list.
Rule: If the new operator is not the first operator, at least one input tensor must be the output tensor of the last non-output operator. All other input tensors must be the global input of the graph (i.e. not the output of any operator).
Rule: The output tensor of the new operator must not be the input tensor of any previously added operator.
PRECONDITION: The current graph is already linear
Definition at line 98 of file DependencyGraph.h.
References ARM_COMPUTE_ERROR_ON, and ARM_COMPUTE_UNUSED.
Referenced by GpuOperatorGroup::try_add_operator().
|
friend |
|
friend |
Strict equality comparison (all internal ids and order of insertion matter).
In the future this may be replaced with a topological comparison, allowing equivalent graphs with different internal ids to be equal
[in] | g0 | |
[in] | g1 |
Definition at line 260 of file DependencyGraph.h.