forked from mindspore-Ecosystem/mindspore
!12299 check ENABLE_DUMP_IR if user set env_config_path
From: @luopengting Reviewed-by: @yelihua,@ouwenchang Signed-off-by: @ouwenchang
This commit is contained in:
commit
1252250d7e
|
@ -142,7 +142,7 @@ std::optional<std::string> Common::GetConfigFile(const std::string &env) {
|
||||||
}
|
}
|
||||||
auto suffix = dump_config_file.substr(point_pos + 1);
|
auto suffix = dump_config_file.substr(point_pos + 1);
|
||||||
if (suffix != "json") {
|
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;
|
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(),
|
if (!std::all_of(path.begin(), path.end(),
|
||||||
[](char c) { return ::isalpha(c) || ::isdigit(c) || c == '-' || c == '_' || c == '/'; })) {
|
[](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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path[0] != '/') {
|
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;
|
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(),
|
if (!std::all_of(filename.begin(), filename.end(),
|
||||||
[](char c) { return ::isalpha(c) || ::isdigit(c) || c == '-' || c == '_' || c == '.'; })) {
|
[](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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,6 +101,7 @@ REGISTER_PYBIND_DEFINE(MsContextPy, ([](const py::module *m) {
|
||||||
.def("get_param", &mindspore::MsCtxGetParameter, "Get value of specified parameter.")
|
.def("get_param", &mindspore::MsCtxGetParameter, "Get value of specified parameter.")
|
||||||
.def("set_param", &mindspore::MsCtxSetParameter, "Set value for specified parameter.")
|
.def("set_param", &mindspore::MsCtxSetParameter, "Set value for specified parameter.")
|
||||||
.def("get_backend_policy", &mindspore::MsContext::backend_policy, "Get backend policy.")
|
.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
|
} // namespace mindspore
|
||||||
|
|
|
@ -257,6 +257,9 @@ class _Context:
|
||||||
|
|
||||||
def set_env_config_path(self, env_config_path):
|
def set_env_config_path(self, env_config_path):
|
||||||
"""Check and set 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)
|
env_config_path = os.path.realpath(env_config_path)
|
||||||
if not os.path.isfile(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)
|
raise ValueError("The %r set by 'env_config_path' should be an existing json file." % env_config_path)
|
||||||
|
|
|
@ -107,4 +107,12 @@ std::string MsContext::backend_policy() const {
|
||||||
}
|
}
|
||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MsContext::enable_dump_ir() const {
|
||||||
|
#ifdef ENABLE_DUMP_IR
|
||||||
|
return true;
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
} // namespace mindspore
|
} // namespace mindspore
|
||||||
|
|
|
@ -127,6 +127,7 @@ class MsContext {
|
||||||
using DeviceTypeSeter = std::function<void(std::shared_ptr<MsContext> &)>;
|
using DeviceTypeSeter = std::function<void(std::shared_ptr<MsContext> &)>;
|
||||||
static std::shared_ptr<MsContext> GetInstance();
|
static std::shared_ptr<MsContext> GetInstance();
|
||||||
|
|
||||||
|
bool enable_dump_ir() const;
|
||||||
std::string backend_policy() const;
|
std::string backend_policy() const;
|
||||||
bool set_backend_policy(const std::string &policy);
|
bool set_backend_policy(const std::string &policy);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue