diff --git a/projects/clr/rocclr/runtime/device/gpu/gpumemory.cpp b/projects/clr/rocclr/runtime/device/gpu/gpumemory.cpp index 7676a00a19..d1993feced 100644 --- a/projects/clr/rocclr/runtime/device/gpu/gpumemory.cpp +++ b/projects/clr/rocclr/runtime/device/gpu/gpumemory.cpp @@ -411,6 +411,10 @@ Memory::~Memory() { // Release associated map target, if any if (NULL != mapMemory_) { + if (owner()->getSvmPtr() != nullptr) { + owner()->uncommitSvmMemory(); + } + mapMemory()->unmap(NULL); mapMemory_->release(); } diff --git a/projects/clr/rocclr/runtime/device/pal/palmemory.cpp b/projects/clr/rocclr/runtime/device/pal/palmemory.cpp index fcf2650b64..e1daa09537 100644 --- a/projects/clr/rocclr/runtime/device/pal/palmemory.cpp +++ b/projects/clr/rocclr/runtime/device/pal/palmemory.cpp @@ -385,6 +385,10 @@ Memory::~Memory() { // Release associated map target, if any if (nullptr != mapMemory_) { + if (owner()->getSvmPtr() != nullptr) { + owner()->uncommitSvmMemory(); + } + mapMemory()->unmap(nullptr); mapMemory_->release(); } diff --git a/projects/clr/rocclr/runtime/platform/memory.cpp b/projects/clr/rocclr/runtime/platform/memory.cpp index 2f00dd8f08..194169d48a 100644 --- a/projects/clr/rocclr/runtime/platform/memory.cpp +++ b/projects/clr/rocclr/runtime/platform/memory.cpp @@ -431,6 +431,14 @@ void Memory::commitSvmMemory() { } } +void Memory::uncommitSvmMemory() { + ScopedLock lock(lockMemoryOps_); + if (svmPtrCommited_ && !(flags_ & CL_MEM_SVM_FINE_GRAIN_BUFFER)) { + amd::Os::uncommitMemory(svmHostAddress_, size_); + svmPtrCommited_ = false; + } +} + void Buffer::initDeviceMemory() { deviceMemories_ = reinterpret_cast(reinterpret_cast(this) + sizeof(Buffer)); memset(deviceMemories_, 0, context_().devices().size() * sizeof(DeviceMemory)); diff --git a/projects/clr/rocclr/runtime/platform/memory.hpp b/projects/clr/rocclr/runtime/platform/memory.hpp index 7648cd6e38..5f151508b7 100644 --- a/projects/clr/rocclr/runtime/platform/memory.hpp +++ b/projects/clr/rocclr/runtime/platform/memory.hpp @@ -306,6 +306,7 @@ class Memory : public amd::RuntimeObject { return svmPtrCommited_; } //!< svm host address committed accessor; void commitSvmMemory(); //!< svm host address committed accessor; + void uncommitSvmMemory(); void setCacheStatus(bool canBeCached) { canBeCached_ = canBeCached; } //!< set the memobject cached status;