• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2022 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 "plugin/device/ascend/optimizer/ge_optimization.h"
17 
18 #include <string>
19 #include <memory>
20 
21 #include "include/backend/optimizer/optimizer.h"
22 #include "include/common/debug/anf_ir_dump.h"
23 #include "plugin/device/ascend/optimizer/mindir/reduce_axis_update.h"
24 #include "include/backend/debug/profiler/profiling.h"
25 
26 namespace mindspore {
27 namespace opt {
ReduceOptimization(const FuncGraphPtr & func_graph)28 void ReduceOptimization(const FuncGraphPtr &func_graph) {
29   MS_EXCEPTION_IF_NULL(func_graph);
30   MS_LOG(INFO) << "Reduce optimization start, graph: " << func_graph->ToString() << ".";
31 
32 #ifdef ENABLE_DUMP_IR
33   auto context = MsContext::GetInstance();
34   MS_EXCEPTION_IF_NULL(context);
35   if (context->CanDump(kIntroductory)) {
36     std::string file_name = "hwopt_d_before_reduce_optimization_graph_" + func_graph->ToString() + ".ir";
37     DumpIR(file_name, func_graph);
38   }
39 #endif
40 
41   profiler::CollectHostInfo("Ascend", "Graph Optimization", "GeOptimizeGraph_ReduceOptimization", 0, 0, 0);
42   auto optimizer = std::make_shared<opt::GraphOptimizer>();
43   auto pm = std::make_shared<opt::PassManager>("reduce_optimization_pm");
44   MS_EXCEPTION_IF_NULL(pm);
45   pm->AddPass(std::make_shared<opt::ReduceAxisUpdate>());
46   MS_EXCEPTION_IF_NULL(optimizer);
47   optimizer->AddPassManager(pm);
48 
49   (void)optimizer->Optimize(func_graph);
50   profiler::CollectHostInfo("Ascend", "Graph Optimization", "GeOptimizeGraph_ReduceOptimization", 0, 0, 1);
51 
52 #ifdef ENABLE_DUMP_IR
53   if (context->CanDump(kIntroductory)) {
54     std::string file_name = "hwopt_d_after_reduce_optimization_graph_" + func_graph->ToString() + ".ir";
55     DumpIR(file_name, func_graph);
56   }
57 #endif
58 
59   MS_LOG(INFO) << "Reduce optimization end.";
60 }
61 }  // namespace opt
62 }  // namespace mindspore
63