Imported Upstream version 1.25.0
[platform/core/ml/nnfw.git] / runtime / onert / backend / cpu / ops / PowLayer.cc
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 "PowLayer.h"
18
19 #include <cker/operation/Pow.h>
20 #include <cker/operation/BinaryArithmeticOps.h>
21
22 namespace onert
23 {
24 namespace backend
25 {
26 namespace cpu
27 {
28 namespace ops
29 {
30
31 void PowLayer::powFloat32()
32 {
33   float output_activation_min = 0, output_activation_max = 0;
34   CalculateActivationRange(_activation, &output_activation_min, &output_activation_max);
35   nnfw::cker::BinaryArithmeticOpParam op_params;
36   op_params.float_activation_max = output_activation_max;
37   op_params.float_activation_min = output_activation_min;
38
39   if (!HaveSameShapes(_lhs, _rhs))
40   {
41     nnfw::cker::BroadcastBinaryArithmeticOp<nnfw::cker::BinaryArithmeticOpType::POW>(
42       op_params, getShape(_lhs), getBuffer<float>(_lhs), getShape(_rhs), getBuffer<float>(_rhs),
43       getShape(_output), getBuffer<float>(_output));
44     return;
45   }
46
47   nnfw::cker::powImpl(getShape(_lhs), getBuffer<float>(_lhs), getShape(_rhs),
48                       getBuffer<float>(_rhs), getShape(_output), getBuffer<float>(_output));
49 }
50
51 void PowLayer::configure(const IPortableTensor *lhs, const IPortableTensor *rhs,
52                          ir::Activation activation, IPortableTensor *output)
53 {
54   _lhs = lhs;
55   _rhs = rhs;
56   _activation = activation;
57   _output = output;
58 }
59
60 void PowLayer::run()
61 {
62   if (_output->data_type() == OperandType::FLOAT32)
63     powFloat32();
64   else
65     throw std::runtime_error{"Pow: unsupportted data type"};
66 }
67
68 } // namespace ops
69 } // namespace cpu
70 } // namespace backend
71 } // namespace onert