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.

proto_exporter.h 3.7 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * Copyright 2021 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_PROTO_EXPORTER_H
  17. #define MINDSPORE_PROTO_EXPORTER_H
  18. #include <map>
  19. #include <string>
  20. #include <vector>
  21. #include "debug/common.h"
  22. #include "debug/data_dump/dump_json_parser.h"
  23. #include "ir/graph_utils.h"
  24. #include "proto/debug_graph.pb.h"
  25. #include "utils/symbolic.h"
  26. #include "utils/trace_base.h"
  27. namespace mindspore {
  28. enum LocDebugDumpMode { kDebugOff = 0, kDebugTopStack = 1, kDebugWholeStack = 2 };
  29. class DebuggerProtoExporter {
  30. public:
  31. DebuggerProtoExporter() {}
  32. ~DebuggerProtoExporter() {}
  33. std::string GetFuncGraphProtoString(const FuncGraphPtr &func_graph, LocDebugDumpMode dump_location = kDebugOff);
  34. debugger::ModelProto GetFuncGraphProto(const FuncGraphPtr &func_graph);
  35. private:
  36. void InitModelInfo();
  37. void GetOpNodeTypeAndAttrs(const FuncGraphPtr &func_graph, const AnfNodePtr &node, debugger::NodeProto *node_proto);
  38. std::string GetOpNodeInputId(const FuncGraphPtr &func_graph, const AnfNodePtr &node,
  39. const std::map<AnfNodePtr, size_t> &apply_map,
  40. std::map<AnfNodePtr, size_t> *const_map_ptr);
  41. void SetValueToProto(const ValuePtr &attr_value, debugger::ValueProto *value_proto);
  42. void SetScalarToProto(const ScalarPtr &val, debugger::ValueProto *value_proto);
  43. void SetSequenceToProto(const ValueSequeuePtr &val, debugger::ValueProto *value_proto);
  44. void SetDictionaryToProto(const ValueDictionaryPtr &val, debugger::ValueProto *value_proto);
  45. void SetNodeOutputType(const AnfNodePtr &node, debugger::TypeProto *type_proto);
  46. void ExportFuncGraph(const FuncGraphPtr &func_graph, debugger::GraphProto *const graph_proto,
  47. LocDebugDumpMode dump_location = kDebugOff);
  48. void ExportParameters(const FuncGraphPtr &func_graph, debugger::GraphProto *graph_proto);
  49. void ExportCNodes(const FuncGraphPtr &func_graph, debugger::GraphProto *const graph_proto,
  50. std::map<AnfNodePtr, size_t> *const_map_ptr, LocDebugDumpMode dump_location = kDebugOff);
  51. void ExportCNode(const FuncGraphPtr &func_graph, const CNodePtr &node, std::map<AnfNodePtr, size_t> *apply_map_ptr,
  52. std::map<AnfNodePtr, size_t> *const_map_ptr, debugger::GraphProto *const graph_proto,
  53. LocDebugDumpMode dump_location = kDebugOff);
  54. void ExportFuncGraphOutput(const FuncGraphPtr &func_graph, const CNodePtr &ret_node,
  55. const std::map<AnfNodePtr, size_t> &apply_map, std::map<AnfNodePtr, size_t> *const_map_ptr,
  56. debugger::GraphProto *graph_proto);
  57. void ExportValueNodes(const std::map<AnfNodePtr, size_t> &const_map, debugger::GraphProto *graph_proto);
  58. static std::string GetConstNodeId(size_t idx) { return std::string("cst") + std::to_string(idx); }
  59. debugger::ModelProto model_;
  60. };
  61. void DumpIRProtoWithSrcInfo(const FuncGraphPtr &func_graph, const std::string &suffix, const std::string &target_dir,
  62. LocDebugDumpMode dump_location = kDebugOff);
  63. } // namespace mindspore
  64. #endif // MINDSPORE_CCSRC_DEBUG_DEBUGGER_MINDSPORE_PROTO_EXPORTER_H_