Skip to content

Commit

Permalink
Fixup and add recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbeckingsale committed Sep 6, 2024
1 parent 0a750e9 commit af54fd2
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
14 changes: 11 additions & 3 deletions examples/cookbook/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,19 @@ if (UMPIRE_ENABLE_NUMA)
endif ()

if (UMPIRE_ENABLE_IPC_SHARED_MEMORY)
if (UMPIRE_ENABLE_MPI)
blt_add_executable(
NAME recipe_shared_memory
SOURCES recipe_shared_memory.cpp
DEPENDS_ON ${cookbook_depends})
list(APPEND umpire_cookbooks recipe_shared_memory)
endif()

blt_add_executable(
NAME recipe_shared_memory
SOURCES recipe_shared_memory.cpp
NAME recipe_naming_shim
SOURCES recipe_naming_shim.cpp
DEPENDS_ON ${cookbook_depends})
list(APPEND umpire_cookbooks recipe_shared_memory)
list(APPEND umpire_cookbooks recipe_naming_shim)
endif()

if (UMPIRE_ENABLE_CUDA)
Expand Down
30 changes: 30 additions & 0 deletions examples/cookbook/recipe_naming_shim.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2016-24, Lawrence Livermore National Security, LLC and Umpire
// project contributors. See the COPYRIGHT file for details.
//
// SPDX-License-Identifier: (MIT)
//////////////////////////////////////////////////////////////////////////////

#include <iostream>

#include "umpire/Allocator.hpp"
#include "umpire/ResourceManager.hpp"
#include "umpire/Umpire.hpp"
#include "umpire/config.hpp"
#include "umpire/resource/HostSharedMemoryResource.hpp"
#include "umpire/strategy/NamingShim.hpp"
#include "umpire/util/MemoryResourceTraits.hpp"

int main(int, char**)
{
auto& rm = umpire::ResourceManager::getInstance();
auto traits{umpire::get_default_resource_traits("SHARED")};
traits.size = 1 * 1024 * 1024; // Maximum size of this Allocator
traits.scope = umpire::MemoryResourceTraits::shared_scope::node; // default
auto node_allocator{rm.makeResource("SHARED::node_allocator", traits)};
auto shim{rm.makeAllocator<umpire::strategy::NamingShim>("shim", node_allocator)};

void* ptr = shim.allocate(1024);
std::cout << "Ptr = " << ptr << std::endl;
shim.deallocate(ptr);
}
3 changes: 1 addition & 2 deletions src/umpire/strategy/NamingShim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
namespace umpire {
namespace strategy {

NamingShim::NamingShim(const std::string& name, int id, Allocator allocator, std::size_t slots)
NamingShim::NamingShim(const std::string& name, int id, Allocator allocator)
: AllocationStrategy{name, id, allocator.getAllocationStrategy(), "NamingShim"},
m_counter{0},
m_allocator(allocator.getAllocationStrategy())
{
UMPIRE_LOG(Debug, "Creating " << m_slots << "-slot pool.");
}

NamingShim::~NamingShim()
Expand Down
3 changes: 1 addition & 2 deletions src/umpire/strategy/NamingShim.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace strategy {

class NamingShim : public AllocationStrategy {
public:
NamingShim(const std::string& name, int id, Allocator allocator, std::size_t slots);
NamingShim(const std::string& name, int id, Allocator allocator);

~NamingShim();

Expand All @@ -27,7 +27,6 @@ class NamingShim : public AllocationStrategy {
MemoryResourceTraits getTraits() const noexcept override;

private:
std::unordered_map<void*, std::string> m_names;
std::size_t m_counter;
strategy::AllocationStrategy* m_allocator;
};
Expand Down

0 comments on commit af54fd2

Please sign in to comment.