diff --git a/mindspore/ccsrc/pre_activate/mem_reuse/mem_reuse_checker.cc b/mindspore/ccsrc/pre_activate/mem_reuse/mem_reuse_checker.cc index fdd6e685079..cf92679187f 100644 --- a/mindspore/ccsrc/pre_activate/mem_reuse/mem_reuse_checker.cc +++ b/mindspore/ccsrc/pre_activate/mem_reuse/mem_reuse_checker.cc @@ -436,28 +436,7 @@ void MemReuseChecker::SetAddNewMembuInfos(const KernelDef *op_def, const std::ve add_new_stream_ids_.push_back(op_def->stream_id()); } -void MemReuseChecker::ExportMembufInfoIR() { - std::string ir_file_name = "./mem_buf_info.ir"; - std::ofstream ofs(ir_file_name); - int64_t total_reuse_size = 0; - if (!ofs.is_open()) { - MS_LOG(ERROR) << "Open file [" << ir_file_name << "] failed!"; - } - ofs << "Total static size:\t" << total_ori_static_size_ << "\n"; - ofs << "Graph inputs size:\t" << total_ori_input_size_ << "\n"; - ofs << "Value nodes size:\t" << total_ori_value_size_ << "\n"; - ofs << "Total dynamic size:\t" << total_ori_dy_size_ << "\n"; - ofs << "Total workspace size:\t" << total_ori_wkspace_size_ << "\n"; - // get last membuf_list - if (membuf_all_infos_.empty()) { - return; - } - auto last_membuf_list = membuf_all_infos_.back(); - for (const auto &membuf : last_membuf_list) { - auto checker_size = SizeToLong(membuf->size_); - total_reuse_size += checker_size; - } - ofs << "After reuse size:\t" << total_reuse_size << "\n\n"; +void MemReuseChecker::ExportEachMembufInfo(std::ofstream &ofs) { size_t i = 0; std::vector each_node_used_size; std::vector each_node_allocated_size; @@ -496,6 +475,8 @@ void MemReuseChecker::ExportMembufInfoIR() { ofs << "curr allocated size: \t" << curr_allocated << "\n"; ofs << "\n\n"; } + auto optimal_iter = std::max_element(each_node_used_size.begin(), each_node_used_size.end()); + ofs << "theoretical optimal size: " << *optimal_iter << "\n"; ofs << "each node used size: \n"; for (auto size : each_node_used_size) { ofs << size << "\t"; @@ -506,6 +487,31 @@ void MemReuseChecker::ExportMembufInfoIR() { ofs << size << "\t"; } ofs << "\n\n"; +} + +void MemReuseChecker::ExportMembufInfoIR() { + std::string ir_file_name = "./mem_buf_info.ir"; + std::ofstream ofs(ir_file_name); + int64_t total_reuse_size = 0; + if (!ofs.is_open()) { + MS_LOG(ERROR) << "Open file [" << ir_file_name << "] failed!"; + } + ofs << "Total static size:\t" << total_ori_static_size_ << "\n"; + ofs << "Graph inputs size:\t" << total_ori_input_size_ << "\n"; + ofs << "Value nodes size:\t" << total_ori_value_size_ << "\n"; + ofs << "Total dynamic size:\t" << total_ori_dy_size_ << "\n"; + ofs << "Total workspace size:\t" << total_ori_wkspace_size_ << "\n"; + // get last membuf_list + if (membuf_all_infos_.empty()) { + return; + } + auto last_membuf_list = membuf_all_infos_.back(); + for (const auto &membuf : last_membuf_list) { + auto checker_size = SizeToLong(membuf->size_); + total_reuse_size += checker_size; + } + ofs << "After reuse size:\t" << total_reuse_size << "\n\n"; + ExportEachMembufInfo(ofs); ofs.close(); } diff --git a/mindspore/ccsrc/pre_activate/mem_reuse/mem_reuse_checker.h b/mindspore/ccsrc/pre_activate/mem_reuse/mem_reuse_checker.h index 6130fb5ed2c..5fd3d0f5aec 100644 --- a/mindspore/ccsrc/pre_activate/mem_reuse/mem_reuse_checker.h +++ b/mindspore/ccsrc/pre_activate/mem_reuse/mem_reuse_checker.h @@ -58,6 +58,7 @@ class MemReuseChecker { void ExportNormalTensorIR(std::ofstream &ofs); void CheckNormalIR(const session::KernelGraph *graph); void ExportMembufInfoIR(); + void ExportEachMembufInfo(std::ofstream &ofs); void SetAddNewMembuInfos(const KernelDef *op_def, const std::vector &membuf_ptr_list, size_t op_idx); void ExportAddNewMmebufIR(); void set_kernel_front_map(const std::map> &kernel_front_map) { diff --git a/mindspore/ccsrc/pre_activate/mem_reuse/mem_swap_manager.h b/mindspore/ccsrc/pre_activate/mem_reuse/mem_swap_manager.h index 585ddd8f51f..c19930000ed 100644 --- a/mindspore/ccsrc/pre_activate/mem_reuse/mem_swap_manager.h +++ b/mindspore/ccsrc/pre_activate/mem_reuse/mem_swap_manager.h @@ -36,6 +36,10 @@ class MemSwapManager { mem_copy_manager_ = mem_copy_manager; } + MemSwapManager(const MemSwapManager &) = delete; + + MemSwapManager &operator=(const MemSwapManager &) = delete; + ~MemSwapManager() = default; void Init(const mindspore::session::KernelGraph *kernel_graph); @@ -82,10 +86,6 @@ class MemSwapManager { void ClearSwapQueue(); private: - MemSwapManager(const MemSwapManager &) = delete; - - MemSwapManager &operator=(const MemSwapManager &) = delete; - void AddSwapInfo(); void ResetSwapInfo(); diff --git a/tests/ut/python/predict/test_predict_save_model.py b/tests/ut/python/predict/test_predict_save_model.py index 5764678e196..4f5fe16ad4f 100644 --- a/tests/ut/python/predict/test_predict_save_model.py +++ b/tests/ut/python/predict/test_predict_save_model.py @@ -69,7 +69,7 @@ if __name__ == '__main__': print("test lenet predict start") seed = 0 np.random.seed(seed) - batch = 1 + batch = 32 channel = 1 input_h = 32 input_w = 32