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

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