HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
onnxruntime::Graph Class Reference

#include <graph.h>

Classes

struct  ResolveOptions
 

Public Member Functions

const std::stringName () const noexcept
 
const std::stringDescription () const noexcept
 
const Path & ModelPath () const
 
bool IsSubgraph () const
 
const GraphParentGraph () const
 
GraphMutableParentGraph ()
 
bool StrictShapeTypeInference () const
 
void SetName (const std::string &name)
 
void SetDescription (const std::string &description)
 
common::Status ReplaceInitializedTensor (ONNX_NAMESPACE::TensorProto new_initializer)
 
common::Status InjectExternalInitializedTensors (const InlinedHashMap< std::string, OrtValue > &external_initializers)
 
void AddInitializedTensor (const ONNX_NAMESPACE::TensorProto &tensor_proto)
 
void RemoveInitializedTensor (const std::string &tensor_name)
 
bool IsInitializedTensor (const std::string &name) const
 
bool IsSparseInitializer (const std::string &name) const
 
bool GetInitializedTensor (const std::string &tensor_name, const ONNX_NAMESPACE::TensorProto *&value) const
 
const InitializedTensorSetGetAllInitializedTensors () const noexcept
 
void CleanAllInitializedTensors () noexcept
 
bool CanOverrideInitializer () const noexcept
 
const ONNX_NAMESPACE::TensorProto * GetConstantInitializer (const std::string &name, bool check_outer_scope) const
 
const ONNX_NAMESPACE::TensorProto * GetInitializer (const std::string &name, bool check_outer_scope) const
 
const std::vector< const
NodeArg * > & 
GetInputs () const noexcept
 
const std::vector< const
NodeArg * > & 
GetInputsIncludingInitializers () const noexcept
 
bool IsInputsIncludingInitializers (const NodeArg *node_arg) const noexcept
 
const std::vector< const
NodeArg * > & 
GetOverridableInitializers () const
 
const std::vector< const
NodeArg * > & 
GetOutputs () const noexcept
 
bool IsOutput (const NodeArg *node_arg) const noexcept
 
bool NodeProducesGraphOutput (const Node &node) const
 
std::vector< intGetNodeOutputsInGraphOutputs (const Node &node) const
 
const std::unordered_set
< const NodeArg * > & 
GetValueInfo () const noexcept
 
void AddValueInfo (const NodeArg *new_value_info)
 
const NodeGetNode (NodeIndex node_index) const
 
NodeGetNode (NodeIndex node_index)
 
GraphNodesNodes () noexcept
 
const GraphNodesNodes () const noexcept
 
ConstGraphNodes FilteredNodes (GraphNodes::NodeFilterFunc &&filter_func) const noexcept
 
int MaxNodeIndex () const noexcept
 
int NumberOfNodes () const noexcept
 
NodeArgGetNodeArg (const std::string &name)
 
const NodeArgGetNodeArg (const std::string &name) const
 
NodeArgGetNodeArgIncludingParentGraphs (const std::string &node_arg_name)
 
NodeArgGetOrCreateNodeArg (const std::string &name, const ONNX_NAMESPACE::TypeProto *p_arg_type)
 
std::string GenerateNodeArgName (const std::string &base_name)
 
std::string GenerateNodeName (const std::string &base_name)
 
NodeAddNode (const Node &other)
 
NodeAddNode (const std::string &name, const std::string &op_type, const std::string &description, gsl::span< NodeArg *const > input_args, gsl::span< NodeArg *const > output_args, const NodeAttributes *attributes=nullptr, const std::string &domain=kOnnxDomain)
 
NodeAddNode (const std::string &name, const std::string &op_type, const std::string &description, std::initializer_list< NodeArg * > input_args, std::initializer_list< NodeArg * > output_args, const NodeAttributes *attributes=nullptr, const std::string &domain=kOnnxDomain)
 
NodeAddNode (const std::string &name, const std::string &op_type, const std::string &description, gsl::span< NodeArg *const > input_args, std::initializer_list< NodeArg * > output_args, const NodeAttributes *attributes=nullptr, const std::string &domain=kOnnxDomain)
 
NodeAddNode (const std::string &name, const std::string &op_type, const std::string &description, std::initializer_list< NodeArg * > input_args, gsl::span< NodeArg *const > output_args, const NodeAttributes *attributes=nullptr, const std::string &domain=kOnnxDomain)
 
bool RemoveNode (NodeIndex node_index)
 
void AddEdge (NodeIndex src_node_index, NodeIndex dst_node_index, int src_arg_index, int dst_arg_index)
 
void RemoveEdge (NodeIndex src_node_index, NodeIndex dst_node_index, int src_arg_index, int dst_arg_index)
 
bool AddControlEdge (NodeIndex src_node_index, NodeIndex dst_node_index)
 
GraphSetGraphResolveNeeded () noexcept
 
bool GraphResolveNeeded () const noexcept
 
GraphSetGraphProtoSyncNeeded () noexcept
 
bool GraphProtoSyncNeeded () const noexcept
 
void ReverseDFSFrom (gsl::span< NodeIndex const > from, const std::function< void(const Node *)> &enter, const std::function< void(const Node *)> &leave, const std::function< bool(const Node *, const Node *)> &comp={}) const
 
void ReverseDFSFrom (gsl::span< const Node *const > from, const std::function< void(const Node *)> &enter, const std::function< void(const Node *)> &leave, const std::function< bool(const Node *, const Node *)> &comp={}) const
 
void ReverseDFSFrom (gsl::span< const Node *const > from, const std::function< void(const Node *)> &enter, const std::function< void(const Node *)> &leave, const std::function< bool(const Node *, const Node *)> &comp, const std::function< bool(const Node *, const Node *)> &stop) const
 
void KahnsTopologicalSort (const std::function< void(const Node *)> &enter, const std::function< bool(const Node *, const Node *)> &comp) const
 
const std::unordered_map
< std::string, int > & 
DomainToVersionMap () const noexcept
 
NodeBeginFuseSubGraph (const IndexedSubGraph &sub_graph, const std::string &fused_node_name)
 
void FinalizeFuseSubGraph (const IndexedSubGraph &sub_graph, Node &fused_node)
 
const ONNX_NAMESPACE::GraphProto & ToGraphProto ()
 
ONNX_NAMESPACE::GraphProto ToGraphProto () const
 
ONNX_NAMESPACE::GraphProto ToGraphProtoWithExternalInitializers (const std::string &external_file_name, size_t initializer_size_threshold) const
 
IOnnxRuntimeOpSchemaCollectionPtr GetSchemaRegistry () const
 
bool SetOpSchemaFromRegistryForNode (Node &node)
 
NodeFuseSubGraph (const IndexedSubGraph &sub_graph, const std::string &fused_node_name)
 
Status InlineFunction (Node &node)
 
void AddOuterScopeNodeArg (const std::string &name)
 
void SetInputs (gsl::span< const NodeArg *const > inputs)
 
void SetInputs (std::initializer_list< const NodeArg * > inputs)
 
const ModelGetModel () const
 
const logging::LoggerGetLogger () const
 
void SetOutputs (gsl::span< const NodeArg *const > outputs)
 
void SetOutputs (std::initializer_list< const NodeArg * > outputs)
 
void SetNodeArgType (NodeArg &arg, const ONNX_NAMESPACE::TypeProto &type_proto)
 
const NodeGetProducerNode (const std::string &node_arg_name) const
 
NodeGetMutableProducerNode (const std::string &node_arg_name)
 
void UpdateProducerNode (const std::string &node_arg_name, NodeIndex node_index)
 
std::vector< const Node * > GetConsumerNodes (const std::string &node_arg_name) const
 
void AddConsumerNode (const std::string &node_arg_name, Node *consumer)
 
void RemoveConsumerNode (const std::string &node_arg_name, Node *consumer)
 
std::vector< Node * > GetMutableConsumerNodes (const std::string &node_arg_name)
 
void UpdateConsumerNodes (const std::string &node_arg_name, gsl::span< Node *const > nodes)
 
void UpdateConsumerNodes (const std::string &node_arg_name, std::initializer_list< Node * > nodes)
 
Status UpdateShapeInference (Node &node)
 
common::Status Resolve (const ResolveOptions &options)
 
common::Status Resolve ()
 
const std::unordered_set
< std::string > & 
GetOuterScopeNodeArgNames () const noexcept
 
common::Status SaveToOrtFormat (flatbuffers::FlatBufferBuilder &builder, flatbuffers::Offset< onnxruntime::fbs::Graph > &fbs_graph) const
 
const NodeParentNode () const
 
bool IsOuterScopeValue (const std::string &name) const
 
 Graph (Graph &parent_graph, const Node &parent_node, ONNX_NAMESPACE::GraphProto &subgraph_proto)
 
 Graph (const Model &owning_model, IOnnxRuntimeOpSchemaCollectionPtr schema_registry, ONNX_NAMESPACE::GraphProto &subgraph_proto, const std::unordered_map< std::string, int > &domain_version_map, const logging::Logger &logger, bool strict_shape_type_inference)
 
virtual ~Graph ()
 
const
RuntimeOptimizationRecordContainer & 
RuntimeOptimizations () const
 
RuntimeOptimizationRecordContainer & MutableRuntimeOptimizations ()
 
 Graph ()=delete
 
 Graph (const Model &owning_model, const std::unordered_map< std::string, int > &domain_to_version, IOnnxRuntimeOpSchemaCollectionPtr schema_registry, Graph *parent_graph, const Node *parent_node, const logging::Logger &logger, bool strict_shape_type_inference)
 
Status LoadFromOrtFormat (const onnxruntime::fbs::Graph &fbs_graph, const OrtFormatLoadOptions &load_options)
 
 Graph (const Model &owning_model, ONNX_NAMESPACE::GraphProto *graph_proto, const std::unordered_map< std::string, int > &domain_to_version, Version ir_version, IOnnxRuntimeOpSchemaCollectionPtr schema_registry, const logging::Logger &logger, bool strict_shape_type_inference)
 
 Graph (const Model &owning_model, ONNX_NAMESPACE::GraphProto *graph_proto, const std::unordered_map< std::string, int > &domain_to_version, Version ir_version, IOnnxRuntimeOpSchemaCollectionPtr schema_registry, Graph *parent_graph, const Node *parent_node, const logging::Logger &logger, bool strict_shape_type_inference)
 
 ORT_DISALLOW_COPY_ASSIGNMENT_AND_MOVE (Graph)
 

Static Public Member Functions

static Status LoadFromOrtFormat (const onnxruntime::fbs::Graph &fbs_graph, const Model &owning_model, const std::unordered_map< std::string, int > &domain_to_version, IOnnxRuntimeOpSchemaCollectionPtr schema_registry, const OrtFormatLoadOptions &load_options, const logging::Logger &logger, std::unique_ptr< Graph > &graph)
 
static Status LoadFromOrtFormat (const onnxruntime::fbs::Graph &fbs_graph, Graph &parent_graph, const Node &parent_node, const OrtFormatLoadOptions &load_options, const logging::Logger &logger, std::unique_ptr< Graph > &graph)
 

Friends

class Model
 

Detailed Description

The Graph representation containing the graph inputs and outputs, the Node instances, and the edges connecting the nodes.

Definition at line 659 of file graph.h.

Constructor & Destructor Documentation

onnxruntime::Graph::Graph ( Graph parent_graph,
const Node parent_node,
ONNX_NAMESPACE::GraphProto &  subgraph_proto 
)

Construct a Graph instance for a subgraph that is created from a GraphProto attribute in a Node. Inherits some properties from the parent graph.

Parameters
parent_graphThe Graph containing the Node that has the GraphProto attribute.
parent_nodeThe Node that has the GraphProto attribute.
subgraph_protoThe GraphProto from the Node attribute.
onnxruntime::Graph::Graph ( const Model owning_model,
IOnnxRuntimeOpSchemaCollectionPtr  schema_registry,
ONNX_NAMESPACE::GraphProto &  subgraph_proto,
const std::unordered_map< std::string, int > &  domain_version_map,
const logging::Logger logger,
bool  strict_shape_type_inference 
)
virtual onnxruntime::Graph::~Graph ( )
virtual
onnxruntime::Graph::Graph ( )
delete
onnxruntime::Graph::Graph ( const Model owning_model,
const std::unordered_map< std::string, int > &  domain_to_version,
IOnnxRuntimeOpSchemaCollectionPtr  schema_registry,
Graph parent_graph,
const Node parent_node,
const logging::Logger logger,
bool  strict_shape_type_inference 
)
onnxruntime::Graph::Graph ( const Model owning_model,
ONNX_NAMESPACE::GraphProto *  graph_proto,
const std::unordered_map< std::string, int > &  domain_to_version,
Version  ir_version,
IOnnxRuntimeOpSchemaCollectionPtr  schema_registry,
const logging::Logger logger,
bool  strict_shape_type_inference 
)
onnxruntime::Graph::Graph ( const Model owning_model,
ONNX_NAMESPACE::GraphProto *  graph_proto,
const std::unordered_map< std::string, int > &  domain_to_version,
Version  ir_version,
IOnnxRuntimeOpSchemaCollectionPtr  schema_registry,
Graph parent_graph,
const Node parent_node,
const logging::Logger logger,
bool  strict_shape_type_inference 
)

Member Function Documentation

void onnxruntime::Graph::AddConsumerNode ( const std::string node_arg_name,
Node consumer 
)
inline

Definition at line 1208 of file graph.h.

bool onnxruntime::Graph::AddControlEdge ( NodeIndex  src_node_index,
NodeIndex  dst_node_index 
)

Add a control edge between two Nodes in this Graph. The source Node does not produce output that is directly consumed by the destination Node, however the destination Node must execute after the source node. The control edge allows this ordering to occur.

void onnxruntime::Graph::AddEdge ( NodeIndex  src_node_index,
NodeIndex  dst_node_index,
int  src_arg_index,
int  dst_arg_index 
)

Add an edge between two Nodes.

Parameters
src_node_indexNodeIndex of source Node that is providing output to the destination Node.
dst_node_indexNodeIndex of destination Node that is receiving input from the source Node.
src_arg_indexnode arg index of source node.
dst_arg_indexnode arg index of destination node.
void onnxruntime::Graph::AddInitializedTensor ( const ONNX_NAMESPACE::TensorProto &  tensor_proto)

Add an initializer tensor to the Graph.

Node& onnxruntime::Graph::AddNode ( const Node other)

Copy a Node and add it to this Graph.

Parameters
otherNode to copy
Returns
Reference to the Node that was created and added to this Graph.
Remarks
Do not call AddNode and Remove Node concurrently as they are not thread-safe.
Node& onnxruntime::Graph::AddNode ( const std::string name,
const std::string op_type,
const std::string description,
gsl::span< NodeArg *const input_args,
gsl::span< NodeArg *const output_args,
const NodeAttributes attributes = nullptr,
const std::string domain = kOnnxDomain 
)

Add a Node to this Graph.

Parameters
nameThe Node name. Must be unique in this Graph.
op_typeThe operator type. e.g. ONNX operator name.
descriptionArbitrary description of the Node.
input_argsThe explicit inputs to this Node.
output_argsThe outputs from this Node.
attributesOptional NodeAttributes to add.
domainThe domain for the op_type.
Returns
Reference to the new Node.
Remarks
Do not call AddNode and Remove Node concurrently as they are not thread-safe.
Node& onnxruntime::Graph::AddNode ( const std::string name,
const std::string op_type,
const std::string description,
std::initializer_list< NodeArg * >  input_args,
std::initializer_list< NodeArg * >  output_args,
const NodeAttributes attributes = nullptr,
const std::string domain = kOnnxDomain 
)
inline

Definition at line 932 of file graph.h.

Node& onnxruntime::Graph::AddNode ( const std::string name,
const std::string op_type,
const std::string description,
gsl::span< NodeArg *const input_args,
std::initializer_list< NodeArg * >  output_args,
const NodeAttributes attributes = nullptr,
const std::string domain = kOnnxDomain 
)
inline

Definition at line 945 of file graph.h.

Node& onnxruntime::Graph::AddNode ( const std::string name,
const std::string op_type,
const std::string description,
std::initializer_list< NodeArg * >  input_args,
gsl::span< NodeArg *const output_args,
const NodeAttributes attributes = nullptr,
const std::string domain = kOnnxDomain 
)
inline

Definition at line 958 of file graph.h.

void onnxruntime::Graph::AddOuterScopeNodeArg ( const std::string name)
inline

Mark a NodeArg name as coming from the outer scope when programmatically constructing a Graph that will be used as a GraphProto attribute in another Node.. e.g. when creating a Graph instance that will be used as a subgraph in a control flow operator, it is necessary to define placeholder NodeArgs for outer scope values. This prevents these values from becoming explicit graph inputs when the Graph is resolved.

Definition at line 1147 of file graph.h.

void onnxruntime::Graph::AddValueInfo ( const NodeArg new_value_info)
Node& onnxruntime::Graph::BeginFuseSubGraph ( const IndexedSubGraph sub_graph,
const std::string fused_node_name 
)

Create a single Node that will be the result of the a fusion of multiple nodes in this Graph.

Parameters
sub_graphA IndexSubGraph instance with details of the nodes to fuse.
fused_node_nameThe name for the new Node.
Returns
Node with fused subgraph.
Remarks
As a new Graph instance for the fused nodes is not created, a GraphViewer can be constructed with the IndexedSubGraph information to provide a view of the subgraph. The original nodes are left in place while this is in use. Call FinalizeFuseSubGraph to remove them once the fused replacement node is fully created.
bool onnxruntime::Graph::CanOverrideInitializer ( ) const
inlinenoexcept

Returns true if an initializer value can be overridden by a graph input with the same name.

Definition at line 738 of file graph.h.

void onnxruntime::Graph::CleanAllInitializedTensors ( )
noexcept

Removes all initializer tensors from this Graph and releases the memory they were using.

const std::string& onnxruntime::Graph::Description ( ) const
noexcept

Gets the Graph description.

const std::unordered_map<std::string, int>& onnxruntime::Graph::DomainToVersionMap ( ) const
inlinenoexcept

Gets the map of operator domains to their opset versions.

Definition at line 1081 of file graph.h.

ConstGraphNodes onnxruntime::Graph::FilteredNodes ( GraphNodes::NodeFilterFunc &&  filter_func) const
inlinenoexcept

Get a ConstGraphNodes instance that provides access to a filtered set of valid Nodes in the Graph.

Remarks
We can't use GraphNodes as that would provide mutable access to the nodes by default, and we can't prevent that by returning a const instance of GraphNodes as we're creating a new instance here due to the filter being something we don't control (i.e. we have to return a new instance so it can't be const).

Definition at line 848 of file graph.h.

void onnxruntime::Graph::FinalizeFuseSubGraph ( const IndexedSubGraph sub_graph,
Node fused_node 
)
Node& onnxruntime::Graph::FuseSubGraph ( const IndexedSubGraph sub_graph,
const std::string fused_node_name 
)

Create a single Function based Node that is the result of the a fusion of multiple nodes in this Graph. A new Graph instance will be created for the fused nodes.

Parameters
sub_graphA IndexSubGraph instance with details of the nodes to fuse. Ownership is transferred to the new Node
fused_node_nameThe name for the new Node.
Returns
Function based Node with fused subgraph. The Node body will contain a Function instance.
std::string onnxruntime::Graph::GenerateNodeArgName ( const std::string base_name)

Generate a unique name in this Graph for a NodeArg

std::string onnxruntime::Graph::GenerateNodeName ( const std::string base_name)

Generate a unique name in this Graph for a Node

const InitializedTensorSet& onnxruntime::Graph::GetAllInitializedTensors ( ) const
inlinenoexcept

Gets all the initializer tensors in this Graph.

Definition at line 732 of file graph.h.

const ONNX_NAMESPACE::TensorProto* onnxruntime::Graph::GetConstantInitializer ( const std::string name,
bool  check_outer_scope 
) const

returns the initializer's TensorProto if 'name' is an initializer, is constant and cannot be overridden at runtime. If the initializer is not found or is not constant, a nullptr is returned.

Parameters
check_outer_scopeIf true and the graph is a subgraph, check ancestor graph/s for 'name' if not found in 'graph'.
Remarks
check_outer_scope of true is not supported in a minimal build
std::vector<const Node*> onnxruntime::Graph::GetConsumerNodes ( const std::string node_arg_name) const
inline

Definition at line 1203 of file graph.h.

bool onnxruntime::Graph::GetInitializedTensor ( const std::string tensor_name,
const ONNX_NAMESPACE::TensorProto *&  value 
) const

Gets an initializer tensor with the provided name.

Parameters
[out]valueSet to the TensorProto* if the initializer is found, or nullptr if not.
Returns
True if found.
const ONNX_NAMESPACE::TensorProto* onnxruntime::Graph::GetInitializer ( const std::string name,
bool  check_outer_scope 
) const

returns the initializer's TensorProto if 'name' is an initializer (both constant and overridable). If the initializer is not found, a nullptr is returned.

Parameters
check_outer_scopeIf true and the graph is a subgraph, check ancestor graph/s for 'name' if not found in 'graph'.
Remarks
check_outer_scope of true is not supported in a minimal build
const std::vector<const NodeArg*>& onnxruntime::Graph::GetInputs ( ) const
inlinenoexcept

Gets the Graph inputs excluding initializers. These are the required inputs to the Graph as the initializers can be optionally overridden via graph inputs.

Remarks
Contains no nullptr values.

Definition at line 759 of file graph.h.

const std::vector<const NodeArg*>& onnxruntime::Graph::GetInputsIncludingInitializers ( ) const
inlinenoexcept

Gets the Graph inputs including initializers. This is the full set of inputs, in the same order as defined in the GraphProto.

Remarks
Contains no nullptr values.

Definition at line 764 of file graph.h.

const logging::Logger& onnxruntime::Graph::GetLogger ( ) const
inline

Definition at line 1165 of file graph.h.

const Model& onnxruntime::Graph::GetModel ( ) const
inline

Definition at line 1161 of file graph.h.

std::vector<Node*> onnxruntime::Graph::GetMutableConsumerNodes ( const std::string node_arg_name)
inline

Definition at line 1219 of file graph.h.

Node* onnxruntime::Graph::GetMutableProducerNode ( const std::string node_arg_name)
inline

Definition at line 1189 of file graph.h.

const Node* onnxruntime::Graph::GetNode ( NodeIndex  node_index) const
inline

Gets the Node with the specified node index.

Returns
Node instance if found. nullptr if node_index is invalid or node has been freed.

Definition at line 830 of file graph.h.

Node* onnxruntime::Graph::GetNode ( NodeIndex  node_index)
inline

Gets the mutable Node with the specified node index.

Returns
Mutable Node instance if found. nullptr if node_index is invalid or node has been freed.

Definition at line 835 of file graph.h.

NodeArg* onnxruntime::Graph::GetNodeArg ( const std::string name)
inline

Gets the mutable NodeArg with the provided name.

Returns
Pointer to NodeArg if found, nullptr if not.

Definition at line 864 of file graph.h.

const NodeArg* onnxruntime::Graph::GetNodeArg ( const std::string name) const
inline

Gets the const NodeArg with the provided name.

Returns
Pointer to const NodeArg if found, nullptr if not.

Definition at line 874 of file graph.h.

NodeArg* onnxruntime::Graph::GetNodeArgIncludingParentGraphs ( const std::string node_arg_name)
std::vector<int> onnxruntime::Graph::GetNodeOutputsInGraphOutputs ( const Node node) const
inline

Returns a vector with the indexes of the outputs of the given Node that are also Graph outputs.

Definition at line 804 of file graph.h.

NodeArg& onnxruntime::Graph::GetOrCreateNodeArg ( const std::string name,
const ONNX_NAMESPACE::TypeProto *  p_arg_type 
)
inline

Gets a mutable NodeArg by name. Creates a new NodeArg that is owned by this Graph if not found.

Parameters
nameThe NodeArg name.
[in]p_arg_typeOptional TypeProto to use if the NodeArg needs to be created.
Returns
NodeArg reference.

Definition at line 886 of file graph.h.

const std::unordered_set<std::string>& onnxruntime::Graph::GetOuterScopeNodeArgNames ( ) const
inlinenoexcept

Definition at line 1275 of file graph.h.

const std::vector<const NodeArg*>& onnxruntime::Graph::GetOutputs ( ) const
inlinenoexcept

Gets the Graph outputs.

Remarks
Contains no nullptr values.

Definition at line 784 of file graph.h.

const std::vector<const NodeArg*>& onnxruntime::Graph::GetOverridableInitializers ( ) const
inline

Gets the Graph inputs that are initializers These are overridable initializers. This is a difference between graph_inputs_including_initializers_ and graph_inputs_excluding_initializers_

Remarks
Contains no nullptr values.

Definition at line 778 of file graph.h.

const Node* onnxruntime::Graph::GetProducerNode ( const std::string node_arg_name) const
inline

Definition at line 1185 of file graph.h.

IOnnxRuntimeOpSchemaCollectionPtr onnxruntime::Graph::GetSchemaRegistry ( ) const

Gets the ISchemaRegistry instances being used with this Graph.

const std::unordered_set<const NodeArg*>& onnxruntime::Graph::GetValueInfo ( ) const
inlinenoexcept

Gets the NodeArgs that represent value_info instances in the Graph. These are the values that are neither Graph inputs nor outputs.

Remarks
Contains no nullptr values.

Definition at line 821 of file graph.h.

bool onnxruntime::Graph::GraphProtoSyncNeeded ( ) const
inlinenoexcept

Gets flag indicating whether Graph::graph_proto_ needs to be synchronized with this Graph instance.

Definition at line 1028 of file graph.h.

bool onnxruntime::Graph::GraphResolveNeeded ( ) const
inlinenoexcept

Gets flag indicating whether Graph::Resolve needs to be called before using the Graph.

Definition at line 1017 of file graph.h.

common::Status onnxruntime::Graph::InjectExternalInitializedTensors ( const InlinedHashMap< std::string, OrtValue > &  external_initializers)

This function takes externally provided data for initializers with external data and replaces graph initializers with its content.

Status onnxruntime::Graph::InlineFunction ( Node node)

Directly insert the nodes in the function Node provided into this Graph.

Parameters
nodeNode with Node::Type of Node::Type::Fused
Returns
Status indicating success or providing an error message.
bool onnxruntime::Graph::IsInitializedTensor ( const std::string name) const

Check if a given name is an initializer tensor's name in this graph.

bool onnxruntime::Graph::IsInputsIncludingInitializers ( const NodeArg node_arg) const
inlinenoexcept

Return true if "node_arg" is a input or an initializer. Otherwise, returns false.

Definition at line 769 of file graph.h.

bool onnxruntime::Graph::IsOuterScopeValue ( const std::string name) const
inline

Returns true if the name is for a value that is coming from outer scope

Definition at line 1288 of file graph.h.

bool onnxruntime::Graph::IsOutput ( const NodeArg node_arg) const
inlinenoexcept

Definition at line 786 of file graph.h.

bool onnxruntime::Graph::IsSparseInitializer ( const std::string name) const

Check if a given name is a sparse initializer's name in the model we currently convert sparse_initializer field in the model into dense Tensor instances. However, we sometimes want to check if this initializer was stored as sparse in the model.

bool onnxruntime::Graph::IsSubgraph ( ) const
inline

Returns true if this is a subgraph or false if it is a high-level graph.

Definition at line 671 of file graph.h.

void onnxruntime::Graph::KahnsTopologicalSort ( const std::function< void(const Node *)> &  enter,
const std::function< bool(const Node *, const Node *)> &  comp 
) const

Performs topological sort with Kahn's algorithm on the graph/s.

Parameters
enterVisit function that will be invoked on a node when it is visited.
compComparison function to stabilize the traversal order by making Node ordering deterministic.
static Status onnxruntime::Graph::LoadFromOrtFormat ( const onnxruntime::fbs::Graph &  fbs_graph,
const Model owning_model,
const std::unordered_map< std::string, int > &  domain_to_version,
IOnnxRuntimeOpSchemaCollectionPtr  schema_registry,
const OrtFormatLoadOptions &  load_options,
const logging::Logger logger,
std::unique_ptr< Graph > &  graph 
)
static
static Status onnxruntime::Graph::LoadFromOrtFormat ( const onnxruntime::fbs::Graph &  fbs_graph,
Graph parent_graph,
const Node parent_node,
const OrtFormatLoadOptions &  load_options,
const logging::Logger logger,
std::unique_ptr< Graph > &  graph 
)
static
Status onnxruntime::Graph::LoadFromOrtFormat ( const onnxruntime::fbs::Graph &  fbs_graph,
const OrtFormatLoadOptions &  load_options 
)
int onnxruntime::Graph::MaxNodeIndex ( ) const
inlinenoexcept

Gets the maximum NodeIndex value used in the Graph. WARNING: This actually returns the max index value used + 1.

Definition at line 855 of file graph.h.

const Path& onnxruntime::Graph::ModelPath ( ) const

Gets the path of the owning model, if any.

Graph* onnxruntime::Graph::MutableParentGraph ( )
inline

Returns the mutable parent graph if this is a subgraph

Definition at line 677 of file graph.h.

RuntimeOptimizationRecordContainer& onnxruntime::Graph::MutableRuntimeOptimizations ( )
inline

Definition at line 1335 of file graph.h.

const std::string& onnxruntime::Graph::Name ( ) const
noexcept

Gets the Graph name.

bool onnxruntime::Graph::NodeProducesGraphOutput ( const Node node) const
inline

Returns true if one or more of the Node outputs are Graph outputs.

Remarks
Cheaper than calling GetNodeOutputsInGraphOutputs.

Definition at line 793 of file graph.h.

GraphNodes& onnxruntime::Graph::Nodes ( )
inlinenoexcept

Get a GraphNodes instance that provides mutable access to all valid Nodes in the Graph.

Definition at line 838 of file graph.h.

const GraphNodes& onnxruntime::Graph::Nodes ( ) const
inlinenoexcept

Get a GraphNodes instance that provides const access to all valid Nodes in the Graph.

Definition at line 841 of file graph.h.

int onnxruntime::Graph::NumberOfNodes ( ) const
inlinenoexcept

Gets the number of valid Nodes in the Graph.

Remarks
This may be smaller than MaxNodeIndex(), as Nodes may be removed during optimization.

Definition at line 860 of file graph.h.

onnxruntime::Graph::ORT_DISALLOW_COPY_ASSIGNMENT_AND_MOVE ( Graph  )
const Graph* onnxruntime::Graph::ParentGraph ( ) const
inline

Returns the parent graph if this is a subgraph

Definition at line 674 of file graph.h.

const Node* onnxruntime::Graph::ParentNode ( ) const
inline

Returns the Node containing the GraphProto for this Graph instance if IsSubgraph is true

Definition at line 1285 of file graph.h.

void onnxruntime::Graph::RemoveConsumerNode ( const std::string node_arg_name,
Node consumer 
)
inline

Definition at line 1213 of file graph.h.

void onnxruntime::Graph::RemoveEdge ( NodeIndex  src_node_index,
NodeIndex  dst_node_index,
int  src_arg_index,
int  dst_arg_index 
)

Remove an edge between two Nodes.

Parameters
src_node_indexNodeIndex of source Node to remove an output edge from.
dst_node_indexNodeIndex of destination Node to remove an input edge from.
src_arg_indexnode arg index of source node.
dst_arg_indexnode arg index of destination node.
void onnxruntime::Graph::RemoveInitializedTensor ( const std::string tensor_name)

Remove the initializer tensor with the provided name from the Graph.

bool onnxruntime::Graph::RemoveNode ( NodeIndex  node_index)

Remove a Node from this Graph and free it. The output edges of this specified node MUST have been removed before removing the node. The input edges of this specified node is removed while removing the node. The process of removing a node from a graph should be,

  1. Remove out edges of this specified node.
  2. Remove this specified node.
  3. Add new input edges connected with all out nodes.
    Returns
    true if the node_index was valid
    Remarks
    Do not call AddNode and Remove Node concurrently as they are not thread-safe.
common::Status onnxruntime::Graph::ReplaceInitializedTensor ( ONNX_NAMESPACE::TensorProto  new_initializer)

Replaces the initializer tensor with the same name as the given initializer tensor. The replacement initializer tensor must have the same type and shape as the existing initializer tensor.

Note: This currently has linear time complexity. There is room for improvement but it would likely require changes to how initializer tensors are stored and tracked.

common::Status onnxruntime::Graph::Resolve ( const ResolveOptions options)

Resolve this Graph to ensure it is completely valid, fully initialized, and able to be executed.

  1. Run through all validation rules. a. Node name and node output's names should be unique. b. Attribute match between node and op definition. c. Input/Output match between node and op definition. d. Graph is acyclic and sort nodes in topological order.
  2. Check & Setup inner nodes' dependency.
  3. Cleanup function definition lists. Note: the weights for training can't be cleaned during resolve.
    Returns
    common::Status with success or error information.
common::Status onnxruntime::Graph::Resolve ( )
inline

Definition at line 1270 of file graph.h.

void onnxruntime::Graph::ReverseDFSFrom ( gsl::span< NodeIndex const from,
const std::function< void(const Node *)> &  enter,
const std::function< void(const Node *)> &  leave,
const std::function< bool(const Node *, const Node *)> &  comp = {} 
) const

Performs a reverse depth-first search (DFS) traversal from a set of nodes, via their inputs, up to their source node/s.

Parameters
fromNodeIndex values for a set of Nodes to traverse from.
enterVisit function that will be invoked on a node when it is visited but its parents haven't been.
leaveVisit function invoked on the node after its parents have all been visited.
compComparison function to stabilize the traversal order by making Node ordering deterministic.
void onnxruntime::Graph::ReverseDFSFrom ( gsl::span< const Node *const from,
const std::function< void(const Node *)> &  enter,
const std::function< void(const Node *)> &  leave,
const std::function< bool(const Node *, const Node *)> &  comp = {} 
) const

Performs a reverse depth-first search (DFS) traversal from a set of nodes, via their inputs, up to their source node/s.

Parameters
fromSet of Nodes to traverse from.
enterVisit function that will be invoked on a node when it is visited but its parents haven't been.
leaveVisit function invoked on the node after its parents have all been visited.
compComparison function to stabilize the traversal order by making Node ordering deterministic.
void onnxruntime::Graph::ReverseDFSFrom ( gsl::span< const Node *const from,
const std::function< void(const Node *)> &  enter,
const std::function< void(const Node *)> &  leave,
const std::function< bool(const Node *, const Node *)> &  comp,
const std::function< bool(const Node *, const Node *)> &  stop 
) const

Performs a reverse depth-first search (DFS) traversal from a set of nodes, via their inputs, up to their source node/s.

Parameters
fromSet of Nodes to traverse from.
enterVisit function that will be invoked on a node when it is visited but its parents haven't been.
leaveVisit function invoked on the node after its parents have all been visited.
stopStop traversal from node n to input node p if stop(n, p) is true.
compComparison function to stabilize the traversal order by making Node ordering deterministic.
const RuntimeOptimizationRecordContainer& onnxruntime::Graph::RuntimeOptimizations ( ) const
inline

Definition at line 1331 of file graph.h.

common::Status onnxruntime::Graph::SaveToOrtFormat ( flatbuffers::FlatBufferBuilder &  builder,
flatbuffers::Offset< onnxruntime::fbs::Graph > &  fbs_graph 
) const
void onnxruntime::Graph::SetDescription ( const std::string description)

Gets the Graph description.

Graph& onnxruntime::Graph::SetGraphProtoSyncNeeded ( )
inlinenoexcept

Sets flag that Graph::graph_proto_ needs to be updated to reflect changes in the Graph.

Definition at line 1022 of file graph.h.

Graph& onnxruntime::Graph::SetGraphResolveNeeded ( )
inlinenoexcept

Mark the Graph as needing Resolve() to be called. This should be done after modifying any aspect of the Graph that changes the Nodes or relationships between them.

Definition at line 1011 of file graph.h.

void onnxruntime::Graph::SetInputs ( gsl::span< const NodeArg *const inputs)

Explicitly set graph inputs.

Parameters
inputsNodeArgs that represent complete graph inputs which need to be explicitly ordered.
Remarks
Note that the input order matters for subgraphs.
void onnxruntime::Graph::SetInputs ( std::initializer_list< const NodeArg * >  inputs)
inline

Definition at line 1157 of file graph.h.

void onnxruntime::Graph::SetName ( const std::string name)

Sets the Graph name.

void onnxruntime::Graph::SetNodeArgType ( NodeArg arg,
const ONNX_NAMESPACE::TypeProto &  type_proto 
)

Sets the type of a NodeArg, replacing existing type/shape if any

bool onnxruntime::Graph::SetOpSchemaFromRegistryForNode ( Node node)

Looks up the op schema in the schema registry and sets it for the given node.

Parameters
nodeThe node to update.
Returns
Whether the node's op schema was set to a valid value.
void onnxruntime::Graph::SetOutputs ( gsl::span< const NodeArg *const outputs)

Explicitly set graph outputs.

Parameters
outputsNodeArgs that represent complete graph outputs which need to be explicitly ordered.
Remarks
Note that the output order matters for subgraphs.
void onnxruntime::Graph::SetOutputs ( std::initializer_list< const NodeArg * >  outputs)
inline

Definition at line 1175 of file graph.h.

bool onnxruntime::Graph::StrictShapeTypeInference ( ) const
inline

Returns the strict_shape_type_inference that was passed into the constructor.

Definition at line 680 of file graph.h.

const ONNX_NAMESPACE::GraphProto& onnxruntime::Graph::ToGraphProto ( )

Gets the GraphProto representation of this Graph.

ONNX_NAMESPACE::GraphProto onnxruntime::Graph::ToGraphProto ( ) const
ONNX_NAMESPACE::GraphProto onnxruntime::Graph::ToGraphProtoWithExternalInitializers ( const std::string external_file_name,
size_t  initializer_size_threshold 
) const

Gets the GraphProto representation of this Graph external_file_name name of the binary file to use for initializers

Parameters
initializer_size_thresholdinitializers larger or equal to this threshold (in bytes) are saved in the external file. Initializer smaller than this threshold are included in the onnx file.
Returns
GraphProto serialization of the graph.
void onnxruntime::Graph::UpdateConsumerNodes ( const std::string node_arg_name,
gsl::span< Node *const nodes 
)
inline

Definition at line 1223 of file graph.h.

void onnxruntime::Graph::UpdateConsumerNodes ( const std::string node_arg_name,
std::initializer_list< Node * >  nodes 
)
inline

Definition at line 1236 of file graph.h.

void onnxruntime::Graph::UpdateProducerNode ( const std::string node_arg_name,
NodeIndex  node_index 
)
inline

Definition at line 1193 of file graph.h.

Status onnxruntime::Graph::UpdateShapeInference ( Node node)

During constant folding it may become possible to infer the shape for a node. To avoid running a full Resolve allow an individual node to have the shape inferencing re-run.

Friends And Related Function Documentation

friend class Model
friend

Definition at line 1342 of file graph.h.


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