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.

aicpu_ext_info.cc 21 kB

5 years ago
4 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
5 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
4 years ago
4 years ago
5 years ago
4 years ago
4 years ago
4 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
5 years ago
4 years ago
4 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
4 years ago
4 years ago
5 years ago
4 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. /**
  2. * Copyright 2019-2020 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "hybrid/node_executor/aicpu/aicpu_ext_info.h"
  17. #include "framework/common/util.h"
  18. #include "framework/common/fmk_error_codes.h"
  19. #include "framework/common/debug/log.h"
  20. namespace ge {
  21. namespace hybrid {
  22. namespace {
  23. // if dim count is not reach kMaxShapeDims(8), use INT64_MIN to mark dim end.
  24. constexpr int64_t kDimEndFlag = INT64_MIN;
  25. const std::map<int32_t, int32_t> kTopicTypeToRtsFlagMap {
  26. {static_cast<int32_t>(aicpu::FWKAdapter::FWK_ADPT_TOPIC_DEVICE_ONLY), 0},
  27. {static_cast<int32_t>(aicpu::FWKAdapter::FWK_ADPT_TOPIC_DEVICE_FIRST), RT_KERNEL_DEVICE_FIRST},
  28. {static_cast<int32_t>(aicpu::FWKAdapter::FWK_ADPT_TOPIC_HOST_ONLY), RT_KERNEL_HOST_ONLY},
  29. {static_cast<int32_t>(aicpu::FWKAdapter::FWK_ADPT_TOPIC_HOST_FIRST), RT_KERNEL_HOST_FIRST}
  30. };
  31. }
  32. Status AicpuExtInfoHandler::Parse(const std::string &ext_info) {
  33. GELOGI("Node[%s] parse ext info start.", node_name_.c_str());
  34. if (ext_info.empty()) {
  35. GELOGE(ACL_ERROR_GE_PARAM_INVALID,
  36. "[Check][Param:ext_info]Node[%s] parse ext info failed as ext info is empty.", node_name_.c_str());
  37. REPORT_INNER_ERROR("E19999", "Node[%s] parse ext info failed as ext info is empty.", node_name_.c_str());
  38. return ACL_ERROR_GE_PARAM_INVALID;
  39. }
  40. ext_info_len_ = ext_info.size();
  41. ext_info_.reset(new(std::nothrow)uint8_t[ext_info_len_]);
  42. GE_CHECK_NOTNULL(ext_info_);
  43. if (memcpy_s(ext_info_.get(), ext_info_len_, ext_info.c_str(), ext_info.size()) != EOK) {
  44. GELOGE(ACL_ERROR_GE_MEMORY_OPERATE_FAILED, "[Update][ext_info_][%s] Failed to copy ext info", node_name_.c_str());
  45. REPORT_CALL_ERROR("E19999", "[%s] Failed to copy ext info.", node_name_.c_str());
  46. return ACL_ERROR_GE_MEMORY_OPERATE_FAILED;
  47. }
  48. input_shape_and_type_.clear();
  49. output_shape_and_type_.clear();
  50. auto ext_info_data = ext_info_.get();
  51. size_t offset = 0;
  52. while (offset + sizeof(AicpuExtInfo) <= ext_info_len_) {
  53. auto aicpu_ext_info = reinterpret_cast<AicpuExtInfo *>(ext_info_data + offset);
  54. GELOGD("Ext infoType=%d, infoLen=%u.", aicpu_ext_info->infoType, aicpu_ext_info->infoLen);
  55. switch (aicpu_ext_info->infoType) {
  56. case aicpu::FWKAdapter::FWK_ADPT_EXT_SHAPE_TYPE:
  57. GE_CHK_STATUS_RET(ParseExtShapeType(aicpu_ext_info), "[Parse][ExtShapeType] failed.");
  58. break;
  59. case aicpu::FWKAdapter::FWK_ADPT_EXT_INPUT_SHAPE:
  60. GE_CHK_STATUS_RET(ParseExtInputShape(aicpu_ext_info), "[Parse][ExtInputShape] failed.");
  61. break;
  62. case aicpu::FWKAdapter::FWK_ADPT_EXT_OUTPUT_SHAPE:
  63. GE_CHK_STATUS_RET(ParseExtOutputShape(aicpu_ext_info), "[Parse][ExtOutputShape] failed.");
  64. break;
  65. case aicpu::FWKAdapter::FWK_ADPT_EXT_SESSION_INFO:
  66. GE_CHK_STATUS_RET(ParseExtSessionInfo(aicpu_ext_info), "[Parse][ExtSessionInfo] failed.");
  67. break;
  68. case aicpu::FWKAdapter::FWK_ADPT_EXT_BITMAP:
  69. GE_CHK_STATUS_RET(ParseExtBitMap(aicpu_ext_info), "[Parse][ExtBitMap] failed.");
  70. break;
  71. case aicpu::FWKAdapter::FWK_ADPT_EXT_UPDATE_ADDR:
  72. GE_CHK_STATUS_RET(ParseExtUpdateAddr(aicpu_ext_info), "[Parse][ExtUpdateAddr] failed.");
  73. break;
  74. case aicpu::FWKAdapter::FWK_ADPT_EXT_TOPIC_TYPE:
  75. GE_CHK_STATUS_RET(ParseExtTopicType(aicpu_ext_info), "[Parse][ExtTopicType] failed.");
  76. break;
  77. case aicpu::FWKAdapter::FWK_ADPT_EXT_ASYNCWAIT:
  78. GE_CHK_STATUS_RET(ParseExtAsyncWait(aicpu_ext_info), "[Parse][ExtAsyncWait] failed.");
  79. break;
  80. default:
  81. GELOGD("Node[%s] ignore infoType=%d, infoLen=%u.",
  82. node_name_.c_str(), aicpu_ext_info->infoType, aicpu_ext_info->infoLen);
  83. break;
  84. }
  85. offset += sizeof(AicpuExtInfo);
  86. offset += aicpu_ext_info->infoLen;
  87. }
  88. GE_IF_BOOL_EXEC(offset != ext_info_len_,
  89. REPORT_INNER_ERROR("E19999", "Node[%s] ext_info format error, parse not reach end,"
  90. "offset=%zu, ext_info_len=%zu.", node_name_.c_str(), offset, ext_info_len_);
  91. GELOGE(ACL_ERROR_GE_PARAM_INVALID, "[Check][Size]Node[%s] ext_info format error,"
  92. "parse not reach end, offset=%zu, ext_info_len=%zu.",
  93. node_name_.c_str(), offset, ext_info_len_);
  94. return ACL_ERROR_GE_PARAM_INVALID;);
  95. GELOGI("Node[%s] parse ext info end.", node_name_.c_str());
  96. return SUCCESS;
  97. }
  98. Status AicpuExtInfoHandler::ParseExtAsyncWait(AicpuExtInfo *aicpu_ext_info) {
  99. if (aicpu_ext_info->infoLen != sizeof(AsyncWaitInfo)) {
  100. REPORT_INNER_ERROR("E19999",
  101. "Node[%s] parse ext async wait info failed as infoLen must be %zu but %u.",
  102. node_name_.c_str(), sizeof(AsyncWaitInfo), aicpu_ext_info->infoLen);
  103. GELOGE(ACL_ERROR_GE_PARAM_INVALID,
  104. "[Check][DataLen]Node[%s] parse ext async wait info failed as infoLen must be %zu but %u.",
  105. node_name_.c_str(), sizeof(AsyncWaitInfo), aicpu_ext_info->infoLen);
  106. return ACL_ERROR_GE_PARAM_INVALID;
  107. }
  108. async_wait_ = reinterpret_cast<AsyncWaitInfo *>(aicpu_ext_info->infoMsg);
  109. GELOGI("Node[%s] parse async wait info success infoLen=%u.", node_name_.c_str(), aicpu_ext_info->infoLen);
  110. return SUCCESS;
  111. }
  112. Status AicpuExtInfoHandler::ParseExtShapeType(AicpuExtInfo *aicpu_ext_info) {
  113. GE_IF_BOOL_EXEC(aicpu_ext_info->infoLen != sizeof(int32_t),
  114. REPORT_INNER_ERROR("E19999", "Node[%s] parse ext shape type failed as infoLen must be %zu but %u.",
  115. node_name_.c_str(), sizeof(int32_t), aicpu_ext_info->infoLen);
  116. GELOGE(ACL_ERROR_GE_PARAM_INVALID,
  117. "[Check][Size]Node[%s] parse ext shape type failed as infoLen must be %zu but %u.",
  118. node_name_.c_str(), sizeof(int32_t), aicpu_ext_info->infoLen);
  119. return ACL_ERROR_GE_PARAM_INVALID;);
  120. auto type = reinterpret_cast<const int32_t *>(aicpu_ext_info->infoMsg);
  121. GE_IF_BOOL_EXEC(*type != unknown_type_,
  122. REPORT_INNER_ERROR("E19999", "Node[%s] parse ext shape type failed as need %d but %d.",
  123. node_name_.c_str(), unknown_type_, *type);
  124. GELOGE(ACL_ERROR_GE_PARAM_INVALID,
  125. "[Check][Type]Node[%s] parse ext shape type failed as need %d but %d.",
  126. node_name_.c_str(), unknown_type_, *type);
  127. return ACL_ERROR_GE_PARAM_INVALID;);
  128. GELOGI("Node[%s] parse ext shape type success infoLen=%u.", node_name_.c_str(), aicpu_ext_info->infoLen);
  129. return SUCCESS;
  130. }
  131. Status AicpuExtInfoHandler::ParseExtInputShape(AicpuExtInfo *aicpu_ext_info) {
  132. auto need_len = input_num_ * sizeof(AicpuShapeAndType);
  133. GE_IF_BOOL_EXEC(aicpu_ext_info->infoLen != need_len,
  134. REPORT_INNER_ERROR("E19999", "Node[%s] parse ext input shape failed as infoLen must be "
  135. "input_num[%u]*sizeof(ShapeAndType)[%zu] but %u.",
  136. node_name_.c_str(), input_num_, sizeof(AicpuShapeAndType),
  137. aicpu_ext_info->infoLen);
  138. GELOGE(ACL_ERROR_GE_PARAM_INVALID,
  139. "[Check][DataLen]Node[%s] parse ext input shape failed as infoLen must be "
  140. "input_num[%u]*sizeof(ShapeAndType)[%zu] but %u.",
  141. node_name_.c_str(), input_num_, sizeof(AicpuShapeAndType), aicpu_ext_info->infoLen);
  142. return ACL_ERROR_GE_PARAM_INVALID;);
  143. auto input = reinterpret_cast<AicpuShapeAndType *>(aicpu_ext_info->infoMsg);
  144. for (uint32_t index = 0; index < input_num_; ++index) {
  145. input_shape_and_type_.emplace_back(&input[index]);
  146. }
  147. GELOGI("Node[%s] parse ext input shape success infoLen=%u.", node_name_.c_str(), aicpu_ext_info->infoLen);
  148. return SUCCESS;
  149. }
  150. Status AicpuExtInfoHandler::ParseExtOutputShape(AicpuExtInfo *aicpu_ext_info) {
  151. if (unknown_type_ == DEPEND_COMPUTE) {
  152. GELOGD("Node[%s] is depend compute type no need ext output shape, ignore it, infoLen=%u.",
  153. node_name_.c_str(), aicpu_ext_info->infoLen);
  154. return SUCCESS;
  155. }
  156. auto need_len = output_num_ * sizeof(AicpuShapeAndType);
  157. GE_IF_BOOL_EXEC(aicpu_ext_info->infoLen != need_len,
  158. REPORT_INNER_ERROR("E19999", "Node[%s] parse ext output shape failed as infoLen must be "
  159. "output_num[%u]*sizeof(ShapeAndType)[%zu] but %u.",
  160. node_name_.c_str(), output_num_, sizeof(AicpuShapeAndType),
  161. aicpu_ext_info->infoLen);
  162. GELOGE(ACL_ERROR_GE_PARAM_INVALID,
  163. "[Check][DataLen]Node[%s] parse ext output shape failed as infoLen must be "
  164. "output_num[%u]*sizeof(ShapeAndType)[%zu] but %u.",
  165. node_name_.c_str(), output_num_, sizeof(AicpuShapeAndType), aicpu_ext_info->infoLen);
  166. return ACL_ERROR_GE_PARAM_INVALID;);
  167. auto output = reinterpret_cast<AicpuShapeAndType *>(aicpu_ext_info->infoMsg);
  168. for (uint32_t index = 0; index < output_num_; ++index) {
  169. output_shape_and_type_.emplace_back(&output[index]);
  170. }
  171. GELOGI("Node[%s] parse ext output shape success infoLen=%u.", node_name_.c_str(), aicpu_ext_info->infoLen);
  172. return SUCCESS;
  173. }
  174. Status AicpuExtInfoHandler::ParseExtSessionInfo(AicpuExtInfo *aicpu_ext_info) {
  175. GE_IF_BOOL_EXEC(aicpu_ext_info->infoLen != sizeof(AicpuSessionInfo),
  176. REPORT_INNER_ERROR("E19999",
  177. "Node[%s] parse ext session info failed as infoLen must be %zu but %u.",
  178. node_name_.c_str(), sizeof(SessionInfo), aicpu_ext_info->infoLen);
  179. GELOGE(ACL_ERROR_GE_PARAM_INVALID,
  180. "[Check][DataLen]Node[%s] parse ext session info failed as infoLen must be %zu but %u.",
  181. node_name_.c_str(), sizeof(SessionInfo), aicpu_ext_info->infoLen);
  182. return ACL_ERROR_GE_PARAM_INVALID;);
  183. session_info_ = reinterpret_cast<AicpuSessionInfo *>(aicpu_ext_info->infoMsg);
  184. GELOGI("Node[%s] parse session info success infoLen=%u.", node_name_.c_str(), aicpu_ext_info->infoLen);
  185. return SUCCESS;
  186. }
  187. Status AicpuExtInfoHandler::ParseExtBitMap(AicpuExtInfo *aicpu_ext_info) {
  188. GE_IF_BOOL_EXEC(aicpu_ext_info->infoLen != sizeof(uint64_t),
  189. REPORT_INNER_ERROR("E19999",
  190. "Node[%s] parse bit_map info failed as infoLen must be %zu but %u.",
  191. node_name_.c_str(), sizeof(uint64_t), aicpu_ext_info->infoLen);
  192. GELOGE(PARAM_INVALID,
  193. "[Check][DataLen]Node[%s] parse bit_map info failed as infoLen must be %zu but %u.",
  194. node_name_.c_str(), sizeof(uint64_t), aicpu_ext_info->infoLen);
  195. return PARAM_INVALID;);
  196. bit_map_ = reinterpret_cast<uint64_t *>(aicpu_ext_info->infoMsg);
  197. GELOGI("Node[%s] bit_map info success infoLen=%u.", node_name_.c_str(), aicpu_ext_info->infoLen);
  198. return SUCCESS;
  199. }
  200. Status AicpuExtInfoHandler::ParseExtUpdateAddr(AicpuExtInfo *aicpu_ext_info) {
  201. GE_IF_BOOL_EXEC(aicpu_ext_info->infoLen != sizeof(uint32_t),
  202. REPORT_INNER_ERROR("E19999",
  203. "Node[%s] parse update_addr info failed as infoLen must be %zu but %u.",
  204. node_name_.c_str(), sizeof(uint32_t), aicpu_ext_info->infoLen);
  205. GELOGE(PARAM_INVALID,
  206. "[Check][DataLen]Node[%s] parse update_addr info failed as infoLen must be %zu but %u.",
  207. node_name_.c_str(), sizeof(uint32_t), aicpu_ext_info->infoLen);
  208. return PARAM_INVALID;);
  209. update_addr_ = reinterpret_cast<uint32_t *>(aicpu_ext_info->infoMsg);
  210. GELOGI("Node[%s] update_addr info success infoLen=%u.", node_name_.c_str(), aicpu_ext_info->infoLen);
  211. return SUCCESS;
  212. }
  213. Status AicpuExtInfoHandler::ParseExtTopicType(AicpuExtInfo *aicpu_ext_info) {
  214. if (aicpu_ext_info->infoLen != sizeof(int32_t)) {
  215. REPORT_INNER_ERROR("E19999",
  216. "Node[%s] parse topic_type info failed as infoLen must be %zu but %u.",
  217. node_name_.c_str(), sizeof(int32_t), aicpu_ext_info->infoLen);
  218. GELOGE(ACL_ERROR_GE_PARAM_INVALID,
  219. "[Check][DataLen]Node[%s] parse topic_type info failed as infoLen must be %zu but %u.",
  220. node_name_.c_str(), sizeof(int32_t), aicpu_ext_info->infoLen);
  221. return ACL_ERROR_GE_PARAM_INVALID;
  222. }
  223. GE_CHECK_NOTNULL(aicpu_ext_info->infoMsg);
  224. auto type_info = reinterpret_cast<int32_t *>(aicpu_ext_info->infoMsg);
  225. int32_t type = *type_info;
  226. topic_type_flag_ = TopicTypeToRtsFlag(type);
  227. if (topic_type_flag_ == -1) {
  228. REPORT_INNER_ERROR("E19999", "Node[%s] parse ext topic type failed as need %d %d %d %d but %d.",
  229. node_name_.c_str(),
  230. aicpu::FWKAdapter::FWK_ADPT_TOPIC_DEVICE_ONLY,
  231. aicpu::FWKAdapter::FWK_ADPT_TOPIC_DEVICE_FIRST,
  232. aicpu::FWKAdapter::FWK_ADPT_TOPIC_HOST_ONLY,
  233. aicpu::FWKAdapter::FWK_ADPT_TOPIC_HOST_FIRST,
  234. type);
  235. GELOGE(ACL_ERROR_GE_PARAM_INVALID,
  236. "[Check][Type]Node[%s] parse ext shape type failed as need %d %d %d %d but %d.",
  237. node_name_.c_str(),
  238. aicpu::FWKAdapter::FWK_ADPT_TOPIC_DEVICE_ONLY,
  239. aicpu::FWKAdapter::FWK_ADPT_TOPIC_DEVICE_FIRST,
  240. aicpu::FWKAdapter::FWK_ADPT_TOPIC_HOST_ONLY,
  241. aicpu::FWKAdapter::FWK_ADPT_TOPIC_HOST_FIRST,
  242. type);
  243. return ACL_ERROR_GE_PARAM_INVALID;
  244. }
  245. GELOGI("Node[%s] parse ext topic type info success infoLen=%u, topic_type=%d, rts_flag=%d.",
  246. node_name_.c_str(), aicpu_ext_info->infoLen, type, topic_type_flag_);
  247. return SUCCESS;
  248. }
  249. Status AicpuExtInfoHandler::UpdateExecuteMode(bool flag) {
  250. if (bit_map_ == nullptr) {
  251. GELOGD("There is no bit_map in ext_info, no need update.");
  252. return SUCCESS;
  253. }
  254. if (flag) {
  255. *(bit_map_) |= 1;
  256. } else {
  257. *(bit_map_) &= ~1;
  258. }
  259. return SUCCESS;
  260. }
  261. Status AicpuExtInfoHandler::UpdateSessionInfo(uint64_t session_id, uint64_t kernel_id, bool sess_flag) {
  262. if (session_info_ == nullptr) {
  263. GELOGD("There is no session info in ext_info, no need update.");
  264. return SUCCESS;
  265. }
  266. session_info_->sessionId = session_id;
  267. session_info_->kernelId = kernel_id;
  268. session_info_->sessFlag = sess_flag;
  269. return SUCCESS;
  270. }
  271. Status AicpuExtInfoHandler::UpdateEventId(uint32_t event_id) {
  272. if (async_wait_ == nullptr) {
  273. REPORT_INNER_ERROR("E19999", "async_wait_ is nullptr.");
  274. GELOGE(FAILED, "[Check][async_wait_] async_wait_ is nullptr.");
  275. return FAILED;
  276. }
  277. async_wait_->waitType = 1;
  278. async_wait_->waitId = event_id;
  279. return SUCCESS;
  280. }
  281. Status AicpuExtInfoHandler::UpdateSessionInfoSessionId(uint64_t session_id) {
  282. if (session_info_ == nullptr) {
  283. GELOGD("There is no session info in ext_info, no need update.");
  284. return SUCCESS;
  285. }
  286. session_info_->sessionId = session_id;
  287. session_info_->sessFlag = true;
  288. return SUCCESS;
  289. }
  290. Status AicpuExtInfoHandler::UpdateInputShapeAndType(uint32_t input_index, const GeTensorDesc &input_desc) {
  291. GE_CHECK_LE(input_index, input_num_);
  292. const auto &shape = input_desc.GetShape();
  293. GE_CHK_STATUS_RET(UpdateShapeAndType(shape, input_desc.GetDataType(), input_shape_and_type_[input_index]),
  294. "[Update][ShapeAndType] failed, Node[%s] input[%u] .",
  295. node_name_.c_str(), input_index);
  296. return SUCCESS;
  297. }
  298. Status AicpuExtInfoHandler::UpdateOutputShapeAndType(uint32_t output_index, const GeTensorDesc &output_desc) {
  299. GE_IF_BOOL_EXEC((unknown_type_ == DEPEND_COMPUTE),
  300. REPORT_INNER_ERROR("E19999", "Node[%s] is depend compute is no need update output shape"
  301. "and type by ext.", node_name_.c_str());
  302. GELOGE(ACL_ERROR_GE_INTERNAL_ERROR,
  303. "[Check][Type]Node[%s] is depend compute is no need update output shape and type by ext.",
  304. node_name_.c_str());
  305. return ACL_ERROR_GE_INTERNAL_ERROR;);
  306. GE_CHECK_LE(output_index, output_num_);
  307. auto shape = output_desc.GetShape();
  308. // shape range need use range update shape
  309. if (unknown_type_ == DEPEND_SHAPE_RANGE) {
  310. std::vector<std::pair<int64_t, int64_t>> range;
  311. auto range_ret = output_desc.GetShapeRange(range);
  312. GE_IF_BOOL_EXEC(range_ret != GRAPH_SUCCESS,
  313. REPORT_INNER_ERROR("E19999", "Node[%s] is shape range type but get GetShapeRange failed, ret=%u",
  314. node_name_.c_str(), range_ret);
  315. GELOGE(ACL_ERROR_GE_INTERNAL_ERROR,
  316. "[Invoke][GetShapeRange]Node[%s] is shape range type but get GetShapeRange failed, ret=%u",
  317. node_name_.c_str(), range_ret);
  318. return ACL_ERROR_GE_INTERNAL_ERROR;);
  319. for (size_t k = 0; k < range.size(); ++k) {
  320. if (shape.GetDim(k) < 0 && k < range.size()) {
  321. GELOGD("Node[%s] output[%u] update dim[%zu] from %ld to range max %ld.",
  322. node_name_.c_str(), output_index, k, shape.GetDim(k), range[k].second);
  323. shape.SetDim(k, range[k].second);
  324. }
  325. }
  326. }
  327. return UpdateShapeAndType(shape, output_desc.GetDataType(), output_shape_and_type_[output_index]);
  328. }
  329. Status AicpuExtInfoHandler::GetOutputShapeAndType(uint32_t output_index, GeShape &shape, DataType &data_type) {
  330. GE_IF_BOOL_EXEC((unknown_type_ == DEPEND_COMPUTE),
  331. REPORT_INNER_ERROR("E19999",
  332. "Node[%s] is depend compute type can not get output shape and type by ext.",
  333. node_name_.c_str());
  334. GELOGE(INTERNAL_ERROR,
  335. "[Check][Type]Node[%s] is depend compute type can not get output shape and type by ext.",
  336. node_name_.c_str());
  337. return INTERNAL_ERROR;);
  338. GetShapeAndType(output_shape_and_type_[output_index], shape, data_type);
  339. return SUCCESS;
  340. }
  341. bool AicpuExtInfoHandler::IsNeedRefreshIOAddr() {
  342. return update_addr_ != nullptr && *update_addr_ != static_cast<uint32_t>(aicpu::FWKAdapter::FWK_ADPT_UPDATE_NULL);
  343. }
  344. Status AicpuExtInfoHandler::UpdateShapeAndType(const GeShape &shape, DataType data_type,
  345. AicpuShapeAndType *shape_and_type) {
  346. auto dim_num = shape.GetDimNum();
  347. if (dim_num > aicpu::FWKAdapter::kMaxShapeDims) {
  348. GELOGE(ACL_ERROR_GE_PARAM_INVALID,
  349. "[Check][DimNum]Update shape and type failed, as dim_num %zu is over max shape dims %u.",
  350. dim_num, aicpu::FWKAdapter::kMaxShapeDims);
  351. REPORT_INNER_ERROR("E19999", "Update shape and type failed, as dim_num %zu is over max shape dims %u.",
  352. dim_num, aicpu::FWKAdapter::kMaxShapeDims);
  353. return ACL_ERROR_GE_PARAM_INVALID;
  354. }
  355. size_t index = 0;
  356. for (; index < dim_num; ++index) {
  357. shape_and_type->dims[index] = shape.GetDim(index);
  358. }
  359. if (index < aicpu::FWKAdapter::kMaxShapeDims) {
  360. shape_and_type->dims[index] = kDimEndFlag;
  361. }
  362. // now only support update shape, type is not support
  363. return SUCCESS;
  364. }
  365. void AicpuExtInfoHandler::GetShapeAndType(const AicpuShapeAndType *shape_and_type,
  366. GeShape &shape,
  367. DataType &data_type) {
  368. std::vector<int64_t> dims;
  369. for (uint32_t index = 0; index < aicpu::FWKAdapter::kMaxShapeDims; ++index) {
  370. auto tmpDim = shape_and_type->dims[index];
  371. if (tmpDim == kDimEndFlag) {
  372. break;
  373. }
  374. dims.emplace_back(tmpDim);
  375. }
  376. data_type = static_cast<DataType>(shape_and_type->type);
  377. shape = GeShape(dims);
  378. }
  379. int32_t AicpuExtInfoHandler::TopicTypeToRtsFlag(int32_t topic_type) {
  380. auto it = kTopicTypeToRtsFlagMap.find(topic_type);
  381. if (it != kTopicTypeToRtsFlagMap.end()) {
  382. return it->second;
  383. }
  384. return -1;
  385. }
  386. } // namespace hybrid
  387. } // namespace ge

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