Skip to content

Commit

Permalink
Fix GPU memory recorder's memory leak (#5491)
Browse files Browse the repository at this point in the history
* Fix memory leak

* Remove useless things
  • Loading branch information
Critsium-xy authored Nov 15, 2024
1 parent f2e91bd commit 6bff8e3
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions source/module_base/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -365,18 +365,15 @@ void Memory::finish(std::ofstream &ofs)
delete[] name_gpu;
delete[] class_name_gpu;
delete[] consume_gpu;
init_flag_gpu = false;
}
#endif
return;
}

void Memory::print_all(std::ofstream &ofs)
{
if(!init_flag
#if defined(__CUDA) || defined(__ROCM)
&& !init_flag_gpu
#endif
)
if(!init_flag)
{
return;
}
Expand Down Expand Up @@ -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 <<std::setw(30)<< "total" << std::setw(15) <<std::setprecision(4)<< Memory::total_gpu << std::endl;

Expand Down

0 comments on commit 6bff8e3

Please sign in to comment.