Skip to content

Commit

Permalink
implementing changes from review
Browse files Browse the repository at this point in the history
  • Loading branch information
kab163 committed Oct 31, 2024
1 parent a028234 commit ee56eea
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
18 changes: 18 additions & 0 deletions src/umpire/Umpire.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,26 @@ MPI_Comm get_communicator_for_allocator(Allocator a, MPI_Comm comm);
void register_external_allocation(void* ptr, util::AllocationRecord record);
util::AllocationRecord deregister_external_allocation(void* ptr);

/*!
* \brief Returns the Camp resource associated with a particular allocation
*
* \param Umpire allocator which was used to allocate the data
* \param Pointer which was used for the allocation
*
* \return Camp resource associated with the allocation *assuming the Allocator
* passed in is a ResourceAwarePool strategy and the allocation is either used or pending*
*/
Resource getResource(Allocator a, void* ptr);

/*!
* \brief Returns the current number of pending chunks associated with the pool. The
* pending chunks are those that have been scheduled to deallocate but may or may not
* have actually been deallocated yet.
*
* \param Umpire allocator with ResourceAwarePool strategy
*
* \return Number of pending chunks in the ResourceAwarePool
*/
std::size_t getPendingSize(Allocator a);

/*!
Expand Down
4 changes: 2 additions & 2 deletions src/umpire/strategy/AllocationStrategy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class AllocationStrategy {
* \return Pointer to start of allocated bytes.
*/
virtual void* allocate(std::size_t bytes) = 0;
virtual void* allocate_resource(camp::resources::Resource r, std::size_t bytes);
virtual void* allocate_resource(Resource r, std::size_t bytes);
virtual void* allocate_named(const std::string& name, std::size_t bytes);

/*!
Expand All @@ -168,7 +168,7 @@ class AllocationStrategy {
* \param ptr Pointer to free.
*/
virtual void deallocate(void* ptr, std::size_t size = 0) = 0;
virtual void deallocate_resource(camp::resources::Resource r, void* ptr, std::size_t size = 0);
virtual void deallocate_resource(Resource r, void* ptr, std::size_t size = 0);
};

} // end of namespace strategy
Expand Down
12 changes: 8 additions & 4 deletions src/umpire/strategy/ResourceAwarePool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ void* ResourceAwarePool::allocate_resource(camp::resources::Resource r, std::siz
{
UMPIRE_LOG(Debug, "(bytes=" << bytes << ")");
const std::size_t rounded_bytes{aligned_round_up(bytes)};
const auto& best = m_free_map.lower_bound(rounded_bytes);

Chunk* chunk{nullptr};

if (!m_pending_map.empty()) {
Expand All @@ -81,6 +79,8 @@ void* ResourceAwarePool::allocate_resource(camp::resources::Resource r, std::siz
}
}

const auto& best = m_free_map.lower_bound(rounded_bytes);

if (chunk == nullptr) {
if (best == m_free_map.end()) {
std::size_t bytes_to_use{(m_actual_bytes == 0) ? m_first_minimum_pool_allocation_size
Expand Down Expand Up @@ -270,8 +270,6 @@ void ResourceAwarePool::deallocate_resource(camp::resources::Resource r, void* p
"but getResource returned: {}", camp::resources::to_string(r), camp::resources::to_string(my_r)));
}

// Chunk is now pending, add to list
m_pending_map.push_back(chunk);
if (m_is_coalescing == false) {
chunk->m_event = r.get_event();
}
Expand All @@ -282,6 +280,9 @@ void ResourceAwarePool::deallocate_resource(camp::resources::Resource r, void* p
// Call deallocate logic only for a non-pending chunk
if (chunk->m_event.check()) {
do_deallocate(chunk, ptr);
} else {
// Chunk is now pending, add to list
m_pending_map.push_back(chunk);
}

std::size_t suggested_size{m_should_coalesce(*this)};
Expand Down Expand Up @@ -473,7 +474,10 @@ void ResourceAwarePool::do_coalesce(std::size_t suggested_size) noexcept
if (size_post < suggested_size) {
std::size_t alloc_size{suggested_size - size_post};

// The coalesce will only ever happen on free chunks, so we use default Host resource
// Once the chunk is reallocated the resource will be reset.
camp::resources::Resource r = camp::resources::Host().get_default();

UMPIRE_LOG(Debug, "coalescing " << alloc_size << " bytes.");
auto ptr = allocate_resource(r, alloc_size);
deallocate_resource(r, ptr, alloc_size);
Expand Down

0 comments on commit ee56eea

Please sign in to comment.