2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "ShapeFixer.h"
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"
37 #include <backend/Backend.h>
38 #include <backend/IConfig.h>
40 #include <util/Utils.h>
41 #include <util/logging.h>
52 ShapeFixer::ShapeFixer(const ir::Operands &operand_ctx) : _ctx(operand_ctx) {}
54 void ShapeFixer::visit(const ir::operation::Comparison &) { /* DO NOTHING */}
56 void ShapeFixer::visit(const ir::operation::Conv2D &) { /* DO NOTHING */}
58 void ShapeFixer::visit(const ir::operation::DepthwiseConv2D &) { /* DO NOTHING */}
60 void ShapeFixer::visit(const ir::operation::MaxPool2D &) { /* DO NOTHING */}
62 void ShapeFixer::visit(const ir::operation::AvgPool2D &) { /* DO NOTHING */}
64 void ShapeFixer::visit(const ir::operation::Concat &) { /* DO NOTHING */}
66 void ShapeFixer::visit(const ir::operation::Exp &) { /* DO NOTHING */}
68 void ShapeFixer::visit(const ir::operation::FullyConnected &) { /* DO NOTHING */}
70 void ShapeFixer::visit(const ir::operation::Reshape &) { /* DO NOTHING */}
72 void ShapeFixer::visit(const ir::operation::Squeeze &) { /* DO NOTHING */}
74 void ShapeFixer::visit(const ir::operation::Softmax &) { /* DO NOTHING */}
76 void ShapeFixer::visit(const ir::operation::Gather &) { /* DO NOTHING */}
78 void ShapeFixer::visit(const ir::operation::Add &node)
80 const auto lhs_index{node.getInputs().at(ir::operation::Add::Input::LHS)};
82 // Quantization : not supported
83 if (_ctx.at(lhs_index).typeInfo().type() == ir::DataType::QUANT8_ASYMM)
85 throw std::runtime_error{"ShapeFixer: NYI for quantized Add"};
89 void ShapeFixer::visit(const ir::operation::Sub &node)
92 const auto lhs_index{node.getInputs().at(ir::operation::Sub::Input::LHS)};
94 // Quantization : not supported
95 if (_ctx.at(lhs_index).typeInfo().type() == ir::DataType::QUANT8_ASYMM)
97 throw std::runtime_error{"ShapeFixer: NYI for quantized Sub"};
101 void ShapeFixer::visit(const ir::operation::Mul &node)
104 const auto lhs_index{node.getInputs().at(ir::operation::Mul::Input::LHS)};
106 // Quantization : not supported
107 if (_ctx.at(lhs_index).typeInfo().type() == ir::DataType::QUANT8_ASYMM)
109 throw std::runtime_error{"ShapeFixer: NYI for quantized Mul"};
113 void ShapeFixer::visit(const ir::operation::Div &node)
116 const auto lhs_index{node.getInputs().at(ir::operation::Div::Input::LHS)};
118 // Quantization : not supported
119 if (_ctx.at(lhs_index).typeInfo().type() == ir::DataType::QUANT8_ASYMM)
121 throw std::runtime_error{"ShapeFixer: NYI for quantized Div"};
125 void ShapeFixer::visit(const ir::operation::Permute &) { /* DO NOTHING */}
127 void ShapeFixer::visit(const ir::operation::Custom &) { /* DO NOTHING */}
129 void ShapeFixer::visit(const ir::operation::Logistic &) { /* DO NOTHING */}
131 void ShapeFixer::visit(const ir::operation::Pad &node)
133 // TODO: empty this method when quantization is supported
134 const auto lhs_index{node.getInputs().at(ir::operation::Sub::Input::LHS)};
136 // Quantization : not supported
137 if (_ctx.at(lhs_index).typeInfo().type() == ir::DataType::QUANT8_ASYMM)
139 throw std::runtime_error{"ShapeFixer: NYI for quantized Pad"};
143 void ShapeFixer::visit(const ir::operation::Max &) { /* DO NOTHING */}
145 void ShapeFixer::visit(const ir::operation::Min &) { /* DO NOTHING */}
147 void ShapeFixer::visit(const ir::operation::Tanh &) { /* DO NOTHING */}
149 void ShapeFixer::visit(const ir::operation::Pack &) { /* DO NOTHING */}
151 void ShapeFixer::visit(const ir::operation::Unpack &) { /* DO NOTHING */}
153 void ShapeFixer::visit(const ir::operation::OneHot &) { /* DO NOTHING */}
155 void ShapeFixer::visit(const ir::operation::Cast &) { /* DO NOTHING */}
157 void ShapeFixer::visit(const ir::operation::Transpose &) { /* DO NOTHING */}
159 void ShapeFixer::visit(const ir::operation::ReduceSum &) { /* DO NOTHING */}
161 void ShapeFixer::visit(const ir::operation::ReduceMax &) { /* DO NOTHING */}
163 void ShapeFixer::visit(const ir::operation::ReduceMin &) { /* DO NOTHING */}
165 void ShapeFixer::visit(const ir::operation::Slice &) { /* DO NOTHING */}
167 void ShapeFixer::visit(const ir::operation::StridedSlice &) { /* DO NOTHING */}
169 void ShapeFixer::visit(const ir::operation::Split &) { /* DO NOTHING */}
171 void ShapeFixer::visit(const ir::operation::Abs &) { /* DO NOTHING */}
173 void ShapeFixer::visit(const ir::operation::Sin &) { /* DO NOTHING */}
175 void ShapeFixer::visit(const ir::operation::RSQRT &) { /* DO NOTHING */}
177 void ShapeFixer::visit(const ir::operation::Shape &) { /* DO NOTHING */}
180 } // namespace backend