ONE - On-device Neural Engine
Loading...
Searching...
No Matches
MeanLayer.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "MeanLayer.h"
18
19#include "OperationUtils.h"
20
22
23namespace onert
24{
25namespace backend
26{
27namespace cpu
28{
29namespace ops
30{
31
32MeanLayer::MeanLayer() : _input(nullptr), _axes(nullptr), _output(nullptr), _keep_dims(false)
33{
34 // DO NOTHING
35}
36
38{
39 const auto inputShape = getShape(_input);
40 const auto axisVec = getReducerAxes(_axes);
41 bool axis_is_1_and_2 =
42 _keep_dims && inputShape.DimensionsCount() == 4 && axisVec.size() == 2 &&
43 ((axisVec[0] == 1 && axisVec[1] == 2) || (axisVec[0] == 2 && axisVec[1] == 1));
44
45 if (axis_is_1_and_2)
46 {
47 nnfw::cker::MeanAxis1And2(inputShape, getBuffer<float>(_input), getShape(_output),
48 getBuffer<float>(_output));
49 }
50 else
51 {
52 nnfw::cker::Mean(inputShape, getBuffer<float>(_input), getShape(_output),
53 getBuffer<float>(_output), axisVec);
54 }
55}
56
63
65 IPortableTensor *output, bool keep_dims)
66{
67 _input = input;
68 _axes = axes;
69 _output = output;
70 _keep_dims = keep_dims;
71
72 if (_input->data_type() != OperandType::FLOAT32 &&
73 _input->data_type() != OperandType::QUANT_UINT8_ASYMM)
74 throw std::runtime_error{"Mean: unsupported data type"};
75}
76
78{
79 if (_input->data_type() == OperandType::FLOAT32)
80 {
82 }
83 else if (_input->data_type() == OperandType::QUANT_UINT8_ASYMM)
84 {
85 MeanQuant8();
86 }
87 else
88 {
89 throw std::runtime_error{"Mean: unsupported data type"};
90 }
91}
92
93} // namespace ops
94} // namespace cpu
95} // namespace backend
96} // namespace onert
A tensor class that is portable for other backends.
float data_scale() const override final
int32_t data_zero_point() const override final
ir::DataType data_type() const override final
void configure(const IPortableTensor *input, const IPortableTensor *axes, IPortableTensor *output, bool keep_dims)
Definition MeanLayer.cc:64
const IPortableTensor * _input
Definition MeanLayer.h:49
const IPortableTensor * _axes
Definition MeanLayer.h:50
void MeanQ8Asymm(const Shape &input_shape, const In *input_data, float input_scale, int32_t input_offset, const Shape &output_shape, Out *output_data, float output_scale, int32_t output_offset, const std::vector< int > &axes)
Definition ReduceMean.h:221
void MeanAxis1And2(const Shape &input_shape, const In *input_data, const Shape &output_shape, Out *output_data)
Definition ReduceMean.h:233
void Mean(const Shape &input_shape, const In *input_data, const Shape &output_shape, Out *output_data, const std::vector< int > &axes)
Definition ReduceMean.h:211
nnfw::cker::Shape getShape(const IPortableTensor *tensor)
std::vector< int32_t > getReducerAxes(const IPortableTensor *axes)