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.

task_generator.cc 55 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
4 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
4 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
4 years ago
4 years ago
4 years ago
4 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
4 years ago
4 years ago
5 years ago
5 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209
  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 "graph/build/task_generator.h"
  17. #include <string>
  18. #include <utility>
  19. #include "common/profiling/profiling_manager.h"
  20. #include "common/types.h"
  21. #include "common/util.h"
  22. #include "framework/common/debug/ge_log.h"
  23. #include "graph/debug/ge_attr_define.h"
  24. #include "graph/ge_context.h"
  25. #include "graph/manager/graph_var_manager.h"
  26. #include "graph/model_serialize.h"
  27. #include "graph/utils/node_utils.h"
  28. #include "graph/utils/tensor_utils.h"
  29. #include "graph/utils/type_utils.h"
  30. #include "graph/common/ge_call_wrapper.h"
  31. #include "init/gelib.h"
  32. #include "graph/ge_local_context.h"
  33. #include "ge/ge_api_types.h"
  34. #include "opskernel_manager/ops_kernel_builder_manager.h"
  35. using domi::LogTimeStampDef;
  36. using domi::ModelTaskDef;
  37. using domi::TaskDef;
  38. using std::map;
  39. using std::set;
  40. using std::string;
  41. using std::vector;
  42. namespace {
  43. const char *const kIsFirstNode = "is_first_node";
  44. const char *const kIsLastNode = "is_last_node";
  45. const char *const kIsInputVar = "INPUT_IS_VAR";
  46. const char *const kIsOutputVar = "OUTPUT_IS_VAR";
  47. const char *const kProfilingMode = "PROFILING_MODE";
  48. const char *const kIteratorV2 = "IteratorV2";
  49. const uint32_t kProfilingArStep = 2;
  50. const uint64_t kProfilingFpStartLogid = 1;
  51. const uint64_t kProfilingBpEndLogid = 2;
  52. const uint64_t kProfilingArStartLogid = 3;
  53. const uint64_t kProfilingArEndLogid = 4;
  54. const uint64_t kProfilingIterEndLogid = 65535;
  55. const int64_t kHashFactor = 100000;
  56. const int64_t kInvalidGroupId = -1;
  57. const std::set<std::string> kFpNodeTypes = {ge::DATA, ge::GETNEXT, kIteratorV2};
  58. } // namespace
  59. namespace ge {
  60. TaskGenerator::TaskGenerator(uint8_t *var_mem_base, uint64_t var_mem_size) {
  61. var_mem_base_ = var_mem_base;
  62. var_mem_size_ = var_mem_size;
  63. }
  64. TaskGenerator::~TaskGenerator() {}
  65. Status TaskGenerator::GetTaskInfo(Model &model, ComputeGraphPtr &graph, uint64_t session_id, RunContext &run_context) {
  66. GELOGD("Begin to Get TaskInfo. session_id=%lu", session_id);
  67. // Check params
  68. if (graph == nullptr) {
  69. REPORT_INNER_ERROR("E19999", "Check param graph is null, session_id:%lu, when %s", session_id, __FUNCTION__);
  70. GELOGE(PARAM_INVALID, "GetTaskInfo param graph is null. session_id=%lu", session_id);
  71. return PARAM_INVALID;
  72. }
  73. std::vector<TaskDef> task_def_list;
  74. std::map<uint32_t, string> op_name_map;
  75. GE_DUMP(graph, "GenerateTaskBefore");
  76. Status ret = GenerateTask(run_context, graph, task_def_list, op_name_map);
  77. GE_DUMP(graph, "GenerateTaskAfter");
  78. if (ret != SUCCESS) {
  79. GELOGE(ret, "GenerateTask failed. session_id=%lu", session_id);
  80. return ret;
  81. }
  82. // op_name_map used when graph load
  83. graph->SetGraphOpName(op_name_map);
  84. // Set op_name for infer profiling
  85. vector<string> op_name;
  86. for (auto &iter : op_name_map) {
  87. op_name.push_back(iter.second);
  88. }
  89. GE_CHK_BOOL_EXEC(ge::AttrUtils::SetListStr(model, ATTR_MODEL_TASK_INDEX_OP_NAME, op_name),
  90. REPORT_INNER_ERROR("E19999", "Set Attr:%s fail for model:%s when %s",
  91. ATTR_MODEL_TASK_INDEX_OP_NAME.c_str(), model.GetName().c_str(), __FUNCTION__);
  92. GELOGE(FAILED, "SetListStr failed.");
  93. return FAILED);
  94. GELOGI("GenerateTask Success, task list:%zu, op map:%zu, logic mem base:%p, logic weight base:%p, logic var base:%p",
  95. task_def_list.size(), op_name_map.size(), run_context.dataMemBase, run_context.weightMemBase, var_mem_base_);
  96. // Init and serialize model_task_def
  97. ModelTaskDef model_task_def;
  98. model_task_def.set_memory_size(run_context.dataMemSize);
  99. model_task_def.set_weight_size(run_context.weightMemSize);
  100. for (const TaskDef &task_def_temp : task_def_list) {
  101. TaskDef *task_def = model_task_def.add_task();
  102. if (task_def == nullptr) {
  103. REPORT_INNER_ERROR("E19999", "Add task_def in ModelTaskDef fail, session_id:%lu, graph:%s, model:%s, when %s",
  104. session_id, graph->GetName().c_str(), model.GetName().c_str(), __FUNCTION__);
  105. GELOGE(FAILED, "task_def is nullptr.");
  106. return FAILED;
  107. }
  108. *task_def = task_def_temp;
  109. }
  110. ret = AddModelTaskToModel(model_task_def, session_id, model, run_context);
  111. if (ret != SUCCESS) {
  112. GELOGE(ret, "AddModelTaskToModel failed. session_id=%lu", session_id);
  113. return ret;
  114. }
  115. GELOGD("Get TaskInfo success. session_id=%lu", session_id);
  116. return SUCCESS;
  117. }
  118. Status TaskGenerator::AddModelTaskToModel(const ModelTaskDef &model_task_def, uint64_t session_id, ge::Model &model,
  119. RunContext &run_context) {
  120. GE_CHK_BOOL_EXEC(
  121. AttrUtils::SetInt(model, MODEL_ATTR_TASK_GEN_BASE_ADDR, reinterpret_cast<uintptr_t>(run_context.dataMemBase)),
  122. REPORT_INNER_ERROR("E19999", "Set Attr:%s fail for model:%s when %s",
  123. MODEL_ATTR_TASK_GEN_BASE_ADDR.c_str(), model.GetName().c_str(), __FUNCTION__);
  124. GELOGE(FAILED, "SetInt MODEL_ATTR_TASK_GEN_BASE_ADDR failed.");
  125. return FAILED);
  126. GE_CHK_BOOL_EXEC(
  127. AttrUtils::SetInt(model, MODEL_ATTR_TASK_GEN_WEIGHT_ADDR, reinterpret_cast<uintptr_t>(run_context.weightMemBase)),
  128. REPORT_INNER_ERROR("E19999", "Set Attr:%s fail for model:%s when %s",
  129. MODEL_ATTR_TASK_GEN_WEIGHT_ADDR.c_str(), model.GetName().c_str(), __FUNCTION__);
  130. GELOGE(FAILED, "SetInt MODEL_ATTR_TASK_GEN_WEIGHT_ADDR failed.");
  131. return FAILED);
  132. GE_CHK_BOOL_EXEC(AttrUtils::SetInt(model, ATTR_MODEL_TASK_GEN_VAR_ADDR, reinterpret_cast<uintptr_t>(var_mem_base_)),
  133. REPORT_INNER_ERROR("E19999", "Set Attr:%s fail for model:%s when %s",
  134. ATTR_MODEL_TASK_GEN_VAR_ADDR.c_str(), model.GetName().c_str(), __FUNCTION__);
  135. GELOGE(FAILED, "SetInt ATTR_MODEL_TASK_GEN_VAR_ADDR failed.");
  136. return FAILED);
  137. GE_CHK_BOOL_EXEC(AttrUtils::SetInt(model, ATTR_MODEL_VAR_SIZE, var_mem_size_),
  138. REPORT_INNER_ERROR("E19999", "Set Attr:%s fail for model:%s when %s",
  139. ATTR_MODEL_VAR_SIZE.c_str(), model.GetName().c_str(), __FUNCTION__);
  140. GELOGE(FAILED, "SetInt ATTR_MODEL_VAR_SIZE failed.");
  141. return FAILED);
  142. GE_CHK_BOOL_EXEC(AttrUtils::SetInt(model, MODEL_ATTR_SESSION_ID, session_id),
  143. REPORT_INNER_ERROR("E19999", "Set Attr:%s fail for mode:%s when %s",
  144. MODEL_ATTR_SESSION_ID.c_str(), model.GetName().c_str(), __FUNCTION__);
  145. GELOGE(FAILED, "SetInt MODEL_ATTR_SESSION_ID failed.");
  146. return FAILED);
  147. size_t task_size = model_task_def.ByteSizeLong();
  148. ge::Buffer serial_buff(task_size);
  149. if (!model_task_def.SerializePartialToArray(serial_buff.GetData(), static_cast<int>(task_size))) {
  150. REPORT_INNER_ERROR("E19999", "model_task_def's serialize failed, model name = %s, task_size=%zu when %s",
  151. model.GetName().c_str(), task_size, __FUNCTION__);
  152. GELOGE(FAILED, "model_task_def's serialize failed, model name = %s, task_size=%zu.", model.GetName().c_str(),
  153. task_size);
  154. return FAILED;
  155. }
  156. if (!AttrUtils::SetZeroCopyBytes(model, MODEL_ATTR_TASKS, std::move(serial_buff))) {
  157. REPORT_INNER_ERROR("E19999", "Set model task to model failed, model name = %s, task_size=%zu when %s",
  158. model.GetName().c_str(), task_size, __FUNCTION__);
  159. GELOGE(FAILED, "Set model task to model failed, model name = %s, task_size=%zu.", model.GetName().c_str(),
  160. task_size);
  161. return FAILED;
  162. }
  163. return SUCCESS;
  164. }
  165. Status TaskGenerator::UpdateOpIsVarAttr(const OpDescPtr &op_desc, uint64_t session_id) {
  166. vector<int64_t> input_offsets = op_desc->GetInputOffset();
  167. GELOGD("Update is var attr, node[name:%s(%s), id:%ld, stream_id:%ld].", op_desc->GetName().c_str(),
  168. op_desc->GetType().c_str(), op_desc->GetId(), op_desc->GetStreamId());
  169. if (!(input_offsets.empty())) {
  170. vector<bool> input_var;
  171. for (int64_t input : input_offsets) {
  172. input_var.push_back(VarManager::Instance(session_id)->IsVarAddr(input));
  173. }
  174. GE_CHK_BOOL_EXEC(AttrUtils::SetListBool(op_desc, kIsInputVar, input_var),
  175. REPORT_INNER_ERROR("E19999", "Set Attr:%s fail for op:%s(%s) when %s", kIsInputVar,
  176. op_desc->GetName().c_str(), op_desc->GetType().c_str(), __FUNCTION__);
  177. GELOGE(FAILED, "SetListBool failed.");
  178. return FAILED);
  179. }
  180. vector<int64_t> output_offsets = op_desc->GetOutputOffset();
  181. if (!(output_offsets.empty())) {
  182. vector<bool> output_var;
  183. for (int64_t output : output_offsets) {
  184. output_var.push_back(VarManager::Instance(session_id)->IsVarAddr(output));
  185. }
  186. GE_CHK_BOOL_EXEC(AttrUtils::SetListBool(op_desc, kIsOutputVar, output_var),
  187. REPORT_INNER_ERROR("E19999", "Set Attr:%s fail for op:%s(%s) when %s", kIsOutputVar,
  188. op_desc->GetName().c_str(), op_desc->GetType().c_str(), __FUNCTION__);
  189. GELOGE(FAILED, "SetListBool failed.");
  190. return FAILED);
  191. }
  192. return SUCCESS;
  193. }
  194. Status TaskGenerator::SaveFusionNodes(map<int64_t, std::vector<NodePtr>> &fusion_nodes, ComputeGraphPtr &graph) {
  195. std::map<NodePtr, int64_t> nodes_with_group_attr;
  196. for (auto &node : graph->GetNodes(graph->GetGraphUnknownFlag())) {
  197. OpDescPtr op_desc = node->GetOpDesc();
  198. GE_CHECK_NOTNULL(op_desc);
  199. int64_t group_id = kInvalidGroupId;
  200. string name = node->GetName();
  201. string type = node->GetType();
  202. // For fusion ddb pass, task def must be continuous.
  203. // Part1: store
  204. // If op_desc have this tag, store it in the map firstly,
  205. // call the elements in the map GenerateTask at last
  206. // l1 and l2 is for now
  207. if (ge::AttrUtils::GetInt(op_desc, ATTR_NAME_L1_FUSION_GROUP_ID, group_id) ||
  208. ge::AttrUtils::GetInt(op_desc, ATTR_NAME_L2_FUSION_GROUP_ID, group_id)) {
  209. auto stream_id = op_desc->GetStreamId();
  210. auto group_key = group_id + stream_id * kHashFactor;
  211. (void)ge::AttrUtils::SetInt(op_desc, ATTR_NAME_FUSION_GROUP_KEY, group_key);
  212. GELOGD("Fusion: store node[name:%s(%s), group id:%ld, group key:%ld, stream_id:%ld] task.", name.c_str(),
  213. type.c_str(), group_id, group_key, op_desc->GetStreamId());
  214. fusion_nodes[group_key].push_back(node);
  215. nodes_with_group_attr.insert({node, group_id});
  216. }
  217. // if node's all in nodes both with same group attr
  218. // and it have no attr or group attr different
  219. // which means bad case, return error
  220. bool call_check = true;
  221. std::set<int64_t> input_group_ids;
  222. for (const auto &input_node : node->GetInNodes()) {
  223. auto iter = nodes_with_group_attr.find(input_node);
  224. if (iter == nodes_with_group_attr.end()) {
  225. call_check = false;
  226. break;
  227. } else {
  228. input_group_ids.insert(iter->second);
  229. }
  230. }
  231. call_check = (call_check && (input_group_ids.size() == 1));
  232. if (call_check) {
  233. auto input_group_id = *input_group_ids.begin();
  234. if (group_id != input_group_id) {
  235. GELOGW("Fusion: node[name:%s(%s) with group id:%ld and diff from it's input nodes's group id:%ld ",
  236. name.c_str(), type.c_str(), group_id, input_group_id);
  237. }
  238. }
  239. }
  240. GELOGD("Fusion: get fusion group numbers [%zu].", fusion_nodes.size());
  241. return SUCCESS;
  242. }
  243. bool TaskGenerator::IsSubGraphOfDynamicGraph(const ComputeGraphPtr &graph) const {
  244. auto parent_graph_ptr = graph->GetParentGraph();
  245. if (parent_graph_ptr == nullptr) {
  246. return false;
  247. }
  248. auto root_graph_ptr = GraphUtils::FindRootGraph(parent_graph_ptr);
  249. if (root_graph_ptr == nullptr) {
  250. return false;
  251. }
  252. return root_graph_ptr->GetGraphUnknownFlag();
  253. }
  254. Status TaskGenerator::GenerateTask(RunContext &run_context, ComputeGraphPtr &graph,
  255. vector<domi::TaskDef> &task_def_list, map<uint32_t, string> &op_name_map) {
  256. GELOGD("Beign to generate task, graph name is %s.", graph->GetName().c_str());
  257. std::shared_ptr<GELib> ge_lib = GELib::GetInstance();
  258. if ((ge_lib == nullptr) || !ge_lib->InitFlag()) {
  259. REPORT_INNER_ERROR("E19999", "Check GELib instance not init before when %s", __FUNCTION__);
  260. GELOGE(GE_CLI_GE_NOT_INITIALIZED, "GenerateTask failed.");
  261. return GE_CLI_GE_NOT_INITIALIZED;
  262. }
  263. GE_CHK_STATUS_RET(MarkNodeAndSetIndex(graph), "MarkNodeAndSetIndex failed.");
  264. ProfilingPoint profiling_point;
  265. vector<uint32_t> all_reduce_nodes;
  266. GE_CHK_STATUS_RET(FindProfilingTaskIndex(graph, profiling_point, all_reduce_nodes));
  267. const OpsKernelManager &ops_kernel_manager = ge_lib->OpsKernelManagerObj();
  268. GE_TIMESTAMP_CALLNUM_START(GenerateTask);
  269. // map store fusion nodes
  270. map<int64_t, std::vector<NodePtr>> fusion_nodes;
  271. string buffer_optimize = "off_optimize";
  272. (void)ge::GetContext().GetOption(BUFFER_OPTIMIZE, buffer_optimize);
  273. if (buffer_optimize != "off_optimize") {
  274. GE_CHK_STATUS_RET(SaveFusionNodes(fusion_nodes, graph));
  275. }
  276. std::unordered_set<Node *> fusion_nodes_seen;
  277. int64_t group_key;
  278. uint32_t node_index = 0;
  279. rtStream_t stream = nullptr;
  280. bool is_unknown_shape = graph->GetGraphUnknownFlag() || GetContext().GetHostExecFlag();
  281. if (is_unknown_shape) {
  282. GE_CHK_STATUS_RET(SetUnknownShapeStream(run_context, stream), "Set unknown shape stream failed.");
  283. }
  284. std::function<void()> callback = [&]() {
  285. if (is_unknown_shape) {
  286. if (DestroyUnknownShapeStream(run_context, stream) != SUCCESS) {
  287. GELOGE(FAILED, "Destory unknown shape stream failed.");
  288. }
  289. }
  290. };
  291. GE_MAKE_GUARD(release, callback);
  292. for (auto &node : graph->GetNodes(graph->GetGraphUnknownFlag())) {
  293. OpDescPtr op_desc = node->GetOpDesc();
  294. GE_CHECK_NOTNULL(op_desc);
  295. node_index++;
  296. string name = node->GetName();
  297. string type = node->GetType();
  298. bool attr_notask = false;
  299. bool get_attr_notask_flag = ge::AttrUtils::GetBool(op_desc, ATTR_NAME_NOTASK, attr_notask);
  300. GE_IF_BOOL_EXEC(get_attr_notask_flag && attr_notask,
  301. GELOGI("Node[name:%s, type:%s] does not need to generate task.", name.c_str(), type.c_str());
  302. continue);
  303. GE_CHK_STATUS_RET(UpdateOpIsVarAttr(op_desc, graph->GetSessionID()));
  304. string op_kernel_lib_name = op_desc->GetOpKernelLibName();
  305. // For fusion ddb pass, task def must be continuous.
  306. // Part2: Call
  307. auto fusion_task_info =
  308. FusionTaskInfo{run_context, graph, node, op_desc, node_index, ge_lib,
  309. ops_kernel_manager, task_def_list, op_name_map, profiling_point, all_reduce_nodes};
  310. GE_CHK_STATUS_RET(GenerateTaskForFusionNode(fusion_task_info, fusion_nodes, fusion_nodes_seen),
  311. "Call GenerateTaskForFusionNode node:%s(%s) failed", name.c_str(), type.c_str());
  312. // continue directly
  313. if (ge::AttrUtils::GetInt(op_desc, ATTR_NAME_FUSION_GROUP_KEY, group_key)) {
  314. GELOGI("Fusion node[name:%s, type:%s] do not need generate task again.", name.c_str(), type.c_str());
  315. continue;
  316. }
  317. if (op_kernel_lib_name.empty()) {
  318. GELOGI("Node[name:%s, type:%s] does not need to generate task.", name.c_str(), type.c_str());
  319. continue;
  320. }
  321. auto kernel_info_store = ops_kernel_manager.GetOpsKernelInfoStore(op_kernel_lib_name);
  322. if (kernel_info_store == nullptr) {
  323. REPORT_INNER_ERROR("E19999", "Get ops kernel info store failed for op:%s(%s), op_kernel_name:%s when %s",
  324. node->GetName().c_str(), node->GetType().c_str(), op_kernel_lib_name.c_str(), __FUNCTION__);
  325. GELOGE(INTERNAL_ERROR,
  326. "No ops kernel store or ops kernel builder found. node:%s(%s), op_kernel_lib_name=%s.",
  327. name.c_str(),
  328. type.c_str(), op_kernel_lib_name.c_str());
  329. return INTERNAL_ERROR;
  330. }
  331. GE_CHK_STATUS_RET(UpdateAnchorStatus(node), "Call UpdateAnchorStatus node:%s(%s) failed", name.c_str(),
  332. type.c_str());
  333. // Profiling task
  334. size_t task_list_size_before = task_def_list.size();
  335. GE_CHK_STATUS_RET(InsertProfilingTaskBefore(op_desc, profiling_point, all_reduce_nodes, node_index, task_def_list));
  336. int64_t op_id = op_desc->GetId();
  337. // Compatible with dynamic shape scenes, the default is 0
  338. int64_t stream_id = 0;
  339. if (!is_unknown_shape) {
  340. stream_id = op_desc->GetStreamId();
  341. GE_CHK_STATUS_RET(SetKnownShapeStream(run_context, stream_id), "node[name:%s(%s), id:%ld] stream id is invalid.",
  342. name.c_str(), type.c_str(), op_id);
  343. }
  344. GELOGD("Call %s to generate node[name:%s(%s), id:%ld, stream_id:%ld] task.", op_kernel_lib_name.c_str(),
  345. name.c_str(), type.c_str(), op_id, stream_id);
  346. GE_TIMESTAMP_RESTART(GenerateTask);
  347. auto ret = OpsKernelBuilderManager::Instance().GenerateTask(*node, run_context, task_def_list);
  348. GE_TIMESTAMP_ADD(GenerateTask);
  349. if (ret != SUCCESS) {
  350. REPORT_CALL_ERROR("E19999", "Call OpsKernelBuilderManager GenerateTask fail for op:%s(%s) when %s",
  351. node->GetName().c_str(), node->GetType().c_str(), __FUNCTION__);
  352. GELOGE(ret, "Call %s to generate node[name:%s(%s), id:%ld, stream_id:%ld] task failed.",
  353. op_kernel_lib_name.c_str(), name.c_str(), type.c_str(), op_id, stream_id);
  354. return ret;
  355. }
  356. // Profiling task
  357. GE_CHK_STATUS_RET(InsertProfilingTaskAfter(op_desc, profiling_point, all_reduce_nodes, node_index, task_def_list));
  358. size_t task_list_size_after = task_def_list.size();
  359. // If tasks is reduced
  360. if (task_list_size_after < task_list_size_before) {
  361. REPORT_INNER_ERROR("E19999", "Call %s to generate node[name:%s(%s), id:%ld, stream_id:%ld] task "
  362. "but task num from %zu to %zu, check invalid", op_kernel_lib_name.c_str(), name.c_str(),
  363. type.c_str(), op_id, stream_id, task_list_size_before, task_list_size_after);
  364. GELOGE(FAILED, "Call %s to generate node[name:%s(%s), id:%ld, stream_id:%ld] task. but task num from %zu to %zu.",
  365. op_kernel_lib_name.c_str(), name.c_str(), type.c_str(), op_id, stream_id, task_list_size_before,
  366. task_list_size_after);
  367. return FAILED;
  368. }
  369. // Reset stream id to ge stream id, as graph load must use ge stream to reassign stream
  370. void *ops_kernel_info_store_ptr = kernel_info_store.get();
  371. for (size_t idx = task_list_size_before; idx < task_list_size_after; ++idx) {
  372. task_def_list[idx].set_stream_id(static_cast<uint32_t>(stream_id));
  373. op_name_map[idx] = name;
  374. // Set opsKernelInfoStorePtr and op_index, the two fields be use in DistributeTask and InitTaskInfo
  375. TaskDef *task_def_ptr = &task_def_list[idx];
  376. GE_CHECK_NOTNULL(task_def_ptr);
  377. task_def_ptr->set_ops_kernel_store_ptr(reinterpret_cast<uintptr_t>(ops_kernel_info_store_ptr));
  378. }
  379. GELOGD("Call %s to generate node[name:%s(%s), id:%ld, stream_id:%ld] task finished, generate %zu task(s).",
  380. op_kernel_lib_name.c_str(), name.c_str(), type.c_str(), op_id, stream_id,
  381. task_list_size_after - task_list_size_before);
  382. }
  383. GE_TIMESTAMP_CALLNUM_EVENT_END(GenerateTask, "GraphBuild::GenerateTask");
  384. return SUCCESS;
  385. }
  386. Status TaskGenerator::GenerateTaskForFusionNode(FusionTaskInfo &fusion_task_info,
  387. std::map<int64_t, std::vector<NodePtr>> &fusion_nodes,
  388. std::unordered_set<Node *> &fusion_nodes_seen) {
  389. Status ret = SUCCESS;
  390. int64_t group_key;
  391. auto &run_context = fusion_task_info.run_context;
  392. auto &graph = fusion_task_info.graph;
  393. auto &node = fusion_task_info.node;
  394. auto &fusion_op_desc = fusion_task_info.fusion_op_desc;
  395. auto &node_index = fusion_task_info.node_index;
  396. const auto &ops_kernel_manager = fusion_task_info.ops_kernel_manager;
  397. auto &task_def_list = fusion_task_info.task_def_list;
  398. auto &op_name_map = fusion_task_info.op_name_map;
  399. auto &profiling_point = fusion_task_info.profiling_point;
  400. auto &all_reduce_nodes = fusion_task_info.all_reduce_nodes;
  401. // If op_desc have this attr, call nodes with same group key in a stream together
  402. if (ge::AttrUtils::GetInt(fusion_op_desc, ATTR_NAME_FUSION_GROUP_KEY, group_key) &&
  403. (fusion_nodes_seen.count(node.get()) == 0)) {
  404. GELOGI("Fusion: start fusion group index[%ld], nodes size[%zu].", group_key, fusion_nodes[group_key].size());
  405. for (auto &fusion_node : fusion_nodes[group_key]) {
  406. OpDescPtr op_desc = fusion_node->GetOpDesc();
  407. UpdateOpIsVarAttr(op_desc, graph->GetSessionID());
  408. std::string fusion_node_name = fusion_node->GetName();
  409. std::string fusion_node_type = fusion_node->GetType();
  410. std::string op_kernel_lib_name = op_desc->GetOpKernelLibName();
  411. if (op_kernel_lib_name.empty()) {
  412. GELOGI("Fusion: fusion_node[name:%s(%s)] task no need to generate task.", fusion_node_name.c_str(),
  413. fusion_node_type.c_str());
  414. continue;
  415. }
  416. bool attr_notask = false;
  417. GE_IF_BOOL_EXEC(ge::AttrUtils::GetBool(op_desc, ATTR_NAME_NOTASK, attr_notask) && attr_notask,
  418. GELOGI("Fusion: fusion_node[name:%s, type:%s] does not need to generate task.",
  419. fusion_node_name.c_str(), fusion_node_type.c_str());
  420. continue);
  421. size_t task_list_size_before = task_def_list.size();
  422. OpsKernelInfoStorePtr kernel_info_store = ops_kernel_manager.GetOpsKernelInfoStore(op_kernel_lib_name);
  423. if (kernel_info_store == nullptr) {
  424. REPORT_INNER_ERROR("E19999", "Get ops kernel info store failed for op:%s(%s), op_kernel_name:%s when %s",
  425. op_desc->GetName().c_str(), op_desc->GetType().c_str(),
  426. op_kernel_lib_name.c_str(), __FUNCTION__);
  427. GELOGE(INTERNAL_ERROR,
  428. "Fusion: No ops kernel store or ops kernel builder found. fusion_node:%s(%s), op_kernel_lib_name=%s.",
  429. fusion_node_name.c_str(), fusion_node_type.c_str(), op_kernel_lib_name.c_str());
  430. return INTERNAL_ERROR;
  431. }
  432. ret = UpdateAnchorStatus(fusion_node);
  433. if (ret != SUCCESS) {
  434. GELOGE(ret, "Fusion: Call UpdateAnchorStatus fusion_node:%s(%s) failed", fusion_node_name.c_str(),
  435. fusion_node_type.c_str());
  436. return ret;
  437. }
  438. int64_t op_id = op_desc->GetId();
  439. int64_t stream_id = op_desc->GetStreamId();
  440. if (stream_id < 0 || stream_id >= (int64_t)run_context.graphStreamList.size()) {
  441. REPORT_INNER_ERROR("E19999", "Fusion: fusion_node[name:%s(%s), id:%ld] stream id is invalid, "
  442. "stream list size=%zu, when %s", fusion_node_name.c_str(), fusion_node_type.c_str(),
  443. op_id, run_context.graphStreamList.size(), __FUNCTION__);
  444. GELOGE(INTERNAL_ERROR, "Fusion: fusion_node[name:%s(%s), id:%ld] stream id is invalid, stream list size=%zu",
  445. fusion_node_name.c_str(), fusion_node_type.c_str(), op_id, run_context.graphStreamList.size());
  446. return INTERNAL_ERROR;
  447. }
  448. // profiling task
  449. (void)InsertProfilingTaskBefore(op_desc, profiling_point, all_reduce_nodes, node_index, task_def_list);
  450. run_context.stream = run_context.graphStreamList[stream_id];
  451. GELOGI("Fusion: Call %s to generate fusion_node:[fusion_node_name:%s(%s), id:%ld, stream_id:%ld] task.",
  452. op_kernel_lib_name.c_str(), fusion_node_name.c_str(), fusion_node_type.c_str(), op_id, stream_id);
  453. ret = OpsKernelBuilderManager::Instance().GenerateTask(*fusion_node, run_context, task_def_list);
  454. if (ret != SUCCESS) {
  455. REPORT_CALL_ERROR("E19999", " Call %s to generate fusion_node:[fusion_node_name:%s(%s), "
  456. "id:%ld, stream_id:%ld] task failed when %s", op_kernel_lib_name.c_str(),
  457. fusion_node_name.c_str(), fusion_node_type.c_str(), op_id, stream_id, __FUNCTION__);
  458. GELOGE(ret,
  459. "Fusion: Call %s to generate fusion_node:[fusion_node_name:%s(%s), "
  460. "id:%ld, stream_id:%ld] task failed.",
  461. op_kernel_lib_name.c_str(), fusion_node_name.c_str(), fusion_node_type.c_str(), op_id, stream_id);
  462. return ret;
  463. }
  464. // profiling task
  465. (void)InsertProfilingTaskAfter(op_desc, profiling_point, all_reduce_nodes, node_index, task_def_list);
  466. size_t task_list_size_after = task_def_list.size();
  467. // if tasks is reduced
  468. if (task_list_size_after < task_list_size_before) {
  469. REPORT_INNER_ERROR("E19999", "InsertProfilingTask for fusion_node:[fusion_node_name:%s(%s), kernel_name:%s"
  470. "id:%ld, stream_id:%ld] task, but task num from %zu to %zu, check invalid when %s",
  471. fusion_node_name.c_str(), fusion_node_type.c_str(), op_kernel_lib_name.c_str(),
  472. op_id, stream_id, task_list_size_before, task_list_size_after, __FUNCTION__);
  473. GELOGE(FAILED,
  474. "Fusion: Call %s to generate fusion_node:[fusion_node_name:%s(%s), "
  475. "id:%ld, stream_id:%ld] task. but task num from %zu to %zu.",
  476. op_kernel_lib_name.c_str(), fusion_node_name.c_str(), fusion_node_type.c_str(), op_id, stream_id,
  477. task_list_size_before, task_list_size_after);
  478. return FAILED;
  479. }
  480. // reset stream id to ge stream id, as graph load must use ge stream to reassign stream
  481. void *ops_kernel_info_store_ptr = kernel_info_store.get();
  482. for (size_t idx = task_list_size_before; idx < task_list_size_after; ++idx) {
  483. task_def_list[idx].set_stream_id(static_cast<uint32_t>(stream_id));
  484. op_name_map[idx] = fusion_node_name;
  485. // set opsKernelInfoStorePtr and op_index, the two fields be use in DistributeTask and InitTaskInfo
  486. TaskDef *task_def_ptr = &task_def_list[idx];
  487. task_def_ptr->set_ops_kernel_store_ptr(reinterpret_cast<uintptr_t>(ops_kernel_info_store_ptr));
  488. }
  489. GELOGI("Fusion: Call %s to generate fusion_node:[fusion_node_name:%s(%s), id:%ld, stream_id:%ld]"
  490. " task finished, generate %zu task(s).",
  491. op_kernel_lib_name.c_str(), fusion_node_name.c_str(), fusion_node_type.c_str(), op_id, stream_id,
  492. task_list_size_after - task_list_size_before);
  493. // record nodes which have call generate task successfully
  494. fusion_nodes_seen.insert(fusion_node.get());
  495. node_index++;
  496. }
  497. }
  498. // without tag or has been seen, skip directly
  499. return ret;
  500. }
  501. Status TaskGenerator::UpdateAnchorStatus(const NodePtr &node) {
  502. if (NodeUtils::SetAllAnchorStatus(node) != GRAPH_SUCCESS) {
  503. REPORT_CALL_ERROR("E19999", "SetAllAnchorStatus fail for op:%s(%s) when %s",
  504. node->GetName().c_str(), node->GetType().c_str(), __FUNCTION__);
  505. GELOGE(INTERNAL_ERROR, "NodeUtils::SetAllAnchorStatus failed.");
  506. return INTERNAL_ERROR;
  507. }
  508. for (auto &anchor : node->GetAllInDataAnchors()) {
  509. auto peer_anchor = anchor->GetPeerOutAnchor();
  510. if (peer_anchor == nullptr) {
  511. if (AnchorUtils::SetStatus(anchor, ANCHOR_SUSPEND) != GRAPH_SUCCESS) {
  512. REPORT_CALL_ERROR("E19999", "Set in peer anchor status fail for op:%s(%s), anchor_index:%d, when %s",
  513. node->GetName().c_str(), node->GetType().c_str(), anchor->GetIdx(), __FUNCTION__);
  514. GELOGE(INTERNAL_ERROR, "AnchorUtils::SetStatus failed.");
  515. return INTERNAL_ERROR;
  516. }
  517. continue;
  518. }
  519. std::string const_type;
  520. bool is_const = NodeUtils::GetConstOpType(peer_anchor->GetOwnerNode(), const_type);
  521. if (is_const && (const_type == CONSTANT)) {
  522. if (AnchorUtils::SetStatus(anchor, ANCHOR_CONST) != GRAPH_SUCCESS) {
  523. REPORT_CALL_ERROR("E19999", "Set in anchor CONST status fail for op:%s(%s), anchor_index:%d, when %s",
  524. node->GetName().c_str(), node->GetType().c_str(), anchor->GetIdx(), __FUNCTION__);
  525. GELOGE(INTERNAL_ERROR, "AnchorUtils::SetStatus failed.");
  526. return INTERNAL_ERROR;
  527. }
  528. } else {
  529. if (AnchorUtils::SetStatus(anchor, ANCHOR_DATA) != GRAPH_SUCCESS) {
  530. REPORT_CALL_ERROR("E19999", "Set in anchor DATA status fail for op:%s(%s), anchor_index:%d, when %s",
  531. node->GetName().c_str(), node->GetType().c_str(), anchor->GetIdx(), __FUNCTION__);
  532. GELOGE(INTERNAL_ERROR, "AnchorUtils::SetStatus failed.");
  533. return INTERNAL_ERROR;
  534. }
  535. }
  536. }
  537. return SUCCESS;
  538. }
  539. Status TaskGenerator::MarkNodeAndSetIndex(ComputeGraphPtr &graph) {
  540. auto ge_lib = GELib::GetInstance();
  541. if ((ge_lib == nullptr) || !ge_lib->InitFlag()) {
  542. REPORT_INNER_ERROR("E19999", "Check GELib instance not init before when %s", __FUNCTION__);
  543. GELOGE(GE_CLI_GE_NOT_INITIALIZED, "GE is not initialized or is finalized.");
  544. return GE_CLI_GE_NOT_INITIALIZED;
  545. }
  546. const auto all_nodes = graph->GetNodes(graph->GetGraphUnknownFlag());
  547. if (all_nodes.empty()) {
  548. REPORT_INNER_ERROR("E19999", "Check param all_nodes empty in graph:%s when %s",
  549. graph->GetName().c_str(), __FUNCTION__);
  550. GELOGE(GE_GRAPH_GRAPH_NODE_NULL, "Graph's node is empty");
  551. return GE_GRAPH_GRAPH_NODE_NULL;
  552. }
  553. map<int64_t, vector<OpDescPtr>> all_stream_ops;
  554. for (auto &node : all_nodes) {
  555. OpDescPtr op_desc = node->GetOpDesc();
  556. GE_CHECK_NOTNULL(op_desc);
  557. // Reset op kernel lib name
  558. if (op_desc->GetOpKernelLibName().empty()) {
  559. (void)ge_lib->DNNEngineManagerObj().GetDNNEngineName(node);
  560. }
  561. (void)op_desc->DelAttr(kIsFirstNode);
  562. (void)op_desc->DelAttr(kIsLastNode);
  563. all_stream_ops[op_desc->GetStreamId()].emplace_back(op_desc);
  564. }
  565. bool is_single_stream = all_stream_ops.size() == 1;
  566. for (const auto &stream_ops : all_stream_ops) {
  567. Status status = MarkFirstAndLastOps(stream_ops.second, is_single_stream);
  568. if (status != SUCCESS) {
  569. GELOGE(status, "Mark first and last nodes failed.");
  570. return status;
  571. }
  572. }
  573. return SUCCESS;
  574. }
  575. Status TaskGenerator::MarkFirstAndLastOps(const vector<OpDescPtr> &ops, bool is_single_stream) const {
  576. vector<vector<OpDescPtr>> continuous_op_lists(1);
  577. const set<string> separator_types(
  578. {LABELSET, LABELGOTO, LABELGOTOEX, LABELSWITCH, LABELSWITCHBYINDEX, STREAMSWITCH, STREAMSWITCHN});
  579. for (auto &op_desc : ops) {
  580. bool attr_notask = false;
  581. if (ge::AttrUtils::GetBool(op_desc, ATTR_NAME_NOTASK, attr_notask) && attr_notask) {
  582. continue;
  583. }
  584. string op_type = op_desc->GetType();
  585. if ((!is_single_stream && !op_desc->GetSubgraphInstanceNames().empty()) || separator_types.count(op_type) != 0) {
  586. continuous_op_lists.emplace_back(vector<OpDescPtr>());
  587. } else {
  588. continuous_op_lists.back().emplace_back(op_desc);
  589. }
  590. }
  591. GELOGD("Number of continuous node lists is %zu.", continuous_op_lists.size());
  592. for (const auto &continuous_ops : continuous_op_lists) {
  593. map<string, std::pair<OpDescPtr, OpDescPtr>> first_and_last_ops;
  594. for (auto &op_desc : continuous_ops) {
  595. string op_kernel_lib_name = op_desc->GetOpKernelLibName();
  596. if (op_kernel_lib_name.empty()) {
  597. REPORT_INNER_ERROR("E19999", "Get ops kernel info store failed for op:%s(%s), op_kernel_name:%s when %s",
  598. op_desc->GetName().c_str(), op_desc->GetType().c_str(),
  599. op_kernel_lib_name.c_str(), __FUNCTION__);
  600. GELOGE(INTERNAL_ERROR, "node:%s(%s) get op kernel lib failed.", op_desc->GetName().c_str(),
  601. op_desc->GetType().c_str());
  602. return INTERNAL_ERROR;
  603. }
  604. auto it = first_and_last_ops.find(op_kernel_lib_name);
  605. if (it == first_and_last_ops.end()) {
  606. first_and_last_ops.emplace(op_kernel_lib_name, std::make_pair(op_desc, op_desc));
  607. } else {
  608. it->second.second = op_desc;
  609. }
  610. }
  611. for (auto &it : first_and_last_ops) {
  612. auto &op_pair = it.second;
  613. GE_CHK_BOOL_EXEC(ge::AttrUtils::SetBool(op_pair.first, kIsFirstNode, true),
  614. REPORT_INNER_ERROR("E19999", "Set Attr:%s fail for op:%s(%s) when %s", kIsFirstNode,
  615. op_pair.first->GetName().c_str(), op_pair.first->GetType().c_str(),
  616. __FUNCTION__);
  617. GELOGE(FAILED, "SetBool failed.");
  618. return FAILED);
  619. GE_CHK_BOOL_EXEC(ge::AttrUtils::SetBool(op_pair.second, kIsLastNode, true),
  620. REPORT_INNER_ERROR("E19999", "Set Attr:%s fail for op:%s(%s) when %s", kIsLastNode,
  621. op_pair.second->GetName().c_str(), op_pair.second->GetType().c_str(),
  622. __FUNCTION__);
  623. GELOGE(FAILED, "SetBool failed.");
  624. return FAILED);
  625. }
  626. }
  627. return SUCCESS;
  628. }
  629. Status TaskGenerator::AutoFindFpOpIndex(const ComputeGraphPtr &graph, ProfilingPoint &profiling_point) const {
  630. GELOGI("Start AutoFindFpOpIndex");
  631. OpDescPtr fp_op_desc = nullptr;
  632. uint32_t current_idx = 0;
  633. uint32_t first_fp = 0;
  634. for (auto &node : graph->GetNodes(graph->GetGraphUnknownFlag())) {
  635. OpDescPtr op_desc = node->GetOpDesc();
  636. GE_CHECK_NOTNULL(op_desc);
  637. string op_kernel_lib_name = op_desc->GetOpKernelLibName();
  638. if (op_kernel_lib_name.empty()) {
  639. continue;
  640. }
  641. auto type = op_desc->GetType();
  642. std::string original_type;
  643. (void)AttrUtils::GetStr(op_desc, ATTR_NAME_FRAMEWORK_ORIGINAL_TYPE, original_type);
  644. if (kFpNodeTypes.find(type) != kFpNodeTypes.end() || kFpNodeTypes.find(original_type) != kFpNodeTypes.end()) {
  645. auto out_anchor = node->GetOutDataAnchor(0);
  646. for (auto &peer_in_anchor : out_anchor->GetPeerInDataAnchors()) {
  647. GE_CHECK_NOTNULL(peer_in_anchor);
  648. auto in_node_desc = peer_in_anchor->GetOwnerNode()->GetOpDesc();
  649. GE_CHECK_NOTNULL(in_node_desc);
  650. if (fp_op_desc == nullptr || ((in_node_desc->GetId()) < (fp_op_desc->GetId()))) {
  651. fp_op_desc = in_node_desc;
  652. }
  653. }
  654. break;
  655. }
  656. }
  657. if (fp_op_desc == nullptr) {
  658. GELOGW("not find fp_op_desc.");
  659. return SUCCESS;
  660. }
  661. GELOGI("Find fp_op_desc is %s, id is %ld", fp_op_desc->GetName().c_str(), fp_op_desc->GetId());
  662. for (auto &node : graph->GetNodes(graph->GetGraphUnknownFlag())) {
  663. OpDescPtr op_desc = node->GetOpDesc();
  664. GE_CHECK_NOTNULL(op_desc);
  665. current_idx++;
  666. if (op_desc->GetName() == fp_op_desc->GetName()) {
  667. first_fp = current_idx;
  668. GELOGI("First fp name is %s, idx is %u", op_desc->GetName().c_str(), first_fp);
  669. break;
  670. }
  671. }
  672. profiling_point.fp_index = first_fp;
  673. return SUCCESS;
  674. }
  675. Status TaskGenerator::AutoFindBpOpIndex(const ComputeGraphPtr &graph, ProfilingPoint &profiling_point,
  676. vector<uint32_t> &all_reduce_nodes) const {
  677. GELOGI("Start AutoFindBpOpIndex");
  678. NodePtr bp_node = nullptr;
  679. uint32_t current_idx = 0;
  680. for (auto &node : graph->GetNodes(graph->GetGraphUnknownFlag())) {
  681. OpDescPtr op_desc = node->GetOpDesc();
  682. GE_CHECK_NOTNULL(op_desc);
  683. current_idx++;
  684. string op_kernel_lib_name = op_desc->GetOpKernelLibName();
  685. if (op_kernel_lib_name.empty()) {
  686. continue;
  687. }
  688. if (op_desc->GetType() == HCOMALLREDUCE || op_desc->GetType() == HVDCALLBACKALLREDUCE) {
  689. bp_node = node;
  690. all_reduce_nodes.emplace_back(current_idx);
  691. GELOGI("Allreduce name %s, idx %u", op_desc->GetName().c_str(), current_idx);
  692. }
  693. if (op_desc->GetName() == NODE_NAME_NET_OUTPUT) {
  694. if (bp_node == nullptr) {
  695. bp_node = node;
  696. }
  697. }
  698. if (graph->GetNeedIteration()) {
  699. if (op_desc->GetName() == NODE_NAME_FLOWCTRL_LOOP_ASSIGNADD) {
  700. profiling_point.end_index.insert(current_idx);
  701. GELOGI("Iter end name %s, idx %u, from Node_Output_IteratorCtrl_StreamSwitch_StreamActive",
  702. op_desc->GetName().c_str(), current_idx);
  703. }
  704. if (op_desc->GetName() == NODE_NAME_FLOWCTRL_LOOP_ASSIGN) {
  705. profiling_point.end_index.insert(current_idx);
  706. GELOGI("Iter end name %s, idx %u, from FlowCtrl_LoopCond_ASSIGN",
  707. op_desc->GetName().c_str(), current_idx);
  708. }
  709. } else {
  710. if (op_desc->GetName() == NODE_NAME_NET_OUTPUT) {
  711. profiling_point.end_index.insert(current_idx);
  712. GELOGI("Iter end name %s, idx %u, from NETOUTPUT", op_desc->GetName().c_str(), current_idx);
  713. }
  714. }
  715. }
  716. if (bp_node == nullptr) {
  717. GELOGW("not find bp_node.");
  718. return SUCCESS;
  719. }
  720. profiling_point.bp_index = FindLastBpFromBpNode(graph, bp_node);
  721. return SUCCESS;
  722. }
  723. uint32_t TaskGenerator::FindLastBpFromBpNode(const ComputeGraphPtr &graph, const NodePtr &bp_node) const {
  724. uint32_t last_bp = 0;
  725. OpDescPtr bp_op_desc = nullptr;
  726. for (auto &in_anchor : bp_node->GetAllInDataAnchors()) {
  727. auto out_anchor = in_anchor->GetPeerOutAnchor();
  728. if (out_anchor == nullptr || out_anchor->GetOwnerNode() == nullptr) {
  729. continue;
  730. }
  731. auto out_node_desc = out_anchor->GetOwnerNode()->GetOpDesc();
  732. GE_CHECK_NOTNULL(out_node_desc);
  733. if (bp_op_desc == nullptr || ((out_node_desc->GetId()) > (bp_op_desc->GetId()))) {
  734. bp_op_desc = out_node_desc;
  735. }
  736. GELOGI("bp_op_desc is %s, id is %ld", bp_op_desc->GetName().c_str(), bp_op_desc->GetId());
  737. }
  738. GE_CHECK_NOTNULL(bp_op_desc);
  739. uint32_t current_idx = 0;
  740. for (auto &node : graph->GetNodes(graph->GetGraphUnknownFlag())) {
  741. OpDescPtr op_desc = node->GetOpDesc();
  742. GE_CHECK_NOTNULL(op_desc);
  743. current_idx++;
  744. if (op_desc->GetName() == bp_op_desc->GetName()) {
  745. last_bp = current_idx;
  746. GELOGI("First bp name %s, idx %u", op_desc->GetName().c_str(), last_bp);
  747. break;
  748. }
  749. }
  750. return last_bp;
  751. }
  752. Status TaskGenerator::FindFpOfEnv(const ComputeGraphPtr &graph, const std::string &fp_point_str,
  753. ProfilingPoint &profiling_point) const {
  754. GELOGI("Start FindFpOfEnv");
  755. uint32_t current_idx = 0;
  756. uint32_t first_fp = 0;
  757. for (auto &node : graph->GetNodes(graph->GetGraphUnknownFlag())) {
  758. OpDescPtr op_desc = node->GetOpDesc();
  759. GE_CHECK_NOTNULL(node->GetOpDesc());
  760. current_idx++;
  761. string op_kernel_lib_name = op_desc->GetOpKernelLibName();
  762. if (op_kernel_lib_name.empty()) {
  763. continue;
  764. }
  765. if (first_fp == 0 && IsProfPoint(op_desc, fp_point_str)) {
  766. first_fp = current_idx;
  767. GELOGI("First fp name from env is %s, idx %u", op_desc->GetName().c_str(), first_fp);
  768. }
  769. }
  770. profiling_point.fp_index = first_fp;
  771. return SUCCESS;
  772. }
  773. Status TaskGenerator::FindBpOfEnv(const ComputeGraphPtr &graph, const std::string &bp_point_str,
  774. ProfilingPoint &profiling_point, vector<uint32_t> &all_reduce_nodes) const {
  775. GELOGI("Start FindBpOfEnv");
  776. uint32_t current_idx = 0;
  777. uint32_t last_bp = 0;
  778. for (auto &node : graph->GetNodes(graph->GetGraphUnknownFlag())) {
  779. OpDescPtr op_desc = node->GetOpDesc();
  780. GE_CHECK_NOTNULL(node->GetOpDesc());
  781. current_idx++;
  782. string op_kernel_lib_name = op_desc->GetOpKernelLibName();
  783. if (op_kernel_lib_name.empty()) {
  784. continue;
  785. }
  786. if (graph->GetNeedIteration()) {
  787. if (op_desc->GetName() == NODE_NAME_FLOWCTRL_LOOP_ASSIGNADD) {
  788. profiling_point.end_index.insert(current_idx);
  789. GELOGI("Iter end name %s, idx %u, from Node_Output_IteratorCtrl_StreamSwitch_StreamActive",
  790. op_desc->GetName().c_str(), current_idx);
  791. }
  792. if (op_desc->GetName() == NODE_NAME_FLOWCTRL_LOOP_ASSIGN) {
  793. profiling_point.end_index.insert(current_idx);
  794. GELOGI("Iter end name %s, idx %u, from FlowCtrl_LoopCond_ASSIGN",
  795. op_desc->GetName().c_str(), current_idx);
  796. }
  797. } else {
  798. if (op_desc->GetName() == NODE_NAME_NET_OUTPUT) {
  799. profiling_point.end_index.insert(current_idx);
  800. GELOGI("Iter end name %s, idx %u, from NETOUTPUT", op_desc->GetName().c_str(), current_idx);
  801. }
  802. }
  803. if (op_desc->GetType() == HCOMALLREDUCE || op_desc->GetType() == HVDCALLBACKALLREDUCE) {
  804. all_reduce_nodes.emplace_back(current_idx);
  805. GELOGI("Allreduce name %s, idx %u", op_desc->GetName().c_str(), current_idx);
  806. }
  807. if (IsProfPoint(op_desc, bp_point_str)) {
  808. last_bp = current_idx;
  809. GELOGI("Last bp name from env is %s, idx %u", op_desc->GetName().c_str(), last_bp);
  810. }
  811. }
  812. profiling_point.bp_index = last_bp;
  813. return SUCCESS;
  814. }
  815. Status TaskGenerator::GetFpBpIndex(const ComputeGraphPtr &graph, ProfilingPoint &profiling_point,
  816. vector<uint32_t> &all_reduce_nodes, std::string &fp_point_str,
  817. std::string &bp_point_str) const {
  818. ProfilingManager::Instance().GetFpBpPoint(fp_point_str, bp_point_str);
  819. Status ret = SUCCESS;
  820. if (fp_point_str.empty()) {
  821. ret = AutoFindFpOpIndex(graph, profiling_point);
  822. if (ret != SUCCESS) {
  823. GELOGW("First forward profiling op_index not set and FindFpOpIndex failed.");
  824. return FAILED;
  825. }
  826. }
  827. if (bp_point_str.empty()) {
  828. ret = AutoFindBpOpIndex(graph, profiling_point, all_reduce_nodes);
  829. if (ret != SUCCESS) {
  830. GELOGW("Last backward profiling op_index not set and FindBpOpIndex failed.");
  831. return FAILED;
  832. }
  833. }
  834. return SUCCESS;
  835. }
  836. Status TaskGenerator::FindProfilingNodeIndex(const ComputeGraphPtr &graph, ProfilingPoint &profiling_point,
  837. std::vector<uint32_t> &all_reduce_nodes) {
  838. return FindProfilingTaskIndex(graph, profiling_point, all_reduce_nodes);
  839. }
  840. Status TaskGenerator::FindProfilingTaskIndex(const ComputeGraphPtr &graph, ProfilingPoint &profiling_point,
  841. vector<uint32_t> &all_reduce_nodes) const {
  842. GE_CHECK_NOTNULL(graph);
  843. const char *profiling_mode = std::getenv(kProfilingMode);
  844. bool is_profiling = (profiling_mode != nullptr) || ProfilingManager::Instance().ProfilingOn() ||
  845. ProfilingManager::Instance().ProfilingTrainingTraceOn();
  846. if (!is_profiling) {
  847. GELOGD("Profiling is not open.");
  848. return SUCCESS;
  849. }
  850. // subgraph of dynamic graph no need to find index, has been found in parent graph
  851. if (IsSubGraphOfDynamicGraph(graph)) {
  852. GELOGI("Graph[%s] is subgraph of dynamic graph, no need to find index.", graph->GetName().c_str());
  853. return SUCCESS;
  854. }
  855. GELOGI("Start get FP/BP index.");
  856. std::string fp_point_str;
  857. std::string bp_point_str;
  858. Status ret = GetFpBpIndex(graph, profiling_point, all_reduce_nodes, fp_point_str, bp_point_str);
  859. if (ret != SUCCESS) {
  860. GELOGW("Get FP_POINT BP_POINT failed.");
  861. return SUCCESS;
  862. }
  863. GELOGI("fp_point_str:%s, bp_point_str:%s.", fp_point_str.c_str(), bp_point_str.c_str());
  864. if (!fp_point_str.empty()) {
  865. ret = FindFpOfEnv(graph, fp_point_str, profiling_point);
  866. if (ret != SUCCESS) {
  867. GELOGW("First backward profiling op name set but FindFpOfEnv failed.");
  868. return SUCCESS;
  869. }
  870. }
  871. if (!bp_point_str.empty()) {
  872. ret = FindBpOfEnv(graph, bp_point_str, profiling_point, all_reduce_nodes);
  873. if (ret != SUCCESS) {
  874. GELOGW("Last backward profiling op name set but FindBpOfEnv failed.");
  875. return SUCCESS;
  876. }
  877. }
  878. bool train_graph = graph->GetNeedIteration();
  879. if (profiling_point.fp_index == 0 && train_graph) {
  880. GELOGW("First forward op name can't be found in graph for training trace.");
  881. }
  882. if (profiling_point.bp_index == 0 && train_graph) {
  883. GELOGW("Last backward op name can't be found in graph for training trace.");
  884. }
  885. return SUCCESS;
  886. }
  887. Status TaskGenerator::InsertProfilingArTaskBefore(const OpDescPtr &op_desc, std::vector<uint32_t> &all_reduce_nodes,
  888. uint32_t node_index, std::vector<domi::TaskDef> &task_def_list,
  889. bool is_insert_bp_profiling_task) {
  890. bool is_insert_all_reduce_task = false;
  891. int64_t ar_log_id = 0xFFFF;
  892. if (is_insert_bp_profiling_task) {
  893. (void)ge::AttrUtils::GetInt(op_desc, ATTR_NAME_INSERT_PROFILILNG_TASK_LOG_ID, ar_log_id);
  894. is_insert_all_reduce_task = true;
  895. }
  896. if (!is_insert_all_reduce_task) {
  897. for (size_t i = 0; i < all_reduce_nodes.size(); i++) {
  898. if (all_reduce_nodes[i] == node_index) {
  899. GE_IF_BOOL_EXEC(TypeUtils::CheckUint64MulOverflow(i, kProfilingArStep),
  900. REPORT_INNER_ERROR("E19999", "Multiply result is out of range when calc profiling ar log id "
  901. "for node:%s(%s)", op_desc->GetName().c_str(), op_desc->GetType().c_str());
  902. GELOGE(FAILED, "Multiply result is out of range.");
  903. return FAILED);
  904. ar_log_id = i * kProfilingArStep + kProfilingArStartLogid;
  905. is_insert_all_reduce_task = true;
  906. break;
  907. }
  908. }
  909. }
  910. if (is_insert_all_reduce_task) {
  911. GELOGI("The start allreduce operator is %s, idx %u, log_id %ld", op_desc->GetName().c_str(), node_index, ar_log_id);
  912. TaskDef ar_task_def;
  913. ar_task_def.set_type(RT_MODEL_TASK_PROFILER_TRACE);
  914. ar_task_def.set_stream_id(op_desc->GetStreamId());
  915. LogTimeStampDef *ar_log_def = ar_task_def.mutable_log_timestamp();
  916. if (ar_log_def != nullptr) {
  917. ar_log_def->set_logid(ar_log_id);
  918. ar_log_def->set_notify(false);
  919. }
  920. task_def_list.push_back(ar_task_def);
  921. }
  922. return SUCCESS;
  923. }
  924. Status TaskGenerator::InsertProfilingTaskBefore(const OpDescPtr &op_desc, const ProfilingPoint &profiling_point,
  925. vector<uint32_t> &all_reduce_nodes, uint32_t node_index,
  926. vector<domi::TaskDef> &task_def_list) {
  927. const char *profiling_mode = std::getenv(kProfilingMode);
  928. bool is_profiling = (profiling_mode != nullptr) || ProfilingManager::Instance().ProfilingOn() ||
  929. ProfilingManager::Instance().ProfilingTrainingTraceOn();
  930. bool is_insert_fp_profiling_task = false;
  931. (void)ge::AttrUtils::GetBool(op_desc, ATTR_NAME_INSERT_FP_PROFILILNG_TASK, is_insert_fp_profiling_task);
  932. bool is_insert_bp_profiling_task = false;
  933. (void)ge::AttrUtils::GetBool(op_desc, ATTR_NAME_INSERT_BP_PROFILILNG_TASK, is_insert_bp_profiling_task);
  934. bool no_insert_profiling_task = ((profiling_point.fp_index == 0) || (profiling_point.bp_index == 0) ||
  935. (profiling_point.end_index.empty())) &&
  936. (!(is_insert_fp_profiling_task || is_insert_bp_profiling_task));
  937. if (!is_profiling || no_insert_profiling_task) {
  938. return SUCCESS;
  939. }
  940. GELOGD("Insert fp profiling task: %d, insert bp profiling task: %d, fp index: %u, bp index: %u, end index size: %zu",
  941. is_insert_fp_profiling_task, is_insert_bp_profiling_task, profiling_point.fp_index, profiling_point.bp_index,
  942. profiling_point.end_index.size());
  943. if ((profiling_point.fp_index == node_index) || is_insert_fp_profiling_task) {
  944. uint64_t jobid_log_id = ge::GetContext().TraceId();
  945. GELOGI("The first FP operator is %s, idx %u, job_id %lu", op_desc->GetName().c_str(), node_index, jobid_log_id);
  946. TaskDef job_task_def;
  947. job_task_def.set_type(RT_MODEL_TASK_PROFILER_TRACE);
  948. job_task_def.set_stream_id(op_desc->GetStreamId());
  949. LogTimeStampDef *job_log_def = job_task_def.mutable_log_timestamp();
  950. if (job_log_def != nullptr) {
  951. job_log_def->set_logid(jobid_log_id);
  952. job_log_def->set_notify(false);
  953. }
  954. task_def_list.emplace_back(job_task_def);
  955. TaskDef fp_task_def;
  956. fp_task_def.set_type(RT_MODEL_TASK_PROFILER_TRACE);
  957. fp_task_def.set_stream_id(op_desc->GetStreamId());
  958. LogTimeStampDef *fp_log_def = fp_task_def.mutable_log_timestamp();
  959. if (fp_log_def != nullptr) {
  960. fp_log_def->set_logid(kProfilingFpStartLogid);
  961. fp_log_def->set_notify(false);
  962. }
  963. task_def_list.emplace_back(fp_task_def);
  964. }
  965. bool is_all_reduce = (op_desc->GetType() == HCOMALLREDUCE || op_desc->GetType() == HVDCALLBACKALLREDUCE);
  966. if (is_all_reduce) {
  967. (void)InsertProfilingArTaskBefore(op_desc, all_reduce_nodes, node_index,
  968. task_def_list, is_insert_bp_profiling_task);
  969. }
  970. return SUCCESS;
  971. }
  972. Status TaskGenerator::InsertProfilingArTaskAfter(const OpDescPtr &op_desc, std::vector<uint32_t> &all_reduce_nodes,
  973. uint32_t node_index, std::vector<domi::TaskDef> &task_def_list,
  974. bool is_insert_bp_profiling_task) {
  975. bool is_insert_all_reduce_task = false;
  976. int64_t ar_log_id = 0xFFFF;
  977. if (is_insert_bp_profiling_task) {
  978. (void)ge::AttrUtils::GetInt(op_desc, ATTR_NAME_INSERT_PROFILILNG_TASK_LOG_ID, ar_log_id);
  979. ar_log_id += 1;
  980. is_insert_all_reduce_task = true;
  981. }
  982. if (!is_insert_all_reduce_task) {
  983. for (size_t i = 0; i < all_reduce_nodes.size(); i++) {
  984. if (all_reduce_nodes[i] == node_index) {
  985. GE_IF_BOOL_EXEC(TypeUtils::CheckUint64MulOverflow(i, kProfilingArStep),
  986. REPORT_INNER_ERROR("E19999", "Multiply result is out of range when calc profiling ar log id "
  987. "for node:%s(%s)", op_desc->GetName().c_str(), op_desc->GetType().c_str());
  988. GELOGE(FAILED, "Multiply result is out of range.");
  989. return FAILED);
  990. ar_log_id = i * kProfilingArStep + kProfilingArEndLogid;
  991. is_insert_all_reduce_task = true;
  992. break;
  993. }
  994. }
  995. }
  996. if (is_insert_all_reduce_task) {
  997. GELOGI("The start allreduce operator is %s, idx %u, log_id %ld", op_desc->GetName().c_str(), node_index, ar_log_id);
  998. TaskDef ar_task_def;
  999. ar_task_def.set_type(RT_MODEL_TASK_PROFILER_TRACE);
  1000. ar_task_def.set_stream_id(op_desc->GetStreamId());
  1001. LogTimeStampDef *ar_log_def = ar_task_def.mutable_log_timestamp();
  1002. if (ar_log_def != nullptr) {
  1003. ar_log_def->set_logid(ar_log_id);
  1004. ar_log_def->set_notify(false);
  1005. }
  1006. task_def_list.push_back(ar_task_def);
  1007. }
  1008. return SUCCESS;
  1009. }
  1010. Status TaskGenerator::InsertProfilingTaskAfter(const OpDescPtr &op_desc, const ProfilingPoint &profiling_point,
  1011. vector<uint32_t> &all_reduce_nodes, uint32_t node_index,
  1012. vector<domi::TaskDef> &task_def_list) {
  1013. GE_CHECK_NOTNULL(op_desc);
  1014. const char *profiling_mode = std::getenv(kProfilingMode);
  1015. bool is_profiling = (profiling_mode != nullptr) || ProfilingManager::Instance().ProfilingOn() ||
  1016. ProfilingManager::Instance().ProfilingTrainingTraceOn();
  1017. bool is_insert_bp_profiling_task = false;
  1018. (void)ge::AttrUtils::GetBool(op_desc, ATTR_NAME_INSERT_BP_PROFILILNG_TASK, is_insert_bp_profiling_task);
  1019. bool is_insert_end_profiling_task = false;
  1020. (void)ge::AttrUtils::GetBool(op_desc, ATTR_NAME_INSERT_END_PROFILILNG_TASK, is_insert_end_profiling_task);
  1021. bool no_insert_profiling_task = ((profiling_point.fp_index == 0) || (profiling_point.bp_index == 0) ||
  1022. (profiling_point.end_index.empty())) &&
  1023. (!(is_insert_bp_profiling_task || is_insert_end_profiling_task));
  1024. if (!is_profiling || no_insert_profiling_task) {
  1025. return SUCCESS;
  1026. }
  1027. GELOGD("Insert bp profiling task: %d, insert end profiling task: %d, fp index: %u, bp index: %u, end index size: %zu",
  1028. is_insert_bp_profiling_task, is_insert_end_profiling_task, profiling_point.fp_index, profiling_point.bp_index,
  1029. profiling_point.end_index.size());
  1030. bool is_all_reduce = (op_desc->GetType() == HCOMALLREDUCE || op_desc->GetType() == HVDCALLBACKALLREDUCE);
  1031. if ((profiling_point.bp_index == node_index) || (!is_all_reduce && is_insert_bp_profiling_task)) {
  1032. GELOGI("The last BP operator is %s, idx %u", op_desc->GetName().c_str(), node_index);
  1033. TaskDef bp_task_def;
  1034. bp_task_def.set_type(RT_MODEL_TASK_PROFILER_TRACE);
  1035. bp_task_def.set_stream_id(op_desc->GetStreamId());
  1036. LogTimeStampDef *bp_log_def = bp_task_def.mutable_log_timestamp();
  1037. GE_CHECK_NOTNULL(bp_log_def);
  1038. bp_log_def->set_logid(kProfilingBpEndLogid);
  1039. bp_log_def->set_notify(false);
  1040. task_def_list.emplace_back(bp_task_def);
  1041. }
  1042. if (profiling_point.end_index.find(node_index) != profiling_point.end_index.end() ||
  1043. is_insert_end_profiling_task) {
  1044. GELOGI("The iteration end operator is %s, idx %u", op_desc->GetName().c_str(), node_index);
  1045. TaskDef end_task_def;
  1046. end_task_def.set_type(RT_MODEL_TASK_PROFILER_TRACE);
  1047. end_task_def.set_stream_id(op_desc->GetStreamId());
  1048. LogTimeStampDef *end_log_def = end_task_def.mutable_log_timestamp();
  1049. GE_CHECK_NOTNULL(end_log_def);
  1050. end_log_def->set_logid(kProfilingIterEndLogid);
  1051. end_log_def->set_notify(true);
  1052. task_def_list.emplace_back(end_task_def);
  1053. }
  1054. if (is_all_reduce) {
  1055. (void)InsertProfilingArTaskAfter(op_desc, all_reduce_nodes, node_index,
  1056. task_def_list, is_insert_bp_profiling_task);
  1057. }
  1058. return SUCCESS;
  1059. }
  1060. bool TaskGenerator::IsProfPoint(const OpDescPtr &op, const std::string &name) {
  1061. if (op == nullptr) {
  1062. return false;
  1063. }
  1064. if (op->GetName() == name) {
  1065. return true;
  1066. }
  1067. std::vector<std::string> original_op_names;
  1068. bool ret = AttrUtils::GetListStr(op, ge::ATTR_NAME_DATA_DUMP_ORIGIN_OP_NAMES, original_op_names);
  1069. if (!ret) {
  1070. return false;
  1071. }
  1072. for (auto &origin_name : original_op_names) {
  1073. if (origin_name == name) {
  1074. return true;
  1075. }
  1076. }
  1077. return false;
  1078. }
  1079. Status TaskGenerator::SetUnknownShapeStream(RunContext &run_context, rtStream_t &stream) {
  1080. GE_CHK_RT_RET(rtStreamCreate(&stream, 0));
  1081. run_context.stream = stream;
  1082. rtError_t rt_ret = rtModelBindStream(run_context.model, stream, 0);
  1083. if (rt_ret != RT_ERROR_NONE) {
  1084. REPORT_CALL_ERROR("E19999", "Call rtModelBindStream fail, ret:0x%X when %s", rt_ret, __FUNCTION__);
  1085. GELOGE(FAILED, "Call rt api failed, ret: 0x%X", rt_ret);
  1086. GE_CHK_RT_RET(rtStreamDestroy(stream));
  1087. return FAILED;
  1088. }
  1089. return SUCCESS;
  1090. }
  1091. Status TaskGenerator::DestroyUnknownShapeStream(RunContext &run_context, rtStream_t &stream) {
  1092. GE_CHK_RT(rtModelUnbindStream(run_context.model, stream));
  1093. GE_CHK_RT_RET(rtStreamDestroy(stream));
  1094. return SUCCESS;
  1095. }
  1096. Status TaskGenerator::SetKnownShapeStream(RunContext &run_context, int64_t stream_id) {
  1097. if (stream_id < 0 || stream_id >= static_cast<int64_t>(run_context.graphStreamList.size())) {
  1098. GELOGE(INTERNAL_ERROR, "Stream id[%ld] is invalid, stream list size=%zu", stream_id,
  1099. run_context.graphStreamList.size());
  1100. return INTERNAL_ERROR;
  1101. }
  1102. run_context.stream = run_context.graphStreamList[stream_id];
  1103. return SUCCESS;
  1104. }
  1105. } // namespace ge

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