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.

op_task.cc 37 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
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
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907
  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/task/op_task.h"
  17. #include <google/protobuf/extension_set.h>
  18. #include <chrono>
  19. #include <thread>
  20. #include "aicpu/common/aicpu_task_struct.h"
  21. #include "common/dump/dump_manager.h"
  22. #include "common/dump/dump_op.h"
  23. #include "common/formats/formats.h"
  24. #include "common/math/math_util.h"
  25. #include "framework/common/debug/log.h"
  26. #include "register/op_tiling.h"
  27. #include "runtime/rt.h"
  28. #include "build_task_utils.h"
  29. namespace ge {
  30. namespace {
  31. constexpr int kLaunchRetryTimes = 1000;
  32. constexpr int kSleepTime = 10;
  33. constexpr uint64_t kReleaseFlag = 1;
  34. constexpr int kCopyNum = 2;
  35. void FreeHbm(void *var) {
  36. if (var) {
  37. (void)rtFree(var);
  38. }
  39. }
  40. } // namespace
  41. Status OpTask::OpenDump(rtStream_t stream) {
  42. if (DumpManager::GetInstance().GetDumpProperties().IsSingleOpNeedDump()) {
  43. GELOGI("Dump is open in single op, start to set dump info");
  44. std::vector<uint64_t> input_addrs;
  45. std::vector<uint64_t> output_adds;
  46. auto input_size = op_desc_->GetInputsSize();
  47. auto output_size = op_desc_->GetOutputsSize();
  48. uintptr_t *arg_base = nullptr;
  49. size_t arg_num = 0;
  50. GetIoAddr(arg_base, arg_num);
  51. if (arg_num < input_size + output_size) {
  52. GELOGE(ACL_ERROR_GE_INTERNAL_ERROR, "io_addrs_for_dump_ size %zu is not equal input and output size %zu",
  53. arg_num,
  54. input_size + output_size);
  55. return ACL_ERROR_GE_INTERNAL_ERROR;
  56. }
  57. for (size_t i = 0; i < input_size; i++) {
  58. uint64_t input_addr = arg_base[i];
  59. input_addrs.emplace_back(input_addr);
  60. }
  61. for (size_t j = 0; j < output_size; j++) {
  62. uint64_t output_addr = arg_base[input_size + j];
  63. output_adds.emplace_back(output_addr);
  64. }
  65. dump_op_.SetDumpInfo(DumpManager::GetInstance().GetDumpProperties(), op_desc_, input_addrs, output_adds, stream);
  66. auto status = dump_op_.LaunchDumpOp();
  67. if (status != SUCCESS) {
  68. GELOGE(status, "Launch dump op failed in single op");
  69. return status;
  70. }
  71. return SUCCESS;
  72. }
  73. GELOGI("Dump is not open in single op");
  74. return SUCCESS;
  75. }
  76. void TbeOpTask::SetStubFunc(const std::string &name, const void *stub_func) {
  77. this->stub_name_ = name;
  78. this->stub_func_ = stub_func;
  79. }
  80. void TbeOpTask::SetKernelArgs(std::unique_ptr<uint8_t[]> &&args, size_t arg_size, uint32_t block_dim,
  81. const OpDescPtr &op_desc) {
  82. args_ = std::move(args);
  83. arg_size_ = arg_size;
  84. block_dim_ = block_dim;
  85. op_desc_ = op_desc;
  86. }
  87. void TbeOpTask::SetKernelWithHandleArgs(std::unique_ptr<uint8_t[]> &&args, size_t arg_size, uint32_t block_dim,
  88. const OpDescPtr &op_desc,
  89. const domi::KernelDefWithHandle &kernel_def_with_handle) {
  90. SetKernelArgs(std::move(args), arg_size, block_dim, op_desc);
  91. original_kernel_key_ = kernel_def_with_handle.original_kernel_key();
  92. node_info_ = kernel_def_with_handle.node_info();
  93. }
  94. void TbeOpTask::SetSmDesc(void *sm_desc) { sm_desc_ = sm_desc; }
  95. void OpTask::SetModelArgs(std::string model_name, uint32_t model_id) {
  96. model_name_ = model_name;
  97. model_id_ = model_id;
  98. }
  99. Status OpTask::GetProfilingArgs(std::string &model_name, std::string &op_name, uint32_t &model_id,
  100. uint32_t &block_dim) {
  101. model_name = model_name_;
  102. model_id = model_id_;
  103. block_dim = block_dim_;
  104. GE_CHECK_NOTNULL(op_desc_);
  105. op_name = op_desc_->GetName();
  106. return SUCCESS;
  107. }
  108. Status OpTask::UpdateRunInfo(const vector<GeTensorDesc> &input_desc, const vector<GeTensorDesc> &output_desc) {
  109. return UNSUPPORTED;
  110. }
  111. Status OpTask::DoUpdateArgTable(const SingleOpModelParam &param, bool keep_workspace) {
  112. auto addresses = BuildTaskUtils::GetAddresses(op_desc_, param, keep_workspace);
  113. auto all_addresses = BuildTaskUtils::JoinAddresses(addresses);
  114. uintptr_t *arg_base = nullptr;
  115. size_t arg_num = 0;
  116. GetIoAddr(arg_base, arg_num);
  117. if (arg_num < all_addresses.size()) {
  118. GELOGE(ACL_ERROR_GE_INTERNAL_ERROR, "[%s] arg number mismatches, expect at least = %zu, but got = %zu",
  119. op_desc_->GetName().c_str(),
  120. all_addresses.size(),
  121. arg_num);
  122. return ACL_ERROR_GE_INTERNAL_ERROR;
  123. }
  124. for (void *addr : all_addresses) {
  125. *arg_base++ = reinterpret_cast<uintptr_t >(addr);
  126. }
  127. return SUCCESS;
  128. }
  129. Status OpTask::UpdateArgTable(const SingleOpModelParam &param) {
  130. return DoUpdateArgTable(param, true);
  131. }
  132. Status OpTask::LaunchKernel(const vector<GeTensorDesc> &input_desc,
  133. const vector<DataBuffer> &input_buffers,
  134. vector<GeTensorDesc> &output_desc,
  135. vector<DataBuffer> &output_buffers,
  136. rtStream_t stream) {
  137. return UNSUPPORTED;
  138. }
  139. uint32_t OpTask::GetTaskType() const { return kTaskTypeInvalid; }
  140. TbeOpTask::~TbeOpTask() {
  141. if (sm_desc_ != nullptr) {
  142. (void)rtMemFreeManaged(sm_desc_);
  143. }
  144. if (tiling_buffer_ != nullptr) {
  145. (void)rtFree(tiling_buffer_);
  146. }
  147. }
  148. const void *TbeOpTask::GetArgs() const { return args_.get(); }
  149. size_t TbeOpTask::GetArgSize() const { return arg_size_; }
  150. const std::string &TbeOpTask::GetStubName() const { return stub_name_; }
  151. uint32_t TbeOpTask::GetTaskType() const { return kTaskTypeAicore; }
  152. void TbeOpTask::SetHandle(void *handle) {
  153. this->handle_ = handle;
  154. }
  155. Status TbeOpTask::LaunchKernel(rtStream_t stream) {
  156. GELOGD("To invoke rtKernelLaunch. task = %s, block_dim = %u", this->stub_name_.c_str(), block_dim_);
  157. auto *sm_desc = reinterpret_cast<rtSmDesc_t *>(sm_desc_);
  158. auto ret = rtKernelLaunch(stub_func_, block_dim_, args_.get(), static_cast<uint32_t>(arg_size_), sm_desc, stream);
  159. int retry_times = 0;
  160. while (ret != RT_ERROR_NONE && retry_times < kLaunchRetryTimes) {
  161. retry_times++;
  162. GELOGW("Retry after %d ms, retry_times: %d", kSleepTime, retry_times);
  163. std::this_thread::sleep_for(std::chrono::milliseconds(kSleepTime));
  164. ret = rtKernelLaunch(stub_func_, block_dim_, args_.get(), arg_size_, sm_desc, stream);
  165. }
  166. if (ret != RT_ERROR_NONE) {
  167. GELOGE(ret, "Invoke rtKernelLaunch failed. ret = %d, task = %s", ret, this->stub_name_.c_str());
  168. return RT_ERROR_TO_GE_STATUS(ret);
  169. }
  170. GELOGI("[TASK_INFO] %s", this->stub_name_.c_str());
  171. auto status = OpenDump(stream);
  172. if (status != SUCCESS) {
  173. GELOGE(status, "Open dump failed in the tbe single op %s", this->stub_name_.c_str());
  174. return status;
  175. }
  176. return SUCCESS;
  177. }
  178. Status TbeOpTask::UpdateRunInfo(const vector<GeTensorDesc> &input_desc, const vector<GeTensorDesc> &output_desc) {
  179. GE_CHK_STATUS_RET_NOLOG(UpdateNodeByShape(input_desc, output_desc));
  180. // invoke OpParaCalculate
  181. GELOGD("Start to invoke OpParaCalculate.");
  182. optiling::OpRunInfo run_info;
  183. run_info.block_dim = 0;
  184. auto ret = optiling::OpParaCalculate(*node_, run_info);
  185. if (ret != GRAPH_SUCCESS) {
  186. GELOGE(ACL_ERROR_GE_INTERNAL_ERROR, "Failed to invoke OpParaCalculate. ret = %u", ret);
  187. return ACL_ERROR_GE_INTERNAL_ERROR;
  188. }
  189. block_dim_ = run_info.block_dim;
  190. tiling_data_ = run_info.tiling_data.str();
  191. tiling_key_ = run_info.tiling_key;
  192. GELOGD("Done invoking OpParaCalculate successfully. block_dim = %u, tiling size = %zu, tiling_key = %u", block_dim_,
  193. tiling_data_.size(), tiling_key_);
  194. GE_CHK_STATUS_RET(AllocateWorkspaces(run_info.workspaces), "Failed to allocate workspaces");
  195. return SUCCESS;
  196. }
  197. Status TbeOpTask::UpdateTensorDesc(const GeTensorDesc &src_tensor, GeTensorDesc &dst_tensor) {
  198. int64_t storage_format_val = static_cast<Format>(FORMAT_RESERVED);
  199. (void)AttrUtils::GetInt(src_tensor, ge::ATTR_NAME_STORAGE_FORMAT, storage_format_val);
  200. auto storage_format = static_cast<Format>(storage_format_val);
  201. if (storage_format == FORMAT_RESERVED) {
  202. GELOGD("Storage format not set. update shape to [%s], and original shape to [%s]",
  203. src_tensor.GetShape().ToString().c_str(), src_tensor.GetOriginShape().ToString().c_str());
  204. dst_tensor.SetShape(src_tensor.GetShape());
  205. dst_tensor.SetOriginShape(src_tensor.GetOriginShape());
  206. } else {
  207. std::vector<int64_t> storage_shape;
  208. if (!AttrUtils::GetListInt(src_tensor, ge::ATTR_NAME_STORAGE_SHAPE, storage_shape)) {
  209. GELOGE(ACL_ERROR_GE_INTERNAL_ERROR, "Failed to get storage_shape while storage_format was set");
  210. return ACL_ERROR_GE_INTERNAL_ERROR;
  211. }
  212. GELOGD("Storage format set. update shape to [%s], and original shape to [%s]",
  213. GeShape(storage_shape).ToString().c_str(), src_tensor.GetShape().ToString().c_str());
  214. dst_tensor.SetShape(GeShape(std::move(storage_shape)));
  215. dst_tensor.SetOriginShape(src_tensor.GetShape());
  216. }
  217. return SUCCESS;
  218. }
  219. Status TbeOpTask::UpdateNodeByShape(const vector<GeTensorDesc> &input_desc, const vector<GeTensorDesc> &output_desc) {
  220. auto op_desc = node_->GetOpDesc();
  221. GE_CHECK_NOTNULL(op_desc);
  222. // Set runtime shape to node
  223. for (size_t i = 0; i < input_desc.size(); ++i) {
  224. auto tensor_desc = op_desc->MutableInputDesc(i);
  225. auto &runtime_tensor_desc = input_desc[i];
  226. GE_CHECK_NOTNULL(tensor_desc);
  227. GE_CHK_STATUS_RET(UpdateTensorDesc(runtime_tensor_desc, *tensor_desc));
  228. }
  229. for (size_t i = 0; i < output_desc.size(); ++i) {
  230. auto tensor_desc = op_desc->MutableOutputDesc(i);
  231. auto &runtime_tensor_desc = output_desc[i];
  232. GE_CHECK_NOTNULL(tensor_desc);
  233. GE_CHK_STATUS_RET(UpdateTensorDesc(runtime_tensor_desc, *tensor_desc));
  234. }
  235. return SUCCESS;
  236. }
  237. void TbeOpTask::EnableDynamicSupport(const NodePtr &node, void *tiling_buffer, size_t max_tiling_size) {
  238. node_ = node;
  239. tiling_buffer_ = tiling_buffer;
  240. max_tiling_size_ = max_tiling_size;
  241. }
  242. Status TbeOpTask::AllocateWorkspaces(const vector<int64_t> &workspace_sizes) {
  243. static const std::string kPurpose("malloc workspace memory for dynamic op.");
  244. if (workspace_sizes.empty()) {
  245. GELOGD("No need to allocate workspace.");
  246. return SUCCESS;
  247. }
  248. int64_t total_size = 0;
  249. std::vector<int64_t> ws_offsets;
  250. for (auto ws_size : workspace_sizes) {
  251. // alignment and padding should be done in OpParaCalculate
  252. if (CheckInt64AddOverflow(total_size, ws_size) != SUCCESS) {
  253. return ACL_ERROR_GE_INTERNAL_ERROR;
  254. }
  255. ws_offsets.emplace_back(total_size);
  256. total_size += ws_size;
  257. }
  258. GELOGD("Total workspace size is %ld", total_size);
  259. GE_CHECK_NOTNULL(stream_resource_);
  260. auto ws_base = stream_resource_->MallocMemory(kPurpose, static_cast<size_t>(total_size));
  261. if (ws_base == nullptr) {
  262. GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "Failed to allocate memory of size: %ld", total_size);
  263. return ACL_ERROR_GE_MEMORY_ALLOCATION;
  264. }
  265. GELOGD("Done allocating workspace memory successfully.");
  266. for (auto ws_offset : ws_offsets) {
  267. workspaces_.emplace_back(ws_base + ws_offset);
  268. }
  269. return SUCCESS;
  270. }
  271. Status TbeOpTask::LaunchKernel(const vector<GeTensorDesc> &input_desc,
  272. const vector<DataBuffer> &input_buffers,
  273. vector<GeTensorDesc> &output_desc,
  274. vector<DataBuffer> &output_buffers,
  275. rtStream_t stream) {
  276. GE_CHK_STATUS_RET_NOLOG(UpdateRunInfo(input_desc, output_desc));
  277. GELOGD("[%s] Start to launch kernel", node_->GetName().c_str());
  278. std::vector<void *> args;
  279. for (auto &buffer : input_buffers) {
  280. args.emplace_back(buffer.data);
  281. }
  282. for (auto &buffer : output_buffers) {
  283. args.emplace_back(buffer.data);
  284. }
  285. for (auto &buffer : workspaces_) {
  286. args.emplace_back(buffer);
  287. }
  288. if (tiling_buffer_ != nullptr) {
  289. GELOGD("[%s] Start to copy tiling info. size = %zu", node_->GetName().c_str(), tiling_data_.size());
  290. GE_CHK_RT_RET(rtMemcpyAsync(tiling_buffer_, max_tiling_size_, tiling_data_.data(), tiling_data_.size(),
  291. RT_MEMCPY_HOST_TO_DEVICE_EX, stream));
  292. args.emplace_back(tiling_buffer_);
  293. }
  294. if (memcpy_s(args_.get(), arg_size_, args.data(), args.size() * sizeof(void *)) != EOK) {
  295. GELOGE(ACL_ERROR_GE_MEMORY_OPERATE_FAILED, "[%s] Failed to update kernel args.",
  296. node_->GetName().c_str());
  297. return ACL_ERROR_GE_MEMORY_OPERATE_FAILED;
  298. }
  299. GELOGD("[%s] Start to invoke rtKernelLaunch", node_->GetName().c_str());
  300. if (handle_ == nullptr) {
  301. GE_CHK_RT_RET(rtKernelLaunch(stub_func_, block_dim_, args_.get(), arg_size_, nullptr, stream));
  302. GELOGD("[%s] Done invoking rtKernelLaunch successfully", node_->GetName().c_str());
  303. } else {
  304. std::string dev_func = original_kernel_key_ + "_" + std::to_string(tiling_key_);
  305. std::string kernel_info = node_info_ + "/" + std::to_string(tiling_key_);
  306. GE_CHK_RT_RET(rtKernelLaunchWithHandle(handle_, dev_func.c_str(), block_dim_, args_.get(), arg_size_, nullptr,
  307. stream, kernel_info.c_str()));
  308. GELOGD("[%s] Done invoking rtKernelLaunchWithHandle successfully", node_->GetName().c_str());
  309. }
  310. return SUCCESS;
  311. }
  312. void TbeOpTask::GetIoAddr(uintptr_t *&arg_base, size_t &arg_count) {
  313. arg_base = reinterpret_cast<uintptr_t *>(args_.get());
  314. arg_count = arg_size_ / sizeof(void *);
  315. if (tiling_buffer_ != nullptr) {
  316. --arg_count;
  317. }
  318. }
  319. AiCpuBaseTask::~AiCpuBaseTask() {
  320. if (ext_info_addr_dev_ != nullptr) {
  321. (void)rtFree(ext_info_addr_dev_);
  322. }
  323. }
  324. Status AiCpuBaseTask::SetExtInfoAndType(const std::string &kernel_ext_info, uint64_t kernel_id) {
  325. if (kernel_ext_info.empty()) {
  326. GELOGI("Kernel_ext_info is empty, no need copy to device.");
  327. return SUCCESS;
  328. }
  329. int32_t unknown_shape_type_val = 0;
  330. (void) AttrUtils::GetInt(op_desc_, ::ge::ATTR_NAME_UNKNOWN_SHAPE_TYPE, unknown_shape_type_val);
  331. GELOGD("Get unknown_type is %d.", unknown_shape_type_val);
  332. unknown_type_ = static_cast<UnknowShapeOpType>(unknown_shape_type_val);
  333. aicpu_ext_handle_.reset(new(std::nothrow) ::ge::hybrid::AicpuExtInfoHandler(op_desc_->GetName(),
  334. num_inputs_,
  335. num_outputs_,
  336. unknown_type_));
  337. GE_CHK_BOOL_RET_STATUS(aicpu_ext_handle_ != nullptr, ACL_ERROR_GE_MEMORY_ALLOCATION, "Malloc aicpu_ext_handle mem failed!");
  338. Status ret = aicpu_ext_handle_->Parse(kernel_ext_info);
  339. if (ret != SUCCESS) {
  340. GELOGE(ret, "Parse kernel ext info failed, kernel_ext_info_size=%zu.", kernel_ext_info.size());
  341. return ret;
  342. }
  343. GE_CHK_STATUS_RET(aicpu_ext_handle_->UpdateSessionInfo(ULLONG_MAX, kernel_id, false),
  344. "UpdateSessionInfo failed.");
  345. GE_CHK_STATUS_RET(aicpu_ext_handle_->UpdateExecuteMode(true), "UpdateExecuteMode failed.");
  346. GE_CHK_RT_RET(rtMalloc(&ext_info_addr_dev_, aicpu_ext_handle_->GetExtInfoLen(), RT_MEMORY_HBM));
  347. GE_CHK_RT_RET(rtMemcpy(ext_info_addr_dev_, aicpu_ext_handle_->GetExtInfoLen(),
  348. aicpu_ext_handle_->GetExtInfo(), aicpu_ext_handle_->GetExtInfoLen(),
  349. RT_MEMCPY_HOST_TO_DEVICE));
  350. return SUCCESS;
  351. }
  352. Status AiCpuBaseTask::SetInputConst() {
  353. input_is_const_.clear();
  354. const vector<bool> v_is_input_const = op_desc_->GetIsInputConst();
  355. for (size_t i = 0; i < op_desc_->GetAllInputsSize(); ++i) {
  356. const GeTensorDescPtr tensor_desc = op_desc_->MutableInputDesc(static_cast<uint32_t>(i));
  357. if (tensor_desc == nullptr) {
  358. GELOGD("SingleOp: %s, Index: %zu, has no input", op_desc_->GetName().c_str(), i);
  359. continue;
  360. }
  361. if (i < v_is_input_const.size() && v_is_input_const[i]) {
  362. GELOGD("SingleOp: %s, Index: %zu, input is const", op_desc_->GetName().c_str(), i);
  363. input_is_const_.push_back(true);
  364. continue;
  365. }
  366. input_is_const_.push_back(false);
  367. }
  368. return SUCCESS;
  369. }
  370. Status AiCpuBaseTask::UpdateExtInfo(const std::vector<GeTensorDesc> &input_desc,
  371. std::vector<GeTensorDesc> &output_desc,
  372. rtStream_t stream) {
  373. GELOGI("Update ext info begin, unknown_type=%d.", unknown_type_);
  374. GE_CHECK_NOTNULL(aicpu_ext_handle_);
  375. GE_CHK_STATUS_RET(aicpu_ext_handle_->UpdateExecuteMode(false), "UpdateExecuteMode failed.");
  376. if (num_inputs_ == 0 && num_outputs_ == 0) {
  377. GELOGI("No input and output, no need update ext info.");
  378. return SUCCESS;
  379. }
  380. size_t non_const_index = 0;
  381. for (size_t input_index = 0; input_index < num_inputs_; input_index++) {
  382. if (input_index < input_is_const_.size() && input_is_const_[input_index]) {
  383. // get input_desc from op_desc if const input, num_inputs_ is op_desc_ input_size
  384. auto const_input_desc = op_desc_->MutableInputDesc(static_cast<uint32_t>(input_index));
  385. GE_CHECK_NOTNULL(const_input_desc);
  386. GE_CHK_STATUS_RET(aicpu_ext_handle_->UpdateInputShapeAndType(input_index, *const_input_desc),
  387. "Input[%zu] update input shape failed.", input_index);
  388. continue;
  389. }
  390. GE_CHK_BOOL_RET_STATUS(non_const_index < input_desc.size(), ACL_ERROR_GE_PARAM_INVALID,
  391. "Input_desc size is %zu, but get non_const_index is %zu",
  392. input_desc.size(), non_const_index);
  393. GE_CHK_STATUS_RET(aicpu_ext_handle_->UpdateInputShapeAndType(input_index, input_desc[non_const_index]),
  394. "Input[%zu] update input shape failed.", input_index);
  395. non_const_index++;
  396. }
  397. if (unknown_type_ != DEPEND_COMPUTE) {
  398. for (size_t j = 0; j < num_outputs_; ++j) {
  399. GE_CHK_STATUS_RET(aicpu_ext_handle_->UpdateOutputShapeAndType(j, output_desc[j]),
  400. "Output[%zu] UpdateOutputShapeAndType failed.", j);
  401. }
  402. }
  403. GE_CHK_RT_RET(rtMemcpyAsync(ext_info_addr_dev_,
  404. aicpu_ext_handle_->GetExtInfoLen(), // check size
  405. aicpu_ext_handle_->GetExtInfo(),
  406. aicpu_ext_handle_->GetExtInfoLen(),
  407. RT_MEMCPY_HOST_TO_DEVICE_EX,
  408. stream));
  409. GELOGI("Update ext info end.");
  410. return SUCCESS;
  411. }
  412. Status AiCpuBaseTask::UpdateOutputShape(vector<GeTensorDesc> &output_desc) {
  413. if (num_outputs_ == 0) {
  414. GELOGD("AiCpuBaseTask output_num is 0, no need update output shape.");
  415. return SUCCESS;
  416. }
  417. GELOGD("Start to update DEPEND_SHAPE_RANGE AiCpuBaseTask outputshape.");
  418. GE_CHK_RT_RET(rtMemcpy(aicpu_ext_handle_->GetExtInfo(),
  419. aicpu_ext_handle_->GetExtInfoLen(),
  420. ext_info_addr_dev_,
  421. aicpu_ext_handle_->GetExtInfoLen(),
  422. RT_MEMCPY_DEVICE_TO_HOST));
  423. for (size_t i = 0; i < num_outputs_; ++i) {
  424. GeShape shape;
  425. DataType data_type;
  426. aicpu_ext_handle_->GetOutputShapeAndType(i, shape, data_type);
  427. GE_CHK_STATUS_RET(UpdateShapeToOutputDesc(shape, output_desc[i]),
  428. "AiCpuCCTask Update [%zu]th output shape failed.", i);
  429. }
  430. GELOGD("Update DEPEND_SHAPE_RANGE AiCpuBaseTask outputshape finished.");
  431. return SUCCESS;
  432. }
  433. Status AiCpuBaseTask::UpdateShapeToOutputDesc(const GeShape &shape_new, GeTensorDesc &output_desc) {
  434. auto shape_old = output_desc.GetShape();
  435. output_desc.SetShape(shape_new);
  436. GELOGD("Update AiCpuBaseTask shape from %s to %s", shape_old.ToString().c_str(), shape_new.ToString().c_str());
  437. auto origin_shape_old = output_desc.GetOriginShape();
  438. auto origin_format = output_desc.GetOriginFormat();
  439. auto format = output_desc.GetFormat();
  440. if (origin_format == format) {
  441. output_desc.SetOriginShape(shape_new);
  442. return SUCCESS;
  443. }
  444. std::vector<int64_t> origin_dims_new;
  445. auto trans_ret = formats::TransShape(format, shape_new.GetDims(),
  446. output_desc.GetDataType(), origin_format, origin_dims_new);
  447. GE_CHK_STATUS_RET(trans_ret,
  448. "AiCpuTask originFormat[%d] is not same as format[%d], but TransShape failed, shape=%s.",
  449. origin_format, format, shape_new.ToString().c_str());
  450. auto origin_shape_new = GeShape(origin_dims_new);
  451. output_desc.SetOriginShape(origin_shape_new);
  452. GELOGD("AiCpuTask originFormat[%d] is not same as format[%d], need update from %s ro %s.",
  453. origin_format, format, origin_shape_old.ToString().c_str(), origin_shape_new.ToString().c_str());
  454. return SUCCESS;
  455. }
  456. Status AiCpuBaseTask::UpdateIoAddr(const vector<DataBuffer> &inputs, const vector<DataBuffer> &outputs) {
  457. uintptr_t *arg_base = nullptr;
  458. size_t arg_num = 0;
  459. GetIoAddr(arg_base, arg_num);
  460. // input number and output number was check in ValidateParams
  461. size_t non_const_index = 0;
  462. for (size_t input_index = 0; input_index < num_inputs_; input_index++) {
  463. if (input_index < input_is_const_.size() && input_is_const_[input_index]) {
  464. // const input no need update addr
  465. GE_CHECK_NOTNULL(arg_base);
  466. GELOGD("AICpuTask input[%zu] addr = %lu", input_index, *arg_base);
  467. arg_base++;
  468. continue;
  469. }
  470. GE_CHK_BOOL_RET_STATUS(non_const_index < inputs.size(), ACL_ERROR_GE_PARAM_INVALID,
  471. "Input size is %zu, but get non_const_index is %zu",
  472. inputs.size(), non_const_index);
  473. auto addr = inputs[non_const_index].data;
  474. GE_CHECK_NOTNULL(addr);
  475. GELOGD("AICpuTask input[%zu] addr = %p", input_index, addr);
  476. *arg_base++ = reinterpret_cast<uintptr_t>(addr);
  477. non_const_index++;
  478. }
  479. for (size_t i = 0; i < outputs.size(); ++i) {
  480. auto addr = outputs[i].data;
  481. GE_CHECK_NOTNULL(addr);
  482. GELOGD("AICpuTask output[%zu] addr = %p", i, addr);
  483. *arg_base++ = reinterpret_cast<uintptr_t>(addr);
  484. }
  485. return SUCCESS;
  486. }
  487. AiCpuTask::~AiCpuTask() {
  488. FreeHbm(args_);
  489. FreeHbm(io_addr_);
  490. if (dynamic_flag_) {
  491. FreeHbm(workspace_addr_);
  492. }
  493. FreeHbm(copy_workspace_buf_);
  494. FreeHbm(copy_ioaddr_dev_);
  495. FreeHbm(copy_input_release_flag_dev_);
  496. FreeHbm(copy_input_data_size_dev_);
  497. FreeHbm(copy_input_src_dev_);
  498. FreeHbm(copy_input_dst_dev_);
  499. FreeHbm(copy_task_args_buf_);
  500. for (auto summary : output_summary_) {
  501. FreeHbm(summary);
  502. }
  503. for (auto out_shape : out_shape_hbm_) {
  504. FreeHbm(out_shape);
  505. }
  506. }
  507. Status AiCpuTask::LaunchKernel(rtStream_t stream) {
  508. GELOGD("Start to launch kernel. task = %s", this->op_type_.c_str());
  509. auto ret = rtMemcpyAsync(io_addr_,
  510. io_addr_size_,
  511. io_addr_host_.data(),
  512. io_addr_host_.size() * sizeof(void *),
  513. RT_MEMCPY_HOST_TO_DEVICE_EX,
  514. stream);
  515. if (ret != RT_ERROR_NONE) {
  516. GELOGE(ret, "rtMemcpyAsync workspace data failed. ret = %d, task = %s", ret, this->op_type_.c_str());
  517. return RT_ERROR_TO_GE_STATUS(ret);
  518. }
  519. GELOGI("To invoke rtKernelLaunchEx. task = %s", this->op_type_.c_str());
  520. ret = rtKernelLaunchEx(args_, arg_size_, 0, stream);
  521. if (ret != RT_ERROR_NONE) {
  522. GELOGE(ret, "Invoke rtKernelLaunch failed. ret = %d, task = %s", ret, this->op_type_.c_str());
  523. return RT_ERROR_TO_GE_STATUS(ret);
  524. }
  525. GELOGI("[TASK_INFO] %lu/%s", kernel_id_, op_type_.c_str());
  526. auto status = OpenDump(stream);
  527. if (status != SUCCESS) {
  528. GELOGE(status, "Open dump failed in aicpu single op %s", this->op_type_.c_str());
  529. return status;
  530. }
  531. GELOGD("Done launch kernel successfully. task = %s", this->op_type_.c_str());
  532. return SUCCESS;
  533. }
  534. Status AiCpuTask::PrepareCopyInputs(vector<DataBuffer> &outputs) {
  535. std::vector<uint64_t> copy_input_release_flag;
  536. std::vector<uint64_t> copy_input_data_size;
  537. std::vector<uint64_t> copy_input_src;
  538. std::vector<uint64_t> copy_input_dst;
  539. for (size_t i = 0; i < num_outputs_; ++i) {
  540. const auto &summary = output_summary_host_[i];
  541. GELOGI("Node out[%zu] summary, shape data=0x%lx, shape data size=%lu, raw data=0x%lx, raw data size=%lu.",
  542. i, summary.shape_data_ptr, summary.shape_data_size,
  543. summary.raw_data_ptr, summary.raw_data_size);
  544. auto output = outputs[i];
  545. copy_input_release_flag.emplace_back(kReleaseFlag);
  546. if (summary.raw_data_size > 0) {
  547. copy_input_data_size.emplace_back(output.length);
  548. } else {
  549. copy_input_data_size.emplace_back(summary.raw_data_size);
  550. }
  551. copy_input_src.emplace_back(summary.raw_data_ptr);
  552. copy_input_dst.emplace_back(reinterpret_cast<uintptr_t>(output.data));
  553. const auto &shape_buffer = out_shape_hbm_[i];
  554. copy_input_release_flag.emplace_back(kReleaseFlag);
  555. copy_input_data_size.emplace_back(summary.shape_data_size);
  556. copy_input_src.emplace_back(summary.shape_data_ptr);
  557. copy_input_dst.emplace_back(reinterpret_cast<uintptr_t>(shape_buffer));
  558. }
  559. const size_t copy_input_buf_len = num_outputs_ * kCopyNum * sizeof(uint64_t);
  560. GE_CHK_RT_RET(rtMemcpy(copy_input_release_flag_dev_, copy_input_buf_len,
  561. copy_input_release_flag.data(), copy_input_buf_len, RT_MEMCPY_HOST_TO_DEVICE));
  562. GE_CHK_RT_RET(rtMemcpy(copy_input_data_size_dev_, copy_input_buf_len,
  563. copy_input_data_size.data(), copy_input_buf_len, RT_MEMCPY_HOST_TO_DEVICE));
  564. GE_CHK_RT_RET(rtMemcpy(copy_input_src_dev_, copy_input_buf_len,
  565. copy_input_src.data(), copy_input_buf_len, RT_MEMCPY_HOST_TO_DEVICE));
  566. GE_CHK_RT_RET(rtMemcpy(copy_input_dst_dev_, copy_input_buf_len,
  567. copy_input_dst.data(), copy_input_buf_len, RT_MEMCPY_HOST_TO_DEVICE));
  568. return SUCCESS;
  569. }
  570. Status AiCpuTask::ReadResultSummaryAndPrepareMemory() {
  571. for (size_t i = 0; i < num_outputs_; ++i) {
  572. auto &result_summary = output_summary_host_[i];
  573. GE_CHK_RT_RET(rtMemcpy(&result_summary, sizeof(aicpu::FWKAdapter::ResultSummary),
  574. output_summary_[i], sizeof(aicpu::FWKAdapter::ResultSummary),
  575. RT_MEMCPY_DEVICE_TO_HOST));
  576. auto shape_data_size = result_summary.shape_data_size;
  577. void *shape_buffer = nullptr;
  578. if (shape_data_size > 0) {
  579. GE_CHK_RT_RET(rtMalloc(&shape_buffer, shape_data_size, RT_MEMORY_HBM));
  580. }
  581. out_shape_hbm_.emplace_back(shape_buffer);
  582. }
  583. return SUCCESS;
  584. }
  585. Status AiCpuTask::CopyDataToHbm(vector<DataBuffer> &outputs,
  586. rtStream_t stream) {
  587. GE_CHK_STATUS_RET_NOLOG(PrepareCopyInputs(outputs));
  588. GE_CHK_RT_RET(rtKernelLaunchEx(copy_task_args_buf_, sizeof(STR_FWK_OP_KERNEL),
  589. RT_KERNEL_DEFAULT, stream));
  590. GE_CHK_RT_RET(rtStreamSynchronize(stream));
  591. return SUCCESS;
  592. }
  593. Status AiCpuTask::UpdateShapeByHbmBuffer(vector<GeTensorDesc> &output_desc) {
  594. for (size_t i = 0; i < num_outputs_; ++i) {
  595. const auto &result_summary = output_summary_host_[i];
  596. std::vector<int64_t> shape_dims;
  597. if (result_summary.shape_data_size > 0) {
  598. const auto &shape_hbm = out_shape_hbm_[i];
  599. uint32_t dim_num = result_summary.shape_data_size / sizeof(int64_t);
  600. std::unique_ptr<int64_t[]> shape_addr(new(std::nothrow) int64_t[dim_num]());
  601. GE_CHECK_NOTNULL(shape_addr);
  602. GE_CHK_RT_RET(rtMemcpy(shape_addr.get(), result_summary.shape_data_size,
  603. shape_hbm, result_summary.shape_data_size, RT_MEMCPY_DEVICE_TO_HOST));
  604. for (uint32_t dim_idx = 0; dim_idx < dim_num; ++dim_idx) {
  605. shape_dims.emplace_back(shape_addr[dim_idx]);
  606. GELOGD("Node [%zu]th output dim[%u]=%ld.", i, dim_idx, shape_addr[dim_idx]);
  607. }
  608. }
  609. GE_CHK_STATUS_RET(UpdateShapeToOutputDesc(GeShape(shape_dims), output_desc[i]),
  610. "AiCpuTask update [%zu]th output shape failed.", i);
  611. }
  612. return SUCCESS;
  613. }
  614. Status AiCpuTask::UpdateShapeAndDataByResultSummary(vector<GeTensorDesc> &output_desc,
  615. vector<DataBuffer> &outputs,
  616. rtStream_t stream) {
  617. if (num_outputs_ == 0) {
  618. GELOGI("Output num is 0, there is no need to update the output and size.");
  619. return SUCCESS;
  620. }
  621. GELOGI("Update shape and data by result summary begin.");
  622. for (auto out_shape : out_shape_hbm_) {
  623. FreeHbm(out_shape);
  624. }
  625. out_shape_hbm_.clear();
  626. GE_CHK_STATUS_RET(ReadResultSummaryAndPrepareMemory(),
  627. "Read ResultSummary and update output shape failed.");
  628. GE_CHK_STATUS_RET(CopyDataToHbm(outputs, stream),
  629. "Copy data to output failed.");
  630. GE_CHK_STATUS_RET(UpdateShapeByHbmBuffer(output_desc),
  631. "Update shape by hbm buffer failed.");
  632. for (auto out_shape : out_shape_hbm_) {
  633. FreeHbm(out_shape);
  634. }
  635. out_shape_hbm_.clear();
  636. GELOGI("Update shape and data by result summary end.");
  637. return SUCCESS;
  638. }
  639. Status AiCpuTask::InitForSummaryAndCopy() {
  640. if (unknown_type_ != DEPEND_COMPUTE || num_outputs_ == 0) {
  641. GELOGI("Unknown_type is %d, output num is %zu.", unknown_type_, num_outputs_);
  642. return SUCCESS;
  643. }
  644. output_summary_.resize(num_outputs_);
  645. constexpr auto result_summary_size = sizeof(aicpu::FWKAdapter::ResultSummary);
  646. for (size_t i = 0; i < num_outputs_; ++i) {
  647. GE_CHK_RT_RET(rtMalloc(&output_summary_[i], result_summary_size, RT_MEMORY_HBM));
  648. }
  649. output_summary_host_.resize(num_outputs_);
  650. const size_t copy_input_buf_len = num_outputs_ * kCopyNum * sizeof(uint64_t);
  651. GE_CHK_RT_RET(rtMalloc(&copy_input_release_flag_dev_, copy_input_buf_len, RT_MEMORY_HBM));
  652. GE_CHK_RT_RET(rtMalloc(&copy_input_data_size_dev_, copy_input_buf_len, RT_MEMORY_HBM));
  653. GE_CHK_RT_RET(rtMalloc(&copy_input_src_dev_, copy_input_buf_len, RT_MEMORY_HBM));
  654. GE_CHK_RT_RET(rtMalloc(&copy_input_dst_dev_, copy_input_buf_len, RT_MEMORY_HBM));
  655. GE_CHK_RT_RET(rtMalloc(&copy_task_args_buf_, sizeof(STR_FWK_OP_KERNEL), RT_MEMORY_HBM));
  656. std::vector<uint64_t> copy_io_addr;
  657. copy_io_addr.emplace_back(reinterpret_cast<uintptr_t>(copy_input_release_flag_dev_));
  658. copy_io_addr.emplace_back(reinterpret_cast<uintptr_t>(copy_input_data_size_dev_));
  659. copy_io_addr.emplace_back(reinterpret_cast<uintptr_t>(copy_input_src_dev_));
  660. copy_io_addr.emplace_back(reinterpret_cast<uintptr_t>(copy_input_dst_dev_));
  661. const auto copy_io_addr_size = sizeof(uint64_t) * copy_io_addr.size();
  662. GE_CHK_RT_RET(rtMalloc(&copy_ioaddr_dev_, copy_io_addr_size, RT_MEMORY_HBM));
  663. GE_CHK_RT_RET(rtMemcpy(copy_ioaddr_dev_, copy_io_addr_size,
  664. copy_io_addr.data(), copy_io_addr_size, RT_MEMCPY_HOST_TO_DEVICE));
  665. return SUCCESS;
  666. }
  667. Status AiCpuTask::SetMemCopyTask(const domi::KernelExDef &kernel_def) {
  668. if (kernel_def.args_size() > sizeof(STR_FWK_OP_KERNEL)) {
  669. GELOGE(ACL_ERROR_GE_PARAM_INVALID, "sizeof STR_FWK_OP_KERNEL is: %lu, but args_size is: %d",
  670. sizeof(STR_FWK_OP_KERNEL), kernel_def.args_size());
  671. return ACL_ERROR_GE_PARAM_INVALID;
  672. }
  673. GE_CHK_RT_RET(rtMalloc(&copy_workspace_buf_, kernel_def.task_info_size(), RT_MEMORY_HBM));
  674. GE_CHK_RT_RET(rtMemcpy(copy_workspace_buf_, kernel_def.task_info_size(),
  675. kernel_def.task_info().data(), kernel_def.task_info_size(), RT_MEMCPY_HOST_TO_DEVICE));
  676. STR_FWK_OP_KERNEL aicpu_task = {0};
  677. auto sec_ret = memcpy_s(&aicpu_task, sizeof(STR_FWK_OP_KERNEL),
  678. kernel_def.args().data(), kernel_def.args().size());
  679. if (sec_ret != EOK) {
  680. GELOGE(ACL_ERROR_GE_MEMORY_OPERATE_FAILED, "memcpy failed, ret: %d", sec_ret);
  681. return ACL_ERROR_GE_MEMORY_OPERATE_FAILED;
  682. }
  683. aicpu_task.fwkKernelBase.fwk_kernel.inputOutputAddr = reinterpret_cast<uintptr_t>(copy_ioaddr_dev_);
  684. aicpu_task.fwkKernelBase.fwk_kernel.workspaceBaseAddr = reinterpret_cast<uintptr_t>(copy_workspace_buf_);
  685. aicpu_task.fwkKernelBase.fwk_kernel.extInfoAddr = 0;
  686. aicpu_task.fwkKernelBase.fwk_kernel.extInfoLen = 0;
  687. GE_CHK_RT_RET(rtMemcpy(copy_task_args_buf_, sizeof(STR_FWK_OP_KERNEL),
  688. &aicpu_task, sizeof(STR_FWK_OP_KERNEL), RT_MEMCPY_HOST_TO_DEVICE));
  689. return SUCCESS;
  690. }
  691. Status AiCpuTask::LaunchKernel(const std::vector<GeTensorDesc> &input_desc,
  692. const std::vector<DataBuffer> &input_buffers,
  693. std::vector<GeTensorDesc> &output_desc,
  694. std::vector<DataBuffer> &output_buffers,
  695. rtStream_t stream) {
  696. GE_CHK_STATUS_RET_NOLOG(UpdateExtInfo(input_desc, output_desc, stream));
  697. if (unknown_type_ == DEPEND_COMPUTE) {
  698. std::vector<DataBuffer> summary_buffers;
  699. for (size_t i = 0; i < num_outputs_; ++i) {
  700. summary_buffers.emplace_back(output_summary_[i], sizeof(aicpu::FWKAdapter::ResultSummary), false);
  701. }
  702. GE_CHK_STATUS_RET_NOLOG(UpdateIoAddr(input_buffers, summary_buffers));
  703. } else {
  704. GE_CHK_STATUS_RET_NOLOG(UpdateIoAddr(input_buffers, output_buffers));
  705. }
  706. GE_CHK_STATUS_RET_NOLOG(LaunchKernel(stream));
  707. if (unknown_type_ == DEPEND_SHAPE_RANGE) {
  708. GE_CHK_RT_RET(rtStreamSynchronize(stream));
  709. GE_CHK_STATUS_RET_NOLOG(UpdateOutputShape(output_desc));
  710. } else if (unknown_type_ == DEPEND_COMPUTE) {
  711. GE_CHK_RT_RET(rtStreamSynchronize(stream));
  712. GE_CHK_STATUS_RET_NOLOG(UpdateShapeAndDataByResultSummary(output_desc, output_buffers, stream));
  713. }
  714. return SUCCESS;
  715. }
  716. Status AiCpuBaseTask::UpdateArgTable(const SingleOpModelParam &param) {
  717. // aicpu do not have workspace, for now
  718. return DoUpdateArgTable(param, false);
  719. }
  720. uint32_t AiCpuBaseTask::GetTaskType() const { return kTaskTypeAicpu; }
  721. void AiCpuTask::GetIoAddr(uintptr_t *&arg_base, size_t &arg_count) {
  722. arg_base = reinterpret_cast<uintptr_t *>(io_addr_host_.data());
  723. arg_count = io_addr_host_.size();
  724. }
  725. void AiCpuCCTask::SetKernelArgs(std::unique_ptr<uint8_t[]> args, size_t arg_size) {
  726. args_ = std::move(args);
  727. arg_size_ = arg_size;
  728. // The blockdim value is defult "1" for rtCpuKernelLaunch
  729. block_dim_ = 1;
  730. }
  731. void AiCpuCCTask::SetSoName(const std::string &so_name) { so_name_ = so_name; }
  732. void AiCpuCCTask::SetkernelName(const std::string &kernel_Name) { kernel_name_ = kernel_Name; }
  733. void AiCpuCCTask::SetIoAddr(uintptr_t *io_addr) { io_addr_ = io_addr; }
  734. const void *AiCpuCCTask::GetArgs() const { return args_.get(); }
  735. size_t AiCpuCCTask::GetArgSize() const { return arg_size_; }
  736. AiCpuCCTask::~AiCpuCCTask() {
  737. }
  738. Status AiCpuCCTask::LaunchKernel(rtStream_t stream) {
  739. GELOGI("To invoke rtCpuKernelLaunch. block_dim = %u, so_name is %s, kernel_name is %s", block_dim_, so_name_.data(),
  740. kernel_name_.data());
  741. // sm_desc is nullptr, because l2 buffer does not support
  742. auto *sm_desc = reinterpret_cast<rtSmDesc_t *>(sm_desc_);
  743. auto ret = rtCpuKernelLaunchWithFlag(static_cast<const void *>(so_name_.data()),
  744. static_cast<const void *>(kernel_name_.data()),
  745. block_dim_, args_.get(), static_cast<uint32_t>(arg_size_),
  746. sm_desc, stream, dump_flag_);
  747. if (ret != RT_ERROR_NONE) {
  748. GELOGE(ret, "Invoke rtCpuKernelLaunch failed. ret = %d", ret);
  749. return RT_ERROR_TO_GE_STATUS(ret);
  750. }
  751. GELOGI("[TASK_INFO] %lu/%s", kernel_id_, op_type_.c_str());
  752. GELOGD("Invoke rtCpuKernelLaunch succeeded");
  753. auto status = OpenDump(stream);
  754. if (status != SUCCESS) {
  755. GELOGE(status, "Open dump failed in the aicpucc single op %s", this->kernel_name_.c_str());
  756. return status;
  757. }
  758. return SUCCESS;
  759. }
  760. Status AiCpuCCTask::LaunchKernel(const std::vector<GeTensorDesc> &input_desc,
  761. const std::vector<DataBuffer> &input_buffers,
  762. std::vector<GeTensorDesc> &output_desc,
  763. std::vector<DataBuffer> &output_buffers,
  764. rtStream_t stream) {
  765. GE_CHK_STATUS_RET_NOLOG(UpdateExtInfo(input_desc, output_desc, stream));
  766. GE_CHK_STATUS_RET_NOLOG(UpdateIoAddr(input_buffers, output_buffers));
  767. GE_CHK_STATUS_RET_NOLOG(LaunchKernel(stream));
  768. if (unknown_type_ == DEPEND_SHAPE_RANGE) {
  769. GE_CHK_RT_RET(rtStreamSynchronize(stream));
  770. GE_CHK_STATUS_RET_NOLOG(UpdateOutputShape(output_desc));
  771. }
  772. return SUCCESS;
  773. }
  774. void AiCpuCCTask::GetIoAddr(uintptr_t *&arg_base, size_t &arg_count) {
  775. arg_base = io_addr_;
  776. arg_count = io_addr_num_;
  777. }
  778. } // namespace ge

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