ONE - On-device Neural Engine
Loading...
Searching...
No Matches
onert::backend::cpu::ops Namespace Reference

Data Structures

class  AddNLayer
 
class  ArgMinMaxLayer
 
class  BatchMatMulLayer
 
class  BatchToSpaceNDLayer
 
class  BinaryArithmeticLayer
 
class  BroadcastToLayer
 
class  CompareLayer
 
class  ConcatLayer
 
union  ConstDataPtr
 
class  ConvolutionLayer
 
union  DataPtr
 
class  DepthToSpaceLayer
 
class  DepthwiseConvolutionLayer
 
class  DetectionPostProcessLayer
 
class  EinsumLayer
 
class  ElementwiseActivationLayer
 
class  ElementwiseBinaryLayer
 
class  ElementwiseUnaryLayer
 
class  ExpandDimsLayer
 
class  FillLayer
 
class  FullyConnectedLayer
 
class  FusedBatchNormLayer
 
class  GatherLayer
 
class  L2NormLayer
 
class  LogSoftMaxLayer
 
class  LSTMLayer
 
class  MatrixBandPartLayer
 
class  MeanLayer
 
class  OneHotLayer
 
class  PackLayer
 
class  PadLayer
 
class  PoolLayer
 
class  PowLayer
 
class  QuantizeLayer
 
class  RangeLayer
 
class  RankLayer
 
class  ReduceLayer
 
class  ReshapeLayer
 
class  ResizeBilinearLayer
 
class  ReverseLayer
 
class  RmsNormLayer
 
class  RoPELayer
 
class  SelectLayer
 
class  ShapeLayer
 
class  SliceLayer
 
class  SoftMaxLayer
 
class  SpaceToBatchNDLayer
 
class  SpaceToDepthLayer
 
class  SplitLayer
 
class  SplitVLayer
 
class  SqDiffLayer
 
class  StatelessRandomUniformLayer
 
class  StridedSliceLayer
 
class  TileLayer
 
class  TransposeLayer
 
class  UnpackLayer
 

Enumerations

enum class  ArithmeticType { kAdd , kSub , kMul , kDiv }
 
enum class  ElementwiseActivationType {
  kElu , kLogistic , kReLU , kTanh ,
  kLeakyReLU
}
 
enum class  ElementwiseBinaryType {
  kFloorDiv , kFloorMod , kLogicalAnd , kLogicalOr ,
  kMax , kMin
}
 
enum class  ElementwiseUnaryType {
  kAbs , kCast , kCos , kDequantize ,
  kErf , kExp , kFloor , kLog ,
  kLogicalNot , kNeg , kQuantize , kRound ,
  kRSqrt , kSin , kSqrt , kSquare ,
  kZerosLike
}
 
enum class  PoolType { kAvg , kL2 , kMax }
 
enum class  ReduceType {
  kSum , kProd , kMax , kMin ,
  kAny , kAll , kInvalid
}
 

Functions

template<typename T >
Array< T > toArray (uint8_t *ptr, std::vector< int32_t > &descr)
 
ggml_type getGGMLType (ir::DataType type)
 
struct ggml_tensor getGGMLTensor (const IPortableTensor *tensor)
 
uint32_t getNumberOfDimensions (const IPortableTensor *tensor)
 
uint32_t getNumberOfElements (const IPortableTensor *tensor)
 
uint32_t getSizeOfDimension (const IPortableTensor *tensor, uint32_t dimensionIdx)
 
void QuantizeMultiplier (double double_multiplier, int32_t *quantized_multiplier, int *shift)
 
void GetQuantizedConvolutionMultiplier (const IPortableTensor *input, const IPortableTensor *filter, const IPortableTensor *bias, const IPortableTensor *output, double *multiplier)
 
void GetQuantizedConvolutionMultipliersAndShifts (float input_scale, float output_scale, const float *filter_scales, size_t filter_scales_size, int num_channels, std::vector< int32_t > &per_channel_output_multiplier, std::vector< int > &per_channel_output_shift)
 
void QuantizeMultiplierGreaterThanOne (double double_multiplier, int32_t *quantized_multiplier, int *left_shift)
 
void CalculateActivationRangeQuantized (ir::Activation activation, const IPortableTensor *output, int32_t *act_min, int32_t *act_max)
 
bool HaveSameShapes (const IPortableTensor *input1, const IPortableTensor *input2)
 
int32_t CalculateInputRadius (int input_integer_bits, int input_left_shift)
 
uint32_t sizeOfData (OperandType type, const std::vector< int32_t > &dimensions)
 
nnfw::cker::PaddingType getPaddingType (ir::PaddingType ir_padding_type)
 
std::vector< int32_t > getReducerAxes (const IPortableTensor *axes)
 
nnfw::cker::RoPEMode getRoPEMode (ir::operation::RoPE::RoPEMode rope_mode)
 
nnfw::cker::Shape getExtendedTensorShape (const IPortableTensor *tensor)
 
nnfw::cker::Shape getShape (const IPortableTensor *tensor)
 
nnfw::cker::FusedActivationFunctionType convertActivationType (const ir::Activation activation)
 
int32_t getAxis (uint32_t rank, int32_t axis)
 
template<typename T >
const T * getBuffer (const IPortableTensor *tensor)
 
template<typename T >
T * getBuffer (IPortableTensor *tensor)
 
template<>
const bool * getBuffer (const IPortableTensor *tensor)
 
template<>
bool * getBuffer (IPortableTensor *tensor)
 
template<typename InputT , typename OutputT >
void affineQuantize (const IPortableTensor *input, IPortableTensor *output)
 
template<typename T >
void GetRawShape (const IPortableTensor *input, T *output_data)
 

Enumeration Type Documentation

◆ ArithmeticType

Enumerator
kAdd 
kSub 
kMul 
kDiv 

Definition at line 34 of file BinaryArithmeticLayer.h.

35{
36 kAdd,
37 kSub,
38 kMul,
39 kDiv,
40};

◆ ElementwiseActivationType

◆ ElementwiseBinaryType

◆ ElementwiseUnaryType

◆ PoolType

Enumerator
kAvg 
kL2 
kMax 

Definition at line 34 of file PoolLayer.h.

◆ ReduceType

Enumerator
kSum 
kProd 
kMax 
kMin 
kAny 
kAll 
kInvalid 

Definition at line 44 of file ReduceLayer.h.

Function Documentation

◆ affineQuantize()

template<typename InputT , typename OutputT >
void onert::backend::cpu::ops::affineQuantize ( const IPortableTensor input,
IPortableTensor output 
)

Definition at line 36 of file QuantizeLayer.cc.

37{
38 nnfw::cker::Quantize(getShape(input), getBuffer<InputT>(input), getShape(output),
39 getBuffer<OutputT>(output), output->data_scale(), output->data_zero_point());
40}
void Quantize(const Shape &input_shape, const InputT *input_data, const Shape &output_shape, OutputT *output_data, const float output_scale, const int32_t output_offset)
Definition Quantize.h:34
nnfw::cker::Shape getShape(const IPortableTensor *tensor)

References getShape(), and nnfw::cker::Quantize().

◆ CalculateActivationRangeQuantized()

void onert::backend::cpu::ops::CalculateActivationRangeQuantized ( ir::Activation  activation,
const IPortableTensor output,
int32_t *  act_min,
int32_t *  act_max 
)

Definition at line 144 of file OperationUtils.cc.

146{
147 int32_t qmin = 0;
148 int32_t qmax = 0;
149
150 switch (output->data_type())
151 {
152 case OperandType::QUANT_UINT8_ASYMM:
153 qmin = std::numeric_limits<uint8_t>::min();
154 qmax = std::numeric_limits<uint8_t>::max();
155 break;
156 case OperandType::QUANT_INT8_ASYMM:
157 case OperandType::QUANT_INT8_SYMM:
158 qmin = std::numeric_limits<int8_t>::min();
159 qmax = std::numeric_limits<int8_t>::max();
160 break;
161 default:
162 throw std::runtime_error("CalculateActivationRangeQuantized: Not supported operand type.");
163 }
164
165 const auto scale = output->data_scale();
166 const auto zero_point = output->data_zero_point();
167 auto quantize = [scale, zero_point](float f) {
168 return zero_point + static_cast<int32_t>(std::round(f / scale));
169 };
170 if (activation == ir::Activation::RELU)
171 {
172 *act_min = std::max(qmin, quantize(0.0));
173 *act_max = qmax;
174 }
175 else if (activation == ir::Activation::RELU6)
176 {
177 *act_min = std::max(qmin, quantize(0.0));
178 *act_max = std::min(qmax, quantize(6.0));
179 }
180 else if (activation == ir::Activation::RELU1)
181 {
182 *act_min = std::max(qmin, quantize(-1.0));
183 *act_max = std::min(qmax, quantize(1.0));
184 }
185 else if (activation == ir::Activation::SIGMOID)
186 {
187 *act_min = std::max(qmin, quantize(0.0));
188 *act_max = std::min(qmax, quantize(1.0));
189 }
190 else if (activation == ir::Activation::NONE)
191 {
192 *act_min = qmin;
193 *act_max = qmax;
194 }
195 else
196 {
197 throw std::runtime_error{"Unsupported fused activation function."};
198 }
199}
std::vector< T > quantize(const float *data, size_t num_elements, float scale, int32_t zero_point)
Definition TestUtils.h:174

References onert::ir::NONE, onert::ir::RELU, onert::ir::RELU1, onert::ir::RELU6, and onert::ir::SIGMOID.

Referenced by onert::backend::cpu::ops::PoolLayer::configure(), onert::backend::cpu::ops::DepthwiseConvolutionLayer::convQ8i(), onert::backend::cpu::ops::DepthwiseConvolutionLayer::convQ8uPerChannel(), onert::backend::cpu::ops::DepthwiseConvolutionLayer::convQ8uPerTensor(), and onert::backend::cpu::ops::FullyConnectedLayer::fullyConnectedQuant8().

◆ CalculateInputRadius()

int32_t onert::backend::cpu::ops::CalculateInputRadius ( int  input_integer_bits,
int  input_left_shift 
)

Definition at line 225 of file OperationUtils.cc.

226{
227 const double max_input_rescaled = 1.0 * ((1 << input_integer_bits) - 1) *
228 (1ll << (31 - input_integer_bits)) / (1ll << input_left_shift);
229 // Tighten bound using floor. Suppose that we could use the exact value.
230 // After scaling the difference, the result would be at the maximum. Thus we
231 // must ensure that our value has lower magnitude.
232 return static_cast<int32_t>(std::floor(max_input_rescaled));
233}

◆ convertActivationType()

nnfw::cker::FusedActivationFunctionType onert::backend::cpu::ops::convertActivationType ( const ir::Activation  activation)
inline

Definition at line 112 of file OperationUtils.h.

113{
114 switch (activation)
115 {
116 case ir::Activation::NONE:
118 case ir::Activation::RELU:
120 case ir::Activation::RELU1:
122 case ir::Activation::RELU6:
124 case ir::Activation::TANH:
126 case ir::Activation::SIGMOID:
128 default:
129 throw std::runtime_error{"CPU backend: Cannot convert activation type"};
130 }
131}

References nnfw::cker::kNone, nnfw::cker::kRelu, nnfw::cker::kRelu1, nnfw::cker::kRelu6, nnfw::cker::kSigmoid, nnfw::cker::kTanh, onert::ir::NONE, onert::ir::RELU, onert::ir::RELU1, onert::ir::RELU6, onert::ir::SIGMOID, and onert::ir::TANH.

Referenced by onert::backend::cpu::ops::FullyConnectedLayer::fullyConnected16x1Float32(), onert::backend::cpu::ops::FullyConnectedLayer::fullyConnectedFloat32(), onert::backend::cpu::ops::FullyConnectedLayer::fullyConnectedHybrid(), onert::backend::cpu::ops::FullyConnectedLayer::fullyConnectedSparseWeight(), and onert::backend::cpu::ops::LSTMLayer::LSTMFloat().

◆ getAxis()

int32_t onert::backend::cpu::ops::getAxis ( uint32_t  rank,
int32_t  axis 
)
inline

Definition at line 133 of file OperationUtils.h.

134{
135 auto ret = axis;
136
137 if (axis < 0)
138 {
139 ret += rank;
140 }
141
142 return ret;
143}

◆ getBuffer() [1/4]

template<typename T >
const T * onert::backend::cpu::ops::getBuffer ( const IPortableTensor tensor)

Definition at line 175 of file OperationUtils.h.

176{
177 return reinterpret_cast<const T *>(tensor->buffer());
178}

References getBuffer().

Referenced by getBuffer(), and getBuffer().

◆ getBuffer() [2/4]

template<>
const bool * onert::backend::cpu::ops::getBuffer ( const IPortableTensor tensor)
inline

Definition at line 185 of file OperationUtils.h.

186{
187 static_assert(sizeof(bool) == 1, "cpu backend supports bool type which is 1 byte");
188 return reinterpret_cast<const bool *>(tensor->buffer());
189}

References getBuffer().

◆ getBuffer() [3/4]

template<typename T >
T * onert::backend::cpu::ops::getBuffer ( IPortableTensor tensor)

Definition at line 180 of file OperationUtils.h.

181{
182 return reinterpret_cast<T *>(tensor->buffer());
183}

References getBuffer().

◆ getBuffer() [4/4]

template<>
bool * onert::backend::cpu::ops::getBuffer ( IPortableTensor tensor)
inline

Definition at line 191 of file OperationUtils.h.

192{
193 static_assert(sizeof(bool) == 1, "cpu backend supports bool type which is 1 byte");
194 return reinterpret_cast<bool *>(tensor->buffer());
195}

References getBuffer().

◆ getExtendedTensorShape()

nnfw::cker::Shape onert::backend::cpu::ops::getExtendedTensorShape ( const IPortableTensor tensor)
inline

Definition at line 73 of file OperationUtils.h.

74{
75 assert(tensor);
76 const int32_t extended_rank = 4;
77 int32_t raw_shape[extended_rank];
78 auto shape = tensor->getShape();
79 uint32_t src = extended_rank - shape.rank();
80 for (uint32_t i = 0; i < extended_rank; ++i)
81 {
82 if (i < src)
83 {
84 raw_shape[i] = 1;
85 }
86 else
87 {
88 raw_shape[i] = shape.dim(i - src);
89 }
90 }
91
92 return nnfw::cker::Shape(extended_rank, raw_shape);
93}

◆ getGGMLTensor()

struct ggml_tensor onert::backend::cpu::ops::getGGMLTensor ( const IPortableTensor tensor)

Definition at line 47 of file GGMLHelper.cc.

48{
49 struct ggml_tensor res;
50
51 res.type = getGGMLType(tensor->data_type());
52 const auto rank = tensor->getShape().rank();
53 for (int i = 0; i < GGML_MAX_DIMS; ++i)
54 {
55 if (i >= rank)
56 res.ne[i] = 1;
57 else
58 res.ne[i] = tensor->getShape().dim(rank - i - 1);
59 }
60
61 res.nb[0] = ggml_type_size(res.type);
62 res.nb[1] = res.nb[0] * (res.ne[0] / ggml_blck_size(res.type));
63 for (int i = 2; i < GGML_MAX_DIMS; ++i)
64 res.nb[i] = res.nb[i - 1] * res.ne[i - 1];
65
66 res.op = GGML_OP_NONE;
67 res.grad = nullptr;
68 res.data = (void *)(tensor->buffer());
69
70 return res;
71}
ggml_type getGGMLType(ir::DataType type)
Definition GGMLHelper.cc:28

References getGGMLType().

Referenced by onert::backend::cpu::ops::FullyConnectedLayer::fullyConnectedGGMLWeight().

◆ getGGMLType()

ggml_type onert::backend::cpu::ops::getGGMLType ( ir::DataType  type)

Definition at line 28 of file GGMLHelper.cc.

29{
30 switch (type)
31 {
32 case ir::DataType::FLOAT32:
33 return GGML_TYPE_F32;
34 case ir::DataType::QUANT_GGML_Q4_0:
35 return GGML_TYPE_Q4_0;
36 case ir::DataType::QUANT_GGML_Q8_0:
37 return GGML_TYPE_Q8_0;
38 case ir::DataType::INT32:
39 return GGML_TYPE_I32;
40 case ir::DataType::INT64:
41 return GGML_TYPE_I64;
42 default:
43 throw std::runtime_error("Unsupported data type");
44 }
45}

Referenced by getGGMLTensor().

◆ getNumberOfDimensions()

uint32_t onert::backend::cpu::ops::getNumberOfDimensions ( const IPortableTensor tensor)

Definition at line 32 of file OperationUtils.cc.

33{
34 assert(tensor);
35 return tensor->getShape().rank();
36}

References getNumberOfDimensions().

◆ getNumberOfElements()

uint32_t onert::backend::cpu::ops::getNumberOfElements ( const IPortableTensor tensor)

Definition at line 38 of file OperationUtils.cc.

39{
40 assert(tensor);
41 uint32_t count = 1;
42 auto shape = tensor->getShape();
43 for (int i = 0; i < shape.rank(); i++)
44 {
45 count *= shape.dim(i);
46 }
47 return count;
48}

References getNumberOfElements().

◆ getPaddingType()

nnfw::cker::PaddingType onert::backend::cpu::ops::getPaddingType ( ir::PaddingType  ir_padding_type)

Definition at line 268 of file OperationUtils.cc.

269{
270 switch (ir_padding_type)
271 {
272 case ir::PaddingType::EXPLICIT:
274 case ir::PaddingType::SAME:
276 case ir::PaddingType::VALID:
278 default:
279 throw std::runtime_error("Wrong padding type.");
280 break;
281 }
282}

References onert::ir::EXPLICIT, getPaddingType(), nnfw::cker::kNone, nnfw::cker::kSame, nnfw::cker::kValid, onert::ir::SAME, and onert::ir::VALID.

Referenced by getPaddingType(), and onert::backend::cpu::ops::ConvolutionLayer::prepare().

◆ GetQuantizedConvolutionMultiplier()

void onert::backend::cpu::ops::GetQuantizedConvolutionMultiplier ( const IPortableTensor input,
const IPortableTensor filter,
const IPortableTensor bias,
const IPortableTensor output,
double *  multiplier 
)

Definition at line 83 of file OperationUtils.cc.

86{
87 const double input_product_scale = input->data_scale() * filter->data_scale();
88 [[maybe_unused]] const double bias_scale =
89 (bias != nullptr) ? bias->data_scale() : input_product_scale;
90 const double output_scale = output->data_scale();
91 // The following conditions must be guaranteed by the training pipeline.
92 assert(std::abs(input_product_scale - bias_scale) <=
93 1e-6 * std::min(input_product_scale, bias_scale));
94 assert(input_product_scale >= 0);
95 assert(input_product_scale < output_scale);
96 *multiplier = input_product_scale / output_scale;
97}

Referenced by onert::backend::cpu::ops::DepthwiseConvolutionLayer::convQ8uPerTensor(), and onert::backend::cpu::ops::FullyConnectedLayer::fullyConnectedQuant8().

◆ GetQuantizedConvolutionMultipliersAndShifts()

void onert::backend::cpu::ops::GetQuantizedConvolutionMultipliersAndShifts ( float  input_scale,
float  output_scale,
const float *  filter_scales,
size_t  filter_scales_size,
int  num_channels,
std::vector< int32_t > &  per_channel_output_multiplier,
std::vector< int > &  per_channel_output_shift 
)

Definition at line 99 of file OperationUtils.cc.

103{
104 // Originates from tflite's PopulateConvolutionQuantizationParams()
105 per_channel_output_multiplier.resize(num_channels);
106 per_channel_output_shift.resize(num_channels);
107
108 const bool is_per_channel = filter_scales_size > 1;
109 auto per_channel_multiplier = per_channel_output_multiplier.data();
110 auto per_channel_shift = per_channel_output_shift.data();
111 for (int i = 0; i < num_channels; ++i)
112 {
113 // If per-tensor quantization parameter is specified, broadcast it along the
114 // quantization dimension (channels_out).
115 const float scale = is_per_channel ? filter_scales[i] : filter_scales[0];
116 const double filter_scale = static_cast<double>(scale);
117 const double effective_output_scale =
118 static_cast<double>(input_scale) * filter_scale / static_cast<double>(output_scale);
119 int32_t significand;
120 int channel_shift;
121 QuantizeMultiplier(effective_output_scale, &significand, &channel_shift);
122 per_channel_multiplier[i] = significand;
123 per_channel_shift[i] = channel_shift;
124 }
125}

References QuantizeMultiplier().

Referenced by onert::backend::cpu::ops::ConvolutionLayer::prepare().

◆ GetRawShape()

template<typename T >
void onert::backend::cpu::ops::GetRawShape ( const IPortableTensor input,
T *  output_data 
)

Definition at line 35 of file ShapeLayer.cc.

36{
37 auto shape = input->getShape();
38 for (int i = 0; i < shape.rank(); ++i)
39 {
40 output_data[i] = static_cast<T>(shape.dim(i));
41 }
42}

Referenced by onert::backend::cpu::ops::ShapeLayer::run().

◆ getReducerAxes()

std::vector< int32_t > onert::backend::cpu::ops::getReducerAxes ( const IPortableTensor axes)

Definition at line 284 of file OperationUtils.cc.

285{
286 std::vector<int32_t> ret;
287
288 auto axes_vals = (axes->getShape().rank() == 0) ? 1 : axes->getShape().dim(0);
289 assert(static_cast<size_t>(axes_vals) == axes->getShape().num_elements());
290 switch (axes->data_type())
291 {
292 case ir::DataType::INT32:
293 {
294 for (int i = 0; i < axes_vals; ++i)
295 ret.emplace_back(*(getBuffer<int32_t>(axes) + i));
296 break;
297 }
298 case ir::DataType::INT64:
299 {
300 for (int i = 0; i < axes_vals; ++i)
301 ret.emplace_back(*(getBuffer<int64_t>(axes) + i));
302 break;
303 }
304 default:
305 throw std::runtime_error("getReducerAxes: Not supported data type");
306 break;
307 }
308 return ret;
309}
ir::DataType data_type() const override final
ir::Shape getShape() const override final
Get ir::Shape of tensor.

References onert::backend::IPortableTensor::data_type(), and onert::backend::IPortableTensor::getShape().

Referenced by onert::backend::train::ops::MeanLayer::backward(), onert::backend::cpu::ops::MeanLayer::MeanFloat32(), onert::backend::cpu::ops::MeanLayer::MeanQuant8(), and onert::backend::cpu::ops::ReduceLayer::run().

◆ getRoPEMode()

nnfw::cker::RoPEMode onert::backend::cpu::ops::getRoPEMode ( ir::operation::RoPE::RoPEMode  rope_mode)

Definition at line 311 of file OperationUtils.cc.

312{
313 switch (rope_mode)
314 {
315 case ir::operation::RoPE::RoPEMode::GPT_NEOX:
317 case ir::operation::RoPE::RoPEMode::GPT_J:
319 default:
320 throw std::runtime_error("Wrong rope mode.");
321 break;
322 }
323}

References onert::ir::operation::RoPE::GPT_J, onert::ir::operation::RoPE::GPT_NEOX, nnfw::cker::kGptJ, and nnfw::cker::kGptNeox.

◆ getShape()

nnfw::cker::Shape onert::backend::cpu::ops::getShape ( const IPortableTensor tensor)
inline

Definition at line 95 of file OperationUtils.h.

96{
97 if (tensor == nullptr)
98 return nnfw::cker::Shape();
99
100 const ir::Shape &shape = tensor->get_info().shape();
101 auto rank = shape.rank();
102 nnfw::cker::Shape ret(rank);
103 auto data = ret.DimsData();
104 for (int i = 0; i < rank; ++i)
105 {
106 data[i] = shape.dim(i);
107 }
108 return ret;
109}

References nnfw::cker::Shape::DimsData().

Referenced by affineQuantize(), onert::backend::cpu::ops::BatchMatMulLayer::batchMatMulFloat32(), onert::backend::cpu::ops::BatchToSpaceNDLayer::batchToSpaceNDGeneric(), onert::backend::cpu::ops::ConcatLayer::concatenationGeneral(), onert::backend::cpu::ops::ConcatLayer::concatenationQuant8(), onert::backend::cpu::ops::ElementwiseActivationLayer::configure(), onert::backend::cpu::ops::DepthwiseConvolutionLayer::convFloat32(), onert::backend::cpu::ops::DepthwiseConvolutionLayer::convQ8i(), onert::backend::cpu::ops::DepthwiseConvolutionLayer::convQ8iHybridPerChannel(), onert::backend::cpu::ops::DepthwiseConvolutionLayer::convQ8uPerChannel(), onert::backend::cpu::ops::DepthwiseConvolutionLayer::convQ8uPerTensor(), onert::backend::cpu::ops::EinsumLayer::einsumFloat32(), onert::backend::cpu::ops::ElementwiseActivationLayer::EvalUsingLookupTable(), onert::backend::cpu::ops::FullyConnectedLayer::fullyConnected16x1Float32(), onert::backend::cpu::ops::FullyConnectedLayer::fullyConnectedFloat32(), onert::backend::cpu::ops::FullyConnectedLayer::fullyConnectedHybrid(), onert::backend::cpu::ops::FullyConnectedLayer::fullyConnectedQuant8(), onert::backend::cpu::ops::FullyConnectedLayer::fullyConnectedSparseWeight(), onert::backend::cpu::ops::FusedBatchNormLayer::fusedbatchnormFloat32(), onert::backend::cpu::ops::LogSoftMaxLayer::logsoftmaxFloat32(), onert::backend::cpu::ops::LogSoftMaxLayer::logsoftmaxQuant8(), onert::backend::cpu::ops::MatrixBandPartLayer::matrixBandPartFloat32(), onert::backend::cpu::ops::MeanLayer::MeanFloat32(), onert::backend::cpu::ops::MeanLayer::MeanQuant8(), onert::backend::cpu::ops::OneHotLayer::oneHotImpl(), onert::backend::cpu::ops::PackLayer::packImpl(), onert::backend::cpu::ops::PadLayer::padImpl(), onert::backend::cpu::ops::PowLayer::powFloat32(), onert::backend::cpu::ops::ConvolutionLayer::prepare(), onert::backend::cpu::ops::FullyConnectedLayer::prepare(), onert::backend::cpu::ops::AddNLayer::run(), onert::backend::cpu::ops::BroadcastToLayer::run(), onert::backend::cpu::ops::FillLayer::run(), onert::backend::cpu::ops::L2NormLayer::run(), onert::backend::cpu::ops::QuantizeLayer::run(), onert::backend::cpu::ops::ReduceLayer::run(), onert::backend::cpu::ops::ResizeBilinearLayer::run(), onert::backend::cpu::ops::ReverseLayer::run(), onert::backend::cpu::ops::RmsNormLayer::run(), onert::backend::cpu::ops::SoftMaxLayer::softmaxFloat32(), onert::backend::cpu::ops::SoftMaxLayer::softmaxQuant8(), onert::backend::cpu::ops::SplitLayer::split(), onert::backend::cpu::ops::SplitVLayer::splitV(), onert::backend::cpu::ops::SqDiffLayer::SqDiffFloat32(), onert::backend::cpu::ops::StatelessRandomUniformLayer::StatelessRandomUniformFloat32(), onert::backend::cpu::ops::TileLayer::tileFloat32(), and onert::backend::cpu::ops::TransposeLayer::transpose().

◆ getSizeOfDimension()

uint32_t onert::backend::cpu::ops::getSizeOfDimension ( const IPortableTensor tensor,
uint32_t  dimensionIdx 
)

Definition at line 50 of file OperationUtils.cc.

51{
52 assert(tensor);
53 auto shape = tensor->getShape();
54 if (dimensionIdx >= static_cast<uint32_t>(shape.rank()))
55 {
56 // TODO, log the error
57 return 0;
58 }
59 return shape.dim(dimensionIdx);
60}

References getSizeOfDimension().

◆ HaveSameShapes()

bool onert::backend::cpu::ops::HaveSameShapes ( const IPortableTensor input1,
const IPortableTensor input2 
)

Definition at line 201 of file OperationUtils.cc.

202{
203 if (input1 == input2)
204 return true;
205 if (input2 == NULL || input2 == NULL)
206 return false;
207
208 if (input1 == NULL)
209 {
210 return (getNumberOfDimensions(input2) == 0);
211 }
212
213 if (getNumberOfDimensions(input1) != getNumberOfDimensions(input2))
214 return false;
215
216 auto shape1 = input1->getShape();
217 auto shape2 = input2->getShape();
218 for (uint32_t i = 0; i < getNumberOfDimensions(input1); i++)
219 if (shape1.dim(i) != shape2.dim(i))
220 return false;
221
222 return true;
223}
uint32_t getNumberOfDimensions(const Shape &shape)
Definition Shape.cpp:58

References getNumberOfDimensions(), and onert::backend::IPortableTensor::getShape().

Referenced by onert::backend::cpu::ops::PowLayer::powFloat32(), and onert::backend::cpu::ops::SelectLayer::run().

◆ QuantizeMultiplier()

void onert::backend::cpu::ops::QuantizeMultiplier ( double  double_multiplier,
int32_t *  quantized_multiplier,
int *  shift 
)

Definition at line 62 of file OperationUtils.cc.

63{
64 if (double_multiplier == 0.)
65 {
66 *quantized_multiplier = 0;
67 *shift = 0;
68 return;
69 }
70 const double q = std::frexp(double_multiplier, shift);
71 auto q_fixed = static_cast<int64_t>(std::round(q * (1ll << 31)));
72
73 assert(q_fixed <= (1ll << 31));
74 if (q_fixed == (1ll << 31))
75 {
76 q_fixed /= 2;
77 ++*shift;
78 }
79 assert(q_fixed <= std::numeric_limits<int32_t>::max());
80 *quantized_multiplier = static_cast<int32_t>(q_fixed);
81}

Referenced by onert::backend::cpu::ops::QuantizeLayer::configure(), onert::backend::cpu::ops::DepthwiseConvolutionLayer::convQ8uPerTensor(), onert::backend::cpu::ops::FullyConnectedLayer::fullyConnectedQuant8(), and GetQuantizedConvolutionMultipliersAndShifts().

◆ QuantizeMultiplierGreaterThanOne()

void onert::backend::cpu::ops::QuantizeMultiplierGreaterThanOne ( double  double_multiplier,
int32_t *  quantized_multiplier,
int *  left_shift 
)

Definition at line 127 of file OperationUtils.cc.

129{
130 assert(double_multiplier > 1.);
131 const double q = std::frexp(double_multiplier, left_shift);
132 int64_t q_fixed = static_cast<int64_t>(std::round(q * (1ll << 31)));
133 assert(q_fixed <= (1ll << 31));
134 if (q_fixed == (1ll << 31))
135 {
136 q_fixed /= 2;
137 ++*left_shift;
138 }
139 assert(*left_shift >= 0);
140 assert(q_fixed <= std::numeric_limits<int32_t>::max());
141 *quantized_multiplier = static_cast<int32_t>(q_fixed);
142}

◆ sizeOfData()

uint32_t onert::backend::cpu::ops::sizeOfData ( OperandType  type,
const std::vector< int32_t > &  dimensions 
)

Definition at line 235 of file OperationUtils.cc.

236{
237 uint32_t size = 4;
238
239 switch (type)
240 {
241 case OperandType::FLOAT32:
242 case OperandType::INT32:
243 case OperandType::UINT32:
244 size = 4;
245 break;
246 case OperandType::BOOL8:
247 case OperandType::QUANT_UINT8_ASYMM:
248 case OperandType::QUANT_INT8_SYMM:
249 size = 1;
250 break;
251 case OperandType::INT64:
252 size = 8;
253 break;
254 default:
255 throw std::runtime_error("Not supported operand type.");
256 break;
257 }
258
259 for (auto &&d : dimensions)
260 {
261 assert(d >= 0);
262 size *= static_cast<uint32_t>(d);
263 }
264
265 return size;
266}
int32_t size[5]
Definition Slice.cpp:35

References size.

Referenced by onert::backend::cpu::ops::SplitLayer::split(), and onert::backend::cpu::ops::SplitVLayer::splitV().

◆ toArray()

template<typename T >
Array< T > onert::backend::cpu::ops::toArray ( uint8_t *  ptr,
std::vector< int32_t > &  descr 
)

Definition at line 264 of file DetectionPostProcessLayer.cc.

265{
266 ndarray::Shape shape(descr.size());
267 for (size_t i = 0; i < descr.size(); ++i)
268 {
269 shape.dim(i) = descr[i];
270 }
271
272 return Array<T>{reinterpret_cast<T *>(ptr), shape};
273}

References ndarray::Shape::dim().