diff --git a/mindspore/ccsrc/debug/data_dump/dump_json_parser.cc b/mindspore/ccsrc/debug/data_dump/dump_json_parser.cc index 0d55180eb6b9c374f423c2672a077463348b8a91..52b22aaa43e6d134f35906cb5929e69978ad0e56 100644 --- a/mindspore/ccsrc/debug/data_dump/dump_json_parser.cc +++ b/mindspore/ccsrc/debug/data_dump/dump_json_parser.cc @@ -292,6 +292,11 @@ bool DumpJsonParser::DumpToFile(const std::string &filename, const void *data, s MS_LOG(ERROR) << "Incorrect parameter."; return false; } + std::string npy_header = GenerateNpyHeader(shape, type); + if (npy_header.empty()) { + MS_LOG(WARNING) << "Failed to generate npy_header for file: " << filename; + return false; + } std::string npy_suffix = ".npy"; std::string origin_file_path = filename + npy_suffix; std::optional prefix_path; @@ -337,19 +342,16 @@ bool DumpJsonParser::DumpToFile(const std::string &filename, const void *data, s if (!fd.is_open()) { MS_LOG(EXCEPTION) << "Open file " << file_path_str << " failed." << ErrnoToString(errno); } - std::string npy_header = GenerateNpyHeader(shape, type); - if (!npy_header.empty()) { - fd << npy_header; - (void)fd.write(reinterpret_cast(data), SizeToLong(len)); - if (fd.bad()) { - fd.close(); - MS_LOG(EXCEPTION) - << "Write mem to file " << file_path_str - << " failed. This error may be caused by insufficient disk space. Please check the available disk space."; - } + fd << npy_header; + (void)fd.write(reinterpret_cast(data), SizeToLong(len)); + if (fd.bad()) { fd.close(); - ChangeFileMode(file_path_str, S_IRUSR); + MS_LOG(EXCEPTION) + << "Write mem to file " << file_path_str + << " failed. This error may be caused by insufficient disk space. Please check the available disk space."; } + fd.close(); + ChangeFileMode(file_path_str, S_IRUSR); return true; } diff --git a/mindspore/ccsrc/debug/data_dump/npy_header.cc b/mindspore/ccsrc/debug/data_dump/npy_header.cc index 3967830475bcb2e0e23a4716328e9cc10466858d..3f0ac8360c4dc7c00edf986d25879fb3fc0d6bfa 100644 --- a/mindspore/ccsrc/debug/data_dump/npy_header.cc +++ b/mindspore/ccsrc/debug/data_dump/npy_header.cc @@ -114,7 +114,7 @@ void int_to_byte(size_t number, char *byte, size_t length) { std::string GenerateNpyHeader(const ShapeVector &shape, TypeId type_id, bool fortran_order) { auto type_desc = type_desc_map.find(type_id); if (type_desc == type_desc_map.end()) { - MS_LOG(INFO) << "Not support dump the " << TypeIdToType(type_id)->ToString() << " data to npy file."; + MS_LOG(WARNING) << "Not support dump the " << TypeIdToType(type_id)->ToString() << " data to npy file."; return std::string(); }