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
22#include <stdexcept>
23
24namespace luci_interpreter
25{
26namespace kernels
27{
28
29Pow::Pow(const Tensor *input1, const Tensor *input2, Tensor *output)
30 : Kernel({input1, input2}, {output})
31{
32}
33
35{
36 LUCI_INTERPRETER_CHECK(input1()->element_type() == input2()->element_type());
37 LUCI_INTERPRETER_CHECK(input1()->element_type() == output()->element_type());
38
39 output()->resize(calculateShapeForBroadcast(input1()->shape(), input2()->shape()));
40}
41
42void Pow::execute() const
43{
44 switch (input1()->element_type())
45 {
46 case DataType::FLOAT32:
47 eval<float>();
48 break;
49 case DataType::S32:
50 eval<int32_t>();
51 break;
52 default:
53 throw std::runtime_error("luci-intp Pow Unsupported type.");
54 }
55}
56
57template <typename T> void Pow::eval() const
58{
59 tflite::ArithmeticParams params{};
60
61 const bool need_broadcast = tflite::reference_ops::ProcessBroadcastShapes(
63
64 if (need_broadcast)
65 {
67 getTensorShape(input2()), getTensorData<T>(input2()),
68 getTensorShape(output()), getTensorData<T>(output()));
69 }
70 else
71 {
73 getTensorShape(input2()), getTensorData<T>(input2()),
74 getTensorShape(output()), getTensorData<T>(output()));
75 }
76}
77
78} // namespace kernels
79} // namespace luci_interpreter
void resize(const Shape &new_shape)
Definition Tensor.cpp:56
Tensor * output() const
Definition Pow.h:34
void execute() const override
Definition Pow.cpp:42
const Tensor * input2() const
Definition Pow.h:33
void configure() override
Definition Pow.cpp:34
Pow(const Tensor *input1, const Tensor *input2, Tensor *output)
Definition Pow.cpp:29
const Tensor * input1() const
Definition Pow.h:32
#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)