Skip to content

Commit

Permalink
Add alias template Gpu::NonManagedDeviceVector (#2999)
Browse files Browse the repository at this point in the history
  • Loading branch information
WeiqunZhang authored Oct 26, 2022
1 parent b3e0a62 commit ab8c892
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Src/AmrCore/AMReX_TagBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ TagBoxArray::local_collate_gpu (Gpu::PinnedVector<IntVect>& v) const
std::partial_sum(nblocks.begin(), nblocks.end(), blockoffset.begin()+1);
int ntotblocks = blockoffset.back();

PODVector<int,DeviceArenaAllocator<int> > dv_ntags(ntotblocks);
Gpu::NonManagedDeviceVector<int> dv_ntags(ntotblocks);

for (MFIter fai(*this); fai.isValid(); ++fai)
{
Expand Down Expand Up @@ -491,21 +491,21 @@ TagBoxArray::local_collate_gpu (Gpu::PinnedVector<IntVect>& v) const
#endif
}

PODVector<int,PinnedArenaAllocator<int> > hv_ntags(ntotblocks);
Gpu::PinnedVector<int> hv_ntags(ntotblocks);
Gpu::dtoh_memcpy(hv_ntags.data(), dv_ntags.data(), ntotblocks*sizeof(int));

PODVector<int,PinnedArenaAllocator<int> > hv_tags_offset(ntotblocks+1);
Gpu::PinnedVector<int> hv_tags_offset(ntotblocks+1);
hv_tags_offset[0] = 0;
std::partial_sum(hv_ntags.begin(), hv_ntags.end(), hv_tags_offset.begin()+1);
int ntotaltags = hv_tags_offset.back();

if (ntotaltags == 0) return;

PODVector<int,DeviceArenaAllocator<int> > dv_tags_offset(ntotblocks);
Gpu::NonManagedDeviceVector<int> dv_tags_offset(ntotblocks);
int* dp_tags_offset = dv_tags_offset.data();
Gpu::htod_memcpy_async(dp_tags_offset, hv_tags_offset.data(), ntotblocks*sizeof(int));

PODVector<IntVect,DeviceArenaAllocator<IntVect> > dv_tags(ntotaltags);
Gpu::NonManagedDeviceVector<IntVect> dv_tags(ntotaltags);
IntVect* dp_tags = dv_tags.data();

int iblock = 0;
Expand Down
10 changes: 10 additions & 0 deletions Src/Base/AMReX_GpuContainers.H
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ namespace Gpu {
template <class T>
using DeviceVector = PODVector<T, ArenaAllocator<T> >;

/**
* \brief A PODVector that uses the non-managed device memory arena.
*
*/
template <class T>
using NonManagedDeviceVector = PODVector<T, DeviceArenaAllocator<T> >;

/**
* \brief A PODVector that uses the managed memory arena.
*
Expand Down Expand Up @@ -83,6 +90,9 @@ namespace Gpu {
template <class T>
using HostVector = PODVector<T>;

template <class T>
using NonManagedVector = PODVector<T>;

template <class T>
using ManagedVector = PODVector<T>;

Expand Down

0 comments on commit ab8c892

Please sign in to comment.