From 06c7997137b625f2c28e1d10f51b1a17fd660f23 Mon Sep 17 00:00:00 2001 From: Sean Keely Date: Mon, 2 Oct 2017 18:34:05 -0500 Subject: [PATCH] Release cached memory blocks when memory allocation fails and retry. Change-Id: I6d96e136e147d8ffe9ff7baec26b4b5a678b739f [ROCm/ROCR-Runtime commit: 9ba83d83f7ce65129bdc2952236888d84d8367c1] --- .../hsa-runtime/core/runtime/amd_memory_region.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_memory_region.cpp b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_memory_region.cpp index a2ba19a543..e72150f764 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_memory_region.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_memory_region.cpp @@ -182,9 +182,15 @@ hsa_status_t MemoryRegion::Allocate(size_t& size, AllocateFlags alloc_flags, voi size = AlignUp(size, fragment_allocator_.max_alloc()); } + // Allocate memory. + // If it fails attempt to release memory from the block allocator and retry. *address = AllocateKfdMemory(kmt_alloc_flags, owner()->node_id(), size); + if (*address == nullptr) { + fragment_allocator_.trim(); + *address = AllocateKfdMemory(kmt_alloc_flags, owner()->node_id(), size); + } - if (*address != NULL) { + if (*address != nullptr) { // Commit the memory. // For system memory, on non-restricted allocation, map it to all GPUs. On // restricted allocation, only CPU is allowed to access by default, so