ONE - On-device Neural Engine
Loading...
Searching...
No Matches
ResizeNearestNeighbor.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3 * Copyright 2023 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 "PALResizeNearestNeighbor.h"
23
24namespace luci_interpreter
25{
26
27void configure_kernel_CircleResizeNearestNeighbor(const circle::Operator *cur_op,
28 BaseRuntimeGraph *runtime_graph)
29{
30 // Check of the size of input. Should be 2
31 LUCI_INTERPRETER_CHECK(cur_op->inputs()->size() == 2);
32 const kernels::TISOKernel tiso_kernel(cur_op, runtime_graph);
33
34 LUCI_INTERPRETER_CHECK(Tensor::element_type(tiso_kernel.input1()) ==
35 Tensor::element_type(tiso_kernel.output()));
36 LUCI_INTERPRETER_CHECK(Tensor::num_dims(tiso_kernel.input1()) == 4);
37 LUCI_INTERPRETER_CHECK(Tensor::num_dims(tiso_kernel.input2()) == 1);
38 LUCI_INTERPRETER_CHECK(Tensor::element_type(tiso_kernel.input2()) == DataType::S32);
39 LUCI_INTERPRETER_CHECK(Tensor::dim(tiso_kernel.input2(), 0) == 2);
40
41 const auto *params = cur_op->builtin_options_as_ResizeNearestNeighborOptions();
42 if (params->half_pixel_centers() && params->align_corners())
43 assert(false && "If half_pixel_centers is True, align_corners must be False.");
44}
45
46void execute_kernel_CircleResizeNearestNeighbor(const circle::Operator *cur_op,
47 BaseRuntimeGraph *runtime_graph)
48{
49 kernels::TISOKernel tiso_kernel(cur_op, runtime_graph);
50 kernels::TISOData tiso_data = tiso_kernel.readData();
51
52 // Get parameters
53 const auto *op_params = cur_op->builtin_options_as_ResizeNearestNeighborOptions();
54
56 params.align_corners = op_params->align_corners();
57 params.half_pixel_centers = false;
58
59 const uint8_t *input_data = runtime_graph->getDataByTensor(tiso_kernel.input1());
60 const uint8_t *size_data = runtime_graph->getConstDataByTensor(tiso_kernel.input2());
61 uint8_t *output_data = runtime_graph->getDataByTensor(tiso_kernel.output());
62
63 switch (Tensor::element_type(tiso_kernel.output()))
64 {
65#ifndef DIS_FLOAT
66 case DataType::FLOAT32:
67 luci_interpreter_pal::ResizeNearestNeighbor(
68 params, kernels::getTensorRuntimeShape(tiso_kernel.input1(), runtime_graph),
69 kernels::getTensorData<float>(input_data),
70 kernels::getTensorRuntimeShape(tiso_kernel.input2(), runtime_graph),
71 kernels::getTensorData<int32_t>(size_data),
72 kernels::getTensorRuntimeShape(tiso_kernel.output(), runtime_graph),
73 kernels::getTensorData<float>(output_data));
74 break;
75#endif // DIS_FLOAT
76 default:
77 assert(false && "Unsupported type.");
78 }
79}
80
81} // namespace luci_interpreter
uint8_t * getConstDataByTensor(const circle::Tensor *raw_tensor)
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 execute_kernel_CircleResizeNearestNeighbor(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
void configure_kernel_CircleResizeNearestNeighbor(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
const loco::Dimension & dim(uint32_t axis) const
Definition Tensor.h:44