Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / src / inference_engine / shape_infer / built-in / ie_built_in_holder.cpp
1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4
5 #include "impl_register.hpp"
6 #include "ie_built_in_holder.hpp"
7 #include "ie_conv_shape_infer.hpp"
8 #include "ie_deconv_shape_infer.hpp"
9 #include "ie_pool_shape_infer.hpp"
10 #include "ie_crop_shape_infer.hpp"
11 #include "ie_tile_shape_infer.hpp"
12 #include "ie_split_shape_infer.hpp"
13 #include "ie_equal_shape_infer.hpp"
14 #include "ie_concat_shape_infer.hpp"
15 #include "ie_eltwise_shape_infer.hpp"
16 #include "ie_permute_shape_infer.hpp"
17 #include "ie_reshape_shape_infer.hpp"
18 #include "ie_flatten_shape_infer.hpp"
19 #include "ie_proposal_shape_infer.hpp"
20 #include "ie_priorbox_shape_infer.hpp"
21 #include "ie_upsampling_shape_infer.hpp"
22 #include "ie_reorg_yolo_shape_infer.hpp"
23 #include "ie_region_yolo_shape_infer.hpp"
24 #include "ie_simpler_nms_shape_infer.hpp"
25 #include "ie_roi_pooling_shape_infer.hpp"
26 #include "ie_psroi_pooling_shape_infer.hpp"
27 #include "ie_detection_output_shape_infer.hpp"
28 #include "ie_priorbox_clustered_shape_infer.hpp"
29 #include "ie_ctc_greedy_decoder_shape_infer.hpp"
30 #include "ie_inner_product_shape_infer.hpp"
31 #include "ie_resample_shape_infer.hpp"
32 #include "ie_interp_shape_infer.hpp"
33 #include "ie_argmax_shape_infer.hpp"
34 #include "ie_gemm_shape_infer.hpp"
35 #include "ie_pad_shape_infer.hpp"
36 #include "ie_gather_shape_infer.hpp"
37 #include "ie_strided_slice_shape_infer.hpp"
38 #include "ie_shuffle_channels_shape_infer.hpp"
39 #include "ie_depth_to_space_shape_infer.hpp"
40 #include "ie_space_to_depth_shape_infer.hpp"
41 #include "ie_reverse_sequence_shape_infer.hpp"
42 #include "ie_shape_shape_infer.hpp"
43 #include "ie_squeeze_shape_infer.hpp"
44 #include "ie_unsqueeze_shape_infer.hpp"
45 #include "ie_range_shape_infer.hpp"
46 #include "ie_fill_shape_infer.hpp"
47 #include "ie_expand_shape_infer.hpp"
48 #include "ie_rnn_shape_infer.hpp"
49 #include "ie_tensor_iterator_shape_infer.hpp"
50 #include "ie_rnn_cell_shape_infer.hpp"
51 #include "ie_quantize_shape_infer.hpp"
52 #include "ie_bin_conv_shape_infer.hpp"
53 #include <algorithm>
54 #include <memory>
55 #include <string>
56
57 namespace InferenceEngine {
58 namespace ShapeInfer {
59
60 BuiltInShapeInferHolder::ImplsHolder::Ptr BuiltInShapeInferHolder::GetImplsHolder() {
61     static ImplsHolder::Ptr localHolder;
62     if (localHolder == nullptr) {
63         localHolder = std::make_shared<ImplsHolder>();
64     }
65     return localHolder;
66 }
67
68 void BuiltInShapeInferHolder::AddImpl(const std::string& name, const IShapeInferImpl::Ptr& impl) {
69     GetImplsHolder()->list[name] = impl;
70 }
71
72 StatusCode BuiltInShapeInferHolder::getShapeInferTypes(char**& types, unsigned int& size, ResponseDesc* resp) noexcept {
73     auto& factories = GetImplsHolder()->list;
74     types = new char* [factories.size()];
75     size = 0;
76     for (auto it = factories.begin(); it != factories.end(); it++, size++) {
77         types[size] = new char[it->first.size() + 1];
78         std::copy(it->first.begin(), it->first.end(), types[size]);
79         types[size][it->first.size()] = '\0';
80     }
81     return OK;
82 }
83
84 StatusCode
85 BuiltInShapeInferHolder::getShapeInferImpl(IShapeInferImpl::Ptr& impl, const char* type, ResponseDesc* resp) noexcept {
86     auto& impls = BuiltInShapeInferHolder::GetImplsHolder()->list;
87     if (impls.find(type) != impls.end()) {
88         impl = impls[type];
89         return OK;
90     }
91     impl.reset();
92     return NOT_FOUND;
93 }
94
95 void BuiltInShapeInferHolder::SetLogCallback(InferenceEngine::IErrorListener& listener) noexcept {}
96
97 // Register without implementation just to protect from adding custom implementation for them
98 REG_SHAPE_INFER_FOR_TYPE(EqualShapeProp, Input);
99 REG_SHAPE_INFER_FOR_TYPE(DoNothingShapeProp, Output);
100 REG_SHAPE_INFER_FOR_TYPE(EqualShapeProp, Memory);
101 REG_SHAPE_INFER_FOR_TYPE(EqualShapeProp, Const);
102
103 // Outputs = Inputs
104 REG_SHAPE_INFER_FOR_TYPE(EqualShapeProp, Activation);
105 REG_SHAPE_INFER_FOR_TYPE(EqualShapeProp, ReLU);
106 REG_SHAPE_INFER_FOR_TYPE(EqualShapeProp, ReLU6);
107 REG_SHAPE_INFER_FOR_TYPE(EqualShapeProp, ELU);
108 REG_SHAPE_INFER_FOR_TYPE(EqualShapeProp, TanH);
109 REG_SHAPE_INFER_FOR_TYPE(EqualShapeProp, Logistic);
110 REG_SHAPE_INFER_FOR_TYPE(EqualShapeProp, Sigmoid);
111 REG_SHAPE_INFER_FOR_TYPE(EqualShapeProp, PReLU);
112 REG_SHAPE_INFER_FOR_TYPE(EqualShapeProp, SoftMax);
113 REG_SHAPE_INFER_FOR_TYPE(EqualShapeProp, LRN);
114 REG_SHAPE_INFER_FOR_TYPE(EqualShapeProp, Norm);
115 REG_SHAPE_INFER_FOR_TYPE(EqualShapeProp, Normalize);
116 // FIXME: Really Copy??? New MO doesn't generate this layer
117 REG_SHAPE_INFER_FOR_TYPE(EqualShapeProp, Copy);
118 REG_SHAPE_INFER_FOR_TYPE(EqualShapeProp, Power);
119 REG_SHAPE_INFER_FOR_TYPE(EqualShapeProp, PowerFile);
120 REG_SHAPE_INFER_FOR_TYPE(EqualShapeProp, Clamp);
121 REG_SHAPE_INFER_FOR_TYPE(EqualShapeProp, ScaleShift);
122 REG_SHAPE_INFER_FOR_TYPE(EqualShapeProp, BatchNormalization);
123 REG_SHAPE_INFER_FOR_TYPE(EqualShapeProp, GRN);
124 REG_SHAPE_INFER_FOR_TYPE(EqualShapeProp, MVN);
125
126
127 REG_SHAPE_INFER_FOR_TYPE(ConvShapeProp, Convolution);
128 REG_SHAPE_INFER_FOR_TYPE(DeconvShapeProp, Deconvolution);
129 REG_SHAPE_INFER_FOR_TYPE(PoolingShapeProp, Pooling);
130 REG_SHAPE_INFER_FOR_TYPE(InnerProductShapeProp, InnerProduct);
131 REG_SHAPE_INFER_FOR_TYPE(InnerProductShapeProp, FullyConnected);
132 REG_SHAPE_INFER_FOR_TYPE(SplitShapeProp, Split);
133 REG_SHAPE_INFER_FOR_TYPE(SplitShapeProp, Slice);
134 REG_SHAPE_INFER_FOR_TYPE(PermuteShapeProp, Permute);
135 REG_SHAPE_INFER_FOR_TYPE(FlattenShapeProp, Flatten);
136 REG_SHAPE_INFER_FOR_TYPE(ReshapeShapeProp, Reshape);
137 REG_SHAPE_INFER_FOR_TYPE(DetectionOutputShapeProp, DetectionOutput);
138 REG_SHAPE_INFER_FOR_TYPE(PriorBoxClusteredShapeProp, PriorBoxClustered);
139 REG_SHAPE_INFER_FOR_TYPE(PriorBoxShapeProp, PriorBox);
140 REG_SHAPE_INFER_FOR_TYPE(RoiPoolingShapeProp, ROIPooling);
141 REG_SHAPE_INFER_FOR_TYPE(PSRoiPoolingShapeProp, PSROIPooling);
142 REG_SHAPE_INFER_FOR_TYPE(UpsamplingShapeProp, Upsampling);
143 REG_SHAPE_INFER_FOR_TYPE(ResampleShapeProp, Resample);
144 REG_SHAPE_INFER_FOR_TYPE(InterpShapeProp, Interp);
145 REG_SHAPE_INFER_FOR_TYPE(SimplerNMSShapeProp, SimplerNMS);
146 REG_SHAPE_INFER_FOR_TYPE(TileShapeProp, Tile);
147 REG_SHAPE_INFER_FOR_TYPE(CropShapeProp, Crop);
148 REG_SHAPE_INFER_FOR_TYPE(ConcatShapeProp, Concat);
149 REG_SHAPE_INFER_FOR_TYPE(EltWiseShapeProp, Eltwise);
150 REG_SHAPE_INFER_FOR_TYPE(EltWiseShapeProp, Mul);
151 REG_SHAPE_INFER_FOR_TYPE(EltWiseShapeProp, Add);
152 REG_SHAPE_INFER_FOR_TYPE(EltWiseShapeProp, Div);
153 REG_SHAPE_INFER_FOR_TYPE(CTCGreedyDecoderShapeProp, CTCGreedyDecoder);
154 REG_SHAPE_INFER_FOR_TYPE(ProposalShapeProp, Proposal);
155 REG_SHAPE_INFER_FOR_TYPE(ReorgYoloShapeProp, ReorgYolo);
156 REG_SHAPE_INFER_FOR_TYPE(RegionYoloShapeProp, RegionYolo);
157 REG_SHAPE_INFER_FOR_TYPE(RNNShapeProp, RNNSequence);
158 REG_SHAPE_INFER_FOR_TYPE(RNNShapeProp, GRUSequence);
159 REG_SHAPE_INFER_FOR_TYPE(RNNShapeProp, LSTMSequence);
160 REG_SHAPE_INFER_FOR_TYPE(RNNCellShapeProp, RNNCell);
161 REG_SHAPE_INFER_FOR_TYPE(GRUCellShapeProp, GRUCell);
162 REG_SHAPE_INFER_FOR_TYPE(LSTMCellShapeProp, LSTMCell);
163 REG_SHAPE_INFER_FOR_TYPE(TensorIteratorShapeProp, TensorIterator);
164 REG_SHAPE_INFER_FOR_TYPE(ArgMaxShapeProp, ArgMax);
165 REG_SHAPE_INFER_FOR_TYPE(GemmShapeProp, Gemm);
166 REG_SHAPE_INFER_FOR_TYPE(PadShapeProp, Pad);
167 REG_SHAPE_INFER_FOR_TYPE(GatherShapeProp, Gather);
168 REG_SHAPE_INFER_FOR_TYPE(StridedSliceShapeProp, StridedSlice);
169 REG_SHAPE_INFER_FOR_TYPE(ShuffleChannelsShapeProp, ShuffleChannels);
170 REG_SHAPE_INFER_FOR_TYPE(DepthToSpaceShapeProp, DepthToSpace);
171 REG_SHAPE_INFER_FOR_TYPE(SpaceToDepthShapeProp, SpaceToDepth);
172 REG_SHAPE_INFER_FOR_TYPE(ReverseSequenceShapeProp, ReverseSequence);
173 REG_SHAPE_INFER_FOR_TYPE(SqueezeShapeProp, Squeeze);
174 REG_SHAPE_INFER_FOR_TYPE(UnsqueezeShapeProp, Unsqueeze);
175 REG_SHAPE_INFER_FOR_TYPE(RangeShapeProp, Range);
176 REG_SHAPE_INFER_FOR_TYPE(FillShapeProp, Fill);
177 REG_SHAPE_INFER_FOR_TYPE(ExpandShapeProp, Expand);
178 REG_SHAPE_INFER_FOR_TYPE(ShapeShapeProp, Shape);
179 REG_SHAPE_INFER_FOR_TYPE(QuantizeShapeProp, Quantize);
180 REG_SHAPE_INFER_FOR_TYPE(BinConvShapeProp, BinaryConvolution);
181
182 }  // namespace ShapeInfer
183 }  // namespace InferenceEngine