ONE - On-device Neural Engine
Loading...
Searching...
No Matches
FloorDiv.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 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 "PALFloorDiv.h"
23
24namespace luci_interpreter
25{
26
27void configure_kernel_CircleFloorDiv(const circle::Operator *cur_op,
28 BaseRuntimeGraph *runtime_graph)
29{
30 kernels::TISOKernel kernel(cur_op, runtime_graph);
31
32 CheckBinaryOpDataTypesEqual(kernel);
33}
34
35void execute_kernel_CircleFloorDiv(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
36{
37 kernels::TISOKernel kernel(cur_op, runtime_graph);
38
39 const auto *options = cur_op->builtin_options_as_FloorDivOptions();
40
42 kernels::getTensorRuntimeShape(kernel.input1(), runtime_graph);
44 kernels::getTensorRuntimeShape(kernel.input2(), runtime_graph);
46 kernels::getTensorRuntimeShape(kernel.output(), runtime_graph);
47
48 const uint8_t *input_data1 = runtime_graph->getDataByTensor(kernel.input1());
49 const uint8_t *input_data2 = runtime_graph->getDataByTensor(kernel.input2());
50 uint8_t *output_data = runtime_graph->getDataByTensor(kernel.output());
51
52 assert(input_data1 != nullptr);
53 assert(input_data2 != nullptr);
54 assert(output_data != nullptr);
55
56 switch (Tensor::element_type(kernel.input1()))
57 {
58#ifndef DIS_FLOAT
59 case DataType::FLOAT32:
60 {
61 // Check the denominator
62 for (int i = 0; i < input_shape2.flatSize(); ++i)
63 {
64 LUCI_INTERPRETER_CHECK(kernels::getTensorData<float>(input_data2)[i] != 0);
65 }
66 // check that input and output dimensions are equal
67 if (kernels::areShapesEqual(input_shape1, input_shape2))
68 {
69 const int flat_size = input_shape1.flatSize();
70 luci_interpreter_pal::FloorDiv(flat_size, kernels::getTensorData<float>(input_data1),
71 kernels::getTensorData<float>(input_data2),
72 kernels::getTensorData<float>(output_data));
73 }
74 else
75 {
77 input_shape1, kernels::getTensorData<float>(input_data1), input_shape2,
78 kernels::getTensorData<float>(input_data2), output_shape,
79 kernels::getTensorData<float>(output_data));
80 }
81 }
82 break;
83#endif // DIS_FLOAT
84 default:
85 assert(false && "Unsupported type.");
86 }
87}
88
89} // namespace luci_interpreter
uint8_t * getDataByTensor(const circle::Tensor *raw_tensor)
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
bool areShapesEqual(const luci_interpreter::RuntimeShape &input_shape1, const luci_interpreter::RuntimeShape &input_shape2)
Definition Utils.cpp:89
luci_interpreter::RuntimeShape getTensorRuntimeShape(const circle::Tensor *circle_tensor, BaseRuntimeGraph *runtime_graph)
Definition Utils.cpp:29
void FloorDiv(const int flat_size, const float *input1_data, const float *input2_data, float *output_data)
void BroadcastFloorDiv4DSlow(const luci_interpreter::RuntimeShape &input1_shape, const float *input1_data, const luci_interpreter::RuntimeShape &input2_shape, const float *input2_data, const luci_interpreter::RuntimeShape &output_shape, float *output_data)
void execute_kernel_CircleFloorDiv(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
Definition FloorDiv.cpp:35
void configure_kernel_CircleFloorDiv(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
Definition FloorDiv.cpp:27