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

Forward allocation names in the NamedAllocationStrategy #928

Merged
merged 4 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions examples/cookbook/recipe_shared_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "umpire/Umpire.hpp"
#include "umpire/config.hpp"
#include "umpire/resource/HostSharedMemoryResource.hpp"
#include "umpire/strategy/NamedAllocationStrategy.hpp"
#include "umpire/util/MemoryResourceTraits.hpp"

//
Expand Down Expand Up @@ -58,6 +59,9 @@ int main(int ac, char** av)
//
auto node_allocator{rm.makeResource("SHARED::node_allocator", traits)};

auto named_node_allocator{
rm.makeAllocator<umpire::strategy::NamedAllocationStrategy>("My Node Allocator", node_allocator)};

//
// Resource of this allocator is SHARED
//
Expand All @@ -82,6 +86,7 @@ int main(int ac, char** av)
// Allocate shared memory
//
void* ptr{node_allocator.allocate("allocation_name_2", sizeof(uint64_t))};
void* ptr2{named_node_allocator.allocate("allocation two", 1024)};
uint64_t* data{static_cast<uint64_t*>(ptr)};

if (shared_rank == foreman_rank)
Expand All @@ -98,6 +103,7 @@ int main(int ac, char** av)
UMPIRE_ASSERT(*data == 0xDEADBEEF);

node_allocator.deallocate(ptr);
named_node_allocator.deallocate(ptr2);

if (use_mpi) {
MPI_Finalize();
Expand Down
5 changes: 5 additions & 0 deletions src/umpire/strategy/NamedAllocationStrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ void* NamedAllocationStrategy::allocate(std::size_t bytes)
return m_allocator->allocate_internal(bytes);
}

void* NamedAllocationStrategy::allocate_named(const std::string& name, std::size_t bytes)
{
return m_allocator->allocate_named_internal(name, bytes);
}

void NamedAllocationStrategy::deallocate(void* ptr, std::size_t size)
{
return m_allocator->deallocate_internal(ptr, size);
Expand Down
1 change: 1 addition & 0 deletions src/umpire/strategy/NamedAllocationStrategy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class NamedAllocationStrategy : public AllocationStrategy {
NamedAllocationStrategy(const std::string& name, int id, Allocator allocator);

void* allocate(std::size_t bytes) override;
void* allocate_named(const std::string& name, std::size_t bytes) override;
void deallocate(void* ptr, std::size_t size) override;

Platform getPlatform() noexcept override;
Expand Down
18 changes: 18 additions & 0 deletions tests/integration/strategy_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,4 +763,22 @@ TEST(NamingShimTests, TestAllocateDeallocate)
shim.deallocate(ptr);
}
}

TEST(NamedAllocatorTest, ForwardName)
{
auto& rm = umpire::ResourceManager::getInstance();

auto traits{umpire::get_default_resource_traits("SHARED")};
traits.size = 1 * 1024 * 1024;
traits.scope = umpire::MemoryResourceTraits::shared_scope::node;

auto node_allocator{rm.makeResource("SHARED::allocator_for_named_test", traits)};

auto allocator{rm.makeAllocator<umpire::strategy::NamedAllocationStrategy>("shared named alloc", node_allocator)};
{
void* ptr = allocator.allocate("test", 1024);
EXPECT_NE(ptr, nullptr);
allocator.deallocate(ptr);
}
}
#endif
Loading