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

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