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.

operator_factory.cc 4.3 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /**
  2. * Copyright 2019-2020 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. #include "graph/operator_factory_impl.h"
  17. #include "debug/ge_log.h"
  18. namespace ge {
  19. Operator OperatorFactory::CreateOperator(const std::string &operator_name, const std::string &operator_type) {
  20. return OperatorFactoryImpl::CreateOperator(operator_name, operator_type);
  21. }
  22. Operator OperatorFactory::CreateOperator(const char *operator_name, const char *operator_type) {
  23. if (operator_name == nullptr || operator_type == nullptr) {
  24. GELOGE(GRAPH_FAILED, "Create Operator input parameter is nullptr.");
  25. return Operator();
  26. }
  27. std::string op_name = operator_name;
  28. std::string op_type = operator_type;
  29. return OperatorFactoryImpl::CreateOperator(op_name, op_type);
  30. }
  31. graphStatus OperatorFactory::GetOpsTypeList(std::vector<std::string> &all_ops) {
  32. return OperatorFactoryImpl::GetOpsTypeList(all_ops);
  33. }
  34. graphStatus OperatorFactory::GetOpsTypeList(std::vector<AscendString> &all_ops) {
  35. std::vector<std::string> all_op_types;
  36. if (OperatorFactoryImpl::GetOpsTypeList(all_op_types) != GRAPH_SUCCESS) {
  37. GELOGE(GRAPH_FAILED, "Get ops type list failed.");
  38. return GRAPH_FAILED;
  39. }
  40. for (auto &op_type : all_op_types) {
  41. all_ops.emplace_back(op_type.c_str());
  42. }
  43. return GRAPH_SUCCESS;
  44. }
  45. bool OperatorFactory::IsExistOp(const string &operator_type) { return OperatorFactoryImpl::IsExistOp(operator_type); }
  46. bool OperatorFactory::IsExistOp(const char *operator_type) {
  47. if (operator_type == nullptr) {
  48. GELOGE(GRAPH_FAILED, "Operator type is nullptr.");
  49. return false;
  50. }
  51. std::string op_type = operator_type;
  52. return OperatorFactoryImpl::IsExistOp(op_type);
  53. }
  54. OperatorCreatorRegister::OperatorCreatorRegister(const string &operator_type, OpCreator const &op_creator) {
  55. (void)OperatorFactoryImpl::RegisterOperatorCreator(operator_type, op_creator);
  56. }
  57. OperatorCreatorRegister::OperatorCreatorRegister(const char *operator_type, OpCreatorV2 const &op_creator) {
  58. std::string op_type;
  59. if (operator_type != nullptr) {
  60. op_type = operator_type;
  61. }
  62. (void)OperatorFactoryImpl::RegisterOperatorCreator(op_type, op_creator);
  63. }
  64. InferShapeFuncRegister::InferShapeFuncRegister(const std::string &operator_type,
  65. const InferShapeFunc &infer_shape_func) {
  66. (void)OperatorFactoryImpl::RegisterInferShapeFunc(operator_type, infer_shape_func);
  67. }
  68. InferShapeFuncRegister::InferShapeFuncRegister(const char *operator_type, const InferShapeFunc &infer_shape_func) {
  69. std::string op_type;
  70. if (operator_type != nullptr) {
  71. op_type = operator_type;
  72. }
  73. (void)OperatorFactoryImpl::RegisterInferShapeFunc(op_type, infer_shape_func);
  74. }
  75. InferFormatFuncRegister::InferFormatFuncRegister(const std::string &operator_type,
  76. const InferFormatFunc &infer_format_func) {
  77. (void)OperatorFactoryImpl::RegisterInferFormatFunc(operator_type, infer_format_func);
  78. }
  79. InferFormatFuncRegister::InferFormatFuncRegister(const char *operator_type, const InferFormatFunc &infer_format_func) {
  80. std::string op_type;
  81. if (operator_type != nullptr) {
  82. op_type = operator_type;
  83. }
  84. (void)OperatorFactoryImpl::RegisterInferFormatFunc(op_type, infer_format_func);
  85. }
  86. VerifyFuncRegister::VerifyFuncRegister(const std::string &operator_type, const VerifyFunc &verify_func) {
  87. (void)OperatorFactoryImpl::RegisterVerifyFunc(operator_type, verify_func);
  88. }
  89. VerifyFuncRegister::VerifyFuncRegister(const char *operator_type, const VerifyFunc &verify_func) {
  90. std::string op_type;
  91. if (operator_type != nullptr) {
  92. op_type = operator_type;
  93. }
  94. (void)OperatorFactoryImpl::RegisterVerifyFunc(op_type, verify_func);
  95. }
  96. } // namespace ge

图引擎模块(GE)是MindSpore的一个子模块,其代码由C++实现,位于前端模块ME和底层硬件之间,起到承接作用。图引擎模块以ME下发的图作为输入,然后进行一系列的深度图优化操作,最后输出一张可以在底层硬件上高效运行的图。GE针对昇腾AI处理器的硬件结构特点,做了特定的优化工作,以此来充分发挥出昇腾AI处理器的强大算力。在进行模型训练/推理时,GE会被自动调用而用户并不感知。GE主要由GE API和GE Core两部分组成,详细的架构图如下所示