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.1 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
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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_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. // register Plugin
  38. class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY PluginImpl : public Msprof::Engine::PluginIntf {
  39. public:
  40. explicit PluginImpl(const std::string &module);
  41. ~PluginImpl() {}
  42. int Init(const Msprof::Engine::Reporter *reporter);
  43. int UnInit();
  44. static Msprof::Engine::Reporter *GetPluginReporter() { return reporter_; }
  45. private:
  46. static Msprof::Engine::Reporter *reporter_;
  47. std::string module_;
  48. };
  49. // register Engine
  50. class ProfilingEngineImpl : public Msprof::Engine::EngineIntf {
  51. public:
  52. ProfilingEngineImpl() {}
  53. ~ProfilingEngineImpl() {}
  54. Msprof::Engine::PluginIntf *CreatePlugin();
  55. int ReleasePlugin(Msprof::Engine::PluginIntf *plugin);
  56. };
  57. class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ProfilingManager {
  58. public:
  59. ProfilingManager();
  60. virtual ~ProfilingManager();
  61. static ProfilingManager &Instance();
  62. ge::Status Init(const Options &options);
  63. ge::Status InitFromOptions(const Options &options);
  64. ge::Status InitFromAclCfg(const std::string &config);
  65. ge::Status StartProfiling(int32_t iter, int32_t device_id);
  66. ge::Status ProfInit(uint64_t module);
  67. ge::Status ProfFinalize();
  68. ge::Status ProfStartProfiling(uint64_t module, const std::map<std::string, std::string> &config_para);
  69. ge::Status ProfStopProfiling(uint64_t module, const std::map<std::string, std::string> &config_para);
  70. void StopProfiling();
  71. bool ProfilingOpTraceOn() const { return is_op_trace_; }
  72. bool ProfilingLoadFlag() const { return is_load_; }
  73. bool ProfilingTrainingTraceOn() const { return is_training_trace_; }
  74. bool ProfilingModelLoadOn() const { return is_load_profiling_; }
  75. bool ProfilingModelExecuteOn() const;
  76. bool ProfilingOn() const { return is_load_profiling_ && is_execute_profiling_; } // only used by command pattern
  77. int32_t GetOpTraceIterNum() const { return op_trace_iter_num_; }
  78. void ReportProfilingData(const std::vector<TaskDescInfo> &task_desc_info,
  79. const std::vector<ComputeGraphDescInfo> &compute_graph_desc_info);
  80. void Report(const int32_t &device_id, const string &data, Msprof::Engine::Reporter &reporter,
  81. Msprof::Engine::ReporterData &reporter_data);
  82. void ProfilingTaskDescInfo(const std::vector<TaskDescInfo> &task_desc_info, const int32_t &device_id);
  83. void ProfilingGraphDescInfo(const std::vector<ComputeGraphDescInfo> &compute_graph_desc_info,
  84. const int32_t &device_id);
  85. void SetProfilingConfig(const string &profiling_cfg);
  86. vector<int32_t> GetProfilingDeviceId() const { return device_id_; }
  87. void PluginUnInit(const std::string &module) const;
  88. private:
  89. ge::Status ParseFeaturesFromAclCfg(const Json &feature);
  90. ge::Status ProfParseParam(const std::map<std::string, std::string> &config_para, int32_t &device_num,
  91. vector<int32_t> &device_list);
  92. ge::Status ProfParseDeviceId(const std::map<std::string, std::string> &config_para, vector<int32_t> &device_list);
  93. uint64_t GetProfilingModule();
  94. void UpdateDeviceIdModuleMap(string prof_type, uint64_t module, const vector<int32_t> &device_list);
  95. bool is_load_profiling_ = false;
  96. bool is_execute_profiling_ = false;
  97. bool is_op_trace_ = false;
  98. bool is_load_ = false;
  99. bool is_training_trace_ = false;
  100. bool is_acl_api_mode_ = false;
  101. int32_t op_trace_iter_num_ = 0;
  102. string job_id_;
  103. string prof_dir_;
  104. vector<int32_t> device_id_;
  105. vector<string> op_trace_conf_;
  106. vector<string> profiling_opts_;
  107. vector<void *> prof_handle_vec_;
  108. string recv_profiling_config_;
  109. string send_profiling_config_;
  110. string system_trace_conf_;
  111. string task_trace_conf_;
  112. const ProfilingEngineImpl engine_;
  113. map<int32_t, uint64_t> device_id_module_map_; // key: device_id, value: profiling on module
  114. std::mutex mutex_;
  115. };
  116. } // namespace ge
  117. #endif // GE_COMMON_PROFILING_PROFILING_MANAGER_H_

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