• 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_LITE_TOOLS_OPTIMIZER_GRAPH_DUMP_GRAPH_H_
17 #define MINDSPORE_LITE_TOOLS_OPTIMIZER_GRAPH_DUMP_GRAPH_H_
18 
19 #include <memory>
20 #include "include/backend/optimizer/pass.h"
21 #include "tools/converter/export_model.h"
22 #include "include/registry/pass_base.h"
23 #include "mindapi/ir/func_graph.h"
24 
25 namespace mindspore {
26 namespace opt {
27 class DumpGraph : public registry::PassBase, public Pass {
28  public:
DumpGraph(const std::shared_ptr<ConverterPara> & param)29   explicit DumpGraph(const std::shared_ptr<ConverterPara> &param) : Pass("DumpGraph"), param_(param) {}
30   ~DumpGraph() = default;
Run(const FuncGraphPtr & graph)31   bool Run(const FuncGraphPtr &graph) override {
32     MS_CHECK_TRUE_MSG(graph != nullptr, false, "funcGraph is a nullptr.");
33     if (lite::ExportModel(graph, param_) != lite::RET_OK) {
34       MS_LOG(ERROR) << "dump graph failed.";
35       return false;
36     }
37     return true;
38   }
39 
Execute(const api::FuncGraphPtr & func_graph)40   bool Execute(const api::FuncGraphPtr &func_graph) override {
41     MS_CHECK_TRUE_MSG(func_graph != nullptr, false, "funcGraph is a nullptr.");
42     auto impl = func_graph->impl();
43     MS_CHECK_TRUE_MSG(impl != nullptr, false, "func_graph impl is a nullptr.");
44     auto graph = std::dynamic_pointer_cast<FuncGraph>(impl);
45     MS_CHECK_TRUE_MSG(graph != nullptr, false, "Graph is a nullptr.");
46     return Run(graph);
47   }
48 
49  private:
50   const std::shared_ptr<ConverterPara> &param_;
51 };
52 }  // namespace opt
53 }  // namespace mindspore
54 
55 #endif  // MINDSPORE_LITE_TOOLS_OPTIMIZER_GRAPH_DUMP_GRAPH_H_
56