From 2919f24b17ee62b4f2c467e85eecc951cf3c4294 Mon Sep 17 00:00:00 2001
From: foreman
Date: Fri, 27 Apr 2018 16:22:03 -0400
Subject: [PATCH] P4 to Git Change 1547415 by gandryey@gera-w8 on 2018/04/27
16:14:51
SWDEV-79445 - OCL generic changes and code clean-up
- Persistent memory failure could be propagated to the app without the second attempt after resource cache release. Try to allocate memory again after resource cache release.
Affected files ...
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palresource.cpp#65 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palresource.hpp#23 edit
[ROCm/clr commit: 402f99f3e63df983a6814c543656c08532abe68c]
---
.../clr/rocclr/runtime/device/pal/palresource.cpp | 13 ++++++++++---
.../clr/rocclr/runtime/device/pal/palresource.hpp | 3 ++-
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/projects/clr/rocclr/runtime/device/pal/palresource.cpp b/projects/clr/rocclr/runtime/device/pal/palresource.cpp
index 178e79055e..cb16e3a695 100644
--- a/projects/clr/rocclr/runtime/device/pal/palresource.cpp
+++ b/projects/clr/rocclr/runtime/device/pal/palresource.cpp
@@ -40,10 +40,14 @@ GpuMemoryReference* GpuMemoryReference::Create(const Device& dev,
GpuMemoryReference* memRef = new (gpuMemSize) GpuMemoryReference(dev);
if (memRef != nullptr) {
result = dev.iDev()->CreateGpuMemory(createInfo, &memRef[1], &memRef->gpuMem_);
+ if ((result != Pal::Result::Success) &&
+ // Free cache if PAL failed allocation
+ dev.resourceCache().free()) {
+ // If cache was freed, then try to allocate again
+ result = dev.iDev()->CreateGpuMemory(createInfo, &memRef[1], &memRef->gpuMem_);
+ }
if (result != Pal::Result::Success) {
memRef->release();
- // Free cache if PAL failed allocation
- dev.resourceCache().free();
return nullptr;
}
}
@@ -2034,14 +2038,17 @@ GpuMemoryReference* ResourceCache::findGpuMemory(Resource::Descriptor* desc, Pal
}
// ================================================================================================
-void ResourceCache::free(size_t minCacheEntries) {
+bool ResourceCache::free(size_t minCacheEntries) {
+ bool result = false;
if (minCacheEntries < resCache_.size()) {
+ result = true;
// Clear the cache
while (static_cast(cacheSize_) > 0) {
removeLast();
}
CondLog((cacheSize_ != 0), "Incorrect size for cache release!");
}
+ return result;
}
// ================================================================================================
diff --git a/projects/clr/rocclr/runtime/device/pal/palresource.hpp b/projects/clr/rocclr/runtime/device/pal/palresource.hpp
index 3ae73d7ec6..f25ed34e99 100644
--- a/projects/clr/rocclr/runtime/device/pal/palresource.hpp
+++ b/projects/clr/rocclr/runtime/device/pal/palresource.hpp
@@ -548,7 +548,8 @@ class ResourceCache : public amd::HeapObject {
Pal::gpusize* offset);
//! Destroys cache
- void free(size_t minCacheEntries = 0);
+ //! Returns true if cache was freed and false if cache is already empty.
+ bool free(size_t minCacheEntries = 0);
private:
//! Disable copy constructor