• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CCSRC_DEBUG_RDR_GRAPH_RECORDER_H_
17 #define MINDSPORE_CCSRC_DEBUG_RDR_GRAPH_RECORDER_H_
18 #include <string>
19 #include <memory>
20 
21 #include "include/common/debug/rdr/base_recorder.h"
22 #include "include/backend/visible.h"
23 
24 namespace mindspore {
25 struct DumpGraphParams {
26   bool dump_full_name;
27   int dump_mode;
28 };
29 class GraphRecorder : public BaseRecorder {
30  public:
GraphRecorder()31   GraphRecorder() : BaseRecorder(), func_graph_(nullptr), graph_type_("") {}
GraphRecorder(const std::string & module,const std::string & name,const FuncGraphPtr & graph,const std::string & file_type)32   GraphRecorder(const std::string &module, const std::string &name, const FuncGraphPtr &graph,
33                 const std::string &file_type)
34       : BaseRecorder(module, name), func_graph_(graph), graph_type_(file_type) {}
~GraphRecorder()35   ~GraphRecorder() {}
SetGraphType(const std::string & file_type)36   void SetGraphType(const std::string &file_type) { graph_type_ = file_type; }
SetFuncGraph(const FuncGraphPtr & func_graph)37   void SetFuncGraph(const FuncGraphPtr &func_graph) { func_graph_ = func_graph; }
SetDumpFlag(const DumpGraphParams & info)38   void SetDumpFlag(const DumpGraphParams &info) { dump_graph_info_ = info; }
39 
40   virtual void Export();
41 
42  private:
43   FuncGraphPtr func_graph_;
44   std::string graph_type_;
45   DumpGraphParams dump_graph_info_{false, 0};
46 };
47 using GraphRecorderPtr = std::shared_ptr<GraphRecorder>;
48 
49 namespace RDR {
50 BACKEND_EXPORT bool RecordAnfGraph(const SubModuleId module, const std::string &name, const FuncGraphPtr &graph,
51                                    const DumpGraphParams &info, const std::string &file_type = ".ir;.pb;.dat");
52 }  // namespace RDR
53 }  // namespace mindspore
54 #endif  // MINDSPORE_CCSRC_DEBUG_RDR_GRAPH_RECORDER_H_
55