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

Namespaces

namespace  operation
 
namespace  train
 
namespace  verifier
 

Data Structures

class  CachedData
 
class  Coordinates
 Class to represent position(offset) of tensor.
Assume that the front is higher dimensional. i.g. N: 0, C: 1, H: 2, W: 3 for NCHW layout. More...
 
struct  Data
 
struct  Dilation
 
struct  ExplicitPadding
 
class  ExternalData
 
struct  FeatureShape
 Structure to have values of dimensions for feature. More...
 
class  Graph
 
struct  IGraph
 
struct  IOperation
 
class  LayoutSet
 
class  MMapedData
 
class  Model
 
struct  ModelEdge
 
struct  ModelEdgeEqual
 
struct  ModelEdgeHash
 
struct  ModelEdges
 Struct to gather model I/O information in multimodel NN package Model I/O will have role one of below. More...
 
class  NNPkg
 
class  Operand
 
class  OperandConstraint
 
class  OperandIndexSequence
 
class  OperandInfo
 Class to save tensor's shape and type. More...
 
class  Operands
 
class  Operation
 
class  OperationDumper
 
class  OperationIndexSet
 
class  Operations
 
class  OperationValidator
 
struct  OperationVisitor
 
struct  Padding
 
struct  Quantization
 
struct  Shape
 
struct  Sparsity
 Structure for Sparse Tensor. More...
 
struct  Stride
 
class  TypeInfo
 

Typedefs

using OperationIndex = ::onert::util::Index< uint32_t, OperationIndexTag >
 
using OperandIndex = ::onert::util::Index< uint32_t, OperandIndexTag >
 
using IOIndex = ::onert::util::Index< uint32_t, IOIndexTag >
 
using SubgraphIndex = ::onert::util::Index< uint16_t, SubgraphIndexTag >
 
using ModelIndex = ::onert::util::Index< uint16_t, ModelIndexTag >
 
using OriginIndex = ::onert::util::Index< uint32_t, OriginIndexTag >
 
using IODesc = std::tuple< ModelIndex, SubgraphIndex, IOIndex >
 
using ModelEdgeSet = std::unordered_set< ir::ModelEdge, ir::ModelEdgeHash, ir::ModelEdgeEqual >
 
template<typename T >
using OperandIndexMap = std::unordered_map< OperandIndex, T >
 
template<typename T >
using OperationIndexMap = std::unordered_map< OperationIndex, T >
 

Enumerations

enum class  DataType {
  FLOAT32 = 0 , INT32 = 1 , UINT32 = 2 , QUANT_UINT8_ASYMM = 3 ,
  BOOL8 = 4 , UINT8 = 5 , QUANT_INT8_SYMM = 6 , FLOAT16 = 7 ,
  INT64 = 8 , QUANT_INT8_ASYMM = 9 , QUANT_INT16_ASYMM = 10 , QUANT_INT8_SYMM_PER_CHANNEL = 11 ,
  QUANT_INT16_SYMM = 12 , QUANT_GGML_Q4_0 = 13 , QUANT_GGML_Q8_0 = 14
}
 
enum class  Activation {
  NONE = 0 , RELU = 1 , RELU1 = 2 , RELU6 = 3 ,
  TANH = 4 , SIGMOID = 5
}
 
enum class  FullyConnectedWeightsFormat { Default = 0 , Shuffled4x16Int8 = 1 , Shuffled16x1Float32 = 127 }
 
enum class  Layout { UNKNOWN = 0 , NHWC , NCHW }
 
enum class  PermuteType { NHWC_TO_NCHW , NCHW_TO_NHWC , COPY }
 
enum class  OpCode { Invalid , OP , COUNT }
 
enum class  Remove { DUPLICATED = 1 , UNDEFINED = 2 }
 
enum class  MemAllocType { STATIC , DYNAMIC }
 enum class indicating when the memory for a tensor is allocated More...
 
enum class  PaddingType { EXPLICIT = 0 , SAME = 1 , VALID = 2 }
 

Functions

Coordinates convertCoordinates (const Coordinates &coords, const PermuteType &type)
 Convert coordinate for layout change.
 
size_t sizeOfDataType (DataType data_type)
 
template<typename IndexType >
std::ostream & _index_print_impl (std::ostream &o, const std::string &prefix, IndexType index)
 
std::ostream & operator<< (std::ostream &o, const OperationIndex &i)
 
std::ostream & operator<< (std::ostream &o, const OperandIndex &i)
 
std::ostream & operator<< (std::ostream &o, const IOIndex &i)
 
std::ostream & operator<< (std::ostream &o, const SubgraphIndex &i)
 
std::ostream & operator<< (std::ostream &o, const ModelIndex &i)
 
std::ostream & operator<< (std::ostream &o, const OriginIndex &i)
 
std::string to_string (Layout layout)
 
std::ostream & operator<< (std::ostream &o, const IODesc &od)
 
const char * toString (OpCode opcode)
 
OpCode toOpCode (const std::string str)
 
std::string to_string (const PaddingType type)
 Converts a internal padding type to const char*.
 
const ExplicitPadding calculatePadding (const Padding &padding, const FeatureShape &ifm_shape, const FeatureShape &ofm_shape, const Stride &stride, uint32_t kw, uint32_t kh, uint32_t dwf=1, uint32_t dhf=1)
 
bool operator== (const Shape &lhs, const Shape &rhs)
 
bool operator!= (const Shape &lhs, const Shape &rhs)
 
Shape convertShape (const Shape &shape, const PermuteType &type)
 Converts shape when its rank is 4.
 
bool rankMaybeUnspecified (const ir::Shape &shape)
 Find out if tha rank in this shape is "maybe" unspecified. Note that when rank == 0, shape could represent scalar or unspecified rank.
 
bool operator== (const TypeInfo &lhs, const TypeInfo &rhs)
 
bool operator!= (const TypeInfo &lhs, const TypeInfo &rhs)
 
std::ostream & operator<< (std::ostream &o, const OperandIndexSequence &operand_seq)
 
std::unique_ptr< Operationclone (const IOperation &operation)
 

Typedef Documentation

◆ IODesc

using onert::ir::IODesc = typedef std::tuple<ModelIndex, SubgraphIndex, IOIndex>

Definition at line 32 of file NNPkg.h.

◆ IOIndex

using onert::ir::IOIndex = typedef ::onert::util::Index<uint32_t, IOIndexTag>

Definition at line 38 of file Index.h.

◆ ModelEdgeSet

Definition at line 66 of file NNPkg.h.

◆ ModelIndex

using onert::ir::ModelIndex = typedef ::onert::util::Index<uint16_t, ModelIndexTag>

Definition at line 44 of file Index.h.

◆ OperandIndex

using onert::ir::OperandIndex = typedef ::onert::util::Index<uint32_t, OperandIndexTag>

Definition at line 35 of file Index.h.

◆ OperandIndexMap

template<typename T >
using onert::ir::OperandIndexMap = typedef std::unordered_map<OperandIndex, T>

Definition at line 29 of file OperandIndexMap.h.

◆ OperationIndex

using onert::ir::OperationIndex = typedef ::onert::util::Index<uint32_t, OperationIndexTag>

Definition at line 32 of file Index.h.

◆ OperationIndexMap

template<typename T >
using onert::ir::OperationIndexMap = typedef std::unordered_map<OperationIndex, T>

Definition at line 29 of file OperationIndexMap.h.

◆ OriginIndex

using onert::ir::OriginIndex = typedef ::onert::util::Index<uint32_t, OriginIndexTag>

Definition at line 47 of file Index.h.

◆ SubgraphIndex

using onert::ir::SubgraphIndex = typedef ::onert::util::Index<uint16_t, SubgraphIndexTag>

Definition at line 41 of file Index.h.

Enumeration Type Documentation

◆ Activation

enum class onert::ir::Activation
strong
Enumerator
NONE 
RELU 
RELU1 
RELU6 
TANH 
SIGMOID 

Definition at line 27 of file InternalType.h.

28{
29 NONE = 0,
30 RELU = 1,
31 RELU1 = 2,
32 RELU6 = 3,
33 TANH = 4,
34 SIGMOID = 5
35};

◆ DataType

enum class onert::ir::DataType
strong
Enumerator
FLOAT32 
INT32 
UINT32 
QUANT_UINT8_ASYMM 
BOOL8 
UINT8 
QUANT_INT8_SYMM 
FLOAT16 
INT64 
QUANT_INT8_ASYMM 
QUANT_INT16_ASYMM 
QUANT_INT8_SYMM_PER_CHANNEL 
QUANT_INT16_SYMM 
QUANT_GGML_Q4_0 
QUANT_GGML_Q8_0 

Definition at line 27 of file DataType.h.

28{
29 FLOAT32 = 0,
30 INT32 = 1,
31 UINT32 = 2,
33 BOOL8 = 4,
34 UINT8 = 5,
36 FLOAT16 = 7,
37 INT64 = 8,
42 QUANT_GGML_Q4_0 = 13, // 4bit quantization, 32 block, 16bit delta
43 QUANT_GGML_Q8_0 = 14 // 8bit quantization, 32 block, 16bit delta
44};

◆ FullyConnectedWeightsFormat

Enumerator
Default 
Shuffled4x16Int8 
Shuffled16x1Float32 

Definition at line 49 of file InternalType.h.

◆ Layout

enum class onert::ir::Layout
strong
Enumerator
UNKNOWN 
NHWC 
NCHW 

Definition at line 29 of file Layout.h.

30{
31 UNKNOWN = 0,
32 NHWC,
33 NCHW
34};

◆ MemAllocType

enum class onert::ir::MemAllocType
strong

enum class indicating when the memory for a tensor is allocated

Enumerator
STATIC 

At compile time, shape for a tensor is known, thus requried memory capacity can be calculated.

DYNAMIC 

At kernel execution time, shape for a tensor is known, thus requried memory capacity can be calculated.

Definition at line 37 of file OperandInfo.h.

38{
43 STATIC,
44
50};
@ DYNAMIC
At kernel execution time, shape for a tensor is known, thus requried memory capacity can be calculate...
@ STATIC
At compile time, shape for a tensor is known, thus requried memory capacity can be calculated.

◆ OpCode

enum class onert::ir::OpCode
strong
Enumerator
Invalid 
OP 
COUNT 

Definition at line 29 of file OpCode.h.

30{
31 Invalid, //< Unused
32#define OP(Name) Name, //< All operations
33#include "ir/Operations.lst"
34#undef OP
35 COUNT
36};
#define COUNT(X)
Definition Macro.h:20

◆ PaddingType

enum class onert::ir::PaddingType
strong
Enumerator
EXPLICIT 
SAME 
VALID 

Definition at line 31 of file Padding.h.

32{
33 EXPLICIT = 0,
34 SAME = 1,
35 VALID = 2
36};

◆ PermuteType

enum class onert::ir::PermuteType
strong
Enumerator
NHWC_TO_NCHW 
NCHW_TO_NHWC 
COPY 

Definition at line 36 of file Layout.h.

◆ Remove

enum class onert::ir::Remove
strong
Enumerator
DUPLICATED 
UNDEFINED 

Definition at line 30 of file OperandIndexSequence.h.

31{
32 DUPLICATED = 1,
33 UNDEFINED = 2
34};

Function Documentation

◆ _index_print_impl()

template<typename IndexType >
std::ostream & onert::ir::_index_print_impl ( std::ostream &  o,
const std::string &  prefix,
IndexType  index 
)

Definition at line 50 of file Index.h.

51{
52 std::ostringstream oss;
53 if (index.undefined())
54 oss << prefix << std::string("?");
55 else
56 oss << prefix << index.value();
57 return o << std::right << std::setw(4) << oss.str();
58}

Referenced by operator<<(), operator<<(), operator<<(), operator<<(), operator<<(), and operator<<().

◆ calculatePadding()

const ExplicitPadding onert::ir::calculatePadding ( const Padding padding,
const FeatureShape ifm_shape,
const FeatureShape ofm_shape,
const Stride stride,
uint32_t  kw,
uint32_t  kh,
uint32_t  dwf = 1,
uint32_t  dhf = 1 
)

Definition at line 133 of file Padding.cc.

136{
137 if (padding.type == PaddingType::EXPLICIT)
138 {
139 return padding.param;
140 }
141 else if (padding.type == PaddingType::SAME)
142 {
143 return samePadding(ifm_shape, ofm_shape, stride, kw, kh, dwf, dhf);
144 }
145 else if (padding.type == PaddingType::VALID)
146 {
147 return validPadding();
148 }
149 else
150 {
151 throw std::runtime_error{"Cannot handle padding type"};
152 }
153}
PaddingType type
Definition Padding.h:61
ExplicitPadding param
Definition Padding.h:62

References EXPLICIT, onert::ir::Padding::param, SAME, onert::ir::Padding::type, and VALID.

Referenced by onert::backend::acl_common::kernelGenPool2D(), onert::backend::cpu::ops::ConvolutionLayer::run(), onert::backend::ruy::ops::ConvolutionLayer::run(), onert::backend::train::KernelGenerator::visit(), onert::backend::train::KernelGenerator::visit(), and onert::backend::train::KernelGenerator::visit().

◆ clone()

std::unique_ptr< Operation > onert::ir::clone ( const IOperation operation)

Definition at line 60 of file OperationCloner.cc.

61{
62 OperationCloner cloner;
63 operation.accept(cloner);
64 return cloner.releaseClone();
65}
virtual void accept(OperationVisitor &v) const =0

References onert::ir::IOperation::accept().

Referenced by onert::ir::Operations::Operations(), and onert::ir::train::TrainableGraph::TrainableGraph().

◆ convertCoordinates()

Coordinates onert::ir::convertCoordinates ( const Coordinates coords,
const PermuteType type 
)

Convert coordinate for layout change.

Parameters
[in]coordCoordinates to be converted
[in]typePermutation type to be applied to coordinates
Returns
Converted coordinates based on permutation type

Definition at line 26 of file Coordinates.cc.

27{
28 assert(coords.size() == 4);
30 if (type == PermuteType::COPY)
31 return to;
32
33 if (type == PermuteType::NHWC_TO_NCHW)
34 {
35 to.set(1, coords[3]);
36 to.set(2, coords[1]);
37 to.set(3, coords[2]);
38 }
39 else
40 {
41 assert(type == PermuteType::NCHW_TO_NHWC);
42 to.set(1, coords[2]);
43 to.set(2, coords[3]);
44 to.set(3, coords[1]);
45 }
46
47 return to;
48}
Array< CornerBox > coords
Class to represent position(offset) of tensor. Assume that the front is higher dimensional....
Definition Coordinates.h:37
void set(size_t dimension, int32_t coordinate)
Set the coordinate of one of the coordinates.
Definition Coordinates.h:79

References coords, COPY, NCHW_TO_NHWC, NHWC_TO_NCHW, and onert::ir::Coordinates::set().

◆ convertShape()

Shape onert::ir::convertShape ( const Shape shape,
const PermuteType type 
)

Converts shape when its rank is 4.

Returns
Return a shape based on permutation type. If rank is not 4, input shape is returned without conversion.

Definition at line 69 of file Shape.cc.

70{
71 assert(shape.rank() <= Shape::kMaxRank);
72 Shape ret{shape};
73
74 if (type == ir::PermuteType::COPY || shape.rank() < 4)
75 return ret;
76
77 // Permutation changing layout beyond 4-D is not supported yet
78 assert(shape.rank() <= 4);
79
80 if (type == ir::PermuteType::NHWC_TO_NCHW)
81 {
82 ret.dim(1) = shape.dim(3);
83 ret.dim(2) = shape.dim(1);
84 ret.dim(3) = shape.dim(2);
85 return ret;
86 }
87
88 assert(type == ir::PermuteType::NCHW_TO_NHWC);
89 ret.dim(1) = shape.dim(2);
90 ret.dim(2) = shape.dim(3);
91 ret.dim(3) = shape.dim(1);
92 return ret;
93}

References COPY, NCHW_TO_NHWC, and NHWC_TO_NCHW.

Referenced by onert::backend::builtin::kernel::PermuteLayer::run().

◆ operator!=() [1/2]

bool onert::ir::operator!= ( const Shape lhs,
const Shape rhs 
)
inline

Definition at line 138 of file Shape.h.

138{ return lhs.dims() != rhs.dims(); }

◆ operator!=() [2/2]

bool onert::ir::operator!= ( const TypeInfo lhs,
const TypeInfo rhs 
)

Definition at line 44 of file TypeInfo.cc.

44{ return !(lhs == rhs); }

◆ operator<<() [1/8]

std::ostream & onert::ir::operator<< ( std::ostream &  o,
const IODesc od 
)
inline

Definition at line 60 of file NNPkg.h.

61{
62 o << std::get<0>(od).value() << ":" << std::get<1>(od).value() << ":" << std::get<2>(od).value();
63 return o;
64}

◆ operator<<() [2/8]

std::ostream & onert::ir::operator<< ( std::ostream &  o,
const IOIndex i 
)
inline

Definition at line 70 of file Index.h.

71{
72 return _index_print_impl(o, "IO", i);
73}
std::ostream & _index_print_impl(std::ostream &o, const std::string &prefix, IndexType index)
Definition Index.h:50

References _index_print_impl().

◆ operator<<() [3/8]

std::ostream & onert::ir::operator<< ( std::ostream &  o,
const ModelIndex i 
)
inline

Definition at line 80 of file Index.h.

81{
82 return _index_print_impl(o, "MODEL", i);
83}

References _index_print_impl().

◆ operator<<() [4/8]

std::ostream & onert::ir::operator<< ( std::ostream &  o,
const OperandIndex i 
)
inline

Definition at line 65 of file Index.h.

66{
67 return _index_print_impl(o, "%", i);
68}

References _index_print_impl().

◆ operator<<() [5/8]

std::ostream & onert::ir::operator<< ( std::ostream &  o,
const OperandIndexSequence operand_seq 
)

Definition at line 70 of file OperandIndexSequence.cc.

71{
72 std::string delimeter;
73 for (const auto &ind : operand_seq._vec)
74 {
75 o << delimeter << ind;
76 delimeter = ',';
77 }
78 return o;
79}

◆ operator<<() [6/8]

std::ostream & onert::ir::operator<< ( std::ostream &  o,
const OperationIndex i 
)
inline

Definition at line 60 of file Index.h.

61{
62 return _index_print_impl(o, "@", i);
63}

References _index_print_impl().

◆ operator<<() [7/8]

std::ostream & onert::ir::operator<< ( std::ostream &  o,
const OriginIndex i 
)
inline

Definition at line 85 of file Index.h.

86{
87 return _index_print_impl(o, "", i);
88}

References _index_print_impl().

◆ operator<<() [8/8]

std::ostream & onert::ir::operator<< ( std::ostream &  o,
const SubgraphIndex i 
)
inline

Definition at line 75 of file Index.h.

76{
77 return _index_print_impl(o, "SUBGRAPH", i);
78}

References _index_print_impl().

◆ operator==() [1/2]

bool onert::ir::operator== ( const Shape lhs,
const Shape rhs 
)
inline

Definition at line 137 of file Shape.h.

137{ return lhs.dims() == rhs.dims(); }

◆ operator==() [2/2]

bool onert::ir::operator== ( const TypeInfo lhs,
const TypeInfo rhs 
)

Definition at line 24 of file TypeInfo.cc.

25{
26 if (lhs.type() != rhs.type())
27 {
28 return false;
29 }
30
31 if (lhs.zero_point() != rhs.zero_point())
32 {
33 return false;
34 }
35
36 if (lhs.scale() != rhs.scale())
37 {
38 return false;
39 }
40
41 return true;
42}
float scale() const
Definition TypeInfo.h:53
int32_t zero_point() const
Definition TypeInfo.h:55
DataType type() const
Definition TypeInfo.h:52

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

◆ rankMaybeUnspecified()

bool onert::ir::rankMaybeUnspecified ( const ir::Shape shape)
inline

Find out if tha rank in this shape is "maybe" unspecified. Note that when rank == 0, shape could represent scalar or unspecified rank.

See also
https://developer.android.com/ndk/reference/struct/a-neural-networks-operand-type

Definition at line 153 of file Shape.h.

153{ return (shape.rank() == 0); }

◆ sizeOfDataType()

size_t onert::ir::sizeOfDataType ( DataType  data_type)

Definition at line 29 of file DataType.cc.

30{
31 switch (data_type)
32 {
33 case DataType::FLOAT32:
34 return sizeof(float);
35 case DataType::INT32:
36 return sizeof(int32_t);
37 case DataType::UINT32:
38 return sizeof(uint32_t);
39 case DataType::BOOL8:
40 case DataType::QUANT_UINT8_ASYMM:
41 case DataType::UINT8:
42 return sizeof(uint8_t);
43 case DataType::QUANT_INT8_SYMM:
44 case DataType::QUANT_INT8_ASYMM:
45 case DataType::QUANT_INT8_SYMM_PER_CHANNEL:
46 return sizeof(int8_t);
47 case DataType::FLOAT16:
48 return sizeof(float16);
49 case DataType::INT64:
50 return sizeof(int64_t);
51 case DataType::QUANT_INT16_ASYMM:
52 return sizeof(int16_t);
53 case DataType::QUANT_INT16_SYMM:
54 return sizeof(int16_t);
55 default:
56 // ggml block quantize type data size is not supported
57 throw std::runtime_error{"Unsupported type size"};
58 }
59}
Half float16
Definition DataType.cc:22

Referenced by onert::backend::builtin::UserTensor::applyShape(), onert::exec::EdgeTensor::applyShape(), onert::ir::Operand::operandSize(), onert::backend::builtin::kernel::PermuteLayer::optimize(), and onert::ir::OperandInfo::total_size().

◆ to_string() [1/2]

std::string onert::ir::to_string ( const PaddingType  type)
inline

Converts a internal padding type to const char*.

Parameters
[in]typePadding type to be converted
Returns
A string holding the converted value

Definition at line 102 of file Padding.cc.

103{
104 switch (type)
105 {
106 case PaddingType::EXPLICIT:
107 return "Padding::EXPLICIT";
108 case PaddingType::SAME:
109 return "Padding::SAME";
110 case PaddingType::VALID:
111 return "Padding::VALID";
112 default:
113 throw std::runtime_error{"Fail to convert string: wrong padding type"};
114 }
115}

References EXPLICIT, SAME, and VALID.

◆ to_string() [2/2]

std::string onert::ir::to_string ( Layout  layout)
inline

Definition at line 43 of file Layout.h.

44{
45 switch (layout)
46 {
47 case Layout::NHWC:
48 return std::string{"NHWC"};
49 case Layout::NCHW:
50 return std::string{"NCHW"};
51 case Layout::UNKNOWN:
52 return std::string{"UNKNOWN"};
53 default:
54 throw std::runtime_error("WRONG LAYOUT");
55 }
56}

References NCHW, NHWC, and UNKNOWN.

◆ toOpCode()

OpCode onert::ir::toOpCode ( const std::string  str)

Definition at line 36 of file OpCode.cc.

37{
38 static const std::unordered_map<std::string, OpCode> map{
39#define OP(Name) {#Name, OpCode::Name},
40#include "ir/Operations.lst"
41#undef OP
42 };
43 return map.at(str);
44}

◆ toString()

const char * onert::ir::toString ( OpCode  opcode)

Definition at line 26 of file OpCode.cc.

27{
28 static const std::unordered_map<OpCode, const char *> map{{OpCode::Invalid, "Invalid"},
29#define OP(Name) {OpCode::Name, #Name},
30#include "ir/Operations.lst"
31#undef OP
32 {OpCode::COUNT, "COUNT"}};
33 return map.at(opcode);
34}

References COUNT, and Invalid.

Referenced by onert::ir::IOperation::name(), onert::ir::operation::Pool2D::name(), and onert::ir::operation::Reduce::name().