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.5 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 <vector>
  20. #include <tuple>
  21. #include "session/kernel_graph.h"
  22. #include "utils/base_ref.h"
  23. #include "utils/contract.h"
  24. namespace mindspore {
  25. namespace session {
  26. class AscendControlParser {
  27. public:
  28. static void LinkGraph(NotNull<KernelGraphPtr> kg);
  29. static void InsertDependToGraph(NotNull<KernelGraphPtr> kg, NotNull<AnfNodePtr> attch_node);
  30. static void InsertControlDependToGraph(NotNull<KernelGraphPtr> kg, NotNull<AnfNodePtr> first_node,
  31. NotNull<AnfNodePtr> second_node);
  32. private:
  33. static NotNull<CNodePtr> ProcessKernelGraph(NotNull<KernelGraphPtr> kg, const CNodePtr &last_node,
  34. const CNodePtr &last_label, const VectorRef &args,
  35. NotNull<std::set<KernelGraphPtr> *> memo);
  36. static void RecurseCall(NotNull<KernelGraphPtr> kg, NotNull<CNodePtr> cur_node, const CNodePtr &next_node,
  37. NotNull<std::set<KernelGraphPtr> *> memo);
  38. static void RecurseSwitch(NotNull<KernelGraphPtr> kg, NotNull<CNodePtr> cur_node,
  39. NotNull<std::set<KernelGraphPtr> *> memo);
  40. static void RecurseSwitchLayer(NotNull<KernelGraphPtr> kg, NotNull<CNodePtr> cur_node,
  41. NotNull<std::set<KernelGraphPtr> *> memo);
  42. static std::vector<CNodePtr> GetCNodes(const std::vector<AnfNodePtr> &in);
  43. static void LinkParentGraph(NotNull<KernelGraphPtr> kg, const CNodePtr &from_graph_call_node,
  44. const CNodePtr &last_label, const VectorRef &args);
  45. static void SetSubGraphInput(NotNull<KernelGraphPtr> kg, NotNull<CNodePtr> from_graph_call_node,
  46. const VectorRef &args);
  47. static std::tuple<CNodePtr, KernelGraphPtr, VectorRef> ParsePartial(NotNull<AnfNodePtr> node);
  48. static void InsertAssignToGraph(NotNull<KernelGraphPtr> kg, NotNull<AnfNodePtr> from, NotNull<AnfNodePtr> to);
  49. static size_t SetChildGraphInput(NotNull<KernelGraphPtr> kg, NotNull<AnfNodePtr> node, size_t input_index);
  50. static constexpr size_t kCNodePrim = 0;
  51. static constexpr size_t kCNodeCallArg = 1;
  52. static constexpr size_t kCNodeSwitchCond = 1;
  53. static constexpr size_t kCNodeSwitchTrue = 2;
  54. static constexpr size_t kCNodeSwitchFalse = 3;
  55. static constexpr size_t kCNodeSwitchLength = 4;
  56. static constexpr size_t kCNodePartialLength = 2;
  57. static constexpr size_t kCNodePartialFunc = 1;
  58. static constexpr size_t kCNodeSwitchLayerCond = 1;
  59. static constexpr size_t kCNodeSwitchLayerBranch = 2;
  60. static constexpr size_t kCNodeSwitchLayerLength = 3;
  61. };
  62. } // namespace session
  63. } // namespace mindspore
  64. #endif // MINDSPORE_CCSRC_SESSION_ASCEND_CONTROL_PARSER_H