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 2.9 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. input_layout_set_flag_(false),
  37. output_layout_set_flag_(false) {}
  38. ~ReshapeInfo() override = default;
  39. Status Init(const StrategyPtr &strategy) override;
  40. void SetInputLayout(const TensorLayout &input_layout) {
  41. input_layout_ = input_layout;
  42. input_layout_set_flag_ = true;
  43. }
  44. void SetOutputLayout(const TensorLayout &output_layout) {
  45. output_layout_ = output_layout;
  46. output_layout_set_flag_ = true;
  47. }
  48. Status InitForCostModel(const StrategyPtr &strategy) override;
  49. Status GenerateStrategies(int32_t stage_id) override;
  50. Status SetCostUnderStrategy(const StrategyPtr &strategy) override;
  51. protected:
  52. Status CheckStrategy(const StrategyPtr &strategy) override;
  53. Status InferMirrorOps() override;
  54. Status InferForwardCommunication() override;
  55. Status InferTensorMap() override;
  56. Status InferTensorInfo() override;
  57. Status InferDevMatrixShape() override;
  58. Status InferTensorLayout(TensorLayouts *inputs_layout, TensorLayouts *outputs_layout);
  59. Status GetAttrs() override;
  60. Strategys GetOutputsStrategy();
  61. private:
  62. Status GetParameterInput();
  63. Status ComputeReplaceOp();
  64. void InferTensorInfoByLayout();
  65. void device_number(const StrategyPtr &strategy);
  66. Status InferDefaultLayout(const Shape &shape, TensorLayout *const layout);
  67. int32_t dev_num_;
  68. std::vector<int32_t> parameter_input_v_;
  69. Dimensions input_strategy_;
  70. TensorLayout input_layout_;
  71. TensorLayout output_layout_;
  72. bool input_layout_set_flag_;
  73. bool output_layout_set_flag_;
  74. };
  75. } // namespace parallel
  76. } // namespace mindspore
  77. #endif // MINDSPORE_CCSRC_PARALLEL_OPS_INFO_RESHAPE_INFO_H_