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.

arithmetic_info.h 5.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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_ARITHMETIC_INFO_H_
  17. #define MINDSPORE_CCSRC_PARALLEL_OPS_INFO_ARITHMETIC_INFO_H_
  18. #include <memory>
  19. #include <string>
  20. #include <unordered_map>
  21. #include <vector>
  22. #include "ir/value.h"
  23. #include "parallel/auto_parallel/operator_costmodel.h"
  24. #include "parallel/ops_info/operator_info.h"
  25. #include "parallel/strategy.h"
  26. namespace mindspore {
  27. namespace parallel {
  28. class ArithmeticBase : public OperatorInfo {
  29. public:
  30. ArithmeticBase(const std::string &operator_name, const Shapes &inputs_shape, const Shapes &outputs_shape,
  31. const PrimitiveAttrs &attrs, OperatorCostPtr cost)
  32. : OperatorInfo(operator_name, inputs_shape, outputs_shape, attrs, cost) {}
  33. ~ArithmeticBase() override = default;
  34. Status Init(const StrategyPtr &strategy) override;
  35. Status InitForCostModel(const StrategyPtr &strategy) override;
  36. Status GenerateStrategies(int32_t) override;
  37. Status SetCostUnderStrategy(const StrategyPtr &) override;
  38. void ReComputeBatchSplitFlagList() override;
  39. protected:
  40. Status GetAttrs() override { return SUCCESS; }
  41. Status CheckStrategy(const StrategyPtr &strategy) override;
  42. Status InferMirrorOps() override;
  43. Status InferForwardCommunication() override { return SUCCESS; }
  44. Status InferTensorInfo() override;
  45. Status InferDevMatrixShape() override;
  46. Status InferTensorMap() override;
  47. Status InferTensorLayout(TensorLayouts *inputs_layout, TensorLayouts *outputs_layout, const Shape &dev_matrix_array);
  48. Shapes InferExpendShape();
  49. };
  50. class SubInfo : public ArithmeticBase {
  51. public:
  52. SubInfo(const std::string &name, const Shapes &inputs_shape, const Shapes &outputs_shape, const PrimitiveAttrs &attrs)
  53. : ArithmeticBase(name, inputs_shape, outputs_shape, attrs, std::make_shared<ArithmeticCost>(false)) {}
  54. ~SubInfo() override = default;
  55. };
  56. class TensorAddInfo : public ArithmeticBase {
  57. public:
  58. TensorAddInfo(const std::string &name, const Shapes &inputs_shape, const Shapes &outputs_shape,
  59. const PrimitiveAttrs &attrs)
  60. : ArithmeticBase(name, inputs_shape, outputs_shape, attrs, std::make_shared<ArithmeticCost>(false)) {}
  61. ~TensorAddInfo() override = default;
  62. };
  63. class MulInfo : public ArithmeticBase {
  64. public:
  65. MulInfo(const std::string &name, const Shapes &inputs_shape, const Shapes &outputs_shape, const PrimitiveAttrs &attrs)
  66. : ArithmeticBase(name, inputs_shape, outputs_shape, attrs, std::make_shared<ArithmeticCost>(true)) {}
  67. ~MulInfo() override = default;
  68. };
  69. class DivInfo : public ArithmeticBase {
  70. public:
  71. DivInfo(const std::string &name, const Shapes &inputs_shape, const Shapes &outputs_shape, const PrimitiveAttrs &attrs)
  72. : ArithmeticBase(name, inputs_shape, outputs_shape, attrs, std::make_shared<ArithmeticCost>(true)) {}
  73. ~DivInfo() override = default;
  74. };
  75. class RealDivInfo : public ArithmeticBase {
  76. public:
  77. RealDivInfo(const std::string &name, const Shapes &inputs_shape, const Shapes &outputs_shape,
  78. const PrimitiveAttrs &attrs)
  79. : ArithmeticBase(name, inputs_shape, outputs_shape, attrs, std::make_shared<ArithmeticCost>(true)) {}
  80. ~RealDivInfo() override = default;
  81. };
  82. class FloorDivInfo : public ArithmeticBase {
  83. public:
  84. FloorDivInfo(const std::string &name, const Shapes &inputs_shape, const Shapes &outputs_shape,
  85. const PrimitiveAttrs &attrs)
  86. : ArithmeticBase(name, inputs_shape, outputs_shape, attrs, std::make_shared<ArithmeticCost>(true)) {}
  87. ~FloorDivInfo() override = default;
  88. };
  89. class PowInfo : public ArithmeticBase {
  90. public:
  91. PowInfo(const std::string &name, const Shapes &inputs_shape, const Shapes &outputs_shape, const PrimitiveAttrs &attrs)
  92. : ArithmeticBase(name, inputs_shape, outputs_shape, attrs, std::make_shared<ArithmeticCost>(true)) {}
  93. ~PowInfo() override = default;
  94. };
  95. class GreaterInfo : public ArithmeticBase {
  96. public:
  97. GreaterInfo(const std::string &name, const Shapes &inputs_shape, const Shapes &outputs_shape,
  98. const PrimitiveAttrs &attrs)
  99. : ArithmeticBase(name, inputs_shape, outputs_shape, attrs, std::make_shared<ArithmeticCost>(false)) {}
  100. ~GreaterInfo() override = default;
  101. };
  102. class AssignSubInfo : public ArithmeticBase {
  103. public:
  104. AssignSubInfo(const std::string &name, const Shapes &inputs_shape, const Shapes &outputs_shape,
  105. const PrimitiveAttrs &attrs)
  106. : ArithmeticBase(name, inputs_shape, outputs_shape, attrs, std::make_shared<ArithmeticCost>(false)) {}
  107. ~AssignSubInfo() override = default;
  108. };
  109. // All dimensions can be split arbitrarily, but the split method of Logits should be the same as that of label.
  110. class SigmoidCrossEntropyWithLogitsInfo : public ArithmeticBase {
  111. public:
  112. SigmoidCrossEntropyWithLogitsInfo(const std::string &name, const Shapes &inputs_shape, const Shapes &outputs_shape,
  113. const PrimitiveAttrs &attrs)
  114. : ArithmeticBase(name, inputs_shape, outputs_shape, attrs, std::make_shared<ArithmeticCost>(false)) {}
  115. ~SigmoidCrossEntropyWithLogitsInfo() override = default;
  116. };
  117. } // namespace parallel
  118. } // namespace mindspore
  119. #endif // MINDSPORE_CCSRC_PARALLEL_OPS_INFO_ARITHMETIC_INFO_H_