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.

dump_manager.cc 4.7 kB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. #include "common/dump/dump_manager.h"
  17. #include "framework/common/debug/ge_log.h"
  18. #include "framework/common/debug/log.h"
  19. namespace {
  20. const char *const kDumpOFF = "OFF";
  21. const char *const kDumpoff = "off";
  22. const char *const kDumpOn = "on";
  23. const uint64_t kInferSessionId = 0;
  24. } // namespace
  25. namespace ge {
  26. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY DumpManager &DumpManager::GetInstance() {
  27. static DumpManager instance;
  28. return instance;
  29. }
  30. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status DumpManager::SetDumpConf(const DumpConfig &dump_config) {
  31. DumpProperties dump_properties;
  32. std::string dump_status;
  33. std::string dump_path;
  34. std::string dump_mode;
  35. std::string dump_op_switch;
  36. if (dump_config.dump_status.empty()) {
  37. dump_properties_map_.emplace(kInferSessionId, dump_properties);
  38. GELOGI("Dump does not open");
  39. return SUCCESS;
  40. }
  41. dump_status = dump_config.dump_status;
  42. GELOGI("Dump status is %s", dump_status.c_str());
  43. if (dump_config.dump_status == kDumpoff || dump_config.dump_status == kDumpOFF) {
  44. dump_properties.ClearDumpPropertyValue();
  45. dump_properties_map_.emplace(kInferSessionId, dump_properties);
  46. return SUCCESS;
  47. }
  48. dump_properties.SetDumpStatus(dump_status);
  49. dump_op_switch = dump_config.dump_op_switch;
  50. dump_properties.SetDumpOpSwitch(dump_op_switch);
  51. if (dump_op_switch == kDumpoff && dump_config.dump_list.empty()) {
  52. dump_properties_map_.emplace(kInferSessionId, dump_properties);
  53. GELOGE(PARAM_INVALID, "[Check][DumpList]Invalid, dump_op_switch is %s",
  54. dump_op_switch.c_str());
  55. REPORT_INNER_ERROR("E19999", "Dump list check invalid, dump_op_switch is %s",
  56. dump_op_switch.c_str());
  57. return PARAM_INVALID;
  58. }
  59. if (!dump_config.dump_list.empty()) {
  60. for (auto model_dump : dump_config.dump_list) {
  61. std::string model_name = model_dump.model_name;
  62. GELOGI("Dump model is %s", model_name.c_str());
  63. std::set<std::string> dump_layers;
  64. for (auto layer : model_dump.layers) {
  65. GELOGI("Dump layer is %s in model", layer.c_str());
  66. dump_layers.insert(layer);
  67. }
  68. dump_properties.AddPropertyValue(model_name, dump_layers);
  69. }
  70. if (dump_op_switch == kDumpOn) {
  71. GELOGI("Start to dump model and single op,dump op switch is %s", dump_op_switch.c_str());
  72. } else {
  73. GELOGI("Only dump model,dump op switch is %s", dump_op_switch.c_str());
  74. }
  75. } else {
  76. GELOGI("Only dump single op,dump op switch is %s", dump_op_switch.c_str());
  77. }
  78. dump_path = dump_config.dump_path;
  79. if (dump_path.empty()) {
  80. GELOGE(PARAM_INVALID, "[Check][DumpPath]It is empty");
  81. REPORT_INNER_ERROR("E19999", "Dump path check is empty");
  82. return PARAM_INVALID;
  83. }
  84. if (dump_path[dump_path.size() - 1] != '/') {
  85. dump_path = dump_path + "/";
  86. }
  87. dump_path = dump_path + CurrentTimeInStr() + "/";
  88. GELOGI("Dump path is %s", dump_path.c_str());
  89. dump_properties.SetDumpPath(dump_path);
  90. dump_mode = dump_config.dump_mode;
  91. GELOGI("Dump mode is %s", dump_mode.c_str());
  92. dump_properties.SetDumpMode(dump_mode);
  93. dump_properties_map_[kInferSessionId] = dump_properties;
  94. return SUCCESS;
  95. }
  96. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY const DumpProperties &DumpManager::GetDumpProperties(
  97. uint64_t session_id) {
  98. std::lock_guard<std::mutex> lock(mutex_);
  99. auto iter = dump_properties_map_.find(session_id);
  100. if (iter != dump_properties_map_.end()) {
  101. return iter->second;
  102. }
  103. static DumpProperties default_properties;
  104. return default_properties;
  105. }
  106. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void DumpManager::AddDumpProperties(
  107. uint64_t session_id, const DumpProperties &dump_properties) {
  108. std::lock_guard<std::mutex> lock(mutex_);
  109. dump_properties_map_.emplace(session_id, dump_properties);
  110. }
  111. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void DumpManager::RemoveDumpProperties(uint64_t session_id) {
  112. std::lock_guard<std::mutex> lock(mutex_);
  113. auto iter = dump_properties_map_.find(session_id);
  114. if (iter != dump_properties_map_.end()) {
  115. dump_properties_map_.erase(iter);
  116. }
  117. }
  118. } // namespace ge

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