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 #ifndef MINDSPORE_CCSRC_BACKEND_OPTIMIZER_RAISE_REDUCTION_PRECISION_H_ 17 #define MINDSPORE_CCSRC_BACKEND_OPTIMIZER_RAISE_REDUCTION_PRECISION_H_ 18 19 #include <string> 20 #include "include/backend/optimizer/optimizer.h" 21 22 namespace mindspore::graphkernel { 23 class RaiseReductionPrecision : public opt::Pass { 24 public: RaiseReductionPrecision()25 RaiseReductionPrecision() : Pass("raise_reduction_precision") {} 26 ~RaiseReductionPrecision() override = default; 27 bool Run(const FuncGraphPtr &func_graph) override; 28 29 private: 30 bool IsFp16ReduceSum(const AnfNodePtr &node) const; 31 bool Process(const FuncGraphPtr &func_graph) const; 32 AnfNodePtr CreateCast(const AnfNodePtr &input, const TypePtr &dst_type, const std::string &format) const; 33 AnfNodePtr CreateReduceSum(const AnfNodePtr &node, const AnfNodePtr &input) const; 34 void ReplaceNode(const AnfNodePtr &reduce_node, const AnfNodePtr &cast_node) const; 35 }; 36 } // namespace mindspore::graphkernel 37 #endif // MINDSPORE_CCSRC_BACKEND_OPTIMIZER_RAISE_REDUCTION_PRECISION_H_ 38