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.

context.h 4.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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_CONTEXT_H_
  17. #define MINDSPORE_CCSRC_PARALLEL_CONTEXT_H_
  18. #include <cstdint>
  19. #include <memory>
  20. #include <string>
  21. #include <vector>
  22. #include "parallel/ops_info/ops_utils.h"
  23. #include "parallel/status.h"
  24. #include "utils/convert_utils.h"
  25. namespace mindspore {
  26. namespace parallel {
  27. constexpr char STAND_ALONE[] = "stand_alone";
  28. constexpr char DATA_PARALLEL[] = "data_parallel";
  29. constexpr char HYBRID_PARALLEL[] = "hybrid_parallel";
  30. constexpr char AUTO_PARALLEL[] = "auto_parallel";
  31. constexpr char SEMI_AUTO_PARALLEL[] = "semi_auto_parallel";
  32. constexpr char DYNAMIC_PROGRAMMING[] = "dynamic_programming";
  33. constexpr char RECURSIVE_PROGRAMMING[] = "recursive_programming";
  34. class ParallelContext {
  35. public:
  36. ~ParallelContext() = default;
  37. ParallelContext(const ParallelContext &) = delete;
  38. ParallelContext &operator=(const ParallelContext &) = delete;
  39. static std::shared_ptr<ParallelContext> GetInstance();
  40. void set_mirror_mean(bool mirror_mean);
  41. bool mirror_mean() const { return mirror_mean_; }
  42. void set_cast_before_mirror(bool cast_before_mirror);
  43. bool cast_before_mirror() const { return cast_before_mirror_; }
  44. void set_loss_repeated_mean(bool loss_repeated_mean);
  45. bool loss_repeated_mean() const { return loss_repeated_mean_; }
  46. void set_device_num(int32_t device_num);
  47. int32_t device_num() const { return device_num_; }
  48. void set_global_rank(int32_t global_rank);
  49. int32_t global_rank() const { return global_rank_; }
  50. void set_communication_backend(const std::string &communication_backend);
  51. std::string communication_backend() const { return communication_backend_; }
  52. bool set_parallel_mode(const std::string &parallel_mode);
  53. std::string parallel_mode() const { return parallel_mode_; }
  54. bool set_strategy_search_mode(const std::string &strategy_search_mode);
  55. std::string strategy_search_mode() const { return strategy_search_mode_; }
  56. void set_parameter_broadcast(bool parameter_broadcast);
  57. bool parameter_broadcast() const { return parameter_broadcast_; }
  58. bool device_num_is_set() const { return device_num_is_set_; }
  59. bool global_rank_is_set() const { return global_rank_is_set_; }
  60. bool parameter_broadcast_is_set() const { return parameter_broadcast_is_set_; }
  61. void set_all_reduce_fusion_split_indices(const std::vector<uint32_t> indices);
  62. const std::vector<uint32_t> all_reduce_fusion_split_indices() const;
  63. void set_all_reduce_fusion_split_sizes(const std::vector<uint32_t> sizes);
  64. const std::vector<uint32_t> all_reduce_fusion_split_sizes() const;
  65. void set_enable_all_reduce_fusion(bool enable_all_reduce_fusion) {
  66. enable_all_reduce_fusion_ = enable_all_reduce_fusion;
  67. }
  68. bool enable_all_reduce_fusion() const { return enable_all_reduce_fusion_; }
  69. void Reset();
  70. private:
  71. ParallelContext();
  72. static std::shared_ptr<ParallelContext> inst_context_;
  73. bool mirror_mean_;
  74. bool cast_before_mirror_;
  75. bool loss_repeated_mean_;
  76. int32_t device_num_;
  77. int32_t global_rank_;
  78. std::string communication_backend_;
  79. std::string parallel_mode_;
  80. std::string strategy_search_mode_;
  81. bool parameter_broadcast_;
  82. bool device_num_is_set_;
  83. bool global_rank_is_set_;
  84. bool parameter_broadcast_is_set_;
  85. bool enable_all_reduce_fusion_;
  86. std::vector<uint32_t> all_reduce_fusion_split_indices_;
  87. std::vector<uint32_t> all_reduce_fusion_split_sizes_;
  88. };
  89. } // namespace parallel
  90. } // namespace mindspore
  91. #endif // MINDSPORE_CCSRC_PARALLEL_CONTEXT_H_