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.

ge_executor.cc 38 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
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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056
  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 "executor/ge_executor.h"
  17. #include <cce/cce.h>
  18. #include <cce/compiler_stub.h>
  19. #include <ctime>
  20. #include <iostream>
  21. #include "common/debug/log.h"
  22. #include "common/ge/ge_util.h"
  23. #include "common/helper/model_helper.h"
  24. #include "common/profiling/profiling_manager.h"
  25. #include "common/dump/dump_manager.h"
  26. #include "common/util.h"
  27. #include "framework/common/debug/ge_log.h"
  28. #include "framework/common/util.h"
  29. #include "graph/execute/graph_execute.h"
  30. #include "graph/load/graph_loader.h"
  31. #include "graph/load/new_model_manager/davinci_model_parser.h"
  32. #include "graph/load/new_model_manager/model_manager.h"
  33. #include "graph/manager/graph_mem_allocator.h"
  34. #include "graph/model.h"
  35. #include "graph/utils/graph_utils.h"
  36. #include "mmpa/mmpa_api.h"
  37. #include "single_op/single_op_manager.h"
  38. #include "graph/manager/graph_var_manager.h"
  39. #include "graph/load/new_model_manager/davinci_model.h"
  40. using std::string;
  41. using std::vector;
  42. namespace {
  43. const size_t kDynamicBatchSizeVecSize = 1;
  44. const size_t kStaticBatchInfoSize = 1;
  45. const size_t kDynamicImageSizeVecSize = 2;
  46. const size_t kDynamicImageSizeInputSize = 2;
  47. const char *const kBatchLabel = "Batch_";
  48. ge::Status TransferDomiErrorCode(const uint32_t errorCode) {
  49. switch (errorCode) {
  50. case ge::PARAM_INVALID:
  51. case domi::PARAM_INVALID:
  52. return ge::PARAM_INVALID;
  53. case ge::INTERNAL_ERROR:
  54. case domi::INTERNAL_ERROR:
  55. return ge::INTERNAL_ERROR;
  56. default:
  57. return ge::FAILED;
  58. }
  59. }
  60. void GetGeTensorDescFromDomiInfo(std::vector<ge::TensorDesc> &ge_descs,
  61. const std::vector<ge::InputOutputDescInfo> &domi_descs,
  62. const std::vector<uint32_t> &formats) {
  63. uint32_t idx = 0;
  64. for (auto desc_item : domi_descs) {
  65. ge::TensorDesc ge_desc;
  66. ge_desc.SetName(desc_item.name);
  67. ge_desc.SetDataType(static_cast<ge::DataType>(desc_item.data_type));
  68. ge_desc.SetFormat(static_cast<ge::Format>(formats[idx]));
  69. std::vector<int64_t> shape_dims;
  70. for (auto dim : desc_item.shape_info.dims) {
  71. shape_dims.push_back(dim);
  72. }
  73. ge::Shape ge_shape(shape_dims);
  74. ge_desc.SetShape(ge_shape);
  75. ge_desc.SetSize(desc_item.size);
  76. ge_descs.emplace_back(ge_desc);
  77. ++idx;
  78. }
  79. }
  80. void GetDomiInputData(const ge::RunModelData &input_data, ge::InputData &inputs) {
  81. inputs.index = input_data.index;
  82. inputs.model_id = input_data.modelId;
  83. inputs.timestamp = input_data.timestamp;
  84. inputs.timeout = input_data.timeout;
  85. inputs.request_id = input_data.request_id;
  86. for (const auto &data_item : input_data.blobs) {
  87. ge::DataBuffer dataBuf{data_item.data, data_item.length, data_item.isDataSupportMemShare};
  88. inputs.blobs.emplace_back(dataBuf);
  89. }
  90. }
  91. void GetDomiOutputData(const ge::RunModelData &output_data, ge::OutputData &outputs) {
  92. outputs.index = output_data.index;
  93. outputs.model_id = output_data.modelId;
  94. for (const auto &data_item : output_data.blobs) {
  95. ge::DataBuffer dataBuf(data_item.data, data_item.length, data_item.isDataSupportMemShare);
  96. outputs.blobs.emplace_back(dataBuf);
  97. }
  98. }
  99. void SetDynamicInputDataFlag(const ge::RunModelData &input_data, const std::vector<std::vector<int64_t>> batch_info,
  100. ge::InputData &inputs) {
  101. inputs.is_dynamic_batch = true;
  102. std::string batch_label;
  103. size_t match_idx = 0;
  104. for (size_t i = 0; i < batch_info.size(); ++i) {
  105. // dynamic_dims
  106. if (input_data.dynamic_dims.size() != 0) {
  107. bool is_match = true;
  108. for (size_t j = 0; j < static_cast<size_t>(input_data.dynamic_dims.size()); ++j) {
  109. if (static_cast<uint64_t>(batch_info[i][j]) != input_data.dynamic_dims[j]) {
  110. is_match = false;
  111. break;
  112. }
  113. }
  114. if (is_match) {
  115. match_idx = i;
  116. break;
  117. }
  118. // dynamic_batch_size
  119. } else if (batch_info[i].size() == kDynamicBatchSizeVecSize &&
  120. batch_info[i][0] == static_cast<int64_t>(input_data.dynamic_batch_size)) {
  121. match_idx = i;
  122. break;
  123. // dynamic_image_size
  124. } else if (batch_info[i].size() == kDynamicImageSizeVecSize &&
  125. batch_info[i][0] == static_cast<int64_t>(input_data.dynamic_image_height) &&
  126. batch_info[i][1] == static_cast<int64_t>(input_data.dynamic_image_width)) {
  127. match_idx = i;
  128. break;
  129. }
  130. }
  131. batch_label = kBatchLabel + std::to_string(match_idx);
  132. inputs.batch_label = batch_label;
  133. GELOGI("current batch label:%s", batch_label.c_str());
  134. }
  135. bool IsDynamicBatchSizeMatchModel(uint64_t batch_size, const vector<std::vector<int64_t>> &batch_info) {
  136. if (batch_info.empty()) {
  137. GELOGE(ge::FAILED, "Dynamic batch info is empty.");
  138. return false;
  139. }
  140. for (auto batch : batch_info) {
  141. if (batch.size() != kDynamicBatchSizeVecSize) {
  142. GELOGE(ge::FAILED, "Dynamic batch param num is %zu, current batch size is %zu.", kDynamicBatchSizeVecSize,
  143. batch.size());
  144. return false;
  145. }
  146. if (batch[0] == static_cast<int64_t>(batch_size)) {
  147. return true;
  148. }
  149. }
  150. GELOGE(ge::FAILED, "Dynamic batch %lu can not match the gear of model.", batch_size);
  151. return false;
  152. }
  153. bool IsDynamicImageSizeMatchModel(uint64_t image_height, uint64_t image_width,
  154. const vector<std::vector<int64_t>> &batch_info) {
  155. if (batch_info.empty()) {
  156. GELOGE(ge::FAILED, "Dynamic batch info is empty.");
  157. return false;
  158. }
  159. for (auto resolution : batch_info) {
  160. if (resolution.size() != kDynamicImageSizeVecSize) {
  161. GELOGE(ge::FAILED, "Dynamic resolution param num is %zu, current resolution size is %zu.",
  162. kDynamicImageSizeVecSize, resolution.size());
  163. return false;
  164. }
  165. if (resolution[0] == static_cast<int64_t>(image_height) && resolution[1] == static_cast<int64_t>(image_width)) {
  166. return true;
  167. }
  168. }
  169. GELOGE(ge::FAILED, "Dynamic resolution (%lu,%lu) can not match the gear of model.", image_height, image_width);
  170. return false;
  171. }
  172. } // namespace
  173. namespace ge {
  174. bool GeExecutor::isInit_ = false;
  175. class ModelListenerAdapter : public ModelListener {
  176. public:
  177. domi::Status OnComputeDone(uint32_t model_id, uint32_t dataIndex, uint32_t resultCode,
  178. std::vector<ge::OutputTensorInfo> &outputs) {
  179. if (listener == nullptr) {
  180. GELOGE(ge::FAILED, "listener is null.");
  181. return FAILED;
  182. }
  183. return listener->OnComputeDone(model_id, dataIndex, resultCode, outputs);
  184. }
  185. std::shared_ptr<ge::ModelListener> listener;
  186. };
  187. GeExecutor::GeExecutor() {}
  188. Status GeExecutor::Initialize() {
  189. GELOGI("Init GeExecutor begin.");
  190. if (isInit_) {
  191. GELOGW("Already initialized, no need to be initialized again.");
  192. return ge::SUCCESS;
  193. }
  194. std::vector<rtMemType_t> mem_type(1, RT_MEMORY_HBM);
  195. auto ret = MemManager::Instance().Initialize(mem_type);
  196. if (ret != SUCCESS) {
  197. GELOGE(ret, "Memory Manager init failed.");
  198. return ret;
  199. }
  200. // Start profiling
  201. Options profiling_options;
  202. profiling_options.device_id = 0;
  203. profiling_options.job_id = "";
  204. ProfilingManager::Instance().Init(profiling_options);
  205. isInit_ = true;
  206. GELOGI("Init GeExecutor over.");
  207. return ge::SUCCESS;
  208. }
  209. Status GeExecutor::Finalize() {
  210. GELOGI("Uninit GeExecutor begin.");
  211. if (isInit_ == false) {
  212. GELOGW("GeExecutor has not been initialized.");
  213. return ge::SUCCESS;
  214. }
  215. // Stop profiling
  216. if (ProfilingManager::Instance().ProfilingOn()) {
  217. ProfilingManager::Instance().StopProfiling();
  218. ProfilingManager::Instance().PluginUnInit(GE_PROFILING_MODULE);
  219. }
  220. GELOGI("Uninit GeExecutor over.");
  221. return ge::SUCCESS;
  222. }
  223. Status GeExecutor::SetDynamicBatchSize(uint32_t model_id, void *dynamic_input_addr, uint64_t length,
  224. uint64_t batch_size) {
  225. if (dynamic_input_addr == nullptr) {
  226. GELOGE(PARAM_INVALID, "Dynamic input addr is nullptr!");
  227. return PARAM_INVALID;
  228. }
  229. uint64_t size = sizeof(uint64_t);
  230. if (length < size) {
  231. GELOGE(PARAM_INVALID, "Dynamic input size [%lu] is less than [%lu]!", length, size);
  232. return PARAM_INVALID;
  233. }
  234. // Verify whether the input dynamic batch matches the model gear
  235. std::vector<std::vector<int64_t>> batch_info;
  236. std::vector<uint64_t> batch_num{batch_size};
  237. int32_t dynamic_type = static_cast<int32_t>(FIXED);
  238. Status ret = GraphExecutor::GetDynamicBatchInfo(model_id, batch_info, dynamic_type);
  239. if (ret != SUCCESS) {
  240. GELOGE(ret, "Get dynamic input info failed.");
  241. return ret;
  242. }
  243. if (!IsDynamicBatchSizeMatchModel(batch_size, batch_info)) {
  244. GELOGE(PARAM_INVALID, "The current dynamic input does not match the gear of the model.");
  245. return PARAM_INVALID;
  246. }
  247. ret = GraphExecutor::SetDynamicSize(model_id, batch_num, static_cast<int32_t>(DYNAMIC_BATCH));
  248. if (ret != SUCCESS) {
  249. GELOGE(ret, "Set dynamic size failed");
  250. return ret;
  251. }
  252. // memcpy dynamic_batch_size from host to device
  253. rtError_t rt_ret = rtMemcpy(dynamic_input_addr, length, &batch_size, size, RT_MEMCPY_HOST_TO_DEVICE);
  254. if (rt_ret != RT_ERROR_NONE) {
  255. GELOGE(RT_FAILED, "memcpy dynamic batch input data failed! ret: 0x%X", rt_ret);
  256. return RT_ERROR_TO_GE_STATUS(rt_ret);
  257. }
  258. return SUCCESS;
  259. }
  260. Status GeExecutor::SetDynamicImageSize(uint32_t model_id, void *dynamic_input_addr, uint64_t length,
  261. uint64_t image_height, uint64_t image_width) {
  262. if (dynamic_input_addr == nullptr) {
  263. GELOGE(PARAM_INVALID, "Dynamic input addr is nullptr!");
  264. return PARAM_INVALID;
  265. }
  266. uint64_t dynamic_input_size = kDynamicImageSizeInputSize * sizeof(uint64_t);
  267. if (length < dynamic_input_size) {
  268. GELOGE(PARAM_INVALID, "Dynamic input size [%lu] is less than [%lu]!", length, dynamic_input_size);
  269. return PARAM_INVALID;
  270. }
  271. // Verify whether the input dynamic resolution matches the model gear
  272. std::vector<std::vector<int64_t>> batch_info;
  273. std::vector<uint64_t> batch_num{image_height, image_width};
  274. int32_t dynamic_type = static_cast<int32_t>(FIXED);
  275. Status ret = GraphExecutor::GetDynamicBatchInfo(model_id, batch_info, dynamic_type);
  276. if (ret != SUCCESS) {
  277. GELOGE(ret, "Get dynamic input info failed.");
  278. return ret;
  279. }
  280. if (!IsDynamicImageSizeMatchModel(image_height, image_width, batch_info)) {
  281. GELOGE(PARAM_INVALID, "The current dynamic input does not match the gear of the model.");
  282. return PARAM_INVALID;
  283. }
  284. ret = GraphExecutor::SetDynamicSize(model_id, batch_num, static_cast<int32_t>(DYNAMIC_IMAGE));
  285. if (ret != SUCCESS) {
  286. GELOGE(ret, "Set dynamic size failed");
  287. return ret;
  288. }
  289. // Memcpy dynamic resolution height from host to device
  290. rtError_t rt_ret =
  291. rtMemcpy(dynamic_input_addr, sizeof(uint64_t), &image_height, sizeof(uint64_t), RT_MEMCPY_HOST_TO_DEVICE);
  292. if (rt_ret != RT_ERROR_NONE) {
  293. GELOGE(RT_FAILED, "memcpy dynamic resolution input data failed! ret: 0x%X", rt_ret);
  294. return RT_ERROR_TO_GE_STATUS(rt_ret);
  295. }
  296. uint64_t remain_size = length - sizeof(uint64_t);
  297. // Memcpy dynamic resolution width from host to device
  298. if (rtMemcpy(reinterpret_cast<void *>(reinterpret_cast<uint8_t *>(dynamic_input_addr) + sizeof(uint64_t)),
  299. remain_size, &image_width, sizeof(uint64_t), RT_MEMCPY_HOST_TO_DEVICE) != RT_ERROR_NONE) {
  300. GELOGE(FAILED, "memcpy dynamic resolution input data failed!");
  301. return FAILED;
  302. }
  303. return SUCCESS;
  304. }
  305. Status GeExecutor::SetDynamicDims(uint32_t model_id, void *dynamic_input_addr, uint64_t length,
  306. const vector<uint64_t> &dynamic_dims) {
  307. if (dynamic_input_addr == nullptr) {
  308. GELOGE(FAILED, "Dynamic input addr is nullptr!");
  309. return FAILED;
  310. }
  311. vector<uint64_t> cur_dynamic_dims;
  312. Status ret = GetCurDynamicDims(model_id, dynamic_dims, cur_dynamic_dims);
  313. if (ret != SUCCESS) {
  314. GELOGE(FAILED, "Set cur gear dynmaic dims failed");
  315. return FAILED;
  316. }
  317. ret = GraphExecutor::SetDynamicSize(model_id, cur_dynamic_dims, static_cast<int32_t>(DYNAMIC_DIMS));
  318. if (ret != SUCCESS) {
  319. GELOGE(FAILED, "Set dynamic size failed");
  320. return FAILED;
  321. }
  322. size_t dynamic_dim_num = cur_dynamic_dims.size();
  323. uint64_t dynamic_input_size = static_cast<uint64_t>(dynamic_dim_num * sizeof(uint64_t));
  324. if (length < dynamic_input_size) {
  325. GELOGE(FAILED, "Dynamic input size [%lu] is less than [%lu]!", length, dynamic_input_size);
  326. return FAILED;
  327. }
  328. for (uint32_t i = 0; i < dynamic_dim_num; ++i) {
  329. // Memcpy dynamic dim[i] from host to device
  330. if (rtMemcpy(reinterpret_cast<void *>(reinterpret_cast<uint8_t *>(dynamic_input_addr) + sizeof(uint64_t) * i),
  331. length - sizeof(uint64_t) * i, &cur_dynamic_dims[i], sizeof(uint64_t),
  332. RT_MEMCPY_HOST_TO_DEVICE) != RT_ERROR_NONE) {
  333. GELOGE(FAILED, "memcpy dynamic resolution input data failed!");
  334. return FAILED;
  335. }
  336. }
  337. return SUCCESS;
  338. }
  339. Status GeExecutor::GetCurDynamicDims(uint32_t model_id, const vector<uint64_t> &dynamic_dims,
  340. vector<uint64_t> &cur_dynamic_dims) {
  341. cur_dynamic_dims.clear();
  342. vector<ge::TensorDesc> input_desc;
  343. vector<ge::TensorDesc> output_desc;
  344. auto ret = GetModelDescInfo(model_id, input_desc, output_desc);
  345. if (ret != ge::SUCCESS) {
  346. GELOGE(FAILED, "GetModelDescInfo failed.");
  347. return FAILED;
  348. }
  349. vector<string> user_designate_shape_order;
  350. vector<int64_t> all_data_dims;
  351. ret = GetUserDesignateShapeOrder(model_id, user_designate_shape_order);
  352. if (ret != ge::SUCCESS) {
  353. GELOGE(FAILED, "GetUserDesignateShapeOrder failed.");
  354. return FAILED;
  355. }
  356. for (auto &data_name : user_designate_shape_order) {
  357. for (auto &desc : input_desc) {
  358. if (desc.GetName() == data_name) {
  359. for (auto dim : desc.GetShape().GetDims()) {
  360. all_data_dims.push_back(dim);
  361. }
  362. break;
  363. }
  364. }
  365. }
  366. if (dynamic_dims.size() != all_data_dims.size()) {
  367. GELOGE(FAILED, "Dynamic input size [%lu] is not equal with all data dims size [%lu]!", dynamic_dims.size(),
  368. all_data_dims.size());
  369. return FAILED;
  370. }
  371. for (std::size_t i = 0; i < all_data_dims.size(); ++i) {
  372. if (all_data_dims[i] < 0) {
  373. cur_dynamic_dims.push_back(dynamic_dims[i]);
  374. }
  375. }
  376. return SUCCESS;
  377. }
  378. Status GeExecutor::GetCurShape(const uint32_t model_id, std::vector<int64_t> &batch_info, int32_t &dynamic_type) {
  379. GELOGI("Begin to get current shape");
  380. if (!isInit_) {
  381. GELOGE(GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!");
  382. return GE_EXEC_NOT_INIT;
  383. }
  384. Status ret = GraphExecutor::GetCurShape(model_id, batch_info, dynamic_type);
  385. if (ret != SUCCESS) {
  386. GELOGE(ret, "Get current shape failed");
  387. return ret;
  388. }
  389. return SUCCESS;
  390. }
  391. Status GeExecutor::SetDynamicAippData(uint32_t model_id, void *dynamic_input_addr, uint64_t length,
  392. const std::vector<kAippDynamicBatchPara> &aippBatchPara,
  393. const kAippDynamicPara &aippParms) {
  394. GELOGI("Enter to SetDynamicAippData.");
  395. if (dynamic_input_addr == nullptr) {
  396. GELOGE(PARAM_INVALID, "Dynamic aipp input addr is nullptr!");
  397. return PARAM_INVALID;
  398. }
  399. if (aippBatchPara.empty()) {
  400. GELOGE(PARAM_INVALID, "aippBatchPara is empty.");
  401. return PARAM_INVALID;
  402. }
  403. uint64_t batch_num = aippBatchPara.size();
  404. uint64_t real_aippParms_size = sizeof(kAippDynamicPara) - sizeof(kAippDynamicBatchPara);
  405. uint64_t struct_len = batch_num * sizeof(kAippDynamicBatchPara) + real_aippParms_size;
  406. GELOGI(
  407. "Get acl input dynamic aipp data, model_id is %u, length is %lu,"
  408. "batch num is %lu, struct_len is %lu",
  409. model_id, length, batch_num, struct_len);
  410. if (struct_len > length) {
  411. GELOGE(PARAM_INVALID, "input dynamic aipp param len [%lu] is larger than aipp_data size [%lu]", struct_len, length);
  412. return PARAM_INVALID;
  413. }
  414. // Memcpy real kAippDynamicBatchPara from host to device
  415. rtError_t rt_ret = rtMemcpy(dynamic_input_addr, length, &aippParms, real_aippParms_size, RT_MEMCPY_HOST_TO_DEVICE);
  416. if (rt_ret != RT_ERROR_NONE) {
  417. GELOGE(RT_FAILED, "memcpy real_aippParms_size failed! ret: 0x%X", rt_ret);
  418. return RT_ERROR_TO_GE_STATUS(rt_ret);
  419. }
  420. uint64_t remain_len = length - real_aippParms_size;
  421. uint8_t *aipp_batch_para_dev = reinterpret_cast<uint8_t *>(dynamic_input_addr) + real_aippParms_size;
  422. for (uint64_t i = 0; i < batch_num; ++i) {
  423. rt_ret = rtMemcpy(reinterpret_cast<void *>(aipp_batch_para_dev + i * sizeof(kAippDynamicBatchPara)),
  424. (remain_len - i * sizeof(kAippDynamicBatchPara)), &(aippBatchPara[i]),
  425. sizeof(kAippDynamicBatchPara), RT_MEMCPY_HOST_TO_DEVICE);
  426. if (rt_ret != RT_ERROR_NONE) {
  427. GELOGE(RT_FAILED, "memcpy kAippDynamicBatchPara input data failed! ret: 0x%X", rt_ret);
  428. return RT_ERROR_TO_GE_STATUS(rt_ret);
  429. }
  430. }
  431. return SUCCESS;
  432. }
  433. // Load model
  434. Status GeExecutor::LoadModelOffline(uint32_t &model_id, const std::string &path, const std::string &key,
  435. int32_t priority, std::shared_ptr<ge::ModelListener> listener) {
  436. GELOGI("load model offline begin.");
  437. if (!isInit_) {
  438. GELOGE(GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!");
  439. return GE_EXEC_NOT_INIT;
  440. }
  441. string filePath = RealPath(path.c_str());
  442. if (filePath.empty()) {
  443. GELOGE(ge::FAILED, "File path is invalid. please check your text file '%s'.", path.c_str());
  444. return ge::FAILED;
  445. }
  446. std::shared_ptr<ModelListenerAdapter> listener_adapter = MakeShared<ModelListenerAdapter>();
  447. if (listener_adapter == nullptr) {
  448. GELOGE(MEMALLOC_FAILED, "ModelListenerAdapter make shared failed!");
  449. return ge::FAILED;
  450. }
  451. listener_adapter->listener = listener;
  452. Status ret = GraphLoader::LoadModelFromFile(path, key, priority, listener_adapter, model_id);
  453. if (ret != SUCCESS) {
  454. GELOGE(ret, "[GeExecutor] LoadModelFromFile failed");
  455. return TransferDomiErrorCode(ret);
  456. }
  457. return SUCCESS;
  458. }
  459. Status GeExecutor::LoadModel(uint32_t &model_id, const ModelData &model_data,
  460. std::shared_ptr<ge::ModelListener> listener) {
  461. GELOGI("Load model begin.");
  462. if (!isInit_) {
  463. GELOGE(GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!");
  464. return GE_EXEC_NOT_INIT;
  465. }
  466. std::shared_ptr<ModelListenerAdapter> listener_adapter = MakeShared<ModelListenerAdapter>();
  467. if (listener_adapter == nullptr) {
  468. GELOGE(MEMALLOC_FAILED, "ModelListenerAdapter make shared failed!");
  469. return ge::FAILED;
  470. }
  471. listener_adapter->listener = listener;
  472. Status ret = GraphLoader::LoadModel(model_data, listener_adapter, model_id);
  473. if (ret != SUCCESS) {
  474. GELOGE(ret, "[GeExecutor] LoadModel failed.");
  475. return TransferDomiErrorCode(ret);
  476. }
  477. return ret;
  478. }
  479. Status GeExecutor::UnloadModel(uint32_t model_id) {
  480. GELOGI("unload model %u begin.", model_id);
  481. if (!isInit_) {
  482. GELOGE(GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!");
  483. return GE_EXEC_NOT_INIT;
  484. }
  485. Status ret = GraphLoader::DestroyAicpuSessionForInfer(model_id);
  486. if (ret != SUCCESS) {
  487. GELOGE(ret, "[GraphLoader] DestroyAicpuSessionForInfer failed. model id: %u", model_id);
  488. return FAILED;
  489. }
  490. std::shared_ptr<DavinciModel> davinci_model = ModelManager::GetInstance()->GetModel(model_id);
  491. if (davinci_model != nullptr) {
  492. uint64_t session_id = davinci_model->GetSessionId();
  493. VarManagerPool::Instance().RemoveVarManager(session_id);
  494. }
  495. return GraphLoader::UnloadModel(model_id);
  496. }
  497. Status GeExecutor::RunModel(const ge::RunModelData &input_data, ge::RunModelData &output_data) {
  498. GELOGI("run model begin.");
  499. if (!isInit_) {
  500. GELOGE(GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!");
  501. return GE_EXEC_NOT_INIT;
  502. }
  503. InputData inputs;
  504. GetDomiInputData(input_data, inputs);
  505. OutputData outputs;
  506. GetDomiOutputData(output_data, outputs);
  507. return GraphExecutor::DataInput(inputs, outputs);
  508. }
  509. // Get input and output descriptor
  510. Status GeExecutor::GetModelDescInfo(uint32_t model_id, std::vector<ge::TensorDesc> &input_desc,
  511. std::vector<ge::TensorDesc> &output_desc, bool new_model_desc) {
  512. GELOGI("get model desc info begin.");
  513. if (!isInit_) {
  514. GELOGE(GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!");
  515. return GE_EXEC_NOT_INIT;
  516. }
  517. std::vector<InputOutputDescInfo> input_desc_infos;
  518. std::vector<InputOutputDescInfo> output_desc_infos;
  519. std::vector<uint32_t> input_formats;
  520. std::vector<uint32_t> output_formats;
  521. Status ret = GraphExecutor::GetInputOutputDescInfo(model_id, input_desc_infos, output_desc_infos, input_formats,
  522. output_formats, new_model_desc);
  523. if (ret != domi::SUCCESS) {
  524. GELOGE(ret, "GetInputOutputDescInfo failed. ret = %u", ret);
  525. return ret;
  526. }
  527. if (input_formats.size() != input_desc_infos.size()) {
  528. GELOGE(ge::PARAM_INVALID, "input_formats size %zu is not equal to input_desc_infos size %zu.", input_formats.size(),
  529. input_desc_infos.size());
  530. return ge::PARAM_INVALID;
  531. }
  532. if (output_formats.size() != output_desc_infos.size()) {
  533. GELOGE(ge::PARAM_INVALID, "output_formats size %zu is not equal to output_desc_infos size %zu.",
  534. output_formats.size(), output_desc_infos.size());
  535. return ge::PARAM_INVALID;
  536. }
  537. // Transfer data to TensorDesc
  538. GetGeTensorDescFromDomiInfo(input_desc, input_desc_infos, input_formats);
  539. GetGeTensorDescFromDomiInfo(output_desc, output_desc_infos, output_formats);
  540. GELOGI("get model desc info end.");
  541. return ge::SUCCESS;
  542. }
  543. ///
  544. /// @ingroup ge
  545. /// @brief Get dynamic batch_info
  546. /// @param [in] model_id
  547. /// @param [out] batch_info
  548. /// @param [out] dynamic_type
  549. /// @return execute result
  550. ///
  551. Status GeExecutor::GetDynamicBatchInfo(uint32_t model_id, std::vector<std::vector<int64_t>> &batch_info,
  552. int32_t &dynamic_type) {
  553. GELOGI("Begin to get dynamic batch info.");
  554. if (!isInit_) {
  555. GELOGE(GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!");
  556. return GE_EXEC_NOT_INIT;
  557. }
  558. Status ret = GraphExecutor::GetDynamicBatchInfo(model_id, batch_info, dynamic_type);
  559. if (ret != SUCCESS) {
  560. GELOGE(ret, "GetDynamicBatchInfo failed.");
  561. return ret;
  562. }
  563. GELOGI("Get dynamic batch info succ.");
  564. return SUCCESS;
  565. }
  566. ///
  567. /// @ingroup ge
  568. /// @brief Get combined dynamic dims info
  569. /// @param [in] model_id
  570. /// @param [out] batch_info
  571. /// @return execute result
  572. ///
  573. Status GeExecutor::GetCombinedDynamicDims(uint32_t model_id, vector<vector<int64_t>> &batch_info) {
  574. GELOGI("Begin to get combined dynamic dims info.");
  575. if (!isInit_) {
  576. GELOGE(GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!");
  577. return GE_EXEC_NOT_INIT;
  578. }
  579. Status ret = GraphExecutor::GetCombinedDynamicDims(model_id, batch_info);
  580. if (ret != SUCCESS) {
  581. GELOGE(ret, "GetCombinedDynamicDims failed.");
  582. return ret;
  583. }
  584. GELOGI("Get combined dynamic dims succ.");
  585. return SUCCESS;
  586. }
  587. ///
  588. /// @ingroup ge
  589. /// @brief Get user designeate shape order
  590. /// @param [in] model_id
  591. /// @param [out] user_designate_shape_order
  592. /// @return execute result
  593. ///
  594. Status GeExecutor::GetUserDesignateShapeOrder(uint32_t model_id, vector<string> &user_designate_shape_order) {
  595. GELOGI("Begin to get user designate shape info.");
  596. if (!isInit_) {
  597. GELOGE(GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!");
  598. return GE_EXEC_NOT_INIT;
  599. }
  600. Status ret = GraphExecutor::GetUserDesignateShapeOrder(model_id, user_designate_shape_order);
  601. if (ret != SUCCESS) {
  602. GELOGE(ret, "GetUserDesignateShapeOrder failed.");
  603. return ret;
  604. }
  605. GELOGI("Get user designate shape order succ.");
  606. return SUCCESS;
  607. }
  608. ///
  609. /// @ingroup ge
  610. /// @brief Get AIPP input format
  611. /// @param [in] model_id
  612. /// @param [in] index
  613. /// @param [out] input_format
  614. /// @return execute result
  615. ///
  616. Status GeExecutor::GetAIPPInfo(uint32_t model_id, uint32_t index, AippConfigInfo &aipp_info) {
  617. GELOGI("Begin to GetAIPPInfo.");
  618. if (!isInit_) {
  619. GELOGE(GE_EXEC_NOT_INIT, "not inited yet!");
  620. return GE_EXEC_NOT_INIT;
  621. }
  622. Status ret = GraphExecutor::GetAIPPInfo(model_id, index, aipp_info);
  623. if (ret != SUCCESS) {
  624. GELOGW("GetAIPPInfo is not success.");
  625. return ret;
  626. }
  627. GELOGI("GetAIPPInfo succ.");
  628. return SUCCESS;
  629. }
  630. Status GeExecutor::GetModelAttr(uint32_t model_id, std::vector<std::string> &dynamic_output_shape_info) {
  631. GELOGI("Begin to get dynamic batch output shape info");
  632. if (!isInit_) {
  633. GELOGE(GE_EXEC_NOT_INIT, "not inited yet!");
  634. return GE_EXEC_NOT_INIT;
  635. }
  636. Status ret = GraphExecutor::GetModelAttr(model_id, dynamic_output_shape_info);
  637. if (ret != SUCCESS) {
  638. GELOGE(ret, "Get dynamic batch output shape info failed.");
  639. return ret;
  640. }
  641. GELOGI("Get dynamic batch output shape info succ.");
  642. return SUCCESS;
  643. }
  644. Status GeExecutor::GetModelDescInfoForZeroCopy(uint32_t model_id, std::vector<ge::TensorDesc> &input_desc,
  645. std::vector<TensorDesc> &output_desc) {
  646. GELOGI("get model desc info for zero copy begin.");
  647. if (!isInit_) {
  648. GELOGE(GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!");
  649. return GE_EXEC_NOT_INIT;
  650. }
  651. std::vector<InputOutputDescInfo> input_desc_infos;
  652. std::vector<InputOutputDescInfo> output_desc_infos;
  653. std::vector<uint32_t> input_formats;
  654. std::vector<uint32_t> output_formats;
  655. Status ret = GraphExecutor::GetInputOutputDescInfoForZeroCopy(model_id, input_desc_infos, output_desc_infos,
  656. input_formats, output_formats);
  657. if (ret != domi::SUCCESS) {
  658. GELOGE(ret, "Get DescInfo from zero copy failed. ret = %u", ret);
  659. return TransferDomiErrorCode(ret);
  660. }
  661. if (input_formats.size() != input_desc_infos.size()) {
  662. GELOGE(ge::FAILED, "input_formats.size() != input_desc_infos.size().");
  663. return ge::FAILED;
  664. }
  665. if (output_formats.size() != output_desc_infos.size()) {
  666. GELOGE(ge::FAILED, "output_formats.size() != output_desc_infos.size().");
  667. return ge::FAILED;
  668. }
  669. GetGeTensorDescFromDomiInfo(input_desc, input_desc_infos, input_formats);
  670. GetGeTensorDescFromDomiInfo(output_desc, output_desc_infos, output_formats);
  671. GELOGI("get model desc info from zero copy end.");
  672. return ge::SUCCESS;
  673. }
  674. Status GeExecutor::CommandHandle(const Command &command) {
  675. GELOGI("command handle begin.");
  676. Status ret = GraphLoader::CommandHandle(command);
  677. if (ret != SUCCESS) {
  678. GELOGE(ret, "CommandHandle: Command Handle failed.");
  679. return TransferDomiErrorCode(ret);
  680. }
  681. return SUCCESS;
  682. }
  683. Status GeExecutor::GetMaxUsedMemory(uint32_t model_id, uint32_t &max_size) {
  684. GELOGI("Get max used memory begin.");
  685. if (!isInit_) {
  686. GELOGE(GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!");
  687. return GE_EXEC_NOT_INIT;
  688. }
  689. uint64_t max_mem_size = 0;
  690. Status ret = GraphLoader::GetMaxUsedMemory(model_id, max_mem_size);
  691. max_size = static_cast<uint32_t>(max_mem_size);
  692. return ret;
  693. }
  694. /**
  695. * @ingroup ge
  696. * @brief Load data from model file to memory
  697. * @param [in] const std::string &path: Offline model file path
  698. * @param [out] domi::ModelData &model_data: Offline model memory data
  699. * @return SUCCESS handle successfully / others handle failed
  700. */
  701. Status GeExecutor::LoadDataFromFile(const std::string &path, ModelData &model_data) {
  702. GELOGI("Load data from file begin.");
  703. if (!isInit_) {
  704. GELOGE(GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!");
  705. return GE_EXEC_NOT_INIT;
  706. }
  707. string filePath = RealPath(path.c_str());
  708. if (filePath.empty()) {
  709. GELOGE(GE_EXEC_MODEL_PATH_INVALID, "File path is invalid. please check your text file '%s'.", path.c_str());
  710. return GE_EXEC_MODEL_PATH_INVALID;
  711. }
  712. GELOGI("load modelData from file: %s.", path.c_str());
  713. std::string key_path;
  714. int32_t priority = 0;
  715. Status ret = GraphLoader::LoadDataFromFile(path, key_path, priority, model_data);
  716. if (ret != SUCCESS) {
  717. if (model_data.model_data != nullptr) {
  718. delete[] static_cast<char *>(model_data.model_data);
  719. model_data.model_data = nullptr;
  720. }
  721. }
  722. return ret;
  723. }
  724. /**
  725. * @ingroup ge
  726. * @brief Load model from offline model memory data
  727. * @param [in] domi::ModelData &model_data: Offline model data
  728. void *dev_ptr: Input/Output memory start address
  729. size_t memsize: Input/Output memory length
  730. void *weight_ptr: Weight memory start address
  731. size_t weightsize: Weight memory length
  732. * @param [out] uint32_t &model_id: identification after model loading
  733. * @return SUCCESS handle successfully / others handle failed
  734. */
  735. Status GeExecutor::LoadModelFromData(uint32_t &model_id, const ModelData &model_data, void *dev_ptr, size_t mem_size,
  736. void *weight_ptr, size_t weight_size) {
  737. GELOGI("Load model from data begin.");
  738. if (!isInit_) {
  739. GELOGE(GE_EXEC_NOT_INIT, "not inited yet!");
  740. return GE_EXEC_NOT_INIT;
  741. }
  742. return GraphLoader::LoadModelFromData(model_id, model_data, dev_ptr, mem_size, weight_ptr, weight_size);
  743. }
  744. /**
  745. * @ingroup ge
  746. * @brief Load task list from ModelData with queue.
  747. * @param [out] model_id: model id allocate from manager.
  748. * @param [in] ge_model_data: Model data load from offline model.
  749. * @param [in] input_queue_ids: input queue ids create from user.
  750. * @param [in] output_queue_ids: input queue ids create from user.
  751. * @return: 0 for success / others for fail
  752. */
  753. Status GeExecutor::LoadModelWithQ(uint32_t &model_id, const ModelData &model_data,
  754. const std::vector<uint32_t> &input_queue_ids,
  755. const std::vector<uint32_t> &output_queue_ids) {
  756. GELOGI("Load model with queue begin.");
  757. if (!isInit_) {
  758. GELOGE(GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!");
  759. return GE_EXEC_NOT_INIT;
  760. }
  761. return GraphLoader::LoadModelWithQ(model_id, model_data, input_queue_ids, output_queue_ids);
  762. }
  763. /**
  764. * @ingroup ge
  765. * @brief Synchronous execution of offline model(Do not create thread)
  766. * @param [in] uint32_t model_id: Model ID to execute
  767. void* stream: stream to execute
  768. const domi::InputData *input_data: Model input data
  769. bool async_mode: is asynchronize mode.
  770. * @param [out] domi::OutputData *output_data: Model output data
  771. * @return SUCCESS handle successfully / others handle failed
  772. */
  773. Status GeExecutor::ExecModel(uint32_t model_id, void *stream, const ge::RunModelData &run_input_data,
  774. ge::RunModelData &run_output_data, bool async_mode) {
  775. GELOGI("Execute model begin.");
  776. if (!isInit_) {
  777. GELOGE(GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!");
  778. return GE_EXEC_NOT_INIT;
  779. }
  780. InputData input_data;
  781. OutputData output_data;
  782. GetDomiInputData(run_input_data, input_data);
  783. GetDomiOutputData(run_output_data, output_data);
  784. if ((run_input_data.dynamic_batch_size != 0) || (run_input_data.dynamic_image_width != 0) ||
  785. (run_input_data.dynamic_image_height != 0) || (run_input_data.dynamic_dims.size() != 0)) {
  786. std::vector<std::vector<int64_t>> batch_info;
  787. int32_t dynamic_type = static_cast<int32_t>(FIXED);
  788. Status ret = GraphExecutor::GetDynamicBatchInfo(model_id, batch_info, dynamic_type);
  789. if (ret != SUCCESS) {
  790. GELOGE(ret, "Get dynamic input info failed.");
  791. return ret;
  792. }
  793. if (!batch_info.empty()) {
  794. SetDynamicInputDataFlag(run_input_data, batch_info, input_data);
  795. }
  796. }
  797. return GraphLoader::ExecuteModel(model_id, stream, async_mode, input_data, output_data);
  798. }
  799. /**
  800. * @ingroup ge
  801. * @brief Get weight memory size from model file
  802. * @param [in] const std::string &path: Offline model file path
  803. * @param [out] size_t &mem_size Execution memory size
  804. size_t &weight_size Weight memory space size
  805. * @return SUCCESS handle successfully / others handle failed
  806. */
  807. Status GeExecutor::GetMemAndWeightSize(const std::string &path, size_t &mem_size, size_t &weight_size) {
  808. GELOGI("Get memory and weight size from file begin.");
  809. if (!isInit_) {
  810. GELOGE(GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!");
  811. return GE_EXEC_NOT_INIT;
  812. }
  813. ModelData model;
  814. std::string key;
  815. Status ret = ge::GraphLoader::LoadDataFromFile(path, key, 0, model);
  816. if ((ret != SUCCESS) || (model.model_data == nullptr)) {
  817. GELOGE(ret, "Load data from file failed. ret = %d", ret);
  818. return ret;
  819. }
  820. ret = ge::ModelManager::GetModelMemAndWeightSize(model, mem_size, weight_size);
  821. delete[] static_cast<char *>(model.model_data);
  822. model.model_data = nullptr;
  823. return ret;
  824. }
  825. /**
  826. * @ingroup ge
  827. * @brief Get weight memory size from model file
  828. * @param [in] const void *model_data Offline model buffer
  829. size_t model_size Offline model buffer length
  830. * @param [out] size_t &mem_size Execution memory size
  831. size_t &weight_size Weight memory space size
  832. * @return SUCCESS handle successfully / others handle failed
  833. */
  834. Status GeExecutor::GetMemAndWeightSize(const void *model_data, size_t model_size, size_t &mem_size,
  835. size_t &weight_size) {
  836. GELOGI("Get memory and weight size from data begin.");
  837. if (!isInit_) {
  838. GELOGE(GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!");
  839. return GE_EXEC_NOT_INIT;
  840. }
  841. if (model_data == nullptr) {
  842. GELOGE(PARAM_INVALID, "invalid model data!");
  843. return PARAM_INVALID;
  844. }
  845. ModelData model;
  846. model.model_data = const_cast<void *>(model_data);
  847. model.model_len = static_cast<uint32_t>(model_size);
  848. return ge::ModelManager::GetModelMemAndWeightSize(model, mem_size, weight_size);
  849. }
  850. Status GeExecutor::LoadSingleOp(const std::string &model_name, const ge::ModelData &modelData, void *stream,
  851. SingleOp **single_op) {
  852. return SingleOpManager::GetInstance().GetOpFromModel(model_name, modelData, stream, single_op);
  853. }
  854. Status GeExecutor::LoadDynamicSingleOp(const std::string &model_name, const ge::ModelData &modelData, void *stream,
  855. DynamicSingleOp **single_op) {
  856. return SingleOpManager::GetInstance().GetDynamicOpFromModel(model_name, modelData, stream, single_op);
  857. }
  858. Status GeExecutor::ExecuteAsync(SingleOp *executor, const std::vector<DataBuffer> &inputs,
  859. std::vector<DataBuffer> &outputs) {
  860. if (executor == nullptr) {
  861. GELOGE(PARAM_INVALID, "param is NULL");
  862. return PARAM_INVALID;
  863. }
  864. return executor->ExecuteAsync(inputs, outputs);
  865. }
  866. ge::Status GeExecutor::ExecuteAsync(DynamicSingleOp *executor, const vector<GeTensorDesc> &input_desc,
  867. const vector<DataBuffer> &inputs, vector<GeTensorDesc> &output_desc,
  868. vector<DataBuffer> &outputs) {
  869. GE_CHECK_NOTNULL(executor);
  870. return executor->ExecuteAsync(input_desc, inputs, output_desc, outputs);
  871. }
  872. Status GeExecutor::ReleaseSingleOpResource(void *stream) {
  873. return SingleOpManager::GetInstance().ReleaseResource(stream);
  874. }
  875. Status GeExecutor::GetBatchInfoSize(uint32_t model_id, size_t &shape_count) {
  876. std::vector<std::vector<int64_t>> batch_info;
  877. int32_t dynamic_type = static_cast<int32_t>(FIXED);
  878. Status ret = GetDynamicBatchInfo(model_id, batch_info, dynamic_type);
  879. if (ret != SUCCESS) {
  880. GELOGE(ret, "Calc batch info size failed. ret = %d", ret);
  881. return ret;
  882. }
  883. if (batch_info.empty()) {
  884. shape_count = kStaticBatchInfoSize;
  885. } else {
  886. shape_count = batch_info.size();
  887. }
  888. return SUCCESS;
  889. }
  890. Status GeExecutor::GetOrigInputInfo(uint32_t model_id, uint32_t index, OriginInputInfo &orig_input_info) {
  891. GELOGI("Begin to GetOrigInputInfo.");
  892. if (!isInit_) {
  893. GELOGE(GE_EXEC_NOT_INIT, "not inited yet!");
  894. return GE_EXEC_NOT_INIT;
  895. }
  896. Status ret = GraphExecutor::GetOrigInputInfo(model_id, index, orig_input_info);
  897. if (ret != SUCCESS) {
  898. GELOGE(ret, "GetOrigInputInfo failed.");
  899. return ret;
  900. }
  901. GELOGI("GetOrigInputInfo succ.");
  902. return SUCCESS;
  903. }
  904. Status GeExecutor::GetAllAippInputOutputDims(uint32_t model_id, uint32_t index,
  905. std::vector<InputOutputDims> &input_dims,
  906. std::vector<InputOutputDims> &output_dims) {
  907. GELOGI("Begin to GetAllAippInputOutputDims.");
  908. if (!isInit_) {
  909. GELOGE(GE_EXEC_NOT_INIT, "not inited yet!");
  910. return GE_EXEC_NOT_INIT;
  911. }
  912. Status ret = GraphExecutor::GetAllAippInputOutputDims(model_id, index, input_dims, output_dims);
  913. if (ret != SUCCESS) {
  914. GELOGE(ret, "GetAllAippInputOutputDims failed.");
  915. return ret;
  916. }
  917. GELOGI("GetAllAippInputOutputDims succ.");
  918. return SUCCESS;
  919. }
  920. Status GeExecutor::GetOpDescInfo(uint32_t device_id, uint32_t stream_id, uint32_t task_id, OpDescInfo &op_desc_info) {
  921. GELOGI("Begin to GetOpDescInfo.");
  922. Status ret = GraphExecutor::GetOpDescInfo(device_id, stream_id, task_id, op_desc_info);
  923. if (ret != SUCCESS) {
  924. GELOGE(ret, "GetOpDescInfo failed.");
  925. return ret;
  926. }
  927. GELOGI("GetOpDescInfo succ.");
  928. return SUCCESS;
  929. }
  930. Status GeExecutor::SetDump(const DumpConfig &dump_config) {
  931. GELOGI("Start to set dump config");
  932. auto ret = DumpManager::GetInstance().SetDumpConf(dump_config);
  933. if (ret != SUCCESS) {
  934. GELOGE(ret, "Set dump conf failed");
  935. return ret;
  936. }
  937. GELOGI("Set dump config succ.");
  938. return SUCCESS;
  939. }
  940. } // namespace ge

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