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

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

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