Skip to content

Commit

Permalink
Deregister BArena from Profiling in Arena::Finalize (#4164)
Browse files Browse the repository at this point in the history
## Summary

Since the BArena is not destructed in Arena::Finalize, we need to
manually deregister it from memory profiling to avoid an assert when
initializing the next time.

## Additional background

ECP-WarpX/impactx#711
  • Loading branch information
AlexanderSinn authored Sep 23, 2024
1 parent 1bfdb84 commit 35353fb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Src/Base/AMReX_Arena.H
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ public:
*/
void registerForProfiling (const std::string& memory_name);

/**
* \brief Remove this Arena from the list of Arenas that are profiled by TinyProfiler.
* This is equivalent to destructing and re-constructing the Arena
*/
void deregisterFromProfiling ();

#ifdef AMREX_USE_GPU
//! Is this GPU stream ordered memory allocator?
[[nodiscard]] virtual bool isStreamOrderedArena () const { return false; }
Expand Down
15 changes: 15 additions & 0 deletions Src/Base/AMReX_Arena.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,19 @@ Arena::registerForProfiling ([[maybe_unused]] const std::string& memory_name)
#endif
}

void
Arena::deregisterFromProfiling ()
{
#ifdef AMREX_TINY_PROFILING
if (m_profiler.m_do_profiling) {
TinyProfiler::DeregisterArena(m_profiler.m_profiling_stats);
m_profiler.m_do_profiling = false;
m_profiler.m_profiling_stats.clear();
m_profiler.m_currently_allocated.clear();
}
#endif
}

std::size_t
Arena::align (std::size_t s)
{
Expand Down Expand Up @@ -588,6 +601,8 @@ Arena::Finalize ()
delete the_cpu_arena;
the_cpu_arena = nullptr;
}

The_BArena()->deregisterFromProfiling();
}

Arena*
Expand Down

0 comments on commit 35353fb

Please sign in to comment.