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.

ops_kernel_manager.h 4.8 kB

5 years ago
3 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
3 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
3 years ago
5 years ago
3 years ago
3 years ago
5 years ago
5 years ago
3 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 GE_OPSKERNEL_MANAGER_OPS_KERNEL_MANAGER_H_
  17. #define GE_OPSKERNEL_MANAGER_OPS_KERNEL_MANAGER_H_
  18. #include <map>
  19. #include <set>
  20. #include <memory>
  21. #include <string>
  22. #include <vector>
  23. #include <mutex>
  24. #include "framework/common/debug/log.h"
  25. #include "common/ge/plugin_manager.h"
  26. #include "common/ge/op_tiling_manager.h"
  27. #include "framework/common/ge_inner_error_codes.h"
  28. #include "common/opskernel/ops_kernel_info_store.h"
  29. #include "common/optimizer/graph_optimizer.h"
  30. #include "graph/optimize/graph_optimize.h"
  31. #include "framework/common/ge_inner_error_codes.h"
  32. #include "external/ge/ge_api_types.h"
  33. #include "runtime/base.h"
  34. using std::string;
  35. using std::map;
  36. using std::vector;
  37. namespace ge {
  38. using OpsKernelInfoStorePtr = std::shared_ptr<OpsKernelInfoStore>;
  39. class GE_FUNC_VISIBILITY OpsKernelManager {
  40. public:
  41. friend class GELib;
  42. // get opsKernelInfo by type
  43. const vector<OpInfo> &GetOpsKernelInfo(const string &op_type);
  44. // get all opsKernelInfo
  45. const map<string, vector<OpInfo>> &GetAllOpsKernelInfo() const;
  46. // get opsKernelInfoStore by name
  47. OpsKernelInfoStorePtr GetOpsKernelInfoStore(const std::string &name) const;
  48. // get all opsKernelInfoStore
  49. const map<string, OpsKernelInfoStorePtr> &GetAllOpsKernelInfoStores() const;
  50. // get all graph_optimizer
  51. const map<string, GraphOptimizerPtr> &GetAllGraphOptimizerObjs() const;
  52. // get all graph_optimizer by priority
  53. const vector<pair<string, GraphOptimizerPtr>> &GetAllGraphOptimizerObjsByPriority() const {
  54. return atomic_first_optimizers_by_priority_;
  55. }
  56. const map<string, std::set<string>> &GetCompoundEngineContains() const {
  57. return compound_engine_contains_;
  58. }
  59. const map<string, string> &GetCompoundEngineKernelLibName() const {
  60. return compound_engine_2_kernel_lib_name_;
  61. }
  62. // get subgraphOptimizer by engine name
  63. void GetGraphOptimizerByEngine(const std::string &engine_name, vector<GraphOptimizerPtr> &graph_optimizer);
  64. // get enableFeFlag
  65. bool GetEnableFeFlag() const;
  66. // get enableAICPUFlag
  67. bool GetEnableAICPUFlag() const;
  68. // get enablePluginFlag
  69. bool GetEnablePluginFlag() const;
  70. private:
  71. OpsKernelManager();
  72. ~OpsKernelManager();
  73. // opsKernelManager initialize, load all opsKernelInfoStore and graph_optimizer
  74. Status Initialize(const map<string, string> &options);
  75. // opsKernelManager finalize, unload all opsKernelInfoStore and graph_optimizer
  76. Status Finalize();
  77. Status InitOpKernelInfoStores(const map<string, string> &options);
  78. Status CheckPluginPtr() const;
  79. void GetExternalEnginePath(std::string &path, const std::map<string, string>& options);
  80. void InitOpsKernelInfo();
  81. Status InitGraphOptimizers(const map<string, string> &options);
  82. Status InitPluginOptions(const map<string, string> &options);
  83. Status ParsePluginOptions(const map<string, string> &options, const string &plugin_name, bool &enable_flag);
  84. void ClassifyGraphOptimizers();
  85. void InitGraphOptimizerPriority();
  86. // Finalize other ops kernel resource
  87. Status FinalizeOpsKernel();
  88. PluginManager plugin_manager_;
  89. OpTilingManager op_tiling_manager_;
  90. // opsKernelInfoStore
  91. map<string, OpsKernelInfoStorePtr> ops_kernel_store_{};
  92. // graph_optimizer
  93. map<string, GraphOptimizerPtr> graph_optimizers_{};
  94. // compound_graph_optimizer
  95. map<string, GraphOptimizerPtr> compound_graph_optimizers_{};
  96. // atomic_graph_optimizer
  97. map<string, GraphOptimizerPtr> atomic_graph_optimizers_{};
  98. // ordered atomic_graph_optimizer
  99. vector<pair<string, GraphOptimizerPtr>> atomic_graph_optimizers_by_priority_{};
  100. // atomic_first graph_optimizer
  101. vector<pair<string, GraphOptimizerPtr>> atomic_first_optimizers_by_priority_{};
  102. // {compound_engine, {containing atomic engines}}
  103. map<string, std::set<string>> compound_engine_contains_{};
  104. // {compound_engine, compound_engine_kernel_lib_name}
  105. map<string, string> compound_engine_2_kernel_lib_name_{};
  106. // opsKernelInfo
  107. map<string, vector<OpInfo>> ops_kernel_info_{};
  108. map<string, string> initialize_{};
  109. vector<OpInfo> empty_op_info_{};
  110. bool init_flag_;
  111. bool enable_fe_flag_ = false;
  112. bool enable_aicpu_flag_ = false;
  113. };
  114. } // namespace ge
  115. #endif // GE_OPSKERNEL_MANAGER_OPS_KERNEL_MANAGER_H_

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