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.

costmodel_context.h 5.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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_COSTMODEL_CONTEXT_H_
  17. #define MINDSPORE_CCSRC_PARALLEL_COSTMODEL_CONTEXT_H_
  18. #include <memory>
  19. #include <string>
  20. #include <vector>
  21. #include "utils/log_adapter.h"
  22. namespace mindspore {
  23. namespace parallel {
  24. class CostModelContext {
  25. public:
  26. ~CostModelContext() = default;
  27. CostModelContext(const CostModelContext &) = delete;
  28. CostModelContext &operator=(const CostModelContext &) = delete;
  29. void ResetCostModel();
  30. void ResetAlgoParameters();
  31. static std::shared_ptr<CostModelContext> GetInstance();
  32. // DEVICE_MEMORY_CAPACITY
  33. void set_device_memory_capacity(double);
  34. double device_memory_capacity() const { return device_memory_capacity_; }
  35. // COST_MODEL_ALPHA
  36. void set_costmodel_alpha(double);
  37. double costmodel_alpha() const { return costmodel_alpha_; }
  38. // COST_MODEL_BETA
  39. void set_costmodel_beta(double);
  40. double costmodel_beta() const { return costmodel_beta_; }
  41. // COST_MODEL_GAMMA
  42. void set_costmodel_gamma(double);
  43. double costmodel_gamma() const { return costmodel_gamma_; }
  44. // COST_MODEL_SIMPLIFY_CALCULATION
  45. void set_costmodel_simplify_cal(bool);
  46. bool costmodel_simplify_cal() const { return costmodel_simplify_cal_; }
  47. // COST_MODEL_COMMUNI_THRESHOLD
  48. void set_costmodel_communi_threshold(double);
  49. double costmodel_communi_threshold() const { return costmodel_communi_threshold_; }
  50. // COST_MODEL_COMMUNI_CONST
  51. void set_costmodel_communi_const(double);
  52. double costmodel_communi_const() const { return costmodel_communi_const_; }
  53. // COST_MODEL_COMMUNI_BIAS
  54. void set_costmodel_communi_bias(double);
  55. double costmodel_communi_bias() const { return costmodel_communi_bias_; }
  56. void set_multi_subgraphs(bool);
  57. bool is_multi_subgraphs() const { return is_multi_subgraphs_; }
  58. void set_costmodel_allreduce_fusion_algorithm(int32_t);
  59. int32_t costmodel_allreduce_fusion_algorithm() const { return costmodel_allreduce_fusion_algorithm_; }
  60. void set_costmodel_allreduce_fusion_times(int32_t);
  61. int32_t costmodel_allreduce_fusion_times() const { return costmodel_allreduce_fusion_times_; }
  62. void set_costmodel_allreduce_fusion_tail_percent(double);
  63. double costmodel_allreduce_fusion_tail_percent() const { return costmodel_allreduce_fusion_tail_percent_; }
  64. void set_costmodel_allreduce_fusion_tail_time(double);
  65. double costmodel_allreduce_fusion_tail_time() const { return costmodel_allreduce_fusion_tail_time_; }
  66. void set_costmodel_allreduce_fusion_allreduce_inherent_time(double);
  67. double costmodel_allreduce_fusion_allreduce_inherent_time() const {
  68. return costmodel_allreduce_fusion_allreduce_inherent_time_;
  69. }
  70. void set_costmodel_allreduce_fusion_allreduce_bandwidth(double);
  71. double costmodel_allreduce_fusion_allreduce_bandwidth() const {
  72. return costmodel_allreduce_fusion_allreduce_bandwidth_;
  73. }
  74. void set_costmodel_allreduce_fusion_computation_time_parameter(double);
  75. double costmodel_allreduce_fusion_computation_time_parameter() const {
  76. return costmodel_allreduce_fusion_computation_time_parameter_;
  77. }
  78. // TENSOR_SLICE_ALIGNMENT_ENABLE
  79. void set_tensor_slice_alignment_enable(bool);
  80. bool tensor_slice_alignment_enable() const { return tensor_slice_alignment_enable_; }
  81. // TENSOR_SLICE_ALIGNMENT_SIZE
  82. void set_tensor_slice_alignment_size(size_t);
  83. size_t tensor_slice_alignment_size() const { return tensor_slice_alignment_size_; }
  84. // FULLY_USE_DEVICES
  85. void set_fully_use_device(bool);
  86. bool fully_use_device() const { return fully_use_device_; }
  87. // ELEMENTWISE_OP_STRA_FOLLOW
  88. void set_elementwise_stra_follow(bool);
  89. bool elementwise_stra_follow() const { return elementwise_stra_follow_; }
  90. void set_run_phase(int32_t);
  91. int32_t run_phase() const { return run_phase_; }
  92. private:
  93. CostModelContext();
  94. static std::shared_ptr<CostModelContext> cm_context_inst_;
  95. // DEVICE_MEMORY_CAPACITY
  96. double device_memory_capacity_;
  97. // COST_MODEL_ALPHA
  98. double costmodel_alpha_;
  99. // COST_MODEL_BETA
  100. double costmodel_beta_;
  101. // COST_MODEL_GAMMA
  102. double costmodel_gamma_;
  103. // COST_MODEL_SIMPLIFY_CALCULATION
  104. bool costmodel_simplify_cal_;
  105. // COST_MODEL_COMMUNI_THRESHOLD
  106. double costmodel_communi_threshold_;
  107. // COST_MODEL_COMMUNI_CONST
  108. double costmodel_communi_const_;
  109. // COST_MODEL_COMMUNI_BIAS
  110. double costmodel_communi_bias_;
  111. // MULTI_SUBGRAPHS
  112. bool is_multi_subgraphs_;
  113. int32_t run_phase_; // 0: 'training', 1: 'inference'
  114. int32_t costmodel_allreduce_fusion_algorithm_;
  115. int32_t costmodel_allreduce_fusion_times_;
  116. double costmodel_allreduce_fusion_tail_percent_;
  117. double costmodel_allreduce_fusion_tail_time_;
  118. double costmodel_allreduce_fusion_allreduce_inherent_time_;
  119. double costmodel_allreduce_fusion_allreduce_bandwidth_;
  120. double costmodel_allreduce_fusion_computation_time_parameter_;
  121. // TENSOR_SLICE_ALIGNMENT_ENABLE
  122. bool tensor_slice_alignment_enable_;
  123. // TENSOR_SLICE_ALIGNMENT_SIZE
  124. size_t tensor_slice_alignment_size_;
  125. // FULLY_USE_DEVICES
  126. bool fully_use_device_;
  127. // ELEMENTWISE_OP_STRA_FOLLOW
  128. bool elementwise_stra_follow_;
  129. };
  130. } // namespace parallel
  131. } // namespace mindspore
  132. #endif // MINDSPORE_CCSRC_PARALLEL_COSTMODEL_CONTEXT_H_