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 17 #ifndef MINDSPORE_CCSRC_BACKEND_OPTIMIZER_GRAPH_KERNEL_ADD_STITCH_ATOMIC_CLEAN_GPU_H_ 18 #define MINDSPORE_CCSRC_BACKEND_OPTIMIZER_GRAPH_KERNEL_ADD_STITCH_ATOMIC_CLEAN_GPU_H_ 19 20 #include <memory> 21 #include <tuple> 22 #include <utility> 23 #include <vector> 24 #include "backend/optimizer/common/optimizer.h" 25 #include "backend/optimizer/graph_kernel/add_atomic_clean.h" 26 #include "backend/session/kernel_graph.h" 27 28 namespace mindspore { 29 namespace opt { 30 class StitchAtomicCleanInsertter : public AtomicCleanInsertter { 31 public: StitchAtomicCleanInsertter()32 StitchAtomicCleanInsertter() : AtomicCleanInsertter("stitch_atomic_clean") {} 33 ~StitchAtomicCleanInsertter() override = default; 34 bool Run(const FuncGraphPtr &func_graph) override; 35 36 private: 37 CNodePtr CreateInplaceAssignNode(const FuncGraphPtr &sub_graph, const AnfNodePtr &new_parameter) const; 38 std::vector<std::pair<AnfNodePtr, int>> FindInnerCNodeUsers(const AnfNodePtr &inner_node, 39 const CNodePtr &target) const; 40 void ProcessOriginCNode(const AnfNodePtr &composite_node, const AnfNodePtr &new_input) override; 41 bool IsStitchWithAtomic(const AnfNodePtr &anf_node); 42 43 AnfNodePtr stitch_node_{nullptr}; 44 }; 45 using StitchAtomicCleanInsertterPtr = std::shared_ptr<StitchAtomicCleanInsertter>; 46 } // namespace opt 47 } // namespace mindspore 48 49 #endif // MINDSPORE_CCSRC_BACKEND_OPTIMIZER_GRAPH_KERNEL_ADD_STITCH_ATOMIC_CLEAN_GPU_H_ 50