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.

hccl_memcpy_pass.cc 19 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 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
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 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
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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/hccl_memcpy_pass.h"
  17. #include <string>
  18. #include "common/debug/log.h"
  19. #include "framework/common/debug/ge_log.h"
  20. #include "common/ge_inner_error_codes.h"
  21. #include "common/ge/ge_util.h"
  22. #include "framework/common/types.h"
  23. #include "graph/utils/graph_utils.h"
  24. namespace {
  25. const int32_t kAnchorSize = 1;
  26. const int kAnchorNum = 0;
  27. const int32_t kAnchorAssignRefIndex = 0;
  28. const int32_t kAnchorAssignValueIndex = 1;
  29. // attr _input_mutable = true means hccl node will modify its input in runtime
  30. const char *const kModifyInput = "_input_mutable";
  31. } // namespace
  32. namespace ge {
  33. Status HcclMemcpyPass::Run(ge::ComputeGraphPtr graph) {
  34. GE_CHECK_NOTNULL(graph);
  35. for (const auto &node : graph->GetDirectNode()) {
  36. auto op_desc = node->GetOpDesc();
  37. if (op_desc == nullptr) {
  38. REPORT_INNER_ERROR("E19999", "Node with nullptr op_desc exist in Param graph:%s, check invalid",
  39. graph->GetName().c_str());
  40. GELOGE(INTERNAL_ERROR, "node has no op_desc, node_name : %s.", node->GetName().c_str());
  41. return INTERNAL_ERROR;
  42. }
  43. Status ret = MutableInputProcess(graph, node);
  44. if (ret != SUCCESS) {
  45. GELOGE(INTERNAL_ERROR, "failed MutableInputProcess, node_name:%s.", node->GetName().c_str());
  46. return ret;
  47. }
  48. }
  49. return SUCCESS;
  50. }
  51. // If node has _input_mutable attr, means input mem may be modified when op execute.
  52. // In order to avoid to affect another op execute with same input when data modified,
  53. // need to inset memcpy node between.
  54. // also works on situation that input is variable or const.
  55. Status HcclMemcpyPass::MutableInputProcess(const ComputeGraphPtr &graph, const NodePtr node) {
  56. bool node_input_mutable = false;
  57. (void)AttrUtils::GetBool(node->GetOpDesc(), kModifyInput, node_input_mutable);
  58. if (!node_input_mutable) {
  59. return SUCCESS;
  60. }
  61. GELOGI("input mutable hcom op is:%s.", node->GetName().c_str());
  62. for (auto &hccl_in_anchor : node->GetAllInDataAnchors()) {
  63. if (hccl_in_anchor == nullptr) {
  64. continue;
  65. }
  66. auto src_out_anchor = hccl_in_anchor->GetPeerOutAnchor();
  67. GE_CHECK_NOTNULL(src_out_anchor);
  68. int32_t src_out_anchor_size = src_out_anchor->GetPeerInDataAnchors().size();
  69. if (src_out_anchor_size == kAnchorSize) {
  70. // Identity needs to be inserted between constant (/data) and hcomallreduce to avoid constant being cleared.
  71. if (IsDataNode(src_out_anchor->GetOwnerNode()->GetType())) {
  72. Status ret = ModifyEdgeConnection(graph, src_out_anchor, hccl_in_anchor);
  73. if (ret != SUCCESS) {
  74. GELOGE(INTERNAL_ERROR, "Failed to modify the connection.");
  75. return ret;
  76. }
  77. }
  78. continue;
  79. }
  80. Status ret = ModifyEdgeConnection(graph, src_out_anchor, hccl_in_anchor);
  81. if (ret != SUCCESS) {
  82. GELOGE(INTERNAL_ERROR, "Failed to modify the connection.");
  83. return ret;
  84. }
  85. }
  86. return SUCCESS;
  87. }
  88. bool HcclMemcpyPass::IsDataNode(const std::string& node_type) {
  89. return (node_type == CONSTANTOP) || (node_type == VARIABLE) || (node_type == DATA) || (node_type == CONSTANT);
  90. }
  91. ///
  92. /// @brief Add Identity Node
  93. /// @param [in] ge::ComputeGraphPtr graph
  94. /// @param [in] ge::OutDataAnchorPtr in_node
  95. /// @return ge::NodePtr
  96. ///
  97. NodePtr HcclMemcpyPass::CreateIdentityNode(const ComputeGraphPtr &graph, const OutDataAnchorPtr &out_data_anchor) {
  98. GE_CHECK_NOTNULL_EXEC(graph, return nullptr);
  99. NodePtr pre_node = out_data_anchor->GetOwnerNode();
  100. OpDescPtr pre_op_desc = pre_node->GetOpDesc();
  101. if (pre_op_desc == nullptr) {
  102. REPORT_INNER_ERROR("E19999", "OpDesc in node is nullptr, check invalid");
  103. GELOGE(INTERNAL_ERROR, "OpDesc of pre node is invalid.");
  104. return nullptr;
  105. }
  106. std::string node_name = pre_node->GetName() + "_" + IDENTITY;
  107. node_name = CheckDuplicateName(node_name);
  108. OpDescPtr op_desc = MakeShared<OpDesc>(node_name.c_str(), IDENTITY);
  109. if (op_desc == nullptr) {
  110. REPORT_CALL_ERROR("E19999", "New OpDesc failed");
  111. GELOGE(INTERNAL_ERROR, "Create Identity op: MakeShared op_desc fail.");
  112. return nullptr;
  113. }
  114. GELOGI("Create Identity op:%s.", op_desc->GetName().c_str());
  115. graphStatus ret = op_desc->AddInputDesc("x", pre_op_desc->GetOutputDesc(out_data_anchor->GetIdx()));
  116. if (ret != GRAPH_SUCCESS) {
  117. REPORT_CALL_ERROR("E19999", "Add input desc to op:%s(%s) failed, name:x",
  118. op_desc->GetName().c_str(), op_desc->GetType().c_str());
  119. GELOGE(INTERNAL_ERROR, "Create Identity op: add input desc fail.");
  120. return nullptr;
  121. }
  122. ret = op_desc->AddOutputDesc("y", pre_op_desc->GetOutputDesc(out_data_anchor->GetIdx()));
  123. if (ret != GRAPH_SUCCESS) {
  124. REPORT_CALL_ERROR("E19999", "Add output desc to op:%s(%s) failed, name:y",
  125. op_desc->GetName().c_str(), op_desc->GetType().c_str());
  126. GELOGE(INTERNAL_ERROR, "Create Identity op: add output desc fail.");
  127. return nullptr;
  128. }
  129. // because history reason ,this pass can not do work after constant fold so mark it
  130. (void)AttrUtils::SetBool(op_desc, ATTR_NO_NEED_CONSTANT_FOLDING, false);
  131. NodePtr memcpy_node = graph->AddNode(op_desc);
  132. if (memcpy_node == nullptr) {
  133. REPORT_CALL_ERROR("E19999", "Add node:%s(%s) to graph:%s failed",
  134. op_desc->GetName().c_str(), op_desc->GetType().c_str(), graph->GetName().c_str());
  135. GELOGE(INTERNAL_ERROR, "Insert Identity node fail.");
  136. return nullptr;
  137. }
  138. return memcpy_node;
  139. }
  140. ///
  141. /// @brief Check duplicate node_name
  142. /// @param [in] std::string& node_name
  143. /// @return std::string
  144. ///
  145. std::string HcclMemcpyPass::CheckDuplicateName(const std::string &node_name) {
  146. std::string tmp_name = node_name;
  147. auto iter = node_num_map_.find(tmp_name);
  148. if (iter != node_num_map_.end()) {
  149. tmp_name = tmp_name + "_" + std::to_string(iter->second);
  150. (iter->second)++;
  151. } else {
  152. node_num_map_[tmp_name] = 1;
  153. }
  154. return tmp_name;
  155. }
  156. ///
  157. /// @brief Modify edge connection
  158. /// @param [in] ComputeGraphPtr graph
  159. /// @param [in] OutDataAnchorPtr src_out_anchor
  160. /// @param [in] InDataAnchorPtr hccl_in_anchor
  161. /// @return status
  162. ///
  163. Status HcclMemcpyPass::ModifyEdgeConnection(const ComputeGraphPtr &graph, const OutDataAnchorPtr &src_out_anchor,
  164. const InDataAnchorPtr &hccl_in_anchor) {
  165. GE_CHECK_NOTNULL(src_out_anchor->GetOwnerNode());
  166. GE_CHECK_NOTNULL(hccl_in_anchor->GetOwnerNode());
  167. Status ret = InsertIdentityBeforeHccl(graph, src_out_anchor, hccl_in_anchor);
  168. if (ret != SUCCESS) {
  169. GELOGE(INTERNAL_ERROR, "add identity failed, var_node:%s, hccl_node:%s.",
  170. src_out_anchor->GetOwnerNode()->GetName().c_str(),
  171. hccl_in_anchor->GetOwnerNode()->GetName().c_str());
  172. return ret;
  173. }
  174. ret = InsertAssignAfterBroadcastIfNeed(graph, src_out_anchor, hccl_in_anchor);
  175. if (ret != SUCCESS) {
  176. GELOGE(INTERNAL_ERROR, "add assign failed, var_node:%s, hccl_node:%s.",
  177. src_out_anchor->GetOwnerNode()->GetName().c_str(),
  178. hccl_in_anchor->GetOwnerNode()->GetName().c_str());
  179. return ret;
  180. }
  181. return SUCCESS;
  182. }
  183. ///
  184. /// @brief Insert Identity node Between Hccl node and variable
  185. /// @param [in] ComputeGraphPtr graph
  186. /// @param [in] OutDataAnchorPtr src_out_anchor
  187. /// @param [in] InDataAnchorPtr hccl_in_anchor
  188. /// @return status
  189. ///
  190. Status HcclMemcpyPass::InsertIdentityBeforeHccl(const ComputeGraphPtr &graph, const OutDataAnchorPtr &src_out_anchor,
  191. const InDataAnchorPtr &hccl_in_anchor) {
  192. GELOGI("Between op %s and op %s need insert memcpy async op.", src_out_anchor->GetOwnerNode()->GetName().c_str(),
  193. hccl_in_anchor->GetOwnerNode()->GetName().c_str());
  194. NodePtr memcpy_node = CreateIdentityNode(graph, src_out_anchor);
  195. GE_CHECK_NOTNULL(memcpy_node);
  196. Status ret1 = src_out_anchor->Unlink(hccl_in_anchor);
  197. if (ret1 != SUCCESS) {
  198. REPORT_CALL_ERROR("E19999",
  199. "Op:%s(%s) out index:%d unlink from op:%s(%s) in index:%d failed",
  200. src_out_anchor->GetOwnerNode()->GetName().c_str(),
  201. src_out_anchor->GetOwnerNode()->GetType().c_str(), src_out_anchor->GetIdx(),
  202. hccl_in_anchor->GetOwnerNode()->GetName().c_str(),
  203. hccl_in_anchor->GetOwnerNode()->GetType().c_str(), hccl_in_anchor->GetIdx());
  204. GELOGE(INTERNAL_ERROR, "The op %s Unlink anchor %s fail.", src_out_anchor->GetOwnerNode()->GetName().c_str(),
  205. hccl_in_anchor->GetOwnerNode()->GetName().c_str());
  206. return FAILED;
  207. }
  208. auto out_data_anchor_0 = memcpy_node->GetOutDataAnchor(kAnchorNum);
  209. GE_CHECK_NOTNULL(out_data_anchor_0);
  210. ret1 = out_data_anchor_0->LinkTo(hccl_in_anchor);
  211. if (ret1 != SUCCESS) {
  212. REPORT_CALL_ERROR("E19999",
  213. "Op:%s(%s) out index:%d link to op:%s(%s) in index:%d failed",
  214. out_data_anchor_0->GetOwnerNode()->GetName().c_str(),
  215. out_data_anchor_0->GetOwnerNode()->GetType().c_str(), out_data_anchor_0->GetIdx(),
  216. hccl_in_anchor->GetOwnerNode()->GetName().c_str(),
  217. hccl_in_anchor->GetOwnerNode()->GetType().c_str(),
  218. hccl_in_anchor->GetIdx());
  219. GELOGE(INTERNAL_ERROR, "The op %s link anchor %s fail.", memcpy_node->GetName().c_str(),
  220. hccl_in_anchor->GetOwnerNode()->GetName().c_str());
  221. return FAILED;
  222. }
  223. Status ret = src_out_anchor->LinkTo(memcpy_node->GetInDataAnchor(kAnchorNum));
  224. if (ret != SUCCESS) {
  225. REPORT_CALL_ERROR("E19999",
  226. "Op:%s(%s) out index:%d link to op:%s(%s) in index:%u failed",
  227. src_out_anchor->GetOwnerNode()->GetName().c_str(),
  228. src_out_anchor->GetOwnerNode()->GetType().c_str(), src_out_anchor->GetIdx(),
  229. memcpy_node->GetName().c_str(), memcpy_node->GetType().c_str(),
  230. kAnchorNum);
  231. GELOGE(INTERNAL_ERROR, "The op %s link anchor %s fail.", src_out_anchor->GetOwnerNode()->GetName().c_str(),
  232. memcpy_node->GetName().c_str());
  233. return FAILED;
  234. }
  235. return SUCCESS;
  236. }
  237. ///
  238. /// @brief Insert assign node after broadcast node and variable to refresh variable data
  239. /// @param [in] ComputeGraphPtr graph
  240. /// @param [in] OutDataAnchorPtr var_out_anchor
  241. /// @param [in] InDataAnchorPtr hccl_in_anchor
  242. /// @return status
  243. ///
  244. Status HcclMemcpyPass::InsertAssignAfterBroadcastIfNeed(const ComputeGraphPtr &graph,
  245. const OutDataAnchorPtr &var_out_anchor,
  246. const InDataAnchorPtr &hccl_in_anchor) {
  247. if (hccl_in_anchor->GetOwnerNode()->GetType() != HCOMBROADCAST) {
  248. GELOGD("%s not broadcast, no need to insert assign node", hccl_in_anchor->GetOwnerNode()->GetName().c_str());
  249. return SUCCESS;
  250. }
  251. if (var_out_anchor->GetOwnerNode()->GetType() != VARIABLE) {
  252. GELOGD("%s not variable, no need to insert assign node", var_out_anchor->GetOwnerNode()->GetName().c_str());
  253. return SUCCESS;
  254. }
  255. GELOGI("after op %s and op %s need insert assign op.", var_out_anchor->GetOwnerNode()->GetName().c_str(),
  256. hccl_in_anchor->GetOwnerNode()->GetName().c_str());
  257. for (auto peer_in_anchor : var_out_anchor->GetPeerInDataAnchors()) {
  258. if (peer_in_anchor->GetOwnerNode()->GetType() == ASSIGN) {
  259. GELOGD("variable %s out assign node is exist.", var_out_anchor->GetOwnerNode()->GetName().c_str());
  260. return SUCCESS;
  261. }
  262. }
  263. NodePtr assign_node = CreateAssignNode(graph, var_out_anchor);
  264. GE_CHECK_NOTNULL(assign_node);
  265. OutDataAnchorPtr hccl_out_anchor = hccl_in_anchor->GetOwnerNode()->GetOutDataAnchor(hccl_in_anchor->GetIdx());
  266. GE_CHECK_NOTNULL(hccl_out_anchor);
  267. Status ret = hccl_out_anchor->LinkTo(assign_node->GetInDataAnchor(kAnchorAssignValueIndex));
  268. if (ret != SUCCESS) {
  269. REPORT_CALL_ERROR("E19999",
  270. "Op:%s(%s) out index:%d link to op:%s(%s) in index:%u failed",
  271. hccl_out_anchor->GetOwnerNode()->GetName().c_str(),
  272. hccl_out_anchor->GetOwnerNode()->GetType().c_str(), hccl_out_anchor->GetIdx(),
  273. assign_node->GetName().c_str(), assign_node->GetType().c_str(),
  274. kAnchorAssignValueIndex);
  275. GELOGE(INTERNAL_ERROR, "The op %s link anchor %s fail.", hccl_out_anchor->GetOwnerNode()->GetName().c_str(),
  276. assign_node->GetName().c_str());
  277. return FAILED;
  278. }
  279. ret = var_out_anchor->LinkTo(assign_node->GetInDataAnchor(kAnchorAssignRefIndex));
  280. if (ret != SUCCESS) {
  281. REPORT_CALL_ERROR("E19999",
  282. "Op:%s(%s) out index:%d link to op:%s(%s) in index:%u failed",
  283. var_out_anchor->GetOwnerNode()->GetName().c_str(),
  284. var_out_anchor->GetOwnerNode()->GetType().c_str(), var_out_anchor->GetIdx(),
  285. assign_node->GetName().c_str(), assign_node->GetType().c_str(),
  286. kAnchorAssignRefIndex);
  287. GELOGE(INTERNAL_ERROR, "The op %s link anchor %s fail.", var_out_anchor->GetOwnerNode()->GetName().c_str(),
  288. assign_node->GetName().c_str());
  289. return FAILED;
  290. }
  291. // add control edge between assign node and node after broadcast node
  292. OutControlAnchorPtr assign_out_control_anchor = assign_node->GetOutControlAnchor();
  293. GE_CHECK_NOTNULL(assign_out_control_anchor);
  294. for (auto in_data_anchor : hccl_out_anchor->GetPeerInDataAnchors()) {
  295. if (in_data_anchor->GetOwnerNode()->GetName() == assign_node->GetName()) {
  296. continue;
  297. }
  298. ret = assign_out_control_anchor->LinkTo(in_data_anchor->GetOwnerNode()->GetInControlAnchor());
  299. if (ret != SUCCESS) {
  300. REPORT_CALL_ERROR("E19999",
  301. "Op:%s(%s) out index:%d link to op:%s(%s) in index:%d failed",
  302. assign_out_control_anchor->GetOwnerNode()->GetName().c_str(),
  303. assign_out_control_anchor->GetOwnerNode()->GetType().c_str(), assign_out_control_anchor->GetIdx(),
  304. in_data_anchor->GetOwnerNode()->GetName().c_str(),
  305. in_data_anchor->GetOwnerNode()->GetType().c_str(),
  306. in_data_anchor->GetIdx());
  307. GELOGE(INTERNAL_ERROR, "The op %s link control anchor %s fail.",
  308. assign_out_control_anchor->GetOwnerNode()->GetName().c_str(),
  309. in_data_anchor->GetOwnerNode()->GetName().c_str());
  310. return FAILED;
  311. }
  312. }
  313. for (auto in_control_anchor : hccl_out_anchor->GetOwnerNode()->GetOutControlAnchor()->GetPeerInControlAnchors()) {
  314. if (in_control_anchor->GetOwnerNode()->GetName() == assign_node->GetName()) {
  315. continue;
  316. }
  317. ret = assign_out_control_anchor->LinkTo(in_control_anchor);
  318. if (ret != SUCCESS) {
  319. REPORT_CALL_ERROR("E19999", "Op:%s(%s) link control to op:%s(%s) failed",
  320. assign_out_control_anchor->GetOwnerNode()->GetName().c_str(),
  321. assign_out_control_anchor->GetOwnerNode()->GetType().c_str(),
  322. in_control_anchor->GetOwnerNode()->GetName().c_str(),
  323. in_control_anchor->GetOwnerNode()->GetType().c_str());
  324. GELOGE(INTERNAL_ERROR, "The op %s link control anchor %s fail.",
  325. assign_out_control_anchor->GetOwnerNode()->GetName().c_str(),
  326. in_control_anchor->GetOwnerNode()->GetName().c_str());
  327. return FAILED;
  328. }
  329. }
  330. return SUCCESS;
  331. }
  332. ///
  333. /// @brief create assign Node, add to graph
  334. /// @param [in] ge::ComputeGraphPtr graph
  335. /// @param [in] ge::OutDataAnchorPtr variable node out anchor
  336. /// @return ge::NodePtr
  337. ///
  338. NodePtr HcclMemcpyPass::CreateAssignNode(const ComputeGraphPtr &graph, const OutDataAnchorPtr &out_data_anchor) {
  339. GE_CHECK_NOTNULL_EXEC(graph, return nullptr);
  340. NodePtr pre_node = out_data_anchor->GetOwnerNode();
  341. OpDescPtr pre_op_desc = pre_node->GetOpDesc();
  342. if (pre_op_desc == nullptr) {
  343. REPORT_INNER_ERROR("E19999", "OpDesc in node is nullptr, check invalid");
  344. GELOGE(INTERNAL_ERROR, "OpDesc of pre node is invalid.");
  345. return nullptr;
  346. }
  347. std::string node_name = pre_node->GetName() + "_" + ASSIGN;
  348. node_name = CheckDuplicateName(node_name);
  349. OpDescPtr op_desc = MakeShared<OpDesc>(node_name.c_str(), ASSIGN);
  350. if (op_desc == nullptr) {
  351. REPORT_CALL_ERROR("E19999", "New OpDesc failed");
  352. GELOGE(INTERNAL_ERROR, "Create Assign op: MakeShared op_desc fail.");
  353. return nullptr;
  354. }
  355. GELOGI("Create Assign op:%s.", op_desc->GetName().c_str());
  356. graphStatus ret = op_desc->AddInputDesc("ref", pre_op_desc->GetOutputDesc(out_data_anchor->GetIdx()));
  357. if (ret != GRAPH_SUCCESS) {
  358. REPORT_CALL_ERROR("E19999", "Add input desc to op:%s(%s) failed, name:ref",
  359. op_desc->GetName().c_str(), op_desc->GetType().c_str());
  360. GELOGE(INTERNAL_ERROR, "Create Assign op: add ref input desc fail.");
  361. return nullptr;
  362. }
  363. ret = op_desc->AddInputDesc("value", pre_op_desc->GetOutputDesc(out_data_anchor->GetIdx()));
  364. if (ret != GRAPH_SUCCESS) {
  365. REPORT_CALL_ERROR("E19999", "Add input desc to op:%s(%s) failed, name:value",
  366. op_desc->GetName().c_str(), op_desc->GetType().c_str());
  367. GELOGE(INTERNAL_ERROR, "Create Assign op: add value input desc fail.");
  368. return nullptr;
  369. }
  370. ret = op_desc->AddOutputDesc("ref", pre_op_desc->GetOutputDesc(out_data_anchor->GetIdx()));
  371. if (ret != GRAPH_SUCCESS) {
  372. REPORT_CALL_ERROR("E19999", "Add output desc to op:%s(%s) failed, name:ref",
  373. op_desc->GetName().c_str(), op_desc->GetType().c_str());
  374. GELOGE(INTERNAL_ERROR, "Create Assign op: add output desc fail.");
  375. return nullptr;
  376. }
  377. NodePtr assign_node = graph->AddNode(op_desc);
  378. if (assign_node == nullptr) {
  379. REPORT_CALL_ERROR("E19999", "Add node:%s(%s) to graph:%s failed",
  380. op_desc->GetName().c_str(), op_desc->GetType().c_str(), graph->GetName().c_str());
  381. GELOGE(INTERNAL_ERROR, "Insert Identity node fail.");
  382. return nullptr;
  383. }
  384. return assign_node;
  385. }
  386. ///
  387. /// @brief Clear Status, used for subgraph pass
  388. /// @return SUCCESS
  389. ///
  390. Status HcclMemcpyPass::ClearStatus() {
  391. node_num_map_.clear();
  392. return SUCCESS;
  393. }
  394. } // namespace ge

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