You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

reshape_info.h 4.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /**
  2. * Copyright 2019 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_PARALLEL_OPS_INFO_RESHAPE_INFO_H_
  17. #define MINDSPORE_CCSRC_PARALLEL_OPS_INFO_RESHAPE_INFO_H_
  18. #include <ir/value.h>
  19. #include <memory>
  20. #include <string>
  21. #include <unordered_map>
  22. #include <vector>
  23. #include "parallel/ops_info/operator_info.h"
  24. #include "parallel/strategy.h"
  25. namespace mindspore {
  26. namespace parallel {
  27. /*
  28. * parallel class for Reshape Primitive
  29. */
  30. class ReshapeInfo : public OperatorInfo {
  31. public:
  32. ReshapeInfo(const std::string &name, const Shapes &inputs_shape, const Shapes &outputs_shape,
  33. const PrimitiveAttrs &attrs)
  34. : OperatorInfo(name, inputs_shape, outputs_shape, attrs, std::make_shared<ReshapeCost>(false)),
  35. dev_num_(0),
  36. pre_operator_index_(0),
  37. next_operator_index_(0),
  38. input_layout_set_flag_(false),
  39. output_layout_set_flag_(false) {}
  40. ~ReshapeInfo() override = default;
  41. Status Init(const StrategyPtr &strategy) override;
  42. void SetInputLayout(const TensorLayout &input_layout) {
  43. input_layout_ = input_layout;
  44. input_layout_set_flag_ = true;
  45. }
  46. void SetOutputLayout(const TensorLayout &output_layout) {
  47. output_layout_ = output_layout;
  48. output_layout_set_flag_ = true;
  49. }
  50. void SetCostForReshape(const mindspore::parallel::StrategyPtr &strategy);
  51. void SetCostForReshapeWithParameter();
  52. void set_pre_operator_name(const std::string &pre_name) { pre_operator_name_ = pre_name; }
  53. void set_next_operator_name(const std::string &next_name) { next_operator_name_ = next_name; }
  54. void set_pre_operator_index(int32_t pre_index) { pre_operator_index_ = pre_index; }
  55. void set_next_operator_index(int32_t next_index) { next_operator_index_ = next_index; }
  56. Status GenetateStrategyCosts(const std::vector<std::shared_ptr<StrategyWithCost>> &pre_stra_costs,
  57. const std::vector<std::shared_ptr<StrategyWithCost>> &next_stra_costs, int32_t out_index,
  58. int32_t in_index, bool is_prev_param);
  59. Status InitForCostModel(const StrategyPtr &strategy) override;
  60. Status GenerateStrategies(int32_t stage_id) override;
  61. Status SetCostUnderStrategy(const StrategyPtr &strategy) override;
  62. std::string pre_operator_name() const { return pre_operator_name_; }
  63. std::string next_operator_name() const { return next_operator_name_; }
  64. int32_t pre_operator_index() const { return pre_operator_index_; }
  65. int32_t next_operator_index() const { return next_operator_index_; }
  66. protected:
  67. Status CheckStrategy(const StrategyPtr &strategy) override;
  68. Status InferMirrorOps() override;
  69. Status InferForwardCommunication() override;
  70. Status InferTensorMap() override;
  71. Status InferTensorInfo() override;
  72. Status InferDevMatrixShape() override;
  73. Status InferTensorLayout(TensorLayouts *inputs_layout, TensorLayouts *outputs_layout);
  74. Status GetAttrs() override;
  75. Strategys GetOutputsStrategy();
  76. private:
  77. Status GetParameterInput();
  78. Status ComputeReplaceOp();
  79. void InferTensorInfoByLayout();
  80. void device_number(const StrategyPtr &strategy);
  81. Status InferDefaultLayout(const Shape &shape, TensorLayout *const layout);
  82. int32_t dev_num_;
  83. int32_t pre_operator_index_;
  84. int32_t next_operator_index_;
  85. std::vector<int32_t> parameter_input_v_;
  86. std::vector<StrategyPtr> sp_vector_;
  87. Dimensions input_strategy_;
  88. TensorLayout input_layout_;
  89. TensorLayout output_layout_;
  90. bool input_layout_set_flag_;
  91. bool output_layout_set_flag_;
  92. bool is_generating_costs_;
  93. std::string pre_operator_name_;
  94. std::string next_operator_name_;
  95. };
  96. } // namespace parallel
  97. } // namespace mindspore
  98. #endif // MINDSPORE_CCSRC_PARALLEL_OPS_INFO_RESHAPE_INFO_H_