ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Neg.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 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 "PALNeg.h"
23
24namespace luci_interpreter
25{
26
27void configure_kernel_CircleNeg(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
28{
29 const auto input_index = cur_op->inputs()->operator[](0);
30 const auto output_index = cur_op->outputs()->operator[](0);
31
32 assert(input_index != -1);
33 assert(output_index != -1);
34
35 const auto input = runtime_graph->getCircleTensorByIndex(input_index);
36 const auto output = runtime_graph->getCircleTensorByIndex(output_index);
37
38 LUCI_INTERPRETER_CHECK(Tensor::element_type(input) == Tensor::element_type(output));
39
40 assert(Tensor::num_dims(input) == 4);
41
42 // TODO: enable it only if kernel with dynamic shapes
43 // output-> resize(input->shape());
44}
45
46void execute_kernel_CircleNeg(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
47{
48 const auto input_index = cur_op->inputs()->operator[](0);
49 const auto output_index = cur_op->outputs()->operator[](0);
50
51 assert(input_index != -1);
52 assert(output_index != -1);
53
54 const auto input = runtime_graph->getCircleTensorByIndex(input_index);
55 const auto output = runtime_graph->getCircleTensorByIndex(output_index);
56
57 const uint8_t *input_data = runtime_graph->getDataByTensor(input);
58 uint8_t *output_data = runtime_graph->getDataByTensor(output);
59
60 assert(input_data != nullptr);
61 assert(output_data != nullptr);
62
63 switch (Tensor::element_type(input))
64 {
65#ifndef DIS_FLOAT
66 case DataType::FLOAT32:
67
68 luci_interpreter_pal::Negate(
69 kernels::getTensorShape(input), kernels::getTensorData<float>(input_data),
70 kernels::getTensorShape(output), kernels::getTensorData<float>(output_data));
71
72 break;
73#endif // DIS_FLOAT
74 default:
75 assert(false && "Unsupported type.");
76 }
77}
78
79} // namespace luci_interpreter
const circle::Tensor * getCircleTensorByIndex(int32_t index)
uint8_t * getDataByTensor(const circle::Tensor *raw_tensor)
#define LUCI_INTERPRETER_CHECK(cond)
Definition Utils.h:36
tflite::RuntimeShape getTensorShape(const Tensor *tensor)
Definition Utils.h:194
void configure_kernel_CircleNeg(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
Definition Neg.cpp:27
void execute_kernel_CircleNeg(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
Definition Neg.cpp:46