From 3e14baceee9cf0f0c7ecd6dd0c70eb52a5d8761d Mon Sep 17 00:00:00 2001
From: foreman
Date: Tue, 10 Apr 2018 12:00:04 -0400
Subject: [PATCH] P4 to Git Change 1538910 by vsytchen@vsytchen-ocl-win10 on
2018/04/10 11:54:42
SWDEV-150453 - [CQE OCL][DTB][Perf][QR][Vega][DTB-BLOCKER] Performance drop observed on multiple subtests while running Nuke
1. Clean up suballocation chunk creation logic.
2. Try to cache a resource if it wasn't a suballocation.
ReviewBoardURL = http://ocltc.amd.com/reviews/r/14591/diff/
Affected files ...
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palresource.cpp#62 edit
---
rocclr/runtime/device/pal/palresource.cpp | 32 +++++++++++++----------
1 file changed, 18 insertions(+), 14 deletions(-)
diff --git a/rocclr/runtime/device/pal/palresource.cpp b/rocclr/runtime/device/pal/palresource.cpp
index db95809669..7c41dabc0a 100644
--- a/rocclr/runtime/device/pal/palresource.cpp
+++ b/rocclr/runtime/device/pal/palresource.cpp
@@ -1803,14 +1803,14 @@ bool MemorySubAllocator::InitAllocator(GpuMemoryReference* mem_ref) {
MemBuddyAllocator* allocator = new MemBuddyAllocator(
device_, device_->settings().subAllocationChunkSize_,
device_->settings().subAllocationMinSize_);
- if ((allocator != nullptr) && (allocator->Init() == Pal::Result::Success)) {
- heaps_.insert({mem_ref, allocator});
- return true;
- } else {
+ if (!((allocator != nullptr) &&
+ (allocator->Init() == Pal::Result::Success) &&
+ heaps_.insert({mem_ref, allocator}).second)) {
+ mem_ref->release();
delete allocator;
return false;
}
- return false;
+ return true;
}
// ================================================================================================
@@ -1868,7 +1868,7 @@ bool FineMemorySubAllocator::CreateChunk(const Pal::IGpuMemory* reserved_va) {
MemorySubAllocator::~MemorySubAllocator()
{
// Release memory heap for suballocations
- for (auto it : heaps_) {
+ for (const auto& it : heaps_) {
it.first->release();
delete it.second;
}
@@ -1887,7 +1887,7 @@ GpuMemoryReference* MemorySubAllocator::Allocate(Pal::gpusize size, Pal::gpusize
size = amd::alignUp(size, device_->settings().subAllocationMinSize_);
do {
// Find if current heap has enough empty space
- for (auto it : heaps_) {
+ for (const auto& it : heaps_) {
mem_ref = it.first;
allocator = it.second;
// SVM allocations may required a fixed VA, make sure we find the heap with the same VA
@@ -1898,17 +1898,16 @@ GpuMemoryReference* MemorySubAllocator::Allocate(Pal::gpusize size, Pal::gpusize
// If we have found a valid chunk, then suballocate memory
if (Pal::Result::Success == allocator->Allocate(size, alignment, offset)) {
return mem_ref;
- } else {
- mem_ref = nullptr;
}
}
- if ((mem_ref == nullptr) && !CreateChunk(reserved_va)) {
+ // We didn't find a valid chunk, so create a new one
+ if (!CreateChunk(reserved_va)) {
return nullptr;
}
i++;
} while (i < 2);
}
- return mem_ref;
+ return nullptr;
}
// ================================================================================================
@@ -1950,11 +1949,16 @@ bool ResourceCache::addGpuMemory(Resource::Descriptor* desc,
// Check if runtime can free suballocation
if ((desc->type_ == Resource::Local) && !desc->SVMRes_) {
- return mem_sub_alloc_local_.Free(&lockCacheOps_, ref, offset);
+ result = mem_sub_alloc_local_.Free(&lockCacheOps_, ref, offset);
} else if ((desc->type_ == Resource::Local) && desc->SVMRes_) {
- return mem_sub_alloc_coarse_.Free(&lockCacheOps_, ref, offset);
+ result = mem_sub_alloc_coarse_.Free(&lockCacheOps_, ref, offset);
} else if (desc->SVMRes_) {
- return mem_sub_alloc_fine_.Free(&lockCacheOps_, ref, offset);
+ result = mem_sub_alloc_fine_.Free(&lockCacheOps_, ref, offset);
+ }
+
+ // If a resource was a suballocation, don't try to cache it
+ if (result == true) {
+ return result;
}
// Make sure current allocation isn't bigger than cache