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 20 kB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  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. default:
  78. GELOGD("Node[%s] ignore infoType=%d, infoLen=%u.",
  79. node_name_.c_str(), aicpu_ext_info->infoType, aicpu_ext_info->infoLen);
  80. break;
  81. }
  82. offset += sizeof(AicpuExtInfo);
  83. offset += aicpu_ext_info->infoLen;
  84. }
  85. GE_IF_BOOL_EXEC(offset != ext_info_len_,
  86. REPORT_INNER_ERROR("E19999", "Node[%s] ext_info format error, parse not reach end,"
  87. "offset=%zu, ext_info_len=%zu.", node_name_.c_str(), offset, ext_info_len_);
  88. GELOGE(ACL_ERROR_GE_PARAM_INVALID, "[Check][Size]Node[%s] ext_info format error,"
  89. "parse not reach end, offset=%zu, ext_info_len=%zu.",
  90. node_name_.c_str(), offset, ext_info_len_);
  91. return ACL_ERROR_GE_PARAM_INVALID;);
  92. GELOGI("Node[%s] parse ext info end.", node_name_.c_str());
  93. return SUCCESS;
  94. }
  95. Status AicpuExtInfoHandler::ParseExtShapeType(AicpuExtInfo *aicpu_ext_info) {
  96. GE_IF_BOOL_EXEC(aicpu_ext_info->infoLen != sizeof(int32_t),
  97. REPORT_INNER_ERROR("E19999", "Node[%s] parse ext shape type failed as infoLen must be %zu but %u.",
  98. node_name_.c_str(), sizeof(int32_t), aicpu_ext_info->infoLen);
  99. GELOGE(ACL_ERROR_GE_PARAM_INVALID,
  100. "[Check][Size]Node[%s] parse ext shape type failed as infoLen must be %zu but %u.",
  101. node_name_.c_str(), sizeof(int32_t), aicpu_ext_info->infoLen);
  102. return ACL_ERROR_GE_PARAM_INVALID;);
  103. auto type = reinterpret_cast<const int32_t *>(aicpu_ext_info->infoMsg);
  104. GE_IF_BOOL_EXEC(*type != unknown_type_,
  105. REPORT_INNER_ERROR("E19999", "Node[%s] parse ext shape type failed as need %d but %d.",
  106. node_name_.c_str(), unknown_type_, *type);
  107. GELOGE(ACL_ERROR_GE_PARAM_INVALID,
  108. "[Check][Type]Node[%s] parse ext shape type failed as need %d but %d.",
  109. node_name_.c_str(), unknown_type_, *type);
  110. return ACL_ERROR_GE_PARAM_INVALID;);
  111. GELOGI("Node[%s] parse ext shape type success infoLen=%u.", node_name_.c_str(), aicpu_ext_info->infoLen);
  112. return SUCCESS;
  113. }
  114. Status AicpuExtInfoHandler::ParseExtInputShape(AicpuExtInfo *aicpu_ext_info) {
  115. auto need_len = input_num_ * sizeof(AicpuShapeAndType);
  116. GE_IF_BOOL_EXEC(aicpu_ext_info->infoLen != need_len,
  117. REPORT_INNER_ERROR("E19999", "Node[%s] parse ext input shape failed as infoLen must be "
  118. "input_num[%u]*sizeof(ShapeAndType)[%zu] but %u.",
  119. node_name_.c_str(), input_num_, sizeof(AicpuShapeAndType),
  120. aicpu_ext_info->infoLen);
  121. GELOGE(ACL_ERROR_GE_PARAM_INVALID,
  122. "[Check][DataLen]Node[%s] parse ext input shape failed as infoLen must be "
  123. "input_num[%u]*sizeof(ShapeAndType)[%zu] but %u.",
  124. node_name_.c_str(), input_num_, sizeof(AicpuShapeAndType), aicpu_ext_info->infoLen);
  125. return ACL_ERROR_GE_PARAM_INVALID;);
  126. auto input = reinterpret_cast<AicpuShapeAndType *>(aicpu_ext_info->infoMsg);
  127. for (uint32_t index = 0; index < input_num_; ++index) {
  128. input_shape_and_type_.emplace_back(&input[index]);
  129. }
  130. GELOGI("Node[%s] parse ext input shape success infoLen=%u.", node_name_.c_str(), aicpu_ext_info->infoLen);
  131. return SUCCESS;
  132. }
  133. Status AicpuExtInfoHandler::ParseExtOutputShape(AicpuExtInfo *aicpu_ext_info) {
  134. if (unknown_type_ == DEPEND_COMPUTE) {
  135. GELOGD("Node[%s] is depend compute type no need ext output shape, ignore it, infoLen=%u.",
  136. node_name_.c_str(), aicpu_ext_info->infoLen);
  137. return SUCCESS;
  138. }
  139. auto need_len = output_num_ * sizeof(AicpuShapeAndType);
  140. GE_IF_BOOL_EXEC(aicpu_ext_info->infoLen != need_len,
  141. REPORT_INNER_ERROR("E19999", "Node[%s] parse ext output shape failed as infoLen must be "
  142. "output_num[%u]*sizeof(ShapeAndType)[%zu] but %u.",
  143. node_name_.c_str(), output_num_, sizeof(AicpuShapeAndType),
  144. aicpu_ext_info->infoLen);
  145. GELOGE(ACL_ERROR_GE_PARAM_INVALID,
  146. "[Check][DataLen]Node[%s] parse ext output shape failed as infoLen must be "
  147. "output_num[%u]*sizeof(ShapeAndType)[%zu] but %u.",
  148. node_name_.c_str(), output_num_, sizeof(AicpuShapeAndType), aicpu_ext_info->infoLen);
  149. return ACL_ERROR_GE_PARAM_INVALID;);
  150. auto output = reinterpret_cast<AicpuShapeAndType *>(aicpu_ext_info->infoMsg);
  151. for (uint32_t index = 0; index < output_num_; ++index) {
  152. output_shape_and_type_.emplace_back(&output[index]);
  153. }
  154. GELOGI("Node[%s] parse ext output shape success infoLen=%u.", node_name_.c_str(), aicpu_ext_info->infoLen);
  155. return SUCCESS;
  156. }
  157. Status AicpuExtInfoHandler::ParseExtSessionInfo(AicpuExtInfo *aicpu_ext_info) {
  158. GE_IF_BOOL_EXEC(aicpu_ext_info->infoLen != sizeof(AicpuSessionInfo),
  159. REPORT_INNER_ERROR("E19999",
  160. "Node[%s] parse ext session info failed as infoLen must be %zu but %u.",
  161. node_name_.c_str(), sizeof(SessionInfo), aicpu_ext_info->infoLen);
  162. GELOGE(ACL_ERROR_GE_PARAM_INVALID,
  163. "[Check][DataLen]Node[%s] parse ext session info failed as infoLen must be %zu but %u.",
  164. node_name_.c_str(), sizeof(SessionInfo), aicpu_ext_info->infoLen);
  165. return ACL_ERROR_GE_PARAM_INVALID;);
  166. session_info_ = reinterpret_cast<AicpuSessionInfo *>(aicpu_ext_info->infoMsg);
  167. GELOGI("Node[%s] parse session info success infoLen=%u.", node_name_.c_str(), aicpu_ext_info->infoLen);
  168. return SUCCESS;
  169. }
  170. Status AicpuExtInfoHandler::ParseExtBitMap(AicpuExtInfo *aicpu_ext_info) {
  171. GE_IF_BOOL_EXEC(aicpu_ext_info->infoLen != sizeof(uint64_t),
  172. REPORT_INNER_ERROR("E19999",
  173. "Node[%s] parse bit_map info failed as infoLen must be %zu but %u.",
  174. node_name_.c_str(), sizeof(uint64_t), aicpu_ext_info->infoLen);
  175. GELOGE(PARAM_INVALID,
  176. "[Check][DataLen]Node[%s] parse bit_map info failed as infoLen must be %zu but %u.",
  177. node_name_.c_str(), sizeof(uint64_t), aicpu_ext_info->infoLen);
  178. return PARAM_INVALID;);
  179. bit_map_ = reinterpret_cast<uint64_t *>(aicpu_ext_info->infoMsg);
  180. GELOGI("Node[%s] bit_map info success infoLen=%u.", node_name_.c_str(), aicpu_ext_info->infoLen);
  181. return SUCCESS;
  182. }
  183. Status AicpuExtInfoHandler::ParseExtUpdateAddr(AicpuExtInfo *aicpu_ext_info) {
  184. GE_IF_BOOL_EXEC(aicpu_ext_info->infoLen != sizeof(uint32_t),
  185. REPORT_INNER_ERROR("E19999",
  186. "Node[%s] parse update_addr info failed as infoLen must be %zu but %u.",
  187. node_name_.c_str(), sizeof(uint32_t), aicpu_ext_info->infoLen);
  188. GELOGE(PARAM_INVALID,
  189. "[Check][DataLen]Node[%s] parse update_addr info failed as infoLen must be %zu but %u.",
  190. node_name_.c_str(), sizeof(uint32_t), aicpu_ext_info->infoLen);
  191. return PARAM_INVALID;);
  192. update_addr_ = reinterpret_cast<uint32_t *>(aicpu_ext_info->infoMsg);
  193. GELOGI("Node[%s] update_addr info success infoLen=%u.", node_name_.c_str(), aicpu_ext_info->infoLen);
  194. return SUCCESS;
  195. }
  196. Status AicpuExtInfoHandler::ParseExtTopicType(AicpuExtInfo *aicpu_ext_info) {
  197. if (aicpu_ext_info->infoLen != sizeof(int32_t)) {
  198. REPORT_INNER_ERROR("E19999",
  199. "Node[%s] parse topic_type info failed as infoLen must be %zu but %u.",
  200. node_name_.c_str(), sizeof(int32_t), aicpu_ext_info->infoLen);
  201. GELOGE(ACL_ERROR_GE_PARAM_INVALID,
  202. "[Check][DataLen]Node[%s] parse topic_type info failed as infoLen must be %zu but %u.",
  203. node_name_.c_str(), sizeof(int32_t), aicpu_ext_info->infoLen);
  204. return ACL_ERROR_GE_PARAM_INVALID;
  205. }
  206. GE_CHECK_NOTNULL(aicpu_ext_info->infoMsg);
  207. auto type_info = reinterpret_cast<int32_t *>(aicpu_ext_info->infoMsg);
  208. int32_t type = *type_info;
  209. topic_type_flag_ = TopicTypeToRtsFlag(type);
  210. if (topic_type_flag_ == -1) {
  211. REPORT_INNER_ERROR("E19999", "Node[%s] parse ext topic type failed as need %d %d %d %d but %d.",
  212. node_name_.c_str(),
  213. aicpu::FWKAdapter::FWK_ADPT_TOPIC_DEVICE_ONLY,
  214. aicpu::FWKAdapter::FWK_ADPT_TOPIC_DEVICE_FIRST,
  215. aicpu::FWKAdapter::FWK_ADPT_TOPIC_HOST_ONLY,
  216. aicpu::FWKAdapter::FWK_ADPT_TOPIC_HOST_FIRST,
  217. type);
  218. GELOGE(ACL_ERROR_GE_PARAM_INVALID,
  219. "[Check][Type]Node[%s] parse ext shape type failed as need %d %d %d %d but %d.",
  220. node_name_.c_str(),
  221. aicpu::FWKAdapter::FWK_ADPT_TOPIC_DEVICE_ONLY,
  222. aicpu::FWKAdapter::FWK_ADPT_TOPIC_DEVICE_FIRST,
  223. aicpu::FWKAdapter::FWK_ADPT_TOPIC_HOST_ONLY,
  224. aicpu::FWKAdapter::FWK_ADPT_TOPIC_HOST_FIRST,
  225. type);
  226. return ACL_ERROR_GE_PARAM_INVALID;
  227. }
  228. GELOGI("Node[%s] parse ext topic type info success infoLen=%u, topic_type=%d, rts_flag=%d.",
  229. node_name_.c_str(), aicpu_ext_info->infoLen, type, topic_type_flag_);
  230. return SUCCESS;
  231. }
  232. Status AicpuExtInfoHandler::UpdateExecuteMode(bool flag) {
  233. if (bit_map_ == nullptr) {
  234. GELOGD("There is no bit_map in ext_info, no need update.");
  235. return SUCCESS;
  236. }
  237. if (flag) {
  238. *(bit_map_) |= 1;
  239. } else {
  240. *(bit_map_) &= ~1;
  241. }
  242. return SUCCESS;
  243. }
  244. Status AicpuExtInfoHandler::UpdateSessionInfo(uint64_t session_id, uint64_t kernel_id, bool sess_flag) {
  245. if (session_info_ == nullptr) {
  246. GELOGD("There is no session info in ext_info, no need update.");
  247. return SUCCESS;
  248. }
  249. session_info_->sessionId = session_id;
  250. session_info_->kernelId = kernel_id;
  251. session_info_->sessFlag = sess_flag;
  252. return SUCCESS;
  253. }
  254. Status AicpuExtInfoHandler::UpdateSessionInfoSessionId(uint64_t session_id) {
  255. if (session_info_ == nullptr) {
  256. GELOGD("There is no session info in ext_info, no need update.");
  257. return SUCCESS;
  258. }
  259. session_info_->sessionId = session_id;
  260. session_info_->sessFlag = true;
  261. return SUCCESS;
  262. }
  263. Status AicpuExtInfoHandler::UpdateInputShapeAndType(uint32_t input_index, const GeTensorDesc &input_desc) {
  264. GE_CHECK_LE(input_index, input_num_);
  265. const auto &shape = input_desc.GetShape();
  266. GE_CHK_STATUS_RET(UpdateShapeAndType(shape, input_desc.GetDataType(), input_shape_and_type_[input_index]),
  267. "[Update][ShapeAndType] failed, Node[%s] input[%u] .",
  268. node_name_.c_str(), input_index);
  269. return SUCCESS;
  270. }
  271. Status AicpuExtInfoHandler::UpdateOutputShapeAndType(uint32_t output_index, const GeTensorDesc &output_desc) {
  272. GE_IF_BOOL_EXEC((unknown_type_ == DEPEND_COMPUTE),
  273. REPORT_INNER_ERROR("E19999", "Node[%s] is depend compute is no need update output shape"
  274. "and type by ext.", node_name_.c_str());
  275. GELOGE(ACL_ERROR_GE_INTERNAL_ERROR,
  276. "[Check][Type]Node[%s] is depend compute is no need update output shape and type by ext.",
  277. node_name_.c_str());
  278. return ACL_ERROR_GE_INTERNAL_ERROR;);
  279. GE_CHECK_LE(output_index, output_num_);
  280. auto shape = output_desc.GetShape();
  281. // shape range need use range update shape
  282. if (unknown_type_ == DEPEND_SHAPE_RANGE) {
  283. std::vector<std::pair<int64_t, int64_t>> range;
  284. auto range_ret = output_desc.GetShapeRange(range);
  285. GE_IF_BOOL_EXEC(range_ret != GRAPH_SUCCESS,
  286. REPORT_INNER_ERROR("E19999", "Node[%s] is shape range type but get GetShapeRange failed, ret=%u",
  287. node_name_.c_str(), range_ret);
  288. GELOGE(ACL_ERROR_GE_INTERNAL_ERROR,
  289. "[Invoke][GetShapeRange]Node[%s] is shape range type but get GetShapeRange failed, ret=%u",
  290. node_name_.c_str(), range_ret);
  291. return ACL_ERROR_GE_INTERNAL_ERROR;);
  292. for (size_t k = 0; k < range.size(); ++k) {
  293. if (shape.GetDim(k) < 0 && k < range.size()) {
  294. GELOGD("Node[%s] output[%u] update dim[%zu] from %ld to range max %ld.",
  295. node_name_.c_str(), output_index, k, shape.GetDim(k), range[k].second);
  296. shape.SetDim(k, range[k].second);
  297. }
  298. }
  299. }
  300. return UpdateShapeAndType(shape, output_desc.GetDataType(), output_shape_and_type_[output_index]);
  301. }
  302. Status AicpuExtInfoHandler::GetOutputShapeAndType(uint32_t output_index, GeShape &shape, DataType &data_type) {
  303. GE_IF_BOOL_EXEC((unknown_type_ == DEPEND_COMPUTE),
  304. REPORT_INNER_ERROR("E19999",
  305. "Node[%s] is depend compute type can not get output shape and type by ext.",
  306. node_name_.c_str());
  307. GELOGE(INTERNAL_ERROR,
  308. "[Check][Type]Node[%s] is depend compute type can not get output shape and type by ext.",
  309. node_name_.c_str());
  310. return INTERNAL_ERROR;);
  311. GetShapeAndType(output_shape_and_type_[output_index], shape, data_type);
  312. return SUCCESS;
  313. }
  314. bool AicpuExtInfoHandler::IsNeedRefreshIOAddr() {
  315. return update_addr_ != nullptr && *update_addr_ != static_cast<uint32_t>(aicpu::FWKAdapter::FWK_ADPT_UPDATE_NULL);
  316. }
  317. Status AicpuExtInfoHandler::UpdateShapeAndType(const GeShape &shape, DataType data_type,
  318. AicpuShapeAndType *shape_and_type) {
  319. auto dim_num = shape.GetDimNum();
  320. if (dim_num > aicpu::FWKAdapter::kMaxShapeDims) {
  321. GELOGE(ACL_ERROR_GE_PARAM_INVALID,
  322. "[Check][DimNum]Update shape and type failed, as dim_num %zu is over max shape dims %u.",
  323. dim_num, aicpu::FWKAdapter::kMaxShapeDims);
  324. REPORT_INNER_ERROR("E19999", "Update shape and type failed, as dim_num %zu is over max shape dims %u.",
  325. dim_num, aicpu::FWKAdapter::kMaxShapeDims);
  326. return ACL_ERROR_GE_PARAM_INVALID;
  327. }
  328. size_t index = 0;
  329. for (; index < dim_num; ++index) {
  330. shape_and_type->dims[index] = shape.GetDim(index);
  331. }
  332. if (index < aicpu::FWKAdapter::kMaxShapeDims) {
  333. shape_and_type->dims[index] = kDimEndFlag;
  334. }
  335. // now only support update shape, type is not support
  336. return SUCCESS;
  337. }
  338. void AicpuExtInfoHandler::GetShapeAndType(const AicpuShapeAndType *shape_and_type,
  339. GeShape &shape,
  340. DataType &data_type) {
  341. std::vector<int64_t> dims;
  342. for (uint32_t index = 0; index < aicpu::FWKAdapter::kMaxShapeDims; ++index) {
  343. auto tmpDim = shape_and_type->dims[index];
  344. if (tmpDim == kDimEndFlag) {
  345. break;
  346. }
  347. dims.emplace_back(tmpDim);
  348. }
  349. data_type = static_cast<DataType>(shape_and_type->type);
  350. shape = GeShape(dims);
  351. }
  352. int32_t AicpuExtInfoHandler::TopicTypeToRtsFlag(int32_t topic_type) {
  353. auto it = kTopicTypeToRtsFlagMap.find(topic_type);
  354. if (it != kTopicTypeToRtsFlagMap.end()) {
  355. return it->second;
  356. }
  357. return -1;
  358. }
  359. } // namespace hybrid
  360. } // namespace ge

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