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

Class to save tensor's shape and type. More...

#include <OperandInfo.h>

Public Member Functions

 OperandInfo ()=delete
 Construct a new OperandInfo object (deleted)
 
 OperandInfo (const Shape &shape, const TypeInfo &typeInfo, MemAllocType alloc_type, bool is_const=false, bool is_variable=false, OriginIndex origin=OriginIndex())
 Construct a new OperandInfo object.
 
 OperandInfo (const OperandInfo &origin)=default
 Construct a new OperandInfo object.
 
const Shapeshape () const
 Return tensor shape.
 
Shapeshape ()
 Return mutable tensor shape.
 
void shape (const ir::Shape &new_shape)
 set shape
 
const TypeInfotypeInfo () const
 Return tensor data type info.
 
void typeInfo (const ir::TypeInfo &typeInfo)
 Set type information.
 
void type (const DataType type)
 Set tensor data type.
 
size_t total_size () const
 Return size of tensor (bytes)
 
MemAllocType memAllocType () const
 
void setAsConstant ()
 
void setAsNonConst ()
 
bool isConstant () const
 
void setAsVariable ()
 
bool isVariable () const
 
bool isDynamic () const
 
void setDynamic ()
 
OriginIndex originIndex () const
 
void setOriginIndex (OriginIndex origin)
 

Static Public Member Functions

static OperandInfo createStaticInfo (const Shape &shape, const TypeInfo &typeInfo)
 Create a static OperandInfo object.
 

Detailed Description

Class to save tensor's shape and type.

Definition at line 55 of file OperandInfo.h.

Constructor & Destructor Documentation

◆ OperandInfo() [1/3]

onert::ir::OperandInfo::OperandInfo ( )
delete

Construct a new OperandInfo object (deleted)

Referenced by createStaticInfo().

◆ OperandInfo() [2/3]

onert::ir::OperandInfo::OperandInfo ( const Shape shape,
const TypeInfo typeInfo,
MemAllocType  alloc_type,
bool  is_const = false,
bool  is_variable = false,
OriginIndex  origin = OriginIndex() 
)
inline

Construct a new OperandInfo object.

Parameters
[in]shapeTensor shape
[in]typeInfoTensor data type
[in]alloc_typeWhen the thesor needs memory allocation

Definition at line 69 of file OperandInfo.h.

71 : _shape(shape), _typeInfo(typeInfo), _alloc_type(alloc_type), _const(is_const),
72 _variable(is_variable), _origin(origin)
73 {
74 // DO NOTHING
75 }
const TypeInfo & typeInfo() const
Return tensor data type info.
const Shape & shape() const
Return tensor shape.
Definition OperandInfo.h:95

◆ OperandInfo() [3/3]

onert::ir::OperandInfo::OperandInfo ( const OperandInfo origin)
default

Construct a new OperandInfo object.

Parameters
[in]origininfo for copy

Member Function Documentation

◆ createStaticInfo()

static OperandInfo onert::ir::OperandInfo::createStaticInfo ( const Shape shape,
const TypeInfo typeInfo 
)
inlinestatic

Create a static OperandInfo object.

Definition at line 85 of file OperandInfo.h.

86 {
88 }
OperandInfo()=delete
Construct a new OperandInfo object (deleted)
@ STATIC
At compile time, shape for a tensor is known, thus requried memory capacity can be calculated.

References OperandInfo(), shape(), onert::ir::STATIC, and typeInfo().

◆ isConstant()

bool onert::ir::OperandInfo::isConstant ( ) const
inline

Definition at line 128 of file OperandInfo.h.

129 {
130 // Impossible case: constant and dynamic operand
131 assert(!(isDynamic() && _const));
132 return _const;
133 }

References isDynamic().

Referenced by onert::backend::basic::ExternalTensor::ExternalTensor(), onert::backend::IPortableTensor::is_constant(), and onert::ir::Operand::isConstant().

◆ isDynamic()

bool onert::ir::OperandInfo::isDynamic ( ) const
inline

Definition at line 142 of file OperandInfo.h.

142{ return _alloc_type == MemAllocType::DYNAMIC; }
@ DYNAMIC
At kernel execution time, shape for a tensor is known, thus requried memory capacity can be calculate...

References onert::ir::DYNAMIC.

Referenced by onert::compiler::StaticShapeInferer::dump(), onert::backend::basic::ExternalTensor::ExternalTensor(), onert::backend::IPortableTensor::is_dynamic(), isConstant(), and setAsVariable().

◆ isVariable()

bool onert::ir::OperandInfo::isVariable ( ) const
inline

Definition at line 141 of file OperandInfo.h.

141{ return _variable; }

◆ memAllocType()

MemAllocType onert::ir::OperandInfo::memAllocType ( ) const
inline

Definition at line 125 of file OperandInfo.h.

125{ return _alloc_type; }

◆ originIndex()

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

Definition at line 144 of file OperandInfo.h.

144{ return _origin; }

Referenced by onert::ir::Operand::originIndex().

◆ setAsConstant()

void onert::ir::OperandInfo::setAsConstant ( )
inline

Definition at line 126 of file OperandInfo.h.

126{ _const = true; }

Referenced by onert::ir::Operand::data().

◆ setAsNonConst()

void onert::ir::OperandInfo::setAsNonConst ( )
inline

Definition at line 127 of file OperandInfo.h.

127{ _const = false; }

◆ setAsVariable()

void onert::ir::OperandInfo::setAsVariable ( )
inline

Definition at line 134 of file OperandInfo.h.

135 {
136 // Impossible case: constant or dynamic operand
137 // The variable operand with buffer is not supported yet
138 assert(!(isDynamic() || _const));
139 _variable = true;
140 }

References isDynamic().

◆ setDynamic()

◆ setOriginIndex()

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

Definition at line 145 of file OperandInfo.h.

145{ _origin = origin; }

Referenced by onert::ir::Operand::setOriginIndex().

◆ shape() [1/3]

Shape & onert::ir::OperandInfo::shape ( )
inline

Return mutable tensor shape.

Returns
Tensor shape

Definition at line 100 of file OperandInfo.h.

100{ return _shape; }

Referenced by RandomDataGenerator.RandomDataGenerator::_gen_float32(), RandomDataGenerator.RandomDataGenerator::_gen_int16(), and RandomDataGenerator.RandomDataGenerator::_gen_uint8().

◆ shape() [2/3]

◆ shape() [3/3]

void onert::ir::OperandInfo::shape ( const ir::Shape new_shape)
inline

◆ total_size()

size_t onert::ir::OperandInfo::total_size ( ) const

Return size of tensor (bytes)

Returns
Tensor size

Definition at line 24 of file OperandInfo.cc.

25{
26 const auto data_type = _typeInfo.type();
27 try
28 {
29 return _shape.num_elements() * sizeOfDataType(data_type);
30 }
31 catch (const std::runtime_error &e)
32 {
33 // Calculate total size for ggml block quantization type on exception handling
34 // because it is rare case and we should care about performance on non-block case.
35 if (data_type != DataType::QUANT_GGML_Q4_0 && data_type != DataType::QUANT_GGML_Q8_0)
36 throw e;
37
38 if (_shape.dim(_shape.rank() - 1) % 32 != 0)
39 throw std::runtime_error{
40 "Block quantization requires the last dimension to be a multiple of 32"};
41
42 const auto num_blocks = _shape.num_elements() / 32;
43 const auto block_size = data_type == DataType::QUANT_GGML_Q4_0
44 ? (sizeof(uint8_t) * 32 / 2 + sizeof(uint16_t))
45 : (sizeof(uint8_t) * 32 + sizeof(uint16_t));
46 return num_blocks * block_size;
47 }
48}
DataType type() const
Definition TypeInfo.h:52
size_t sizeOfDataType(DataType data_type)
Definition DataType.cc:29

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

Referenced by onert::exec::EdgeTensor::allocate_buffer(), onert::backend::basic::Tensor::applyShape(), onert::exec::EdgeTensor::applyShape(), and onert::backend::IPortableTensor::total_size().

◆ type()

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

Set tensor data type.

Definition at line 118 of file OperandInfo.h.

118{ _typeInfo.type(type); }
void type(const DataType type)
Set tensor data type.

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

Referenced by onert::ir::Operand::type(), and type().

◆ typeInfo() [1/2]

◆ typeInfo() [2/2]

void onert::ir::OperandInfo::typeInfo ( const ir::TypeInfo typeInfo)
inline

Set type information.

Parameters
[in]typeInfoType information

Definition at line 114 of file OperandInfo.h.

114{ _typeInfo = typeInfo; }

References typeInfo().

Referenced by typeInfo().


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