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.5 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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, "Dump list is invalid,dump_op_switch is %s", dump_op_switch.c_str());
  54. return PARAM_INVALID;
  55. }
  56. if (!dump_config.dump_list.empty()) {
  57. for (auto model_dump : dump_config.dump_list) {
  58. std::string model_name = model_dump.model_name;
  59. GELOGI("Dump model is %s", model_name.c_str());
  60. std::set<std::string> dump_layers;
  61. for (auto layer : model_dump.layers) {
  62. GELOGI("Dump layer is %s in model", layer.c_str());
  63. dump_layers.insert(layer);
  64. }
  65. dump_properties.AddPropertyValue(model_name, dump_layers);
  66. }
  67. if (dump_op_switch == kDumpOn) {
  68. GELOGI("Start to dump model and single op,dump op switch is %s", dump_op_switch.c_str());
  69. } else {
  70. GELOGI("Only dump model,dump op switch is %s", dump_op_switch.c_str());
  71. }
  72. } else {
  73. GELOGI("Only dump single op,dump op switch is %s", dump_op_switch.c_str());
  74. }
  75. dump_path = dump_config.dump_path;
  76. if (dump_path.empty()) {
  77. GELOGE(PARAM_INVALID, "Dump path is empty");
  78. return PARAM_INVALID;
  79. }
  80. if (dump_path[dump_path.size() - 1] != '/') {
  81. dump_path = dump_path + "/";
  82. }
  83. dump_path = dump_path + CurrentTimeInStr() + "/";
  84. GELOGI("Dump path is %s", dump_path.c_str());
  85. dump_properties.SetDumpPath(dump_path);
  86. dump_mode = dump_config.dump_mode;
  87. GELOGI("Dump mode is %s", dump_mode.c_str());
  88. dump_properties.SetDumpMode(dump_mode);
  89. dump_properties_map_[kInferSessionId] = dump_properties;
  90. return SUCCESS;
  91. }
  92. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY const DumpProperties &DumpManager::GetDumpProperties(
  93. uint64_t session_id) {
  94. std::lock_guard<std::mutex> lock(mutex_);
  95. auto iter = dump_properties_map_.find(session_id);
  96. if (iter != dump_properties_map_.end()) {
  97. return iter->second;
  98. }
  99. static DumpProperties default_properties;
  100. return default_properties;
  101. }
  102. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void DumpManager::AddDumpProperties(
  103. uint64_t session_id, const DumpProperties &dump_properties) {
  104. std::lock_guard<std::mutex> lock(mutex_);
  105. dump_properties_map_.emplace(session_id, dump_properties);
  106. }
  107. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void DumpManager::RemoveDumpProperties(uint64_t session_id) {
  108. std::lock_guard<std::mutex> lock(mutex_);
  109. auto iter = dump_properties_map_.find(session_id);
  110. if (iter != dump_properties_map_.end()) {
  111. dump_properties_map_.erase(iter);
  112. }
  113. }
  114. } // namespace ge

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