ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 33 of file Operand.h.

Constructor & Destructor Documentation

◆ Operand() [1/2]

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

Definition at line 36 of file Operand.h.

38 {
39 // DO NOTHING
40 }
const Shape & shape(void) const
Definition Operand.h:44
void type(const DataType type)
Definition Operand.h:59
@ 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 86 of file Operand.h.

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

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 95 of file Operand.h.

96 {
97 assert(_data != nullptr);
98 assert(_data->size() % sizeof(T) == 0);
99
100 const auto *base = reinterpret_cast<const T *>(_data->base());
101 const std::size_t size = _data->size() / sizeof(T);
102 return std::vector<T>(base, base + size);
103 }
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 80 of file Operand.h.

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

References data().

◆ data() [2/3]

◆ data() [3/3]

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

Definition at line 67 of file Operand.h.

67{ return _data.get(); }

Referenced by data(), and data().

◆ getDef()

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

Definition at line 51 of file Operand.h.

51{ return _def; }

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

◆ getUses()

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

Definition at line 50 of file Operand.h.

50{ return _uses; }

◆ info() [1/2]

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

Definition at line 47 of file Operand.h.

47{ return _info; }

◆ info() [2/2]

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

Definition at line 46 of file Operand.h.

46{ return _info; }

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

◆ insertUse()

void Operand::insertUse ( const OperationIndex idx)

Definition at line 39 of file Operand.cc.

39{ _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 22 of file Operand.cc.

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

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

◆ originIndex()

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

Definition at line 106 of file Operand.h.

106{ 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 69 of file Operand.h.

69{ _data.reset(); }

◆ removeUse()

void Operand::removeUse ( const OperationIndex idx)

Definition at line 41 of file Operand.cc.

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

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

◆ setDef()

void Operand::setDef ( const OperationIndex idx)

Definition at line 43 of file Operand.cc.

43{ _def = idx; }

◆ setOriginIndex()

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

Definition at line 105 of file Operand.h.

105{ _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 71 of file Operand.h.

71{ 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 59 of file Operand.h.

59{ _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 45 of file Operand.h.

45{ 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 45 of file Operand.cc.

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

Referenced by clearDefUse().


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