diff --git a/mindspore/ccsrc/debug/common.cc b/mindspore/ccsrc/debug/common.cc index 6caf7e2c393143aa877dbd39712974e929c57236..931e6d4b8585679faa8aa7a47806d2f6e910c2f9 100644 --- a/mindspore/ccsrc/debug/common.cc +++ b/mindspore/ccsrc/debug/common.cc @@ -120,6 +120,10 @@ std::optional Common::GetConfigFile(const std::string &env) { MS_LOG(ERROR) << dump_config_file << " not exist."; return {}; } + auto suffix = dump_config_file.substr(dump_config_file.find_last_of('.') + 1); + if (suffix != "json") { + MS_LOG(EXCEPTION) << "[DataDump] dump config file suffix only support json! But got:." << suffix; + } return dump_config_file; } } // namespace mindspore diff --git a/mindspore/ccsrc/debug/data_dump_parser.cc b/mindspore/ccsrc/debug/data_dump_parser.cc index 55c66e055ba9ed9a2093c712919e231ccf7885de..0f8e1bb598e33d0c0f0913030f6961c7765aab75 100644 --- a/mindspore/ccsrc/debug/data_dump_parser.cc +++ b/mindspore/ccsrc/debug/data_dump_parser.cc @@ -29,7 +29,7 @@ void DataDumpParser::ResetParam() { net_name_.clear(); dump_mode_ = 0; dump_step_ = 0; - kernel_set_.clear(); + kernel_map_.clear(); } bool DataDumpParser::DumpEnabled() const { @@ -60,9 +60,18 @@ std::optional DataDumpParser::GetDumpPath() const { return {}; } std::string dump_path_str(dump_path); + if (!std::all_of(dump_path_str.begin(), dump_path_str.end(), ::isalpha)) { + MS_LOG(EXCEPTION) << "[DataDump] dump path only support alphas, but got:" << dump_path_str; + } return dump_path_str; } +std::string GetIfstreamString(const std::ifstream &ifstream) { + std::stringstream buffer; + buffer << ifstream.rdbuf(); + return buffer.str(); +} + void DataDumpParser::ParseDumpConfig() { std::lock_guard guard(lock_); MS_LOG(INFO) << "[DataDump] parse start"; @@ -84,7 +93,12 @@ void DataDumpParser::ParseDumpConfig() { } nlohmann::json j; - json_file >> j; + try { + json_file >> j; + } catch (nlohmann::json::parse_error &e) { + MS_LOG(ERROR) << "[DataDump] json contents:" << GetIfstreamString(json_file); + MS_LOG(EXCEPTION) << "[DataDump] parse json failed, error:" << e.what(); + } if (j.find("DumpSettings") == j.end()) { MS_LOG(EXCEPTION) << "[DataDump] DumpSettings is not exist."; } @@ -111,8 +125,8 @@ bool DataDumpParser::NeedDump(const std::string &op_full_name) const { if (dump_mode_ == 0) { return true; } - auto iter = kernel_set_.find(op_full_name); - return iter != kernel_set_.end(); + auto iter = kernel_map_.find(op_full_name); + return iter != kernel_map_.end(); } bool DataDumpParser::IsConfigExist(const nlohmann::json &dump_settings) const { @@ -145,8 +159,25 @@ bool DataDumpParser::ParseDumpSetting(const nlohmann::json &dump_settings) { auto kernel_str = kernel.dump(); kernel_str.erase(std::remove(kernel_str.begin(), kernel_str.end(), '\"'), kernel_str.end()); MS_LOG(INFO) << "[DataDump] Need dump kernel:" << kernel_str; - kernel_set_.insert(kernel_str); + kernel_map_.insert({kernel_str, 0}); } return true; } + +void DataDumpParser::MatchKernel(const std::string &kernel_name) { + auto iter = kernel_map_.find(kernel_name); + if (iter == kernel_map_.end()) { + return; + } + iter->second = iter->second + 1; + MS_LOG(INFO) << "Match dump kernel:" << iter->first << " match times:" << iter->second; +} + +void DataDumpParser::PrintUnusedKernel() { + for (const auto &iter : kernel_map_) { + if (iter.second == 0) { + MS_LOG(WARNING) << "[DataDump] Unused Kernel in json:" << iter.first; + } + } +} } // namespace mindspore diff --git a/mindspore/ccsrc/debug/data_dump_parser.h b/mindspore/ccsrc/debug/data_dump_parser.h index 751c61dd1a183698ee504f4c47ca1c44ab877ed2..535ef4f6150d521415b365c0663eade24770cc6b 100644 --- a/mindspore/ccsrc/debug/data_dump_parser.h +++ b/mindspore/ccsrc/debug/data_dump_parser.h @@ -18,7 +18,7 @@ #define MINDSPORE_MINDSPORE_CCSRC_DEBUG_ASYNC_DUMP_JSON_PARE_H_ #include -#include +#include #include #include #include "nlohmann/json.hpp" @@ -39,7 +39,8 @@ class DataDumpParser { const std::string &net_name() const { return net_name_; } uint32_t dump_mode() const { return dump_mode_; } uint32_t dump_step() const { return dump_step_; } - const std::set &kernel_set() const { return kernel_set_; } + void MatchKernel(const std::string &kernel_name); + void PrintUnusedKernel(); private: DataDumpParser() = default; @@ -55,7 +56,7 @@ class DataDumpParser { std::string net_name_; uint32_t dump_mode_{0}; uint32_t dump_step_{0}; - std::set kernel_set_; + std::map kernel_map_; }; } // namespace mindspore #endif // MINDSPORE_MINDSPORE_CCSRC_DEBUG_ASYNC_DUMP_JSON_PARE_H_ diff --git a/mindspore/ccsrc/runtime/device/ascend/ascend_kernel_runtime.cc b/mindspore/ccsrc/runtime/device/ascend/ascend_kernel_runtime.cc index c1e3bff79fe49cb0304acb29e687a251cb710d9b..aafbf757654a72a59cb96a30cbb9a44e3a7ddbf3 100644 --- a/mindspore/ccsrc/runtime/device/ascend/ascend_kernel_runtime.cc +++ b/mindspore/ccsrc/runtime/device/ascend/ascend_kernel_runtime.cc @@ -100,6 +100,9 @@ void AscendKernelRuntime::ClearGraphModelMap() { iter.second->UnloadDumpInfo(); } graph_data_dumper_.clear(); + // tell users which dump kernel name not used + DataDumpParser::GetInstance().PrintUnusedKernel(); + for (auto &iter : graph_model_map_) { MS_LOG(INFO) << "Ge UnloadModel " << iter.first; auto ret = ModelRunner::Instance().UnloadModel(iter.first); diff --git a/mindspore/ccsrc/runtime/device/ascend/dump/data_dumper.cc b/mindspore/ccsrc/runtime/device/ascend/dump/data_dumper.cc index 61b3b04f7396908ab46f7e61a282421613a0e338..a4509197ceecf99ddc0bd3514c909f1f2c862eff 100644 --- a/mindspore/ccsrc/runtime/device/ascend/dump/data_dumper.cc +++ b/mindspore/ccsrc/runtime/device/ascend/dump/data_dumper.cc @@ -62,6 +62,7 @@ void DataDumper::LoadDumpInfo() { } MS_LOG(INFO) << "[DataDump] LoadDumpInfo kernel:" << kernel->fullname_with_scope(); dump_kernel_names_.emplace_back(kernel->fullname_with_scope()); + DataDumpParser::GetInstance().MatchKernel(kernel->fullname_with_scope()); aicpu::dump::Task task; ConstructDumpTask(NOT_NULL(kernel), NOT_NULL(&task)); @@ -84,7 +85,7 @@ void DataDumper::SetOpMappingInfo(NotNull dump_inf MS_LOG(EXCEPTION) << "Dump path invalid"; } auto device_id = context_ptr->device_id(); - dump_info->set_dump_path(dump_path.value() + "_" + std::to_string(device_id) + "/"); + dump_info->set_dump_path("/" + dump_path.value() + "_" + std::to_string(device_id) + "/"); MS_LOG(INFO) << "[DataDump] dump_path:" << dump_path.value(); dump_info->set_model_name(DataDumpParser::GetInstance().net_name() + "_" + std::to_string(kernel_graph_->graph_id()));