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

4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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_properties.h"
  17. #include <cstdio>
  18. #include <string>
  19. #include "common/ge/ge_util.h"
  20. #include "framework/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 std::string kDumpStatusOpen = "on";
  31. const uint32_t kAicoreOverflow = (0x1 << 0);
  32. const uint32_t kAtomicOverflow = (0x1 << 1);
  33. const uint32_t kAllOverflow = (kAicoreOverflow | kAtomicOverflow);
  34. } // namespace
  35. namespace ge {
  36. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY DumpProperties::DumpProperties(const DumpProperties &other) {
  37. CopyFrom(other);
  38. }
  39. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY DumpProperties &DumpProperties::operator=(
  40. const DumpProperties &other) {
  41. CopyFrom(other);
  42. return *this;
  43. }
  44. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void DumpProperties::InitByOptions() {
  45. enable_dump_.clear();
  46. enable_dump_debug_.clear();
  47. dump_path_.clear();
  48. dump_step_.clear();
  49. dump_mode_.clear();
  50. is_train_op_debug_ = false;
  51. is_infer_op_debug_ = false;
  52. op_debug_mode_ = 0;
  53. std::string enable_dump;
  54. (void)GetContext().GetOption(OPTION_EXEC_ENABLE_DUMP, enable_dump);
  55. enable_dump_ = enable_dump;
  56. std::string enable_dump_debug;
  57. (void)GetContext().GetOption(OPTION_EXEC_ENABLE_DUMP_DEBUG, enable_dump_debug);
  58. enable_dump_debug_ = enable_dump_debug;
  59. if ((enable_dump_ == kEnableFlag) || (enable_dump_debug_ == kEnableFlag)) {
  60. std::string dump_path;
  61. if (GetContext().GetOption(OPTION_EXEC_DUMP_PATH, dump_path) == GRAPH_SUCCESS) {
  62. if (!dump_path.empty() && dump_path[dump_path.size() - 1] != '/') {
  63. dump_path = dump_path + "/";
  64. }
  65. dump_path = dump_path + CurrentTimeInStr() + "/";
  66. GELOGI("Get dump path %s successfully", dump_path.c_str());
  67. SetDumpPath(dump_path);
  68. } else {
  69. GELOGW("Dump path is not set");
  70. }
  71. }
  72. if (enable_dump_ == kEnableFlag) {
  73. std::string dump_step;
  74. if (GetContext().GetOption(OPTION_EXEC_DUMP_STEP, dump_step) == GRAPH_SUCCESS) {
  75. GELOGI("Get dump step %s successfully", dump_step.c_str());
  76. SetDumpStep(dump_step);
  77. }
  78. string dump_mode;
  79. if (GetContext().GetOption(OPTION_EXEC_DUMP_MODE, dump_mode) == GRAPH_SUCCESS) {
  80. GELOGI("Get dump mode %s successfully", dump_mode.c_str());
  81. SetDumpMode(dump_mode);
  82. }
  83. AddPropertyValue(DUMP_ALL_MODEL, {});
  84. }
  85. SetDumpDebugOptions();
  86. }
  87. // The following is the new dump scenario of the fusion operator
  88. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void DumpProperties::AddPropertyValue(
  89. const std::string &model, const std::set<std::string> &layers) {
  90. for (const std::string &layer : layers) {
  91. GELOGI("This model %s config to dump layer %s", model.c_str(), layer.c_str());
  92. }
  93. model_dump_properties_map_[model] = layers;
  94. }
  95. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void DumpProperties::DeletePropertyValue(const std::string &model) {
  96. auto iter = model_dump_properties_map_.find(model);
  97. if (iter != model_dump_properties_map_.end()) {
  98. model_dump_properties_map_.erase(iter);
  99. }
  100. }
  101. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void DumpProperties::ClearDumpPropertyValue() {
  102. model_dump_properties_map_.clear();
  103. }
  104. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void DumpProperties::ClearDumpInfo() {
  105. enable_dump_.clear();
  106. enable_dump_debug_.clear();
  107. dump_path_.clear();
  108. dump_step_.clear();
  109. dump_mode_.clear();
  110. dump_op_switch_.clear();
  111. dump_status_.clear();
  112. is_train_op_debug_ = false;
  113. is_infer_op_debug_ = false;
  114. op_debug_mode_ = 0;
  115. }
  116. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY std::set<std::string> DumpProperties::GetAllDumpModel() const {
  117. std::set<std::string> model_list;
  118. for (auto &iter : model_dump_properties_map_) {
  119. model_list.insert(iter.first);
  120. }
  121. return model_list;
  122. }
  123. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY std::set<std::string> DumpProperties::GetPropertyValue(
  124. const std::string &model) const {
  125. auto iter = model_dump_properties_map_.find(model);
  126. if (iter != model_dump_properties_map_.end()) {
  127. return iter->second;
  128. }
  129. return {};
  130. }
  131. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool DumpProperties::IsLayerNeedDump(
  132. const std::string &model, const std::string &om_name, const std::string &op_name) const {
  133. // if dump all
  134. GELOGD("model name is %s om name is %s op is %s in layer need dump", model.c_str(), om_name.c_str(), op_name.c_str());
  135. if (model_dump_properties_map_.find(DUMP_ALL_MODEL) != model_dump_properties_map_.end()) {
  136. return true;
  137. }
  138. // if this model need dump
  139. auto om_name_iter = model_dump_properties_map_.find(om_name);
  140. auto model_name_iter = model_dump_properties_map_.find(model);
  141. if (om_name_iter != model_dump_properties_map_.end() || model_name_iter != model_dump_properties_map_.end()) {
  142. // if no dump layer info, dump all layer in this model
  143. auto model_iter = om_name_iter != model_dump_properties_map_.end() ? om_name_iter : model_name_iter;
  144. if (model_iter->second.empty()) {
  145. return true;
  146. }
  147. return model_iter->second.find(op_name) != model_iter->second.end();
  148. }
  149. GELOGD("Model %s is not seated to be dump.", model.c_str());
  150. return false;
  151. }
  152. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void DumpProperties::SetDumpPath(const std::string &path) {
  153. dump_path_ = path;
  154. }
  155. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY const std::string &DumpProperties::GetDumpPath() const {
  156. return dump_path_;
  157. }
  158. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void DumpProperties::SetDumpStep(const std::string &step) {
  159. dump_step_ = step;
  160. }
  161. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY const std::string &DumpProperties::GetDumpStep() const {
  162. return dump_step_;
  163. }
  164. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void DumpProperties::SetDumpMode(const std::string &mode) {
  165. dump_mode_ = mode;
  166. }
  167. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY const std::string &DumpProperties::GetDumpMode() const {
  168. return dump_mode_;
  169. }
  170. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void DumpProperties::SetDumpStatus(const std::string &status) {
  171. dump_status_ = status;
  172. }
  173. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY const std::string &DumpProperties::GetDumpStatus() const {
  174. return dump_status_;
  175. }
  176. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void DumpProperties::InitInferOpDebug() {
  177. is_infer_op_debug_ = true;
  178. }
  179. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void DumpProperties::SetOpDebugMode(const uint32_t &op_debug_mode) {
  180. op_debug_mode_ = op_debug_mode;
  181. }
  182. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void DumpProperties::SetDumpOpSwitch(
  183. const std::string &dump_op_switch) {
  184. dump_op_switch_ = dump_op_switch;
  185. }
  186. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY const std::string &DumpProperties::GetDumpOpSwitch() const {
  187. return dump_op_switch_;
  188. }
  189. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool DumpProperties::IsSingleOpNeedDump() const {
  190. if (dump_op_switch_ == kDumpStatusOpen) {
  191. return true;
  192. }
  193. return false;
  194. }
  195. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool DumpProperties::IsDumpOpen() const {
  196. if (enable_dump_ == kEnableFlag || dump_status_ == kDumpStatusOpen) {
  197. return true;
  198. }
  199. return false;
  200. }
  201. void DumpProperties::CopyFrom(const DumpProperties &other) {
  202. if (&other != this) {
  203. enable_dump_ = other.enable_dump_;
  204. enable_dump_debug_ = other.enable_dump_debug_;
  205. dump_path_ = other.dump_path_;
  206. dump_step_ = other.dump_step_;
  207. dump_mode_ = other.dump_mode_;
  208. dump_status_ = other.dump_status_;
  209. dump_op_switch_ = other.dump_op_switch_;
  210. model_dump_properties_map_ = other.model_dump_properties_map_;
  211. is_train_op_debug_ = other.is_train_op_debug_;
  212. is_infer_op_debug_ = other.is_infer_op_debug_;
  213. op_debug_mode_ = other.op_debug_mode_;
  214. }
  215. }
  216. void DumpProperties::SetDumpDebugOptions() {
  217. if (enable_dump_debug_ == kEnableFlag) {
  218. std::string dump_debug_mode;
  219. if (GetContext().GetOption(OPTION_EXEC_DUMP_DEBUG_MODE, dump_debug_mode) == GRAPH_SUCCESS) {
  220. GELOGD("Get dump debug mode %s successfully", dump_debug_mode.c_str());
  221. } else {
  222. GELOGW("Dump debug mode is not set.");
  223. return;
  224. }
  225. if (dump_debug_mode == OP_DEBUG_AICORE) {
  226. GELOGD("ge.exec.dumpDebugMode=aicore_overflow, op debug is open.");
  227. is_train_op_debug_ = true;
  228. op_debug_mode_ = kAicoreOverflow;
  229. } else if (dump_debug_mode == OP_DEBUG_ATOMIC) {
  230. GELOGD("ge.exec.dumpDebugMode=atomic_overflow, op debug is open.");
  231. is_train_op_debug_ = true;
  232. op_debug_mode_ = kAtomicOverflow;
  233. } else if (dump_debug_mode == OP_DEBUG_ALL) {
  234. GELOGD("ge.exec.dumpDebugMode=all, op debug is open.");
  235. is_train_op_debug_ = true;
  236. op_debug_mode_ = kAllOverflow;
  237. } else {
  238. GELOGW("ge.exec.dumpDebugMode is invalid.");
  239. }
  240. } else {
  241. GELOGI("ge.exec.enableDumpDebug is false or is not set.");
  242. }
  243. }
  244. } // namespace ge

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