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.

profiling_properties.cc 4.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /**
  2. * Copyright 2021 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 "profiling_properties.h"
  17. #include "framework/common/debug/ge_log.h"
  18. #include "framework/common/debug/log.h"
  19. #include "graph/ge_context.h"
  20. namespace {
  21. const uint64_t kMsProfOptionsMaxlen = 2048;
  22. const char *const kFpPoint = "fp_point";
  23. const char *const kBpPoint = "bp_point";
  24. } // namespace ge
  25. namespace ge{
  26. ProfilingProperties& ProfilingProperties::Instance() {
  27. static ProfilingProperties profiling_properties;
  28. return profiling_properties;
  29. }
  30. void ProfilingProperties::SetLoadProfiling(bool is_load_profiling) {
  31. std::lock_guard<std::mutex>lock(mutex_);
  32. is_load_profiling_ = is_load_profiling;
  33. }
  34. bool ProfilingProperties::IsLoadProfiling() {
  35. std::lock_guard<std::mutex>lock(mutex_);
  36. return is_load_profiling_;
  37. }
  38. void ProfilingProperties::SetExecuteProfiling(bool is_exec_profiling) {
  39. std::lock_guard<std::mutex>lock(mutex_);
  40. is_execute_profiling_ = is_exec_profiling;
  41. }
  42. bool ProfilingProperties::IsExecuteProfiling() {
  43. std::lock_guard<std::mutex>lock(mutex_);
  44. return is_execute_profiling_;
  45. }
  46. void ProfilingProperties::SetTrainingTrace(bool is_train_trace) {
  47. std::lock_guard<std::mutex>lock(mutex_);
  48. is_training_trace_ = is_train_trace;
  49. }
  50. void ProfilingProperties::GetFpBpPoint(std::string &fp_point, std::string &bp_point) {
  51. // Env or options mode, fp_point_/bp_point_ have initiliazed on profiling init
  52. std::lock_guard<std::mutex>lock(mutex_);
  53. if (!fp_point_.empty() && !bp_point_.empty()) {
  54. fp_point = fp_point_;
  55. bp_point = bp_point_;
  56. GELOGI("Bp Fp have been initialized in env or options. bp_point: %s, fp_point: %s", bp_point.c_str(),
  57. fp_point.c_str());
  58. return;
  59. }
  60. // ProfApi mode and training trace is set
  61. // Parse options first
  62. char env_profiling_options[kMsProfOptionsMaxlen] = {0x00};
  63. bool is_profiling_valid = false;
  64. std::string profiling_options;
  65. if (ge::GetContext().GetOption(OPTION_EXEC_PROFILING_OPTIONS, profiling_options) == SUCCESS &&
  66. !profiling_options.empty()) {
  67. is_profiling_valid = true;
  68. } else {
  69. INT32 ret = mmGetEnv("PROFILING_OPTIONS", env_profiling_options, kMsProfOptionsMaxlen);
  70. if (ret != EN_OK) {
  71. GELOGI("PROFILING_OPTIONS env is not exist.");
  72. return;
  73. }
  74. GELOGI("Parse env PROFILING_OPTIONS:%s.", env_profiling_options);
  75. profiling_options = env_profiling_options;
  76. is_profiling_valid = true;
  77. }
  78. if (is_profiling_valid) {
  79. try {
  80. Json prof_options = Json::parse(profiling_options);
  81. if (prof_options.contains(kFpPoint)) {
  82. fp_point_ = prof_options[kFpPoint];
  83. }
  84. if (prof_options.contains(kBpPoint)) {
  85. bp_point_ = prof_options[kBpPoint];
  86. }
  87. fp_point = fp_point_;
  88. bp_point = bp_point_;
  89. if (!fp_point_.empty() && !bp_point_.empty()) {
  90. GELOGI("Training trace bp fp is set, bp_point:%s, fp_point:%s.", bp_point_.c_str(), fp_point_.c_str());
  91. }
  92. } catch (...) {
  93. GELOGW("Json prof options is invalid.");
  94. return;
  95. }
  96. }
  97. return;
  98. }
  99. void ProfilingProperties::SetFpBpPoint(const std::string &fp_point, const std::string &bp_point) {
  100. std::lock_guard<std::mutex>lock(mutex_);
  101. fp_point_ = fp_point;
  102. bp_point_ = bp_point;
  103. }
  104. void ProfilingProperties::ClearProperties() {
  105. std::lock_guard<std::mutex>lock(mutex_);
  106. is_load_profiling_ = false;
  107. is_execute_profiling_ = false;
  108. is_training_trace_ = false;
  109. fp_point_.clear();
  110. bp_point_.clear();
  111. }
  112. } // namespace ge

图引擎模块(GE)是MindSpore的一个子模块,其代码由C++实现,位于前端模块ME和底层硬件之间,起到承接作用。图引擎模块以ME下发的图作为输入,然后进行一系列的深度图优化操作,最后输出一张可以在底层硬件上高效运行的图。GE针对昇腾AI处理器的硬件结构特点,做了特定的优化工作,以此来充分发挥出昇腾AI处理器的强大算力。在进行模型训练/推理时,GE会被自动调用而用户并不感知。GE主要由GE API和GE Core两部分组成,详细的架构图如下所示