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_GATHER_V2_INFO_H_ 18 #define MINDSPORE_CCSRC_FRONTEND_PARALLEL_OPS_INFO_GATHER_V2_INFO_H_ 19 20 #include <memory> 21 #include <string> 22 #include <unordered_map> 23 #include <vector> 24 25 #include "ir/value.h" 26 #include "frontend/parallel/auto_parallel/operator_costmodel.h" 27 #include "frontend/parallel/ops_info/operator_info.h" 28 #include "frontend/parallel/strategy.h" 29 30 namespace mindspore { 31 namespace parallel { 32 constexpr size_t GATHER_V2_INPUTS_SIZE = 2; 33 constexpr size_t GATHER_V2_OUTPUTS_SIZE = 1; 34 constexpr size_t GATHER_V2_INPUTS_VALUE_SIZE = 3; 35 // We now supported limited parallel strategies. 36 // If the strategy corresponding to axis is more than 1, index must be evenly distributed across the axis-dimension of 37 // the input. 38 // If Index is a scalar or n-dimension vector(n > 1), the strategy corresponding to axis must be 1. 39 class GatherInfo : public OperatorInfo { 40 public: GatherInfo(const std::string & name,const Shapes & inputs_shape,const Shapes & outputs_shape,const PrimitiveAttrs & attrs)41 GatherInfo(const std::string &name, const Shapes &inputs_shape, const Shapes &outputs_shape, 42 const PrimitiveAttrs &attrs) 43 : OperatorInfo(name, inputs_shape, outputs_shape, attrs, std::make_shared<GatherV2Cost>()), 44 axis_(-1), 45 index_size_(0), 46 axis_strategy_(1) {} 47 ~GatherInfo() override = default; 48 Status Init(const StrategyPtr &strategy) override; 49 Status InitForCostModel(const StrategyPtr &strategy) override; 50 51 std::vector<StrategyPtr> GenerateOpStrategies(int64_t stage_id) override; 52 Status SetCostUnderStrategy(const StrategyPtr &strategy) override; 53 std::shared_ptr<Strategys> GenerateBatchStrategies() override; 54 55 protected: 56 Status CheckStrategy(const StrategyPtr &strategy) override; InferMirrorOps()57 Status InferMirrorOps() override { return SUCCESS; } InferForwardCommunication()58 Status InferForwardCommunication() override { return SUCCESS; } 59 Status InferTensorInfo() override; 60 Status InferDevMatrixShape() override; 61 Status InferTensorMap() override; 62 Status GetAttrs() override; 63 64 private: 65 Status InferTensorSubOps(); 66 67 int64_t axis_; 68 size_t index_size_; 69 int64_t axis_strategy_; 70 }; 71 } // namespace parallel 72 } // namespace mindspore 73 #endif // MINDSPORE_CCSRC_FRONTEND_PARALLEL_OPS_INFO_GATHER_V2_INFO_H_ 74