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 17 #ifndef MINDSPORE_CCSRC_FRONTEND_PARALLEL_OPS_INFO_RANGE_INFO_H_ 18 #define MINDSPORE_CCSRC_FRONTEND_PARALLEL_OPS_INFO_RANGE_INFO_H_ 19 20 #include <memory> 21 #include <string> 22 #include <unordered_map> 23 #include <vector> 24 25 #include "utils/ms_utils.h" 26 #include "ir/value.h" 27 #include "frontend/parallel/auto_parallel/operator_costmodel.h" 28 #include "frontend/parallel/ops_info/operator_info.h" 29 #include "frontend/parallel/strategy.h" 30 31 namespace mindspore { 32 namespace parallel { 33 // Range op: 34 // (start=8.0, limit=16.0, delta=1.0) -> [8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0] 35 // (start=8.0, limit=None, delta=1.0) -> [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0] 36 // when entering the step_parallel, the limit=None has been processed 37 // the parallel op need to modify the 'start' and 'limit' 38 class RangeInfo : public OperatorInfo { 39 public: RangeInfo(const std::string & name,const Shapes & inputs_shape,const Shapes & outputs_shape,const PrimitiveAttrs & attrs)40 RangeInfo(const std::string &name, const Shapes &inputs_shape, const Shapes &outputs_shape, 41 const PrimitiveAttrs &attrs) 42 : OperatorInfo(name, inputs_shape, outputs_shape, attrs, std::make_shared<RangeCost>()) {} 43 ~RangeInfo() override = default; 44 45 Status Init(const StrategyPtr &strategy) override; 46 Status InitForCostModel(const StrategyPtr &strategy) override; 47 48 std::vector<StrategyPtr> GenerateOpStrategies(int64_t stage_id) override; 49 Status SetCostUnderStrategy(const StrategyPtr &strategy) override; 50 51 protected: 52 Status CheckStrategy(const StrategyPtr &strategy) override; 53 Status InferMirrorOps() override; 54 Status InferForwardCommunication() override; 55 Status InferDevMatrixShape() override; 56 Status InferTensorMap() override; 57 Status GetAttrs() override; 58 float GetRangeAttr(const std::string &arg); 59 60 float start_ = 0.0; 61 float limit_ = 0.0; 62 float delta_ = 0.0; 63 float new_start_ = 0.0; 64 float new_limit_ = 0.0; 65 int64_t split_num_ = 1; 66 }; 67 } // namespace parallel 68 } // namespace mindspore 69 #endif // MINDSPORE_CCSRC_FRONTEND_PARALLEL_OPS_INFO_RANGE_INFO_H_ 70