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

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