diff --git a/projects/clr/rocclr/device/pal/palresource.cpp b/projects/clr/rocclr/device/pal/palresource.cpp index 61a6f333e7..c6545cbc2b 100644 --- a/projects/clr/rocclr/device/pal/palresource.cpp +++ b/projects/clr/rocclr/device/pal/palresource.cpp @@ -2207,7 +2207,8 @@ bool MemorySubAllocator::Free(amd::Monitor* monitor, GpuMemoryReference* ref, Pa it->second->Free(offset); // If this suballocator empty, then release memory chunk - if (it->second->IsEmpty()) { + // while keeping at least one chunk available, if retain_final_chunk is true + if (it->second->IsEmpty() && !(retain_final_chunk_ && heaps_.size() == 1)) { delete it->second; heaps_.erase(it); release_mem = true; diff --git a/projects/clr/rocclr/device/pal/palresource.hpp b/projects/clr/rocclr/device/pal/palresource.hpp index 172b1128d0..b7c5a8ed5c 100644 --- a/projects/clr/rocclr/device/pal/palresource.hpp +++ b/projects/clr/rocclr/device/pal/palresource.hpp @@ -535,7 +535,8 @@ typedef Util::BuddyAllocator MemBuddyAllocator; class MemorySubAllocator : public amd::HeapObject { public: - MemorySubAllocator(Device* device) : device_(device) {} + MemorySubAllocator(Device* device, bool retain_final_chunk = false) + : device_(device), retain_final_chunk_(retain_final_chunk) {} ~MemorySubAllocator(); @@ -553,6 +554,7 @@ class MemorySubAllocator : public amd::HeapObject { Device* device_; std::unordered_map heaps_; + bool retain_final_chunk_; }; class CoarseMemorySubAllocator : public MemorySubAllocator { @@ -564,7 +566,8 @@ class CoarseMemorySubAllocator : public MemorySubAllocator { class FineMemorySubAllocator : public MemorySubAllocator { public: - FineMemorySubAllocator(Device* device) : MemorySubAllocator(device) {} + FineMemorySubAllocator(Device* device) + : MemorySubAllocator(device, true /*retain_final_chunk*/) {} bool CreateChunk(const Pal::IGpuMemory* reserved_va) override; };