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.

action.cc 20 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. /**
  2. * Copyright 2019 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 "pipeline/jit/action.h"
  17. #include <memory>
  18. #include <utility>
  19. #include <vector>
  20. #include <string>
  21. #include <algorithm>
  22. #include <functional>
  23. #include "ir/func_graph_cloner.h"
  24. #include "ir/param_value.h"
  25. #include "frontend/parallel/costmodel_context.h"
  26. #include "frontend/parallel/context.h"
  27. #include "pipeline/jit/pass.h"
  28. #include "pipeline/jit/parse/parse_base.h"
  29. #include "pipeline/jit/parse/data_converter.h"
  30. #include "abstract/abstract_value.h"
  31. #include "pipeline/jit/static_analysis/static_analysis.h"
  32. #include "pipeline/jit/static_analysis/program_specialize.h"
  33. #include "pipeline/jit/resource.h"
  34. #include "utils/context/ms_context.h"
  35. #include "pipeline/jit/remove_value_node_dup.h"
  36. #include "frontend/optimizer/optimizer.h"
  37. #include "vm/transform.h"
  38. #include "parse/python_adapter.h"
  39. #include "frontend/optimizer/py_pass_manager.h"
  40. #if (ENABLE_CPU && (ENABLE_D || ENABLE_GPU))
  41. #include "frontend/parallel/ps/parameter_server.h"
  42. #include "frontend/parallel/ps/scheduler.h"
  43. #include "frontend/parallel/ps/worker.h"
  44. #endif
  45. namespace mindspore {
  46. namespace pipeline {
  47. using CompileGraphs = compile::CompileGraphs;
  48. using abstract::AnalysisResult;
  49. using mindspore::abstract::AnalysisContextPtr;
  50. abstract::AnalysisResult AbstractAnalyze(const ResourcePtr &res, const FuncGraphPtr &func_graph,
  51. const abstract::AbstractBasePtrList &args_spec, bool clear) {
  52. MS_LOG(DEBUG) << "AbstractAnalyze start";
  53. auto engine = res->engine();
  54. MS_EXCEPTION_IF_NULL(engine);
  55. if (clear) {
  56. auto manager = res->manager();
  57. MS_EXCEPTION_IF_NULL(manager);
  58. engine->Clear();
  59. for (auto &node : manager->all_nodes()) {
  60. MS_EXCEPTION_IF_NULL(node);
  61. const AbstractBasePtr &prev_inferred = node->abstract();
  62. // Keep previous inferred value for ValueNode if the inferred value is not AbstractFunction.
  63. if (!node->isa<ValueNode>() || (prev_inferred != nullptr && prev_inferred->isa<abstract::AbstractFunction>())) {
  64. node->set_abstract(nullptr);
  65. MS_LOG(DEBUG) << "Abstract of node " << node->ToString() << " is set to nullptr";
  66. }
  67. }
  68. }
  69. auto ret = engine->Run(func_graph, args_spec);
  70. MS_LOG(DEBUG) << "AbstractAnalyze end";
  71. return ret;
  72. }
  73. FuncGraphPtr ProgramSpecialize(const ResourcePtr &res, const FuncGraphPtr &func_graph,
  74. const abstract::AnalysisContextPtr &context) {
  75. MS_LOG(DEBUG) << "ProgramSpecialize start";
  76. abstract::ProgramSpecializer spc(res->engine());
  77. FuncGraphPtr result = spc.Run(func_graph, context);
  78. auto manager = res->manager();
  79. MS_EXCEPTION_IF_NULL(manager);
  80. manager->KeepRoots({result});
  81. MS_LOG(DEBUG) << "ProgramSpecialize end";
  82. return result;
  83. }
  84. FuncGraphPtr Renormalize(const ResourcePtr &res, const FuncGraphPtr &func_graph,
  85. const abstract::AbstractBasePtrList &args_spec) {
  86. MS_LOG(DEBUG) << "Renormalize start";
  87. #ifdef ENABLE_PROFILE
  88. double t1 = GetTime();
  89. #endif
  90. abstract::AnalysisResult result = AbstractAnalyze(res, func_graph, args_spec, true);
  91. #ifdef ENABLE_PROFILE
  92. double t2 = GetTime();
  93. #endif
  94. auto ret = ProgramSpecialize(res, func_graph, result.context);
  95. res->set_func_graph(ret);
  96. #ifdef ENABLE_PROFILE
  97. double t3 = GetTime();
  98. MsProfile::StatTime("renormalize.infer", t2 - t1);
  99. MsProfile::StatTime("renormalize.specialize", t3 - t2);
  100. #endif
  101. MS_LOG(DEBUG) << "Renormalize end";
  102. return ret;
  103. }
  104. bool ParseAction(const ResourcePtr &res) {
  105. if (!res->input()) {
  106. MS_LOG(EXCEPTION) << "Parse error";
  107. }
  108. py::object input = res->input();
  109. parse::Parser::InitParserEnvironment(input);
  110. py::module path = py::module::import("os.path");
  111. std::string dir = path.attr("dirname")(py::globals()["__file__"]).cast<std::string>();
  112. parse::python_adapter::set_python_env_flag(true);
  113. parse::python_adapter::SetPythonPath(dir);
  114. FuncGraphPtr fg = parse::ConvertToFuncGraph(input);
  115. if (fg == nullptr) {
  116. MS_LOG(EXCEPTION) << "Parse error.";
  117. }
  118. res->set_func_graph(fg);
  119. FuncGraphManagerPtr manager = res->manager();
  120. if (manager == nullptr) {
  121. MS_LOG(EXCEPTION) << "Manager is nullptr.";
  122. }
  123. manager->AddFuncGraph(fg);
  124. return true;
  125. }
  126. // obj_map's graphs have the same construct, these graphs can be optimized to one graph.
  127. // This step do this optimize: graph1(x){xx(fv1),xxx(fv2)}, graph2(x){xxx(fv3),xxx(fv4)}->
  128. // graph1(x){base_graph(x, fv1, fv2)}, graph1(x){base_graph(x, fv3, fv4)}, base_graph(x, fv...){xxx,xxx}
  129. // all obj_map's graph shared base_graph
  130. bool CombineLikeGraphs(const ResourcePtr &res) {
  131. auto &obj_map = parse::data_converter::GetObjGraphs();
  132. for (auto it : obj_map) {
  133. auto &graphs = it.second;
  134. MS_LOG(DEBUG) << "Start combine like graph:" << it.first << ", size:" << graphs.size();
  135. auto fg = graphs[0];
  136. FuncGraphPtrList func_graphs = {fg};
  137. ClonerPtr cloner = std::make_shared<Cloner>(func_graphs, false, false, true, std::make_shared<TraceCopy>(),
  138. std::make_shared<TraceCombileLikeGraphs>());
  139. cloner->Run();
  140. auto base_graph = cloner->cloned_func_graph()[fg];
  141. MS_LOG(DEBUG) << "Basegraph:" << base_graph->ToString();
  142. if (fg->paramter_obj_nodes().size() == 0 || graphs.size() <= 1) {
  143. continue;
  144. }
  145. for (auto &fv : fg->paramter_obj_nodes()) {
  146. TraceManager::DebugTrace(std::make_shared<TraceCombileLikeGraphs>(fv->debug_info()));
  147. auto param = base_graph->add_parameter();
  148. TraceManager::EndTrace();
  149. auto &node_users = res->manager()->node_users()[fv];
  150. for (auto &n : node_users) {
  151. auto repl_n = (*cloner->cloned_node())[n.first]->cast<CNodePtr>();
  152. repl_n->set_input(n.second, param);
  153. }
  154. }
  155. MS_LOG(DEBUG) << "Fg0 paramter_obj_nodes size :" << fg->paramter_obj_nodes().size();
  156. for (auto &g : graphs) {
  157. auto fvs = g->paramter_obj_nodes();
  158. std::vector<AnfNodePtr> new_node_inputs;
  159. new_node_inputs.push_back(NewValueNode(base_graph));
  160. for (auto &p : g->parameters()) {
  161. AnfNodePtr para_after_cast = parse::GetMixedPrecisionCastHelp(g, p);
  162. new_node_inputs.push_back(para_after_cast);
  163. }
  164. (void)new_node_inputs.insert(new_node_inputs.end(), fvs.begin(), fvs.end());
  165. AnfNodePtr out = g->NewCNode(new_node_inputs);
  166. g->set_output(out);
  167. MS_LOG(DEBUG) << "Combine graph newout:" << out->DebugString(4);
  168. }
  169. MS_LOG(DEBUG) << "End combine graph:" << it.first;
  170. }
  171. return true;
  172. }
  173. bool SymbolResolveAction(const ResourcePtr &res) {
  174. if (res->manager() == nullptr) {
  175. MS_LOG(EXCEPTION) << "SymbolResolve error, manager is null";
  176. }
  177. if (res->func_graph() == nullptr) {
  178. MS_LOG(EXCEPTION) << "SymbolResolve error, graph is null";
  179. }
  180. FuncGraphPtr func_graph = res->func_graph();
  181. auto succ = parse::ResolveFuncGraph(func_graph, res);
  182. // Remove unused nodes in cnode order list.
  183. func_graph->EraseUnusedNodeInOrder();
  184. func_graph->ReleaseFullOrderToEffectOrder();
  185. for (auto fg : func_graph->func_graphs_used_total()) {
  186. MS_EXCEPTION_IF_NULL(fg);
  187. fg->EraseUnusedNodeInOrder();
  188. fg->ReleaseFullOrderToEffectOrder();
  189. }
  190. return succ;
  191. }
  192. bool InferenceOptPrepareAction(const ResourcePtr &res) {
  193. if (res->manager() == nullptr) {
  194. MS_LOG(EXCEPTION) << "InferenceOptPrepare error, manager is null.";
  195. }
  196. if (res->func_graph() == nullptr) {
  197. MS_LOG(EXCEPTION) << "InferenceOptPrepare error, graph is null.";
  198. }
  199. return InferenceOptPreparePass(res);
  200. }
  201. bool AbstractSpecializeAction(const ResourcePtr &res) {
  202. if (res->func_graph() == nullptr) {
  203. MS_LOG(EXCEPTION) << "AbstractSpecialize error";
  204. }
  205. FuncGraphPtr func_graph = res->func_graph();
  206. abstract::AbstractBasePtrList args_spec = res->args_spec();
  207. parallel::ParallelParameterContextInit(func_graph);
  208. // suppose that there is not KeywordArgument for the top graph
  209. // get the hyper parameter
  210. for (const auto &param : func_graph->parameters()) {
  211. auto param_node = std::static_pointer_cast<Parameter>(param);
  212. if (param_node->has_default()) {
  213. const auto &param_value = param_node->default_param();
  214. ValuePtr value = param_value->value();
  215. constexpr bool broaden = true;
  216. AbstractBasePtr ptr = abstract::FromValue(value, broaden);
  217. parallel::ParallelParameterContextRestoreInNoTraining(func_graph, param_node, ptr);
  218. args_spec.push_back(ptr);
  219. parallel::ParallelParameterContextCkptInTraining(func_graph, param_node, ptr);
  220. }
  221. }
  222. // Analyze
  223. AnalysisResult result = AbstractAnalyze(res, func_graph, args_spec);
  224. // The top graph may be replaced by infer, update the top graph when the infer is done
  225. parse::Parser::UpdateTopFuncGraph(result.context->func_graph());
  226. // Specialize
  227. FuncGraphPtr new_fg = ProgramSpecialize(res, result.context->func_graph(), result.context);
  228. res->set_func_graph(new_fg);
  229. MS_LOG(DEBUG) << "End graph: " << new_fg->ToString() << ", return: " << new_fg->get_return()->DebugString(true);
  230. return true;
  231. }
  232. bool OptimizeAction(const ResourcePtr &res, const std::vector<PassItem> &passes) {
  233. size_t counter = 0;
  234. for (auto &pass : passes) {
  235. WITH(MsProfile::GetProfile()->Step(pass.first))[&pass, &res, &counter]() {
  236. MS_LOG(DEBUG) << "Pass " << pass.first << " start ...";
  237. auto result = pass.second(res);
  238. if (!result) {
  239. MS_LOG(EXCEPTION) << "Pass running to end, failed in pass:" << pass.first;
  240. }
  241. if (MsContext::GetInstance()->save_graphs_flag() && res->func_graph() != nullptr) {
  242. auto fg_name = "opt_pass_" + std::to_string(counter) + "_" + pass.first;
  243. auto func_graph = res->func_graph();
  244. MS_EXCEPTION_IF_NULL(func_graph);
  245. func_graph->DumpFuncGraph(fg_name);
  246. DumpIR(fg_name + ".ir", func_graph);
  247. MS_LOG(DEBUG) << "Dump " << fg_name << " func graph.";
  248. }
  249. counter++;
  250. MS_LOG(DEBUG) << "Pass " << pass.first << " end.";
  251. };
  252. }
  253. return true;
  254. }
  255. bool GeOptimizeAction(const ResourcePtr &res) { return OptimizeAction(res, kGePasses); }
  256. bool VmOptimizeAction(const ResourcePtr &res) { return OptimizeAction(res, kVmPasses); }
  257. bool PynativeOptimizeAction(const ResourcePtr &res) { return OptimizeAction(res, kPynativePasses); }
  258. static bool IsCtrlSink() {
  259. auto ms_ctx = MsContext::GetInstance();
  260. if (ms_ctx->execution_mode() != kGraphMode) {
  261. return false;
  262. }
  263. std::string device_target = ms_ctx->device_target();
  264. if (device_target != kAscendDevice) {
  265. return false;
  266. }
  267. if (!ms_ctx->enable_task_sink()) {
  268. return false;
  269. }
  270. if (!ms_ctx->is_multi_graph_sink()) {
  271. return false;
  272. }
  273. return true;
  274. }
  275. bool TaskEmitAction(const ResourcePtr &res) {
  276. if (res->func_graph() == nullptr) {
  277. MS_LOG(EXCEPTION) << "TaskEmit args error";
  278. }
  279. FuncGraphPtr func_graph = res->func_graph();
  280. auto bc_ptr = res->results()[kBackend].cast<compile::BackendPtr>();
  281. auto context_ptr = MsContext::GetInstance();
  282. MS_EXCEPTION_IF_NULL(context_ptr);
  283. if (CompileGraphs::ContainMixedTarget(func_graph)) {
  284. bc_ptr->set_is_multi_graph_sink(false);
  285. context_ptr->set_is_multi_graph_sink(false);
  286. context_ptr->set_loop_sink_flag(false);
  287. } else if (context_ptr->execution_mode() != kPynativeMode) {
  288. std::string device_target = context_ptr->device_target();
  289. if (device_target == kAscendDevice) {
  290. bc_ptr->set_is_multi_graph_sink(true);
  291. context_ptr->set_is_multi_graph_sink(true);
  292. }
  293. }
  294. if (IsCtrlSink()) {
  295. res->results()[kOutput] = bc_ptr->CompileGraph(NOT_NULL(func_graph));
  296. return true;
  297. }
  298. std::vector<PrimitivePtr> cut_list = compile::nonlinear_ops;
  299. if (bc_ptr->name() == kMsConvert) {
  300. cut_list = compile::GetMsNonlinearOps();
  301. }
  302. std::shared_ptr<CompileGraphs> compile = std::make_shared<CompileGraphs>(bc_ptr, cut_list);
  303. res->results()[kOutput] = compile->CompileAndLink(func_graph);
  304. return true;
  305. }
  306. bool ExecuteAction(const ResourcePtr &res) {
  307. if (res->results().count(kOutput) == 0) {
  308. MS_LOG(EXCEPTION) << "Execute args error";
  309. }
  310. if (IsCtrlSink()) {
  311. if (!res->results()[kOutput].is<GraphId>()) {
  312. MS_LOG(EXCEPTION) << "Execute args error";
  313. }
  314. auto graph_id = res->results()[kOutput].cast<GraphId>();
  315. std::shared_ptr<compile::Backend> bc_ptr = res->results()[kBackend].cast<std::shared_ptr<compile::Backend>>();
  316. std::shared_ptr<compile::MsBackend> msbc_ptr = std::dynamic_pointer_cast<compile::MsBackend>(bc_ptr);
  317. MS_EXCEPTION_IF_NULL(msbc_ptr);
  318. compile::VmEvalFuncPtr run =
  319. std::make_shared<compile::VmEvalFunc>([msbc_ptr, graph_id](const VectorRef &args) -> BaseRef {
  320. MS_LOG(INFO) << "Execute args size " << args.size();
  321. auto outs = msbc_ptr->RunGraph(graph_id, args);
  322. MS_LOG(DEBUG) << "out size " << outs.size();
  323. return outs[0];
  324. });
  325. res->results()[kOutput] = run;
  326. return true;
  327. }
  328. if (!res->results()[kOutput].is<compile::FinalVMPtr>()) {
  329. MS_LOG(EXCEPTION) << "Execute args error";
  330. }
  331. compile::FinalVMPtr vm = res->results()[kOutput].cast<compile::FinalVMPtr>();
  332. if (vm == nullptr) {
  333. MS_LOG(INFO) << "Call GE to Run the func_graph instead of VM";
  334. return true;
  335. }
  336. compile::VmEvalFuncPtr run =
  337. std::make_shared<compile::VmEvalFunc>(std::bind(&compile::FinalVM::Eval, vm, std::placeholders::_1));
  338. res->results()[kOutput] = run;
  339. return true;
  340. }
  341. #if (ENABLE_CPU && (ENABLE_D || ENABLE_GPU))
  342. bool StartPSWorkerAction(const ResourcePtr &res) {
  343. parallel::ps::Worker<float>::GetInstance().Run();
  344. return true;
  345. }
  346. bool StartPSServerAction(const ResourcePtr &res) {
  347. FuncGraphPtr func_graph = res->func_graph();
  348. auto &ps = parallel::ps::ParameterServer<float>::GetInstance();
  349. ps.Run(func_graph);
  350. return true;
  351. }
  352. bool StartPSSchedulerAction(const ResourcePtr &res) {
  353. parallel::ps::Scheduler::GetInstance().Run();
  354. return true;
  355. }
  356. #endif
  357. // The parallel primitive related valuenode might be partitioned so that its value changes by device,
  358. // that will result in a syncronization error due to different executing order.
  359. // Here we temporarily avoid the problem by skipping valuenode merging used by parallel related primitive,
  360. // the final solution will be proposed later as a parallel feature.
  361. bool KeepValueNodeDuplication(const AnfNodePtr &value_node, const ResourcePtr &res) {
  362. auto &node_users = res->manager()->node_users();
  363. auto &users = node_users[value_node];
  364. auto used_by_keep_value_prim =
  365. std::any_of(users.begin(), users.end(), [](const std::pair<AnfNodePtr, int> &user) -> bool {
  366. MS_EXCEPTION_IF_NULL(user.first);
  367. auto cnode = user.first->cast<CNodePtr>();
  368. if (cnode == nullptr) {
  369. return false;
  370. }
  371. auto prim_node = cnode->input(0);
  372. if (IsValueNode<Primitive>(prim_node)) {
  373. auto prim = GetValue<PrimitivePtr>(prim_node->cast<ValueNodePtr>()->value());
  374. // value_node is referenced by some parallel primitive
  375. return prim->HasAttr("keep_value_node_input");
  376. }
  377. return false;
  378. });
  379. return used_by_keep_value_prim;
  380. }
  381. bool RemoveValueNodeDuplicationsAction(const ResourcePtr &res) {
  382. if (res->func_graph() == nullptr) {
  383. MS_LOG(EXCEPTION) << "Remove value node duplications error.";
  384. }
  385. FuncGraphPtr func_graph = res->func_graph();
  386. auto manager = res->manager();
  387. // Remove duplicated value nodes, due to replace operation, can't use reference.
  388. auto value_nodes = func_graph->value_nodes();
  389. HashCache hash_cache;
  390. HashValue hashes;
  391. for (const auto &value_pair : value_nodes) {
  392. if (KeepValueNodeDuplication(value_pair.first, res)) {
  393. continue;
  394. }
  395. TryToDoReplace(manager.get(), value_pair.first, &hash_cache, &hashes);
  396. }
  397. return true;
  398. }
  399. bool ValidateAction(const ResourcePtr &res) { return ValidatePass(res); }
  400. void ActionPyStub(const ResourcePtr &res, opt::python_pass::Phase phase) {
  401. MS_EXCEPTION_IF_NULL(res->manager());
  402. MS_EXCEPTION_IF_NULL(res->func_graph());
  403. auto ppm = opt::python_pass::PyPassManager::GetInstance();
  404. if (!ppm->GetPassGroup(phase)->Run(res->func_graph())) {
  405. MS_LOG(DEBUG) << "No match.\n";
  406. }
  407. }
  408. bool ResolveActionPyStub(const ResourcePtr &res) {
  409. ActionPyStub(res, opt::python_pass::Phase::RESOLVE);
  410. return true;
  411. }
  412. bool OptActionPyStub(const ResourcePtr &res) {
  413. ActionPyStub(res, opt::python_pass::Phase::OPT);
  414. return true;
  415. }
  416. static std::vector<ActionItem> CommonPipeline() {
  417. std::vector<ActionItem> actions;
  418. // Parse the python ast to ANF graph
  419. actions.emplace_back(std::make_pair("parse", ParseAction));
  420. // Resolve the python func
  421. actions.emplace_back(std::make_pair("symbol_resolve", SymbolResolveAction));
  422. auto multi_graphs = parallel::CostModelContext::GetInstance()->is_multi_subgraphs();
  423. if (!multi_graphs) {
  424. actions.emplace_back(std::make_pair("combine_like_graphs", CombineLikeGraphs));
  425. }
  426. // Add resolve-stage python pass stub
  427. actions.emplace_back(std::make_pair("py_resolve", ResolveActionPyStub));
  428. actions.emplace_back(std::make_pair("inference_opt_prepare", InferenceOptPrepareAction));
  429. // Evaluate type and shape, and specialize
  430. actions.emplace_back(std::make_pair("abstract_specialize", AbstractSpecializeAction));
  431. return actions;
  432. }
  433. std::vector<ActionItem> GePipeline() {
  434. auto actions = CommonPipeline();
  435. // optimize
  436. actions.emplace_back(std::make_pair("optimize", GeOptimizeAction));
  437. // Add opt-stage python pass stub
  438. actions.emplace_back(std::make_pair("py_opt", OptActionPyStub));
  439. actions.emplace_back(std::make_pair("remove_value_node_duplications", RemoveValueNodeDuplicationsAction));
  440. actions.emplace_back(std::make_pair("validate", ValidateAction));
  441. return actions;
  442. }
  443. std::vector<ActionItem> VmPipeline() {
  444. auto actions = CommonPipeline();
  445. // optimize
  446. actions.emplace_back(std::make_pair("optimize", VmOptimizeAction));
  447. // Add opt-stage python pass stub
  448. actions.emplace_back(std::make_pair("py_opt", OptActionPyStub));
  449. actions.emplace_back(std::make_pair("validate", ValidateAction));
  450. #if (ENABLE_CPU && (ENABLE_D || ENABLE_GPU))
  451. if (parallel::ps::Util::IsRoleOfWorker()) {
  452. actions.emplace_back(std::make_pair("worker", StartPSWorkerAction));
  453. }
  454. #endif
  455. // compile the ANF graph
  456. actions.emplace_back(std::make_pair("task_emit", TaskEmitAction));
  457. // to execute the graph
  458. actions.emplace_back(std::make_pair("execute", ExecuteAction));
  459. return actions;
  460. }
  461. #if (ENABLE_CPU && (ENABLE_D || ENABLE_GPU))
  462. std::vector<ActionItem> PServerPipeline() {
  463. auto actions = CommonPipeline();
  464. actions.emplace_back(std::make_pair("optimize", VmOptimizeAction));
  465. actions.emplace_back(std::make_pair("validate", ValidateAction));
  466. actions.emplace_back(std::make_pair("pserver", StartPSServerAction));
  467. return actions;
  468. }
  469. std::vector<ActionItem> PSchedulerPipeline() {
  470. std::vector<ActionItem> actions;
  471. actions.emplace_back(std::make_pair("scheduler", StartPSSchedulerAction));
  472. return actions;
  473. }
  474. #endif
  475. } // namespace pipeline
  476. } // namespace mindspore