Skip to content

Commit

Permalink
Fix segfault when managed memory is not used. (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
WeiqunZhang authored Jul 28, 2023
1 parent db271ac commit 92f0e72
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Source/Projection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1961,8 +1961,22 @@ Projection::computeRhoG(FArrayBox* rhoFab,
{
const auto lo = amrex::lbound(phiFab[iface].box());
const auto hi = amrex::ubound(phiFab[iface].box());
#ifdef AMREX_USE_GPU
FArrayBox h_phiFab(phiFab[iface].box(), phiFab[iface].nComp(),
The_Pinned_Arena());
FArrayBox h_rhoFab(rhoFab[iface].box(), rhoFab[iface].nComp(),
The_Pinned_Arena());
Gpu::dtoh_memcpy_async(h_phiFab.dataPtr(), phiFab[iface].dataPtr(),
h_phiFab.nBytes());
Gpu::dtoh_memcpy_async(h_rhoFab.dataPtr(), rhoFab[iface].dataPtr(),
h_rhoFab.nBytes());
Gpu::streamSynchronize();
const auto& phi = h_phiFab.array();
const auto& rho = h_rhoFab.array();
#else
const auto& phi = phiFab[iface].array();
const auto& rho = rhoFab[iface].array();
#endif
const Real dh = geom.CellSize(AMREX_SPACEDIM-1);

auto add_rhog = [gravity, dh] ( Real rho1, Real rho2,
Expand Down Expand Up @@ -2352,6 +2366,14 @@ Projection::computeRhoG(FArrayBox* rhoFab,
} // endif over hi/low sides
} // endif over directions
#endif

#ifdef AMREX_USE_GPU
Gpu::htod_memcpy_async(phiFab[iface].dataPtr(), h_phiFab.dataPtr(),
phiFab[iface].nBytes());
Gpu::htod_memcpy_async(rhoFab[iface].dataPtr(), h_rhoFab.dataPtr(),
rhoFab[iface].nBytes());
Gpu::streamSynchronize();
#endif
} // endif integrate rho*g*dh
} // end loop over outflow faces
}
Expand Down

0 comments on commit 92f0e72

Please sign in to comment.