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.

register.h 4.9 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
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. #ifndef INC_EXTERNAL_REGISTER_REGISTER_H_
  17. #define INC_EXTERNAL_REGISTER_REGISTER_H_
  18. #include <functional>
  19. #include <initializer_list>
  20. #include <map>
  21. #include <memory>
  22. #include <set>
  23. #include <string>
  24. #include <utility>
  25. #include <unordered_map>
  26. #include <vector>
  27. #include "graph/operator.h"
  28. #include "register/register_error_codes.h"
  29. #include "register/register_fmk_types.h"
  30. #include "register/register_types.h"
  31. using std::make_shared;
  32. using std::map;
  33. using std::pair;
  34. using std::string;
  35. using std::to_string;
  36. using std::unique_ptr;
  37. using std::vector;
  38. namespace ge {
  39. class Operator;
  40. class TensorDesc;
  41. class Tensor;
  42. class TBEPluginManager;
  43. } // namespace ge
  44. namespace google {
  45. namespace protobuf {
  46. class Message;
  47. }
  48. } // namespace google
  49. namespace domi {
  50. Status AutoMappingFn(const google::protobuf::Message *op_src, ge::Operator &op);
  51. Status AutoMappingFnDynamic(const google::protobuf::Message *op_src, ge::Operator &op,
  52. std::map<std::string, std::pair<std::string, std::string>> dynamic_name_attr_value,
  53. int in_pos = -1, int out_pos = -1);
  54. using google::protobuf::Message;
  55. class OpRegistrationDataImpl;
  56. using ParseParamFunc = std::function<domi::Status(const google::protobuf::Message *, ge::Operator &)>;
  57. using FusionParseParamFunc =
  58. std::function<domi::Status(const std::vector<const google::protobuf::Message *>, ge::Operator &)>;
  59. class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY OpRegistrationData {
  60. public:
  61. OpRegistrationData(const std::string &om_optype);
  62. ~OpRegistrationData();
  63. OpRegistrationData &FrameworkType(const domi::FrameworkType &fmk_type);
  64. OpRegistrationData &OriginOpType(const std::initializer_list<std::string> &ori_optype_list);
  65. OpRegistrationData &OriginOpType(const std::string &ori_optype);
  66. OpRegistrationData &ParseParamsFn(const ParseParamFunc &parseParamFn);
  67. OpRegistrationData &FusionParseParamsFn(const FusionParseParamFunc &fusionParseParamFn);
  68. OpRegistrationData &ImplyType(const domi::ImplyType &imply_type);
  69. OpRegistrationData &DelInputWithCond(int inputIdx, const std::string &attrName, bool attrValue);
  70. OpRegistrationData &DelInputWithOriginalType(int input_idx, const std::string &ori_type);
  71. domi::ImplyType GetImplyType() const;
  72. std::string GetOmOptype() const;
  73. std::set<std::string> GetOriginOpTypeSet() const;
  74. domi::FrameworkType GetFrameworkType() const;
  75. ParseParamFunc GetParseParamFn() const;
  76. FusionParseParamFunc GetFusionParseParamFn() const;
  77. private:
  78. std::shared_ptr<OpRegistrationDataImpl> impl_;
  79. friend class OpRegistry;
  80. friend class OpRegistrationTbe;
  81. friend class ge::TBEPluginManager;
  82. };
  83. class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY OpReceiver {
  84. public:
  85. OpReceiver(OpRegistrationData &reg_data);
  86. ~OpReceiver() {}
  87. };
  88. #define REGISTER_CUSTOM_OP(name) REGISTER_CUSTOM_OP_UNIQ_HELPER(__COUNTER__, name)
  89. #define REGISTER_CUSTOM_OP_UNIQ_HELPER(ctr, name) REGISTER_CUSTOM_OP_UNIQ(ctr, name)
  90. #define REGISTER_CUSTOM_OP_UNIQ(ctr, name) \
  91. static OpReceiver register_op##ctr __attribute__((unused)) = OpRegistrationData(name)
  92. } // namespace domi
  93. namespace ge {
  94. using OpRegistrationData = domi::OpRegistrationData;
  95. using OpReceiver = domi::OpReceiver;
  96. class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY HostCpuOp {
  97. public:
  98. HostCpuOp() = default;
  99. virtual ~HostCpuOp() = default;
  100. virtual graphStatus Compute(Operator &op, const std::map<std::string, const Tensor> &inputs,
  101. std::map<std::string, Tensor> &outputs) = 0;
  102. };
  103. class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY HostCpuOpRegistrar {
  104. public:
  105. HostCpuOpRegistrar(const char *op_type, HostCpuOp *(*create_fn)());
  106. };
  107. #define REGISTER_HOST_CPU_OP_BUILDER(name, op) REGISTER_HOST_CPU_OP_BUILDER_UNIQ_HELPER(__COUNTER__, name, op)
  108. #define REGISTER_HOST_CPU_OP_BUILDER_UNIQ_HELPER(ctr, name, op) REGISTER_HOST_CPU_OP_BUILDER_UNIQ(ctr, name, op)
  109. #define REGISTER_HOST_CPU_OP_BUILDER_UNIQ(ctr, name, op) \
  110. static ::ge::HostCpuOpRegistrar register_host_cpu_op##ctr __attribute__((unused)) = \
  111. ::ge::HostCpuOpRegistrar(name, []() -> ::ge::HostCpuOp * { return new (std::nothrow) op(); })
  112. } // namespace ge
  113. #endif // INC_EXTERNAL_REGISTER_REGISTER_H_

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