Browse Source

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.
tags/v1.2.0-rc1
luopengting 4 years ago
parent
commit
bd7e5e9d37
5 changed files with 18 additions and 5 deletions
  1. +4
    -4
      mindspore/ccsrc/debug/common.cc
  2. +2
    -1
      mindspore/ccsrc/pybind_api/utils/ms_context_py.cc
  3. +3
    -0
      mindspore/context.py
  4. +8
    -0
      mindspore/core/utils/ms_context.cc
  5. +1
    -0
      mindspore/core/utils/ms_context.h

+ 4
- 4
mindspore/ccsrc/debug/common.cc View File

@@ -142,7 +142,7 @@ std::optional<std::string> 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;
}


+ 2
- 1
mindspore/ccsrc/pybind_api/utils/ms_context_py.cc View File

@@ -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

+ 3
- 0
mindspore/context.py View File

@@ -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)


+ 8
- 0
mindspore/core/utils/ms_context.cc View File

@@ -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

+ 1
- 0
mindspore/core/utils/ms_context.h View File

@@ -127,6 +127,7 @@ class MsContext {
using DeviceTypeSeter = std::function<void(std::shared_ptr<MsContext> &)>;
static std::shared_ptr<MsContext> GetInstance();

bool enable_dump_ir() const;
std::string backend_policy() const;
bool set_backend_policy(const std::string &policy);



Loading…
Cancel
Save