ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Div.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 "Builders.h"
18#include "kernels/Utils.h"
19
20#include "kernels/BinaryOpCommon.h"
21
22#include "PALDiv.h"
23
24namespace luci_interpreter
25{
26
27// TODO: reduce code duplication with Mul
28void configure_kernel_CircleDiv(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
29{
30 kernels::TISOKernel kernel(cur_op, runtime_graph);
31
32 LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.input1()) ==
33 Tensor::element_type(kernel.input2()));
34 LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.input1()) ==
35 Tensor::element_type(kernel.input2()));
36}
37
38void execute_kernel_CircleDiv(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
39{
40 kernels::TISOKernel kernel(cur_op, runtime_graph);
41
42 const auto *options = cur_op->builtin_options_as_DivOptions();
43
45 kernels::getTensorRuntimeShape(kernel.input1(), runtime_graph);
47 kernels::getTensorRuntimeShape(kernel.input2(), runtime_graph);
48
49 bool is_inplace = runtime_graph->is_inplace_op(cur_op);
50
52 kernels::getTensorRuntimeShape(kernel.output(), runtime_graph);
53
54 switch (Tensor::element_type(kernel.input1()))
55 {
56#ifndef DIS_FLOAT
57 case DataType::FLOAT32:
58 {
59 auto tiso_func = luci_interpreter_pal::Div<float>;
60 auto broadcast_tiso_func = luci_interpreter_pal::BroadcastDiv4DSlow<float>;
61 if (is_inplace)
62 {
63 kernels::evalTISOInplaceKernel<float>(tiso_func, broadcast_tiso_func, &kernel, options,
64 std::move(input_shape1), std::move(input_shape2),
65 std::move(output_shape));
66 }
67 else
68 {
69 kernels::TISOData kernel_data = kernel.readData();
70 kernels::evalTISOKernel<float>(tiso_func, broadcast_tiso_func, &kernel, &kernel_data,
71 options, std::move(input_shape1), std::move(input_shape2),
72 std::move(output_shape));
73 }
74 }
75 break;
76#endif // DIS_FLOAT
77 default:
78 assert(false && "Unsupported type.");
79 }
80}
81
82} // namespace luci_interpreter
bool is_inplace_op(const circle::Operator *op)
const circle::Tensor * output() const
Definition TISOKernel.h:62
const circle::Tensor * input2() const
Definition TISOKernel.h:61
const circle::Tensor * input1() const
Definition TISOKernel.h:60
#define LUCI_INTERPRETER_CHECK(cond)
Definition Utils.h:36
const luci_interpreter::RuntimeShape output_shape
luci_interpreter::RuntimeShape getTensorRuntimeShape(const circle::Tensor *circle_tensor, BaseRuntimeGraph *runtime_graph)
Definition Utils.cpp:29
void execute_kernel_CircleDiv(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
Definition Div.cpp:38
void configure_kernel_CircleDiv(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
Definition Div.cpp:28