ONE - On-device Neural Engine
Loading...
Searching...
No Matches
DepthwiseConv2D.cpp
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#include "OMStatus.h"
18
19#include "core/OMUtils.h"
20#include "core/OMKernelData.h"
21
23
25#include "execute/OMUtils.h"
26
27using namespace onert_micro;
28using namespace onert_micro::core;
29
30namespace
31{
32
33constexpr uint32_t inputTensorIdx = 0;
34constexpr uint32_t weightTensorIdx = 1;
35constexpr uint32_t biasTensorIdx = 2;
36
37constexpr uint32_t outputTensorIdx = 0;
38
39} // namespace
40
41namespace onert_micro
42{
43namespace import
44{
45
47{
48 OMRuntimeContext &runtime_context = config_args.runtime_context;
49 uint16_t op_index = config_args.kernel_index;
50
51 execute::OMRuntimeKernel runtime_kernel;
52 runtime_kernel.readKernel(op_index, runtime_context);
53
54 const circle::Tensor *input = runtime_kernel.inputs[inputTensorIdx];
55 const circle::Tensor *weight = runtime_kernel.inputs[weightTensorIdx];
56 const circle::Tensor *bias = runtime_kernel.inputs[biasTensorIdx];
57
58 const circle::Tensor *output = runtime_kernel.outputs[outputTensorIdx];
59
60 assert(input != nullptr);
61 assert(weight != nullptr);
62 // Bias can be nullptr
63 assert(output != nullptr);
64
65 OMStatus status = Ok;
66 const auto *options = runtime_kernel.first_operator->builtin_options_as_DepthwiseConv2DOptions();
67
68 core::OMRuntimeShape input_shape(input);
69 core::OMRuntimeShape weight_shape(weight);
70 core::OMRuntimeShape bias_shape(bias);
72
73 status = utils::checkCondition(input->type() == output->type());
74 if (status != Ok)
75 return status;
76
77 status = utils::checkCondition(input->type() == weight->type());
78 if (status != Ok)
79 return status;
80
81 status = utils::checkCondition(input_shape.dimensionsCount() == 4);
82 if (status != Ok)
83 return status;
84
85 status = utils::checkCondition(input_shape.dimensionsCount() == output_shape.dimensionsCount());
86 if (status != Ok)
87 return status;
88
89 status = utils::checkCondition(input_shape.dimensionsCount() == weight_shape.dimensionsCount());
90 if (status != Ok)
91 return status;
92
93 const auto output_depth = output_shape.dims(3);
94
95 status = utils::checkCondition(
96 bias == nullptr or (bias_shape.dimensionsCount() == 1 && bias_shape.dims(0) == output_depth));
97 if (status != Ok)
98 return status;
99
100 switch (options->fused_activation_function())
101 {
102 case circle::ActivationFunctionType_NONE:
103 case circle::ActivationFunctionType_RELU:
104 case circle::ActivationFunctionType_RELU6:
105 case circle::ActivationFunctionType_RELU_N1_TO_1:
106 break;
107 default:
109 }
110
111 if (input->type() == circle::TensorType_FLOAT32)
112 {
113 status = utils::checkCondition(bias == nullptr or input->type() == bias->type());
114 return status;
115 }
116
117 auto input_quant = input->quantization();
118 auto filter_quant = weight->quantization();
119 auto output_quant = output->quantization();
120
121 status = utils::checkCondition(input_quant != nullptr and filter_quant != nullptr and
122 output_quant != nullptr);
123 if (status != Ok)
124 return status;
125
126 auto input_scales = input_quant->scale();
127 auto filter_scales = filter_quant->scale();
128 auto output_scales = output_quant->scale();
129
130 status = utils::checkCondition(input_scales != nullptr and filter_scales != nullptr and
131 output_scales != nullptr);
132 if (status != Ok)
133 return status;
134
135 // Support only per channel
136 status = utils::checkCondition(filter_scales->size() > 1);
137 if (status != Ok)
138 return status;
139
140 return status;
141}
142
143} // namespace import
144} // namespace onert_micro
int32_t dimensionsCount() const
Definition Tensor.h:106
int32_t dims(int i) const
Definition Tensor.h:108
size_t dimensionsCount() const noexcept
const circle::Operator * first_operator
OMStatus readKernel(uint16_t op_index, core::OMRuntimeContext &runtime_context)
const circle::Tensor * outputs[maxOutputSize]
const circle::Tensor * inputs[maxInputSize]
const luci_interpreter::RuntimeShape output_shape
constexpr uint32_t outputTensorIdx
OMStatus configure_kernel_CircleDepthwiseConv2D(const OMConfigureArgs &config_args)
@ UnsupportedActivation
Definition OMStatus.h:28
core::OMRuntimeContext & runtime_context