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.

env_config_parser.h 2.9 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #ifndef MINDSPORE_CCSRC_DEBUG_ENV_CONFIG_PARSER_H_
  17. #define MINDSPORE_CCSRC_DEBUG_ENV_CONFIG_PARSER_H_
  18. #include <string>
  19. #include <map>
  20. #include <set>
  21. #include <mutex>
  22. #include "nlohmann/json.hpp"
  23. #include "utils/ms_utils.h"
  24. namespace mindspore {
  25. enum RdrModes : int { Exceptional = 1, Normal = 2 };
  26. class EnvConfigParser {
  27. public:
  28. static EnvConfigParser &GetInstance() {
  29. static EnvConfigParser instance;
  30. instance.Parse();
  31. return instance;
  32. }
  33. void Parse();
  34. std::string ConfigPath() const { return config_file_; }
  35. #ifdef ENABLE_DUMP_IR
  36. bool HasRdrSetting() const { return has_rdr_setting_; }
  37. bool RdrEnabled() const { return rdr_enabled_; }
  38. int RdrMode() const { return rdr_mode_; }
  39. std::string RdrPath() const { return rdr_path_; }
  40. #endif
  41. bool GetSysMemreuse() { return sys_memreuse_; }
  42. void SetSysMemreuse(bool set_memreuse) { sys_memreuse_ = set_memreuse; }
  43. private:
  44. EnvConfigParser() {}
  45. ~EnvConfigParser() {}
  46. std::mutex lock_;
  47. std::string config_file_{""};
  48. bool already_parsed_{false};
  49. #ifdef ENABLE_DUMP_IR
  50. // rdr
  51. bool has_rdr_setting_{false};
  52. bool rdr_enabled_{false};
  53. int rdr_mode_{1};
  54. std::string rdr_path_{"./"};
  55. #endif
  56. // memreuse
  57. bool sys_memreuse_{true};
  58. void ParseFromFile();
  59. void ParseFromEnv();
  60. std::string GetIfstreamString(const std::ifstream &ifstream) const;
  61. bool CheckJsonStringType(const nlohmann::json &content, const std::string &setting_key, const std::string &key) const;
  62. std::optional<nlohmann::detail::iter_impl<const nlohmann::json>> CheckJsonKeyExist(const nlohmann::json &content,
  63. const std::string &setting_key,
  64. const std::string &key) const;
  65. #ifdef ENABLE_DUMP_IR
  66. void ParseRdrSetting(const nlohmann::json &content);
  67. void ParseRdrPath(const nlohmann::json &content);
  68. void ParseRdrEnable(const nlohmann::json &content);
  69. void ParseRdrMode(const nlohmann::json &content);
  70. #endif
  71. void ParseMemReuseSetting(const nlohmann::json &content);
  72. void ParseSysMemReuse(const nlohmann::json &content);
  73. void ConfigToString();
  74. };
  75. } // namespace mindspore
  76. #endif // MINDSPORE_CCSRC_DEBUG_ENV_CONFIG_PARSER_H_