!3484 Add json config checking

Merge pull request !3484 from caifubi/data-dump
This commit is contained in:
mindspore-ci-bot 2020-07-27 19:37:30 +08:00 committed by Gitee
commit a9f482f3a1
2 changed files with 19 additions and 1 deletions

View File

@ -155,12 +155,16 @@ bool DataDumpParser::ParseDumpSetting(const nlohmann::json &dump_settings) {
auto net_name = dump_settings.at(kConfigNetName);
auto iteration = dump_settings.at(kConfigIteration);
auto kernels = dump_settings.at(kConfigKernels);
if (!(mode.is_number() && net_name.is_string() && iteration.is_number() && kernels.is_array())) {
if (!(mode.is_number_unsigned() && op_debug_mode.is_number_unsigned() && net_name.is_string() &&
iteration.is_number_unsigned() && kernels.is_array())) {
MS_LOG(ERROR) << "[DataDump] Element's type in Dump config json is invalid.";
enable_ = false;
return false;
}
CheckDumpMode(mode);
CheckOpDebugMode(op_debug_mode);
enable_ = true;
auto context_ptr = MsContext::GetInstance();
MS_EXCEPTION_IF_NULL(context_ptr);
@ -193,4 +197,16 @@ void DataDumpParser::PrintUnusedKernel() {
}
}
}
void DataDumpParser::CheckDumpMode(uint32_t dump_mode) const {
if (dump_mode != 0 && dump_mode != 1) {
MS_LOG(EXCEPTION) << "[DataDump] dump_mode in config json should be 0 or 1";
}
}
void DataDumpParser::CheckOpDebugMode(uint32_t op_debug_mode) const {
if (op_debug_mode < 0 || op_debug_mode > 3) {
MS_LOG(EXCEPTION) << "[DataDump] op_debug_mode in config json file should be [0-3]";
}
}
} // namespace mindspore

View File

@ -51,6 +51,8 @@ class DataDumpParser {
void ResetParam();
bool IsConfigExist(const nlohmann::json &dump_settings) const;
bool ParseDumpSetting(const nlohmann::json &dump_settings);
void CheckDumpMode(uint32_t dump_mode) const;
void CheckOpDebugMode(uint32_t op_debug_mode) const;
std::mutex lock_;
bool enable_{false};