ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Square.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#include "Builders.h"
17#include "kernels/Utils.h"
18#include "SISOKernel.h"
19
20#include "PALSquare.h"
21
22namespace luci_interpreter
23{
24void configure_kernel_CircleSquare(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
25{
26 kernels::SISOKernel kernel(cur_op, runtime_graph);
27
28 LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.input()) ==
29 Tensor::element_type(kernel.output()));
30
31 // check that input and output dimensions are equal
32 int N = Tensor::num_dims(kernel.input());
33 LUCI_INTERPRETER_CHECK(N == Tensor::num_dims(kernel.output()));
34
35 // check that sizes of all dimensions are equal
36 for (int i = 0; i < N; ++i)
37 {
39 kernels::getTensorShape(kernel.output()).dims(i));
40 }
41}
42
43void execute_kernel_CircleSquare(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
44{
45 kernels::SISOKernel kernel(cur_op, runtime_graph);
46
47 const auto *input_data = runtime_graph->getDataByTensor(kernel.input());
48 assert(input_data);
49
50 auto *output_data = runtime_graph->getDataByTensor(kernel.output());
51
52 bool is_inplace = runtime_graph->is_inplace_op(cur_op);
53
54 switch (Tensor::element_type(kernel.input()))
55 {
56#ifndef DIS_FLOAT
57 case DataType::FLOAT32:
58 {
59 const float *input_data_float = kernels::getTensorData<float>(input_data);
60 float *output_data_float = kernels::getTensorData<float>(output_data);
61 if (is_inplace)
62 {
63 output_data_float = const_cast<float *>(input_data_float);
64 }
65
66 assert(output_data_float);
67
68 const int flat_size =
69 kernels::getTensorRuntimeShape(kernel.input(), runtime_graph).flatSize();
70
71 luci_interpreter_pal::Square(flat_size, input_data_float, output_data_float);
72 break;
73 }
74#endif // DIS_FLOAT
75 default:
76 assert(false && "Unsupported type");
77 }
78
79 if (is_inplace)
80 runtime_graph->makeInplaceOperation(kernel.input(), kernel.output());
81}
82
83} // namespace luci_interpreter
void makeInplaceOperation(const circle::Tensor *src_tensor, const circle::Tensor *dst_tensor)
bool is_inplace_op(const circle::Operator *op)
uint8_t * getDataByTensor(const circle::Tensor *raw_tensor)
const circle::Tensor * output() const
Definition SISOKernel.h:47
const circle::Tensor * input() const
Definition SISOKernel.h:46
#define LUCI_INTERPRETER_CHECK(cond)
Definition Utils.h:36
tflite::RuntimeShape getTensorShape(const Tensor *tensor)
Definition Utils.h:194
luci_interpreter::RuntimeShape getTensorRuntimeShape(const circle::Tensor *circle_tensor, BaseRuntimeGraph *runtime_graph)
Definition Utils.cpp:29
void Square(const int flat_size, const float *input_data, float *output_data)
void configure_kernel_CircleSquare(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
Definition Square.cpp:24
void execute_kernel_CircleSquare(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
Definition Square.cpp:43