From: @luopengting Reviewed-by: Signed-off-by:tags/v1.2.0-rc1
| @@ -5,6 +5,7 @@ set(_DEBUG_SRC_LIST | |||
| "${CMAKE_CURRENT_SOURCE_DIR}/dump_proto.cc" | |||
| "${CMAKE_CURRENT_SOURCE_DIR}/trace.cc" | |||
| "${CMAKE_CURRENT_SOURCE_DIR}/common.cc" | |||
| "${CMAKE_CURRENT_SOURCE_DIR}/env_config_parser.cc" | |||
| "${CMAKE_CURRENT_SOURCE_DIR}/rdr/graph_exec_order_recorder.cc" | |||
| "${CMAKE_CURRENT_SOURCE_DIR}/rdr/graph_recorder.cc" | |||
| "${CMAKE_CURRENT_SOURCE_DIR}/rdr/somas_recorder.cc" | |||
| @@ -1,5 +1,5 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * Copyright 2020-2021 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| @@ -18,6 +18,7 @@ | |||
| #include <memory> | |||
| #include <optional> | |||
| #include "utils/ms_context.h" | |||
| #include "utils/system/env.h" | |||
| #include "utils/system/file_system.h" | |||
| #include "utils/log_adapter.h" | |||
| @@ -145,4 +146,28 @@ std::optional<std::string> Common::GetConfigFile(const std::string &env) { | |||
| } | |||
| return dump_config_file; | |||
| } | |||
| std::optional<std::string> Common::GetEnvConfigFile() { | |||
| auto context = MsContext::GetInstance(); | |||
| MS_EXCEPTION_IF_NULL(context); | |||
| std::string env_config_path = context->get_param<std::string>(MS_CTX_ENV_CONFIG_PATH); | |||
| if (env_config_path.empty()) { | |||
| MS_LOG(INFO) << "The env_config_path is not set in context."; | |||
| return {}; | |||
| } | |||
| MS_LOG(INFO) << "Get env_config_path: " << env_config_path; | |||
| std::string config_file(env_config_path); | |||
| std::shared_ptr<system::FileSystem> fs = system::Env::GetFileSystem(); | |||
| MS_EXCEPTION_IF_NULL(fs); | |||
| if (!fs->FileExist(config_file)) { | |||
| MS_LOG(ERROR) << config_file << " not exist."; | |||
| return {}; | |||
| } | |||
| auto point_pos = config_file.find_last_of('.'); | |||
| if (point_pos == std::string::npos) { | |||
| MS_LOG(EXCEPTION) << "Invalid json file name:" << config_file; | |||
| } | |||
| return config_file; | |||
| } | |||
| } // namespace mindspore | |||
| @@ -1,5 +1,5 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * Copyright 2020-2021 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| @@ -28,6 +28,7 @@ class Common { | |||
| ~Common() = default; | |||
| static std::optional<std::string> GetRealPath(const std::string &input_path); | |||
| static std::optional<std::string> GetConfigFile(const std::string &env); | |||
| static std::optional<std::string> GetEnvConfigFile(); | |||
| private: | |||
| static bool CreateNotExistDirs(const std::string &path); | |||
| @@ -0,0 +1,160 @@ | |||
| /** | |||
| * Copyright 2021 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #include "debug/env_config_parser.h" | |||
| #include <fstream> | |||
| #include "nlohmann/json.hpp" | |||
| #include "utils/log_adapter.h" | |||
| #include "debug/common.h" | |||
| #include "utils/ms_context.h" | |||
| #include "utils/convert_utils_base.h" | |||
| namespace { | |||
| constexpr auto kRdrSettings = "rdr"; | |||
| constexpr auto kPath = "path"; | |||
| constexpr auto kEnable = "enable"; | |||
| } // namespace | |||
| namespace mindspore { | |||
| bool EnvConfigParser::CheckJsonStringType(const nlohmann::json &content, const std::string &setting_key, | |||
| const std::string &key) { | |||
| if (!content.is_string()) { | |||
| MS_LOG(WARNING) << "Json Parse Failed. The '" << key << "' in '" << setting_key << "' should be string." | |||
| << " Please check the config file '" << config_file_ << "' set by 'env_config_path' in context."; | |||
| return false; | |||
| } | |||
| return true; | |||
| } | |||
| auto EnvConfigParser::CheckJsonKeyExist(const nlohmann::json &content, const std::string &setting_key, | |||
| const std::string &key) { | |||
| auto iter = content.find(key); | |||
| if (iter == content.end()) { | |||
| MS_LOG(WARNING) << "Check json failed, '" << key << "' not found in '" << setting_key << "'." | |||
| << " Please check the config file '" << config_file_ << "' set by 'env_config_path' in context."; | |||
| } | |||
| return iter; | |||
| } | |||
| std::string EnvConfigParser::GetIfstreamString(const std::ifstream &ifstream) { | |||
| std::stringstream buffer; | |||
| buffer << ifstream.rdbuf(); | |||
| return buffer.str(); | |||
| } | |||
| void EnvConfigParser::Parse() { | |||
| std::lock_guard<std::mutex> guard(lock_); | |||
| if (already_parsed_) { | |||
| return; | |||
| } | |||
| already_parsed_ = true; | |||
| auto context = MsContext::GetInstance(); | |||
| MS_EXCEPTION_IF_NULL(context); | |||
| auto config_file = context->get_param<std::string>(MS_CTX_ENV_CONFIG_PATH); | |||
| if (config_file.empty()) { | |||
| MS_LOG(INFO) << "Get env config file failed. Please check the 'env_config_path' set in context."; | |||
| return; | |||
| } | |||
| config_file_ = config_file; | |||
| std::ifstream json_file(config_file_); | |||
| if (!json_file.is_open()) { | |||
| MS_LOG(WARNING) << "Env config file:" << config_file_ << " open failed." | |||
| << " Please check the config file '" << config_file_ << "' set by 'env_config_path' in context."; | |||
| return; | |||
| } | |||
| nlohmann::json j; | |||
| try { | |||
| json_file >> j; | |||
| } catch (nlohmann::json::parse_error &e) { | |||
| MS_LOG(WARNING) << "Env config json contents '" << GetIfstreamString(json_file) << "' in config file '" | |||
| << config_file_ << "' set by 'env_config_path' in context."; | |||
| return; | |||
| } | |||
| // convert json to string | |||
| std::stringstream ss; | |||
| ss << j; | |||
| std::string cfg = ss.str(); | |||
| MS_LOG(INFO) << "Env config json:" << cfg; | |||
| ParseRdrSetting(j); | |||
| ConfigToString(); | |||
| } | |||
| void EnvConfigParser::ParseRdrSetting(const nlohmann::json &content) { | |||
| auto rdr_setting = content.find(kRdrSettings); | |||
| if (rdr_setting == content.end()) { | |||
| MS_LOG(WARNING) << "The '" << kRdrSettings << "' not exists. Please check the config file '" << config_file_ | |||
| << "' set by 'env_config_path' in context."; | |||
| return; | |||
| } | |||
| auto rdr_enable = CheckJsonKeyExist(*rdr_setting, kRdrSettings, kEnable); | |||
| auto rdr_path = CheckJsonKeyExist(*rdr_setting, kRdrSettings, kPath); | |||
| ParseRdrEnable(*rdr_enable); | |||
| ParseRdrPath(*rdr_path); | |||
| } | |||
| void EnvConfigParser::ParseRdrPath(const nlohmann::json &content) { | |||
| if (!CheckJsonStringType(content, kRdrSettings, kPath)) { | |||
| MS_LOG(WARNING) << "The RDR path will be a default value: '" << rdr_path_ << "'."; | |||
| return; | |||
| } | |||
| std::string path = content; | |||
| if (!std::all_of(path.begin(), path.end(), | |||
| [](char c) { return ::isalpha(c) || ::isdigit(c) || c == '-' || c == '_' || c == '/'; })) { | |||
| MS_LOG(WARNING) << "The path in " << kRdrSettings | |||
| << " only support alphabets, digit or {'-', '_', '/'}, but got:" << path << "." | |||
| << " Please check the config file '" << config_file_ << "' set by 'env_config_path' in context."; | |||
| return; | |||
| } | |||
| if (path.empty()) { | |||
| MS_LOG(WARNING) << "The path in " << kRdrSettings << " is empty." | |||
| << " Please check the config file '" << config_file_ << "' set by 'env_config_path' in context."; | |||
| return; | |||
| } | |||
| if (path[0] != '/') { | |||
| MS_LOG(WARNING) << "The path in " << kRdrSettings << " only support absolute path and should start with '/'." | |||
| << " Please check the config file '" << config_file_ << "' set by 'env_config_path' in context."; | |||
| return; | |||
| } | |||
| if (path.back() != '/') { | |||
| path += '/'; | |||
| } | |||
| rdr_path_ = path; | |||
| } | |||
| void EnvConfigParser::ParseRdrEnable(const nlohmann::json &content) { | |||
| if (!content.is_boolean()) { | |||
| MS_LOG(WARNING) << "Json Parse Failed. 'enable' in " << kRdrSettings << " should be boolean." | |||
| << " Please check the config file '" << config_file_ << "' set by 'env_config_path' in context."; | |||
| rdr_enabled_ = false; | |||
| return; | |||
| } | |||
| rdr_enabled_ = content; | |||
| } | |||
| void EnvConfigParser::ConfigToString() { | |||
| std::string cur_config; | |||
| cur_config.append("After parsed, rdr path: "); | |||
| cur_config.append(rdr_path_); | |||
| cur_config.append(", rdr_enable: "); | |||
| cur_config.append(std::to_string(rdr_enabled_)); | |||
| MS_LOG(INFO) << cur_config; | |||
| } | |||
| } // namespace mindspore | |||
| @@ -0,0 +1,60 @@ | |||
| /** | |||
| * Copyright 2021 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_CCSRC_DEBUG_ENV_CONFIG_PARSER_H_ | |||
| #define MINDSPORE_CCSRC_DEBUG_ENV_CONFIG_PARSER_H_ | |||
| #include <string> | |||
| #include <map> | |||
| #include <set> | |||
| #include <mutex> | |||
| #include "nlohmann/json.hpp" | |||
| #include "utils/ms_utils.h" | |||
| namespace mindspore { | |||
| class EnvConfigParser { | |||
| public: | |||
| static EnvConfigParser &GetInstance() { | |||
| static EnvConfigParser instance; | |||
| return instance; | |||
| } | |||
| void Parse(); | |||
| bool rdr_enabled() const { return rdr_enabled_; } | |||
| std::string rdr_path() const { return rdr_path_; } | |||
| private: | |||
| EnvConfigParser() {} | |||
| ~EnvConfigParser() {} | |||
| std::mutex lock_; | |||
| std::string config_file_{""}; | |||
| bool already_parsed_{false}; | |||
| bool rdr_enabled_{false}; | |||
| std::string rdr_path_{"./rdr/"}; | |||
| std::string GetIfstreamString(const std::ifstream &ifstream); | |||
| void ParseRdrSetting(const nlohmann::json &content); | |||
| bool CheckJsonStringType(const nlohmann::json &content, const std::string &setting_key, const std::string &key); | |||
| auto CheckJsonKeyExist(const nlohmann::json &content, const std::string &setting_key, const std::string &key); | |||
| void ParseRdrPath(const nlohmann::json &content); | |||
| void ParseRdrEnable(const nlohmann::json &content); | |||
| void ConfigToString(); | |||
| }; | |||
| } // namespace mindspore | |||
| #endif // MINDSPORE_CCSRC_DEBUG_ENV_CONFIG_PARSER_H_ | |||
| @@ -13,18 +13,23 @@ | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_BASE_RECORDER_H_ | |||
| #define MINDSPORE_BASE_RECORDER_H_ | |||
| #ifndef MINDSPORE_CCSRC_DEBUG_RDR_BASE_RECORDER_H_ | |||
| #define MINDSPORE_CCSRC_DEBUG_RDR_BASE_RECORDER_H_ | |||
| #include <memory> | |||
| #include <string> | |||
| #include "debug/env_config_parser.h" | |||
| namespace mindspore { | |||
| class BaseRecorder { | |||
| public: | |||
| BaseRecorder() : module_(""), tag_(""), directory_("./rdr/"), filename_(""), timestamp_("") {} | |||
| BaseRecorder() : module_(""), tag_(""), directory_(""), filename_(""), timestamp_("") {} | |||
| BaseRecorder(const std::string &module, const std::string &tag) | |||
| : module_(module), tag_(tag), directory_("./rdr/"), filename_(""), timestamp_("") {} | |||
| : module_(module), tag_(tag), directory_(""), filename_(""), timestamp_("") { | |||
| auto &config_parser_ptr = mindspore::EnvConfigParser::GetInstance(); | |||
| config_parser_ptr.Parse(); | |||
| directory_ = config_parser_ptr.rdr_path(); | |||
| } | |||
| ~BaseRecorder() {} | |||
| std::string GetModule() { return module_; } | |||
| @@ -44,4 +49,4 @@ class BaseRecorder { | |||
| using BaseRecorderPtr = std::shared_ptr<BaseRecorder>; | |||
| } // namespace mindspore | |||
| #endif // MINDSPORE_BASE_RECORDER_H_ | |||
| #endif // MINDSPORE_CCSRC_DEBUG_RDR_BASE_RECORDER_H_ | |||
| @@ -13,13 +13,14 @@ | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_GRAPH_RECORDER_H_ | |||
| #define MINDSPORE_GRAPH_RECORDER_H_ | |||
| #ifndef MINDSPORE_CCSRC_DEBUG_RDR_GRAPH_RECORDER_H_ | |||
| #define MINDSPORE_CCSRC_DEBUG_RDR_GRAPH_RECORDER_H_ | |||
| #include <vector> | |||
| #include <string> | |||
| #include <memory> | |||
| #include "debug/anf_ir_utils.h" | |||
| #include "debug/rdr/base_recorder.h" | |||
| namespace mindspore { | |||
| class FuncGraph; | |||
| @@ -44,4 +45,4 @@ class GraphRecorder : public BaseRecorder { | |||
| }; | |||
| using GraphRecorderPtr = std::shared_ptr<GraphRecorder>; | |||
| } // namespace mindspore | |||
| #endif // MINDSPORE_GRAPH_RECORDER_H_ | |||
| #endif // MINDSPORE_CCSRC_DEBUG_RDR_GRAPH_RECORDER_H_ | |||
| @@ -16,6 +16,7 @@ | |||
| #include "debug/rdr/recorder_manager.h" | |||
| #include <utility> | |||
| #include "debug/rdr/base_recorder.h" | |||
| #include "debug/env_config_parser.h" | |||
| #include "mindspore/core/base/base.h" | |||
| #include "mindspore/core/ir/func_graph.h" | |||
| @@ -32,6 +33,13 @@ bool RecorderManager::RecordObject(const BaseRecorderPtr &recorder) { | |||
| } | |||
| void RecorderManager::TriggerAll() { | |||
| auto &config_parser_ptr = mindspore::EnvConfigParser::GetInstance(); | |||
| config_parser_ptr.Parse(); | |||
| if (!config_parser_ptr.rdr_enabled()) { | |||
| MS_LOG(INFO) << "RDR is not enable."; | |||
| return; | |||
| } | |||
| bool trigger = false; | |||
| std::lock_guard<std::mutex> lock(mtx_); | |||
| for (auto iter = recorder_container_.begin(); iter != recorder_container_.end(); ++iter) { | |||
| @@ -1,5 +1,5 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * Copyright 2020-2021 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| @@ -71,7 +71,7 @@ py::object MsCtxGetParameter(const std::shared_ptr<MsContext> &ctx, MsCtxParam p | |||
| } | |||
| } // namespace | |||
| // Note: exported python enum variables begining with '_' are for internal use | |||
| // Note: exported python enum variables beginning with '_' are for internal use | |||
| REGISTER_PYBIND_DEFINE(MsContextPy, ([](const py::module *m) { | |||
| (void)py::enum_<MsCtxParam>(*m, "ms_ctx_param", py::arithmetic()) | |||
| .value("enable_auto_mixed_precision", MsCtxParam::MS_CTX_ENABLE_AUTO_MIXED_PRECISION) | |||
| @@ -95,11 +95,12 @@ REGISTER_PYBIND_DEFINE(MsContextPy, ([](const py::module *m) { | |||
| .value("variable_memory_max_size", MsCtxParam::MS_CTX_VARIABLE_MEMORY_MAX_SIZE) | |||
| .value("device_id", MsCtxParam::MS_CTX_DEVICE_ID) | |||
| .value("max_call_depth", MsCtxParam::MS_CTX_MAX_CALL_DEPTH) | |||
| .value("profiling_dir_path", MsCtxParam::MS_CTX_PROFILING_DIR_PATH); | |||
| .value("profiling_dir_path", MsCtxParam::MS_CTX_PROFILING_DIR_PATH) | |||
| .value("env_config_path", MsCtxParam::MS_CTX_ENV_CONFIG_PATH); | |||
| (void)py::class_<mindspore::MsContext, std::shared_ptr<mindspore::MsContext>>(*m, "MSContext") | |||
| .def_static("get_instance", &mindspore::MsContext::GetInstance, "Get ms context instance.") | |||
| .def("get_param", &mindspore::MsCtxGetParameter, "Get value of specified paramter.") | |||
| .def("set_param", &mindspore::MsCtxSetParameter, "Set value for specified paramter.") | |||
| .def("get_param", &mindspore::MsCtxGetParameter, "Get value of specified parameter.") | |||
| .def("set_param", &mindspore::MsCtxSetParameter, "Set value for specified parameter.") | |||
| .def("get_backend_policy", &mindspore::MsContext::backend_policy, "Get backend policy.") | |||
| .def("set_backend_policy", &mindspore::MsContext::set_backend_policy, "Set backend policy."); | |||
| })); | |||
| @@ -1,4 +1,4 @@ | |||
| # Copyright 2020 Huawei Technologies Co., Ltd | |||
| # Copyright 2020-2021 Huawei Technologies Co., Ltd | |||
| # | |||
| # Licensed under the Apache License, Version 2.0 (the "License"); | |||
| # you may not use this file except in compliance with the License. | |||
| @@ -254,6 +254,15 @@ class _Context: | |||
| full_file_name = print_file_path | |||
| self.set_param(ms_ctx_param.print_file_path, full_file_name) | |||
| def set_env_config_path(self, env_config_path): | |||
| """Check and set env_config_path.""" | |||
| env_config_path = os.path.realpath(env_config_path) | |||
| if not os.path.isfile(env_config_path): | |||
| raise ValueError("'env_config_path' should be a json file.") | |||
| if not os.path.exists(env_config_path): | |||
| raise ValueError("The json file set by 'env_config_path' is not exist.") | |||
| self.set_param(ms_ctx_param.env_config_path, env_config_path) | |||
| setters = { | |||
| 'mode': set_mode, | |||
| 'save_graphs_path': set_save_graphs_path, | |||
| @@ -263,7 +272,8 @@ class _Context: | |||
| 'profiling_options': set_profiling_options, | |||
| 'variable_memory_max_size': set_variable_memory_max_size, | |||
| 'max_device_memory': set_max_device_memory, | |||
| 'print_file_path': set_print_file_path | |||
| 'print_file_path': set_print_file_path, | |||
| 'env_config_path': set_env_config_path | |||
| } | |||
| @property | |||
| @@ -376,7 +386,7 @@ def set_auto_parallel_context(**kwargs): | |||
| parameter_broadcast (bool): Whether to broadcast parameters before training. Before training, in order to have | |||
| the same network initialization parameter values for all devices, broadcast the parameters | |||
| on device 0 to other devices. Parameter broadcasting in different parallel modes is different, | |||
| data_parallel mode, all parameters are broadcast except for the prameter whose attribute | |||
| data_parallel mode, all parameters are broadcast except for the parameter whose attribute | |||
| layerwise_parallel is True. Hybrid_parallel, semi_auto_parallel and auto_parallel mode, the | |||
| segmented parameters do not participate in broadcasting. Default: False. | |||
| strategy_ckpt_load_file (str): The path to load parallel strategy checkpoint. Default: '' | |||
| @@ -480,7 +490,7 @@ def _check_target_specific_cfgs(device, arg_key): | |||
| save_dump_path=str, enable_reduce_precision=bool, variable_memory_max_size=str, | |||
| enable_profiling=bool, profiling_options=str, enable_auto_mixed_precision=bool, | |||
| enable_graph_kernel=bool, check_bprop=bool, max_device_memory=str, print_file_path=str, | |||
| enable_sparse=bool, max_call_depth=int) | |||
| enable_sparse=bool, max_call_depth=int, env_config_path=str) | |||
| def set_context(**kwargs): | |||
| """ | |||
| Sets context for running environment. | |||
| @@ -497,10 +507,10 @@ def set_context(**kwargs): | |||
| Note: | |||
| Attribute name is required for setting attributes. | |||
| The mode is not recommended to be changed after net was initilized because the implementations of some | |||
| The mode is not recommended to be changed after net was initialized because the implementations of some | |||
| operations are different in graph mode and pynative mode. Default: PYNATIVE_MODE. | |||
| Some configurations are device specific, see the bellow table for details: | |||
| Some configurations are device specific, see the below table for details: | |||
| =========================== =========================== ================= | |||
| Common(CPU/GPU/Ascend) Ascend GPU | |||
| @@ -514,6 +524,7 @@ def set_context(**kwargs): | |||
| reserve_class_name_in_scope profiling_options | |||
| save_graphs variable_memory_max_size | |||
| save_graphs_path | |||
| env_config_path | |||
| =========================== =========================== ================= | |||
| Args: | |||
| @@ -543,10 +554,9 @@ def set_context(**kwargs): | |||
| the Ascend 910 processor, and analyze the information of beginning and ending of the task. | |||
| - op_trace: collect single operator performance data. | |||
| The profiling can choose the combination of `training_trace`, `task_trace`, | |||
| `training_trace` and `task_trace` combination, and separated by colons; | |||
| a single operator can choose `op_trace`, `op_trace` cannot be combined with | |||
| `training_trace` and `task_trace`. Default: "training_trace". | |||
| The profiling can choose the combination of `training_trace`, `task_trace`, `training_trace` and | |||
| `task_trace` combination, and separated by colons; a single operator can choose `op_trace`, `op_trace` | |||
| cannot be combined with `training_trace` and `task_trace`. Default: "training_trace". | |||
| check_bprop (bool): Whether to check bprop. Default: False. | |||
| max_device_memory (str): Sets the maximum memory available for devices. | |||
| Currently, it is only supported on GPU. The format is "xxGB". Default: "1024GB". | |||
| @@ -554,7 +564,8 @@ def set_context(**kwargs): | |||
| a file by default, and turns off printing to the screen. If the file already exists, add a timestamp | |||
| suffix to the file. Default: ''. | |||
| enable_sparse (bool): Whether to enable sparsity feature. Default: False. | |||
| max_call_depth(int): Specify the maximum depth of function call. Default: 1000. | |||
| max_call_depth (int): Specify the maximum depth of function call. Default: 1000. | |||
| env_config_path (str): Config path for DFX. | |||
| Raises: | |||
| ValueError: If input key is not an attribute in context. | |||
| @@ -576,6 +587,7 @@ def set_context(**kwargs): | |||
| >>> context.set_context(max_device_memory="3.5GB") | |||
| >>> context.set_context(print_file_path="print.pb") | |||
| >>> context.set_context(max_call_depth=80) | |||
| >>> context.set_context(env_config_path="./env_config.json") | |||
| """ | |||
| ctx = _context() | |||
| # set device target first | |||
| @@ -595,7 +607,7 @@ def set_context(**kwargs): | |||
| if key in ctx.setters: | |||
| ctx.setters[key](ctx, value) | |||
| continue | |||
| # enum variables begining with '_' are for internal use | |||
| # enum variables beginning with '_' are for internal use | |||
| if key in ms_ctx_param.__members__ and key[0] != '_': | |||
| ctx.set_param(ms_ctx_param.__members__[key], value) | |||
| continue | |||
| @@ -620,7 +632,7 @@ def get_context(attr_key): | |||
| _ = _check_target_specific_cfgs(device, attr_key) | |||
| if hasattr(ctx, attr_key): | |||
| return getattr(ctx, attr_key) | |||
| # enum variables begining with '_' are for internal use | |||
| # enum variables beginning with '_' are for internal use | |||
| if attr_key in ms_ctx_param.__members__ and attr_key[0] != '_': | |||
| return ctx.get_param(ms_ctx_param.__members__[attr_key]) | |||
| raise ValueError("Get context keyword %s is not recognized!" % attr_key) | |||
| @@ -1,5 +1,5 @@ | |||
| /** | |||
| * Copyright 2019 Huawei Technologies Co., Ltd | |||
| * Copyright 2019-2021 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| @@ -37,6 +37,7 @@ MsContext::MsContext(const std::string &policy, const std::string &target) { | |||
| set_param<std::string>(MS_CTX_PYTHON_EXE_PATH, "python"); | |||
| set_param<bool>(MS_CTX_ENABLE_DUMP, false); | |||
| set_param<std::string>(MS_CTX_SAVE_DUMP_PATH, "."); | |||
| set_param<std::string>(MS_CTX_ENV_CONFIG_PATH, ""); | |||
| set_param<uint32_t>(MS_CTX_TSD_REF, 0); | |||
| set_param<uint32_t>(MS_CTX_GE_REF, 0); | |||
| set_param<bool>(MS_CTX_IS_MULTI_GRAPH_SINK, false); | |||
| @@ -1,5 +1,5 @@ | |||
| /** | |||
| * Copyright 2019 Huawei Technologies Co., Ltd | |||
| * Copyright 2019-2021 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| @@ -51,7 +51,7 @@ const float kDefaultMaxDeviceMemory = 1024; | |||
| // enum definition for MindSpore Context Parameter | |||
| enum MsCtxParam : unsigned { | |||
| // paramater of type bool | |||
| // parameter of type bool | |||
| MS_CTX_TYPE_BOOL_BEGIN, | |||
| MS_CTX_ENABLE_AUTO_MIXED_PRECISION = MS_CTX_TYPE_BOOL_BEGIN, | |||
| MS_CTX_CHECK_BPROP_FLAG, | |||
| @@ -76,12 +76,12 @@ enum MsCtxParam : unsigned { | |||
| MS_CTX_ENABLE_PARALLEL_SPLIT, | |||
| MS_CTX_TYPE_BOOL_END, | |||
| // paramater of type int | |||
| // parameter of type int | |||
| MS_CTX_TYPE_INT_BEGIN = MS_CTX_TYPE_BOOL_END, | |||
| MS_CTX_EXECUTION_MODE = MS_CTX_TYPE_INT_BEGIN, | |||
| MS_CTX_TYPE_INT_END, | |||
| // paramater of type uint32 | |||
| // parameter of type uint32 | |||
| MS_CTX_TYPE_UINT32_BEGIN = MS_CTX_TYPE_INT_END, | |||
| MS_CTX_DEVICE_ID = MS_CTX_TYPE_UINT32_BEGIN, | |||
| MS_CTX_GE_REF, | |||
| @@ -89,12 +89,12 @@ enum MsCtxParam : unsigned { | |||
| MS_CTX_TSD_REF, | |||
| MS_CTX_TYPE_UINT32_END, | |||
| // paramater of type float | |||
| // parameter of type float | |||
| MS_CTX_TYPE_FLOAT_BEGIN = MS_CTX_TYPE_UINT32_END, | |||
| MS_CTX_MAX_DEVICE_MEMORY = MS_CTX_TYPE_FLOAT_BEGIN, | |||
| MS_CTX_TYPE_FLOAT_END, | |||
| // paramater of type string | |||
| // parameter of type string | |||
| MS_CTX_TYPE_STRING_BEGIN = MS_CTX_TYPE_FLOAT_END, | |||
| MS_CTX_DEVICE_TARGET = MS_CTX_TYPE_STRING_BEGIN, | |||
| MS_CTX_GRAPH_MEMORY_MAX_SIZE, | |||
| @@ -105,6 +105,7 @@ enum MsCtxParam : unsigned { | |||
| MS_CTX_VARIABLE_MEMORY_MAX_SIZE, | |||
| MS_CTX_PYTHON_EXE_PATH, | |||
| MS_CTX_PROFILING_DIR_PATH, | |||
| MS_CTX_ENV_CONFIG_PATH, | |||
| MS_CTX_TYPE_STRING_END, | |||
| // parameter numbers of each type | |||