diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/inc/runtime.h b/projects/rocr-runtime/runtime/hsa-runtime/core/inc/runtime.h index 53d78f8f08..dd615d2422 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/inc/runtime.h +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/inc/runtime.h @@ -314,7 +314,7 @@ class Runtime { amd::hsa::code::AmdHsaCodeManager* code_manager() { return &code_manager_; } - std::function& + std::function& system_allocator() { return system_allocator_; } @@ -482,8 +482,7 @@ class Runtime { std::map allocation_map_; // Allocator using ::system_region_ - std::function - system_allocator_; + std::function system_allocator_; // Deallocator using ::system_region_ std::function system_deallocator_; diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp index 9ea49a9e30..2e481b7da9 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp @@ -173,20 +173,14 @@ void Runtime::RegisterAgent(Agent* agent) { if (cpu_agents_.size() == 1) { // Might need memory pooling to cover allocation that // requires less than 4096 bytes. - system_allocator_ = - [&](size_t size, size_t alignment, - MemoryRegion::AllocateFlags alloc_flags) -> void* { - assert(alignment <= 4096); - void* ptr = NULL; - return (HSA_STATUS_SUCCESS == - core::Runtime::runtime_singleton_->AllocateMemory( - system_regions_fine_[0], size, alloc_flags, &ptr)) - ? ptr - : NULL; - }; + system_allocator_ = [this](size_t size, size_t align, MemoryRegion::AllocateFlags alloc_flags) -> void* { + assert(align <= 4096); + void* ptr = nullptr; + core::Runtime::runtime_singleton_->AllocateMemory(system_regions_fine_[0], size, alloc_flags, &ptr); + return ptr; + }; - system_deallocator_ = - [](void* ptr) { core::Runtime::runtime_singleton_->FreeMemory(ptr); }; + system_deallocator_ = [](void* ptr) { core::Runtime::runtime_singleton_->FreeMemory(ptr); }; BaseShared::SetAllocateAndFree(system_allocator_, system_deallocator_); } @@ -451,9 +445,8 @@ hsa_status_t Runtime::CopyMemory(void* dst, const void* src, size_t size) { requires the caller to specify all allowed agents we can't assume that a peer mapped pointer would remain mapped for the duration of the copy. */ - void* temp = nullptr; - system_region->Allocate(size, core::MemoryRegion::AllocateNoFlags, &temp); - MAKE_SCOPE_GUARD([&]() { system_region->Free(temp, size); }); + void* temp = system_allocator_(size, 0, core::MemoryRegion::AllocateNoFlags); + MAKE_SCOPE_GUARD([&]() { system_deallocator_(temp); }); hsa_status_t err = src_agent->DmaCopy(temp, source, size); if (err == HSA_STATUS_SUCCESS) err = dst_agent->DmaCopy(dst, temp, size); return err;