ONE - On-device Neural Engine
Loading...
Searching...
No Matches
onert::ir::Operand Class Reference

#include <Operand.h>

Public Member Functions

 Operand (const Shape &shape, const TypeInfo &type)
 
 Operand (const Operand &)=default
 
const Shapeshape (void) const
 
const TypeInfotypeInfo (void) const
 
const OperandInfoinfo (void) const
 
OperandInfoinfo (void)
 
size_t operandSize (void) const
 
const OperationIndexSetgetUses () const
 
OperationIndex getDef () const
 
void insertUse (const OperationIndex &idx)
 
void removeUse (const OperationIndex &idx)
 
void setDef (const OperationIndex &idx)
 
void unsetDef ()
 
void clearDefUse ()
 
void type (const DataType type)
 
void data (std::shared_ptr< Data > &&data)
 
const Datadata (void) const
 
void releaseData (void)
 
std::shared_ptr< DatashareData (void) const
 
bool isConstant (void) const
 Get true if Operand is const, otherwise false a.
 
template<typename T , typename... Args>
void data (Args &&...args)
 
template<typename T >
asScalar (void) const
 
template<typename T >
std::vector< T > asVector () const
 
void setOriginIndex (OriginIndex origin)
 
OriginIndex originIndex () const
 

Detailed Description

Definition at line 35 of file Operand.h.

Constructor & Destructor Documentation

◆ Operand() [1/2]

onert::ir::Operand::Operand ( const Shape shape,
const TypeInfo type 
)
inlineexplicit

Definition at line 38 of file Operand.h.

40 {
41 // DO NOTHING
42 }
const Shape & shape(void) const
Definition Operand.h:46
void type(const DataType type)
Definition Operand.h:61
@ STATIC
At compile time, shape for a tensor is known, thus requried memory capacity can be calculated.

◆ Operand() [2/2]

onert::ir::Operand::Operand ( const Operand )
explicitdefault

Member Function Documentation

◆ asScalar()

template<typename T >
T onert::ir::Operand::asScalar ( void  ) const
inline

Definition at line 88 of file Operand.h.

89 {
90 assert((shape().rank() == 0) || ((shape().rank() == 1) && (shape().dim(0) == 1)));
91 assert(_data != nullptr);
92 assert((_data->base() != nullptr) && (_data->size() == sizeof(T)));
93
94 return *(reinterpret_cast<const T *>(_data->base()));
95 }

References shape().

Referenced by onert::backend::acl_common::asPixelValue().

◆ asVector()

template<typename T >
std::vector< T > onert::ir::Operand::asVector ( ) const
inline

Definition at line 97 of file Operand.h.

98 {
99 assert(_data != nullptr);
100 assert(_data->size() % sizeof(T) == 0);
101
102 const auto *base = reinterpret_cast<const T *>(_data->base());
103 const std::size_t size = _data->size() / sizeof(T);
104 return std::vector<T>(base, base + size);
105 }
int32_t size[5]
Definition Slice.cpp:35

References size.

◆ clearDefUse()

void Operand::clearDefUse ( )

◆ data() [1/3]

template<typename T , typename... Args>
void onert::ir::Operand::data ( Args &&...  args)
inline

Definition at line 82 of file Operand.h.

83 {
84 data(std::make_unique<T>(std::forward<Args>(args)...));
85 }
const Data * data(void) const
Definition Operand.h:69

References data().

◆ data() [2/3]

◆ data() [3/3]

const Data * onert::ir::Operand::data ( void  ) const
inline

Definition at line 69 of file Operand.h.

69{ return _data.get(); }

Referenced by data(), and data().

◆ getDef()

OperationIndex onert::ir::Operand::getDef ( ) const
inline

Definition at line 53 of file Operand.h.

53{ return _def; }

Referenced by onert::ir::train::TrainableGraph::btopolSortOperations().

◆ getUses()

const OperationIndexSet & onert::ir::Operand::getUses ( ) const
inline

Definition at line 52 of file Operand.h.

52{ return _uses; }

◆ info() [1/2]

OperandInfo & onert::ir::Operand::info ( void  )
inline

Definition at line 49 of file Operand.h.

49{ return _info; }

◆ info() [2/2]

const OperandInfo & onert::ir::Operand::info ( void  ) const
inline

Definition at line 48 of file Operand.h.

48{ return _info; }

Referenced by onert::ir::train::TrainableGraph::changeBackwardShape(), and onert::compiler::StaticShapeInferer::dump().

◆ insertUse()

void Operand::insertUse ( const OperationIndex idx)

Definition at line 41 of file Operand.cc.

41{ _uses.insert(idx); }
void insert(const OperationIndex &index)

References onert::ir::OperationIndexSet::insert().

◆ isConstant()

bool onert::ir::Operand::isConstant ( void  ) const
inline

◆ operandSize()

size_t Operand::operandSize ( void  ) const

Definition at line 24 of file Operand.cc.

25{
26 const uint32_t ranks = shape().rank();
27 int32_t elements = 1;
28
29 for (uint32_t rank = 0; rank < ranks; rank++)
30 {
31 elements *= shape().dim(rank);
32 }
33
35 size_t element_size = sizeOfDataType(type);
36
37 // Value of type is matched with OperandCode enum in NeuralNetworks.h
38 return element_size * elements;
39}
const TypeInfo & typeInfo(void) const
Definition Operand.h:47
DataType type() const
Definition TypeInfo.h:52
DataType
"scalar" value type
Definition DataType.h:27
size_t sizeOfDataType(DataType data_type)
Definition DataType.cc:29

References shape(), onert::ir::sizeOfDataType(), onert::ir::TypeInfo::type(), type(), and typeInfo().

◆ originIndex()

OriginIndex onert::ir::Operand::originIndex ( ) const
inline

Definition at line 108 of file Operand.h.

108{ return _info.originIndex(); }
OriginIndex originIndex() const

References onert::ir::OperandInfo::originIndex().

Referenced by onert::dumper::text::dumpGraph().

◆ releaseData()

void onert::ir::Operand::releaseData ( void  )
inline

Definition at line 71 of file Operand.h.

71{ _data.reset(); }

◆ removeUse()

void Operand::removeUse ( const OperationIndex idx)

Definition at line 43 of file Operand.cc.

43{ _uses.remove(idx); }
void remove(const OperationIndex &index)

References onert::ir::OperationIndexSet::remove().

◆ setDef()

void Operand::setDef ( const OperationIndex idx)

Definition at line 45 of file Operand.cc.

45{ _def = idx; }

◆ setOriginIndex()

void onert::ir::Operand::setOriginIndex ( OriginIndex  origin)
inline

Definition at line 107 of file Operand.h.

107{ _info.setOriginIndex(origin); }
void setOriginIndex(OriginIndex origin)

References onert::ir::OperandInfo::setOriginIndex().

◆ shape()

◆ shareData()

std::shared_ptr< Data > onert::ir::Operand::shareData ( void  ) const
inline

Definition at line 73 of file Operand.h.

73{ return _data; }

Referenced by onert::backend::train::BackendContext::gen(), and onert::backend::basic::initConsts().

◆ type()

void onert::ir::Operand::type ( const DataType  type)
inline

Definition at line 61 of file Operand.h.

61{ _info.type(type); };
void type(const DataType type)
Set tensor data type.

References type(), and onert::ir::OperandInfo::type().

Referenced by operandSize(), and type().

◆ typeInfo()

const TypeInfo & onert::ir::Operand::typeInfo ( void  ) const
inline

Definition at line 47 of file Operand.h.

47{ return _info.typeInfo(); }
const TypeInfo & typeInfo() const
Return tensor data type info.

References onert::ir::OperandInfo::typeInfo().

Referenced by onert::backend::acl_common::asPixelValue(), onert::backend::acl_common::asSet(), and operandSize().

◆ unsetDef()

void Operand::unsetDef ( )

Definition at line 47 of file Operand.cc.

47{ _def = OperationIndex{}; }
::onert::util::Index< uint32_t, OperationIndexTag > OperationIndex
Definition Index.h:32

Referenced by clearDefUse().


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