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.

folding_pass.cc 18 kB

5 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
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
4 years ago
5 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
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
4 years ago
5 years ago
4 years ago
5 years ago
4 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
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. /**
  2. * Copyright 2019-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/folding_pass.h"
  17. #include <memory>
  18. #include <string>
  19. #include <utility>
  20. #include <vector>
  21. #include <unordered_set>
  22. #include "framework/common/debug/ge_log.h"
  23. #include "graph/utils/graph_utils.h"
  24. #include "graph/utils/node_utils.h"
  25. #include "inc/kernel.h"
  26. #include "inc/kernel_factory.h"
  27. #include "graph/debug/ge_attr_define.h"
  28. #include "ge_local_engine/engine/host_cpu_engine.h"
  29. #include "init/gelib.h"
  30. namespace ge {
  31. namespace folding_pass {
  32. shared_ptr<Kernel> GetKernelByType(const NodePtr &node) {
  33. if (node == nullptr) {
  34. REPORT_INNER_ERROR("E19999", "Param node is nullptr, check invalid");
  35. GELOGE(FAILED, "[Check][Param] parameter node is nullptr.");
  36. return nullptr;
  37. }
  38. KernelFactory &factory = KernelFactory::Instance();
  39. string type = node->GetType();
  40. if (type == FRAMEWORKOP) {
  41. if (!ge::AttrUtils::GetStr(node->GetOpDesc(), ATTR_NAME_FRAMEWORK_ORIGINAL_TYPE, type)) {
  42. REPORT_CALL_ERROR("E19999", "Get Attr:%s from op:%s(%s) failed",
  43. ATTR_NAME_FRAMEWORK_ORIGINAL_TYPE.c_str(),
  44. node->GetName().c_str(), node->GetType().c_str());
  45. return nullptr;
  46. }
  47. }
  48. return factory.Create(type);
  49. }
  50. bool IsNoNeedConstantFolding(const NodePtr &node) {
  51. auto node_desc = node->GetOpDesc();
  52. return node_desc == nullptr || node_desc->HasAttr(ATTR_NO_NEED_CONSTANT_FOLDING);
  53. }
  54. } // namespace folding_pass
  55. namespace {
  56. const std::string kKernelLibName = "aicpu_tf_kernel";
  57. const std::string kOpsFlagClose = "0";
  58. IndexsToAnchors GetIndexAndPeerInDataAnchors(NodePtr &node) {
  59. IndexsToAnchors indexes_to_anchors;
  60. for (auto &out_anchor : node->GetAllOutDataAnchors()) {
  61. if (out_anchor == nullptr) {
  62. continue;
  63. }
  64. for (auto &peer_in_anchor : out_anchor->GetPeerInDataAnchors()) {
  65. if (peer_in_anchor == nullptr) {
  66. continue;
  67. }
  68. const auto &peer_node = peer_in_anchor->GetOwnerNode();
  69. if (peer_node == nullptr) {
  70. continue;
  71. }
  72. indexes_to_anchors[out_anchor->GetIdx()].push_back(peer_in_anchor);
  73. }
  74. }
  75. return indexes_to_anchors;
  76. }
  77. NodePtr AddConstNodeToGraph(GeTensorPtr &tensor, ComputeGraphPtr &graph) {
  78. auto const_desc = OpDescUtils::CreateConstOp(tensor);
  79. if (const_desc == nullptr) {
  80. REPORT_CALL_ERROR("E19999", "Create Const op failed");
  81. GELOGE(OUT_OF_MEMORY, "[Create][ConstOp] failed");
  82. return nullptr;
  83. }
  84. GE_IF_BOOL_EXEC(graph == nullptr, GELOGW("input param graph is null"); return nullptr);
  85. (void) AttrUtils::SetListStr(const_desc, ATTR_NAME_DATA_DUMP_ORIGIN_OP_NAMES, std::move(std::vector<std::string>()));
  86. return graph->AddNodeFront(const_desc);
  87. }
  88. NodePtr AddIdentityNodeToGraph(const std::string &name, const GeTensorDesc &tensor, ComputeGraphPtr &graph) {
  89. if (graph == nullptr) {
  90. REPORT_INNER_ERROR("E19999", "Param graph is nullptr, check invalid");
  91. GELOGE(INTERNAL_ERROR, "[Check][Param] Compute graph ptr is null in creating identity node.");
  92. return nullptr;
  93. }
  94. OpDescPtr desc = MakeShared<OpDesc>("", "");
  95. if (desc == nullptr) {
  96. REPORT_CALL_ERROR("E19999", "New OpDesc failed");
  97. GELOGE(MEMALLOC_FAILED, "[New][OpDesc] failed.");
  98. return nullptr;
  99. }
  100. desc->SetName(name);
  101. desc->SetType(IDENTITY);
  102. auto ret = desc->AddInputDesc(tensor);
  103. auto ret2 = desc->AddOutputDesc(tensor);
  104. if ((ret != GRAPH_SUCCESS) || (ret2 != GRAPH_SUCCESS)) {
  105. REPORT_CALL_ERROR("E19999", "Add input or output desc to op:%s(%s) failed",
  106. desc->GetName().c_str(), desc->GetType().c_str());
  107. GELOGE(INTERNAL_ERROR, "[Add][GeTensorDesc] to op:%s(%s) failed",
  108. desc->GetName().c_str(), desc->GetType().c_str());
  109. return nullptr;
  110. }
  111. return graph->AddNodeFront(desc);
  112. }
  113. } // namespace
  114. Status FoldingPass::RunOpKernel(NodePtr &node,
  115. const vector<ConstGeTensorPtr> &inputs,
  116. std::vector<GeTensorPtr> &outputs) {
  117. return HostCpuEngine::GetInstance().Run(node, inputs, outputs);
  118. }
  119. Status FoldingPass::RunOpKernelWithCheck(NodePtr &node, const vector<ConstGeTensorPtr> &inputs,
  120. std::vector<GeTensorPtr> &outputs) {
  121. std::shared_ptr<GELib> instance_ptr = ge::GELib::GetInstance();
  122. if ((instance_ptr == nullptr) || (!instance_ptr->InitFlag())) {
  123. GELOGE(GE_CLI_GE_NOT_INITIALIZED, "[Check][Param] GE is not initialized or is finalized.");
  124. return UNSUPPORTED;
  125. }
  126. OpsKernelInfoStorePtr kernel_info = instance_ptr->OpsKernelManagerObj().GetOpsKernelInfoStore(kKernelLibName);
  127. if (kernel_info == nullptr) {
  128. GELOGE(FAILED, "[Get][OpsKernelInfoStore] %s failed", kKernelLibName.c_str());
  129. return UNSUPPORTED;
  130. }
  131. std::string ops_flag;
  132. kernel_info->opsFlagCheck(*node, ops_flag);
  133. if (ops_flag == kOpsFlagClose) {
  134. return UNSUPPORTED;
  135. }
  136. return FoldingPass::RunOpKernel(node, inputs, outputs);
  137. }
  138. Status FoldingPass::Folding(NodePtr &node, vector<GeTensorPtr> &outputs) {
  139. GE_CHECK_NOTNULL(node);
  140. GELOGD("begin folding node:%s", node->GetName().c_str());
  141. // Before processing nodes, collect the relations between the out anchor and the peer out data nodes
  142. // to prepare for const reconnection
  143. auto indexes_to_anchors = GetIndexAndPeerInDataAnchors(node);
  144. auto ret = DealWithInNodes(node);
  145. if (ret != SUCCESS) {
  146. return ret;
  147. }
  148. if (AddConstNode(node, indexes_to_anchors, outputs) != SUCCESS) {
  149. return INTERNAL_ERROR;
  150. }
  151. auto in_data_nodes = node->GetInDataNodes();
  152. std::unordered_set<NodePtr> in_data_nodes_set(in_data_nodes.begin(), in_data_nodes.end());
  153. if (IsolateAndDeleteNode(node, {}) != SUCCESS) {
  154. REPORT_INNER_ERROR("E19999", "Isolate and delete node:%s(%s) failed",
  155. node->GetName().c_str(), node->GetType().c_str());
  156. GELOGE(INTERNAL_ERROR, "[IsolateAndDelete][Node] %s(%s) failed.",
  157. node->GetName().c_str(), node->GetType().c_str());
  158. return INTERNAL_ERROR;
  159. }
  160. for (auto iter = in_data_nodes_set.begin(); iter != in_data_nodes_set.end(); ++iter) {
  161. auto pre_node = *iter;
  162. if (pre_node->GetOutDataNodesSize() == 0) {
  163. if ((pre_node->GetType() == DATA) || (pre_node->GetType() == ENTER)) {
  164. GELOGI("No need to remove data/enter, node name:%s.", pre_node->GetName().c_str());
  165. continue;
  166. }
  167. if (IsolateAndDeleteNode(pre_node, {}) != SUCCESS) {
  168. REPORT_INNER_ERROR("E19999", "Isolate and delete node:%s(%s) failed",
  169. pre_node->GetName().c_str(), pre_node->GetType().c_str());
  170. GELOGE(INTERNAL_ERROR, "[IsolateAndDelete][Node] %s(%s) failed.",
  171. pre_node->GetName().c_str(), pre_node->GetType().c_str());
  172. return INTERNAL_ERROR;
  173. }
  174. }
  175. }
  176. return SUCCESS;
  177. }
  178. Status FoldingPass::DealWithInNodes(NodePtr &node) {
  179. GE_CHECK_NOTNULL(node);
  180. GE_CHECK_NOTNULL(node->GetOpDesc());
  181. auto graph = node->GetOwnerComputeGraph();
  182. auto in_data_anchors = node->GetAllInDataAnchors();
  183. for (auto &in_data_anchor : in_data_anchors) {
  184. if (in_data_anchor == nullptr) {
  185. continue;
  186. }
  187. auto in_node_anchor = in_data_anchor->GetPeerOutAnchor();
  188. if (in_node_anchor == nullptr) {
  189. continue;
  190. }
  191. auto in_node = in_node_anchor->GetOwnerNode();
  192. if ((in_node->GetType() == SWITCH) || (in_node->GetType() == REFSWITCH) || (in_node->GetType() == SWITCHN)) {
  193. GELOGI("The in_node name is %s, and node type is %s.", in_node->GetName().c_str(), in_node->GetType().c_str());
  194. auto ret = in_node_anchor->Unlink(in_data_anchor);
  195. if (ret != SUCCESS) {
  196. REPORT_CALL_ERROR("E19999", "Op:%s(%s) out index:%d unlink from op:%s(%s) in index:%d failed",
  197. in_node->GetName().c_str(), in_node->GetType().c_str(), in_node_anchor->GetIdx(),
  198. node->GetName().c_str(), node->GetType().c_str(), in_data_anchor->GetIdx());
  199. GELOGE(INTERNAL_ERROR, "[Unlink][Anchor] between const node:%s and constant-folding-node:%s(%s) failed.",
  200. in_node->GetName().c_str(), node->GetName().c_str(), node->GetType().c_str());
  201. return INTERNAL_ERROR;
  202. }
  203. GELOGI("Unlink anchor between in_node %s and node %s success.", in_node->GetName().c_str(),
  204. node->GetName().c_str());
  205. auto identity_name = node->GetName() + "_ctrl_identity_" + std::to_string(in_data_anchor->GetIdx());
  206. auto identity =
  207. AddIdentityNodeToGraph(identity_name, node->GetOpDesc()->GetInputDesc(in_data_anchor->GetIdx()), graph);
  208. if (identity == nullptr) {
  209. GELOGE(INTERNAL_ERROR, "[Add][IdentityNode] %s to graph:%s failed.",
  210. identity_name.c_str(), graph->GetName().c_str());
  211. return INTERNAL_ERROR;
  212. }
  213. ret = GraphUtils::AddEdge(in_node_anchor, identity->GetInDataAnchor(0));
  214. if (ret != GRAPH_SUCCESS) {
  215. REPORT_CALL_ERROR("E19999", "Add edge between op:%s(%s)(index:%d) and op:%s(%s)(index:0) failed",
  216. in_node->GetName().c_str(), in_node->GetType().c_str(), in_node_anchor->GetIdx(),
  217. identity->GetName().c_str(), identity->GetType().c_str());
  218. GELOGE(INTERNAL_ERROR, "[Add][Edge] between op:%s(%s)(index:%d) and op:%s(%s)(index:0) failed",
  219. in_node->GetName().c_str(), in_node->GetType().c_str(), in_node_anchor->GetIdx(),
  220. identity->GetName().c_str(), identity->GetType().c_str());
  221. return INTERNAL_ERROR;
  222. }
  223. GELOGI("Create new identity node success.");
  224. ret = GraphUtils::AddEdge(identity->GetOutControlAnchor(), node->GetInControlAnchor());
  225. if (ret != GRAPH_SUCCESS) {
  226. REPORT_CALL_ERROR("E19999", "Add control edge between op:%s(%s) and op:%s(%s) failed",
  227. identity->GetName().c_str(), identity->GetType().c_str(),
  228. node->GetName().c_str(), node->GetType().c_str());
  229. GELOGE(INTERNAL_ERROR, "[Add][ControlEdge] between op:%s(%s) and op:%s(%s) failed",
  230. identity->GetName().c_str(), identity->GetType().c_str(),
  231. node->GetName().c_str(), node->GetType().c_str());
  232. return INTERNAL_ERROR;
  233. }
  234. }
  235. }
  236. return SUCCESS;
  237. }
  238. Status FoldingPass::AddConstNode(NodePtr &node, IndexsToAnchors indexes_to_anchors,
  239. std::vector<GeTensorPtr> &v_weight) {
  240. if (node == nullptr) {
  241. REPORT_INNER_ERROR("E19999", "Param node is nullptr, check invalid");
  242. GELOGE(PARAM_INVALID, "[Check][Param] node is nullptr");
  243. return FAILED;
  244. }
  245. auto graph = node->GetOwnerComputeGraph();
  246. for (auto &index_to_anchors : indexes_to_anchors) {
  247. auto index = static_cast<size_t>(index_to_anchors.first);
  248. if (index >= v_weight.size()) {
  249. REPORT_INNER_ERROR("E19999", "Index:%lu in param index_to_anchors >= param v_weight.size:%zu, "
  250. "check invalid", index, v_weight.size());
  251. GELOGE(INTERNAL_ERROR, "[Check][Param] Failed to constant fold on node %s type %s, "
  252. "the out nodes num %lu calculated is less than the node out anchor index %zu",
  253. node->GetName().c_str(), node->GetType().c_str(), v_weight.size(), index);
  254. return INTERNAL_ERROR;
  255. }
  256. GeTensorPtr weight = v_weight[index];
  257. if (weight == nullptr) {
  258. REPORT_INNER_ERROR("E19999", "Index:%lu in param v_weight is nullptr check invalid", index);
  259. GELOGE(INTERNAL_ERROR,
  260. "[Check][Param] Failed to constant fold on node %s type %s, the %lust node calculated is null",
  261. node->GetName().c_str(), node->GetType().c_str(), index);
  262. return INTERNAL_ERROR;
  263. }
  264. auto const_node = AddConstNodeToGraph(weight, graph);
  265. if (const_node == nullptr) {
  266. GELOGE(INTERNAL_ERROR, "[Add][ConstNode] To Graph failed, node name:%s, index:%zu.",
  267. node->GetName().c_str(), index);
  268. return INTERNAL_ERROR;
  269. }
  270. GELOGI("add const_node:%s, replace node %s, type %s, index %zu.", const_node->GetName().c_str(),
  271. node->GetName().c_str(), node->GetType().c_str(), index);
  272. // add new const to re-pass node
  273. for (auto &in_anchor : index_to_anchors.second) {
  274. if (in_anchor == nullptr) {
  275. REPORT_INNER_ERROR("E19999", "Index:%lu in param index_to_anchors has nullptr member in_anchor, "
  276. "check invalid", index);
  277. GELOGE(INTERNAL_ERROR,
  278. "[Check][Param] Index:%lu in param index_to_anchors has nullptr member in_anchor", index);
  279. return INTERNAL_ERROR;
  280. }
  281. auto ret = ConnectNodeToInAnchor(in_anchor, const_node, 0);
  282. if (ret != SUCCESS) {
  283. return ret;
  284. }
  285. NodeUtils::UpdateIsInputConst(*(in_anchor->GetOwnerNode()));
  286. }
  287. Status ret = GraphUtils::AddEdge(node->GetOutControlAnchor(), const_node->GetInControlAnchor());
  288. if (ret != GRAPH_SUCCESS) {
  289. REPORT_CALL_ERROR("E19999", "Add control edge between op:%s(%s) and op:%s(%s) failed",
  290. node->GetName().c_str(), node->GetType().c_str(),
  291. const_node->GetName().c_str(), const_node->GetType().c_str());
  292. GELOGE(INTERNAL_ERROR, "[Add][ControlEdge] failed, from node %s to const node %s.", node->GetName().c_str(),
  293. const_node->GetName().c_str());
  294. return INTERNAL_ERROR;
  295. }
  296. GE_CHECK_NOTNULL(node->GetOpDesc());
  297. std::string stream_label;
  298. if (AttrUtils::GetStr(node->GetOpDesc(), ATTR_NAME_STREAM_LABEL, stream_label)) {
  299. GE_CHECK_NOTNULL(const_node->GetOpDesc());
  300. if (!AttrUtils::SetStr(const_node->GetOpDesc(), ATTR_NAME_STREAM_LABEL, stream_label)) {
  301. REPORT_CALL_ERROR("E19999", "Set Attr:%s to op:%s(%s) failed", ATTR_NAME_STREAM_LABEL.c_str(),
  302. const_node->GetName().c_str(), const_node->GetType().c_str());
  303. GELOGE(INTERNAL_ERROR, "[Set][Attr] %s to op:%s(%s) failed", ATTR_NAME_STREAM_LABEL.c_str(),
  304. const_node->GetName().c_str(), const_node->GetType().c_str());
  305. return INTERNAL_ERROR;
  306. }
  307. }
  308. GELOGD("Add control edge when insert dynamic const, from node %s to const node %s, with stream label:%s.",
  309. node->GetName().c_str(), const_node->GetName().c_str(), stream_label.c_str());
  310. }
  311. return SUCCESS;
  312. }
  313. Status FoldingPass::RemoveNodeKeepingCtrlEdges(NodePtr &node) {
  314. GE_IF_BOOL_EXEC(node == nullptr, GELOGE(PARAM_INVALID, "node is null"); return PARAM_INVALID);
  315. auto ret = GraphUtils::IsolateNode(node, {});
  316. if (ret != GRAPH_SUCCESS) {
  317. REPORT_CALL_ERROR("E19999", "Isolate node:%s(%s) in graph failed",
  318. node->GetName().c_str(), node->GetType().c_str());
  319. GELOGE(INTERNAL_ERROR, "[Isolate][Node] %s type %s failed", node->GetName().c_str(),
  320. node->GetType().c_str());
  321. return INTERNAL_ERROR;
  322. }
  323. auto graph = node->GetOwnerComputeGraph();
  324. ret = GraphUtils::RemoveNodeWithoutRelink(graph, node);
  325. if (ret != GRAPH_SUCCESS) {
  326. REPORT_CALL_ERROR("E19999", "Remove node:%s(%s) without relink in graph:%s failed",
  327. node->GetName().c_str(), node->GetType().c_str(), graph->GetName().c_str());
  328. GELOGE(INTERNAL_ERROR, "[Remove][Node] %s(%s) without relink in graph:%s failed",
  329. node->GetName().c_str(), node->GetType().c_str(), graph->GetName().c_str());
  330. return INTERNAL_ERROR;
  331. }
  332. AddNodeDeleted(node);
  333. return SUCCESS;
  334. }
  335. Status FoldingPass::ConnectNodeToInAnchor(InDataAnchorPtr &in_anchor, NodePtr &node, int node_index) {
  336. // the origin edge must be removed before add
  337. if (in_anchor == nullptr || node == nullptr) {
  338. REPORT_INNER_ERROR("E19999", "Param node or in_anchor is nullptr, check invalid");
  339. GELOGE(PARAM_INVALID, "[Check][Param] in anchor or node is null");
  340. return PARAM_INVALID;
  341. }
  342. auto peer_out_anchor = in_anchor->GetPeerOutAnchor();
  343. if (peer_out_anchor != nullptr) {
  344. if (ge::GraphUtils::RemoveEdge(peer_out_anchor, in_anchor) != GRAPH_SUCCESS) {
  345. GELOGW("RemoveEdge failed.");
  346. }
  347. }
  348. auto new_out_anchor = node->GetOutDataAnchor(node_index);
  349. if (new_out_anchor == nullptr) {
  350. REPORT_INNER_ERROR("E19999", "Param out index:%d data anchor of node:%s(%s) is nullptr, check invalid",
  351. node_index, node->GetName().c_str(), node->GetType().c_str());
  352. GELOGE(INTERNAL_ERROR, "[Check][Param] Failed to add node to in anchor,"
  353. " the index %d for node %s, type %s is invalid",
  354. node_index, node->GetName().c_str(), node->GetType().c_str());
  355. return INTERNAL_ERROR;
  356. }
  357. if (GraphUtils::AddEdge(new_out_anchor, in_anchor) != GRAPH_SUCCESS) {
  358. REPORT_CALL_ERROR("E19999", "Add edge between op:%s(%s)(index:%d) and op:%s(%s)(index:%d) failed",
  359. node->GetName().c_str(), node->GetType().c_str(), node_index,
  360. in_anchor->GetOwnerNode()->GetName().c_str(), in_anchor->GetOwnerNode()->GetType().c_str(),
  361. in_anchor->GetIdx());
  362. GELOGE(INTERNAL_ERROR, "[Add][Edge] between op:%s(%s)(index:%d) and op:%s(%s)(index:%d) failed",
  363. node->GetName().c_str(), node->GetType().c_str(), node_index,
  364. in_anchor->GetOwnerNode()->GetName().c_str(), in_anchor->GetOwnerNode()->GetType().c_str(),
  365. in_anchor->GetIdx());
  366. return INTERNAL_ERROR;
  367. }
  368. AddRePassNodesWithInOut(node);
  369. return SUCCESS;
  370. }
  371. } // namespace ge

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