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.

task_context.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
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
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  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 "task_context.h"
  17. #include "framework/common/ge_inner_error_codes.h"
  18. #include "framework/common/debug/log.h"
  19. #include "graph/utils/tensor_utils.h"
  20. #include "graph/types.h"
  21. #include "graph/debug/ge_attr_define.h"
  22. #include "hybrid/executor/hybrid_execution_context.h"
  23. #include "hybrid/executor/subgraph_executor.h"
  24. #include "common/profiling/profiling_manager.h"
  25. namespace ge {
  26. namespace hybrid {
  27. TaskContext::TaskContext(GraphExecutionContext *execution_context,
  28. NodeState *node_state,
  29. SubgraphContext *subgraph_context)
  30. : node_state_(node_state),
  31. node_item_(node_state->GetNodeItem()),
  32. execution_context_(execution_context),
  33. subgraph_context_(subgraph_context) {}
  34. TaskContext::~TaskContext() {
  35. GELOGD("[%s] TaskContext destroyed.", node_item_->NodeName().c_str());
  36. // release output
  37. for (int i = 0; i < NumOutputs(); ++i) {
  38. auto output_tensor = MutableOutput(i);
  39. if (output_tensor != nullptr) {
  40. output_tensor->Destroy();
  41. }
  42. }
  43. }
  44. void TaskContext::ReleaseWorkspace() {
  45. GELOGD("[%s] Start ReleaseWorkspace.", node_item_->NodeName().c_str());
  46. for (auto ws_addr : workspaces_) {
  47. execution_context_->allocator->Deallocate(ws_addr);
  48. }
  49. }
  50. std::unique_ptr<TaskContext> TaskContext::Create(NodeState *node_state,
  51. GraphExecutionContext *execution_context,
  52. SubgraphContext *subgraph_context) {
  53. const NodeItem &node_item = *node_state->GetNodeItem();
  54. GELOGI("[%s] To create task context, input start = %d, num_inputs = %d, output start = %d, num_outputs = %d.",
  55. node_item.NodeName().c_str(),
  56. node_item.input_start,
  57. node_item.num_inputs,
  58. node_item.output_start,
  59. node_item.num_outputs);
  60. if (node_item.input_start < 0 || node_item.output_start < 0) {
  61. GELOGE(INTERNAL_ERROR,
  62. "NodeItem not property initialized. input_start = %d, output_start = %d",
  63. node_item.input_start,
  64. node_item.output_start);
  65. return nullptr;
  66. }
  67. auto task_context = std::unique_ptr<TaskContext>(
  68. new(std::nothrow)TaskContext(execution_context, node_state, subgraph_context));
  69. if (task_context == nullptr) {
  70. GELOGE(MEMALLOC_FAILED, "[%s] Failed to create instance of TaskContext.", node_item.NodeName().c_str());
  71. return nullptr;
  72. }
  73. task_context->node_item_ = &node_item;
  74. task_context->inputs_start_ = subgraph_context->all_inputs_.data() + node_item.input_start;
  75. task_context->outputs_start_ = subgraph_context->all_outputs_.data() + node_item.output_start;
  76. task_context->iteration_ = execution_context->iteration;
  77. return task_context;
  78. }
  79. int TaskContext::NumInputs() const {
  80. return node_item_->num_inputs;
  81. }
  82. int TaskContext::NumOutputs() const {
  83. return node_item_->num_outputs;
  84. }
  85. TensorValue *TaskContext::MutableInput(int index) {
  86. if (index < 0 || index >= node_item_->num_inputs) {
  87. GELOGE(PARAM_INVALID, "Index out of range. index = %d, num_inputs = %d", index, node_item_->num_inputs);
  88. return nullptr;
  89. }
  90. return inputs_start_ + index;
  91. }
  92. const TensorValue *TaskContext::GetOutput(int index) const {
  93. if (index < 0 || index >= node_item_->num_outputs) {
  94. GELOGE(PARAM_INVALID, "Index out of range. index = %d, num_outputs = %d", index, node_item_->num_outputs);
  95. return nullptr;
  96. }
  97. return outputs_start_ + index;
  98. }
  99. TensorValue *TaskContext::MutableOutput(int index) {
  100. if (index < 0 || index >= node_item_->num_outputs) {
  101. GELOGE(PARAM_INVALID, "Index out of range. index = %d, num_outputs = %d", index, node_item_->num_outputs);
  102. return nullptr;
  103. }
  104. return outputs_start_ + index;
  105. }
  106. std::size_t TaskContext::NumWorkspaces() const {
  107. return workspaces_.size();
  108. }
  109. void *TaskContext::MutableWorkspace(int index) {
  110. if (index < 0 || static_cast<size_t>(index) >= workspaces_.size()) {
  111. GELOGE(PARAM_INVALID, "Index out of range. index = %d, num_workspaces = %d", index, node_item_->num_outputs);
  112. return nullptr;
  113. }
  114. return workspaces_[index];
  115. }
  116. const TensorValue *TaskContext::GetInput(int index) const {
  117. if (index < 0 || index >= node_item_->num_inputs) {
  118. GELOGE(PARAM_INVALID, "Index out of range. index = %d, num_inputs = %d", index, node_item_->num_inputs);
  119. return nullptr;
  120. }
  121. return inputs_start_ + index;
  122. }
  123. Status TaskContext::AllocateWorkspaces() {
  124. auto workspace_sizes = node_item_->node->GetOpDesc()->GetWorkspaceBytes();
  125. for (auto size : workspace_sizes) {
  126. void *workspace = execution_context_->allocator->Allocate(size);
  127. if (workspace == nullptr) {
  128. GELOGE(MEMALLOC_FAILED, "Failed to allocate workspace of size: %ld", size);
  129. return MEMALLOC_FAILED;
  130. }
  131. workspaces_.emplace_back(workspace);
  132. }
  133. return SUCCESS;
  134. }
  135. Status TaskContext::RegisterCallback(const std::function<void()> &callback_fun) const {
  136. if (callback_fun == nullptr) {
  137. GELOGW("[%s] Callback is NULL", GetNodeName());
  138. return SUCCESS;
  139. }
  140. auto ret = execution_context_->callback_manager->RegisterCallback(GetStream(), callback_fun);
  141. if (ret != SUCCESS) {
  142. GELOGE(ret, "[%s] Failed to register callback", GetNodeName());
  143. execution_context_->callback_manager->Destroy();
  144. return ret;
  145. }
  146. return SUCCESS;
  147. }
  148. string TaskContext::TensorDesc2String(const GeTensorDesc &desc) {
  149. std::stringstream ss;
  150. ss << "[TensorDesc] ";
  151. ss << "DataType = " << desc.GetDataType();
  152. ss << ", Format = " << desc.GetFormat();
  153. ss << ", Shape = [";
  154. for (auto dim : desc.GetShape().GetDims()) {
  155. ss << dim << ", ";
  156. }
  157. ss << "]";
  158. return ss.str();
  159. }
  160. Status TaskContext::AllocateTensor(const GeTensorDesc &tensor_desc, TensorValue &tensor, AllocationAttr *attr) {
  161. int64_t size = 0;
  162. if (ge::TensorUtils::GetSize(tensor_desc, size) != GRAPH_SUCCESS) {
  163. GELOGE(INTERNAL_ERROR, "Failed to get tensor size");
  164. return INTERNAL_ERROR;
  165. }
  166. if (size == 0) {
  167. GELOGW("size from tensor_desc == 0");
  168. }
  169. auto buffer = TensorBuffer::Create(execution_context_->allocator, size, attr);
  170. GE_CHECK_NOTNULL(buffer);
  171. tensor = TensorValue(shared_ptr<TensorBuffer>(buffer.release()));
  172. return SUCCESS;
  173. }
  174. Status TaskContext::AllocateOutput(int index,
  175. const GeTensorDesc &tensor_desc,
  176. TensorValue **tensor,
  177. AllocationAttr *attr) {
  178. GELOGI("To allocate output for node: %s. index = %d, tensor desc = %s",
  179. node_item_->NodeName().c_str(),
  180. index,
  181. TensorDesc2String(tensor_desc).c_str());
  182. if (index < 0 || index >= node_item_->num_outputs) {
  183. GELOGE(PARAM_INVALID, "output index out of range. num_output = %d, index = %d", node_item_->num_outputs, index);
  184. return PARAM_INVALID;
  185. }
  186. if (outputs_start_[index].GetData() != nullptr) {
  187. GELOGI("already allocated as net output");
  188. return SUCCESS;
  189. }
  190. int32_t calc_type = 0;
  191. bool ret = ge::AttrUtils::GetInt(tensor_desc, ATTR_NAME_MEMORY_SIZE_CALC_TYPE, calc_type);
  192. if (ret && (calc_type == static_cast<int32_t>(ge::MemorySizeCalcType::ALWAYS_EMPTY))) {
  193. outputs_start_[index] = TensorValue();
  194. return SUCCESS;
  195. }
  196. auto it = node_item_->ref_outputs.find(index);
  197. if (it != node_item_->ref_outputs.end()) {
  198. auto &ref_node = it->second;
  199. GELOGD("source node of %s:%d = %s, op_type = %s",
  200. node_item_->NodeName().c_str(),
  201. index,
  202. ref_node->GetName().c_str(),
  203. ref_node->GetType().c_str());
  204. TensorValue *ref_tensor = execution_context_->model->GetTensor(ref_node);
  205. GE_CHECK_NOTNULL(ref_tensor);
  206. outputs_start_[index] = *ref_tensor;
  207. } else {
  208. auto reuse_output_it = node_item_->reuse_outputs.find(index);
  209. if (reuse_output_it != node_item_->reuse_outputs.end()) {
  210. GELOGD("[%s] reuse output [%d] with output [%d]", GetNodeName(), index, reuse_output_it->second);
  211. outputs_start_[index] = outputs_start_[reuse_output_it->second];
  212. } else {
  213. auto reuse_input = node_item_->reuse_inputs.find(index);
  214. if (reuse_input != node_item_->reuse_inputs.end()) {
  215. GELOGD("[%s] Output[%d] is referenced to input[%d]", GetNodeName(), index, reuse_input->second);
  216. outputs_start_[index] = inputs_start_[reuse_input->second];
  217. } else {
  218. GE_CHK_STATUS_RET_NOLOG(AllocateTensor(tensor_desc, outputs_start_[index], attr));
  219. GELOGD("Allocating output successfully. node: %s. index = %d, size = %zu",
  220. node_item_->NodeName().c_str(), index, outputs_start_[index].GetSize());
  221. }
  222. }
  223. }
  224. if (execution_context_->trace_enabled) {
  225. outputs_start_[index].SetName(node_item_->NodeName() + "_out_" + std::to_string(index));
  226. }
  227. if (tensor != nullptr) {
  228. *tensor = outputs_start_ + index;
  229. }
  230. return SUCCESS;
  231. }
  232. Status TaskContext::AllocateOutputs(AllocationAttr *attr) {
  233. for (int i = 0; i < node_item_->num_outputs; ++i) {
  234. const auto &output_desc = node_item_->MutableOutputDesc(i);
  235. GE_CHECK_NOTNULL(output_desc);
  236. uint32_t mem_type = 0;
  237. (void)AttrUtils::GetInt(output_desc, ATTR_OUTPUT_MEMORY_TYPE, mem_type);
  238. if (attr == nullptr) {
  239. auto tmp_attr = AllocationAttr(0, nullptr, static_cast<MemStorageType>(mem_type));
  240. GE_CHK_STATUS_RET_NOLOG(AllocateOutput(i, *output_desc, nullptr, &tmp_attr));
  241. } else {
  242. attr->SetMemType(static_cast<MemStorageType>(mem_type));
  243. GE_CHK_STATUS_RET_NOLOG(AllocateOutput(i, *output_desc, nullptr, attr));
  244. }
  245. }
  246. return SUCCESS;
  247. }
  248. Status TaskContext::AllocateTensor(size_t size, TensorValue &tensor, AllocationAttr *attr) {
  249. auto buffer = TensorBuffer::Create(execution_context_->allocator, size, attr);
  250. if (buffer == nullptr) {
  251. GELOGE(MEMALLOC_FAILED, "Failed to allocate buffer of size: %zu", size);
  252. return MEMALLOC_FAILED;
  253. }
  254. tensor = TensorValue(shared_ptr<TensorBuffer>(buffer.release()));
  255. return SUCCESS;
  256. }
  257. const NodeItem &TaskContext::GetNodeItem() const {
  258. return *node_item_;
  259. }
  260. Status TaskContext::SetOutput(int index, const TensorValue &tensor) {
  261. if (index < 0 || index >= node_item_->num_outputs) {
  262. GELOGE(PARAM_INVALID, "output index out of range. num_output = %d, index = %d", node_item_->num_outputs, index);
  263. return PARAM_INVALID;
  264. }
  265. GELOGD("Set %s:%d with tensor: %s",
  266. node_item_->NodeName().c_str(),
  267. index,
  268. tensor.DebugString().c_str());
  269. outputs_start_[index] = tensor;
  270. return SUCCESS;
  271. }
  272. rtStream_t TaskContext::GetStream() const {
  273. return execution_context_->stream;
  274. }
  275. int64_t TaskContext::GetSessionId() const {
  276. return execution_context_->session_id;
  277. }
  278. Status TaskContext::GetStatus() const {
  279. return status_;
  280. }
  281. void TaskContext::SetStatus(Status status) {
  282. status_ = status;
  283. if (status != SUCCESS) {
  284. execution_context_->SetErrorCode(status);
  285. }
  286. }
  287. uint32_t TaskContext::GetTaskId() const {
  288. return task_id_;
  289. }
  290. void TaskContext::SetTaskId(uint32_t task_id) {
  291. task_id_ = task_id;
  292. }
  293. uint32_t TaskContext::GetStreamId() const {
  294. return stream_id_;
  295. }
  296. void TaskContext::SetStreamId(uint32_t stream_id) {
  297. stream_id_ = stream_id;
  298. }
  299. void TaskContext::SetOverFlow(bool is_over_flow) {
  300. is_over_flow_ = is_over_flow;
  301. }
  302. bool TaskContext::IsOverFlow() {
  303. return is_over_flow_;
  304. }
  305. Status TaskContext::AllocateWorkspace(size_t size, void **buffer, void *ori_addr) {
  306. GE_CHECK_NOTNULL(buffer);
  307. if (ori_addr == nullptr) {
  308. *buffer = execution_context_->allocator->Allocate(size, nullptr);
  309. } else {
  310. AllocationAttr attr(ori_addr);
  311. *buffer = execution_context_->allocator->Allocate(size, &attr);
  312. }
  313. if (*buffer == nullptr) {
  314. GELOGE(MEMALLOC_FAILED, "Failed to allocate workspace of size = %zu", size);
  315. return MEMALLOC_FAILED;
  316. }
  317. GELOGD("Allocating workspace of size = %zu successfully", size);
  318. workspaces_.emplace_back(*buffer);
  319. return SUCCESS;
  320. }
  321. Status TaskContext::PropagateOutputs() {
  322. // propagate outputs
  323. for (int i = 0; i < NumOutputs(); ++i) {
  324. auto tensor = MutableOutput(i);
  325. GE_CHECK_NOTNULL(tensor);
  326. if (tensor->GetData() == nullptr) {
  327. GELOGD("[%s] Node output[%d] is null.", node_item_->NodeName().c_str(), i);
  328. }
  329. auto &output_nodes = node_item_->outputs[i];
  330. for (auto &dst_input_index_and_node : output_nodes) {
  331. auto dst_input_idx = dst_input_index_and_node.first;
  332. auto dst_node_item = dst_input_index_and_node.second;
  333. auto input_offset = dst_node_item->input_start + dst_input_idx;
  334. GELOGD(
  335. "Propagate output of node %s, output index = %d, dst node = %s, "
  336. "dst_input_index = %d, dst_input_offset = %d.",
  337. node_item_->NodeName().c_str(),
  338. i,
  339. dst_node_item->NodeName().c_str(),
  340. dst_input_idx,
  341. input_offset);
  342. if (subgraph_context_->all_inputs_.size() <= static_cast<size_t>(input_offset)) {
  343. GELOGE(INTERNAL_ERROR,
  344. "[%s] input index out of range. index = %d, total input num = %zu",
  345. GetNodeName(),
  346. input_offset,
  347. subgraph_context_->all_inputs_.size());
  348. return INTERNAL_ERROR;
  349. }
  350. subgraph_context_->all_inputs_[input_offset] = *tensor;
  351. if (execution_context_->trace_enabled) {
  352. subgraph_context_->all_inputs_[input_offset].SetName(
  353. node_item_->NodeName() + "_in_" + std::to_string(dst_input_idx));
  354. }
  355. }
  356. }
  357. return SUCCESS;
  358. }
  359. const void *TaskContext::GetVarBaseAddr() {
  360. return execution_context_->model->GetVarMemBase();
  361. }
  362. const char *TaskContext::GetNodeName() const {
  363. return node_item_->NodeName().c_str();
  364. }
  365. void TaskContext::ReleaseInputsAndOutputs() {
  366. for (int i = 0; i < node_item_->num_inputs; ++i) {
  367. auto tensor = inputs_start_ + i;
  368. tensor->Destroy();
  369. GELOGD("[%s] Tensor of input[%d] released", GetNodeName(), i);
  370. }
  371. for (int i = 0; i < node_item_->num_outputs; ++i) {
  372. auto tensor = outputs_start_ + i;
  373. tensor->Destroy();
  374. GELOGD("[%s] Tensor of output[%d] released", GetNodeName(), i);
  375. }
  376. }
  377. void TaskContext::ReleaseInput(int index) {
  378. auto input_tensor = MutableInput(index);
  379. if (input_tensor != nullptr) {
  380. input_tensor->Destroy();
  381. GELOGD("[%s] Tensor of input[%d] released", GetNodeName(), index);
  382. }
  383. }
  384. ConstGeTensorDescPtr TaskContext::GetOutputDesc(int index) const {
  385. return node_item_->MutableOutputDesc(static_cast<uint32_t>(index));
  386. }
  387. ConstGeTensorDescPtr TaskContext::GetInputDesc(int index) const {
  388. return node_item_->MutableInputDesc(index);
  389. }
  390. GeTensorDescPtr TaskContext::MutableInputDesc(int index) const {
  391. return node_item_->MutableInputDesc(index);
  392. }
  393. GeTensorDescPtr TaskContext::MutableOutputDesc(int index) const {
  394. return node_item_->MutableOutputDesc(static_cast<uint32_t>(index));
  395. }
  396. bool TaskContext::IsForceInferShape() const {
  397. return force_infer_shape_;
  398. }
  399. void TaskContext::SetForceInferShape(bool force_infer_shape) {
  400. force_infer_shape_ = force_infer_shape;
  401. }
  402. void TaskContext::NodeDone() {
  403. subgraph_context_->NodeDone(node_item_->node);
  404. }
  405. void TaskContext::OnError(Status error) {
  406. subgraph_context_->OnError(error);
  407. execution_context_->SetErrorCode(error);
  408. }
  409. bool TaskContext::IsTraceEnabled() const {
  410. return execution_context_->trace_enabled;
  411. }
  412. TensorValue *TaskContext::GetVariable(const std::string &name) {
  413. return execution_context_->model->GetVariable(name);
  414. }
  415. uint64_t TaskContext::GetIterationNumber() const {
  416. return iteration_;
  417. }
  418. bool TaskContext::IsDumpEnabled() const {
  419. return execution_context_->dump_enabled;
  420. }
  421. Status TaskContext::TryExecuteCallback(const function<void()> &callback_fun) const {
  422. if (!callback_fun) {
  423. return SUCCESS;
  424. }
  425. if (node_item_->has_observer) {
  426. return RegisterCallback(callback_fun);
  427. }
  428. callback_fun();
  429. return SUCCESS;
  430. }
  431. const DumpProperties &TaskContext::GetDumpProperties() const {
  432. return execution_context_->dump_properties;
  433. }
  434. bool TaskContext::NeedCallback() {
  435. return node_item_->has_observer || IsDumpEnabled() || execution_context_->profiling_level > 0;
  436. }
  437. Status TaskContext::Synchronize() {
  438. return execution_context_->Synchronize(GetStream());
  439. }
  440. Status TaskContext::SaveProfilingTaskDescInfo(uint32_t task_id, uint32_t stream_id,
  441. const std::string &task_type, uint32_t block_dim) {
  442. if (ProfilingManager::Instance().ProfilingModelExecuteOn()) {
  443. const NodeItem &node_item = GetNodeItem();
  444. auto op_desc = node_item.GetOpDesc();
  445. GE_CHECK_NOTNULL(op_desc);
  446. const GraphExecutionContext *graph_context = GetExecutionContext();
  447. GE_CHECK_NOTNULL(graph_context);
  448. const HybridModel *model = graph_context->model;
  449. GE_CHECK_NOTNULL(model);
  450. std::string dynamic_model_name = model->GetModelName();
  451. TaskDescInfo tmp_task_desc_info;
  452. tmp_task_desc_info.model_name = dynamic_model_name;
  453. tmp_task_desc_info.op_name = op_desc->GetName();
  454. tmp_task_desc_info.op_type = op_desc->GetType();
  455. tmp_task_desc_info.block_dim = block_dim;
  456. tmp_task_desc_info.task_type = task_type;
  457. tmp_task_desc_info.task_id = task_id;
  458. tmp_task_desc_info.stream_id = stream_id;
  459. tmp_task_desc_info.shape_type = "dynamic";
  460. tmp_task_desc_info.cur_iter_num = iteration_ + 1;
  461. task_desc_info.emplace_back(tmp_task_desc_info);
  462. }
  463. return SUCCESS;
  464. }
  465. NodeState *TaskContext::GetNodeState() const {
  466. return node_state_;
  467. }
  468. Status TaskContext::GetInputDesc(int index, GeTensorDesc &tensor_desc) const {
  469. return node_item_->GetInputDesc(index, tensor_desc);
  470. }
  471. Status TaskContext::UpdateInputDesc(int index, const GeTensorDesc &tensor_desc) {
  472. return const_cast<NodeItem *>(node_item_)->UpdateInputDesc(index, tensor_desc);
  473. }
  474. Status TaskContext::GetOutputDesc(int index, GeTensorDesc &tensor_desc) const {
  475. return node_item_->GetOutputDesc(index, tensor_desc);
  476. }
  477. } // namespace hybrid
  478. } // namespace ge

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