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.

ascend_control_parser.h 3.6 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #ifndef MINDSPORE_CCSRC_SESSION_ASCEND_CONTROL_PARSER_H
  17. #define MINDSPORE_CCSRC_SESSION_ASCEND_CONTROL_PARSER_H
  18. #include <set>
  19. #include <map>
  20. #include <vector>
  21. #include <tuple>
  22. #include "session/kernel_graph.h"
  23. #include "utils/base_ref.h"
  24. #include "utils/contract.h"
  25. #include "utils/union_find_set.h"
  26. namespace mindspore {
  27. namespace session {
  28. class AscendControlParser {
  29. public:
  30. static void ChildGraphDataAssign(const std::map<uint32_t, KernelGraphPtr> &graph_id_map);
  31. static void LinkGraph(NotNull<KernelGraphPtr> kg);
  32. static void InsertDependToGraph(NotNull<KernelGraphPtr> kg, NotNull<AnfNodePtr> attch_node);
  33. static void InsertControlDependToGraph(NotNull<KernelGraphPtr> kg, NotNull<AnfNodePtr> first_node,
  34. NotNull<AnfNodePtr> second_node);
  35. static void ExecutorValidate(NotNull<KernelGraphPtr> root_graph);
  36. static void UpdateChildGraphOrder(NotNull<KernelGraphPtr> kg);
  37. private:
  38. static NotNull<CNodePtr> GetStartLabel(NotNull<KernelGraphPtr> kg, const CNodePtr &last_node,
  39. const CNodePtr &last_label);
  40. static NotNull<CNodePtr> ProcessKernelGraph(NotNull<KernelGraphPtr> kg, const CNodePtr &last_node,
  41. const CNodePtr &last_label,
  42. const NotNull<std::set<KernelGraphPtr> *> memo);
  43. static void RecurseCall(NotNull<KernelGraphPtr> kg, NotNull<CNodePtr> cur_node, const CNodePtr &next_node,
  44. const NotNull<std::set<KernelGraphPtr> *> memo);
  45. static void RecurseSwitch(NotNull<KernelGraphPtr> kg, NotNull<CNodePtr> cur_node, const CNodePtr &next_node,
  46. const NotNull<std::set<KernelGraphPtr> *> memo);
  47. static void RecurseSwitchLayer(NotNull<KernelGraphPtr> kg, NotNull<CNodePtr> cur_node, const CNodePtr &next_node,
  48. const NotNull<std::set<KernelGraphPtr> *> memo);
  49. static void LinkParentGraph(NotNull<KernelGraphPtr> kg, const CNodePtr &from_graph_call_node,
  50. const CNodePtr &last_label);
  51. static KernelGraphPtr ParsePartial(NotNull<AnfNodePtr> node);
  52. static void InsertMultipleAssignToGraph(NotNull<KernelGraphPtr> from_graph, NotNull<KernelGraphPtr> to_graph,
  53. NotNull<AnfNodePtr> from, NotNull<AnfNodePtr> to);
  54. static AnfNodePtr InsertAssignToGraph(NotNull<KernelGraphPtr> kg, NotNull<AnfNodePtr> from, NotNull<AnfNodePtr> to);
  55. // root graph order
  56. static bool CheckLabelIndex(uint32_t order_index, uint32_t label_index, const CNodePtr &cnode,
  57. NotNull<KernelGraphPtr> graph);
  58. static std::vector<CNodePtr> RecurseGraph(NotNull<KernelGraphPtr> graph,
  59. const NotNull<std::set<KernelGraphPtr> *> memo);
  60. };
  61. } // namespace session
  62. } // namespace mindspore
  63. #endif // MINDSPORE_CCSRC_SESSION_ASCEND_CONTROL_PARSER_H