You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

node_parser_registry.h 3.2 kB

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