• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2021 Huawei Technologies Co., Ltd
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 MINDSPORE_LITE_TOOLS_OPTIMIZER_FISSON_FISSON_UTIL_H_
18 #define MINDSPORE_LITE_TOOLS_OPTIMIZER_FISSON_FISSON_UTIL_H_
19 
20 #include <vector>
21 #include <string>
22 #include <unordered_map>
23 #include <memory>
24 #include "schema/inner/model_generated.h"
25 #include "mindspore/ccsrc/utils/utils.h"
26 #include "tools/optimizer/common/gllo_utils.h"
27 #include "tools/converter/converter_flags.h"
28 #include "mindspore/lite/include/context.h"
29 #include "mindspore/lite/include/lite_types.h"
30 #include "ops/fusion/conv2d_fusion.h"
31 
32 namespace mindspore {
33 using mindspore::schema::PrimitiveType;
34 namespace opt {
35 
36 struct SplitInfo {
37   int64_t axis{0};
38   int64_t out_num{0};
39   std::vector<int64_t> size_splits{};
40   std::vector<int64_t> extend_top{};
41   std::vector<int64_t> extend_bottom{};
42   std::vector<mindspore::lite::DeviceType> dev_types{};
43   int64_t ori_split_axis_value{0};
44   int64_t in_num_conv{0};
45   int64_t fmk_type{0};
46   PrimitiveType primitive_type{schema::PrimitiveType_NONE};
47 };
48 
49 typedef enum { CUT_N, CUT_H, CUT_W, CUT_C_IN, CUT_C_OUT, CUT_NONE } CuttingStragedy;
50 
51 std::vector<int64_t> GetSplitPadList(const std::shared_ptr<ops::Conv2DFusion> &ori_conv_prim, int64_t input_h,
52                                      int64_t input_w);
53 
54 bool IsConv2D(const AnfNodePtr &node);
55 
56 std::shared_ptr<ops::Conv2DFusion> CopyConvPrim(const std::shared_ptr<ops::Conv2DFusion> &ori_attr);
57 
58 bool UpdateSplitInfo(const FuncGraphPtr &func_graph, const std::vector<AnfNodePtr> &conv_nodes, SplitInfo *split_info);
59 
60 bool GetMultipleOutputsOfAnfNode(const FuncGraphPtr &func_graph, const AnfNodePtr &node, size_t output_num,
61                                  std::vector<AnfNodePtr> *outputs);
62 
63 AnfNodePtr CreateOutputsOfConcat(const FuncGraphPtr &func_graph, const AnfNodePtr &conv_cnode,
64                                  const std::vector<AnfNodePtr> &conv_outputs, SplitInfo *split_info,
65                                  const std::string &node_name);
66 bool CreateOutputsOfSplitWithOverlap(const FuncGraphPtr &func_graph, const AnfNodePtr &conv_cnode,
67                                      std::vector<AnfNodePtr> *split_outputs, SplitInfo *split_info,
68                                      const std::string &node_name);
69 bool UpdateRatioWithPadStride(int64_t *ratio, size_t ratio_len, size_t split_size, int split_dim_size, int pad,
70                               int stride);
71 }  // namespace opt
72 }  // namespace mindspore
73 #endif  // MINDSPORE_LITE_TOOLS_OPTIMIZER_FISSON_FISSON_UTIL_H_
74