• 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 "tools/optimizer/common/gllo_utils.h"
26 #include "mindspore/lite/include/lite_types.h"
27 #include "ops/fusion/conv2d_fusion.h"
28 
29 namespace mindspore {
30 using mindspore::schema::PrimitiveType;
31 namespace opt {
32 
33 struct SplitInfo {
34   int64_t axis{0};
35   int64_t out_num{0};
36   std::vector<int64_t> size_splits{};
37   std::vector<int64_t> extend_top{};
38   std::vector<int64_t> extend_bottom{};
39   std::vector<mindspore::lite::DeviceType> dev_types{};
40   int64_t ori_split_axis_value{0};
41   int64_t in_num_conv{0};
42   int64_t fmk_type{0};
43   PrimitiveType primitive_type{schema::PrimitiveType_NONE};
44 };
45 
46 typedef enum { CUT_N, CUT_H, CUT_W, CUT_C_IN, CUT_C_OUT, CUT_NONE } CuttingStragedy;
47 
48 std::vector<int64_t> GetSplitPadList(const api::SharedPtr<ops::Conv2DFusion> &ori_conv_prim, int64_t input_h,
49                                      int64_t input_w);
50 
51 bool IsConv2D(const AnfNodePtr &node);
52 
53 api::SharedPtr<ops::Conv2DFusion> CopyConvPrim(const api::SharedPtr<ops::Conv2DFusion> &ori_attr);
54 
55 bool UpdateSplitInfo(const FuncGraphPtr &func_graph, const std::vector<AnfNodePtr> &conv_nodes, SplitInfo *split_info);
56 
57 bool GetMultipleOutputsOfAnfNode(const FuncGraphPtr &func_graph, const AnfNodePtr &node, size_t output_num,
58                                  std::vector<AnfNodePtr> *outputs);
59 
60 AnfNodePtr CreateOutputsOfConcat(const FuncGraphPtr &func_graph, const AnfNodePtr &conv_cnode,
61                                  const std::vector<AnfNodePtr> &conv_outputs, const SplitInfo &split_info,
62                                  const std::string &node_name);
63 bool CreateOutputsOfSplitWithOverlap(const FuncGraphPtr &func_graph, const AnfNodePtr &conv_cnode,
64                                      std::vector<AnfNodePtr> *split_outputs, const SplitInfo &split_info,
65                                      const std::string &node_name);
66 bool UpdateRatioWithPadStride(int64_t *ratio, size_t ratio_len, size_t split_size, int split_dim_size);
67 }  // namespace opt
68 }  // namespace mindspore
69 #endif  // MINDSPORE_LITE_TOOLS_OPTIMIZER_FISSON_FISSON_UTIL_H_
70