Imported Upstream version 1.7.0
[platform/core/ml/nnfw.git] / runtime / onert / backend / cpu / ops / FullyConnectedLayer.h
1 /*
2  * Copyright (c) 2018 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_BACKEND_CPU_OPS_FULLYCONNECTEDLAYER_H__
18 #define __ONERT_BACKEND_CPU_OPS_FULLYCONNECTEDLAYER_H__
19
20 #include <backend/IPortableTensor.h>
21 #include "OperationUtils.h"
22
23 #include <exec/IFunction.h>
24
25 namespace nnfw
26 {
27 namespace cker
28 {
29 class FCTempArena;
30 }
31 } // namespace nnfw
32
33 namespace onert
34 {
35 namespace backend
36 {
37 namespace cpu
38 {
39 namespace ops
40 {
41
42 class FullyConnectedLayer : public ::onert::exec::IFunction
43 {
44 public:
45   FullyConnectedLayer();
46   ~FullyConnectedLayer();
47
48 public:
49   void fullyConnectedFloat32();
50
51   void fullyConnectedQuant8();
52
53   void fullyConnectedHybrid();
54
55   void configure(const IPortableTensor *input, const IPortableTensor *weights,
56                  const IPortableTensor *bias, ir::Activation activation, IPortableTensor *output);
57
58   void run() override;
59
60   void prepare() override;
61
62 private:
63   const IPortableTensor *_input;
64   const IPortableTensor *_weights;
65   const IPortableTensor *_bias;
66   IPortableTensor *_output;
67
68   ir::Activation _activation;
69   std::unique_ptr<nnfw::cker::FCTempArena> _temp_arena;
70
71   bool _is_hybrid;
72
73 #ifdef USE_RUY_GEMV
74   uint8_t *_cached_weights = nullptr; // weights to be cached and a key
75 #endif
76 };
77
78 } // namespace ops
79 } // namespace cpu
80 } // namespace backend
81 } // namespace onert
82
83 #endif // __ONERT_BACKEND_CPU_OPS_FULLYCONNECTEDLAYER_H__