1 /** 2 * Copyright 2024 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 17 #ifndef MINDSPORE_CORE_UTILS_COMPILE_CONFIG_H_ 18 #define MINDSPORE_CORE_UTILS_COMPILE_CONFIG_H_ 19 20 #include <string> 21 #include <memory> 22 #include <map> 23 #include <functional> 24 #include "mindapi/base/macros.h" 25 26 namespace mindspore { 27 class MS_CORE_API CompileConfigManager { 28 public: 29 using CompileConfigCollectFunc = std::function<std::map<std::string, std::string>()>; 30 31 /// \brief Get instance of CompileConfigManager. 32 /// 33 /// \return Instance of CompileConfigManager. 34 static CompileConfigManager &GetInstance() noexcept; 35 36 /// \brief Disable the default constructor. 37 CompileConfigManager(const CompileConfigManager &) = delete; 38 /// \brief Disable the default copy constructor. 39 CompileConfigManager &operator=(const CompileConfigManager &) = delete; 40 /// \brief Destructor. 41 ~CompileConfigManager() = default; 42 set_collect_func(CompileConfigCollectFunc func)43 static void set_collect_func(CompileConfigCollectFunc func) { collect_func_ = func; } 44 45 void CollectCompileConfig(); 46 47 void SetConfig(const std::string &config_name, const std::string &value, bool overwrite = true); 48 49 std::string GetConfig(const std::string &config_name); 50 51 private: 52 CompileConfigManager() = default; 53 inline static CompileConfigCollectFunc collect_func_{nullptr}; 54 std::map<std::string, std::string> compile_config_; 55 bool collect_finished_{false}; 56 }; 57 58 namespace common { 59 MS_CORE_API std::string GetCompileConfig(const std::string &config_name); 60 MS_CORE_API void SetCompileConfig(const std::string &config_name, const std::string &value, bool overwrite = true); 61 } // namespace common 62 } // namespace mindspore 63 64 #endif // MINDSPORE_CORE_UTILS_COMPILE_CONFIG_H_ 65