You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

single_op_parser.cc 19 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. /**
  2. * Copyright 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_parser.h"
  17. #include <vector>
  18. #include <algorithm>
  19. #include <fstream>
  20. #include <sstream>
  21. #include <nlohmann/json.hpp>
  22. #include "framework/common/debug/ge_log.h"
  23. #include "common/util/error_manager/error_manager.h"
  24. #include "common/ge_inner_error_codes.h"
  25. #include "framework/common/util.h"
  26. #include "graph/utils/tensor_utils.h"
  27. #include "graph/utils/op_desc_utils.h"
  28. #include "graph/operator_factory_impl.h"
  29. using Json = nlohmann::json;
  30. using std::string;
  31. using std::vector;
  32. using std::map;
  33. namespace ge {
  34. namespace {
  35. constexpr char const *kKeyOp = "op";
  36. constexpr char const *kKeyInputDesc = "input_desc";
  37. constexpr char const *kKeyOutputDesc = "output_desc";
  38. constexpr char const *kKeyAttr = "attr";
  39. constexpr char const *kKeyName = "name";
  40. constexpr char const *kKeyType = "type";
  41. constexpr char const *kKeyShape = "shape";
  42. constexpr char const *kKeyShapeRange = "shape_range";
  43. constexpr char const *kKeyValue = "value";
  44. constexpr char const *kKeyFormat = "format";
  45. constexpr char const *kFileSuffix = ".om";
  46. constexpr int kDumpJsonIndent = 2;
  47. constexpr int kShapeRangePairSize = 2;
  48. constexpr int kShapeRangeLow = 0;
  49. constexpr int kShapeRangeHigh = 1;
  50. map<string, GeAttrValue::ValueType> kAttrTypeDict = {
  51. {"bool", GeAttrValue::VT_BOOL},
  52. {"int", GeAttrValue::VT_INT},
  53. {"float", GeAttrValue::VT_FLOAT},
  54. {"string", GeAttrValue::VT_STRING},
  55. {"list_bool", GeAttrValue::VT_LIST_BOOL},
  56. {"list_int", GeAttrValue::VT_LIST_INT},
  57. {"list_float", GeAttrValue::VT_LIST_FLOAT},
  58. {"list_string", GeAttrValue::VT_LIST_STRING},
  59. {"list_list_int", GeAttrValue::VT_LIST_LIST_INT},
  60. {"data_type", GeAttrValue::VT_DATA_TYPE},
  61. };
  62. map<string, DataType> kDataTypeDict = {
  63. {"bool", DT_BOOL},
  64. {"int8", DT_INT8},
  65. {"uint8", DT_UINT8},
  66. {"int16", DT_INT16},
  67. {"uint16", DT_UINT16},
  68. {"int32", DT_INT32},
  69. {"uint32", DT_UINT32},
  70. {"int64", DT_INT64},
  71. {"uint64", DT_UINT64},
  72. {"float16", DT_FLOAT16},
  73. {"half", DT_FLOAT16},
  74. {"fp16", DT_FLOAT16},
  75. {"float", DT_FLOAT},
  76. {"float32", DT_FLOAT},
  77. {"double", DT_DOUBLE},
  78. };
  79. map<string, Format> kFormatDict = {
  80. {"nchw", FORMAT_NCHW},
  81. {"nhwc", FORMAT_NHWC},
  82. {"nd", FORMAT_ND},
  83. {"fractal_nz", FORMAT_FRACTAL_NZ},
  84. {"fractal_z", FORMAT_FRACTAL_Z},
  85. {"nc1hwc0", FORMAT_NC1HWC0},
  86. };
  87. }
  88. template<typename T>
  89. void SetAttrValue(const Json &j, SingleOpAttr &attr) {
  90. attr.value.SetValue<T>(j.at(kKeyValue).get<T>());
  91. }
  92. template<typename T>
  93. T GetValue(const map<string, T> &dict, string &key, T default_val) {
  94. transform(key.begin(), key.end(), key.begin(), ::tolower);
  95. auto it = dict.find(key);
  96. if (it == dict.end()) {
  97. return default_val;
  98. }
  99. return it->second;
  100. }
  101. void from_json(const Json &j, SingleOpTensorDesc &desc) {
  102. desc.dims = j.at(kKeyShape).get<vector<int64_t>>();
  103. auto it = j.find(kKeyShapeRange);
  104. if (it != j.end()) {
  105. desc.dim_ranges = j.at(kKeyShapeRange).get<vector<std::vector<int64_t>>>();
  106. }
  107. string format_str = j.at(kKeyFormat).get<string>();
  108. string type_str = j.at(kKeyType).get<string>();
  109. desc.format = GetValue(kFormatDict, format_str, FORMAT_RESERVED);
  110. desc.type = GetValue(kDataTypeDict, type_str, DT_UNDEFINED);
  111. auto tensor_name = j.find(kKeyName);
  112. if (tensor_name != j.end()) {
  113. desc.name = tensor_name->get<string>();
  114. }
  115. }
  116. void from_json(const Json &j, SingleOpAttr &attr) {
  117. attr.name = j.at(kKeyName).get<string>();
  118. attr.type = j.at(kKeyType).get<string>();
  119. auto it = kAttrTypeDict.find(attr.type);
  120. if (it == kAttrTypeDict.end()) {
  121. GELOGE(UNSUPPORTED, "Parse attr[%s] failed. Unsupported type: %s", attr.name.c_str(), attr.type.c_str());
  122. return;
  123. }
  124. switch (it->second) {
  125. case GeAttrValue::VT_BOOL:
  126. SetAttrValue<bool>(j, attr);
  127. break;
  128. case GeAttrValue::VT_INT:
  129. SetAttrValue<int64_t>(j, attr);
  130. break;
  131. case GeAttrValue::VT_FLOAT:
  132. SetAttrValue<float>(j, attr);
  133. break;
  134. case GeAttrValue::VT_STRING:
  135. SetAttrValue<string>(j, attr);
  136. break;
  137. case GeAttrValue::VT_LIST_BOOL:
  138. SetAttrValue<vector<bool>>(j, attr);
  139. break;
  140. case GeAttrValue::VT_LIST_INT:
  141. SetAttrValue<vector<int64_t>>(j, attr);
  142. break;
  143. case GeAttrValue::VT_LIST_FLOAT:
  144. SetAttrValue<vector<float>>(j, attr);
  145. break;
  146. case GeAttrValue::VT_LIST_STRING:
  147. SetAttrValue<vector<string>>(j, attr);
  148. break;
  149. case GeAttrValue::VT_LIST_LIST_INT:
  150. SetAttrValue<vector<vector<int64_t>>>(j, attr);
  151. break;
  152. case GeAttrValue::VT_DATA_TYPE:
  153. SetAttrValue<DataType>(j, attr);
  154. break;
  155. default:
  156. GELOGE(UNSUPPORTED, "Parse attr[%s] failed. Unsupported type: %s", attr.name.c_str(), attr.type.c_str());
  157. break;
  158. }
  159. }
  160. void from_json(const Json &j, SingleOpDesc &desc) {
  161. desc.op = j.at(kKeyOp).get<string>();
  162. auto input_desc = j.find(kKeyInputDesc);
  163. if (input_desc != j.end()) {
  164. desc.input_desc = input_desc->get<vector<SingleOpTensorDesc>>();
  165. }
  166. auto output_desc = j.find(kKeyOutputDesc);
  167. if (output_desc != j.end()) {
  168. desc.output_desc = output_desc->get<vector<SingleOpTensorDesc>>();
  169. }
  170. auto attr_field = j.find(kKeyAttr);
  171. if (attr_field != j.end()) {
  172. desc.attrs = attr_field->get<vector<SingleOpAttr>>();
  173. }
  174. }
  175. Status SingleOpParser::ReadJsonFile(const std::string &file, Json &json_obj) {
  176. std::string real_path = RealPath(file.c_str());
  177. if (real_path.empty()) {
  178. ErrorManager::GetInstance().ATCReportErrMessage("E10023", {"value"}, {file});
  179. GELOGE(FAILED, "Input parameter[--singleop]'s value[%s] is not a valid path.", file.c_str());
  180. return INTERNAL_ERROR;
  181. }
  182. std::ifstream ifs(real_path);
  183. if (!ifs.is_open()) {
  184. ErrorManager::GetInstance().ATCReportErrMessage("E10024", {"value"}, {file});
  185. GELOGE(FAILED, "Open file[%s] provided in input parameter[--singleop] failed.", file.c_str());
  186. return FAILED;
  187. }
  188. try {
  189. ifs >> json_obj;
  190. } catch (const std::exception &e) {
  191. ErrorManager::GetInstance().ATCReportErrMessage("E10025", {"realpath", "errmsg"}, {real_path, e.what()});
  192. GELOGE(PARAM_INVALID, "Parse file[%s] provided in input parameter[--singleop] failed, exception = %s.",
  193. real_path.c_str(), e.what());
  194. return PARAM_INVALID;
  195. }
  196. ifs.close();
  197. return SUCCESS;
  198. }
  199. bool SingleOpParser::Validate(const SingleOpDesc &op_desc) {
  200. if (op_desc.op.empty()) {
  201. ErrorManager::GetInstance().ATCReportErrMessage("E10026");
  202. GELOGE(PARAM_INVALID, "Op name is empty");
  203. return false;
  204. }
  205. int index = 0;
  206. for (auto &tensor_desc : op_desc.input_desc) {
  207. if (tensor_desc.type == DT_UNDEFINED) {
  208. ErrorManager::GetInstance().ATCReportErrMessage("E10027", {"input", "index"}, {"input", std::to_string(index)});
  209. GELOGE(false, "Input's dataType is invalid when the index is %d", index);
  210. return false;
  211. }
  212. if (tensor_desc.format == FORMAT_RESERVED) {
  213. ErrorManager::GetInstance().ATCReportErrMessage("E10028", {"input", "index"}, {"input", std::to_string(index)});
  214. GELOGE(PARAM_INVALID, "Input's format is invalid when the index is %d", index);
  215. return false;
  216. }
  217. ++index;
  218. }
  219. index = 0;
  220. for (auto &tensor_desc : op_desc.output_desc) {
  221. if (tensor_desc.type == DT_UNDEFINED) {
  222. ErrorManager::GetInstance().ATCReportErrMessage("E10027", {"input", "index"}, {"output", std::to_string(index)});
  223. GELOGE(PARAM_INVALID, "Output's dataType is invalid when the index is %d", index);
  224. return false;
  225. }
  226. if (tensor_desc.format == FORMAT_RESERVED) {
  227. ErrorManager::GetInstance().ATCReportErrMessage("E10028", {"input", "index"}, {"output", std::to_string(index)});
  228. GELOGE(PARAM_INVALID, "Output's format is invalid when the index is %d", index);
  229. return false;
  230. }
  231. ++index;
  232. }
  233. for (auto &attr : op_desc.attrs) {
  234. if (attr.name.empty()) {
  235. ErrorManager::GetInstance().ATCReportErrMessage("E10029");
  236. GELOGE(PARAM_INVALID, "attr name is empty");
  237. return false;
  238. }
  239. if (attr.value.IsEmpty()) {
  240. ErrorManager::GetInstance().ATCReportErrMessage("E10030", {"attrname"}, {attr.name});
  241. GELOGE(PARAM_INVALID, "Parse attr \"%s\" failed. ", attr.name.c_str());
  242. return false;
  243. }
  244. }
  245. return true;
  246. }
  247. std::unique_ptr<OpDesc> SingleOpParser::CreateOpDesc(const string &op_type) {
  248. return std::unique_ptr<OpDesc>(new(std::nothrow) OpDesc(op_type, op_type));
  249. }
  250. Status SingleOpParser::ConvertToBuildParam(int index,
  251. const SingleOpDesc &single_op_desc,
  252. SingleOpBuildParam &build_param) {
  253. auto op_desc = CreateOpDesc(single_op_desc.op);
  254. if (op_desc == nullptr) {
  255. GELOGE(MEMALLOC_FAILED, "Failed to create instance of opDesc");
  256. return MEMALLOC_FAILED;
  257. }
  258. std::stringstream file_name;
  259. file_name << index;
  260. file_name << "_" << single_op_desc.op;
  261. for (auto &desc : single_op_desc.input_desc) {
  262. file_name << "_" << desc.type << "_" << desc.format;
  263. for (auto dim : desc.dims) {
  264. file_name << "_" << dim;
  265. }
  266. GeTensorDesc ge_tensor_desc(GeShape(desc.dims),
  267. desc.format,
  268. desc.type);
  269. ge_tensor_desc.SetOriginFormat(desc.format);
  270. GE_CHK_STATUS_RET_NOLOG(SetShapeRange(op_desc->GetName(), desc, ge_tensor_desc));
  271. TensorUtils::SetRealDimCnt(ge_tensor_desc, desc.dims.size());
  272. TensorUtils::SetInputTensor(ge_tensor_desc, true);
  273. TensorUtils::SetOutputTensor(ge_tensor_desc, false);
  274. if (desc.name.empty()) {
  275. op_desc->AddInputDesc(ge_tensor_desc);
  276. } else {
  277. op_desc->AddInputDesc(desc.name, ge_tensor_desc);
  278. }
  279. build_param.inputs.emplace_back(ge_tensor_desc);
  280. }
  281. for (auto &desc : single_op_desc.output_desc) {
  282. file_name << "_" << desc.type << "_" << desc.format;
  283. for (auto dim : desc.dims) {
  284. file_name << "_" << dim;
  285. }
  286. GeTensorDesc ge_tensor_desc(GeShape(desc.dims),
  287. desc.format,
  288. desc.type);
  289. ge_tensor_desc.SetOriginFormat(desc.format);
  290. GE_CHK_STATUS_RET_NOLOG(SetShapeRange(op_desc->GetName(), desc, ge_tensor_desc));
  291. TensorUtils::SetRealDimCnt(ge_tensor_desc, desc.dims.size());
  292. TensorUtils::SetInputTensor(ge_tensor_desc, false);
  293. TensorUtils::SetOutputTensor(ge_tensor_desc, true);
  294. if (desc.name.empty()) {
  295. op_desc->AddOutputDesc(ge_tensor_desc);
  296. } else {
  297. op_desc->AddOutputDesc(desc.name, ge_tensor_desc);
  298. }
  299. build_param.outputs.emplace_back(ge_tensor_desc);
  300. }
  301. for (const auto &attr : single_op_desc.attrs) {
  302. op_desc->SetAttr(attr.name, attr.value);
  303. }
  304. if (VerifyOpInputOutputSizeByIr(*op_desc) != SUCCESS) {
  305. GELOGE(PARAM_INVALID, "Verify op [%s] input or output size failed.", op_desc->GetType().c_str());
  306. return PARAM_INVALID;
  307. }
  308. file_name << kFileSuffix;
  309. build_param.file_name = file_name.str();
  310. build_param.op_desc.reset(op_desc.release());
  311. return SUCCESS;
  312. }
  313. Status SingleOpParser::VerifyOpInputOutputSizeByIr(const OpDesc &current_op_desc) {
  314. ge::Operator operator_ir = ge::OperatorFactory::CreateOperator("tmp_operator", current_op_desc.GetType());
  315. if (!operator_ir.IsEmpty()) {
  316. auto opdesc_ir = ge::OpDescUtils::GetOpDescFromOperator(operator_ir);
  317. GE_CHECK_NOTNULL(opdesc_ir);
  318. size_t current_opdesc_inputs_num = current_op_desc.GetInputsSize();
  319. size_t ir_opdesc_inputs_num = opdesc_ir->GetInputsSize();
  320. if (current_opdesc_inputs_num < ir_opdesc_inputs_num) {
  321. string reason = "is smaller than the ir needed input size " + std::to_string(ir_opdesc_inputs_num);
  322. ErrorManager::GetInstance().ATCReportErrMessage("E19014", {"opname", "value", "reason"},
  323. {current_op_desc.GetName(), "input size " + std::to_string(current_opdesc_inputs_num), reason});
  324. GELOGE(PARAM_INVALID, "This op [%s] input size %zu is smaller than the ir needed input size %zu",
  325. current_op_desc.GetName().c_str(), current_opdesc_inputs_num, ir_opdesc_inputs_num);
  326. return PARAM_INVALID;
  327. }
  328. size_t current_opdesc_outputs_num = current_op_desc.GetOutputsSize();
  329. size_t ir_opdesc_outputs_num = opdesc_ir->GetOutputsSize();
  330. if (current_opdesc_outputs_num < ir_opdesc_outputs_num) {
  331. string reason = "is smaller than the ir needed output size " + std::to_string(ir_opdesc_outputs_num);
  332. ErrorManager::GetInstance().ATCReportErrMessage("E19014", {"opname", "value", "reason"},
  333. {current_op_desc.GetName(), "output size " + std::to_string(current_opdesc_outputs_num), reason});
  334. GELOGE(PARAM_INVALID, "This op [%s] output size %zu is smaller than the ir needed output size %zu",
  335. current_op_desc.GetName().c_str(), current_opdesc_outputs_num, ir_opdesc_outputs_num);
  336. return PARAM_INVALID;
  337. }
  338. }
  339. return SUCCESS;
  340. }
  341. Status SingleOpParser::SetShapeRange(const std::string &op_name,
  342. const SingleOpTensorDesc &tensor_desc,
  343. GeTensorDesc &ge_tensor_desc) {
  344. auto num_shape_ranges = tensor_desc.dim_ranges.size();
  345. GELOGD("Number of shape ranges = %zu", num_shape_ranges);
  346. auto it = std::find(tensor_desc.dims.begin(), tensor_desc.dims.end(), ge::UNKNOWN_DIM_NUM);
  347. if (it != tensor_desc.dims.end()) {
  348. if (tensor_desc.dims != ge::UNKNOWN_RANK) {
  349. ErrorManager::GetInstance().ATCReportErrMessage("E19014", {"opname", "value", "reason"},
  350. {op_name,
  351. "shape",
  352. "has unknown rank but dim size is not one"});
  353. GELOGE(PARAM_INVALID, "Invalid tensor shape: [%s]", ge_tensor_desc.MutableShape().ToString().c_str());
  354. return PARAM_INVALID;
  355. }
  356. if (!tensor_desc.dim_ranges.empty()) {
  357. ErrorManager::GetInstance().ATCReportErrMessage("E19014", {"opname", "value", "reason"},
  358. {op_name,
  359. "shape range",
  360. "is not needed while the rank the shape is unknown"});
  361. GELOGE(PARAM_INVALID, "Shape range is not needed while the rank the shape is unknown");
  362. return PARAM_INVALID;
  363. }
  364. GELOGD("Shape is unknown rank, do not set shape range");
  365. return SUCCESS;
  366. }
  367. std::vector<std::pair<int64_t, int64_t>> shape_range;
  368. size_t range_index = 0;
  369. for (auto dim : tensor_desc.dims) {
  370. if (dim >= 0) {
  371. shape_range.emplace_back(dim, dim);
  372. GELOGD("Adding shape range: [%ld, %ld]", dim, dim);
  373. } else {
  374. GELOGD("To get shape range by index = %zu", range_index);
  375. if (range_index >= num_shape_ranges) {
  376. string reason = "is smaller than the unknown dim size " + std::to_string(++range_index);
  377. ErrorManager::GetInstance().ATCReportErrMessage("E19014", {"opname", "value", "reason"},
  378. {op_name,
  379. "shape range size " + std::to_string(num_shape_ranges),
  380. reason});
  381. GELOGE(PARAM_INVALID, "The number of shape_range mismatches that of unknown dims.");
  382. return PARAM_INVALID;
  383. }
  384. auto &range = tensor_desc.dim_ranges[range_index];
  385. if (range.size() != kShapeRangePairSize) {
  386. string reason = "has " + std::to_string(range.size()) + " item(s)";
  387. ErrorManager::GetInstance().ATCReportErrMessage("E19014", {"opname", "value", "reason"},
  388. {op_name,
  389. "shape range " + std::to_string(range_index),
  390. reason});
  391. GELOGE(PARAM_INVALID, "Invalid shape range entry. index = %zu, size = %zu", range_index, range.size());
  392. return PARAM_INVALID;
  393. }
  394. shape_range.emplace_back(range[kShapeRangeLow], range[kShapeRangeHigh]);
  395. GELOGD("Adding shape range: [%ld, %ld]", range[kShapeRangeLow], range[kShapeRangeHigh]);
  396. ++range_index;
  397. }
  398. }
  399. if (num_shape_ranges != range_index) {
  400. string reason = "is greater than the unknown dim size " + std::to_string(range_index);
  401. ErrorManager::GetInstance().ATCReportErrMessage("E19014", {"opname", "value", "reason"},
  402. {op_name,
  403. "shape range size " + std::to_string(num_shape_ranges),
  404. reason});
  405. GELOGE(PARAM_INVALID,
  406. "The number of shape_range(%zu) mismatches that of unknown dims(%zu).",
  407. num_shape_ranges,
  408. range_index);
  409. return PARAM_INVALID;
  410. }
  411. if (range_index > 0) {
  412. ge_tensor_desc.SetShapeRange(shape_range);
  413. }
  414. return SUCCESS;
  415. }
  416. Status SingleOpParser::ParseSingleOpList(const std::string &file, std::vector<SingleOpBuildParam> &op_list) {
  417. Json single_op_list_json;
  418. auto ret = ReadJsonFile(file, single_op_list_json);
  419. if (ret != SUCCESS) {
  420. return ret;
  421. }
  422. int index = 0;
  423. for (const Json &single_op_json : single_op_list_json) {
  424. SingleOpDesc single_op_desc;
  425. try {
  426. GELOGI("Parsing op[%d], jsonStr = %s", index, single_op_json.dump(kDumpJsonIndent).c_str());
  427. single_op_desc = single_op_json;
  428. } catch (const nlohmann::json::exception &e) {
  429. ErrorManager::GetInstance().ATCReportErrMessage("E10032", {"index", "jsonfile", "exception"},
  430. {std::to_string(index), file, e.what()});
  431. GELOGE(PARAM_INVALID, "Parse the index[%d] of op failed when read json file[%s], exception %s",
  432. index, file.c_str(), e.what());
  433. return PARAM_INVALID;
  434. }
  435. if (!Validate(single_op_desc)) {
  436. GELOGE(PARAM_INVALID, "Validate the index[%d] of op failed when read json file[%s].", index, file.c_str());
  437. return PARAM_INVALID;
  438. }
  439. SingleOpBuildParam param;
  440. ret = ConvertToBuildParam(index, single_op_desc, param);
  441. if (ret != SUCCESS) {
  442. return ret;
  443. }
  444. op_list.emplace_back(param);
  445. GELOGI("Parse the index[%d] of op success", index);
  446. index += 1;
  447. }
  448. return SUCCESS;
  449. }
  450. } // namespace ge

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