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

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

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