ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DepthwiseConvolutionLayer.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 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 __ONERT_KERNEL_CPU_DEPTHWISECONVOLUTIONLAYER_H__
18#define __ONERT_KERNEL_CPU_DEPTHWISECONVOLUTIONLAYER_H__
19
21#include "OperationUtils.h"
22#include "../ExternalContext.h"
23#include "../Tensor.h"
24
25#include <exec/IFunction.h>
26
28{
29
31{
32public:
34
35public:
36 void convFloat32();
37
38 void convQ8uPerTensor();
39 void convQ8uPerChannel();
40
41 void convQ8i();
43
44 void configure(const IPortableTensor *input, const IPortableTensor *kernel,
45 const IPortableTensor *bias, const uint32_t paddingLeft,
46 const uint32_t paddingRight, const uint32_t paddingTop,
47 const uint32_t paddingBottom, const uint32_t strideW, const uint32_t strideH,
48 const uint32_t multiplier, const uint32_t dilationWidth,
49 const uint32_t dilationHeight, const ir::Activation activation,
50 IPortableTensor *output, const std::shared_ptr<ExternalContext> &external_context);
51
52 void run() override;
53
54private:
55 void prepareF32();
56 void prepareQ8i();
57 void prepareQ8uPerChannel();
58 void prepareQ8iHybridPerChannel();
59 void ensureQ8iHybridPerChannel();
60
61protected:
62 const IPortableTensor *_input{nullptr};
63 const IPortableTensor *_kernel{nullptr};
64 const IPortableTensor *_bias{nullptr};
66
67 uint32_t _paddingLeft{0};
68 uint32_t _paddingTop{0};
69 uint32_t _paddingRight{0};
70 uint32_t _paddingBottom{0};
71
72 uint32_t _strideWidth{0};
73 uint32_t _strideHeight{0};
74
75 uint32_t _multiplier{0};
76
77 uint32_t _dilationWidth{1};
78 uint32_t _dilationHeight{1};
79
81
82 bool _use_padded_filter{false};
83 std::unique_ptr<Tensor> _padded_filter{nullptr};
84 std::unique_ptr<Tensor> _filter_buffers{nullptr};
85
86private:
87 std::shared_ptr<ExternalContext> _external_context;
88
89 bool _prepared{false};
90
91 // Per channel output multiplier and shift.
92 std::vector<int32_t> _per_channel_output_multiplier;
93 std::vector<int> _per_channel_output_shift;
94
95 // For hybrid
96 bool _is_hybrid{false};
97 std::vector<int8_t> _input_quantized;
98 std::vector<float> _input_scaling_factors;
99 std::vector<int32_t> _input_offsets;
100};
101
102} // namespace onert::backend::cpu::ops
103
104#endif // __ONERT_KERNEL_CPU_DEPTHWISECONVOLUTIONLAYER_H__
A tensor class that is portable for other backends.
void configure(const IPortableTensor *input, const IPortableTensor *kernel, const IPortableTensor *bias, const uint32_t paddingLeft, const uint32_t paddingRight, const uint32_t paddingTop, const uint32_t paddingBottom, const uint32_t strideW, const uint32_t strideH, const uint32_t multiplier, const uint32_t dilationWidth, const uint32_t dilationHeight, const ir::Activation activation, IPortableTensor *output, const std::shared_ptr< ExternalContext > &external_context)