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

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