Skip to content

Commit 91323f2

Browse files
committed
Merge branch 'development'
2 parents 749721f + 6e1acca commit 91323f2

File tree

7 files changed

+44
-21
lines changed

7 files changed

+44
-21
lines changed

Src/Base/AMReX_BLassert.H

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,11 @@
4848
#define AMREX_ALWAYS_ASSERT_WITH_MESSAGE(EX,MSG) (EX)?((void)0):amrex::Assert( # EX , __FILE__, __LINE__ , # MSG)
4949
#define AMREX_ALWAYS_ASSERT(EX) (EX)?((void)0):amrex::Assert( # EX , __FILE__, __LINE__)
5050

51+
52+
#if !defined(AMREX_USE_GPU) || !defined(AMREX_DEBUG) && !defined(AMREX_USE_ASSERTION)
53+
#define AMREX_GPU_ASSERT(EX) ((void)0)
54+
#else
55+
#define AMREX_GPU_ASSERT(EX) (EX)?((void)0):amrex::Assert( # EX , __FILE__, __LINE__)
56+
#endif
57+
5158
#endif /*BL_BL_ASSERT_H*/

Src/Base/AMReX_CArena.H

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include <set>
66
#include <vector>
77
#include <mutex>
8+
#include <unordered_set>
9+
#include <functional>
810

911
#include <AMReX_Arena.H>
1012

@@ -89,6 +91,12 @@ protected:
8991
return m_owner == rhs.m_owner;
9092
}
9193

94+
struct hash {
95+
std::size_t operator() (const Node& n) const noexcept {
96+
return std::hash<void*>{}(n.m_block);
97+
}
98+
};
99+
92100
private:
93101
//! The block of memory we reference.
94102
void* m_block;
@@ -117,7 +125,8 @@ protected:
117125
* \brief The list of busy blocks.
118126
* A block is either on the freelist or on the blocklist, but not on both.
119127
*/
120-
NL m_busylist;
128+
// NL m_busylist;
129+
std::unordered_set<Node, Node::hash> m_busylist;
121130
//! The minimal size of hunks to request via ::operator new().
122131
std::size_t m_hunk;
123132
//! The amount of heap space currently allocated.

Src/Base/AMReX_CArena.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ CArena::free (void* vp)
116116
//
117117
// `vp' had better be in the busy list.
118118
//
119-
NL::iterator busy_it = m_busylist.find(Node(vp,0,0));
119+
auto busy_it = m_busylist.find(Node(vp,0,0));
120120

121121
BL_ASSERT(!(busy_it == m_busylist.end()));
122122
BL_ASSERT(m_freelist.find(*busy_it) == m_freelist.end());

Src/Base/AMReX_FabArray.H

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,9 @@ FabArray<FAB>::fabDevicePtr (const MFIter& mfi)
782782
{
783783
BL_ASSERT(mfi.LocalIndex() < indexArray.size());
784784
BL_ASSERT(DistributionMap() == mfi.DistributionMap());
785-
return m_fabs_v[mfi.LocalIndex()];
785+
int li = mfi.LocalIndex();
786+
AMREX_GPU_ASSERT(m_fabs_v[li]->dataPtr() == m_host_fabs_v[li]->dataPtr());
787+
return m_fabs_v[li];
786788
}
787789

788790
template <class FAB>
@@ -791,7 +793,9 @@ FabArray<FAB>::fabDevicePtr (const MFIter& mfi) const
791793
{
792794
BL_ASSERT(mfi.LocalIndex() < indexArray.size());
793795
BL_ASSERT(DistributionMap() == mfi.DistributionMap());
794-
return m_fabs_v[mfi.LocalIndex()];
796+
int li = mfi.LocalIndex();
797+
AMREX_GPU_ASSERT(m_fabs_v[li]->dataPtr() == m_host_fabs_v[li]->dataPtr());
798+
return m_fabs_v[li];
795799
}
796800

797801
template <class FAB>
@@ -800,6 +804,7 @@ FabArray<FAB>::fabDevicePtr (int K)
800804
{
801805
int li = localindex(K);
802806
BL_ASSERT(li >=0 && li < indexArray.size());
807+
AMREX_GPU_ASSERT(m_fabs_v[li]->dataPtr() == m_host_fabs_v[li]->dataPtr());
803808
return m_fabs_v[li];
804809
}
805810

@@ -818,10 +823,12 @@ FabArray<FAB>::fabHostPtr (const MFIter& mfi)
818823
{
819824
BL_ASSERT(mfi.LocalIndex() < indexArray.size());
820825
BL_ASSERT(DistributionMap() == mfi.DistributionMap());
826+
int li = mfi.LocalIndex();
827+
AMREX_GPU_ASSERT(m_fabs_v[li]->dataPtr() == m_host_fabs_v[li]->dataPtr());
821828
#if AMREX_USE_GPU
822-
return m_host_fabs_v[mfi.LocalIndex()];
829+
return m_host_fabs_v[li];
823830
#else
824-
return m_fabs_v[mfi.LocalIndex()];
831+
return m_fabs_v[li];
825832
#endif
826833
}
827834

@@ -831,10 +838,12 @@ FabArray<FAB>::fabHostPtr (const MFIter& mfi) const
831838
{
832839
BL_ASSERT(mfi.LocalIndex() < indexArray.size());
833840
BL_ASSERT(DistributionMap() == mfi.DistributionMap());
841+
int li = mfi.LocalIndex();
842+
AMREX_GPU_ASSERT(m_fabs_v[li]->dataPtr() == m_host_fabs_v[li]->dataPtr());
834843
#if AMREX_USE_GPU
835-
return m_host_fabs_v[mfi.LocalIndex()];
844+
return m_host_fabs_v[li];
836845
#else
837-
return m_fabs_v[mfi.LocalIndex()];
846+
return m_fabs_v[li];
838847
#endif
839848
}
840849

@@ -844,6 +853,7 @@ FabArray<FAB>::fabHostPtr (int K)
844853
{
845854
int li = localindex(K);
846855
BL_ASSERT(li >=0 && li < indexArray.size());
856+
AMREX_GPU_ASSERT(m_fabs_v[li]->dataPtr() == m_host_fabs_v[li]->dataPtr());
847857
#if AMREX_USE_GPU
848858
return m_host_fabs_v[li];
849859
#else
@@ -857,6 +867,7 @@ FabArray<FAB>::fabHostPtr (int K) const
857867
{
858868
int li = localindex(K);
859869
BL_ASSERT(li >=0 && li < indexArray.size());
870+
AMREX_GPU_ASSERT(m_fabs_v[li]->dataPtr() == m_host_fabs_v[li]->dataPtr());
860871
#if AMREX_USE_GPU
861872
return m_host_fabs_v[li];
862873
#else

Src/Base/AMReX_FabArrayCommI.H

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,6 @@ FabArray<FAB>::FBEP_nowait (int scomp, int ncomp, const IntVect& nghost,
301301

302302
if (Gpu::inLaunchRegion())
303303
{
304-
LayoutData<Array<Vector<FabCopyTag<FAB> >,AMREX_SPACEDIM> >
305-
dtags(loc_copy_tags.boxArray(), loc_copy_tags.DistributionMap());
306304
for (MFIter mfi(*this); mfi.isValid(); ++mfi)
307305
{
308306
FAB* dfab = this->fabPtr(mfi);
@@ -318,7 +316,7 @@ FabArray<FAB>::FBEP_nowait (int scomp, int ncomp, const IntVect& nghost,
318316
gbx_lo.grow(jdim,nghost[jdim]);
319317
}
320318
const int ncells_to_hi = vbx.length(idim)+nghost[idim];
321-
const Box gbx_hi = gbx_lo + IntVect{ncells_to_hi};
319+
const Box gbx_hi = amrex::shift(gbx_lo, idim, ncells_to_hi);
322320

323321
Vector<FabCopyTag<FAB> > tags_lo, tags_hi;
324322
for (const auto& lc_tag : lc_tags) {
@@ -1503,8 +1501,6 @@ FillBoundary (Vector<FabArray<FAB>*> const& mf, const Periodicity& period)
15031501

15041502
if (Gpu::inLaunchRegion())
15051503
{
1506-
LayoutData<Array<Vector<FabCopyTag<FAB> >,AMREX_SPACEDIM> >
1507-
dtags(loc_copy_tags.boxArray(), loc_copy_tags.DistributionMap());
15081504
for (MFIter mfi(fa); mfi.isValid(); ++mfi)
15091505
{
15101506
FAB* dfab = fa.fabPtr(mfi);
@@ -1520,7 +1516,7 @@ FillBoundary (Vector<FabArray<FAB>*> const& mf, const Periodicity& period)
15201516
gbx_lo.grow(jdim,ng[jdim]);
15211517
}
15221518
const int ncells_to_hi = vbx.length(idim)+ng[idim];
1523-
const Box gbx_hi = gbx_lo + IntVect{ncells_to_hi};
1519+
const Box gbx_hi = amrex::shift(gbx_lo, idim, ncells_to_hi);
15241520

15251521
Vector<FabCopyTag<FAB> > vtags_lo, vtags_hi;
15261522
for (const auto& lc_tag : lc_tags) {

Src/LinearSolvers/MLMG/AMReX_MLEBABecLap.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ MLEBABecLap::FFlux (int amrlev, const MFIter& mfi, const Array<FArrayBox*,AMREX_
603603
const FArrayBox& sol, Location loc, const int face_only) const
604604
{
605605
// todo: gpu
606-
Gpu::LaunchSafeGuard(false);
606+
Gpu::LaunchSafeGuard lg(false);
607607
BL_PROFILE("MLEBABecLap::FFlux()");
608608
const int at_centroid = (Location::FaceCentroid == loc) ? 1 : 0;
609609
const int mglev = 0;
@@ -665,7 +665,7 @@ MLEBABecLap::compGrad (int amrlev, const Array<MultiFab*,AMREX_SPACEDIM>& grad,
665665
MultiFab& sol, Location loc) const
666666
{
667667
// todo: gpu
668-
Gpu::LaunchSafeGuard(false);
668+
Gpu::LaunchSafeGuard lg(false);
669669
BL_PROFILE("MLEBABecLap::compGrad()");
670670

671671
const int at_centroid = (Location::FaceCentroid == loc) ? 1 : 0;
@@ -753,7 +753,7 @@ void
753753
MLEBABecLap::normalize (int amrlev, int mglev, MultiFab& mf) const
754754
{
755755
// todo: gpu
756-
Gpu::LaunchSafeGuard(false);
756+
Gpu::LaunchSafeGuard lg(false);
757757
const MultiFab& acoef = m_a_coeffs[amrlev][mglev];
758758
AMREX_D_TERM(const MultiFab& bxcoef = m_b_coeffs[amrlev][mglev][0];,
759759
const MultiFab& bycoef = m_b_coeffs[amrlev][mglev][1];,
@@ -840,7 +840,7 @@ void
840840
MLEBABecLap::interpolation (int amrlev, int fmglev, MultiFab& fine, const MultiFab& crse) const
841841
{
842842
// todo: gpu
843-
Gpu::LaunchSafeGuard(false);
843+
Gpu::LaunchSafeGuard lg(false);
844844
auto factory = dynamic_cast<EBFArrayBoxFactory const*>(m_factory[amrlev][fmglev].get());
845845
const FabArray<EBCellFlagFab>* flags = (factory) ? &(factory->getMultiEBCellFlagFab()) : nullptr;
846846

@@ -891,7 +891,7 @@ MLEBABecLap::applyBC (int amrlev, int mglev, MultiFab& in, BCMode bc_mode, State
891891
const MLMGBndry* bndry, bool skip_fillboundary) const
892892
{
893893
// todo: gpu
894-
Gpu::LaunchSafeGuard(false);
894+
Gpu::LaunchSafeGuard lg(false);
895895
BL_PROFILE("MLEBABecLap::applyBC()");
896896

897897
// No coarsened boundary values, cannot apply inhomog at mglev>0.

Src/LinearSolvers/MLMG/AMReX_MLMG.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ MLMG::interpCorrection (int alev)
561561

562562
if (linop.isCellCentered())
563563
{
564-
Gpu::LaunchSafeGuard(!isEB); // turn off gpu for eb for now TODO
564+
Gpu::LaunchSafeGuard lg(!isEB); // turn off gpu for eb for now TODO
565565
MFItInfo mfi_info;
566566
if (Gpu::notInLaunchRegion()) mfi_info.EnableTiling().SetDynamic(true);
567567
#ifdef _OPENMP
@@ -692,7 +692,7 @@ MLMG::interpCorrection (int alev, int mglev)
692692

693693
if (linop.isCellCentered())
694694
{
695-
Gpu::LaunchSafeGuard(!isEB); // turn off gpu for eb for now TODO
695+
Gpu::LaunchSafeGuard lg(!isEB); // turn off gpu for eb for now TODO
696696
MFItInfo mfi_info;
697697
if (Gpu::notInLaunchRegion()) mfi_info.EnableTiling().SetDynamic(true);
698698
#ifdef _OPENMP

0 commit comments

Comments
 (0)