From bd7e5e9d3775ef9675d9cb0763c11e30579dbef2 Mon Sep 17 00:00:00 2001 From: luopengting Date: Tue, 9 Feb 2021 09:58:37 +0800 Subject: [PATCH] check ENABLE_DUMP_IR if user set env_config_path If the ENABLE_DUMP_IR is off, the program will raise ValueError to remind user to turn on ENABLE_DUMP_IR. --- mindspore/ccsrc/debug/common.cc | 8 ++++---- mindspore/ccsrc/pybind_api/utils/ms_context_py.cc | 3 ++- mindspore/context.py | 3 +++ mindspore/core/utils/ms_context.cc | 8 ++++++++ mindspore/core/utils/ms_context.h | 1 + 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/mindspore/ccsrc/debug/common.cc b/mindspore/ccsrc/debug/common.cc index 2b1a9687ea4..a3751c3f18d 100644 --- a/mindspore/ccsrc/debug/common.cc +++ b/mindspore/ccsrc/debug/common.cc @@ -142,7 +142,7 @@ std::optional Common::GetConfigFile(const std::string &env) { } auto suffix = dump_config_file.substr(point_pos + 1); if (suffix != "json") { - MS_LOG(EXCEPTION) << "[DataDump] dump config file suffix only support json! But got:." << suffix; + MS_LOG(EXCEPTION) << "[DataDump] dump config file suffix only supports json! But got:." << suffix; } return dump_config_file; } @@ -233,12 +233,12 @@ bool Common::IsPathValid(const std::string &path, const int &length_limit, const if (!std::all_of(path.begin(), path.end(), [](char c) { return ::isalpha(c) || ::isdigit(c) || c == '-' || c == '_' || c == '/'; })) { - MS_LOG(WARNING) << err_msg << "The path only support alphabets, digit or {'-', '_', '/'}, but got:" << path << "."; + MS_LOG(WARNING) << err_msg << "The path only supports alphabets, digit or {'-', '_', '/'}, but got:" << path << "."; return false; } if (path[0] != '/') { - MS_LOG(WARNING) << err_msg << "The path only support absolute path and should start with '/'."; + MS_LOG(WARNING) << err_msg << "The path only supports absolute path and should start with '/'."; return false; } @@ -265,7 +265,7 @@ bool Common::IsFilenameValid(const std::string &filename, const int &length_limi if (!std::all_of(filename.begin(), filename.end(), [](char c) { return ::isalpha(c) || ::isdigit(c) || c == '-' || c == '_' || c == '.'; })) { - MS_LOG(WARNING) << err_msg << "The filename only support alphabets, digit or {'-', '_', '.'}, but got:" << filename + MS_LOG(WARNING) << err_msg << "The filename only supports alphabets, digit or {'-', '_', '.'}, but got:" << filename << "."; return false; } diff --git a/mindspore/ccsrc/pybind_api/utils/ms_context_py.cc b/mindspore/ccsrc/pybind_api/utils/ms_context_py.cc index 821b58958eb..6554db29534 100644 --- a/mindspore/ccsrc/pybind_api/utils/ms_context_py.cc +++ b/mindspore/ccsrc/pybind_api/utils/ms_context_py.cc @@ -101,6 +101,7 @@ REGISTER_PYBIND_DEFINE(MsContextPy, ([](const py::module *m) { .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."); + .def("set_backend_policy", &mindspore::MsContext::set_backend_policy, "Set backend policy.") + .def("enable_dump_ir", &mindspore::MsContext::enable_dump_ir, "Get the ENABLE_DUMP_IR."); })); } // namespace mindspore diff --git a/mindspore/context.py b/mindspore/context.py index 33818071c9a..09caacf38cd 100644 --- a/mindspore/context.py +++ b/mindspore/context.py @@ -257,6 +257,9 @@ class _Context: def set_env_config_path(self, env_config_path): """Check and set env_config_path.""" + if not self._context_handle.enable_dump_ir(): + raise ValueError("The 'env_config_path' is not supported, please turn on ENABLE_DUMP_IR " + "and recompile source to enable it.") env_config_path = os.path.realpath(env_config_path) if not os.path.isfile(env_config_path): raise ValueError("The %r set by 'env_config_path' should be an existing json file." % env_config_path) diff --git a/mindspore/core/utils/ms_context.cc b/mindspore/core/utils/ms_context.cc index 7d3afd23105..5ea13730937 100644 --- a/mindspore/core/utils/ms_context.cc +++ b/mindspore/core/utils/ms_context.cc @@ -107,4 +107,12 @@ std::string MsContext::backend_policy() const { } return "unknown"; } + +bool MsContext::enable_dump_ir() const { +#ifdef ENABLE_DUMP_IR + return true; +#else + return false; +#endif +} } // namespace mindspore diff --git a/mindspore/core/utils/ms_context.h b/mindspore/core/utils/ms_context.h index 3beeabeb922..683394efea1 100644 --- a/mindspore/core/utils/ms_context.h +++ b/mindspore/core/utils/ms_context.h @@ -127,6 +127,7 @@ class MsContext { using DeviceTypeSeter = std::function &)>; static std::shared_ptr GetInstance(); + bool enable_dump_ir() const; std::string backend_policy() const; bool set_backend_policy(const std::string &policy);