Imported Upstream version 1.4.0
[platform/core/ml/nnfw.git] / runtime / onert / backend / cpu / ShapeFixer.cc
1 /*
2  * Copyright (c) 2020 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 "ShapeFixer.h"
18
19 #include "kernel/AddLayer.h"
20 #include "kernel/AvgPoolLayer.h"
21 #include "kernel/CastLayer.h"
22 #include "kernel/ConcatLayer.h"
23 #include "kernel/ConvolutionLayer.h"
24 #include "kernel/DepthwiseConvolutionLayer.h"
25 #include "kernel/DivLayer.h"
26 #include "kernel/ExpLayer.h"
27 #include "kernel/FullyConnectedLayer.h"
28 #include "kernel/GatherLayer.h"
29 #include "kernel/MaxPoolLayer.h"
30 #include "kernel/MulLayer.h"
31 #include "kernel/OperationUtils.h"
32 #include "kernel/PermuteLayer.h"
33 #include "kernel/ReshapeLayer.h"
34 #include "kernel/SoftMaxLayer.h"
35 #include "kernel/SubLayer.h"
36
37 #include <backend/Backend.h>
38 #include <backend/IConfig.h>
39 #include <memory>
40 #include <util/Utils.h>
41 #include <util/logging.h>
42
43 #include <stdexcept>
44
45 namespace onert
46 {
47 namespace backend
48 {
49 namespace cpu
50 {
51
52 ShapeFixer::ShapeFixer(const ir::Operands &operand_ctx) : _ctx(operand_ctx) {}
53
54 void ShapeFixer::visit(const ir::operation::Comparison &) { /* DO NOTHING */}
55
56 void ShapeFixer::visit(const ir::operation::Conv2D &) { /* DO NOTHING */}
57
58 void ShapeFixer::visit(const ir::operation::DepthwiseConv2D &) { /* DO NOTHING */}
59
60 void ShapeFixer::visit(const ir::operation::MaxPool2D &) { /* DO NOTHING */}
61
62 void ShapeFixer::visit(const ir::operation::AvgPool2D &) { /* DO NOTHING */}
63
64 void ShapeFixer::visit(const ir::operation::Concat &) { /* DO NOTHING */}
65
66 void ShapeFixer::visit(const ir::operation::Exp &) { /* DO NOTHING */}
67
68 void ShapeFixer::visit(const ir::operation::FullyConnected &) { /* DO NOTHING */}
69
70 void ShapeFixer::visit(const ir::operation::Reshape &) { /* DO NOTHING */}
71
72 void ShapeFixer::visit(const ir::operation::Squeeze &) { /* DO NOTHING */}
73
74 void ShapeFixer::visit(const ir::operation::Softmax &) { /* DO NOTHING */}
75
76 void ShapeFixer::visit(const ir::operation::Gather &) { /* DO NOTHING */}
77
78 void ShapeFixer::visit(const ir::operation::Add &node)
79 {
80   const auto lhs_index{node.getInputs().at(ir::operation::Add::Input::LHS)};
81
82   // Quantization : not supported
83   if (_ctx.at(lhs_index).typeInfo().type() == ir::DataType::QUANT8_ASYMM)
84   {
85     throw std::runtime_error{"ShapeFixer: NYI for quantized Add"};
86   }
87 }
88
89 void ShapeFixer::visit(const ir::operation::Sub &node)
90 {
91   // The same as Add
92   const auto lhs_index{node.getInputs().at(ir::operation::Sub::Input::LHS)};
93
94   // Quantization : not supported
95   if (_ctx.at(lhs_index).typeInfo().type() == ir::DataType::QUANT8_ASYMM)
96   {
97     throw std::runtime_error{"ShapeFixer: NYI for quantized Sub"};
98   }
99 }
100
101 void ShapeFixer::visit(const ir::operation::Mul &node)
102 {
103   // The same as Add
104   const auto lhs_index{node.getInputs().at(ir::operation::Mul::Input::LHS)};
105
106   // Quantization : not supported
107   if (_ctx.at(lhs_index).typeInfo().type() == ir::DataType::QUANT8_ASYMM)
108   {
109     throw std::runtime_error{"ShapeFixer: NYI for quantized Mul"};
110   }
111 }
112
113 void ShapeFixer::visit(const ir::operation::Div &node)
114 {
115   // The same as Add
116   const auto lhs_index{node.getInputs().at(ir::operation::Div::Input::LHS)};
117
118   // Quantization : not supported
119   if (_ctx.at(lhs_index).typeInfo().type() == ir::DataType::QUANT8_ASYMM)
120   {
121     throw std::runtime_error{"ShapeFixer: NYI for quantized Div"};
122   }
123 }
124
125 void ShapeFixer::visit(const ir::operation::Permute &) { /* DO NOTHING */}
126
127 void ShapeFixer::visit(const ir::operation::Custom &) { /* DO NOTHING */}
128
129 void ShapeFixer::visit(const ir::operation::Logistic &) { /* DO NOTHING */}
130
131 void ShapeFixer::visit(const ir::operation::Pad &node)
132 {
133   // TODO: empty this method when quantization is supported
134   const auto lhs_index{node.getInputs().at(ir::operation::Sub::Input::LHS)};
135
136   // Quantization : not supported
137   if (_ctx.at(lhs_index).typeInfo().type() == ir::DataType::QUANT8_ASYMM)
138   {
139     throw std::runtime_error{"ShapeFixer: NYI for quantized Pad"};
140   }
141 }
142
143 void ShapeFixer::visit(const ir::operation::Max &) { /* DO NOTHING */}
144
145 void ShapeFixer::visit(const ir::operation::Min &) { /* DO NOTHING */}
146
147 void ShapeFixer::visit(const ir::operation::Tanh &) { /* DO NOTHING */}
148
149 void ShapeFixer::visit(const ir::operation::Pack &) { /* DO NOTHING */}
150
151 void ShapeFixer::visit(const ir::operation::Unpack &) { /* DO NOTHING */}
152
153 void ShapeFixer::visit(const ir::operation::OneHot &) { /* DO NOTHING */}
154
155 void ShapeFixer::visit(const ir::operation::Cast &) { /* DO NOTHING */}
156
157 void ShapeFixer::visit(const ir::operation::Transpose &) { /* DO NOTHING */}
158
159 void ShapeFixer::visit(const ir::operation::ReduceSum &) { /* DO NOTHING */}
160
161 void ShapeFixer::visit(const ir::operation::ReduceMax &) { /* DO NOTHING */}
162
163 void ShapeFixer::visit(const ir::operation::ReduceMin &) { /* DO NOTHING */}
164
165 void ShapeFixer::visit(const ir::operation::Slice &) { /* DO NOTHING */}
166
167 void ShapeFixer::visit(const ir::operation::StridedSlice &) { /* DO NOTHING */}
168
169 void ShapeFixer::visit(const ir::operation::Split &) { /* DO NOTHING */}
170
171 void ShapeFixer::visit(const ir::operation::Abs &) { /* DO NOTHING */}
172
173 void ShapeFixer::visit(const ir::operation::Sin &) { /* DO NOTHING */}
174
175 void ShapeFixer::visit(const ir::operation::RSQRT &) { /* DO NOTHING */}
176
177 void ShapeFixer::visit(const ir::operation::Shape &) { /* DO NOTHING */}
178
179 } // namespace cpu
180 } // namespace backend
181 } // namespace onert