1 /** 2 * Copyright 2020 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_GRAPH_KERNEL_CSE_H_ 17 #define MINDSPORE_CCSRC_BACKEND_OPTIMIZER_GRAPH_KERNEL_GRAPH_KERNEL_CSE_H_ 18 19 #include <vector> 20 #include "backend/common/pass/common_subexpression_elimination.h" 21 22 namespace mindspore::graphkernel { 23 using opt::BackendCSE; 24 class GraphKernelCSE : public opt::Pass { 25 public: 26 explicit GraphKernelCSE(const std::vector<PrimitivePtr> &black_list = {}) 27 : Pass("graph_kernel_cse"), black_list_(black_list) {} 28 ~GraphKernelCSE() override = default; 29 bool Run(const FuncGraphPtr &func_graph) override; 30 31 private: 32 std::vector<PrimitivePtr> black_list_; 33 }; 34 35 class GraphKernelBackendCSE : public BackendCSE { 36 public: black_list_(black_list)37 explicit GraphKernelBackendCSE(const std::vector<PrimitivePtr> &black_list = {}) : black_list_(black_list) {} 38 ~GraphKernelBackendCSE() override = default; 39 bool CheckEqualKernelBuildInfo(const AnfNodePtr &main, const AnfNodePtr &node) const override; 40 bool CheckEqualCnodeInputs(const AnfNodePtr &main, const AnfNodePtr &node) const override; 41 42 private: 43 std::vector<PrimitivePtr> black_list_; 44 }; 45 } // namespace mindspore::graphkernel 46 #endif // MINDSPORE_CCSRC_BACKEND_OPTIMIZER_GRAPH_KERNEL_GRAPH_KERNEL_CSE_H_ 47