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.3 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
4 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. using std::map;
  28. using std::string;
  29. using std::vector;
  30. using Json = nlohmann::json;
  31. namespace {
  32. const std::string GE_PROFILING_MODULE = "Framework";
  33. // DataTypeConfig MASK
  34. const uint64_t PROF_ACL_API_MASK = 0x0001;
  35. const uint64_t PROF_TASK_TIME_MASK = 0x0002;
  36. const uint64_t PROF_AICORE_METRICS_MASK = 0x0004;
  37. const uint64_t PROF_AICPU_TRACE_MASK = 0x0008;
  38. const uint64_t PROF_MODEL_EXECUTE_MASK = 0x0010;
  39. const uint64_t PROF_RUNTIME_API_MASK = 0x0020;
  40. const uint64_t PROF_RUNTIME_TRACE_MASK = 0x0040;
  41. const uint64_t PROF_SCHEDULE_TIMELINE_MASK = 0x0080;
  42. const uint64_t PROF_SCHEDULE_TRACE_MASK = 0x0100;
  43. const uint64_t PROF_AIVECTORCORE_METRICS_MASK = 0x0200;
  44. const uint64_t PROF_SUBTASK_TIME_MASK = 0x0400;
  45. const uint64_t PROF_TRAINING_TRACE_MASK = 0x0800;
  46. const uint64_t PROF_HCCL_TRACE_MASK = 0x1000;
  47. const uint64_t PROF_DATA_PROCESS_MASK = 0x2000;
  48. const uint64_t PROF_MODEL_LOAD_MASK = 0x8000000000000000;
  49. } // namespace
  50. namespace ge {
  51. struct DeviceSubsInfo {
  52. uint64_t module;
  53. uint32_t subscribe_count;
  54. };
  55. struct MsprofCallback {
  56. MsprofCtrlCallback msprofCtrlCallback;
  57. MsprofReporterCallback msprofReporterCallback;
  58. };
  59. class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ProfilingManager {
  60. public:
  61. ProfilingManager();
  62. virtual ~ProfilingManager();
  63. static ProfilingManager &Instance();
  64. Status Init(const Options &options);
  65. Status ProfInit(uint64_t module);
  66. Status ProfFinalize();
  67. Status ProfStartProfiling(uint64_t module, const std::map<std::string, std::string> &config_para);
  68. Status ProfStopProfiling(uint64_t module, const std::map<std::string, std::string> &config_para);
  69. Status ProfModelSubscribe(uint64_t module, void *model);
  70. Status ProfModelUnsubscribe(void *model);
  71. void StopProfiling();
  72. bool ProfilingTrainingTraceOn() const { return is_training_trace_; }
  73. bool ProfilingModelLoadOn() const { return is_load_profiling_; }
  74. bool ProfilingModelExecuteOn() const;
  75. // is_execute_profiling_ only used by ge option and env
  76. bool ProfilingOn() const { return is_load_profiling_ && is_execute_profiling_; }
  77. void ReportProfilingData(uint32_t model_id, const std::vector<TaskDescInfo> &task_desc_info,
  78. const std::vector<ComputeGraphDescInfo> &compute_graph_desc_info);
  79. void ProfilingTaskDescInfo(uint32_t model_id, const std::vector<TaskDescInfo> &task_desc_info,
  80. const int32_t &device_id);
  81. void ProfilingGraphDescInfo(uint32_t model_id, const std::vector<ComputeGraphDescInfo> &compute_graph_desc_info,
  82. const int32_t &device_id);
  83. Status PluginInit() const;
  84. void PluginUnInit() const;
  85. Status CallMsprofReport(ReporterData &reporter_data) const;
  86. struct MsprofCallback &GetMsprofCallback() { return prof_cb_; }
  87. void SetMsprofCtrlCallback(MsprofCtrlCallback func) { prof_cb_.msprofCtrlCallback = func; }
  88. void SetMsprofReporterCallback(MsprofReporterCallback func) { prof_cb_.msprofReporterCallback = func; }
  89. void GetFpBpPoint(std::string &fp_point, std::string &bp_point);
  90. private:
  91. Status InitFromOptions(const Options &options, MsprofGeOptions &prof_conf);
  92. Status ParseOptions(const std::string &options);
  93. Status ProfParseParam(const std::map<std::string, std::string> &config_para, int32_t &device_num,
  94. vector<int32_t> &device_list);
  95. Status ProfParseDeviceId(const std::map<std::string, std::string> &config_para,
  96. vector<int32_t> &device_list);
  97. uint64_t GetProfilingModule();
  98. void GraphDescReport(const int32_t &device_id, const string &data);
  99. void UpdateDeviceIdModuleMap(string prof_type, uint64_t module, const vector<int32_t> &device_list);
  100. void UpdateSubscribeDeviceModuleMap(std::string prof_type, uint32_t device_id, uint64_t module);
  101. bool is_load_profiling_;
  102. bool is_execute_profiling_;
  103. bool is_training_trace_;
  104. vector<int32_t> device_id_;
  105. map<int32_t, uint64_t> device_id_module_map_; // key: device_id, value: profiling on module
  106. map<uint32_t, DeviceSubsInfo> subs_dev_module_; // key: device_id, value: profiling on module
  107. uint32_t subscribe_count_;
  108. std::mutex mutex_;
  109. MsprofCallback prof_cb_;
  110. std::string fp_point_;
  111. std::string bp_point_;
  112. };
  113. } // namespace ge
  114. #endif // GE_COMMON_PROFILING_PROFILING_MANAGER_H_

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