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.

profiling_manager.h 5.7 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
4 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
5 years ago
4 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /**
  2. * Copyright 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_COMMON_PROFILING_PROFILING_MANAGER_H_
  17. #define GE_COMMON_PROFILING_PROFILING_MANAGER_H_
  18. #include <nlohmann/json.hpp>
  19. #include <mutex>
  20. #include <map>
  21. #include <string>
  22. #include <vector>
  23. #include "framework/common/ge_inner_error_codes.h"
  24. #include "framework/common/ge_types.h"
  25. #include "external/register/register_types.h"
  26. #include "toolchain/prof_engine.h"
  27. #include "toolchain/prof_mgr_core.h"
  28. #include "toolchain/prof_acl_api.h"
  29. using std::map;
  30. using std::string;
  31. using std::vector;
  32. using Json = nlohmann::json;
  33. namespace {
  34. const std::string GE_PROFILING_MODULE = "Framework";
  35. } // namespace
  36. namespace ge {
  37. struct DeviceSubsInfo {
  38. uint64_t module;
  39. uint32_t subscribe_count;
  40. };
  41. // register Plugin
  42. class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY PluginImpl : public Msprof::Engine::PluginIntf {
  43. public:
  44. explicit PluginImpl(const std::string &module);
  45. ~PluginImpl() {}
  46. int Init(const Msprof::Engine::Reporter *reporter);
  47. int UnInit();
  48. static Msprof::Engine::Reporter *GetPluginReporter() { return reporter_; }
  49. private:
  50. static Msprof::Engine::Reporter *reporter_;
  51. std::string module_;
  52. };
  53. // register Engine
  54. class ProfilingEngineImpl : public Msprof::Engine::EngineIntf {
  55. public:
  56. ProfilingEngineImpl() {}
  57. ~ProfilingEngineImpl() {}
  58. Msprof::Engine::PluginIntf *CreatePlugin();
  59. int ReleasePlugin(Msprof::Engine::PluginIntf *plugin);
  60. };
  61. class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ProfilingManager {
  62. public:
  63. ProfilingManager();
  64. virtual ~ProfilingManager();
  65. static ProfilingManager &Instance();
  66. ge::Status Init(const Options &options);
  67. ge::Status InitFromOptions(const Options &options);
  68. ge::Status InitFromAclCfg(const std::string &config);
  69. ge::Status StartProfiling(int32_t iter, int32_t device_id);
  70. void UpdateSubscribeDeviceModuleMap(std::string prof_type, uint32_t device_id, uint64_t module);
  71. ge::Status ProfModelSubscribe(uint64_t module, void *model);
  72. ge::Status ProfModelUnsubscribe(void *model);
  73. ge::Status ProfInit(uint64_t module);
  74. ge::Status ProfFinalize();
  75. ge::Status ProfStartProfiling(uint64_t module, const std::map<std::string, std::string> &config_para);
  76. ge::Status ProfStopProfiling(uint64_t module, const std::map<std::string, std::string> &config_para);
  77. void StopProfiling();
  78. bool ProfilingOpTraceOn() const { return is_op_trace_; }
  79. bool ProfilingLoadFlag() const { return is_load_; }
  80. bool ProfilingTrainingTraceOn() const { return is_training_trace_; }
  81. bool ProfilingModelLoadOn() const { return is_load_profiling_; }
  82. bool ProfilingModelExecuteOn() const;
  83. bool ProfilingOn() const { return is_load_profiling_ && is_execute_profiling_; } // only used by command pattern
  84. bool IsAclApiMode() const { return is_acl_api_mode_; }
  85. int32_t GetOpTraceIterNum() const { return op_trace_iter_num_; }
  86. void ReportProfilingData(uint32_t model_id, const std::vector<TaskDescInfo> &task_desc_info,
  87. const std::vector<ComputeGraphDescInfo> &compute_graph_desc_info,
  88. bool check_device);
  89. void Report(const int32_t &device_id, const string &data, Msprof::Engine::Reporter &reporter,
  90. Msprof::Engine::ReporterData &reporter_data);
  91. void ProfilingTaskDescInfo(uint32_t model_id, const std::vector<TaskDescInfo> &task_desc_info,
  92. const int32_t &device_id);
  93. void ProfilingGraphDescInfo(uint32_t model_id, const std::vector<ComputeGraphDescInfo> &compute_graph_desc_info,
  94. const int32_t &device_id);
  95. void SetProfilingConfig(const string &profiling_cfg);
  96. vector<int32_t> GetProfilingDeviceId() const { return device_id_; }
  97. void PluginUnInit(const std::string &module) const;
  98. private:
  99. ge::Status ParseFeaturesFromAclCfg(const Json &feature);
  100. ge::Status ProfParseParam(const std::map<std::string, std::string> &config_para, int32_t &device_num,
  101. vector<int32_t> &device_list);
  102. ge::Status ProfParseDeviceId(const std::map<std::string, std::string> &config_para,
  103. vector<int32_t> &device_list);
  104. uint64_t GetProfilingModule();
  105. void UpdateDeviceIdModuleMap(string prof_type, uint64_t module, const vector<int32_t> &device_list);
  106. bool is_load_profiling_ = false;
  107. bool is_execute_profiling_ = false;
  108. bool is_op_trace_ = false;
  109. bool is_load_ = false;
  110. bool is_training_trace_ = false;
  111. bool is_acl_api_mode_ = false;
  112. int32_t op_trace_iter_num_ = 0;
  113. string job_id_;
  114. string prof_dir_;
  115. vector<int32_t> device_id_;
  116. vector<string> op_trace_conf_;
  117. vector<string> profiling_opts_;
  118. vector<void *> prof_handle_vec_;
  119. string recv_profiling_config_;
  120. string send_profiling_config_;
  121. string system_trace_conf_;
  122. string task_trace_conf_;
  123. const ProfilingEngineImpl engine_;
  124. map<int32_t, uint64_t> device_id_module_map_; // key: device_id, value: profiling on module
  125. map<uint32_t, DeviceSubsInfo> subs_dev_module_; // key: device_id, value: profiling on module
  126. uint32_t subscribe_count_;
  127. std::mutex mutex_;
  128. };
  129. } // namespace ge
  130. #endif // GE_COMMON_PROFILING_PROFILING_MANAGER_H_

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