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.0 kB

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

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