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

4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. } // namespace
  24. namespace ge {
  25. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY DumpManager &DumpManager::GetInstance() {
  26. static DumpManager instance;
  27. return instance;
  28. }
  29. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status DumpManager::SetDumpConf(const DumpConfig &dump_config) {
  30. std::lock_guard<std::mutex> lock(mutex_);
  31. dump_properties_.ClearDumpPropertyValue();
  32. dump_properties_.ClearDumpInfo();
  33. std::string dump_status;
  34. std::string dump_path;
  35. std::string dump_mode;
  36. std::string dump_op_switch;
  37. if (dump_config.dump_status.empty()) {
  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. return SUCCESS;
  46. }
  47. dump_properties_.SetDumpStatus(dump_status);
  48. dump_op_switch = dump_config.dump_op_switch;
  49. dump_properties_.SetDumpOpSwitch(dump_op_switch);
  50. if (dump_op_switch == kDumpoff && dump_config.dump_list.empty()) {
  51. GELOGE(PARAM_INVALID, "Dump list is invalid,dump_op_switch is %s", dump_op_switch.c_str());
  52. return PARAM_INVALID;
  53. }
  54. if (!dump_config.dump_list.empty()) {
  55. for (auto model_dump : dump_config.dump_list) {
  56. std::string model_name = model_dump.model_name;
  57. GELOGI("Dump model is %s", model_name.c_str());
  58. std::set<std::string> dump_layers;
  59. for (auto layer : model_dump.layers) {
  60. GELOGI("Dump layer is %s in model", layer.c_str());
  61. dump_layers.insert(layer);
  62. }
  63. dump_properties_.AddPropertyValue(model_name, dump_layers);
  64. }
  65. if (dump_op_switch == kDumpOn) {
  66. GELOGI("Start to dump model and single op,dumo op switch is %s", dump_op_switch.c_str());
  67. } else {
  68. GELOGI("Only dump model,dump op switch is %s", dump_op_switch.c_str());
  69. }
  70. } else {
  71. GELOGI("Only dump single op,dumo op switch is %s", dump_op_switch.c_str());
  72. }
  73. dump_path = dump_config.dump_path;
  74. if (dump_path.empty()) {
  75. GELOGE(PARAM_INVALID, "Dump path is empty");
  76. return PARAM_INVALID;
  77. }
  78. if (dump_path[dump_path.size() - 1] != '/') {
  79. dump_path = dump_path + "/";
  80. }
  81. dump_path = dump_path + CurrentTimeInStr() + "/";
  82. GELOGI("Dump path is %s", dump_path.c_str());
  83. dump_properties_.SetDumpPath(dump_path);
  84. dump_mode = dump_config.dump_mode;
  85. GELOGI("Dump mode is %s", dump_mode.c_str());
  86. dump_properties_.SetDumpMode(dump_mode);
  87. return SUCCESS;
  88. }
  89. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY const DumpProperties &DumpManager::GetDumpProperties() {
  90. std::lock_guard<std::mutex> lock(mutex_);
  91. return dump_properties_;
  92. }
  93. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void DumpManager::SetModelName(const std::string &model_name) {
  94. std::lock_guard<std::mutex> lock(mutex_);
  95. model_name_ = model_name;
  96. }
  97. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY const std::string &DumpManager::GetModelName() {
  98. std::lock_guard<std::mutex> lock(mutex_);
  99. return model_name_;
  100. }
  101. } // namespace ge

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