Skip to content

Commit

Permalink
updates to RAP
Browse files Browse the repository at this point in the history
  • Loading branch information
kab163 committed Oct 11, 2024
1 parent d96e150 commit 244bee4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
10 changes: 5 additions & 5 deletions examples/rap_example.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <stdio.h>

#include <iostream>

#include "camp/camp.hpp"
Expand Down Expand Up @@ -68,8 +67,9 @@ int main(int, char**)
auto pool = rm.makeAllocator<umpire::strategy::ResourceAwarePool>("rap-pool", rm.getAllocator("HOST"));
#endif

resource_type d1, d2, d3;
Resource r1{d1}, r2{d2}, r3{d3};
// Create camp resources for RAP
resource_type d1, d2;
Resource r1{d1}, r2{d2};

// allocate memory in the pool with r1
double* a = static_cast<double*>(pool.allocate(r1, NUM_THREADS * sizeof(double)));
Expand All @@ -89,14 +89,14 @@ int main(int, char**)

// deallocate memory with r1 and reallocate using a different stream r2
pool.deallocate(r1, a);

a = static_cast<double*>(pool.allocate(r2, NUM_THREADS * sizeof(double)));
double* ptr2 = a;

// Make sure resource was correctly tracked
UMPIRE_ASSERT(getResource(pool, a) == r2);

// Use Camp resource to synchronize devices
r1.get_event().wait();
r2.get_event().wait();

#if defined(UMPIRE_ENABLE_CUDA) || defined(UMPIRE_ENABLE_HIP)
UMPIRE_ASSERT(ptr1 != ptr2);
Expand Down
7 changes: 1 addition & 6 deletions src/umpire/strategy/ResourceAwarePool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ void* ResourceAwarePool::allocate_resource(camp::resources::Resource r, std::siz

Chunk* chunk{nullptr};

// auto pending_chunks_exist = m_pending_map.find(r);

if (!m_pending_map.empty()) {
for (auto pending_chunk : m_pending_map) {
if (pending_chunk->free == false && pending_chunk->m_event.check()) // no longer pending
Expand Down Expand Up @@ -270,12 +268,9 @@ void ResourceAwarePool::deallocate_resource(camp::resources::Resource r, void* p

auto my_r = getResource(ptr);
if (my_r != r) {
UMPIRE_LOG(
Warning,
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)));
UMPIRE_LOG(Debug, fmt::format("getResource doesn't match resource passed to deallocate. Resource used: {} .",
camp::resources::to_string(r)));
}

// Chunk is now pending, add to list
Expand Down
3 changes: 3 additions & 0 deletions src/umpire/strategy/ResourceAwarePool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ class ResourceAwarePool : public AllocationStrategy, private mixins::AlignedAllo
std::size_t getPendingSize() const noexcept;

Platform getPlatform() noexcept override;
/*!
* \brief get the (generic) camp resource associated with a ptr
*/
Resource getResource(void* ptr) const;

MemoryResourceTraits getTraits() const noexcept override;
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/resource_aware_pool_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ TEST_P(ResourceAwarePoolTest, Check_States)
hipLaunchKernelGGL(do_sleep, 1, 32, 0, d1.get_stream(), ptr);
#endif

m_pool.deallocate(ptr);
m_pool.deallocate(r1, ptr);
EXPECT_EQ(getPendingSize(m_pool), 1);

double* ptr2 = static_cast<double*>(m_pool.allocate(r2, 2048));
Expand Down

0 comments on commit 244bee4

Please sign in to comment.