ONE - On-device Neural Engine
Loading...
Searching...
No Matches
loco::Pull Class Referencefinal

Create a value from user data. More...

#include <Nodes.h>

Collaboration diagram for loco::Pull:

Public Member Functions

 Pull ()=default
 
void index (const GraphInputIndex &index)
 
GraphInputIndex index (void) const
 Get associated input index.
 
bool indexed (void) const
 Check whether index is initialized.
 
void dtype (const DataType &d)
 
DataType dtype (void) const
 
- Public Member Functions inherited from loco::CanonicalNodeDef< CanonicalOpcode::Pull, FixedArity< 0 >::Mixin, With< NodeTrait::TensorShape >::Mixin >
virtual ~CanonicalNodeDef ()=default
 
uint32_t opnum (void) const final
 
CanonicalOpcode opcode (void) const final
 
- Public Member Functions inherited from loco::CanonicalNode
virtual ~CanonicalNode ()=default
 
const Dialectdialect (void) const final
 Return "Dialect" identifier that this node belongs to.
 
template<typename T >
accept (CanonicalNodeVisitorBase< T > *) const
 
template<typename T >
accept (CanonicalNodeMutableVisitorBase< T > *)
 
- Public Member Functions inherited from loco::Node
 Node ()=default
 
 Node (const Node &)=delete
 
 Node (Node &&)=delete
 
virtual ~Node ()
 
Graphgraph (void)
 
const Graphgraph (void) const
 
virtual uint32_t arity (void) const =0
 Return the number of arguments.
 
virtual Nodearg (uint32_t N) const =0
 Access N-th argument node.
 
virtual void drop (void)=0
 Drop all the reference of arguments.
 
- Public Member Functions inherited from loco::AnnotatedItem< NodeAnnotation >
 AnnotatedItem ()=default
 
virtual ~AnnotatedItem ()=default
 
const T * annot (void) const
 Retrieve a stored annotation of type T.
 
void annot (std::unique_ptr< T > &&p)
 Attach or remove a new annotation of type T.
 

Detailed Description

Create a value from user data.

Definition at line 93 of file Nodes.h.

Constructor & Destructor Documentation

◆ Pull()

loco::Pull::Pull ( )
default

Member Function Documentation

◆ dtype() [1/2]

void loco::Pull::dtype ( const DataType d)

Definition at line 129 of file Nodes.cpp.

130{
131 // ASSUMPTION: "dtype" is never invalidated!
132 assert(dt != loco::DataType::Unknown);
133 // ASSUMPTION
134 //
135 // It is possible to update index multiple times, but only with the same value!
136 if (indexed())
137 {
138 assert(dtype_assignable(graph()->inputs()->at(_index)->dtype(), dt));
139 graph()->inputs()->at(_index)->dtype(dt);
140 return;
141 }
142
143 // Use local cache
144 _dtype = dt;
145}
InputContext * inputs(void)
Definition Graph.h:220
const DataType & dtype(void) const
Definition Graph.h:63
Graph * graph(void)
Definition Node.h:70
T * at(uint32_t n) const
Access N-th object.
Definition ObjectPool.h:41
DataType dtype(void) const
Definition Nodes.cpp:147
bool indexed(void) const
Check whether index is initialized.
Definition Nodes.h:118

References loco::ObjectPool< T >::at(), loco::Mixin< Trait::DataTyped >::dtype(), dtype(), loco::Node::graph(), indexed(), and loco::Graph::inputs().

◆ dtype() [2/2]

DataType loco::Pull::dtype ( void  ) const

Definition at line 147 of file Nodes.cpp.

148{
149 if (graph() != nullptr and _index >= 0)
150 {
151 assert(_dtype == DataType::Unknown);
152 return graph()->inputs()->at(_index)->dtype();
153 }
154 else
155 {
156 return _dtype;
157 }
158}

References loco::ObjectPool< T >::at(), loco::Mixin< Trait::DataTyped >::dtype(), loco::Node::graph(), and loco::Graph::inputs().

Referenced by dtype(), and index().

◆ index() [1/2]

void loco::Pull::index ( const GraphInputIndex index)

Definition at line 90 of file Nodes.cpp.

91{
92 // ASSUMPTION
93 //
94 // It is possible to update index multiple times, but only with the same value!
95 assert(!indexed() or _index == index);
96
97 if (indexed())
98 {
99 assert(_index == index);
100 return;
101 }
102
103 // Push internally stores "GraphInputIndex" as int64_t
104 _index = static_cast<int64_t>(index);
105
106 // ASSUMPTION: The return value of graph() never changes!
107 if (graph() != nullptr && _dtype != loco::DataType::Unknown)
108 {
109 // Update Graph-level input only if it is not yet specified
110 if (graph()->inputs()->at(_index)->dtype() == DataType::Unknown)
111 {
112 graph()->inputs()->at(_index)->dtype(_dtype);
113 }
114 assert(graph()->inputs()->at(_index)->dtype() == _dtype);
115 graph()->inputs()->at(_index)->dtype(_dtype);
116
117 // Reset the locally cached data
118 _dtype = DataType::Unknown;
119 }
120}
GraphInputIndex index(void) const
Get associated input index.
Definition Nodes.cpp:122

References loco::ObjectPool< T >::at(), loco::Mixin< Trait::DataTyped >::dtype(), dtype(), loco::Node::graph(), index(), indexed(), and loco::Graph::inputs().

Referenced by GraphTestcase< GraphCode::AvgPool2D >::GraphTestcase(), GraphTestcase< GraphCode::MaxPool2D >::GraphTestcase(), GraphTestcase< GraphCode::TensorConcat >::GraphTestcase(), GraphTestcase< GraphCode::TensorTranspose >::GraphTestcase(), loco::link(), and InputLayer::operator()().

◆ index() [2/2]

GraphInputIndex loco::Pull::index ( void  ) const

Get associated input index.

The behavior of this method is undefined when "index" is not set before.

NOTE This method intentionally returns "GraphInputIndex" instead of "const GraphInputIndex &" not to expose the internal implementation details.

Definition at line 122 of file Nodes.cpp.

123{
124 assert(_index >= std::numeric_limits<GraphInputIndex>::min());
125 assert(_index <= std::numeric_limits<GraphInputIndex>::max());
126 return static_cast<GraphInputIndex>(_index);
127}
uint32_t GraphInputIndex

Referenced by index().

◆ indexed()

bool loco::Pull::indexed ( void  ) const
inline

Check whether index is initialized.

NOTE "indexed" method does not validate whether index is in a valid range

Definition at line 118 of file Nodes.h.

118{ return _index != -1; }

Referenced by dtype(), and index().


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