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

#include <graph.h>

Classes

class  Definitions
 
class  EdgeEnd
 
struct  EdgeEndCompare
 
class  NodeConstIterator
 
class  Relationships
 

Public Types

enum  Type { Type::Primitive = 0, Type::Fused = 1 }
 
using EdgeSet = std::set< EdgeEnd, EdgeEndCompare >
 
using EdgeConstIterator = EdgeSet::const_iterator
 

Public Member Functions

 Node ()=default
 
 Node (std::string_view name, std::string_view op_type, std::string_view description, gsl::span< NodeArg *const > input_args, gsl::span< NodeArg *const > output_args, const NodeAttributes *attributes, std::string_view domain)
 
 ~Node ()=default
 
NodeIndex Index () const noexcept
 
const std::stringName () const noexcept
 
const std::stringOpType () const noexcept
 
const std::stringDomain () const noexcept
 
const Path & ModelPath () const noexcept
 
int Priority () const noexcept
 
void SetPriority (int priority) noexcept
 
const std::stringDescription () const noexcept
 
Node::Type NodeType () const noexcept
 
int SinceVersion () const noexcept
 
void SetSinceVersion (int since_version) noexcept
 
const ONNX_NAMESPACE::OpSchema * Op () const noexcept
 
bool TryGetFunctionProto (ONNX_NAMESPACE::FunctionProto &func_proto) const
 
bool CanBeInlined () const
 
const FunctionGetFunctionBody () const noexcept
 
const std::vector< int > & InputArgCount () const noexcept
 
ConstPointerContainer
< std::vector< NodeArg * > > 
InputDefs () const noexcept
 
ConstPointerContainer
< std::vector< NodeArg * > > 
ImplicitInputDefs () const noexcept
 
ConstPointerContainer
< std::vector< NodeArg * > > 
OutputDefs () const noexcept
 
std::vector< NodeArg * > & MutableImplicitInputDefs () noexcept
 
std::vector< int > & MutableInputArgsCount ()
 
std::vector< NodeArg * > & MutableInputDefs () noexcept
 
std::vector< NodeArg * > & MutableOutputDefs () noexcept
 
NodeConstIterator InputNodesBegin () const noexcept
 
NodeConstIterator InputNodesEnd () const noexcept
 
NodeConstIterator OutputNodesBegin () const noexcept
 
NodeConstIterator OutputNodesEnd () const noexcept
 
EdgeConstIterator InputEdgesBegin () const noexcept
 
EdgeConstIterator InputEdgesEnd () const noexcept
 
EdgeConstIterator OutputEdgesBegin () const noexcept
 
EdgeConstIterator OutputEdgesEnd () const noexcept
 
const std::set< std::string > & ControlInputs () const noexcept
 
size_t GetInputEdgesCount () const noexcept
 
size_t GetOutputEdgesCount () const noexcept
 
void AddAttributeProto (ONNX_NAMESPACE::AttributeProto value)
 
void AddAttribute (std::string attr_name, int64_t value)
 
void AddAttribute (std::string attr_name, gsl::span< const int64_t > values)
 
 ADD_ATTR_INTERFACES (float)
 
 ADD_ATTR_INTERFACES (std::string)
 
 ADD_ATTR_INTERFACES (ONNX_NAMESPACE::TensorProto)
 
 ADD_ATTR_INTERFACES (ONNX_NAMESPACE::SparseTensorProto)
 
 ADD_ATTR_INTERFACES (ONNX_NAMESPACE::TypeProto)
 
 ADD_ATTR_SINGLE_INTERFACE (ONNX_NAMESPACE::GraphProto)
 
template<size_t N>
void AddAttribute (std::string attr_name, const char(&value)[N])
 
const NodeAttributesGetAttributes () const noexcept
 
bool ClearAttribute (const std::string &attr_name)
 
NodeAttributesGetMutableAttributes () noexcept
 
const GraphGetGraphAttribute (const std::string &attr_name) const
 
GraphGetMutableGraphAttribute (const std::string &attr_name)
 
bool ContainsSubgraph () const
 
std::vector< gsl::not_null
< const Graph * > > 
GetSubgraphs () const
 
const std::unordered_map
< std::string, gsl::not_null
< Graph * > > & 
GetAttributeNameToMutableSubgraphMap ()
 
std::unordered_map
< std::string, gsl::not_null
< const Graph * > > 
GetAttributeNameToSubgraphMap () const
 
ProviderType GetExecutionProviderType () const noexcept
 
void SetExecutionProviderType (ProviderType execution_provider_type)
 
void ForEachDef (std::function< void(const onnxruntime::NodeArg &, bool is_input)> func, bool include_missing_optional_defs=false) const
 
void ReplaceDefs (const std::map< const onnxruntime::NodeArg *, onnxruntime::NodeArg * > &replacements)
 
void ToProto (ONNX_NAMESPACE::NodeProto &proto, bool update_subgraphs=false) const
 
Status SaveToOrtFormat (flatbuffers::FlatBufferBuilder &builder, flatbuffers::Offset< onnxruntime::fbs::Node > &fbs_node) const
 
flatbuffers::Offset
< onnxruntime::fbs::NodeEdge > 
SaveEdgesToOrtFormat (flatbuffers::FlatBufferBuilder &builder) const
 
void SetFunctionTemplate (const FunctionTemplate &func_template)
 
Status LoadFromOrtFormat (const onnxruntime::fbs::Node &fbs_node, const OrtFormatLoadOptions &load_options, const logging::Logger &logger)
 
Status LoadEdgesFromOrtFormat (const onnxruntime::fbs::NodeEdge &fbs_node_edgs, const Graph &graph)
 
 Node (NodeIndex index, Graph &graph)
 

Static Public Member Functions

static common::Status ForEachWithIndex (const ConstPointerContainer< std::vector< NodeArg * >> &node_args, std::function< common::Status(const NodeArg &arg, size_t index)> func)
 
static common::Status ForEachMutableWithIndex (std::vector< NodeArg * > &node_args, std::function< common::Status(NodeArg &arg, size_t index)> func)
 
static Status LoadFromOrtFormat (const onnxruntime::fbs::Node &fbs_node, Graph &graph, const OrtFormatLoadOptions &load_options, const logging::Logger &logger, std::unique_ptr< Node > &node)
 

Friends

class Graph
 

Detailed Description

Class representing a node in the graph.

Definition at line 77 of file graph.h.

Member Typedef Documentation

using onnxruntime::Node::EdgeConstIterator = EdgeSet::const_iterator

Definition at line 298 of file graph.h.

Definition at line 297 of file graph.h.

Member Enumeration Documentation

Node types

Enumerator
Primitive 

The node refers to a primitive operator.

Fused 

The node refers to a function.

Definition at line 80 of file graph.h.

Constructor & Destructor Documentation

onnxruntime::Node::Node ( )
explicitdefault
onnxruntime::Node::Node ( std::string_view  name,
std::string_view  op_type,
std::string_view  description,
gsl::span< NodeArg *const input_args,
gsl::span< NodeArg *const output_args,
const NodeAttributes attributes,
std::string_view  domain 
)
inline

Definition at line 88 of file graph.h.

onnxruntime::Node::~Node ( )
default
onnxruntime::Node::Node ( NodeIndex  index,
Graph graph 
)
inline

Definition at line 563 of file graph.h.

Member Function Documentation

onnxruntime::Node::ADD_ATTR_INTERFACES ( float  )
onnxruntime::Node::ADD_ATTR_INTERFACES ( std::string  )
onnxruntime::Node::ADD_ATTR_INTERFACES ( ONNX_NAMESPACE::TensorProto  )
onnxruntime::Node::ADD_ATTR_INTERFACES ( ONNX_NAMESPACE::SparseTensorProto  )
onnxruntime::Node::ADD_ATTR_INTERFACES ( ONNX_NAMESPACE::TypeProto  )
onnxruntime::Node::ADD_ATTR_SINGLE_INTERFACE ( ONNX_NAMESPACE::GraphProto  )
void onnxruntime::Node::AddAttribute ( std::string  attr_name,
int64_t  value 
)

Adds an attribute to this Node with the specified attribute name and value.

void onnxruntime::Node::AddAttribute ( std::string  attr_name,
gsl::span< const int64_t >  values 
)

Adds an attribute to this Node with the specified attribute name and values.

template<size_t N>
void onnxruntime::Node::AddAttribute ( std::string  attr_name,
const char(&)  value[N] 
)
inline

Definition at line 398 of file graph.h.

void onnxruntime::Node::AddAttributeProto ( ONNX_NAMESPACE::AttributeProto  value)

Adds an AttributeProto to this Node.

Remarks
The attribute name is used as the key in the attribute map.
bool onnxruntime::Node::CanBeInlined ( ) const
bool onnxruntime::Node::ClearAttribute ( const std::string attr_name)

Remove the specified attribute from this Node

bool onnxruntime::Node::ContainsSubgraph ( ) const
inline

Checks if the Node contains at least one subgraph (this is the case for control flow operators, such as If, Scan, Loop).

Returns
true if the Node contains a subgraph.

Definition at line 430 of file graph.h.

const std::set<std::string>& onnxruntime::Node::ControlInputs ( ) const
inlinenoexcept

Gets the Node's control inputs.

Definition at line 351 of file graph.h.

const std::string& onnxruntime::Node::Description ( ) const
inlinenoexcept

Gets the node description.

Definition at line 169 of file graph.h.

const std::string& onnxruntime::Node::Domain ( ) const
inlinenoexcept

Gets the domain of the OperatorSet that specifies the operator returned by OpType.

Remarks
If this is an ONNX operator the value will be kOnnxDomain not kOnnxDomainAlias

Definition at line 155 of file graph.h.

void onnxruntime::Node::ForEachDef ( std::function< void(const onnxruntime::NodeArg &, bool is_input)>  func,
bool  include_missing_optional_defs = false 
) const

Call the provided function for all explicit inputs, implicit inputs, and outputs of this Node. If the NodeArg is an explicit or implicit input, is_input will be true when func is called.

Parameters
include_missing_optional_defsInclude NodeArgs that are optional and were not provided i.e. NodeArg::Exists() == false.
static common::Status onnxruntime::Node::ForEachMutableWithIndex ( std::vector< NodeArg * > &  node_args,
std::function< common::Status(NodeArg &arg, size_t index)>  func 
)
inlinestatic

Helper to iterate through the container returned by MutableInputDefs() or MutableOutputDefs() and call the provided function.

Parameters
node_argsCollection of NodeArgs returned by MutableInputDefs() or MutableOutputDefs()
funcFunction to call for each valid NodeArg in the node_args. The function is called with the NodeArg and the index number in the container.
Returns
common::Status with success or error information.
Remarks
Returns immediately on error.

Definition at line 250 of file graph.h.

static common::Status onnxruntime::Node::ForEachWithIndex ( const ConstPointerContainer< std::vector< NodeArg * >> &  node_args,
std::function< common::Status(const NodeArg &arg, size_t index)>  func 
)
inlinestatic

Helper to iterate through the container returned by InputDefs() or OutputDefs() and call the provided function.

Parameters
node_argsCollection of NodeArgs returned by InputDefs() or OutputDefs()
funcFunction to call for each valid NodeArg in the node_args. The function is called with the NodeArg and the index number in the container.
Returns
common::Status with success or error information.
Remarks
Returns immediately on error.

Definition at line 208 of file graph.h.

const std::unordered_map<std::string, gsl::not_null<Graph*> >& onnxruntime::Node::GetAttributeNameToMutableSubgraphMap ( )
inline

Gets a map of attribute name to the mutable Graph instances for all subgraphs of the Node.

Returns
Map of the attribute name that defines the subgraph to the subgraph's Graph instance. nullptr if the Node has no subgraphs.

Definition at line 442 of file graph.h.

std::unordered_map<std::string, gsl::not_null<const Graph*> > onnxruntime::Node::GetAttributeNameToSubgraphMap ( ) const

Gets a map of attribute name to the const Graph instances for all subgraphs of the Node.

Returns
Map of the attribute name that defines the subgraph to the subgraph's Graph instance. nullptr if the Node has no subgraphs.
const NodeAttributes& onnxruntime::Node::GetAttributes ( ) const
inlinenoexcept

Gets the Node's attributes.

Definition at line 403 of file graph.h.

ProviderType onnxruntime::Node::GetExecutionProviderType ( ) const
inlinenoexcept

Gets the execution ProviderType that this node will be executed by.

Definition at line 453 of file graph.h.

const Function* onnxruntime::Node::GetFunctionBody ( ) const
inlinenoexcept

Gets the function body if applicable otherwise nullptr.

Definition at line 197 of file graph.h.

const Graph* onnxruntime::Node::GetGraphAttribute ( const std::string attr_name) const

Gets the Graph instance that is instantiated from a GraphProto attribute during Graph::Resolve.

Parameters
attr_nameAttribute name for the GraphProto attribute.
Returns
nullptr if the Graph instance has not been instantiated or attribute does not contain a GraphProto.
size_t onnxruntime::Node::GetInputEdgesCount ( ) const
inlinenoexcept

Gets the number of input edges to this Node

Definition at line 354 of file graph.h.

NodeAttributes& onnxruntime::Node::GetMutableAttributes ( )
inlinenoexcept

Gets the Node's mutable attributes.

Definition at line 412 of file graph.h.

Graph* onnxruntime::Node::GetMutableGraphAttribute ( const std::string attr_name)

Gets the mutable Graph instance that is instantiated from a GraphProto attribute during Graph::Resolve.

Parameters
attr_nameAttribute name for the GraphProto attribute.
Returns
nullptr if the Graph instance has not been instantiated or attribute does not contain a GraphProto.
size_t onnxruntime::Node::GetOutputEdgesCount ( ) const
inlinenoexcept

Gets the number of output edges from this Node

Definition at line 357 of file graph.h.

std::vector<gsl::not_null<const Graph*> > onnxruntime::Node::GetSubgraphs ( ) const

Get the const subgraphs from a node.

Remarks
Creates a new vector so calling ContainsSubgraphs first is preferred.
ConstPointerContainer<std::vector<NodeArg*> > onnxruntime::Node::ImplicitInputDefs ( ) const
inlinenoexcept

Gets the implicit inputs to this Node. If this Node contains a subgraph, these are the NodeArg's that are implicitly consumed by Nodes within that subgraph. e.g. If and Loop operators.

Definition at line 231 of file graph.h.

NodeIndex onnxruntime::Node::Index ( ) const
inlinenoexcept

Gets the Node's NodeIndex.

Definition at line 144 of file graph.h.

const std::vector<int>& onnxruntime::Node::InputArgCount ( ) const
inlinenoexcept

Gets the count of arguments for each of the Node's explicit inputs.

Definition at line 220 of file graph.h.

ConstPointerContainer<std::vector<NodeArg*> > onnxruntime::Node::InputDefs ( ) const
inlinenoexcept

Gets the Node's input definitions.

Remarks
requires ConstPointerContainer wrapper to apply const to the NodeArg pointers so access is read-only.

Definition at line 224 of file graph.h.

EdgeConstIterator onnxruntime::Node::InputEdgesBegin ( ) const
inlinenoexcept

Gets an iterator to the beginning of the input edges to this Node.

Remarks
There are no nullptr entries in this collection.

Definition at line 338 of file graph.h.

EdgeConstIterator onnxruntime::Node::InputEdgesEnd ( ) const
inlinenoexcept

Gets an iterator to the end of the input edges to this Node.

Definition at line 341 of file graph.h.

NodeConstIterator onnxruntime::Node::InputNodesBegin ( ) const
inlinenoexcept

Gets an iterator to the beginning of the input nodes to this Node.

Definition at line 324 of file graph.h.

NodeConstIterator onnxruntime::Node::InputNodesEnd ( ) const
inlinenoexcept

Gets an iterator to the end of the input nodes to this Node.

Definition at line 326 of file graph.h.

Status onnxruntime::Node::LoadEdgesFromOrtFormat ( const onnxruntime::fbs::NodeEdge &  fbs_node_edgs,
const Graph graph 
)
static Status onnxruntime::Node::LoadFromOrtFormat ( const onnxruntime::fbs::Node &  fbs_node,
Graph graph,
const OrtFormatLoadOptions &  load_options,
const logging::Logger logger,
std::unique_ptr< Node > &  node 
)
static
Status onnxruntime::Node::LoadFromOrtFormat ( const onnxruntime::fbs::Node &  fbs_node,
const OrtFormatLoadOptions &  load_options,
const logging::Logger logger 
)
const Path& onnxruntime::Node::ModelPath ( ) const
noexcept

Gets the path of the owning model if any.

std::vector<NodeArg*>& onnxruntime::Node::MutableImplicitInputDefs ( )
inlinenoexcept

Gets a modifiable collection of the Node's implicit input definitions.

Definition at line 262 of file graph.h.

std::vector<int>& onnxruntime::Node::MutableInputArgsCount ( )
inline

Gets a modifiable count of arguments for each of the Node's explicit inputs.

Todo:
This should be removed in favor of a method that updates the input args and the count. Currently these operations are separate which is not a good setup.

Definition at line 271 of file graph.h.

std::vector<NodeArg*>& onnxruntime::Node::MutableInputDefs ( )
inlinenoexcept

Gets a modifiable collection of the Node's input definitions.

Definition at line 274 of file graph.h.

std::vector<NodeArg*>& onnxruntime::Node::MutableOutputDefs ( )
inlinenoexcept

Gets a modifiable collection of the Node's output definitions.

Definition at line 279 of file graph.h.

const std::string& onnxruntime::Node::Name ( ) const
inlinenoexcept

Gets the Node's name.

Definition at line 147 of file graph.h.

Node::Type onnxruntime::Node::NodeType ( ) const
inlinenoexcept

Gets the Node's Node::Type.

Definition at line 172 of file graph.h.

const ONNX_NAMESPACE::OpSchema* onnxruntime::Node::Op ( ) const
inlinenoexcept

Gets the Node's OpSchema.

Remarks
The graph containing this node must be resolved, otherwise nullptr will be returned.

Definition at line 189 of file graph.h.

const std::string& onnxruntime::Node::OpType ( ) const
inlinenoexcept

Gets the Node's operator type.

Definition at line 150 of file graph.h.

ConstPointerContainer<std::vector<NodeArg*> > onnxruntime::Node::OutputDefs ( ) const
inlinenoexcept

Gets the Node's output definitions.

Remarks
requires ConstPointerContainer wrapper to apply const to the NodeArg pointers so access is read-only.

Definition at line 237 of file graph.h.

EdgeConstIterator onnxruntime::Node::OutputEdgesBegin ( ) const
inlinenoexcept

Gets an iterator to the beginning of the output edges from this Node.

Remarks
There are no nullptr entries in this collection.

Definition at line 345 of file graph.h.

EdgeConstIterator onnxruntime::Node::OutputEdgesEnd ( ) const
inlinenoexcept

Gets an iterator to the end of the output edges from this Node.

Definition at line 348 of file graph.h.

NodeConstIterator onnxruntime::Node::OutputNodesBegin ( ) const
inlinenoexcept

Gets an iterator to the beginning of the output nodes from this Node.

Definition at line 329 of file graph.h.

NodeConstIterator onnxruntime::Node::OutputNodesEnd ( ) const
inlinenoexcept

Gets an iterator to the end of the output nodes from this Node.

Definition at line 334 of file graph.h.

int onnxruntime::Node::Priority ( ) const
inlinenoexcept

Gets the Node's execution priority.

Remarks
Lower value means higher priority

Definition at line 162 of file graph.h.

void onnxruntime::Node::ReplaceDefs ( const std::map< const onnxruntime::NodeArg *, onnxruntime::NodeArg * > &  replacements)

Replaces any matching definitions in the Node's explicit inputs or explicit outputs.

Parameters
replacementsMap of current NodeArg to replacement NodeArg.
flatbuffers::Offset<onnxruntime::fbs::NodeEdge> onnxruntime::Node::SaveEdgesToOrtFormat ( flatbuffers::FlatBufferBuilder &  builder) const
Status onnxruntime::Node::SaveToOrtFormat ( flatbuffers::FlatBufferBuilder &  builder,
flatbuffers::Offset< onnxruntime::fbs::Node > &  fbs_node 
) const
void onnxruntime::Node::SetExecutionProviderType ( ProviderType  execution_provider_type)
inline

Sets the execution ProviderType that this Node will be executed by.

Definition at line 456 of file graph.h.

void onnxruntime::Node::SetFunctionTemplate ( const FunctionTemplate &  func_template)
void onnxruntime::Node::SetPriority ( int  priority)
noexcept

Sets the execution priority of a node.

Remarks
Lower value means higher priority
void onnxruntime::Node::SetSinceVersion ( int  since_version)
inlinenoexcept

Sets the since version (opset version that the Node's operator was first defined in.) for this node.

Remarks
Used during layout transformation for setting since version for layout transformed nodes with domain kMSNHWC.

Definition at line 184 of file graph.h.

int onnxruntime::Node::SinceVersion ( ) const
inlinenoexcept

Gets the opset version that the Node's operator was first defined in.

Returns
Opset version. If -1 the Node's operator has not been set.
Remarks
Prefer over Op()->SinceVersion() as Op() is disabled in a minimal build

Definition at line 178 of file graph.h.

void onnxruntime::Node::ToProto ( ONNX_NAMESPACE::NodeProto &  proto,
bool  update_subgraphs = false 
) const

Gets the NodeProto representation of this Node.

Parameters
update_subgraphsUpdate the GraphProto values for any subgraphs in the returned NodeProto. If graph optimization has been run this is most likely required to ensure the complete Graph is valid.
bool onnxruntime::Node::TryGetFunctionProto ( ONNX_NAMESPACE::FunctionProto &  func_proto) const

Create a copy of the called op's FunctionProto if it has one. Returns true if successful.

Friends And Related Function Documentation

friend class Graph
friend

Definition at line 562 of file graph.h.


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