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.cc 5.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. #include "parallel/costmodel_context.h"
  17. #include <memory>
  18. #include "parallel/allreduce_fusion/allreduce_fusion.h"
  19. #include "parallel/auto_parallel/graph_costmodel.h"
  20. namespace mindspore {
  21. namespace parallel {
  22. std::shared_ptr<CostModelContext> CostModelContext::cm_context_inst_ = nullptr;
  23. std::shared_ptr<CostModelContext> CostModelContext::GetInstance() {
  24. if (cm_context_inst_ == nullptr) {
  25. MS_LOG(INFO) << "Create costmodel_context";
  26. cm_context_inst_.reset(new (std::nothrow) CostModelContext());
  27. }
  28. return cm_context_inst_;
  29. }
  30. CostModelContext::CostModelContext() {
  31. ResetCostModel();
  32. ResetAlgoParameters();
  33. }
  34. void CostModelContext::ResetCostModel() {
  35. device_memory_capacity_ = DEFAULT_DEVICE_MEMORY_CAPACITY;
  36. costmodel_alpha_ = DEFAULT_COST_MODEL_ALPHA;
  37. costmodel_beta_ = DEFAULT_COST_MODEL_BETA;
  38. costmodel_gamma_ = DEFAULT_COST_MODEL_GAMMA;
  39. costmodel_communi_threshold_ = DEFAULT_COST_MODEL_COMMUNI_THRESHOLD;
  40. costmodel_communi_const_ = DEFAULT_COST_MODEL_COMMUNI_CONST;
  41. costmodel_communi_bias_ = DEFAULT_COST_MODEL_COMMUNI_BIAS;
  42. is_multi_subgraphs_ = DEFAULT_IS_MULTI_SUBGRAPHS;
  43. run_phase_ = DEFAULT_RUN_PHASE;
  44. costmodel_allreduce_fusion_algorithm_ = DEFAULT_COST_MODEL_ALLREDUCE_FUSION_ALGORITHM;
  45. costmodel_allreduce_fusion_times_ = DEFAULT_COST_MODEL_ALLREDUCE_FUSION_TIMES;
  46. costmodel_allreduce_fusion_tail_percent_ = DEFAULT_COST_MODEL_ALLREDUCE_FUSION_TAIL_PERCENT;
  47. costmodel_allreduce_fusion_tail_time_ = DEFAULT_COST_MODEL_ALLREDUCE_FUSION_TAIL_TIME;
  48. costmodel_allreduce_fusion_allreduce_inherent_time_ = DEFAULT_COST_MODEL_ALLREDUCE_FUSION_ALLREDUCE_INHERENT_TIME;
  49. costmodel_allreduce_fusion_allreduce_bandwidth_ = DEFAULT_COST_MODEL_ALLREDUCE_FUSION_ALLREDUCE_BANDWIDTH;
  50. costmodel_allreduce_fusion_computation_time_parameter_ =
  51. DEFAULT_COST_MODEL_ALLREDUCE_FUSION_COMPUTATION_TIME_PARAMETER;
  52. }
  53. void CostModelContext::ResetAlgoParameters() {
  54. costmodel_simplify_cal_ = DEFAULT_COST_MODEL_SIMPLIFY_CALCULATION;
  55. tensor_slice_alignment_enable_ = DEFAULT_TENSOR_SLICE_ALIGNMENT_ENABLE;
  56. tensor_slice_alignment_size_ = DEFAULT_TENSOR_SLICE_ALIGNMENT_SIZE;
  57. fully_use_device_ = DEFAULT_FULLY_USE_DEVICES;
  58. elementwise_stra_follow_ = DEFAULT_ELEMENTWISE_OP_STRA_FOLLOW;
  59. }
  60. void CostModelContext::set_device_memory_capacity(double dm_capacity) { device_memory_capacity_ = dm_capacity; }
  61. void CostModelContext::set_costmodel_alpha(double cm_alpha) { costmodel_alpha_ = cm_alpha; }
  62. void CostModelContext::set_costmodel_beta(double cm_beta) { costmodel_beta_ = cm_beta; }
  63. void CostModelContext::set_costmodel_gamma(double cm_gamma) { costmodel_gamma_ = cm_gamma; }
  64. void CostModelContext::set_costmodel_simplify_cal(bool cm_simplify) { costmodel_simplify_cal_ = cm_simplify; }
  65. void CostModelContext::set_costmodel_communi_threshold(double cm_communi_th) {
  66. costmodel_communi_threshold_ = cm_communi_th;
  67. }
  68. void CostModelContext::set_costmodel_communi_const(double cm_communi_const) {
  69. costmodel_communi_const_ = cm_communi_const;
  70. }
  71. void CostModelContext::set_costmodel_communi_bias(double cm_communi_bias) { costmodel_communi_bias_ = cm_communi_bias; }
  72. void CostModelContext::set_multi_subgraphs(bool multi_graphs) { is_multi_subgraphs_ = multi_graphs; }
  73. void CostModelContext::set_costmodel_allreduce_fusion_algorithm(int32_t algorithm) {
  74. costmodel_allreduce_fusion_algorithm_ = algorithm;
  75. }
  76. void CostModelContext::set_costmodel_allreduce_fusion_times(int32_t allreduce_fusion_times) {
  77. costmodel_allreduce_fusion_times_ = allreduce_fusion_times;
  78. }
  79. void CostModelContext::set_costmodel_allreduce_fusion_tail_percent(double tail_percent) {
  80. costmodel_allreduce_fusion_tail_percent_ = tail_percent;
  81. }
  82. void CostModelContext::set_costmodel_allreduce_fusion_tail_time(double tail_time) {
  83. costmodel_allreduce_fusion_tail_time_ = tail_time;
  84. }
  85. void CostModelContext::set_costmodel_allreduce_fusion_allreduce_inherent_time(double allreduce_inherent_time) {
  86. costmodel_allreduce_fusion_allreduce_inherent_time_ = allreduce_inherent_time;
  87. }
  88. void CostModelContext::set_costmodel_allreduce_fusion_allreduce_bandwidth(double allreduce_bandwidth) {
  89. costmodel_allreduce_fusion_allreduce_bandwidth_ = allreduce_bandwidth;
  90. }
  91. void CostModelContext::set_costmodel_allreduce_fusion_computation_time_parameter(double computation_time_parameter) {
  92. costmodel_allreduce_fusion_computation_time_parameter_ = computation_time_parameter;
  93. }
  94. void CostModelContext::set_tensor_slice_alignment_enable(bool ts_align) { tensor_slice_alignment_enable_ = ts_align; }
  95. void CostModelContext::set_tensor_slice_alignment_size(size_t ts_align_size) {
  96. tensor_slice_alignment_size_ = ts_align_size;
  97. }
  98. void CostModelContext::set_fully_use_device(bool fully_use) { fully_use_device_ = fully_use; }
  99. void CostModelContext::set_elementwise_stra_follow(bool elementwise_follow) {
  100. elementwise_stra_follow_ = elementwise_follow;
  101. }
  102. void CostModelContext::set_run_phase(int32_t phase) { run_phase_ = phase; }
  103. } // namespace parallel
  104. } // namespace mindspore