5c910109a5e5c1f24b125456b77c4013bed17464
[platform/core/ml/nnfw.git] / runtime / onert / backend / cpu / ops / DepthwiseConvolutionLayer.h
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
20 #include <backend/IPortableTensor.h>
21 #include "OperationUtils.h"
22 #include "../ExternalContext.h"
23
24 #include <exec/IFunction.h>
25
26 namespace onert
27 {
28 namespace backend
29 {
30 namespace cpu
31 {
32 namespace ops
33 {
34
35 class DepthwiseConvolutionLayer : public ::onert::exec::IFunction
36 {
37 public:
38   DepthwiseConvolutionLayer() = default;
39
40 public:
41   void convFloat32();
42
43   void convQ8uPerTensor();
44   void convQ8uPerChannel();
45
46   void convQ8i();
47
48   void configure(const IPortableTensor *input, const IPortableTensor *kernel,
49                  const IPortableTensor *bias, const uint32_t paddingLeft,
50                  const uint32_t paddingRight, const uint32_t paddingTop,
51                  const uint32_t paddingBottom, const uint32_t strideW, const uint32_t strideH,
52                  const uint32_t multiplier, const uint32_t dilationWidth,
53                  const uint32_t dilationHeight, const ir::Activation activation,
54                  IPortableTensor *output, const std::shared_ptr<ExternalContext> &external_context);
55
56   void run() override;
57
58 private:
59   void prepareQ8i();
60   void prepareQ8uPerChannel();
61
62 private:
63   const IPortableTensor *_input{nullptr};
64   const IPortableTensor *_kernel{nullptr};
65   const IPortableTensor *_bias{nullptr};
66   IPortableTensor *_output{nullptr};
67
68   uint32_t _paddingLeft{0};
69   uint32_t _paddingTop{0};
70   uint32_t _paddingRight{0};
71   uint32_t _paddingBottom{0};
72
73   uint32_t _strideWidth{0};
74   uint32_t _strideHeight{0};
75
76   uint32_t _multiplier{0};
77
78   uint32_t _dilationWidth{1};
79   uint32_t _dilationHeight{1};
80
81   ir::Activation _activation{ir::Activation::NONE};
82
83   std::shared_ptr<ExternalContext> _external_context;
84
85   bool _prepared{false};
86
87   // Per channel output multiplier and shift.
88   std::vector<int32_t> _per_channel_output_multiplier;
89   std::vector<int> _per_channel_output_shift;
90 };
91
92 } // namespace ops
93 } // namespace cpu
94 } // namespace backend
95 } // namespace onert
96
97 #endif // __ONERT_KERNEL_CPU_DEPTHWISECONVOLUTIONLAYER_H__