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

Port WriteEBSurface by copying EB information to pinned tmps before writing. #3793

Merged
merged 4 commits into from
Mar 8, 2024
Merged
Changes from 1 commit
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
Next Next commit
Port WriteEBSurface by copying EB information to pinned tmps before w…
…riting.
  • Loading branch information
atmyers committed Mar 8, 2024
commit dffb44955d26feb0c53cd472655d02a34607e33e
72 changes: 61 additions & 11 deletions Src/EB/AMReX_WriteEBSurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,62 @@ void WriteEBSurface (const BoxArray & ba, const DistributionMapping & dmap, cons

const auto & sfab = static_cast<EBFArrayBox const &>(mf_ba[mfi]);
const auto & my_flag = sfab.getEBCellFlagFab();
auto my_flag_ptr = &my_flag;
atmyers marked this conversation as resolved.
Show resolved Hide resolved

const Box & bx = mfi.validbox();

if (my_flag.getType(bx) == FabType::covered ||
my_flag.getType(bx) == FabType::regular) { continue; }

std::array<const MultiCutFab *, AMREX_SPACEDIM> areafrac;
const MultiCutFab * bndrycent;

areafrac = ebf->getAreaFrac();
bndrycent = &(ebf->getBndryCent());
std::array<const CutFab *, AMREX_SPACEDIM> areafrac;
const CutFab * bndrycent;

for (int d = 0; d < AMREX_SPACEDIM; ++d) {
areafrac[d] = &(*ebf->getAreaFrac()[d])[mfi];
}
bndrycent = &(ebf->getBndryCent()[mfi]);

#ifdef AMREX_USE_GPU
std::unique_ptr<EBCellFlagFab> host_flag;
if (my_flag.arena()->isManaged() || my_flag.arena()->isDevice()) {
host_flag = std::make_unique<EBCellFlagFab>(my_flag.box(), my_flag.nComp(),
The_Pinned_Arena());
Gpu::dtoh_memcpy_async(host_flag->dataPtr(), my_flag.dataPtr(),
my_flag.size()*sizeof(Real));
atmyers marked this conversation as resolved.
Show resolved Hide resolved
Gpu::streamSynchronize();
my_flag_ptr = host_flag.get();
}

std::array<std::unique_ptr<CutFab>, AMREX_SPACEDIM> areafrac_h;
for (int d = 0; d < AMREX_SPACEDIM; ++d) {
if (areafrac[d]->arena()->isManaged() || areafrac[d]->arena()->isDevice()) {
areafrac_h[d] = std::make_unique<CutFab>(areafrac[d]->box(), areafrac[d]->nComp(),
The_Pinned_Arena());
Gpu::dtoh_memcpy_async(areafrac_h[d]->dataPtr(), areafrac[d]->dataPtr(),
areafrac[d]->size()*sizeof(Real));
Gpu::streamSynchronize();
areafrac[d] = areafrac_h[d].get();
}
}

std::unique_ptr<CutFab> bndrycent_h;
if (bndrycent->arena()->isManaged() || bndrycent->arena()->isDevice()) {
bndrycent_h = std::make_unique<CutFab>(bndrycent->box(), bndrycent->nComp(),
The_Pinned_Arena());
Gpu::dtoh_memcpy_async(bndrycent_h->dataPtr(), bndrycent->dataPtr(),
bndrycent->size()*sizeof(Real));
Gpu::streamSynchronize();
bndrycent = bndrycent_h.get();
}
#endif

eb_to_pvd.EBToPolygon(
problo, dx,
bx, my_flag.const_array(),
bndrycent->const_array(mfi),
areafrac[0]->const_array(mfi),
areafrac[1]->const_array(mfi),
areafrac[2]->const_array(mfi));
bx, my_flag_ptr->const_array(),
bndrycent->const_array(),
areafrac[0]->const_array(),
areafrac[1]->const_array(),
areafrac[2]->const_array());
}

int cpu = ParallelDescriptor::MyProc();
Expand All @@ -58,13 +95,26 @@ void WriteEBSurface (const BoxArray & ba, const DistributionMapping & dmap, cons

const auto & sfab = static_cast<EBFArrayBox const &>(mf_ba[mfi]);
const auto & my_flag = sfab.getEBCellFlagFab();
auto my_flag_ptr = &my_flag;
atmyers marked this conversation as resolved.
Show resolved Hide resolved

const Box & bx = mfi.validbox();

if (my_flag.getType(bx) == FabType::covered ||
my_flag.getType(bx) == FabType::regular) { continue; }

eb_to_pvd.EBGridCoverage(cpu, problo, dx, bx, my_flag.const_array());
#ifdef AMREX_USE_GPU
std::unique_ptr<EBCellFlagFab> host_flag;
if (my_flag.arena()->isManaged() || my_flag.arena()->isDevice()) {
host_flag = std::make_unique<EBCellFlagFab>(my_flag.box(), my_flag.nComp(),
The_Pinned_Arena());
Gpu::dtoh_memcpy_async(host_flag->dataPtr(), my_flag.dataPtr(),
my_flag.size()*sizeof(Real));
WeiqunZhang marked this conversation as resolved.
Show resolved Hide resolved
Gpu::streamSynchronize();
my_flag_ptr = host_flag.get();
}
#endif

eb_to_pvd.EBGridCoverage(cpu, problo, dx, bx, my_flag_ptr->const_array());
}
}

Expand Down
Loading