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 6.8 kB

5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
4 years ago
4 years ago
5 years ago
5 years ago
4 years ago
5 years ago
4 years ago
4 years ago
4 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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_callback.h"
  27. #include "runtime/stream.h"
  28. using std::map;
  29. using std::string;
  30. using std::vector;
  31. using Json = nlohmann::json;
  32. namespace {
  33. const std::string GE_PROFILING_MODULE = "Framework";
  34. // DataTypeConfig MASK
  35. const uint64_t PROF_ACL_API_MASK = 0x0001;
  36. const uint64_t PROF_TASK_TIME_MASK = 0x0002;
  37. const uint64_t PROF_AICORE_METRICS_MASK = 0x0004;
  38. const uint64_t PROF_AICPU_TRACE_MASK = 0x0008;
  39. const uint64_t PROF_MODEL_EXECUTE_MASK = 0x0010;
  40. const uint64_t PROF_RUNTIME_API_MASK = 0x0020;
  41. const uint64_t PROF_RUNTIME_TRACE_MASK = 0x0040;
  42. const uint64_t PROF_SCHEDULE_TIMELINE_MASK = 0x0080;
  43. const uint64_t PROF_SCHEDULE_TRACE_MASK = 0x0100;
  44. const uint64_t PROF_AIVECTORCORE_METRICS_MASK = 0x0200;
  45. const uint64_t PROF_SUBTASK_TIME_MASK = 0x0400;
  46. const uint64_t PROF_TRAINING_TRACE_MASK = 0x0800;
  47. const uint64_t PROF_HCCL_TRACE_MASK = 0x1000;
  48. const uint64_t PROF_DATA_PROCESS_MASK = 0x2000;
  49. const uint64_t PROF_MODEL_LOAD_MASK = 0x8000000000000000;
  50. } // namespace
  51. namespace ge {
  52. class OpDesc;
  53. using OpDescPtr = std::shared_ptr<OpDesc>;
  54. struct DeviceSubsInfo {
  55. uint64_t module;
  56. uint32_t subscribe_count;
  57. };
  58. struct ProfSubscribeInfo {
  59. bool is_subscribe;
  60. uint64_t prof_switch;
  61. uint32_t graph_id;
  62. };
  63. struct MsprofCallback {
  64. MsprofCtrlCallback msprofCtrlCallback;
  65. MsprofReporterCallback msprofReporterCallback;
  66. };
  67. class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ProfilingManager {
  68. public:
  69. ProfilingManager();
  70. virtual ~ProfilingManager();
  71. static ProfilingManager &Instance();
  72. Status Init(const Options &options);
  73. Status ProfInit(uint64_t module);
  74. Status ProfFinalize();
  75. Status ProfStartProfiling(uint64_t module, const std::map<std::string, std::string> &config_para);
  76. Status ProfStopProfiling(uint64_t module, const std::map<std::string, std::string> &config_para);
  77. Status ProfModelSubscribe(uint64_t module, void *model);
  78. Status ProfModelUnsubscribe(void *model);
  79. void StopProfiling();
  80. bool ProfilingTrainingTraceOn() const { return is_training_trace_; }
  81. // report model load profiling data flag, data contain task desc info, step info, model load fusion op info
  82. bool ProfilingModelLoadOn() const { return is_load_profiling_; }
  83. // report model execute profiling data flag, data contain model execute time info
  84. bool ProfilingModelExecuteOn() const;
  85. // is_execute_profiling_ only used by ge option and env
  86. bool ProfilingOn() const { return is_load_profiling_ && is_execute_profiling_; }
  87. void ReportProfilingData(uint32_t model_id, const std::vector<TaskDescInfo> &task_desc_info);
  88. void ProfilingTaskDescInfo(uint32_t model_id, const std::vector<TaskDescInfo> &task_desc_info,
  89. const int32_t &device_id);
  90. void ProfilingOpInputOutInfo(const TaskDescInfo &task, Json &task_json);
  91. Status PluginInit();
  92. void PluginUnInit() const;
  93. Status CallMsprofReport(ReporterData &reporter_data) const;
  94. struct MsprofCallback &GetMsprofCallback() { return prof_cb_; }
  95. void SetMsprofCtrlCallback(MsprofCtrlCallback func) { prof_cb_.msprofCtrlCallback = func; }
  96. void SetMsprofReporterCallback(MsprofReporterCallback func) { prof_cb_.msprofReporterCallback = func; }
  97. void GetFpBpPoint(std::string &fp_point, std::string &bp_point);
  98. void GetOpInputOutputInfo(const OpDescPtr &op, TaskDescInfo &task_desc_info) const;
  99. void ReportData(const int32_t &device_id, const std::string &data, const std::string &tag_name);
  100. Status ProfileStepInfo(uint64_t index_id, uint64_t model_id, uint16_t tag_id, rtStream_t stream, int32_t device_id);
  101. void SetStepInfoIndex(uint64_t index_id) { index_id_ = index_id; }
  102. uint64_t GetStepInfoIndex() const { return index_id_; }
  103. void SetGraphIdToDeviceMap(uint32_t graph_id, uint32_t device_id) { device_id_map_[graph_id] = device_id; }
  104. Status GetDeviceIdFromGraph(uint32_t graph_id, uint32_t &device_id);
  105. void SetSubscribeInfo(uint64_t prof_switch, uint32_t model_id, bool is_subscribe);
  106. const ProfSubscribeInfo &GetSubscribeInfo() const { return subscribe_info_; }
  107. void CleanSubscribeInfo();
  108. void SetGraphIdToModelMap(uint32_t graph_id, uint32_t model_id) { model_id_map_[graph_id] = model_id; }
  109. Status GetModelIdFromGraph(uint32_t graph_id, uint32_t &model_id);
  110. private:
  111. Status InitFromOptions(const Options &options, MsprofGeOptions &prof_conf);
  112. Status ParseOptions(const std::string &options);
  113. Status ProfParseParam(const std::map<std::string, std::string> &config_para, int32_t &device_num,
  114. vector<int32_t> &device_list);
  115. Status ProfParseDeviceId(const std::map<std::string, std::string> &config_para,
  116. vector<int32_t> &device_list);
  117. uint64_t GetProfilingModule();
  118. void UpdateDeviceIdModuleMap(string prof_type, uint64_t module, const vector<int32_t> &device_list);
  119. void UpdateSubscribeDeviceModuleMap(std::string prof_type, uint32_t device_id, uint64_t module);
  120. void GetOpInputInfo(const OpDescPtr &op, TaskDescInfo &task_desc_info) const;
  121. void GetOpOutputInfo(const OpDescPtr &op, TaskDescInfo &task_desc_info) const;
  122. bool is_load_profiling_;
  123. bool is_execute_profiling_;
  124. bool is_training_trace_;
  125. vector<int32_t> device_id_;
  126. map<int32_t, uint64_t> device_id_module_map_; // key: device_id, value: profiling on module
  127. map<uint32_t, DeviceSubsInfo> subs_dev_module_; // key: device_id, value: profiling on module
  128. uint32_t subscribe_count_;
  129. std::mutex mutex_;
  130. std::mutex mutex_report_;
  131. MsprofCallback prof_cb_;
  132. std::string fp_point_;
  133. std::string bp_point_;
  134. uint32_t reporter_max_len_ = 0;
  135. uint64_t index_id_;
  136. std::map<uint32_t, uint32_t> device_id_map_; // key: graph_id, value: device_id
  137. std::map<uint32_t, uint32_t> model_id_map_; // key: graph_id, value: model_id
  138. ProfSubscribeInfo subscribe_info_;
  139. };
  140. } // namespace ge
  141. #endif // GE_COMMON_PROFILING_PROFILING_MANAGER_H_

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