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.
 
OperandInfooperator= (const OperandInfo &origin)=default
 Assign 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 53 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 67 of file OperandInfo.h.

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

◆ 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 89 of file OperandInfo.h.

90 {
92 }
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 132 of file OperandInfo.h.

133 {
134 // Impossible case: constant and dynamic operand
135 assert(!(isDynamic() && _const));
136 return _const;
137 }

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 146 of file OperandInfo.h.

146{ 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 145 of file OperandInfo.h.

145{ return _variable; }

◆ memAllocType()

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

Definition at line 129 of file OperandInfo.h.

129{ return _alloc_type; }

◆ operator=()

OperandInfo & onert::ir::OperandInfo::operator= ( const OperandInfo origin)
default

Assign a new OperandInfo object.

Parameters
[in]origininfo for copy

◆ originIndex()

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

Definition at line 148 of file OperandInfo.h.

148{ return _origin; }

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

◆ setAsConstant()

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

Definition at line 130 of file OperandInfo.h.

130{ _const = true; }

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

◆ setAsNonConst()

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

Definition at line 131 of file OperandInfo.h.

131{ _const = false; }

◆ setAsVariable()

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

Definition at line 138 of file OperandInfo.h.

139 {
140 // Impossible case: constant or dynamic operand
141 // The variable operand with buffer is not supported yet
142 assert(!(isDynamic() || _const));
143 _variable = true;
144 }

References isDynamic().

◆ setDynamic()

◆ setOriginIndex()

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

Definition at line 149 of file OperandInfo.h.

149{ _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 104 of file OperandInfo.h.

104{ 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 22 of file OperandInfo.cc.

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

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 122 of file OperandInfo.h.

122{ _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 118 of file OperandInfo.h.

118{ _typeInfo = typeInfo; }

References typeInfo().

Referenced by typeInfo().


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