ONE - On-device Neural Engine
Loading...
Searching...
No Matches
ConvolutionCommon.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 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#ifndef LUCI_INTERPRETER_KERNELS_CONVOLUTIONCOMMON_H
18#define LUCI_INTERPRETER_KERNELS_CONVOLUTIONCOMMON_H
19
20#include "Builders.h"
21#include "Utils.h"
22
23namespace luci_interpreter
24{
25
26int32_t computeConvPadding(const circle::Tensor *input, const circle::Tensor *filter,
27 circle::Padding padding, int32_t stride, int32_t dilation, int axis);
28
30 const circle::Tensor *filter,
31 const circle::Tensor *output,
32 const circle::Conv2DOptions *options);
33
34namespace kernels
35{
36
37// Conv2D kernel for downsampling
39{
40public:
42
43 explicit DownsamplingConv2DKernel(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
44 : _runtime_graph(runtime_graph)
45 {
46 const auto input_index = cur_op->inputs()->operator[](0);
47 const auto filter_index = cur_op->inputs()->operator[](1);
48 const auto bias_index = cur_op->inputs()->operator[](2);
49 const auto output_index = cur_op->outputs()->operator[](0);
50
51 assert(input_index != -1);
52 assert(filter_index != -1);
53 assert(output_index != -1);
54
55 _input_tensor = _runtime_graph->getCircleTensorByIndex(input_index);
56 _filter_tensor = _runtime_graph->getCircleTensorByIndex(filter_index);
57 _bias_tensor = _runtime_graph->getCircleTensorByIndex(bias_index);
58 _output_tensor = _runtime_graph->getCircleTensorByIndex(output_index);
59
60 assert(_input_tensor != nullptr);
61 assert(_filter_tensor != nullptr);
62 }
63
64 const circle::Tensor *input() const { return _input_tensor; }
65 const circle::Tensor *filter() const { return _filter_tensor; }
66 const circle::Tensor *bias() const { return _bias_tensor; }
67 const circle::Tensor *output() const { return _output_tensor; }
68
69 BaseRuntimeGraph *runtime_graph() const { return _runtime_graph; }
70
71private:
72 const circle::Tensor *_input_tensor;
73 const circle::Tensor *_filter_tensor;
74 const circle::Tensor *_bias_tensor;
75 const circle::Tensor *_output_tensor;
76
77 BaseRuntimeGraph *_runtime_graph;
78};
79
80} // namespace kernels
81} // namespace luci_interpreter
82
83#endif // LUCI_INTERPRETER_KERNELS_CONVOLUTIONCOMMON_H
const circle::Tensor * getCircleTensorByIndex(int32_t index)
DownsamplingConv2DKernel(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
luci_interpreter_pal::ConvParams createConv2DParams(const circle::Tensor *input, const circle::Tensor *filter, const circle::Tensor *output, const circle::Conv2DOptions *options)
int32_t computeConvPadding(const circle::Tensor *input, const circle::Tensor *filter, circle::Padding padding_type, int32_t stride, int32_t dilation, int axis)
This file contains utility macro.