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.

next_iteration_pass.cc 18 kB

5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
4 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 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
5 years ago
5 years ago
4 years ago
5 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
4 years ago
4 years ago
5 years ago
4 years ago
4 years ago
4 years ago
5 years ago
4 years ago
5 years ago
5 years ago
4 years ago
4 years ago
5 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  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 "graph/passes/next_iteration_pass.h"
  17. #include "common/ge/ge_util.h"
  18. #include "graph/common/omg_util.h"
  19. #include "graph/utils/node_utils.h"
  20. using std::string;
  21. namespace ge {
  22. namespace {
  23. constexpr int64_t kLoopType = 1;
  24. constexpr uint8_t kMaxTransOp = 3;
  25. constexpr uint8_t kTransOpIoSize = 1;
  26. }
  27. Status NextIterationPass::Run(ComputeGraphPtr graph) {
  28. GELOGD("NextIterationPass Enter");
  29. /// Enter-----------+
  30. /// +-> Merge -> Switch <- LoopCond <- Cond
  31. /// NextIteration---+
  32. for (auto &node : graph->GetDirectNode()) {
  33. const std::string type = node->GetType();
  34. if ((type != ENTER) && (type != REFENTER)) {
  35. continue;
  36. }
  37. if (GroupEnterNode(node) != SUCCESS) {
  38. GELOGE(INTERNAL_ERROR, "[Group][EnterNode] %s failed.", node->GetName().c_str());
  39. return INTERNAL_ERROR;
  40. }
  41. }
  42. if (FindWhileGroups() != SUCCESS) {
  43. GELOGE(INTERNAL_ERROR, "[Find][WhileGroups] in graph:%s failed.", graph->GetName().c_str());
  44. return INTERNAL_ERROR;
  45. }
  46. if (!VerifyWhileGroup()) {
  47. GELOGE(INTERNAL_ERROR, "[Verify][WhileGroup] in graph:%s failed.", graph->GetName().c_str());
  48. return INTERNAL_ERROR;
  49. }
  50. if (HandleWhileGroup(graph) != SUCCESS) {
  51. GELOGE(FAILED, "[Handle][WhileGroup] in graph:%s failed.", graph->GetName().c_str());
  52. return FAILED;
  53. }
  54. GELOGD("NextIterationPass Leave");
  55. return SUCCESS;
  56. }
  57. ///
  58. /// @brief Group Enter node
  59. /// @param [in] enter_node
  60. /// @return Status
  61. ///
  62. Status NextIterationPass::GroupEnterNode(const NodePtr &enter_node) {
  63. OpDescPtr enter_desc = enter_node->GetOpDesc();
  64. GE_CHECK_NOTNULL(enter_desc);
  65. std::string frame_name;
  66. if (!ge::AttrUtils::GetStr(enter_desc, ENTER_ATTR_FRAME_NAME, frame_name) || frame_name.empty()) {
  67. REPORT_CALL_ERROR("E19999", "Get Attr:%s from op:%s(%s) failed", ENTER_ATTR_FRAME_NAME.c_str(),
  68. enter_desc->GetName().c_str(), enter_desc->GetType().c_str());
  69. GELOGE(FAILED, "[Get][Attr] %s from op:%s(%s) failed", ENTER_ATTR_FRAME_NAME.c_str(),
  70. enter_desc->GetName().c_str(), enter_desc->GetType().c_str());
  71. return FAILED;
  72. }
  73. string batch_label;
  74. if (ge::AttrUtils::GetStr(enter_desc, ATTR_NAME_BATCH_LABEL, batch_label)) {
  75. frame_name += batch_label;
  76. }
  77. auto iter = loop_group_map_.find(frame_name);
  78. if (iter == loop_group_map_.end()) {
  79. LoopCondGroupPtr loop_group = MakeShared<LoopCondGroup>();
  80. if (loop_group == nullptr) {
  81. REPORT_CALL_ERROR("E19999", "New LoopCondGroup failed");
  82. GELOGE(FAILED, "[New][LoopCondGroup] failed.");
  83. return FAILED;
  84. }
  85. loop_group->enter_nodes.emplace_back(enter_node);
  86. loop_group_map_[frame_name] = loop_group;
  87. } else {
  88. iter->second->enter_nodes.emplace_back(enter_node);
  89. }
  90. return SUCCESS;
  91. }
  92. ///
  93. /// @brief Find while groups
  94. /// @return Status
  95. ///
  96. Status NextIterationPass::FindWhileGroups() {
  97. for (const auto &loop_group_iter : loop_group_map_) {
  98. const std::string &frame_name = loop_group_iter.first;
  99. for (const auto &enter_node : loop_group_iter.second->enter_nodes) {
  100. for (const auto &out_node : enter_node->GetOutAllNodes()) {
  101. std::string type;
  102. GE_CHK_STATUS_RET(GetOriginalType(out_node, type), "[Get][OriginalType] failed.");
  103. if ((type != MERGE) && (type != REFMERGE)) {
  104. continue;
  105. }
  106. NodePtr next_node = nullptr;
  107. if (FindTargetNode(out_node, NEXTITERATION, true, next_node) != SUCCESS) {
  108. GELOGE(INTERNAL_ERROR, "[Get][NextIterationNode] failed, frame_name:%s", frame_name.c_str());
  109. return INTERNAL_ERROR;
  110. }
  111. loop_group_iter.second->merge_next_pairs.emplace_back(std::make_pair(out_node, next_node));
  112. NodePtr switch_node = nullptr;
  113. if (FindTargetNode(out_node, SWITCH, false, switch_node) != SUCCESS) {
  114. GELOGE(INTERNAL_ERROR, "[Get][SwitchNode] failed, frame_name:%s.", frame_name.c_str());
  115. return INTERNAL_ERROR;
  116. }
  117. if (switch_node == nullptr) {
  118. continue;
  119. }
  120. if (!AttrUtils::SetInt(switch_node->GetOpDesc(), ATTR_NAME_STREAM_SWITCH_TYPE, kLoopType)) {
  121. REPORT_CALL_ERROR("E19999", "Set Attr:%s to op:%s(%s) failed", ATTR_NAME_STREAM_SWITCH_TYPE.c_str(),
  122. switch_node->GetName().c_str(), switch_node->GetType().c_str());
  123. GELOGE(INTERNAL_ERROR, "[Set][Attr] %s to op:%s(%s) failed", ATTR_NAME_STREAM_SWITCH_TYPE.c_str(),
  124. switch_node->GetName().c_str(), switch_node->GetType().c_str());
  125. return INTERNAL_ERROR;
  126. }
  127. NodePtr loop_cond = nullptr;
  128. if (FindTargetNode(switch_node, LOOPCOND, true, loop_cond) != SUCCESS) {
  129. GELOGE(INTERNAL_ERROR, "[Get][LoopCondNode] failed, frame_name:%s.", frame_name.c_str());
  130. return INTERNAL_ERROR;
  131. }
  132. loop_group_iter.second->switch_nodes.emplace_back(switch_node);
  133. if (loop_group_iter.second->loop_cond == nullptr) {
  134. loop_group_iter.second->loop_cond = loop_cond;
  135. } else if (loop_group_iter.second->loop_cond != loop_cond) {
  136. REPORT_INNER_ERROR("E19999", "Multi LoopCond nodes exist, frame_name:%s, check invalid", frame_name.c_str());
  137. GELOGE(FAILED, "[Check][Param] Multi LoopCond nodes exist, frame_name:%s.", frame_name.c_str());
  138. return FAILED;
  139. }
  140. }
  141. }
  142. }
  143. return SUCCESS;
  144. }
  145. ///
  146. /// @brief Verify if valid
  147. /// @return bool
  148. ///
  149. bool NextIterationPass::VerifyWhileGroup() {
  150. // map<frame_name, LoopCondGroup>
  151. for (const auto &loop_group_iter : loop_group_map_) {
  152. const std::string &frame_name = loop_group_iter.first;
  153. if (frame_name.empty()) {
  154. REPORT_INNER_ERROR("E19999", "Verify while group failed, frame_name is empty");
  155. GELOGE(INTERNAL_ERROR, "[Check][Param] Verify while group failed, frame_name is empty.");
  156. return false;
  157. }
  158. if (loop_group_iter.second->loop_cond == nullptr) {
  159. REPORT_INNER_ERROR("E19999", "Verify while group failed, LoopCond is null, frame_name:%s.", frame_name.c_str());
  160. GELOGE(INTERNAL_ERROR, "[Check][Param] Verify while group failed, LoopCond is null, frame_name:%s.",
  161. frame_name.c_str());
  162. return false;
  163. }
  164. for (const auto &pair_iter : loop_group_iter.second->merge_next_pairs) {
  165. if ((pair_iter.first == nullptr) || (pair_iter.second == nullptr)) {
  166. REPORT_INNER_ERROR("E19999", "Verify while group failed, merge_node/next_node is null, frame_name:%s.",
  167. frame_name.c_str());
  168. GELOGE(INTERNAL_ERROR, "[Check][Param] Verify while group failed, merge_node/next_node is null, frame_name:%s.",
  169. frame_name.c_str());
  170. return false;
  171. }
  172. }
  173. }
  174. return true;
  175. }
  176. ///
  177. /// @brief Handle while group
  178. /// @param [in] graph
  179. /// @return Status
  180. ///
  181. Status NextIterationPass::HandleWhileGroup(ComputeGraphPtr &graph) {
  182. for (const auto &loop_cond_iter : loop_group_map_) {
  183. const LoopCondGroup &loop_group = *loop_cond_iter.second;
  184. const std::string &cond_name = loop_cond_iter.second->loop_cond->GetName();
  185. const int64_t group_index = loop_group.loop_cond->GetOpDesc()->GetId();
  186. GELOGI("Handle while group, LoopCond node: %s.", cond_name.c_str());
  187. // Create Active node, Enter->Active->Merge, NextIteration->Active->Merge
  188. NodePtr enter_active = CreateActiveNode(graph, cond_name + "_Enter_" + STREAMACTIVE);
  189. NodePtr next_active = CreateActiveNode(graph, cond_name + "_Next_" + STREAMACTIVE);
  190. if ((enter_active == nullptr) || (next_active == nullptr)) {
  191. GELOGE(INTERNAL_ERROR, "[Create][ActiveNode] failed, cond_name:%s.", cond_name.c_str());
  192. return INTERNAL_ERROR;
  193. }
  194. for (const auto &enter_node : loop_cond_iter.second->enter_nodes) {
  195. // Enter --> Active
  196. if (GraphUtils::AddEdge(enter_node->GetOutControlAnchor(), enter_active->GetInControlAnchor()) != GRAPH_SUCCESS) {
  197. REPORT_CALL_ERROR("E19999", "Add control edge between op:%s(%s) and op:%s(%s) failed",
  198. enter_node->GetName().c_str(), enter_node->GetType().c_str(),
  199. enter_active->GetName().c_str(), enter_active->GetType().c_str());
  200. GELOGE(INTERNAL_ERROR, "[Add][ControlEdge] between op:%s(%s) and op:%s(%s) failed",
  201. enter_node->GetName().c_str(), enter_node->GetType().c_str(),
  202. enter_active->GetName().c_str(), enter_active->GetType().c_str());
  203. return INTERNAL_ERROR;
  204. }
  205. SetControlFlowGroup(enter_node, group_index);
  206. }
  207. for (const auto &pair : loop_cond_iter.second->merge_next_pairs) {
  208. NodePtr merge_node = pair.first;
  209. NodePtr next_node = pair.second;
  210. // Active --> Merge
  211. if (GraphUtils::AddEdge(enter_active->GetOutControlAnchor(), merge_node->GetInControlAnchor()) != GRAPH_SUCCESS) {
  212. REPORT_CALL_ERROR("E19999", "Add control edge between op:%s(%s) and op:%s(%s) failed",
  213. enter_active->GetName().c_str(), enter_active->GetType().c_str(),
  214. merge_node->GetName().c_str(), merge_node->GetType().c_str());
  215. GELOGE(INTERNAL_ERROR, "[Add][ControlEdge] between op:%s(%s) and op:%s(%s) failed",
  216. enter_active->GetName().c_str(), enter_active->GetType().c_str(),
  217. merge_node->GetName().c_str(), merge_node->GetType().c_str());
  218. return INTERNAL_ERROR;
  219. }
  220. // NextIteration --> Active
  221. if (GraphUtils::AddEdge(next_node->GetOutControlAnchor(), next_active->GetInControlAnchor()) != GRAPH_SUCCESS) {
  222. REPORT_CALL_ERROR("E19999", "Add control edge between op:%s(%s) and op:%s(%s) failed",
  223. next_node->GetName().c_str(), next_node->GetType().c_str(),
  224. next_active->GetName().c_str(), next_active->GetType().c_str());
  225. GELOGE(INTERNAL_ERROR, "[Add][ControlEdge] between op:%s(%s) and op:%s(%s) failed",
  226. next_node->GetName().c_str(), next_node->GetType().c_str(),
  227. next_active->GetName().c_str(), next_active->GetType().c_str());
  228. return INTERNAL_ERROR;
  229. }
  230. // break link between NextIteration and Merge
  231. if (BreakNextIteration(next_node, merge_node) != SUCCESS) {
  232. GELOGE(INTERNAL_ERROR, "[Break][NextIteration] failed, next_node:%s, merge_node:%s",
  233. next_node->GetName().c_str(), merge_node->GetName().c_str());
  234. return INTERNAL_ERROR;
  235. }
  236. SetControlFlowGroup(next_node, group_index);
  237. SetControlFlowGroup(merge_node, group_index);
  238. }
  239. if ((SetActiveLabelList(enter_active, {cond_name}) != SUCCESS) ||
  240. (SetActiveLabelList(next_active, {cond_name}) != SUCCESS)) {
  241. GELOGE(INTERNAL_ERROR, "[Set][ActiveLabelList] failed, cond_name:%s.", cond_name.c_str());
  242. return INTERNAL_ERROR;
  243. }
  244. SetControlFlowGroup(loop_group.loop_cond, group_index);
  245. SetControlFlowGroup(enter_active, group_index);
  246. SetControlFlowGroup(next_active, group_index);
  247. HandleSwitchExitNodes(loop_group, group_index);
  248. }
  249. return SUCCESS;
  250. }
  251. ///
  252. /// @brief Mark force unknown for Exit node
  253. /// @param [in] group of LoopCond
  254. /// @param [in] index of LoopCond Node
  255. /// @return void
  256. ///
  257. void NextIterationPass::HandleSwitchExitNodes(const LoopCondGroup &loop_group, int64_t group_index) {
  258. std::string node_type;
  259. for (const auto &switch_node : loop_group.switch_nodes) {
  260. SetControlFlowGroup(switch_node, group_index);
  261. for (auto node : switch_node->GetOutDataNodes()) {
  262. // Switch --> Exit
  263. // Switch --> Cast --> Exit
  264. // Switch --> TransData --> Cast --> Exit
  265. for (uint8_t i = 0; i < kMaxTransOp; ++i) {
  266. if (node->GetInDataNodes().size() != kTransOpIoSize || node->GetAllOutDataAnchorsSize() != kTransOpIoSize) {
  267. break;
  268. }
  269. if (kExitOpTypes.count(NodeUtils::GetNodeType(node)) > 0) {
  270. SetControlFlowGroup(node, group_index);
  271. break;
  272. }
  273. const auto &all_nodes = node->GetOutAllNodes();
  274. if (all_nodes.size() != kTransOpIoSize) {
  275. break;
  276. }
  277. node = all_nodes.at(0);
  278. }
  279. }
  280. }
  281. }
  282. ///
  283. /// @brief Create Active Node
  284. /// @param [in] graph
  285. /// @param [in] name
  286. /// @return ge::NodePtr
  287. ///
  288. NodePtr NextIterationPass::CreateActiveNode(ComputeGraphPtr &graph, const std::string &name) {
  289. OpDescPtr op_desc = MakeShared<OpDesc>(name, STREAMACTIVE);
  290. if (op_desc == nullptr) {
  291. REPORT_CALL_ERROR("E19999", "New OpDesc failed");
  292. GELOGE(FAILED, "[New][OpDesc] failed");
  293. return nullptr;
  294. }
  295. GELOGI("Create StreamActive op:%s.", op_desc->GetName().c_str());
  296. NodePtr active_node = graph->AddNode(op_desc);
  297. if (active_node == nullptr) {
  298. REPORT_CALL_ERROR("E19999", "Add node:%s(%s) to graph:%s failed",
  299. op_desc->GetName().c_str(), op_desc->GetType().c_str(), graph->GetName().c_str());
  300. GELOGE(INTERNAL_ERROR, "[Add][Node] %s(%s) to graph:%s failed",
  301. op_desc->GetName().c_str(), op_desc->GetType().c_str(), graph->GetName().c_str());
  302. return nullptr;
  303. }
  304. if (SetSwitchBranchNodeLabel(active_node, name) != SUCCESS) {
  305. REPORT_CALL_ERROR("E19999", "Set switch branch node label:%s to node:%s(%s) failed",
  306. name.c_str(), op_desc->GetName().c_str(), op_desc->GetType().c_str());
  307. GELOGE(INTERNAL_ERROR, "[Set][SwitchBranchNodeLabel] %s to node:%s(%s) failed",
  308. name.c_str(), op_desc->GetName().c_str(), op_desc->GetType().c_str());
  309. return nullptr;
  310. }
  311. return active_node;
  312. }
  313. ///
  314. /// @brief Break NextIteration Link & add name to merge attr
  315. /// @param [in] next_node
  316. /// @param [in] merge_node
  317. /// @return Status
  318. ///
  319. Status NextIterationPass::BreakNextIteration(const NodePtr &next_node, NodePtr &merge_node) {
  320. if ((merge_node == nullptr) || (next_node == nullptr)) {
  321. GELOGE(PARAM_INVALID, "[Check][Param] merge node or next node is nullptr.");
  322. return PARAM_INVALID;
  323. }
  324. for (const auto &in_anchor : merge_node->GetAllInDataAnchors()) {
  325. OutDataAnchorPtr out_anchor = in_anchor->GetPeerOutAnchor();
  326. if ((out_anchor == nullptr) || (out_anchor->GetOwnerNode() != next_node)) {
  327. continue;
  328. }
  329. if (GraphUtils::RemoveEdge(out_anchor, in_anchor) != SUCCESS) {
  330. REPORT_CALL_ERROR("E19999", "Remove edge between op:%s(%s)(index:%d) and op:%s(%s)(index:%d) failed",
  331. out_anchor->GetOwnerNode()->GetName().c_str(), out_anchor->GetOwnerNode()->GetType().c_str(),
  332. out_anchor->GetIdx(),
  333. merge_node->GetName().c_str(), merge_node->GetType().c_str(), in_anchor->GetIdx());
  334. GELOGE(INTERNAL_ERROR, "[Remove][Edge] between op:%s(%s)(index:%d) and op:%s(%s)(index:%d) failed",
  335. out_anchor->GetOwnerNode()->GetName().c_str(), out_anchor->GetOwnerNode()->GetType().c_str(),
  336. out_anchor->GetIdx(), merge_node->GetName().c_str(), merge_node->GetType().c_str(), in_anchor->GetIdx());
  337. return INTERNAL_ERROR;
  338. }
  339. if (SetNextIteration(merge_node, next_node) != SUCCESS) {
  340. REPORT_CALL_ERROR("E19999", "Set attr NEXT_ITERATION value:%s to node:%s(%s) failed",
  341. next_node->GetName().c_str(), merge_node->GetName().c_str(), merge_node->GetType().c_str());
  342. GELOGE(INTERNAL_ERROR, "[Set][Attr] NEXT_ITERATION value:%s to node:%s(%s) failed",
  343. next_node->GetName().c_str(), merge_node->GetName().c_str(), merge_node->GetType().c_str());
  344. return INTERNAL_ERROR;
  345. }
  346. }
  347. return SUCCESS;
  348. }
  349. ///
  350. /// @brief find target node
  351. /// @param [in] node
  352. /// @param [in] target_type
  353. /// @param [in] is_input
  354. /// @param [out] target_node
  355. /// @return Status
  356. ///
  357. Status NextIterationPass::FindTargetNode(const NodePtr &node, const std::string &target_type, bool is_input,
  358. NodePtr &target_node) {
  359. if (node == nullptr) {
  360. REPORT_INNER_ERROR("E19999", "Param node is nullptr, check invalid");
  361. GELOGE(PARAM_INVALID, "[Check][Param] node is nullptr.");
  362. return PARAM_INVALID;
  363. }
  364. std::vector<NodePtr> nodes;
  365. if (is_input) {
  366. for (const auto &tmp_node : node->GetInDataNodes()) {
  367. nodes.emplace_back(tmp_node);
  368. }
  369. } else {
  370. for (const auto &tmp_node : node->GetOutDataNodes()) {
  371. nodes.emplace_back(tmp_node);
  372. }
  373. }
  374. for (const auto &tmp_node : nodes) {
  375. std::string type;
  376. GE_CHK_STATUS_RET(GetOriginalType(tmp_node, type), "[Get][NodeType] failed.");
  377. if ((target_type == LOOPCOND) && (type == target_type)) {
  378. target_node = tmp_node;
  379. break;
  380. } else if ((type == target_type) || (type == "Ref" + target_type)) {
  381. target_node = tmp_node;
  382. break;
  383. }
  384. }
  385. if ((target_type != SWITCH) && (target_node == nullptr)) {
  386. REPORT_INNER_ERROR("E19999", "Find target_type:%s node around node:%s(%s) failed",
  387. target_type.c_str(), node->GetName().c_str(), node->GetType().c_str());
  388. GELOGE(INTERNAL_ERROR, "[Check][Param] Find target_type:%s node around node:%s(%s) failed",
  389. target_type.c_str(), node->GetName().c_str(), node->GetType().c_str());
  390. return INTERNAL_ERROR;
  391. }
  392. return SUCCESS;
  393. }
  394. ///
  395. /// @brief Clear Status, used for subgraph pass
  396. /// @return SUCCESS
  397. ///
  398. Status NextIterationPass::ClearStatus() {
  399. loop_group_map_.clear();
  400. return SUCCESS;
  401. }
  402. } // namespace ge

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