1 /** 2 * Copyright 2021-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_CCSRC_BACKEND_OPTIMIZER_GRAPH_KERNEL_ADAPTER_GRAPH_KERNEL_OPTIMIZATION_H_ 17 #define MINDSPORE_CCSRC_BACKEND_OPTIMIZER_GRAPH_KERNEL_ADAPTER_GRAPH_KERNEL_OPTIMIZATION_H_ 18 19 #include <vector> 20 #include "include/backend/kernel_graph.h" 21 #include "include/backend/optimizer/optimizer.h" 22 #include "include/backend/optimizer/pass_manager.h" 23 24 namespace mindspore::graphkernel { 25 using opt::PassManagerPtr; 26 class GraphKernelOptimizer { 27 public: 28 void Run(const KernelGraphPtr &kernel_graph); 29 void RunKernelPacket(const KernelGraphPtr &kernel_graph); 30 31 private: 32 void Init() const; 33 // Pre-process 34 PassManagerPtr PreProcess() const; 35 // Cluster kernels 36 PassManagerPtr Cluster() const; 37 // High level optimize 1 38 PassManagerPtr HighLevelOpt1() const; 39 // Split kernels 40 PassManagerPtr Split() const; 41 // High level optimize 2 42 PassManagerPtr HighLevelOpt2() const; 43 // Combine kernels 44 PassManagerPtr Combine() const; 45 // Build kernels 46 PassManagerPtr Build() const; 47 // Post-process 48 PassManagerPtr PostProcess() const; 49 // Pack a device op with input host ops 50 PassManagerPtr KernelPacket() const; 51 52 bool is_gpu{false}; 53 bool is_ascend{false}; 54 bool is_cpu{false}; 55 bool is_ge{false}; 56 bool is_dvm{false}; 57 }; 58 59 BACKEND_EXPORT void GraphKernelOptimize(const KernelGraphPtr &kernel_graph); 60 BACKEND_EXPORT bool GraphKernelSupported(const std::vector<AnfNodePtr> &nodes); 61 BACKEND_EXPORT void KernelPacketOptimize(const KernelGraphPtr &kernel_graph); 62 } // namespace mindspore::graphkernel 63 #endif // MINDSPORE_CCSRC_BACKEND_OPTIMIZER_GRAPH_KERNEL_ADAPTER_GRAPH_KERNEL_OPTIMIZATION_H_ 64