ONE - On-device Neural Engine
Loading...
Searching...
No Matches
MirrorPad.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 Samsung Electronics Co., Ltd. All Rights Reserved
3 * Copyright 2019 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 "PALMirrorPad.h"
23
24namespace luci_interpreter
25{
26namespace
27{
28constexpr int maxInputSize = 5;
29}
30
31void configure_kernel_CircleMirrorPad(const circle::Operator *cur_op,
32 BaseRuntimeGraph *runtime_graph)
33{
34 kernels::TISOKernel kernel(cur_op, runtime_graph);
35
36 LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.input1()) ==
37 Tensor::element_type(kernel.output()));
38 LUCI_INTERPRETER_CHECK(Tensor::num_dims(kernel.input2()) == 2);
39 LUCI_INTERPRETER_CHECK(Tensor::dim(kernel.input2(), 0) == Tensor::num_dims(kernel.input1()));
40}
41
42void execute_kernel_CircleMirrorPad(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
43{
44 kernels::TISOKernel kernel(cur_op, runtime_graph);
45
47
48 const auto *options = cur_op->builtin_options_as_MirrorPadOptions();
49
50 const auto offset = options->mode() != circle::MirrorPadMode_REFLECT ? 0 : 1;
51 const auto input_dims = Tensor::num_dims(kernel.input1());
52 const auto output_size = Tensor::num_elements(kernel.output());
53
54 int output_dims_num_elements[5];
55 int input_dims_num_elements[5];
56
57 for (int i = 0; i < input_dims; i++)
58 {
59 output_dims_num_elements[i] = 1;
60 input_dims_num_elements[i] = 1;
61 }
62
63 for (int i = input_dims - 2; i >= 0; i--)
64 {
65 output_dims_num_elements[i] =
66 output_dims_num_elements[i + 1] * Tensor::dim(kernel.output(), i + 1);
67
68 input_dims_num_elements[i] =
69 input_dims_num_elements[i + 1] * Tensor::dim(kernel.input1(), i + 1);
70 }
71
72 switch (Tensor::element_type(kernel.input1()))
73 {
74#ifndef DIS_FLOAT
75 case DataType::FLOAT32:
76 {
78 Tensor::element_type(kernel.input2()), data.input2_data,
79 wrap(kernel.input1()->shape()).data(), output_dims_num_elements, input_dims_num_elements,
80 kernels::getTensorData<float>(data.input1_data),
81 kernels::getTensorData<float>(data.output_data), offset, input_dims, output_size);
82
83 break;
84 }
85#endif // DIS_FLOAT
86 default:
87 assert(false && "Unsupported type");
88 }
89}
90
91} // namespace luci_interpreter
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
__global uchar * offset(const Image *img, int x, int y)
Definition helpers.h:540
const T * data(const std::vector< T, Alloc > &v)
void MirrorPad(const luci_interpreter::DataType padding_matrix_type, const uint8_t *padding_matrix_data, const int32_t *input_dims, int *output_dims_num_elements, int *input_dims_num_elements, const T *input_data, T *output_data, const int offset, const int num_dims, const int output_size)
void execute_kernel_CircleMirrorPad(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
Definition MirrorPad.cpp:42
void configure_kernel_CircleMirrorPad(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
Definition MirrorPad.cpp:31
VectorWrapper< T > wrap(const flatbuffers::Vector< T > *vec)
const loco::Dimension & dim(uint32_t axis) const
Definition Tensor.h:44