From 6bff8e3213b41f451a43d72c0343678b9fc3d065 Mon Sep 17 00:00:00 2001 From: Critsium Date: Thu, 14 Nov 2024 21:01:27 -0500 Subject: [PATCH] Fix GPU memory recorder's memory leak (#5491) * Fix memory leak * Remove useless things --- source/module_base/memory.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/source/module_base/memory.cpp b/source/module_base/memory.cpp index bc4cd642df..fdb6195be6 100644 --- a/source/module_base/memory.cpp +++ b/source/module_base/memory.cpp @@ -23,7 +23,7 @@ int Memory::short_memory = sizeof(short); // 2.0 Byte int Memory::n_memory = 1000; int Memory::n_now = 0; -bool Memory::init_flag = false; +bool Memory::init_flag = false; #if defined(__CUDA) || defined(__ROCM) @@ -365,6 +365,7 @@ void Memory::finish(std::ofstream &ofs) delete[] name_gpu; delete[] class_name_gpu; delete[] consume_gpu; + init_flag_gpu = false; } #endif return; @@ -372,11 +373,7 @@ void Memory::finish(std::ofstream &ofs) void Memory::print_all(std::ofstream &ofs) { - if(!init_flag -#if defined(__CUDA) || defined(__ROCM) - && !init_flag_gpu -#endif - ) + if(!init_flag) { return; } @@ -437,6 +434,11 @@ void Memory::print_all(std::ofstream &ofs) } #if defined(__CUDA) || defined(__ROCM) + if(!init_flag_gpu) + { + return; + } + ofs <<"\n NAME-------------------------|GPU MEMORY(MB)----" << std::endl; ofs <