Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deadlock for CUDA #4044

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions Src/Base/AMReX_CArena.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <AMReX_CArena.H>
#include <AMReX_BLassert.H>
#include <AMReX_Gpu.H>
#include <AMReX_MFIter.H>
#include <AMReX_ParallelReduce.H>

#ifdef AMREX_TINY_PROFILING
Expand Down Expand Up @@ -57,7 +58,11 @@ CArena::alloc_protected (std::size_t nbytes)
}
#endif

if (static_cast<Long>(m_used+nbytes) >= arena_info.release_threshold) {
if (static_cast<Long>(m_used+nbytes) >= arena_info.release_threshold
#ifdef AMREX_USE_GPU
&& (MFIter::currentDepth() == 0)
#endif
) {
freeUnused_protected();
}

Expand Down Expand Up @@ -393,7 +398,11 @@ CArena::hasFreeDeviceMemory (std::size_t sz)

std::size_t nbytes = Arena::align(sz == 0 ? 1 : sz);

if (static_cast<Long>(m_used+nbytes) >= arena_info.release_threshold) {
if (static_cast<Long>(m_used+nbytes) >= arena_info.release_threshold
#ifdef AMREX_USE_GPU
&& (MFIter::currentDepth() == 0)
#endif
) {
freeUnused_protected();
}

Expand Down
2 changes: 2 additions & 0 deletions Src/Base/AMReX_MFIter.H
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ public:

static int allowMultipleMFIters (int allow);

static int currentDepth ();

void Finalize ();

protected:
Expand Down
25 changes: 18 additions & 7 deletions Src/Base/AMReX_MFIter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ MFIter::allowMultipleMFIters (int allow)
return allow;
}

int
MFIter::currentDepth ()
{
int r;
#ifdef AMREX_USE_OMP
#pragma omp atomic read
#endif
r = MFIter::depth;
return r;
}

MFIter::MFIter (const FabArrayBase& fabarray_,
unsigned char flags_)
:
Expand Down Expand Up @@ -222,13 +233,6 @@ MFIter::Finalize ()
// mark as invalid
currentIndex = endIndex;

#ifdef AMREX_USE_OMP
#pragma omp master
#endif
{
depth = 0;
}

#ifdef BL_USE_TEAM
if ( ! (flags & NoTeamBarrier) )
ParallelDescriptor::MyTeam().MemoryBarrier();
Expand Down Expand Up @@ -257,6 +261,13 @@ MFIter::Finalize ()
if (m_fa) {
m_fa.reset(nullptr);
}

#ifdef AMREX_USE_OMP
#pragma omp master
#endif
{
depth = 0;
}
}

void
Expand Down
Loading