forked from mindspore-Ecosystem/mindspore
!3155 Fix data dump security bug
Merge pull request !3155 from caifubi/data-dump-new
This commit is contained in:
commit
eb630f2501
|
@ -120,6 +120,10 @@ std::optional<std::string> 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
|
||||
|
|
|
@ -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<std::string> 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<std::mutex> 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
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#define MINDSPORE_MINDSPORE_CCSRC_DEBUG_ASYNC_DUMP_JSON_PARE_H_
|
||||
|
||||
#include <string>
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#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<std::string> &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<std::string> kernel_set_;
|
||||
std::map<std::string, uint32_t> kernel_map_;
|
||||
};
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_MINDSPORE_CCSRC_DEBUG_ASYNC_DUMP_JSON_PARE_H_
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<aicpu::dump::OpMappingInfo *> 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()));
|
||||
|
|
Loading…
Reference in New Issue