ir.h#
Lightweight in-memory intermediate representation (IR) for ONNX graphs.
Provides the core graph data structures used by the ONNX version converter and related tools:
ONNX_LIGHT_NAMESPACE::Graph – owns all nodes and values of one function.
ONNX_LIGHT_NAMESPACE::Node – a single computation step with typed attributes.
ONNX_LIGHT_NAMESPACE::Value – a typed edge (SSA value) connecting nodes.
ONNX_LIGHT_NAMESPACE::OpSetID – a lightweight (domain, version) pair without protobuf overhead.
All raw pointers returned by this API are non-owning; the Graph is the sole owner of every Node and Value it creates. Destroying a Graph invalidates all pointers into it.
-
namespace ONNX_LIGHT_NAMESPACE
Typedefs
-
using FloatAttr = ScalarAttributeValue<double, AttributeKind::f>#
Scalar float attribute (
doublestorage, kindf).
-
using FloatsAttr = VectorAttributeValue<double, AttributeKind::fs>#
Float-list attribute (
doubleelement storage, kindfs).
-
using IntAttr = ScalarAttributeValue<int64_t, AttributeKind::i>#
Scalar integer attribute (
int64_tstorage, kindi).
-
using IntsAttr = VectorAttributeValue<int64_t, AttributeKind::is>#
Integer-list attribute (
int64_telement storage, kindis).
-
using StringAttr = ScalarAttributeValue<std::string, AttributeKind::s>#
Scalar string attribute (
std::stringstorage, kinds).
-
using StringsAttr = VectorAttributeValue<std::string, AttributeKind::ss>#
String-list attribute (
std::stringelement storage, kindss).
-
using TensorAttr = ScalarAttributeValue<Tensor, AttributeKind::t>#
Scalar tensor attribute (kind
t).
-
using TensorsAttr = VectorAttributeValue<Tensor, AttributeKind::ts>#
Tensor-list attribute (kind
ts).
-
using GraphAttr = ScalarAttributeValue<std::shared_ptr<Graph>, AttributeKind::g>#
Scalar subgraph attribute (kind
g).
-
using GraphsAttr = VectorAttributeValue<std::shared_ptr<Graph>, AttributeKind::gs>#
Subgraph-list attribute (kind
gs).
-
using TypeProtoAttr = ScalarAttributeValue<TypeProto, AttributeKind::tp>#
Scalar type-proto attribute (kind
tp).
-
using TypeProtosAttr = VectorAttributeValue<TypeProto, AttributeKind::tps>#
Type-proto-list attribute (kind
tps).
Enums
-
enum class AttributeKind : uint8_t#
Discriminator tag for the concrete type of an attribute value.
Each enumerator corresponds to a scalar or vector ONNX attribute type: float (
f), float list (fs), integer (i), integer list (is), string (s), string list (ss), tensor (t), tensor list (ts), subgraph (g), subgraph list (gs), type-proto (tp), and type-proto list (tps).Values:
-
enumerator f#
-
enumerator fs#
-
enumerator i#
-
enumerator is#
-
enumerator s#
-
enumerator ss#
-
enumerator t#
-
enumerator ts#
-
enumerator g#
-
enumerator gs#
-
enumerator tp#
-
enumerator tps#
-
enumerator f#
Functions
-
static inline const char *toString(AttributeKind kind)#
Converts an AttributeKind enumerator to its string name.
- Parameters:
kind – The attribute kind.
- Returns:
A null-terminated string such as
"f","fs","i", etc.
-
template<typename Derived>
struct Attributes# - #include <ir.h>
CRTP mixin that adds typed attribute storage to a node class.
Enables method chaining via a
Derived*return type, e.g.:Node *n = g->create(kSelect)->i_(kOffset, 3)->f_(kValue, 3.5f);
Attribute lookup is O(n) in the number of attributes to keep deterministic ordering; nodes are not expected to carry a large number of attributes.
- Template Parameters:
Derived – The concrete node type that inherits this mixin.
Subclassed by ONNX_LIGHT_NAMESPACE::Node
Public Functions
-
Attributes() = default#
-
inline void copyAttributes(const Attributes &rhs)#
Replaces all attributes of this object with deep copies from
rhs.- Parameters:
rhs – Source object whose attributes are cloned.
-
inline bool hasAttribute(Symbol name) const#
Returns true if an attribute with the given name exists.
- Parameters:
name – Attribute symbol to look up.
-
inline AttributeKind kindOf(Symbol name) const#
Returns the kind of the attribute with the given name.
- Parameters:
name – Attribute symbol (must exist).
-
inline Derived *removeAttribute(Symbol name)#
Removes the attribute with the given name and returns
this.- Parameters:
name – Attribute symbol (must exist).
-
inline bool hasAttributes() const#
Returns true if any attributes are set.
Private Types
-
using AVPtr = AttributeValue::Ptr#
Private Functions
-
inline const_iterator find(Symbol name, bool required) const#
-
struct AttributeValue#
- #include <ir.h>
Abstract base class for a named attribute value stored on a Node.
Concrete subtypes are ScalarAttributeValue and VectorAttributeValue, instantiated for each supported ONNX attribute kind.
Subclassed by ONNX_LIGHT_NAMESPACE::ScalarAttributeValue< T, Kind >, ONNX_LIGHT_NAMESPACE::VectorAttributeValue< T, Kind >
Public Types
-
using Ptr = std::unique_ptr<AttributeValue>#
Owning pointer alias for convenience.
-
using Ptr = std::unique_ptr<AttributeValue>#
-
struct Dimension#
- #include <ir.h>
Represents a single dimension of a tensor shape.
A dimension is one of:
unknown – neither an integer nor a symbolic parameter (default).
symbolic – a named parameter string (e.g.
"batch_size").static – a concrete non-negative
int64_tvalue.
Public Functions
-
inline Dimension()#
Constructs an unknown dimension.
-
inline explicit Dimension(std::string param)#
Constructs a symbolic dimension.
- Parameters:
param – Symbolic parameter name.
-
inline explicit Dimension(int64_t dim)#
Constructs a static integer dimension.
- Parameters:
dim – Non-negative size of this dimension.
-
struct Graph#
- #include <ir.h>
Computation graph owning all its nodes and values.
A
Graphowns every Node and Value it creates. All pointers returned by its API are non-owning; destroying the graph invalidates them.The graph maintains two pseudo-nodes:
input_ — its outputs represent the graph’s formal input Value objects.
output_ — its inputs represent the graph’s output Value objects; also serves as the sentinel for the circular topological node list.
A separate initializer_node_ holds Value objects for IR ≥ 4 initializers that are not required to appear in the input list.
Public Functions
-
inline Graph()#
Constructs an empty graph with input, output, and initializer sentinel nodes.
-
inline bool has_doc_string() const#
Returns true if a documentation string is set.
-
inline void setDocString(std::string doc_string)#
Sets the graph documentation string.
- Parameters:
doc_string – Documentation text.
-
inline void addInitializer(Tensor &initializer)#
Adds
initializerto the graph’s initializer list.If the initializer has no name, a unique name is generated automatically.
- Parameters:
initializer – Tensor to register as an initializer.
-
inline Value *addInitializerAndCreateValue(Tensor &initializer)#
Adds
initializerto the initializer list and returns a corresponding Value.For IR ≥ 4, initializers are not required to appear in the graph input list. This method registers the initializer and creates a Value in the internal initializer node list.
-
inline void eraseInitializer(const std::string &name)#
Removes the initializer with the given name from all lists.
- Parameters:
name – Name of the initializer to remove.
-
inline void clearInitializers()#
Removes all initializers and clears the initializer name list.
-
inline const std::vector<std::string> &initializer_names() const#
Returns the list of initializer names.
-
inline std::vector<Tensor>::const_iterator getInitializer(const std::string &name) const#
Returns a const iterator to the initializer with the given name, or
initializers().end() if not found.- Parameters:
name – Initializer name to search for.
-
inline bool is_constant_initializer(const Value *value) const#
Returns true if
valueoriginates from the internal initializer node (i.e. it is an IR ≥ 4 initializer not present in the input list).- Parameters:
value – Value to test.
-
inline ArrayRef<const Value*> inputs() const#
Returns a const
ArrayRefover the graph’s formal input values.
-
inline ArrayRef<const Value*> outputs() const#
Returns a const
ArrayRefover the graph’s output values.
-
inline graph_node_list nodes()#
Returns a forward-iterable view over the computation nodes in topological order.
-
inline const_graph_node_list nodes() const#
Returns a const forward-iterable view over the computation nodes.
-
inline std::vector<OpSetID> &opset_versions_mutable()#
Returns a mutable reference to the operator-set version list.
-
inline size_t getNextUnique()#
Allocates and returns the next graph-unique integer identifier.
Skips any integers whose generated name (
_v_N) is already in use.
-
inline std::string getNextUniqueName()#
Returns a unique name string of the form
"_v_N".Equivalent to
toVarName(getNextUnique()).
-
inline graph_node_list_iterator begin()#
Returns a forward iterator to the first computation node.
Safe to call on the temporary
graph_node_listreturned by nodes() because the list is non-owning.
-
inline const_graph_node_list_iterator begin() const#
Returns a const forward iterator to the first computation node.
-
inline graph_node_list_iterator end()#
Returns a forward sentinel iterator (one past the last node).
-
inline const_graph_node_list_iterator end() const#
Returns a const forward sentinel iterator.
-
inline graph_node_list_iterator rbegin()#
Returns a reverse iterator to the last computation node.
-
inline const_graph_node_list_iterator rbegin() const#
Returns a const reverse iterator to the last computation node.
-
inline graph_node_list_iterator rend()#
Returns a reverse sentinel iterator.
-
inline const_graph_node_list_iterator rend() const#
Returns a const reverse sentinel iterator.
-
inline void eraseInput(size_t i)#
Removes the formal input at index
i.- Parameters:
i – Zero-based input index.
-
inline void advanceStage()#
Increments the current node-stage counter.
-
inline void setStage(size_t new_stage)#
Sets the current node-stage counter.
- Parameters:
new_stage – New stage value.
-
inline size_t stage() const#
Returns the current node-stage counter.
-
inline ResourceGuard setStageTemporary(size_t s)#
Temporarily sets the stage to
sand returns a ResourceGuard that restores the previous value on destruction.- Parameters:
s – Temporary stage value.
-
inline size_t registerOutput(Value *n)#
Registers
nas a graph output and returns its output index.- Parameters:
n – Value to register as a graph output.
- Returns:
Zero-based index of the newly registered output.
-
inline Node *create(NodeKind kind, size_t num_outputs = 1)#
Creates and returns a new unattached node with
num_outputsoutputs.The node is added to the graph’s allocation set but not yet in the topological node list. Use appendNode or Node::insertBefore / Node::insertAfter to place it.
- Parameters:
kind – Symbolic operation kind.
num_outputs – Number of output values to allocate (default: 1).
- Returns:
The new node.
-
inline Node *create(NodeKind kind, ArrayRef<Value*> inputs, size_t num_outputs = 1)#
Creates a new unattached node with the given inputs and outputs.
- Parameters:
kind – Symbolic operation kind.
inputs – Input values to wire up immediately.
num_outputs – Number of output values to allocate (default: 1).
- Returns:
The new node.
-
inline Node *appendNode(Node *n)#
Appends
nat the end of the topological node list and returns it.- Parameters:
n – Unattached node belonging to this graph.
-
inline Node *prependNode(Node *n)#
Prepends
nat the beginning of the topological node list and returns it.- Parameters:
n – Unattached node belonging to this graph.
-
inline Value *addInitializerAndInput(const Tensor &initializer, const std::string &name)#
Adds
initializeras both a graph input and an initializer entry.Registers the initializer in the initializer list, creates a formal input Value, and synchronises the initializer name, tensor name, and value name.
- Parameters:
initializer – Source tensor (copied internally).
name – Name to assign to the initializer and its value.
- Returns:
The new input Value.
-
inline Value *addInitializerAndInput(const Tensor &initializer)#
Adds
initializeras both a graph input and an initializer entry, generating a unique name automatically.- Parameters:
initializer – Source tensor (copied internally).
- Returns:
The new input Value.
-
inline void eraseInitializerAndInput(Value *v)#
Removes
vfrom the initializer list and, if it is a graph input, from the input list as well.- Parameters:
v – The initializer value to erase.
- Pre:
vmust have no remaining uses.
-
inline ~Graph()#
Destroys all owned nodes and values.
-
inline bool has_name() const#
Returns true if a graph name is set.
-
inline const std::string &name() const#
Returns the graph name (meaningful only when has_name() is true).
-
inline void forSelfAndEachSubGraph(const std::function<void(Graph*)> &fn)#
Calls
fnon this graph and recursively on every subgraph in node attributes.- Parameters:
fn – Callable accepting a
Graph*pointer.
-
inline void forSelfAndEachSubGraph(const std::function<void(const Graph*)> &fn) const#
Const overload of forSelfAndEachSubGraph.
Private Functions
-
struct Node : public ONNX_LIGHT_NAMESPACE::Attributes<Node>#
- #include <ir.h>
A single computation node in the IR graph.
A
Nodehas a symbolic kind() that identifies the operation, an ordered list of input Value pointers, and a list of output Value objects it produces. It also inherits typed attribute storage from Attributes<Node>.Nodes are maintained in topological order via an intrusive doubly-linked list (next_in_graph). The
Return/Parampseudo-nodes serve as sentinels and are not part of the logical computation.Nodeobjects are owned by their Graph; never delete them manually — use destroy() instead.Public Functions
-
inline Node *&next_in_graph(size_t i)#
Returns a reference to the linked-list pointer in direction
i.- Parameters:
i – 0 for
next, 1 forprev(seekNextDirection/kPrevDirection).
-
inline Node *const &next_in_graph(size_t i) const#
Returns a const reference to the linked-list pointer in direction
i.
-
inline Node *const &next() const#
Returns a const reference to the forward (next) linked-list pointer.
-
inline Node *const &prev() const#
Returns a const reference to the backward (prev) linked-list pointer.
-
inline bool has_name() const#
Returns true if a node name is set.
-
inline const std::string &name() const#
Returns the node name (meaningful only when has_name() is true).
-
inline bool has_domain() const#
Returns true if an operator domain is set.
-
inline const std::string &domain() const#
Returns the operator domain (meaningful only when has_domain() is true).
-
inline void setDomain(std::string domain)#
Sets the operator domain.
- Parameters:
domain – Domain string (e.g.
""for the default ONNX domain).
-
inline bool has_overload() const#
Returns true if an overload string is set.
-
inline const std::string &overload() const#
Returns the overload string (meaningful only when has_overload() is true).
-
inline void setOverload(std::string overload)#
Sets the overload string.
- Parameters:
overload – Overload identifier.
-
inline bool has_doc_string() const#
Returns true if a documentation string is set.
-
inline void setDocString(std::string doc_string)#
Sets the documentation string.
- Parameters:
doc_string – Documentation text.
-
inline size_t stage() const#
Returns the current stage index of this node.
-
inline Node *setStage(size_t s)#
Sets the stage index and returns
this.- Parameters:
s – New stage index (0 = forward, 1 = backward, …).
-
inline ArrayRef<Value*> inputs()#
Returns an
ArrayRefover this node’s input values.Warning
The returned reference is invalidated if the input list is resized (e.g. via addInput).
-
inline ArrayRef<const Value*> inputs() const#
Returns a const
ArrayRefover this node’s input values.
-
inline ArrayRef<Value*> outputs()#
Returns an
ArrayRefover this node’s output values.Warning
The returned reference is invalidated if the output list is resized.
-
inline ArrayRef<const Value*> outputs() const#
Returns a const
ArrayRefover this node’s output values.
-
inline bool hasUses() const#
Returns true if any output of this node has at least one use.
-
inline void replaceAllUsesWith(Node *n)#
Replaces all uses of every output of
thiswith the corresponding output ofn.nmust have the same number of outputs asthis.- Parameters:
n – Replacement node.
-
inline Value *input()#
Returns the sole input of this node.
Asserts that the node has exactly one input.
-
inline Value *output()#
Returns the sole output of this node.
Asserts that the node has exactly one output.
-
inline Value *input(size_t i)#
Returns the input at index
i(bounds-checked).- Parameters:
i – Zero-based input index.
-
inline Value *addInput(Value *node)#
Appends
nodeas an input tothisand returns it for chaining.Given: %3 = f(%1, %2) Execute: %3.addInput(%4) Result: %3 = f(%1, %2, %4)
- Parameters:
node – Input value to append (must belong to the same graph).
- Returns:
The appended value
node.
-
inline Value *replaceInput(size_t i, Value *newValue)#
Replaces the input at position
iwithnewValue.Given: %3 = f(%1, %2) Execute: %3.replaceInput(1, %4) Result: %3 = f(%1, %4)
- Parameters:
i – Zero-based index of the input to replace.
newValue – Replacement value (must belong to the same graph).
- Returns:
The old input value at position
i.
-
inline void replaceInputWith(Value *from, Value *to)#
Replaces all occurrences of
fromin the input list withto.Corresponds to LLVM’s
replaceUsesOfWith.Given: %3 = f(%1, %2, %1) Execute: %3.replaceInputWith(%1, %4) Result: %3 = f(%4, %2, %4)
- Parameters:
from – Value to replace (must belong to the same graph).
to – Replacement value (must belong to the same graph).
-
inline void eraseOutput(size_t i)#
Removes the output at index
i.- Parameters:
i – Zero-based output index (the output must have no uses).
-
inline Node *insertBefore(Node *n)#
Inserts an unattached node before
nin topological order.Given: %3 = f(%1, %2) %4 = g(%3) and unattached: %5 = h(%1) Execute: %5.insertBefore(%4) Result: %3 = f(%1, %2) %5 = h(%1) %4 = g(%3)
- Parameters:
n – An existing node already in the graph list.
- Returns:
thisfor chaining.
-
inline Node *insertAfter(Node *n)#
Inserts an unattached node after
nin topological order.Given: %3 = f(%1, %2) %4 = g(%3) and unattached: %5 = h(%1) Execute: %5.insertAfter(%4) Result: %3 = f(%1, %2) %4 = g(%3) %5 = h(%1)
- Parameters:
n – An existing node already in the graph list.
- Returns:
thisfor chaining.
-
inline void moveAfter(Node *n)#
Moves
this(already in the graph) to appear aftern.Given: %2 = f(%1) %3 = g(%1) Execute: %2.moveAfter(%3) Result: %3 = g(%1) %2 = f(%1)
- Parameters:
n – Target node (must be in the graph).
-
inline void moveBefore(Node *n)#
Moves
this(already in the graph) to appear beforen.Given: %2 = f(%1) %3 = g(%1) Execute: %3.moveBefore(%2) Result: %3 = g(%1) %2 = f(%1)
- Parameters:
n – Target node (must be in the graph).
-
inline void removeInput(size_t i)#
Removes the input at index
i.Given: %3 = f(%1, %2) Execute: %3.removeInput(1) Result: %3 = f(%1)
Warning
This is O(n) in the number of inputs; avoid calling it in a loop.
- Parameters:
i – Zero-based index of the input to remove.
-
inline void removeAllInputs()#
Removes all inputs from this node.
Given: %3 = f(%1, %2) Execute: %3.removeAllInputs() Result: %3 = f()
-
inline bool isBefore(const Node *n)#
Returns true if
thisappears beforenin topological order.- Parameters:
n – Node to compare against.
-
inline graph_node_list_iterator iterator()#
Returns a forward iterator to the node-list position of
this.Useful for resuming a graph traversal starting at a known node.
-
inline graph_node_list_iterator reverseIterator()#
Returns a reverse iterator to the node-list position of
this.
-
inline const_graph_node_list_iterator iterator() const#
Returns a const forward iterator to the node-list position of
this.
-
inline const_graph_node_list_iterator reverseIterator() const#
Returns a const reverse iterator to the node-list position of
this.
-
inline void destroy()#
Removes
thisfrom the node list and deallocates it.Given: %2 = f(%1) %3 = g(%1) Execute: %2.destroy() Result: %3 = g(%1)
- Pre:
No outputs of
thismay have any remaining uses.
-
template<typename T>
inline T *cast()# Dynamically casts
thistoT; returnsnullptrif the kind does not match.Example:
if (auto *s = n->cast<Select>()) { ... }
- Template Parameters:
T – Subclass with a static
Kindmember to compare against.
-
template<typename T>
inline T *expect()# Asserts that the kind matches
Tand returns a typed pointer.Aborts with a descriptive message if the kind does not match.
- Template Parameters:
T – Subclass with a static
Kindmember.
-
virtual ~Node() = default#
Protected Functions
-
inline virtual Node *allocNewInstance(Graph *g)#
Allocates a new node of the same concrete type in graph
g.Used by
createCloneto create a fresh instance in a different graph. Subclasses must override if they introduce additional state.
-
inline virtual void cloneFrom(Node *s)#
Copies all attribute values from
sintothis.Subclasses should extend to also copy any additional state they introduce.
thiswill have been allocated vias->allocNewInstance(g).Note
Stage information is not cloned; set it explicitly if needed.
- Parameters:
s – Source node (same concrete type as
this).
Private Members
-
size_t stage_#
-
bool has_name_ = {false}#
-
bool has_domain_ = {false}#
-
bool has_doc_string_ = {false}#
-
bool has_overload_ = {false}#
Friends
- friend struct Graph
- friend struct Value
-
inline Node *&next_in_graph(size_t i)#
-
class OpSetID#
- #include <ir.h>
Lightweight (domain, version) pair identifying an ONNX operator set.
Provides the same information as
OperatorSetIdProtobut without protobuf overhead, resulting in simpler and more readable code.Public Functions
-
inline explicit OpSetID(const OperatorSetIdProto &proto)#
Constructs an
OpSetIDfrom a protobufOperatorSetIdProto.- Parameters:
proto – Source protobuf message.
-
inline explicit OpSetID(const int64_t version)#
Constructs an
OpSetIDfor the default ONNX domain at the given version.- Parameters:
version – Operator-set version number.
-
inline explicit OpSetID(std::string domain, int64_t version)#
Constructs an
OpSetIDfor the specified domain and version.- Parameters:
domain – Domain string (e.g.
""or"ai.onnx.ml").version – Operator-set version number.
-
inline std::string toString() const#
Returns a string representation in the form
"<domain>$<version>".
-
inline int64_t version() const#
Returns the operator set version number.
-
inline void incrementVersion(int64_t step)#
Increments the version by
step.- Parameters:
step – Amount to add to the current version.
-
inline void setVersion(int64_t newVal)#
Sets the version to
newVal.- Parameters:
newVal – New version number.
Public Static Functions
-
inline explicit OpSetID(const OperatorSetIdProto &proto)#
-
class ResourceGuard#
- #include <ir.h>
RAII guard that invokes a callable destructor when it goes out of scope.
Non-copyable and non-movable. Typically used to restore transient graph state (e.g. stage number) set for the duration of a code region.
Public Functions
-
ONNX_DISALLOW_COPY_AND_ASSIGN(ResourceGuard)#
-
ResourceGuard(ResourceGuard&&) = delete#
-
ResourceGuard &operator=(ResourceGuard&&) = delete#
-
inline ~ResourceGuard()#
Invokes the destructor callable function.
-
ONNX_DISALLOW_COPY_AND_ASSIGN(ResourceGuard)#
-
template<typename T, AttributeKind Kind>
struct ScalarAttributeValue : public ONNX_LIGHT_NAMESPACE::AttributeValue# - #include <ir.h>
Holds a single scalar attribute value of type
Tand kindKind.- Template Parameters:
T – The C++ value type (e.g.
double,int64_t,std::string).Kind – The AttributeKind tag for this type.
Public Functions
-
inline ScalarAttributeValue(Symbol name, ConstructorType value_)#
-
inline virtual Ptr clone() const override#
Returns a deep copy wrapped in a
Ptr.
-
inline virtual AttributeKind kind() const override#
Returns
Kind.
-
struct Use#
- #include <ir.h>
Records a single use of a Value by a Node.
A
Uselinks a producer Value to the Node that consumes it and the position (offset) in that node’s input list where the value appears.Public Functions
-
struct Value#
- #include <ir.h>
A typed SSA value (edge) in the IR graph.
Each
Valueis produced by exactly one Node (its node()) and may be consumed by zero or more nodes, tracked via uses(). The value carries optional type information: ONNX element type (elemType()) and shape (sizes()).Valueobjects are owned by their Graph; do not delete them manually.Public Functions
-
inline Value(Node *node_, size_t offset_)#
Constructs a value produced by
node_at output positionoffset_.
-
~Value() = default#
-
inline Value *setElemType(int32_t elem_type)#
Sets the ONNX element type and returns
thisfor chaining.- Parameters:
elem_type – ONNX DataType enum value.
-
inline int32_t elemType() const#
Returns the ONNX element type.
-
inline bool has_sizes() const#
Returns true if shape information has been set.
-
inline Value *setSizes(std::vector<Dimension> sizes)#
Sets the shape of this value and returns
thisfor chaining.- Parameters:
sizes – Per-dimension size descriptors.
-
inline const std::vector<Dimension> &sizes() const#
Returns the shape dimensions (may be empty if shape is unknown).
-
inline size_t unique() const#
Returns the graph-unique numeric identifier of this value.
-
inline bool has_unique_name() const#
Returns true if an explicit string name has been assigned.
-
inline std::string uniqueName() const#
Returns the string name of this value.
If no explicit name has been set, returns a generated name of the form
"_v_N"whereNis unique().
-
inline Value *setUniqueName(const std::string &name, bool update_related_names = true)#
Sets the string name of this value.
- Parameters:
name – New name for this value.
update_related_names – When true, propagates the rename to initializer entries and captured nodes in subgraphs.
-
inline Value *setStage(size_t s)#
Sets the stage index (forward=0, backward=1, …) and returns
this.- Parameters:
s – New stage index.
-
inline size_t stage() const#
Returns the stage index.
-
inline size_t offset() const#
Returns the output offset within the producing node.
-
inline void replaceAllUsesWith(Value *newValue)#
Replaces all uses of this value with
newValue.Also propagates element type and size information to
newValue, and renames captured references in subgraphs if this value is a graph output.Given: %3 = f(%1, %2) %4 = g(%3) %5 = h(%3, %3) Execute: %3.replaceAllUsesWith(%6) Result: %3 = f(%1, %2) %4 = g(%6) %5 = h(%6, %6)
- Parameters:
newValue – The replacement value (must belong to the same graph).
Private Members
-
size_t offset_#
-
size_t unique_ = 0#
-
size_t stage_ = 0#
-
bool has_unique_name_ = {false}#
-
int32_t elem_type_ = {TensorProto::DataType::UNDEFINED}#
-
bool has_sizes_ = {false}#
Friends
- friend struct Node
- friend struct Graph
-
inline Value(Node *node_, size_t offset_)#
-
template<typename T, AttributeKind Kind>
struct VectorAttributeValue : public ONNX_LIGHT_NAMESPACE::AttributeValue# - #include <ir.h>
Holds a vector attribute value of element type
Tand kindKind.- Template Parameters:
T – The C++ element type (e.g.
double,int64_t).Kind – The AttributeKind tag for this list type.
Public Functions
-
inline virtual AttributeKind kind() const override#
Returns
Kind.
-
inline virtual std::unique_ptr<AttributeValue> clone() const override#
Returns a deep copy wrapped in a
unique_ptr.
-
using FloatAttr = ScalarAttributeValue<double, AttributeKind::f>#