Skip to content

Commit

Permalink
adding default resource when not specified
Browse files Browse the repository at this point in the history
  • Loading branch information
kab163 committed Dec 3, 2024
1 parent 7d4d668 commit 8345094
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
19 changes: 9 additions & 10 deletions src/umpire/strategy/ResourceAwarePool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,13 @@ ResourceAwarePool::~ResourceAwarePool()
release();
}

void* ResourceAwarePool::allocate(std::size_t UMPIRE_UNUSED_ARG(bytes))
void* ResourceAwarePool::allocate(std::size_t bytes)
{
void* ptr{nullptr};
UMPIRE_ERROR(
runtime_error,
UMPIRE_LOG(Warning,
fmt::format("The ResourceAwarePool requires a Camp resource. See "
"https://umpire.readthedocs.io/en/develop/sphinx/cookbook/resource_aware_pool.html for more info."));
return ptr;

return allocate_resource(bytes, camp::resources::Host().get_default());
}

void* ResourceAwarePool::allocate_resource(std::size_t bytes, camp::resources::Resource r)
Expand Down Expand Up @@ -262,8 +261,8 @@ void ResourceAwarePool::deallocate_resource(void* ptr, camp::resources::Resource
if (my_r != r) {
UMPIRE_ERROR(
runtime_error,
fmt::format("Called deallocate with different resource than what is returned by getResource. Called with {},",
"but getResource returned: {}", camp::resources::to_string(r), camp::resources::to_string(my_r)));
fmt::format("Called deallocate with a different resource than what was expected. Called with {},",
"but expected: {}", camp::resources::to_string(r), camp::resources::to_string(my_r)));
}

if (m_is_coalescing == false) {
Expand Down Expand Up @@ -415,10 +414,10 @@ camp::resources::Resource ResourceAwarePool::getResource(void* ptr) const
}
}

UMPIRE_ERROR(runtime_error,
fmt::format("The pointer {} does not seem to be allocated with the ResourceAwarePool!", ptr));
UMPIRE_LOG(Warning, fmt::format("The pointer {} does not seem to be associated with the ResourceAwarePool."
"Returning the default Host resource...", ptr));

return camp::resources::Host{}; // Function needs a return
return camp::resources::Host().get_default(); // Returning a default resource for the ResourceAwarePool
}

MemoryResourceTraits ResourceAwarePool::getTraits() const noexcept
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/resource_aware_pool_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ TEST_P(ResourceAwarePoolTest, CheckStates)

do_sleep<<<1, 32, 0, d1.get_stream()>>>(ptr);

m_pool.deallocate(ptr, r1);
EXPECT_THROW(m_pool.deallocate(ptr, r2));
EXPECT_NO_THROW(m_pool.deallocate(ptr, r1));

EXPECT_EQ(get_num_pending(m_pool), 1);

Expand Down

0 comments on commit 8345094

Please sign in to comment.