• 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_CONVERTER_PARSER_PARSER_UTILS_H
18 #define MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_PARSER_UTILS_H
19 
20 #include <set>
21 #include <vector>
22 #include "include/registry/model_parser.h"
23 #include "ir/anf.h"
24 #include "ir/func_graph.h"
25 #include "src/common/log_adapter.h"
26 #include "schema/inner/model_generated.h"
27 
28 namespace mindspore {
29 namespace lite {
30 void GetAllFuncGraph(const FuncGraphPtr &func_graph, std::set<FuncGraphPtr> *all_func_graphs);
31 int CommonAnfAdjust(const std::set<FuncGraphPtr> &all_func_graphs);
32 int GetTransposePerm(schema::Format src_format, schema::Format dst_format, std::vector<int> *perm);
33 int GetTransposePermSharing(schema::Format src_format, schema::Format dst_format, std::vector<int> *perm);
34 AnfNodePtr GetRealConvWeightNode(const FuncGraphPtr &graph, const CNodePtr &cnode, size_t index);
35 int UnifyConvWeightFormat(const FuncGraphPtr &graph, const CNodePtr &cnode, schema::Format src_format,
36                           schema::Format dst_format, std::set<AnfNodePtr> *has_visited);
37 int UnifyVariableConvWeight(const FuncGraphPtr &graph, const AnfNodePtr &weight_node, schema::Format src_format,
38                             schema::Format dst_format, std::set<AnfNodePtr> *has_visited);
39 int UnifyConstConvWeight(const FuncGraphPtr &graph, const AnfNodePtr &weight_node, schema::Format src_format,
40                          schema::Format dst_format, std::set<AnfNodePtr> *has_visited);
41 int HandleConstConvWeightShared(const FuncGraphPtr &graph, const AnfNodePtr &weight_node, schema::Format src_format,
42                                 schema::Format dst_format, std::set<AnfNodePtr> *has_visited);
43 
44 template <class T>
LiteModelParserCreator()45 converter::ModelParser *LiteModelParserCreator() {
46   auto *parser = new (std::nothrow) T();
47   if (parser == nullptr) {
48     MS_LOG(ERROR) << "new model parser failed";
49     return nullptr;
50   }
51   return parser;
52 }
53 }  // namespace lite
54 }  // namespace mindspore
55 
56 #endif
57