ONE - On-device Neural Engine
Loading...
Searching...
No Matches
SquaredDifference.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 Samsung Electronics Co., Ltd. All Rights Reserved
3 * Copyright 2018 The TensorFlow Authors. All Rights Reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#include "Builders.h"
19#include "kernels/Utils.h"
20#include "TISOKernel.h"
21
22#include "PALSquaredDifference.h"
23
24namespace luci_interpreter
25{
26
27void configure_kernel_CircleSquaredDifference(const circle::Operator *cur_op,
28 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.output()));
34 LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.input1()) ==
35 Tensor::element_type(kernel.input2()));
36 LUCI_INTERPRETER_CHECK(Tensor::num_elements(kernel.input1()) ==
37 Tensor::num_elements(kernel.output()));
38 LUCI_INTERPRETER_CHECK(Tensor::num_elements(kernel.input1()) ==
39 Tensor::num_elements(kernel.input2()));
40 LUCI_INTERPRETER_CHECK(Tensor::num_dims(kernel.input1()) == Tensor::num_dims(kernel.output()));
41}
42
43void execute_kernel_CircleSquaredDifference(const circle::Operator *cur_op,
44 BaseRuntimeGraph *runtime_graph)
45{
46 kernels::TISOKernel kernel(cur_op, runtime_graph);
47
48 const auto *input_data_1 = runtime_graph->getDataByTensor(kernel.input1());
49 const auto *input_data_2 = runtime_graph->getDataByTensor(kernel.input2());
50 assert(input_data_1);
51 assert(input_data_2);
52
53 auto *output_data = runtime_graph->getDataByTensor(kernel.output());
54
55 switch (Tensor::element_type(kernel.input1()))
56 {
57#ifndef DIS_FLOAT
58 case DataType::FLOAT32:
59 {
60 const float *input_data_1_float = kernels::getTensorData<float>(input_data_1);
61 const float *input_data_2_float = kernels::getTensorData<float>(input_data_2);
62 float *output_data_float = kernels::getTensorData<float>(output_data);
63
64 assert(output_data_float);
65
66 const int flat_size =
67 kernels::getTensorRuntimeShape(kernel.input1(), runtime_graph).flatSize();
68
69 luci_interpreter_pal::SquaredDifference(flat_size, input_data_1_float, input_data_2_float,
70 output_data_float);
71 break;
72 }
73#endif // DIS_FLOAT
74 default:
75 assert(false && "Unsupported type");
76 }
77}
78} // 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
luci_interpreter::RuntimeShape getTensorRuntimeShape(const circle::Tensor *circle_tensor, BaseRuntimeGraph *runtime_graph)
Definition Utils.cpp:29
void SquaredDifference(const int flat_size, const float *input_data_1, const float *input_data_2, float *output_data)
void configure_kernel_CircleSquaredDifference(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
void execute_kernel_CircleSquaredDifference(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)