1 /** 2 * Copyright 2020-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 17 #ifndef MINDSPORE_CCSRC_FRONTEND_PARALLEL_ALLREDUCE_FUSION_ALLREDUCE_FUSION_H_ 18 #define MINDSPORE_CCSRC_FRONTEND_PARALLEL_ALLREDUCE_FUSION_ALLREDUCE_FUSION_H_ 19 20 #include <string> 21 #include "utils/hash_map.h" 22 #include "ir/anf.h" 23 #include "frontend/parallel/allreduce_fusion/allreduce_graph.h" 24 #include "frontend/parallel/status.h" 25 #include "frontend/parallel/ops_info/ops_utils.h" 26 #include "frontend/parallel/step_parallel_utils.h" 27 28 namespace mindspore { 29 namespace parallel { 30 constexpr int64_t DEFAULT_COST_MODEL_ALLREDUCE_FUSION_ALGORITHM = 0; 31 constexpr int64_t DEFAULT_COST_MODEL_ALLREDUCE_FUSION_TIMES = 0; 32 constexpr double DEFAULT_COST_MODEL_ALLREDUCE_FUSION_TAIL_PERCENT = 0.1; 33 constexpr double DEFAULT_COST_MODEL_ALLREDUCE_FUSION_TAIL_TIME = 0.1; 34 constexpr double DEFAULT_COST_MODEL_ALLREDUCE_FUSION_ALLREDUCE_INHERENT_TIME = 0.1; 35 constexpr double DEFAULT_COST_MODEL_ALLREDUCE_FUSION_ALLREDUCE_BANDWIDTH = 0.1; 36 constexpr double DEFAULT_COST_MODEL_ALLREDUCE_FUSION_COMPUTATION_TIME_PARAMETER = 0.1; 37 constexpr int64_t DEFAULT_THRESHOLD_MB_TO_BYTE = 262144; 38 39 const uint64_t MAX_RECURSIVE_CALL_TIMES = 100; 40 class AllCommFusion { 41 public: AllCommFusion()42 AllCommFusion() 43 : allreduce_graph_(), 44 ret_(nullptr), 45 forward_ret_(nullptr), 46 root_graph_(nullptr), 47 tail_time_(0), 48 computation_time_parameter_(0) {} 49 virtual ~AllCommFusion() = default; 50 Status ProcessCommOpsFusion(const CNodePtr &ret, const std::string &comm_name); 51 52 private: 53 Status SetFusionBySize(const CNodePtr &ret, int64_t threshold, const PrimitivePtr &primp) const; 54 Status SetFusionBySizeReduceScatter(const CNodePtr &ret, int64_t threshold, const PrimitivePtr &primp) const; 55 AllreduceGraph allreduce_graph_; 56 CNodePtr ret_; 57 CNodePtr forward_ret_; 58 FuncGraphPtr root_graph_; 59 double tail_time_; 60 double computation_time_parameter_; 61 }; 62 } // namespace parallel 63 } // namespace mindspore 64 65 #endif // MINDSPORE_CCSRC_FRONTEND_PARALLEL_ALLREDUCE_FUSION_ALLREDUCE_FUSION_H_ 66