ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Pow.cpp
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 "kernels/Pow.h"
18#include "kernels/Utils.h"
19
20#include <tensorflow/lite/kernels/internal/reference/reference_ops.h>
21
22namespace luci_interpreter
23{
24namespace kernels
25{
26
27Pow::Pow(const Tensor *input1, const Tensor *input2, Tensor *output)
28 : Kernel({input1, input2}, {output})
29{
30}
31
32void Pow::configure()
33{
34 LUCI_INTERPRETER_CHECK(input1()->element_type() == input2()->element_type());
35 LUCI_INTERPRETER_CHECK(input1()->element_type() == output()->element_type());
36 // TODO: enable it only if kernel with dynamic shapes
37 output()->resize(calculateShapeForBroadcast(input1()->shape(), input2()->shape()));
38}
39
40void Pow::execute() const
41{
42 switch (input1()->element_type())
43 {
44 case DataType::FLOAT32:
45 eval<float>();
46 break;
47 case DataType::S32:
48 eval<int32_t>();
49 break;
50 default:
51 assert(false && "Unsupported type.");
52 }
53}
54
55template <typename T> void Pow::eval() const
56{
57 tflite::ArithmeticParams params{};
58
59 const bool need_broadcast = tflite::reference_ops::ProcessBroadcastShapes(
60 getTensorShape(input1()), getTensorShape(input2()), &params);
61
62 if (need_broadcast)
63 {
64 tflite::reference_ops::BroadcastPow4DSlow(getTensorShape(input1()), getTensorData<T>(input1()),
65 getTensorShape(input2()), getTensorData<T>(input2()),
66 getTensorShape(output()), getTensorData<T>(output()));
67 }
68 else
69 {
70 tflite::reference_ops::Pow(getTensorShape(input1()), getTensorData<T>(input1()),
71 getTensorShape(input2()), getTensorData<T>(input2()),
72 getTensorShape(output()), getTensorData<T>(output()));
73 }
74}
75
76} // namespace kernels
77} // namespace luci_interpreter
Pow(const Tensor *input1, const Tensor *input2, Tensor *output)
Definition Pow.cpp:29
#define LUCI_INTERPRETER_CHECK(cond)
Definition Utils.h:36
Shape calculateShapeForBroadcast(const Shape &input1_shape, const Shape &input2_shape)
Definition Utils.cpp:204
tflite::RuntimeShape getTensorShape(const Tensor *tensor)
Definition Utils.h:194
void BroadcastPow4DSlow(const RuntimeShape &unextended_input1_shape, const T *input1_data, const RuntimeShape &unextended_input2_shape, const T *input2_data, const RuntimeShape &unextended_output_shape, T *output_data)
void Pow(const RuntimeShape &input1_shape, const T *input1_data, const RuntimeShape &input2_shape, const T *input2_data, const RuntimeShape &output_shape, T *output_data)