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_properties.cc 8.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /**
  2. * Copyright 2019-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_properties.h"
  17. #include <cstdio>
  18. #include <string>
  19. #include "common/ge/ge_util.h"
  20. #include "common/util.h"
  21. #include "framework/common/debug/ge_log.h"
  22. #include "framework/common/debug/log.h"
  23. #include "framework/common/ge_types.h"
  24. #include "framework/common/types.h"
  25. #include "graph/debug/ge_attr_define.h"
  26. #include "graph/ge_context.h"
  27. #include "graph/utils/attr_utils.h"
  28. namespace {
  29. const std::string kEnableFlag = "1";
  30. const uint32_t kAicoreOverflow = (0x1 << 0);
  31. const uint32_t kAtomicOverflow = (0x1 << 1);
  32. const uint32_t kAllOverflow = (kAicoreOverflow | kAtomicOverflow);
  33. } // namespace
  34. namespace ge {
  35. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY DumpProperties::DumpProperties(const DumpProperties &other) {
  36. CopyFrom(other);
  37. }
  38. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY DumpProperties &DumpProperties::operator=(
  39. const DumpProperties &other) {
  40. CopyFrom(other);
  41. return *this;
  42. }
  43. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void DumpProperties::InitByOptions() {
  44. enable_dump_.clear();
  45. enable_dump_debug_.clear();
  46. dump_path_.clear();
  47. dump_step_.clear();
  48. dump_mode_.clear();
  49. is_op_debug_ = false;
  50. op_debug_mode_ = 0;
  51. std::string enable_dump;
  52. (void)GetContext().GetOption(OPTION_EXEC_ENABLE_DUMP, enable_dump);
  53. enable_dump_ = enable_dump;
  54. std::string enable_dump_debug;
  55. (void)GetContext().GetOption(OPTION_EXEC_ENABLE_DUMP_DEBUG, enable_dump_debug);
  56. enable_dump_debug_ = enable_dump_debug;
  57. if ((enable_dump_ == kEnableFlag) || (enable_dump_debug_ == kEnableFlag)) {
  58. std::string dump_path;
  59. if (GetContext().GetOption(OPTION_EXEC_DUMP_PATH, dump_path) == GRAPH_SUCCESS) {
  60. if (!dump_path.empty() && dump_path[dump_path.size() - 1] != '/') {
  61. dump_path = dump_path + "/";
  62. }
  63. dump_path = dump_path + CurrentTimeInStr() + "/";
  64. GELOGI("Get dump path %s successfully", dump_path.c_str());
  65. SetDumpPath(dump_path);
  66. } else {
  67. GELOGW("Dump path is not set");
  68. }
  69. }
  70. if (enable_dump_ == kEnableFlag) {
  71. std::string dump_step;
  72. if (GetContext().GetOption(OPTION_EXEC_DUMP_STEP, dump_step) == GRAPH_SUCCESS) {
  73. GELOGD("Get dump step %s successfully", dump_step.c_str());
  74. SetDumpStep(dump_step);
  75. }
  76. string dump_mode;
  77. if (GetContext().GetOption(OPTION_EXEC_DUMP_MODE, dump_mode) == GRAPH_SUCCESS) {
  78. GELOGD("Get dump mode %s successfully", dump_mode.c_str());
  79. SetDumpMode(dump_mode);
  80. }
  81. AddPropertyValue(DUMP_ALL_MODEL, {});
  82. }
  83. SetDumpDebugOptions();
  84. }
  85. // The following is the new dump scenario of the fusion operator
  86. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void DumpProperties::AddPropertyValue(
  87. const std::string &model, const std::set<std::string> &layers) {
  88. for (const std::string &layer : layers) {
  89. GELOGI("This model %s config to dump layer %s", model.c_str(), layer.c_str());
  90. }
  91. model_dump_properties_map_[model] = layers;
  92. }
  93. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void DumpProperties::DeletePropertyValue(const std::string &model) {
  94. auto iter = model_dump_properties_map_.find(model);
  95. if (iter != model_dump_properties_map_.end()) {
  96. model_dump_properties_map_.erase(iter);
  97. }
  98. }
  99. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void DumpProperties::ClearDumpPropertyValue() {
  100. model_dump_properties_map_.clear();
  101. }
  102. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void DumpProperties::ClearDumpInfo() {
  103. enable_dump_.clear();
  104. enable_dump_debug_.clear();
  105. dump_path_.clear();
  106. dump_step_.clear();
  107. dump_mode_.clear();
  108. is_op_debug_ = false;
  109. op_debug_mode_ = 0;
  110. }
  111. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY std::set<std::string> DumpProperties::GetAllDumpModel() const {
  112. std::set<std::string> model_list;
  113. for (auto &iter : model_dump_properties_map_) {
  114. model_list.insert(iter.first);
  115. }
  116. return model_list;
  117. }
  118. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY std::set<std::string> DumpProperties::GetPropertyValue(
  119. const std::string &model) const {
  120. auto iter = model_dump_properties_map_.find(model);
  121. if (iter != model_dump_properties_map_.end()) {
  122. return iter->second;
  123. }
  124. return {};
  125. }
  126. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool DumpProperties::IsLayerNeedDump(
  127. const std::string &model, const std::string &om_name, const std::string &op_name) const {
  128. // if dump all
  129. if (model_dump_properties_map_.find(DUMP_ALL_MODEL) != model_dump_properties_map_.end()) {
  130. return true;
  131. }
  132. // if this model need dump
  133. auto om_name_iter = model_dump_properties_map_.find(om_name);
  134. auto model_name_iter = model_dump_properties_map_.find(model);
  135. if (om_name_iter != model_dump_properties_map_.end() || model_name_iter != model_dump_properties_map_.end()) {
  136. // if no dump layer info, dump all layer in this model
  137. auto model_iter = om_name_iter != model_dump_properties_map_.end() ? om_name_iter : model_name_iter;
  138. if (model_iter->second.empty()) {
  139. return true;
  140. }
  141. return model_iter->second.find(op_name) != model_iter->second.end();
  142. }
  143. GELOGD("Model %s is not seated to be dump.", model.c_str());
  144. return false;
  145. }
  146. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void DumpProperties::SetDumpPath(const std::string &path) {
  147. dump_path_ = path;
  148. }
  149. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY const std::string &DumpProperties::GetDumpPath() const {
  150. return dump_path_;
  151. }
  152. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void DumpProperties::SetDumpStep(const std::string &step) {
  153. dump_step_ = step;
  154. }
  155. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY const std::string &DumpProperties::GetDumpStep() const {
  156. return dump_step_;
  157. }
  158. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void DumpProperties::SetDumpMode(const std::string &mode) {
  159. dump_mode_ = mode;
  160. }
  161. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY const std::string &DumpProperties::GetDumpMode() const {
  162. return dump_mode_;
  163. }
  164. void DumpProperties::CopyFrom(const DumpProperties &other) {
  165. if (&other != this) {
  166. enable_dump_ = other.enable_dump_;
  167. enable_dump_debug_ = other.enable_dump_debug_;
  168. dump_path_ = other.dump_path_;
  169. dump_step_ = other.dump_step_;
  170. dump_mode_ = other.dump_mode_;
  171. model_dump_properties_map_ = other.model_dump_properties_map_;
  172. is_op_debug_ = other.is_op_debug_;
  173. op_debug_mode_ = other.op_debug_mode_;
  174. }
  175. }
  176. void DumpProperties::SetDumpDebugOptions() {
  177. if (enable_dump_debug_ == kEnableFlag) {
  178. std::string dump_debug_mode;
  179. if (GetContext().GetOption(OPTION_EXEC_DUMP_DEBUG_MODE, dump_debug_mode) == GRAPH_SUCCESS) {
  180. GELOGD("Get dump debug mode %s successfully", dump_debug_mode.c_str());
  181. } else {
  182. GELOGW("Dump debug mode is not set.");
  183. return;
  184. }
  185. if (dump_debug_mode == OP_DEBUG_AICORE) {
  186. GELOGD("ge.exec.dumpDebugMode=aicore_overflow, op debug is open.");
  187. is_op_debug_ = true;
  188. op_debug_mode_ = kAicoreOverflow;
  189. } else if (dump_debug_mode == OP_DEBUG_ATOMIC) {
  190. GELOGD("ge.exec.dumpDebugMode=atomic_overflow, op debug is open.");
  191. is_op_debug_ = true;
  192. op_debug_mode_ = kAtomicOverflow;
  193. } else if (dump_debug_mode == OP_DEBUG_ALL) {
  194. GELOGD("ge.exec.dumpDebugMode=all, op debug is open.");
  195. is_op_debug_ = true;
  196. op_debug_mode_ = kAllOverflow;
  197. } else {
  198. GELOGW("ge.exec.dumpDebugMode is invalid.");
  199. }
  200. } else {
  201. GELOGI("ge.exec.enableDumpDebug is false or is not set.");
  202. }
  203. }
  204. } // namespace ge

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