• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2022-2023 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_GRAPH_KERNEL_CONVERTER_GRAPH_KERNEL_OPTIMIZATION_H_
17 #define MINDSPORE_LITE_TOOLS_GRAPH_KERNEL_CONVERTER_GRAPH_KERNEL_OPTIMIZATION_H_
18 
19 #include <memory>
20 #include "ir/anf.h"
21 #include "ir/func_graph.h"
22 #include "include/errorcode.h"
23 #include "tools/converter/cxx_api/converter_para.h"
24 #include "tools/graph_kernel/converter/graph_kernel_pass_manager_lite.h"
25 
26 namespace mindspore {
27 namespace graphkernel {
28 class GraphKernelOptimizer {
29  public:
GraphKernelOptimizer(const std::shared_ptr<ConverterPara> & param)30   explicit GraphKernelOptimizer(const std::shared_ptr<ConverterPara> &param) : converter_param_(param) {}
31   ~GraphKernelOptimizer() = default;
32   void Run(const FuncGraphPtr &func_graph);
33 
34  private:
35   void Init() const;
36   // Pre-process
37   GkPassManagerPtr PreProcess() const;
38   // Cluster kernels
39   GkPassManagerPtr Cluster() const;
40   // Optimize 1
41   GkPassManagerPtr HighLevelOpt1() const;
42   // Split kernels
43   GkPassManagerPtr Split() const;
44   // Build akg kernel
45   GkPassManagerPtr BuildKernel() const;
46   // Post-process
47   GkPassManagerPtr PostProcess() const;
48 
49   std::shared_ptr<ConverterPara> converter_param_;
50 
51   bool is_cpu{false};
52   bool is_ascend{false};
53 };
54 }  // namespace graphkernel
55 
56 lite::STATUS GraphKernelOptimize(const FuncGraphPtr &func_graph, const std::shared_ptr<ConverterPara> &param);
57 }  // namespace mindspore
58 #endif  // MINDSPORE_LITE_TOOLS_GRAPH_KERNEL_CONVERTER_GRAPH_KERNEL_OPTIMIZATION_H_
59