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.

onehot_info.h 2.4 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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_ONEHOT_INFO_H_
  17. #define MINDSPORE_CCSRC_PARALLEL_OPS_INFO_ONEHOT_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 OneHotInfo : public OperatorInfo {
  29. public:
  30. OneHotInfo(const std::string &name, const Shapes &inputs_shape, const Shapes &outputs_shape,
  31. const PrimitiveAttrs &attrs)
  32. : OperatorInfo(name, inputs_shape, outputs_shape, attrs, std::make_shared<OneHotCost>(false)) {}
  33. ~OneHotInfo() override = default;
  34. Status Init(const StrategyPtr &strategy) override;
  35. Status InitForCostModel(const StrategyPtr &strategy) override;
  36. Status GenerateStrategies(int32_t stage_id) override;
  37. Status SetCostUnderStrategy(const StrategyPtr &strategy) override;
  38. ReplaceGraphPtr replace_graph(const CNodePtr &cnode) override;
  39. std::shared_ptr<std::vector<std::vector<int32_t>>> GenerateBatchStrategies() override;
  40. protected:
  41. Status CheckStrategy(const StrategyPtr &strategy) override;
  42. Status GetAttrs() override;
  43. Status InferMirrorOps() override { return SUCCESS; }
  44. Status InferForwardCommunication() override { return SUCCESS; }
  45. Status InferTensorInfo() override;
  46. Status InferDevMatrixShape() override;
  47. Status InferTensorMap() override;
  48. Status ExtractInputInfo();
  49. private:
  50. Status ComputeReplaceGraph(const CNodePtr &cnode);
  51. int axis_ = -1;
  52. int32_t rank_ = 0;
  53. int32_t total_class_number_ = 1;
  54. int32_t classes_each_device_ = 1;
  55. ValuePtr axis_value_ptr_;
  56. int32_t mod_rank_ = 0;
  57. };
  58. } // namespace parallel
  59. } // namespace mindspore
  60. #endif // MINDSPORE_CCSRC_PARALLEL_OPS_INFO_ONEHOT_INFO_H_