Browse Source

Add json checking

tags/v0.7.0-beta
caifubi 5 years ago
parent
commit
77a5425e2e
2 changed files with 19 additions and 1 deletions
  1. +17
    -1
      mindspore/ccsrc/debug/data_dump_parser.cc
  2. +2
    -0
      mindspore/ccsrc/debug/data_dump_parser.h

+ 17
- 1
mindspore/ccsrc/debug/data_dump_parser.cc View File

@@ -155,12 +155,16 @@ bool DataDumpParser::ParseDumpSetting(const nlohmann::json &dump_settings) {
auto net_name = dump_settings.at(kConfigNetName); auto net_name = dump_settings.at(kConfigNetName);
auto iteration = dump_settings.at(kConfigIteration); auto iteration = dump_settings.at(kConfigIteration);
auto kernels = dump_settings.at(kConfigKernels); 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."; MS_LOG(ERROR) << "[DataDump] Element's type in Dump config json is invalid.";
enable_ = false; enable_ = false;
return false; return false;
} }


CheckDumpMode(mode);
CheckOpDebugMode(op_debug_mode);

enable_ = true; enable_ = true;
auto context_ptr = MsContext::GetInstance(); auto context_ptr = MsContext::GetInstance();
MS_EXCEPTION_IF_NULL(context_ptr); 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 } // namespace mindspore

+ 2
- 0
mindspore/ccsrc/debug/data_dump_parser.h View File

@@ -51,6 +51,8 @@ class DataDumpParser {
void ResetParam(); void ResetParam();
bool IsConfigExist(const nlohmann::json &dump_settings) const; bool IsConfigExist(const nlohmann::json &dump_settings) const;
bool ParseDumpSetting(const nlohmann::json &dump_settings); 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_; std::mutex lock_;
bool enable_{false}; bool enable_{false};


Loading…
Cancel
Save