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

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