Skip to content

Commit

Permalink
Fix a gpu issue
Browse files Browse the repository at this point in the history
If gpu aware mpi is not used, we need to use host memory for communication.
  • Loading branch information
WeiqunZhang committed Jan 25, 2024
1 parent edd6049 commit c7a225e
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions Source/Laser/LaserProfilesImpl/LaserProfileStationField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,36 @@ void StationFieldLaserProfile::update (amrex::Real t)
a(i,j,0) = (a(i,j,0)*(amrex::Real(1.0)-w) + a(i,j,1)*w);
#endif
});
amrex::Gpu::streamSynchronize();
}

amrex::Box b = m_slice_fab->box();
b.setBig(AMREX_SPACEDIM-1,0);
amrex::ParallelDescriptor::Bcast(m_slice_fab->dataPtr(), b.numPts());
if (amrex::ParallelDescriptor::NProcs() > 1) {
amrex::Box b = m_slice_fab->box();
b.setBig(AMREX_SPACEDIM-1,0);
#ifdef AMREX_USE_GPU
if ( ! amrex::ParallelDescriptor::UseGpuAwareMpi() &&
! m_slice_fab->arena()->isHostAccessible() )
{
amrex::FArrayBox host_fab(b, 1, amrex::The_Pinned_Arena());
if (amrex::ParallelDescriptor::MyProc() == 0) {
amrex::Gpu::dtoh_memcpy_async(host_fab.dataPtr(),
m_slice_fab->dataPtr(),
host_fab.nBytes());
amrex::Gpu::streamSynchronize();
}
amrex::ParallelDescriptor::Bcast(host_fab.dataPtr(), b.numPts());
if (amrex::ParallelDescriptor::MyProc() != 0) {
amrex::Gpu::htod_memcpy_async(m_slice_fab->dataPtr(),
host_fab.dataPtr(),
host_fab.nBytes());
amrex::Gpu::streamSynchronize();
}
} else
#endif
{
amrex::ParallelDescriptor::Bcast(m_slice_fab->dataPtr(), b.numPts());
}
}
}

void StationFieldLaserProfile::fill_amplitude (
Expand Down

0 comments on commit c7a225e

Please sign in to comment.