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

Create a value from constant byte array. More...

#include <Nodes.h>

Collaboration diagram for loco::ConstGen:

Public Member Functions

 ConstGen ()=default
 
template<DataType DT>
uint32_t size (void) const
 Return the number of reserved elements.
 
template<DataType DT>
void size (uint32_t size)
 Adjust the number of reserved elements.
 
template<DataType DT>
const DataTypeImpl< DT >::Type & at (uint32_t n) const
 Get the element at a given position @require at(n) is valid only when n < size()
 
template<DataType DT>
DataTypeImpl< DT >::Type & at (uint32_t n)
 Update the element at a given position @require at(n) is valid only when n < size()
 
- Public Member Functions inherited from loco::CanonicalNodeDef< CanonicalOpcode::ConstGen, FixedArity< 0 >::Mixin, With< NodeTrait::DataType >::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 constant byte array.

Note
ConstGen assumes "lexical memory layout".

Let us assume that a 'ConstGen' generates a constant tensor of shape "S". for each valid index I, the corresponding value comes from offset(S, I) where the implementation of "offset" is given as follows:

uint32_t stride(TensorShape shape, uint32_t axis) { uint32_t res = 1; for (uint32_t n = rank(shape) - 1; n > axis; –n) { res *= shape.dim(n); } return res; }

uint32_t offset(TensorShape shape, TensorIndex index) { uint32_t res = 0; for (uint32_t n = 0; n < rank(shape); ++n) { res += index.at(n) * stride(shape, n); } return res; }

Definition at line 215 of file Nodes.h.

Constructor & Destructor Documentation

◆ ConstGen()

loco::ConstGen::ConstGen ( )
default

Member Function Documentation

◆ at() [1/2]

template<DataType DT>
DataTypeImpl< DT >::Type & loco::ConstGen::at ( uint32_t  n)

Update the element at a given position @require at(n) is valid only when n < size()

Definition at line 205 of file Nodes.cpp.

206{
207 assert(dtype() == DT);
208 assert(n < size<DT>());
209 return *(reinterpret_cast<typename DataTypeImpl<DT>::Type *>(_data.data()) + n);
210}

◆ at() [2/2]

template<DataType DT>
const DataTypeImpl< DT >::Type & loco::ConstGen::at ( uint32_t  n) const

Get the element at a given position @require at(n) is valid only when n < size()

Definition at line 198 of file Nodes.cpp.

199{
200 assert(dtype() == DT);
201 assert(n < size<DT>());
202 return *(reinterpret_cast<const typename DataTypeImpl<DT>::Type *>(_data.data()) + n);
203}

Referenced by moco::onnx::Constant_V1::build(), moco::onnx::Constant_V9::build(), and exo::ConstGenConverter::convert().

◆ size() [1/2]

template<DataType DT>
void loco::ConstGen::size ( uint32_t  size)

Adjust the number of reserved elements.

Definition at line 192 of file Nodes.cpp.

193{
194 assert(dtype() == DT);
195 _data.resize(l * sizeof(typename DataTypeImpl<DT>::Type));
196}

◆ size() [2/2]

template<DataType DT>
uint32_t loco::ConstGen::size ( void  ) const

Return the number of reserved elements.

Note
This method returns the number of ELEMENT (not BYTE).

Definition at line 185 of file Nodes.cpp.

186{
187 assert(dtype() == DT);
188 assert(_data.size() % sizeof(typename DataTypeImpl<DT>::Type) == 0);
189 return _data.size() / sizeof(typename DataTypeImpl<DT>::Type);
190}

Referenced by exo::ConstGenConverter::convert().


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