From dc4ad8c99cfdeff84e289dbe5a913ec6104a5c0c Mon Sep 17 00:00:00 2001 From: German Date: Thu, 27 Oct 2022 16:39:05 -0400 Subject: [PATCH] SWDEV-363074 - Enable resource cache for SVM Blender creates and destroys big allocations during the benchmark. That causes big delays, because vidmm has to page-in/page-out memory. Change-Id: I2baf4545807127406e3d2870a7581ff9ae7bcdb5 --- rocclr/device/pal/palresource.cpp | 18 +++++++++++------- rocclr/device/pal/palresource.hpp | 1 + 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/rocclr/device/pal/palresource.cpp b/rocclr/device/pal/palresource.cpp index 78cb1b6814..9f77ff70c1 100644 --- a/rocclr/device/pal/palresource.cpp +++ b/rocclr/device/pal/palresource.cpp @@ -1230,6 +1230,7 @@ bool Resource::create(MemoryType memType, CreateParams* params, bool forceLinear svmPtr = reinterpret_cast(params->owner_->getSvmPtr()); desc_.SVMRes_ = true; svmPtr = (svmPtr == 1) ? 0 : svmPtr; + desc_.reserved_va_ = (svmPtr == 1) ? false : true; if (params->owner_->getMemFlags() & CL_MEM_SVM_ATOMICS) { desc_.gl2CacheDisabled_ = true; } @@ -1424,7 +1425,8 @@ bool Resource::partialMemCopyTo(VirtualGPU& gpu, const amd::Coord3D& srcOrigin, } } - if (dev().settings().disableSdma_) { + bool cp_dma = dev().settings().disableSdma_; + if (cp_dma) { // Make sure compute is done before CP DMA start gpu.addBarrier(RgpSqqtBarrierReason::MemDependency); } else { @@ -1517,7 +1519,7 @@ bool Resource::partialMemCopyTo(VirtualGPU& gpu, const amd::Coord3D& srcOrigin, copyRegion.dstOffset = dstOrigin[0] + dstResource.offset(); copyRegion.copySize = size[0]; constexpr size_t CpCopySizeLimit = (1 << 26) - sizeof(uint64_t); - if (dev().settings().disableSdma_ && (size[0] > CpCopySizeLimit)) { + if (cp_dma && (size[0] > CpCopySizeLimit)) { size_t orgSize = size[0]; copyRegion.copySize = CpCopySizeLimit; do { @@ -1535,7 +1537,7 @@ bool Resource::partialMemCopyTo(VirtualGPU& gpu, const amd::Coord3D& srcOrigin, } } - if (dev().settings().disableSdma_) { + if (cp_dma) { // Make sure CP dma is done gpu.addBarrier(RgpSqqtBarrierReason::MemDependency); } @@ -2146,7 +2148,7 @@ bool ResourceCache::addGpuMemory(Resource::Descriptor* desc, GpuMemoryReference* // Make sure current allocation isn't bigger than cache if (((desc->type_ == Resource::Local) || (desc->type_ == Resource::Persistent) || (desc->type_ == Resource::Remote) || (desc->type_ == Resource::RemoteUSWC)) && - (size < cacheSizeLimit_) && !desc->SVMRes_) { + (size < cacheSizeLimit_ && !(desc->SVMRes_ && desc->reserved_va_))) { // Validate the cache size limit. Loop until we have enough space while ((cacheSize_ + size) > cacheSizeLimit_) { removeLast(); @@ -2197,8 +2199,8 @@ GpuMemoryReference* ResourceCache::findGpuMemory(Resource::Descriptor* desc, Pal return ref; } - // Early exit if resource is too big - if (size >= cacheSizeLimit_ || desc->SVMRes_) { + // Early exit if resource is too big or it's SVM allocation with a reserved VA + if (size >= cacheSizeLimit_ || (desc->SVMRes_ && desc->reserved_va_)) { //! \note we may need to free the cache here to reduce memory pressure return ref; } @@ -2210,7 +2212,9 @@ GpuMemoryReference* ResourceCache::findGpuMemory(Resource::Descriptor* desc, Pal // Find if we can reuse this entry if ((entry->type_ == desc->type_) && (entry->flags_ == desc->flags_) && (size <= sizeRes) && (size > (sizeRes >> 1)) && ((it.second->iMem()->Desc().gpuVirtAddr % alignment) == 0) && - (entry->isAllocExecute_ == desc->isAllocExecute_)) { + (entry->isAllocExecute_ == desc->isAllocExecute_) && + (entry->SVMRes_ == desc->SVMRes_) && + (entry->gl2CacheDisabled_ == desc->gl2CacheDisabled_)) { ref = it.second; cacheSize_ -= sizeRes; if (entry->type_ == Resource::Local) { diff --git a/rocclr/device/pal/palresource.hpp b/rocclr/device/pal/palresource.hpp index cad4f2b3b4..00cf5a048a 100644 --- a/rocclr/device/pal/palresource.hpp +++ b/rocclr/device/pal/palresource.hpp @@ -209,6 +209,7 @@ class Resource : public amd::HeapObject { uint isAllocExecute_ : 1; //!< SVM resource allocation attribute for shader\cmdbuf uint isDoppTexture_ : 1; //!< PAL resource is for a DOPP desktop texture uint gl2CacheDisabled_ : 1;//!< PAL resource is allocated with GPU L2 cache disabled. + uint reserved_va_ : 1; //!< PAL resource was allocated for a reserved VA }; uint state_; };