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.

properties_manager.h 4.5 kB

5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /**
  2. * Copyright 2019-2020 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 GE_COMMON_PROPERTIES_MANAGER_H_
  17. #define GE_COMMON_PROPERTIES_MANAGER_H_
  18. #include <map>
  19. #include <mutex>
  20. #include <set>
  21. #include <string>
  22. #include <vector>
  23. #include "graph/op_desc.h"
  24. namespace ge {
  25. // Configuration property management
  26. static const char *SYSMODE __attribute__((unused)) = "FMK_SYSMODE";
  27. static const char *USE_FUSION __attribute__((unused)) = "FMK_USE_FUSION";
  28. static const char *TIMESTAT_ENABLE __attribute__((unused)) = "DAVINCI_TIMESTAT_ENABLE";
  29. static const char *ANNDROID_DEBUG __attribute__((unused)) = "ANNDROID_DEBUG";
  30. class DumpProperties {
  31. public:
  32. DumpProperties() = default;
  33. ~DumpProperties() = default;
  34. DumpProperties(const DumpProperties &dump);
  35. DumpProperties &operator=(const DumpProperties &dump);
  36. void InitByOptions();
  37. void AddPropertyValue(const std::string &model, const std::set<std::string> &layers);
  38. void DeletePropertyValue(const std::string &model);
  39. std::set<std::string> GetAllDumpModel() const;
  40. std::set<std::string> GetPropertyValue(const std::string &model) const;
  41. bool IsLayerNeedDump(const std::string &model, const std::string &om_name, const std::string &op_name) const;
  42. void SetDumpPath(const std::string &path);
  43. std::string GetDumpPath() const;
  44. void SetDumpStep(const std::string &step);
  45. std::string GetDumpStep() const;
  46. void SetDumpMode(const std::string &mode);
  47. std::string GetDumpMode() const;
  48. bool IsOpDebugOpen() const { return is_op_debug_; }
  49. uint32_t GetOpDebugMode() const { return op_debug_mode_; }
  50. private:
  51. void CopyFrom(const DumpProperties &other);
  52. void SetDumpDebugOptions();
  53. string enable_dump_;
  54. string enable_dump_debug_;
  55. std::string dump_path_;
  56. std::string dump_step_;
  57. std::string dump_mode_;
  58. std::map<std::string, std::set<std::string>> model_dump_properties_map_;
  59. bool is_op_debug_ = false;
  60. uint32_t op_debug_mode_ = 0;
  61. };
  62. class PropertiesManager {
  63. public:
  64. // Singleton
  65. static PropertiesManager &Instance();
  66. /**
  67. * @ingroup domi_ome
  68. * @brief Initialize configuration parameters, which must be invoked in main.
  69. * @param [in] file_path Property profile path
  70. * @return true success
  71. * @return false fail
  72. * @author
  73. */
  74. bool Init(const std::string &file_path);
  75. /**
  76. * @ingroup domi_ome
  77. * @brief Get configuration parameter value
  78. * @param [in] key Configuration parameter name
  79. * @return Configuration parameter value. If the parameter name does not exist, return null
  80. * @author
  81. */
  82. std::string GetPropertyValue(const std::string &key);
  83. /**
  84. * @ingroup domi_ome
  85. * @brief Set configuration parameters
  86. * @param [in] key Configuration parameter name
  87. * @param [out] key Configuration parameter value
  88. * @author
  89. */
  90. void SetPropertyValue(const std::string &key, const std::string &value);
  91. /**
  92. * @ingroup domi_ome
  93. * @brief Return configuration parameters
  94. * @return properties_map_
  95. * @author
  96. */
  97. std::map<std::string, std::string> GetPropertyMap();
  98. /**
  99. * @ingroup domi_ome
  100. * @brief Adapt key value pair form, set different separators
  101. * @param [in] delimiter
  102. * @author
  103. */
  104. void SetPropertyDelimiter(const std::string &de);
  105. DumpProperties &GetDumpProperties(uint64_t session_id);
  106. void RemoveDumpProperties(uint64_t session_id);
  107. private:
  108. // Private construct, destructor
  109. PropertiesManager();
  110. ~PropertiesManager();
  111. // Get file content
  112. bool LoadFileContent(const std::string &file_path);
  113. // Parsing a single line file
  114. bool ParseLine(const std::string &line);
  115. // Remove space before and after string
  116. std::string Trim(const std::string &str);
  117. bool is_inited_;
  118. // Configuration item separator, default is "="
  119. std::string delimiter;
  120. std::map<std::string, std::string> properties_map_;
  121. std::mutex mutex_;
  122. std::map<uint64_t, DumpProperties> dump_properties_map_;
  123. };
  124. } // namespace ge
  125. #endif // GE_COMMON_PROPERTIES_MANAGER_H_

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