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.

single_op.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
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
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
4 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  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 "single_op/single_op.h"
  17. #include "common/fmk_types.h"
  18. #include "common/ge_types.h"
  19. #include "common/math/math_util.h"
  20. #include "common/profiling/profiling_manager.h"
  21. #include "framework/common/debug/ge_log.h"
  22. #include "framework/common/util.h"
  23. #include "graph/load/model_manager/model_utils.h"
  24. #include "runtime/mem.h"
  25. #include "single_op/single_op_manager.h"
  26. #include "single_op/task/build_task_utils.h"
  27. #include "graph/load/model_manager/model_manager.h"
  28. namespace ge {
  29. namespace {
  30. const size_t kDataMemAlignSize = 32;
  31. const size_t kDataMemAlignUnit = 2;
  32. const string kShapeTypeDynamic = "dynamic";
  33. const string kShapeTypeStatic = "static";
  34. const int64_t kHostMemType = 1;
  35. const uint32_t kFuzzDeviceBufferSize = 1 * 1024 * 1024;
  36. const uint32_t kAlignBytes = 512;
  37. size_t GetAlignedSize(size_t size) {
  38. size_t aligned_size = (size + kDataMemAlignUnit * kDataMemAlignSize - 1) / kDataMemAlignSize * kDataMemAlignSize;
  39. return aligned_size;
  40. }
  41. Status ProfilingTaskInfo(OpTask *op_task, const string &shape_type) {
  42. if (!ProfilingManager::Instance().ProfilingModelLoadOn()) {
  43. return SUCCESS;
  44. }
  45. TaskDescInfo tmp_task_desc_info;
  46. uint32_t model_id;
  47. if (op_task->GetProfilingArgs(tmp_task_desc_info, model_id) != SUCCESS) {
  48. GELOGE(ACL_ERROR_GE_PARAM_INVALID, "[Get][ProfilingArgs] failed.");
  49. return ACL_ERROR_GE_PARAM_INVALID;
  50. }
  51. GELOGD("ProfilingReport of op[%s] model[%s] start.",
  52. tmp_task_desc_info.op_name.c_str(), tmp_task_desc_info.model_name.c_str());
  53. tmp_task_desc_info.shape_type = shape_type;
  54. tmp_task_desc_info.cur_iter_num = 0;
  55. tmp_task_desc_info.task_type = op_task->GetTaskType();
  56. std::vector<TaskDescInfo> task_desc_info;
  57. task_desc_info.emplace_back(tmp_task_desc_info);
  58. auto &profiling_manager = ProfilingManager::Instance();
  59. profiling_manager.ReportProfilingData(model_id, task_desc_info);
  60. return SUCCESS;
  61. }
  62. Status CalInputsHostMemSize(const std::vector<DataBuffer> &inputs,
  63. std::vector<std::pair<size_t, uint64_t>> &inputs_size) {
  64. int64_t total_size = 0;
  65. size_t index = 0;
  66. for (auto &input_buffer : inputs) {
  67. int64_t input_size = 0;
  68. if (input_buffer.placement == kHostMemType) {
  69. GE_CHECK_LE(input_buffer.length, INT64_MAX);
  70. input_size = input_buffer.length;
  71. // input_size pad to 512
  72. GE_CHK_STATUS_RET(CheckInt64AddOverflow(input_size, (kAlignBytes - 1)), "Padding size is beyond the INT64_MAX.");
  73. input_size = ((input_size + kAlignBytes - 1) / kAlignBytes) * kAlignBytes;
  74. inputs_size.emplace_back(index, input_size);
  75. GE_CHK_STATUS_RET(CheckInt64AddOverflow(total_size, input_size), "Total size is beyond the INT64_MAX.");
  76. total_size += input_size;
  77. GELOGD("The %zu input mem type is host, the tensor size is %ld.", index, input_size);
  78. }
  79. index++;
  80. }
  81. if (total_size > kFuzzDeviceBufferSize) {
  82. GELOGE(FAILED, "[Check][Size]Total size is %ld, larger than 1M.", total_size);
  83. return FAILED;
  84. }
  85. return SUCCESS;
  86. }
  87. Status UpdateInputsBufferAddr(StreamResource *stream_resource, rtStream_t stream,
  88. const std::vector<std::pair<size_t, uint64_t>> &inputs_size,
  89. std::vector<DataBuffer> &update_buffers) {
  90. GE_CHECK_NOTNULL(stream_resource);
  91. auto dst_addr = reinterpret_cast<uint8_t *>(stream_resource->GetDeviceBufferAddr());
  92. // copy host mem from input_buffer to device mem of dst_addr
  93. for (const auto &input_size : inputs_size) {
  94. auto index = input_size.first;
  95. auto size = input_size.second;
  96. GELOGD("Do h2d for %zu input, dst size is %zu, src length is %lu.", index, size, update_buffers[index].length);
  97. GE_CHK_RT_RET(rtMemcpyAsync(dst_addr, size, update_buffers[index].data, update_buffers[index].length,
  98. RT_MEMCPY_HOST_TO_DEVICE_EX, stream));
  99. update_buffers[index].data = dst_addr;
  100. dst_addr = dst_addr + size;
  101. }
  102. return SUCCESS;
  103. }
  104. Status InitHybridModelArgs(const std::vector<DataBuffer> &input_buffers,
  105. const std::vector<DataBuffer> &output_buffers,
  106. const std::vector<GeTensorDesc> &inputs_desc,
  107. hybrid::HybridModelExecutor::ExecuteArgs &args) {
  108. for (auto &input : input_buffers) {
  109. args.inputs.emplace_back(hybrid::TensorValue(input.data, input.length));
  110. }
  111. for (auto &output : output_buffers) {
  112. args.outputs.emplace_back(hybrid::TensorValue(output.data, output.length));
  113. }
  114. for (auto &tensor_desc : inputs_desc) {
  115. auto desc = MakeShared<GeTensorDesc>(tensor_desc);
  116. GE_CHECK_NOTNULL(desc);
  117. args.input_desc.emplace_back(desc);
  118. }
  119. return SUCCESS;
  120. }
  121. } // namespace
  122. SingleOp::SingleOp(StreamResource *stream_resource, std::mutex *stream_mutex, rtStream_t stream)
  123. : stream_resource_(stream_resource), stream_mutex_(stream_mutex), stream_(stream) {
  124. }
  125. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY SingleOp::~SingleOp() {
  126. for (auto task : tasks_) {
  127. delete task;
  128. task = nullptr;
  129. }
  130. }
  131. Status SingleOp::ValidateArgs(const std::vector<DataBuffer> &inputs, const std::vector<DataBuffer> &outputs) {
  132. auto num_inputs = inputs.size();
  133. if (num_inputs != input_sizes_.size()) {
  134. GELOGE(ACL_ERROR_GE_PARAM_INVALID,
  135. "[Check][Param:inputs]Input num mismatch. model expect %zu, but given %zu", input_addr_list_.size(),
  136. inputs.size());
  137. REPORT_INPUT_ERROR("E10401", std::vector<std::string>({"expect_num", "input_num"}),
  138. std::vector<std::string>({std::to_string(input_addr_list_.size()), std::to_string(num_inputs)}));
  139. return ACL_ERROR_GE_PARAM_INVALID;
  140. }
  141. for (size_t i = 0; i < num_inputs; ++i) {
  142. // preventing from read out of bound
  143. size_t aligned_size = GetAlignedSize(inputs[i].length);
  144. GELOGI("Input [%zu], aligned_size:%zu, inputs.length:%lu, input_sizes_:%zu",
  145. i, aligned_size, inputs[i].length, input_sizes_[i]);
  146. if (aligned_size < input_sizes_[i]) {
  147. GELOGE(ACL_ERROR_GE_PARAM_INVALID,
  148. "[Check][Param:inputs]Input size mismatch. index = %zu, model expect %zu, but given %zu(after align)",
  149. i, input_sizes_[i], aligned_size);
  150. REPORT_INPUT_ERROR("E10402", std::vector<std::string>({"index", "expect_size", "input_size"}),
  151. std::vector<std::string>({std::to_string(i), std::to_string(input_sizes_[i]), std::to_string(aligned_size)})
  152. );
  153. return ACL_ERROR_GE_PARAM_INVALID;
  154. }
  155. }
  156. auto num_outputs = outputs.size();
  157. if (num_outputs != output_sizes_.size()) {
  158. GELOGE(ACL_ERROR_GE_PARAM_INVALID, "[Check][Param:outputs]output num mismatch. model expect %zu, but given %zu",
  159. output_sizes_.size(), outputs.size());
  160. REPORT_INPUT_ERROR("E10403", std::vector<std::string>({"expect_num", "input_num"}),
  161. std::vector<std::string>({std::to_string(output_sizes_.size()), std::to_string(outputs.size())}));
  162. return ACL_ERROR_GE_PARAM_INVALID;
  163. }
  164. for (size_t i = 0; i < num_outputs; ++i) {
  165. // preventing from write out of bound
  166. size_t aligned_size = GetAlignedSize(outputs[i].length);
  167. GELOGI("Output [%zu], aligned_size:%zu, outputs.length:%lu, output_sizes_:%zu",
  168. i, aligned_size, outputs[i].length, output_sizes_[i]);
  169. if (aligned_size < output_sizes_[i]) {
  170. GELOGE(ACL_ERROR_GE_PARAM_INVALID,
  171. "[Check][Param:outputs]Output size mismatch. index = %zu, model expect %zu, but given %zu(after align)",
  172. i, output_sizes_[i], aligned_size);
  173. REPORT_INPUT_ERROR("E10404", std::vector<std::string>({"index", "expect_size", "input_size"}),
  174. std::vector<std::string>({std::to_string(i), std::to_string(output_sizes_[i]), std::to_string(aligned_size)})
  175. );
  176. return ACL_ERROR_GE_PARAM_INVALID;
  177. }
  178. }
  179. return SUCCESS;
  180. }
  181. Status SingleOp::GetArgs(const std::vector<DataBuffer> &inputs, const std::vector<DataBuffer> &outputs) {
  182. size_t arg_index = 0;
  183. for (auto &input : inputs) {
  184. args_[arg_index++] = reinterpret_cast<uintptr_t>(input.data);
  185. }
  186. for (auto &output : outputs) {
  187. args_[arg_index++] = reinterpret_cast<uintptr_t>(output.data);
  188. }
  189. return SUCCESS;
  190. }
  191. Status SingleOp::UpdateArgs(const std::vector<DataBuffer> &inputs, const std::vector<DataBuffer> &outputs) {
  192. Status ret = GetArgs(inputs, outputs);
  193. if (ret != SUCCESS) {
  194. return ret;
  195. }
  196. // update tbe task args
  197. size_t num_args = arg_table_.size();
  198. for (size_t i = 0; i < num_args; ++i) {
  199. std::vector<uintptr_t *> &ptr_to_arg_in_tasks = arg_table_[i];
  200. if (ptr_to_arg_in_tasks.empty()) {
  201. GELOGW("found NO arg address to update for arg[%lu]", i);
  202. continue;
  203. }
  204. for (uintptr_t *arg_addr : ptr_to_arg_in_tasks) {
  205. *arg_addr = args_[i];
  206. }
  207. }
  208. return SUCCESS;
  209. }
  210. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status SingleOp::ExecuteAsync(const std::vector<DataBuffer> &inputs,
  211. const std::vector<DataBuffer> &outputs) {
  212. GELOGD("Start SingleOp::ExecuteAsync.");
  213. Status ret = ValidateArgs(inputs, outputs);
  214. if (ret != SUCCESS) {
  215. return ret;
  216. }
  217. GE_CHECK_NOTNULL(stream_resource_);
  218. vector<pair<size_t, uint64_t>> inputs_size;
  219. GE_CHK_STATUS_RET_NOLOG(CalInputsHostMemSize(inputs, inputs_size));
  220. std::lock_guard<std::mutex> lk(*stream_mutex_);
  221. vector<DataBuffer> update_buffers = inputs;
  222. if (!inputs_size.empty()) {
  223. GE_CHK_STATUS_RET_NOLOG(UpdateInputsBufferAddr(stream_resource_, stream_, inputs_size, update_buffers));
  224. }
  225. if (hybrid_model_executor_ != nullptr) {
  226. GELOGD("Execute multi-task single op by hybrid model executor");
  227. hybrid::HybridModelExecutor::ExecuteArgs args;
  228. GE_CHK_STATUS_RET_NOLOG(InitHybridModelArgs(update_buffers, outputs, inputs_desc_, args));
  229. return hybrid_model_executor_->Execute(args);
  230. }
  231. auto current_mem_base = stream_resource_->GetMemoryBase();
  232. if (running_param_->mem_base != current_mem_base) {
  233. running_param_->mem_base = const_cast<uint8_t *>(current_mem_base);
  234. GELOGD("Memory base changed, new memory base = %p", current_mem_base);
  235. for (auto &task : tasks_) {
  236. auto new_address = BuildTaskUtils::GetAddresses(task->GetOpdesc(), *running_param_);
  237. GE_CHK_STATUS_RET(task->UpdateArgTable(*running_param_), "[Update][ArgTable] failed, single op:%s.",
  238. task->GetOpdesc()->GetName().c_str());
  239. }
  240. }
  241. ret = UpdateArgs(update_buffers, outputs);
  242. if (ret != SUCCESS) {
  243. return ret;
  244. }
  245. for (auto &task : tasks_) {
  246. ret = task->LaunchKernel(stream_);
  247. if (ret != SUCCESS) {
  248. return ret;
  249. }
  250. GE_CHK_STATUS_RET(task->OpenDump(stream_), "[Open][Dump]failed, single op:%s.",
  251. task->GetOpdesc()->GetName().c_str());
  252. GE_CHK_STATUS_RET_NOLOG(ProfilingTaskInfo(task, kShapeTypeStatic));
  253. }
  254. return ret;
  255. }
  256. void SingleOp::SetStream(rtStream_t stream) {
  257. stream_ = stream;
  258. }
  259. DynamicSingleOp::DynamicSingleOp(uintptr_t resource_id, std::mutex *stream_mutex, rtStream_t stream)
  260. : resource_id_(resource_id), stream_mutex_(stream_mutex), stream_(stream) {
  261. }
  262. Status DynamicSingleOp::ValidateParams(const vector<GeTensorDesc> &input_desc,
  263. const std::vector<DataBuffer> &inputs,
  264. std::vector<GeTensorDesc> &output_desc,
  265. std::vector<DataBuffer> &outputs) const {
  266. if (inputs.size() != input_desc.size()) {
  267. GELOGE(ACL_ERROR_GE_PARAM_INVALID,
  268. "[Check][Param:inputs]Input number mismatches input desc number. Input num = %zu, input desc num = %zu",
  269. inputs.size(), input_desc.size());
  270. REPORT_INPUT_ERROR("E10405", std::vector<std::string>({"input_num", "input_desc_num"}),
  271. std::vector<std::string>({std::to_string(inputs.size()), std::to_string(input_desc.size())}));
  272. return ACL_ERROR_GE_PARAM_INVALID;
  273. }
  274. if (outputs.size() != output_desc.size()) {
  275. GELOGE(ACL_ERROR_GE_PARAM_INVALID,
  276. "[Check][Param:outputs]Output number mismatches output desc number. Output num = %zu, output desc num = %zu",
  277. outputs.size(), output_desc.size());
  278. REPORT_INPUT_ERROR("E10406", std::vector<std::string>({"out_num", "out_desc_num"}),
  279. std::vector<std::string>({std::to_string(outputs.size()), std::to_string(output_desc.size())}));
  280. return ACL_ERROR_GE_PARAM_INVALID;
  281. }
  282. if (input_desc.size() != num_inputs_) {
  283. GELOGE(ACL_ERROR_GE_PARAM_INVALID, "[Check][Param:input_desc]Input number mismatches. expect %zu, but given %zu",
  284. num_inputs_, input_desc.size());
  285. REPORT_INPUT_ERROR("E10401", std::vector<std::string>({"expect_num", "input_num"}),
  286. std::vector<std::string>({std::to_string(num_inputs_), std::to_string(input_desc.size())}));
  287. return ACL_ERROR_GE_PARAM_INVALID;
  288. }
  289. if (output_desc.size() != num_outputs_) {
  290. GELOGE(ACL_ERROR_GE_PARAM_INVALID, "[Check][Param:output_desc]Output number mismatches. expect %zu, but given %zu",
  291. num_outputs_, output_desc.size());
  292. REPORT_INPUT_ERROR("E10403", std::vector<std::string>({"expect_num", "input_num"}),
  293. std::vector<std::string>({std::to_string(num_outputs_), std::to_string(output_desc.size())}));
  294. return ACL_ERROR_GE_PARAM_INVALID;
  295. }
  296. return SUCCESS;
  297. }
  298. Status DynamicSingleOp::SetHostTensorValue(const std::vector<std::pair<size_t, uint64_t>> &inputs_size,
  299. const vector<GeTensorDesc> &input_desc,
  300. const std::vector<DataBuffer> &input_buffers) {
  301. auto op_desc = op_task_->GetOpdesc();
  302. GE_CHECK_NOTNULL(op_desc);
  303. GELOGD("Start update inputs tensor value of %s.", op_desc->GetName().c_str());
  304. for (const auto &input_size : inputs_size) {
  305. size_t index = input_size.first;
  306. auto ge_tensor_desc = input_desc.at(index);
  307. // reconstruct GeTensor by DataBuffer
  308. GeTensorPtr ge_tensor = MakeShared<GeTensor>(ge_tensor_desc);
  309. GE_CHECK_NOTNULL(ge_tensor);
  310. GELOGD("The %zu tensor input type is host, desc data type is %d, input buffer addr is %p, size is %ld.",
  311. index, ge_tensor_desc.GetDataType(), input_buffers[index].data, input_buffers[index].length);
  312. if (ge_tensor->SetData(reinterpret_cast<uint8_t *>(input_buffers[index].data),
  313. static_cast<size_t>(input_buffers[index].length)) != SUCCESS) {
  314. GELOGE(INTERNAL_ERROR, "[Set][Data]Failed to set data of ge tensor.");
  315. return INTERNAL_ERROR;
  316. }
  317. auto tensor_desc = op_desc->MutableInputDesc(index);
  318. GE_CHECK_NOTNULL(tensor_desc);
  319. if (!AttrUtils::SetTensor(tensor_desc, ATTR_NAME_VALUE, ge_tensor)) {
  320. GELOGE(FAILED, "[Set][ATTR_NAME_VALUE]Failed to set ATTR_NAME_VALUE to %s.", op_desc->GetName().c_str());
  321. return FAILED;
  322. }
  323. }
  324. return SUCCESS;
  325. }
  326. Status DynamicSingleOp::SetHostTensorValue(const vector<GeTensorDesc> &input_desc,
  327. const vector<DataBuffer> &input_buffers) {
  328. for (auto &tensor_map : tensor_with_hostmem_) {
  329. auto index = static_cast<size_t>(tensor_map.first);
  330. if (index >= input_desc.size() || index >= input_buffers.size()) {
  331. GELOGE(INTERNAL_ERROR, "[Check][Size]Index %zu should smaller then input desc size %zu "
  332. "and input buffers size %zu.", index, input_desc.size(), input_buffers.size());
  333. return INTERNAL_ERROR;
  334. }
  335. auto ge_tensor_desc = input_desc[index];
  336. // reconstruct GeTensor by DataBuffer
  337. GeTensorPtr ge_tensor = MakeShared<GeTensor>(ge_tensor_desc);
  338. GE_CHECK_NOTNULL(ge_tensor);
  339. GELOGD("The %zu tensor input type is host, desc data type is %d, input buffer addr is %p, size is %ld.",
  340. index, ge_tensor_desc.GetDataType(), input_buffers[index].data, input_buffers[index].length);
  341. if (ge_tensor->SetData(reinterpret_cast<uint8_t *>(input_buffers[index].data),
  342. static_cast<size_t>(input_buffers[index].length)) != SUCCESS) {
  343. GELOGE(INTERNAL_ERROR, "[Set][Data]Failed to set data of ge tensor.");
  344. return INTERNAL_ERROR;
  345. }
  346. for (auto &tensor_desc : tensor_map.second) {
  347. GE_CHECK_NOTNULL(tensor_desc);
  348. if (!AttrUtils::SetTensor(tensor_desc, ATTR_NAME_VALUE, ge_tensor)) {
  349. GELOGE(FAILED, "[Set][ATTR_NAME_VALUE]Failed to set ATTR_NAME_VALUE.");
  350. return FAILED;
  351. }
  352. }
  353. }
  354. return SUCCESS;
  355. }
  356. Status DynamicSingleOp::ExecuteAsync(const vector<GeTensorDesc> &input_desc,
  357. const vector<DataBuffer> &input_buffers,
  358. vector<GeTensorDesc> &output_desc,
  359. vector<DataBuffer> &output_buffers) {
  360. GELOGD("Start DynamicSingleOp::ExecuteAsync.");
  361. GE_CHK_STATUS_RET_NOLOG(ValidateParams(input_desc, input_buffers, output_desc, output_buffers));
  362. vector<pair<size_t, uint64_t>> inputs_size;
  363. GE_CHK_STATUS_RET_NOLOG(CalInputsHostMemSize(input_buffers, inputs_size));
  364. vector<DataBuffer> update_buffers = input_buffers;
  365. std::lock_guard<std::mutex> lk(*stream_mutex_);
  366. if (!inputs_size.empty()) {
  367. StreamResource *stream_resource = SingleOpManager::GetInstance().GetResource(resource_id_, stream_);
  368. GE_CHK_STATUS_RET_NOLOG(UpdateInputsBufferAddr(stream_resource, stream_, inputs_size, update_buffers));
  369. GE_CHK_STATUS_RET_NOLOG(SetHostTensorValue(input_desc, input_buffers));
  370. }
  371. if (hybrid_model_executor_ != nullptr) {
  372. GELOGD("Execute multi-task dynamic single op by hybrid model executor");
  373. hybrid::HybridModelExecutor::ExecuteArgs args;
  374. GE_CHK_STATUS_RET_NOLOG(InitHybridModelArgs(update_buffers, output_buffers, input_desc, args));
  375. return hybrid_model_executor_->Execute(args);
  376. }
  377. GE_CHECK_NOTNULL(op_task_);
  378. if (!inputs_size.empty()) {
  379. GE_CHK_STATUS_RET_NOLOG(SetHostTensorValue(inputs_size, input_desc, input_buffers));
  380. GE_CHK_STATUS_RET_NOLOG(op_task_->LaunchKernel(input_desc, update_buffers, output_desc, output_buffers, stream_));
  381. } else {
  382. GE_CHK_STATUS_RET_NOLOG(op_task_->LaunchKernel(input_desc, input_buffers, output_desc, output_buffers, stream_));
  383. }
  384. GE_CHK_STATUS_RET_NOLOG(op_task_->OpenDump(stream_));
  385. GE_CHK_STATUS_RET_NOLOG(ProfilingTaskInfo(op_task_.get(), kShapeTypeDynamic));
  386. return SUCCESS;
  387. }
  388. } // namespace ge

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