Skip to content

Commit

Permalink
Merge pull request #66 from LLNL/feature/custom-allocators
Browse files Browse the repository at this point in the history
Only create Allocators if they don't already exist
  • Loading branch information
davidbeckingsale authored May 15, 2019
2 parents e3b5206 + e42c860 commit 0646fd1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 21 deletions.
2 changes: 1 addition & 1 deletion source/SAMRAI/pdat/ArrayData.C
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ ArrayData<TYPE>::ArrayData(
d_offset(box.size()),
d_box(box)
#if defined(HAVE_UMPIRE)
, d_allocator(umpire::ResourceManager::getInstance().getAllocator("SAMRAI_pool"))
, d_allocator(umpire::ResourceManager::getInstance().getAllocator("samrai::data_allocator"))
, d_array(d_allocator.allocate(d_depth * d_offset * sizeof(TYPE)))
#else
, d_array(d_depth * d_offset)
Expand Down
51 changes: 31 additions & 20 deletions source/SAMRAI/tbox/AllocatorDatabase.C
Original file line number Diff line number Diff line change
Expand Up @@ -67,42 +67,53 @@ AllocatorDatabase::initialize()
{
umpire::ResourceManager& rm = umpire::ResourceManager::getInstance();

if (!rm.isAllocator("samrai::data_allocator")) {
#if defined(HAVE_CUDA)
// Internal pool for allocations
auto main_allocator = rm.makeAllocator<umpire::strategy::AllocationAdvisor>(
"SAMRAI_UM",
rm.getAllocator(umpire::resource::Unified),
// Set preferred location to GPU
"PREFERRED_LOCATION");

// Pool for memory used only in the for_all loops
auto device_allocator = rm.getAllocator(umpire::resource::Device);

// Pool for message streams
auto stream_allocator = rm.getAllocator(umpire::resource::Pinned);
// Internal pool for allocations
auto allocator = rm.makeAllocator<umpire::strategy::AllocationAdvisor>(
"internal::samrai::um_allocation_advisor",
rm.getAllocator(umpire::resource::Unified),
// Set preferred location to GPU
"PREFERRED_LOCATION");
#else
auto main_allocator = rm.getAllocator(umpire::resource::Host);
auto device_allocator = rm.getAllocator(umpire::resource::Host);
auto stream_allocator = rm.getAllocator(umpire::resource::Host);
auto allocator = rm.getAllocator(umpire::resource::Host);
#endif

rm.makeAllocator<umpire::strategy::DynamicPool>("SAMRAI_pool", main_allocator);
rm.makeAllocator<umpire::strategy::DynamicPool>("SAMRAI_device_pool", device_allocator);
rm.makeAllocator<umpire::strategy::DynamicPool>("SAMRAI_stream_pool", stream_allocator);
rm.makeAllocator<umpire::strategy::DynamicPool>("samrai::data_allocator", allocator);
}

if (!rm.isAllocator("samrai::stream_allocator")) {
#if defined(HAVE_CUDA)
auto allocator = rm.getAllocator(umpire::resource::Pinned);
#else
auto allocator = rm.getAllocator(umpire::resource::Host);
#endif

rm.makeAllocator<umpire::strategy::DynamicPool>("samrai::stream_allocator", allocator);
}

if (!rm.isAllocator("samrai::temporary_data_allocator")) {
#if defined(HAVE_CUDA)
auto allocator = rm.getAllocator(umpire::resource::Device);
#else
auto allocator = rm.getAllocator(umpire::resource::Host);
#endif
rm.makeAllocator<umpire::strategy::DynamicPool>("samrai::temporary_data_allocator", allocator);
}
}

umpire::Allocator
AllocatorDatabase::getDevicePool()
{
umpire::ResourceManager& rm = umpire::ResourceManager::getInstance();
return rm.getAllocator("SAMRAI_device_pool");
return rm.getAllocator("samrai::temporary_data_allocator");
}

umpire::TypedAllocator<char>
AllocatorDatabase::getStreamAllocator()
{
umpire::ResourceManager& rm = umpire::ResourceManager::getInstance();
return umpire::TypedAllocator<char>(rm.getAllocator("SAMRAI_stream_pool"));
return umpire::TypedAllocator<char>(rm.getAllocator("samrai::stream_allocator"));
}

#endif
Expand Down

0 comments on commit 0646fd1

Please sign in to comment.