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.

execution_engine.cc 20 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  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 "hybrid/executor/worker/execution_engine.h"
  17. #include "graph/runtime_inference_context.h"
  18. #include "graph/utils/tensor_utils.h"
  19. #include "graph/utils/tensor_adapter.h"
  20. #include "graph/debug/ge_attr_define.h"
  21. #include "hybrid/node_executor/node_executor.h"
  22. #include "common/dump/dump_manager.h"
  23. #include "common/dump/dump_op.h"
  24. #include "common/types.h"
  25. #include "common/ge_types.h"
  26. #include "common/profiling/profiling_manager.h"
  27. #include "runtime/base.h"
  28. namespace ge {
  29. namespace hybrid {
  30. namespace {
  31. constexpr int64_t kMaxPadding = 63;
  32. Status LogInputs(const NodeItem &node_item, const TaskContext &task_context) {
  33. for (auto i = 0; i < task_context.NumInputs(); ++i) {
  34. const auto &input_tensor = task_context.GetInput(i);
  35. GE_CHECK_NOTNULL(input_tensor);
  36. const auto &tensor_desc = node_item.op_desc->MutableInputDesc(i);
  37. GE_CHECK_NOTNULL(tensor_desc);
  38. GELOGD("[%s] Print task args. input[%d] = %s, shape = [%s]", node_item.NodeName().c_str(), i,
  39. input_tensor->DebugString().c_str(), tensor_desc->MutableShape().ToString().c_str());
  40. }
  41. return SUCCESS;
  42. }
  43. Status LogOutputs(const NodeItem &node_item, const TaskContext &task_context) {
  44. for (auto i = 0; i < task_context.NumOutputs(); ++i) {
  45. const auto &output_tensor = task_context.GetOutput(i);
  46. GE_CHECK_NOTNULL(output_tensor);
  47. const auto &tensor_desc = node_item.op_desc->MutableOutputDesc(i);
  48. GE_CHECK_NOTNULL(tensor_desc);
  49. GELOGD("[%s] Print task args. output[%d] = %s, shape = [%s]", node_item.NodeName().c_str(), i,
  50. output_tensor->DebugString().c_str(), tensor_desc->MutableShape().ToString().c_str());
  51. }
  52. return SUCCESS;
  53. }
  54. } // namespace
  55. class NodeDoneCallback {
  56. public:
  57. NodeDoneCallback(GraphExecutionContext *graph_context, std::shared_ptr<TaskContext> task_context);
  58. ~NodeDoneCallback() = default;
  59. Status OnNodeDone();
  60. private:
  61. Status PrepareConstInputs(const NodeItem &node_item);
  62. Status DumpDynamicNode();
  63. Status ProfilingReport();
  64. Status GetGraphDescInfo(const NodePtr node, const HybridModel *model,
  65. std::vector<ComputeGraphDescInfo> &compute_graph_info);
  66. Status GetTaskDescInfo(const NodePtr node, const HybridModel *model, std::vector<TaskDescInfo> &task_desc_info);
  67. GraphExecutionContext *graph_context_;
  68. std::shared_ptr<TaskContext> context_;
  69. DumpOp dump_op_;
  70. };
  71. NodeDoneCallback::NodeDoneCallback(GraphExecutionContext *graph_context, std::shared_ptr<TaskContext> task_context)
  72. : graph_context_(graph_context), context_(std::move(task_context)) {}
  73. Status NodeDoneCallback::PrepareConstInputs(const NodeItem &node_item) {
  74. for (auto output_idx : node_item.to_const_output_id_list) {
  75. RECORD_CALLBACK_EVENT(graph_context_, node_item.NodeName().c_str(), "[PrepareConstInputs] [index = %d] Start",
  76. output_idx);
  77. auto output_tensor = context_->GetOutput(output_idx);
  78. GE_CHECK_NOTNULL(output_tensor);
  79. Tensor tensor;
  80. auto ge_tensor_desc = node_item.op_desc->MutableOutputDesc(output_idx);
  81. GE_CHECK_NOTNULL(ge_tensor_desc);
  82. tensor.SetTensorDesc(TensorAdapter::GeTensorDesc2TensorDesc(*ge_tensor_desc));
  83. int64_t tensor_size;
  84. GE_CHK_GRAPH_STATUS_RET(TensorUtils::GetTensorSizeInBytes(*ge_tensor_desc, tensor_size),
  85. "Failed to invoke GetTensorSizeInBytes");
  86. if (output_tensor->GetSize() < static_cast<size_t>(tensor_size)) {
  87. GELOGE(INTERNAL_ERROR, "[%s] Tensor size is not enough. output index = %d, required size = %zu, tensor = %s",
  88. node_item.NodeName().c_str(), output_idx, tensor_size, output_tensor->DebugString().c_str());
  89. return INTERNAL_ERROR;
  90. }
  91. vector<uint8_t> host_buffer(static_cast<unsigned long>(tensor_size));
  92. GELOGD("[%s] To cache output[%d] to host, size = %zu", node_item.NodeName().c_str(), output_idx,
  93. output_tensor->GetSize());
  94. if (tensor_size > 0) {
  95. GE_CHK_RT_RET(
  96. rtMemcpy(host_buffer.data(), tensor_size, output_tensor->GetData(), tensor_size, RT_MEMCPY_DEVICE_TO_HOST));
  97. }
  98. tensor.SetData(std::move(host_buffer));
  99. string session_id = std::to_string(context_->GetSessionId());
  100. RuntimeInferenceContext *runtime_infer_ctx = nullptr;
  101. GE_CHK_GRAPH_STATUS_RET(RuntimeInferenceContext::GetContext(session_id, &runtime_infer_ctx),
  102. "Failed to get RuntimeInferenceContext, session_id = %s", session_id.c_str());
  103. GE_CHK_STATUS_RET(runtime_infer_ctx->SetTensor(node_item.node_id, output_idx, std::move(tensor)),
  104. "Failed to SetTensor, node = %s, output_index = %d", node_item.NodeName().c_str(), output_idx);
  105. GELOGD("[%s] Output[%d] cached successfully in session: %s. node_id = %d, shape = [%s]",
  106. node_item.NodeName().c_str(), output_idx, session_id.c_str(), node_item.node_id,
  107. ge_tensor_desc->GetShape().ToString().c_str());
  108. RECORD_CALLBACK_EVENT(graph_context_, node_item.NodeName().c_str(), "[PrepareConstInputs] [index = %d] End",
  109. output_idx);
  110. }
  111. return SUCCESS;
  112. }
  113. Status NodeDoneCallback::GetTaskDescInfo(const NodePtr node, const HybridModel *model,
  114. std::vector<TaskDescInfo> &task_desc_info) {
  115. GE_CHECK_NOTNULL(node);
  116. GE_CHECK_NOTNULL(model);
  117. GELOGD("GetTaskDescInfo of node [%s] start.", node->GetName().c_str());
  118. auto op_desc = node->GetOpDesc();
  119. std::string op_name = op_desc->GetName();
  120. std::string dynamic_model_name = model->GetModelName();
  121. uint32_t task_id = 0;
  122. uint32_t stream_id = 0;
  123. if (rtGetTaskIdAndStreamID(&task_id, &stream_id) != RT_ERROR_NONE) {
  124. GELOGE(PARAM_INVALID, "Get task_id and stream_id failed.");
  125. return PARAM_INVALID;
  126. }
  127. TaskDescInfo tmp_task_desc_info;
  128. tmp_task_desc_info.model_name = dynamic_model_name;
  129. tmp_task_desc_info.op_name = op_name;
  130. tmp_task_desc_info.block_dim = 0;
  131. auto task_defs = model->GetTaskDefs(node);
  132. if (task_defs != nullptr && (*task_defs).size() > 0) {
  133. const auto &task_def = (*task_defs)[0];
  134. tmp_task_desc_info.block_dim = task_def.kernel().block_dim();
  135. }
  136. tmp_task_desc_info.task_id = task_id;
  137. tmp_task_desc_info.stream_id = stream_id;
  138. GELOGD("GetTaskDescInfo of node [%s] end, task_id[%u], stream_id[%u]", node->GetName().c_str(), task_id, stream_id);
  139. task_desc_info.emplace_back(tmp_task_desc_info);
  140. return SUCCESS;
  141. }
  142. Status NodeDoneCallback::GetGraphDescInfo(const NodePtr node, const HybridModel *model,
  143. std::vector<ComputeGraphDescInfo> &compute_graph_info) {
  144. GE_CHECK_NOTNULL(node);
  145. GE_CHECK_NOTNULL(model);
  146. GELOGD("GetComputeGraphInfo of node [%s] start.", node->GetName().c_str());
  147. std::string dynamic_model_name = model->GetModelName();
  148. auto op_desc = node->GetOpDesc();
  149. if (op_desc == nullptr) {
  150. GELOGE(PARAM_INVALID, "op_desc is nullptr.");
  151. return PARAM_INVALID;
  152. }
  153. auto op_mode = static_cast<uint32_t>(domi::ImplyType::INVALID);
  154. if (AttrUtils::GetInt(op_desc, ATTR_NAME_IMPLY_TYPE, op_mode) &&
  155. op_mode == static_cast<uint32_t>(domi::ImplyType::TVM)) {
  156. ComputeGraphDescInfo tmp_compute_graph_info;
  157. tmp_compute_graph_info.model_name = dynamic_model_name;
  158. tmp_compute_graph_info.op_name = op_desc->GetName();
  159. tmp_compute_graph_info.op_type = op_desc->GetType();
  160. for (size_t i = 0; i < op_desc->GetAllInputsSize(); ++i) {
  161. GeTensorDescPtr input_desc = op_desc->MutableInputDesc(i);
  162. if (input_desc == nullptr) {
  163. continue;
  164. }
  165. tmp_compute_graph_info.input_format.emplace_back(input_desc->GetFormat());
  166. tmp_compute_graph_info.input_shape.emplace_back(input_desc->GetShape().GetDims());
  167. tmp_compute_graph_info.input_data_type.emplace_back(input_desc->GetDataType());
  168. }
  169. for (size_t j = 0; j < op_desc->GetOutputsSize(); ++j) {
  170. GeTensorDesc output_desc = op_desc->GetOutputDesc(j);
  171. tmp_compute_graph_info.output_format.emplace_back(output_desc.GetFormat());
  172. tmp_compute_graph_info.output_shape.emplace_back(output_desc.GetShape().GetDims());
  173. tmp_compute_graph_info.output_data_type.emplace_back(output_desc.GetDataType());
  174. }
  175. compute_graph_info.emplace_back(tmp_compute_graph_info);
  176. GELOGD("GetComputeGraphInfo of node [%s] end.", node->GetName().c_str());
  177. }
  178. return SUCCESS;
  179. }
  180. Status NodeDoneCallback::ProfilingReport() {
  181. auto node = context_->GetNodeItem().node;
  182. if (node == nullptr) {
  183. GELOGE(PARAM_INVALID, "Get node is nullptr");
  184. return PARAM_INVALID;
  185. }
  186. const auto &op_type = node->GetType();
  187. if (op_type == PARTITIONEDCALL) {
  188. return SUCCESS;
  189. }
  190. GE_CHECK_NOTNULL(graph_context_);
  191. const HybridModel *model = graph_context_->model;
  192. GE_CHECK_NOTNULL(model);
  193. GELOGD("ProfilingReport of node [%s] model [%s] start.", node->GetName().c_str(), model->GetModelName().c_str());
  194. std::vector<TaskDescInfo> task_desc_info;
  195. TaskDescInfo tmp_task_desc_info;
  196. auto profiling_ret = GetTaskDescInfo(node, model, task_desc_info);
  197. if (profiling_ret != RT_ERROR_NONE) {
  198. GELOGE(profiling_ret, "Get task info of node[%s] failed.", node->GetName().c_str());
  199. return profiling_ret;
  200. }
  201. std::vector<ComputeGraphDescInfo> compute_graph_info;
  202. profiling_ret = GetGraphDescInfo(node, model, compute_graph_info);
  203. if (profiling_ret != RT_ERROR_NONE) {
  204. GELOGE(profiling_ret, "Get graph info of node[%s] failed.", node->GetName().c_str());
  205. return profiling_ret;
  206. }
  207. auto &profiling_manager = ProfilingManager::Instance();
  208. profiling_manager.ReportProfilingData(model->GetModelId(), task_desc_info, compute_graph_info,
  209. !profiling_manager.IsAclApiMode());
  210. return SUCCESS;
  211. }
  212. Status NodeDoneCallback::DumpDynamicNode() {
  213. auto node = context_->GetNodeItem().node;
  214. if (node == nullptr) {
  215. GELOGE(PARAM_INVALID, "Get node is nullptr");
  216. return PARAM_INVALID;
  217. }
  218. auto op_desc = node->GetOpDesc();
  219. auto stream = context_->GetStream();
  220. vector<uintptr_t> input_addrs;
  221. vector<uintptr_t> output_addrs;
  222. for (int i = 0; i < context_->NumInputs(); i++) {
  223. auto tensor_value = context_->GetInput(i);
  224. GE_CHK_BOOL_RET_STATUS(tensor_value != nullptr, PARAM_INVALID, "Tensor value is nullptr");
  225. uint64_t input_addr = reinterpret_cast<uintptr_t>(tensor_value->GetData());
  226. input_addrs.emplace_back(input_addr);
  227. }
  228. for (int j = 0; j < context_->NumOutputs(); j++) {
  229. auto tensor_value = context_->GetOutput(j);
  230. GE_CHK_BOOL_RET_STATUS(tensor_value != nullptr, PARAM_INVALID, "Tensor value is nullptr");
  231. uint64_t output_addr = reinterpret_cast<uintptr_t>(tensor_value->GetData());
  232. output_addrs.emplace_back(output_addr);
  233. }
  234. dump_op_.SetDumpInfo(context_->GetDumpProperties(), op_desc, input_addrs, output_addrs, stream);
  235. GE_CHECK_NOTNULL(graph_context_);
  236. const HybridModel *model = graph_context_->model;
  237. GE_CHECK_NOTNULL(model);
  238. std::string dynamic_model_name = model->GetModelName();
  239. uint32_t model_id = model->GetModelId();
  240. dump_op_.SetDynamicModelInfo(dynamic_model_name, model_id);
  241. void *global_step = nullptr;
  242. TensorValue *varible_global_step = context_->GetVariable(NODE_NAME_GLOBAL_STEP);
  243. if (varible_global_step != nullptr) {
  244. global_step = const_cast<void *>(varible_global_step->GetData());
  245. }
  246. void *loop_per_iter = nullptr;
  247. TensorValue *varible_loop_per_iter = context_->GetVariable(NODE_NAME_FLOWCTRL_LOOP_PER_ITER);
  248. if (varible_loop_per_iter != nullptr) {
  249. loop_per_iter = const_cast<void *>(varible_loop_per_iter->GetData());
  250. }
  251. void *loop_cond = nullptr;
  252. TensorValue *varible_loop_cond = context_->GetVariable(NODE_NAME_FLOWCTRL_LOOP_COND);
  253. if (varible_loop_cond != nullptr) {
  254. loop_cond = const_cast<void *>(varible_loop_cond->GetData());
  255. }
  256. dump_op_.SetLoopAddr(global_step, loop_per_iter, loop_cond);
  257. GE_CHK_STATUS_RET(dump_op_.LaunchDumpOp(), "Failed to launch dump op in hybird model");
  258. auto rt_ret = rtStreamSynchronize(stream);
  259. if (rt_ret != RT_ERROR_NONE) {
  260. GELOGE(rt_ret, "rtStreamSynchronize failed");
  261. return rt_ret;
  262. }
  263. return SUCCESS;
  264. }
  265. Status NodeDoneCallback::OnNodeDone() {
  266. auto &node_item = context_->GetNodeItem();
  267. GELOGI("[%s] Start callback process.", node_item.NodeName().c_str());
  268. RECORD_CALLBACK_EVENT(graph_context_, context_->GetNodeName(), "[Compute] End");
  269. RECORD_CALLBACK_EVENT(graph_context_, context_->GetNodeName(), "[Callback] Start");
  270. auto dump_path = context_->GetDumpProperties().GetDumpPath();
  271. if (!dump_path.empty()) {
  272. GELOGI("Start to dump dynamic shape,dump_path is %s", dump_path.c_str());
  273. GE_CHK_STATUS_RET(DumpDynamicNode(), "Failed to dump dynamic node");
  274. }
  275. if (ProfilingManager::Instance().ProfilingModelExecuteOn()) {
  276. GE_CHK_STATUS_RET(ProfilingReport(), "Report node[%s] to profiling failed.", node_item.NodeName().c_str());
  277. }
  278. // release inputs
  279. for (int i = 0; i < context_->NumInputs(); ++i) {
  280. context_->ReleaseInput(i);
  281. }
  282. GE_CHK_STATUS_RET_NOLOG(PrepareConstInputs(node_item));
  283. // PropagateOutputs for type == DEPEND_COMPUTE
  284. if (node_item.shape_inference_type == DEPEND_COMPUTE) {
  285. if (graph_context_->trace_enabled) {
  286. (void)LogOutputs(node_item, *context_);
  287. }
  288. GE_CHK_STATUS_RET(context_->PropagateOutputs(), "[%s] Failed to propagate outputs failed",
  289. node_item.NodeName().c_str());
  290. RECORD_CALLBACK_EVENT(graph_context_, context_->GetNodeName(), "[PropagateOutputs] End");
  291. }
  292. // release condition variable
  293. if (node_item.has_observer) {
  294. GELOGI("[%s] Notify observer. node_id = %d", node_item.NodeName().c_str(), node_item.node_id);
  295. context_->NodeDone();
  296. }
  297. RECORD_CALLBACK_EVENT(graph_context_, context_->GetNodeName(), "[Callback] End");
  298. return SUCCESS;
  299. }
  300. Status ExecutionEngine::ExecuteAsync(NodeState &node_state, const std::shared_ptr<TaskContext> &task_context,
  301. GraphExecutionContext &execution_context) {
  302. GELOGI("[%s] Node is ready for execution", task_context->GetNodeName());
  303. RECORD_EXECUTION_EVENT(&execution_context, task_context->GetNodeName(), "Start");
  304. auto cb = std::shared_ptr<NodeDoneCallback>(new (std::nothrow) NodeDoneCallback(&execution_context, task_context));
  305. GE_CHECK_NOTNULL(cb);
  306. auto callback = [&, cb]() {
  307. auto ret = cb->OnNodeDone();
  308. if (ret != SUCCESS) {
  309. task_context->OnError(ret);
  310. }
  311. };
  312. GE_CHK_STATUS_RET_NOLOG(DoExecuteAsync(node_state, *task_context, execution_context, callback));
  313. GE_CHK_STATUS_RET_NOLOG(PropagateOutputs(*node_state.GetNodeItem(), *task_context, execution_context));
  314. return SUCCESS;
  315. }
  316. Status ExecutionEngine::DoExecuteAsync(NodeState &node_state, TaskContext &task_context, GraphExecutionContext &context,
  317. const std::function<void()> &callback) {
  318. const auto &task = node_state.GetKernelTask();
  319. if (task == nullptr) {
  320. GELOGE(INTERNAL_ERROR, "[%s] NodeTask is null.", node_state.GetName().c_str());
  321. return INTERNAL_ERROR;
  322. }
  323. // Wait for dependent nodes(DEPEND_COMPUTE), so that the input tensors are valid.
  324. RECORD_EXECUTION_EVENT(&context, task_context.GetNodeName(), "[AwaitDependents] Start");
  325. GE_CHK_STATUS_RET(node_state.AwaitInputTensors(context), "[%s] Failed to wait for dependent nodes.",
  326. node_state.GetName().c_str());
  327. const auto &node_item = *node_state.GetNodeItem();
  328. auto executor = node_item.node_executor;
  329. GE_CHECK_NOTNULL(executor);
  330. RECORD_EXECUTION_EVENT(&context, task_context.GetNodeName(), "[PrepareTask] Start");
  331. GE_CHK_STATUS_RET(executor->PrepareTask(*task, task_context), "[%s] Failed to prepare task",
  332. node_state.GetName().c_str());
  333. RECORD_EXECUTION_EVENT(&context, task_context.GetNodeName(), "[PrepareTask] End");
  334. GELOGD("[%s] Done task preparation successfully.", node_state.GetName().c_str());
  335. if (context.trace_enabled) {
  336. LogInputs(node_item, task_context);
  337. if (node_item.shape_inference_type != DEPEND_COMPUTE) {
  338. LogOutputs(node_item, task_context);
  339. }
  340. }
  341. GE_CHK_STATUS_RET(ValidateInputTensors(node_state, task_context), "Failed to validate input tensors.");
  342. RECORD_EXECUTION_EVENT(&context, task_context.GetNodeName(), "[ValidateInputTensors] End");
  343. if (context.profiling_level > 0) {
  344. auto *ctx = &context;
  345. const string &name = node_state.GetName();
  346. (void)task_context.RegisterCallback([ctx, name]() { RECORD_CALLBACK_EVENT(ctx, name.c_str(), "[Compute] Start"); });
  347. }
  348. RECORD_EXECUTION_EVENT(&context, task_context.GetNodeName(), "[ExecuteTask] Start");
  349. GE_CHK_STATUS_RET(node_item.node_executor->ExecuteTask(*task, task_context, callback), "[%s] Failed to execute task",
  350. node_state.GetName().c_str());
  351. RECORD_EXECUTION_EVENT(&context, task_context.GetNodeName(), "[ExecuteTask] End");
  352. GELOGD("[%s] Done task launch successfully.", node_state.GetName().c_str());
  353. return SUCCESS;
  354. }
  355. Status ExecutionEngine::ValidateInputTensors(const NodeState &node_state, const TaskContext &task_context) {
  356. for (auto i = 0; i < task_context.NumInputs(); ++i) {
  357. const auto &input_tensor = task_context.GetInput(i);
  358. GE_CHECK_NOTNULL(input_tensor);
  359. if (input_tensor->GetData() == nullptr) {
  360. GELOGD("[%s] Skipping null input, index = %d", task_context.GetNodeName(), i);
  361. continue;
  362. }
  363. const auto &tensor_desc = node_state.GetOpDesc()->MutableInputDesc(i);
  364. GE_CHECK_NOTNULL(tensor_desc);
  365. if (tensor_desc->GetDataType() == DT_STRING) {
  366. GELOGD("[%s] Skipping DT_STRING input, index = %d", task_context.GetNodeName(), i);
  367. continue;
  368. }
  369. if (input_tensor->GetData() == nullptr) {
  370. GELOGD("[%s] Skipping null input, index = %d", task_context.GetNodeName(), i);
  371. continue;
  372. }
  373. int64_t expected_size;
  374. GE_CHK_GRAPH_STATUS_RET(TensorUtils::GetTensorMemorySizeInBytes(*tensor_desc, expected_size));
  375. GELOGD("[%s] Input[%d] expects [%ld] bytes.", task_context.GetNodeName(), i, expected_size);
  376. auto size_diff = expected_size - static_cast<int64_t>(input_tensor->GetSize());
  377. if (size_diff > 0) {
  378. if (size_diff <= kMaxPadding) {
  379. GELOGW("[%s] Input[%d]: tensor size mismatches. expected: %ld, but given %zu", task_context.GetNodeName(), i,
  380. expected_size, input_tensor->GetSize());
  381. } else {
  382. GELOGE(INTERNAL_ERROR, "[%s] Input[%d]: tensor size mismatches. expected: %ld, but given %zu",
  383. task_context.GetNodeName(), i, expected_size, input_tensor->GetSize());
  384. return INTERNAL_ERROR;
  385. }
  386. }
  387. }
  388. return SUCCESS;
  389. }
  390. Status ExecutionEngine::PropagateOutputs(const NodeItem &node_item, TaskContext &task_context,
  391. GraphExecutionContext &context) {
  392. if (node_item.shape_inference_type != DEPEND_COMPUTE) {
  393. GE_CHK_STATUS_RET(task_context.PropagateOutputs(), "[%s] Failed to propagate outputs.",
  394. node_item.NodeName().c_str());
  395. RECORD_EXECUTION_EVENT(&context, task_context.GetNodeName(), "[PropagateOutputs] End");
  396. GELOGD("[%s] Done propagating outputs successfully.", node_item.NodeName().c_str());
  397. }
  398. return SUCCESS;
  399. }
  400. } // namespace hybrid
  401. } // namespace ge

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