• 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_INCLUDE_REGISTRY_NODE_PARSER_REGISTRY_H_
18 #define MINDSPORE_LITE_INCLUDE_REGISTRY_NODE_PARSER_REGISTRY_H_
19 
20 #include <string>
21 #include <vector>
22 #include "include/registry/node_parser.h"
23 #include "include/api/dual_abi_helper.h"
24 
25 namespace mindspore {
26 namespace registry {
27 /// \brief NodeParserRegistry defined registration of NodeParser.
28 class MS_API NodeParserRegistry {
29  public:
30   /// \brief Constructor of NodeParserRegistry to register NodeParser.
31   ///
32   /// \param[in] fmk_type Define the framework.
33   /// \param[in] node_type Define the type of the node to be resolved.
34   /// \param[in] node_parser Define the NodeParser instance to parse the node.
35   inline NodeParserRegistry(converter::FmkType fmk_type, const std::string &node_type,
36                             const converter::NodeParserPtr &node_parser);
37 
38   /// \brief Destructor
39   ~NodeParserRegistry() = default;
40 
41   /// \brief Static method to obtain NodeParser instance of a certain node.
42   ///
43   /// \param[in] fmk_type Define the framework.
44   /// \param[in] node_type Define the type of the node to be resolved.
45   ///
46   /// \return NodeParser instance.
47   inline static converter::NodeParserPtr GetNodeParser(converter::FmkType fmk_type, const std::string &node_type);
48 
49  private:
50   NodeParserRegistry(converter::FmkType fmk_type, const std::vector<char> &node_type,
51                      const converter::NodeParserPtr &node_parser);
52   static converter::NodeParserPtr GetNodeParser(converter::FmkType fmk_type, const std::vector<char> &node_type);
53 };
54 
NodeParserRegistry(converter::FmkType fmk_type,const std::string & node_type,const converter::NodeParserPtr & node_parser)55 NodeParserRegistry::NodeParserRegistry(converter::FmkType fmk_type, const std::string &node_type,
56                                        const converter::NodeParserPtr &node_parser)
57     : NodeParserRegistry(fmk_type, StringToChar(node_type), node_parser) {}
58 
GetNodeParser(converter::FmkType fmk_type,const std::string & node_type)59 converter::NodeParserPtr NodeParserRegistry::GetNodeParser(converter::FmkType fmk_type, const std::string &node_type) {
60   return GetNodeParser(fmk_type, StringToChar(node_type));
61 }
62 
63 /// \brief Defined registering macro to register NodeParser instance.
64 ///
65 /// \param[in] fmk_type Define the framework.
66 /// \param[in] node_type Define the type of the node to be resolved.
67 /// \param[in] node_parser instance corresponding with its framework and node type.
68 #define REG_NODE_PARSER(fmk_type, node_type, node_parser) \
69   static mindspore::registry::NodeParserRegistry g_##fmk_type##node_type##ParserReg(fmk_type, #node_type, node_parser);
70 }  // namespace registry
71 }  // namespace mindspore
72 
73 #endif  // MINDSPORE_LITE_INCLUDE_REGISTRY_NODE_PARSER_REGISTRY_H_
74