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.

graph_info.cc 1.9 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 "parallel/graph_util/graph_info.h"
  17. #include "debug/anf_ir_dump.h"
  18. #include "debug/anf_ir_utils.h"
  19. #include "debug/draw.h"
  20. #include "ir/func_graph.h"
  21. #include "utils/context/ms_context.h"
  22. #include "utils/graph_utils.h"
  23. namespace mindspore {
  24. namespace parallel {
  25. std::vector<PrimitivePtr> FindPrimtive(const FuncGraphPtr &graph, const std::string &name) {
  26. AnfNodePtr ret = graph->get_return();
  27. MS_EXCEPTION_IF_NULL(ret);
  28. std::vector<AnfNodePtr> all_nodes = DeepScopedGraphSearch(ret);
  29. std::vector<PrimitivePtr> prim_list;
  30. for (auto &node : all_nodes) {
  31. if (!IsValueNode<Primitive>(node)) {
  32. continue;
  33. }
  34. ValueNodePtr prim_node_anf = node->cast<ValueNodePtr>();
  35. MS_EXCEPTION_IF_NULL(prim_node_anf);
  36. PrimitivePtr node_prim = prim_node_anf->value()->cast<PrimitivePtr>();
  37. MS_EXCEPTION_IF_NULL(node_prim);
  38. if (node_prim->name() == name) {
  39. prim_list.emplace_back(node_prim);
  40. }
  41. }
  42. return prim_list;
  43. }
  44. void DumpGraph(const FuncGraphPtr &root, const std::string &name) {
  45. if (MsContext::GetInstance()->save_graphs_flag()) {
  46. draw::Draw(name + ".dot", root);
  47. DumpIR(name + ".ir", root);
  48. ExportIR(name + ".dat", "0", root);
  49. }
  50. }
  51. } // namespace parallel
  52. } // namespace mindspore