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_USS_ATOMIC_ADD_H_ 18 #define MINDSPORE_CCSRC_BACKEND_OPTIMIZER_GRAPH_KERNEL_USS_ATOMIC_ADD_H_ 19 20 #include <memory> 21 #include <tuple> 22 #include "include/backend/optimizer/optimizer.h" 23 #include "backend/common/graph_kernel/add_atomic_clean.h" 24 #include "include/backend/kernel_graph.h" 25 26 namespace mindspore::graphkernel { 27 /* 28 * output = SubGraph(input_x, segment_ids) { 29 * %0 = UnsortedSegmentSum(%para1, %para2) 30 * return %0 31 * } 32 * ----------------------------------------------------------------> 33 * // Clean output with zero. 34 * output = broadcast_to(0.0) // attrs{"shape": [shape of origin output.]} 35 * fake_out = SubGraph'(input_x, segment_ids, output) { 36 * %0 = UnsortedSegmentSum(%para1, %para2) 37 * %1 = Assign(%para3, %0, umond) 38 * return %1 39 * } 40 */ 41 class UssAtomicAdd : public AtomicCleanInserter { 42 public: UssAtomicAdd()43 UssAtomicAdd() : AtomicCleanInserter("unsorted_segment_sum_atomic_add_process") {} 44 ~UssAtomicAdd() override = default; 45 bool Run(const FuncGraphPtr &func_graph) override; 46 }; 47 using UssAtomicAddPtr = std::shared_ptr<UssAtomicAdd>; 48 } // namespace mindspore::graphkernel 49 50 #endif // MINDSPORE_CCSRC_BACKEND_OPTIMIZER_GRAPH_KERNEL_USS_ATOMIC_ADD_H_ 51