From 48590452f11f1b2b6b4f7b2ed146beaf541505fb Mon Sep 17 00:00:00 2001
From: foreman
Date: Wed, 21 Sep 2016 17:08:14 -0400
Subject: [PATCH] P4 to Git Change 1317211 by gandryey@gera-w8 on 2016/09/21
16:53:02
SWDEV-102971 - [CQE OCL][OpenCL on PAL] "computer on low memory" issue observed folllowed by tdr while running few WF Conformance tests together
- Use custom memory allocator to avoid memory grow in PAL
- Extra clean-ups in resource alloc, including a fix for image pitch in the persistent memory
Affected files ...
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palmemory.cpp#6 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palresource.cpp#11 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palresource.hpp#7 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palvirtual.cpp#22 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palvirtual.hpp#9 edit
---
rocclr/runtime/device/pal/palmemory.cpp | 4 ++--
rocclr/runtime/device/pal/palresource.cpp | 27 ++++++++++++++---------
rocclr/runtime/device/pal/palresource.hpp | 26 +++++++++++-----------
rocclr/runtime/device/pal/palvirtual.cpp | 1 +
rocclr/runtime/device/pal/palvirtual.hpp | 17 ++++++++------
5 files changed, 42 insertions(+), 33 deletions(-)
diff --git a/rocclr/runtime/device/pal/palmemory.cpp b/rocclr/runtime/device/pal/palmemory.cpp
index 6f03d78cdb..eb7f8cc2b3 100644
--- a/rocclr/runtime/device/pal/palmemory.cpp
+++ b/rocclr/runtime/device/pal/palmemory.cpp
@@ -190,10 +190,10 @@ bool Memory::processGLResource(GLResourceOP operation)
switch (operation)
{
case GLDecompressResource:
- retVal = gslGLAcquire();
+ retVal = glAcquire();
break;
case GLInvalidateFBO:
- retVal = gslGLRelease();
+ retVal = glRelease();
break;
default:
assert(false && "unknown GLResourceOP");
diff --git a/rocclr/runtime/device/pal/palresource.cpp b/rocclr/runtime/device/pal/palresource.cpp
index 1773ca3c42..e433dc3e1c 100644
--- a/rocclr/runtime/device/pal/palresource.cpp
+++ b/rocclr/runtime/device/pal/palresource.cpp
@@ -946,7 +946,6 @@ Resource::create(MemoryType memType, CreateParams* params)
pinAddress = tmpHost;
- // Align width to avoid GSL useless assert with a view
if (hostMemOffset != 0) {
allocSize += hostMemOffset;
}
@@ -1045,8 +1044,8 @@ Resource::free()
}
// Add resource to the cache
- if (wait && !dev().resourceCache().addGpuMemory(&desc_, memRef_)) {
- gslFree();
+ if (!dev().resourceCache().addGpuMemory(&desc_, memRef_)) {
+ palFree();
}
}
}
@@ -1064,7 +1063,7 @@ Resource::free()
dev().vgpus()[idx]->releaseMemory(iMem());
}
}
- gslFree();
+ palFree();
}
}
}
@@ -1072,10 +1071,10 @@ Resource::free()
else {
if (renames_.size() == 0) {
// Destroy GSL resource
- if (wait && (iMem() != 0)) {
+ if (iMem() != 0) {
// Release virtual memory object on the specified virtual GPU
gpu_->releaseMemory(iMem(), wait);
- gslFree();
+ palFree();
}
}
else for (size_t i = 0; i < renames_.size(); ++i) {
@@ -1084,7 +1083,7 @@ Resource::free()
if (iMem() != 0) {
// Release virtual memory object on the specified virtual GPUs
gpu_->releaseMemory(iMem());
- gslFree();
+ palFree();
}
}
}
@@ -1496,7 +1495,13 @@ Resource::gpuMemoryMap(size_t* pitch, uint flags, Pal::IGpuMemory* resource) con
else {
amd::ScopedLock lk(dev().lockPAL());
void* address;
- *pitch = desc().width_ * elementSize();
+ if (image_ != nullptr) {
+ constexpr Pal::SubresId ImgSubresId = { Pal::ImageAspect::Color, 0, 0 };
+ Pal::SubresLayout layout;
+ image_->GetSubresourceLayout(ImgSubresId, &layout);
+ *pitch = layout.rowPitch / elementSize();
+ }
+ *pitch = desc().width_;
if (Pal::Result::Success == resource->Map(&address)) {
return address;
}
@@ -1524,7 +1529,7 @@ Resource::gpuMemoryUnmap(Pal::IGpuMemory* resource) const
}
bool
-Resource::gslGLAcquire()
+Resource::glAcquire()
{
bool retVal = true;
if (desc().type_ == OGLInterop) {
@@ -1534,7 +1539,7 @@ Resource::gslGLAcquire()
}
bool
-Resource::gslGLRelease()
+Resource::glRelease()
{
bool retVal = true;
if (desc().type_ == OGLInterop) {
@@ -1543,7 +1548,7 @@ Resource::gslGLRelease()
return retVal;
}
void
-Resource::gslFree() const
+Resource::palFree() const
{
amd::ScopedLock lk(dev().lockPAL());
diff --git a/rocclr/runtime/device/pal/palresource.hpp b/rocclr/runtime/device/pal/palresource.hpp
index 5d89ca9850..ca489a6d69 100644
--- a/rocclr/runtime/device/pal/palresource.hpp
+++ b/rocclr/runtime/device/pal/palresource.hpp
@@ -174,10 +174,10 @@ public:
union {
struct {
uint dimSize_ : 2; //!< Dimension size
- uint cardMemory_ : 1; //!< GSL resource is in video memory
- uint imageArray_ : 1; //!< GSL resource is an array of images
- uint buffer_ : 1; //!< GSL resource is a buffer
- uint tiled_ : 1; //!< GSL resource is tiled
+ uint cardMemory_ : 1; //!< PAL resource is in video memory
+ uint imageArray_ : 1; //!< PAL resource is an array of images
+ uint buffer_ : 1; //!< PAL resource is a buffer
+ uint tiled_ : 1; //!< PAL resource is tiled
uint SVMRes_ : 1; //!< SVM flag to the cal resource
uint scratch_ : 1; //!< Scratch buffer
uint isAllocExecute_ : 1; //!< SVM resource allocation attribute for shader\cmdbuf
@@ -351,8 +351,8 @@ public:
bool isCacheable() const
{ return (isMemoryType(Remote) || isMemoryType(Pinned)) ? true : false; }
- bool gslGLAcquire() ;
- bool gslGLRelease() ;
+ bool glAcquire() ;
+ bool glRelease() ;
//! Returns HW state for the resource (used for images only)
const void* hwState() const { return hwState_; }
@@ -407,20 +407,20 @@ private:
VirtualGPU* gpu //!< Virtual GPU device object
);
- //! Calls GSL to map a resource
+ //! Calls PAL to map a resource
void* gpuMemoryMap(
size_t* pitch, //!< Pitch value for the image
uint flags, //!< Map flags
- Pal::IGpuMemory* resource //!< GSL memory object
+ Pal::IGpuMemory* resource //!< PAL memory object
) const;
- //! Uses GSL to unmap a resource
+ //! Uses PAL to unmap a resource
void gpuMemoryUnmap(
- Pal::IGpuMemory* resource //!< GSL memory object
+ Pal::IGpuMemory* resource //!< PAL memory object
) const;
- //! Fress all GSL resources associated with OCL resource
- void gslFree() const;
+ //! Fress all PAL resources associated with OCL resource
+ void palFree() const;
//! Converts Resource memory type to the PAL heaps
void memTypeToHeap(
@@ -434,7 +434,7 @@ private:
size_t offset_; //!< Resource offset
size_t curRename_; //!< Current active rename in the list
RenameList renames_; //!< Rename resource list
- GpuMemoryReference* memRef_; //!< GSL resource reference
+ GpuMemoryReference* memRef_; //!< PAL resource reference
const Resource* viewOwner_; //!< GPU resource, which owns this view
uint64_t pinOffset_; //!< Pinned memory offset
void* glInteropMbRes_;//!< Mb Res handle
diff --git a/rocclr/runtime/device/pal/palvirtual.cpp b/rocclr/runtime/device/pal/palvirtual.cpp
index bacd8e88c7..b88737cb81 100644
--- a/rocclr/runtime/device/pal/palvirtual.cpp
+++ b/rocclr/runtime/device/pal/palvirtual.cpp
@@ -251,6 +251,7 @@ VirtualGPU::Queue::flush()
}
// Start command buffer building
Pal::CmdBufferBuildInfo cmdBuildInfo = {};
+ cmdBuildInfo.pMemAllocator = &vlAlloc_;
if (Pal::Result::Success != iCmdBuffs_[cmdBufIdSlot_]->Begin(cmdBuildInfo)) {
LogError("PAL failed CB building initialization!");
return false;
diff --git a/rocclr/runtime/device/pal/palvirtual.hpp b/rocclr/runtime/device/pal/palvirtual.hpp
index c35bcb6318..d4716f0550 100644
--- a/rocclr/runtime/device/pal/palvirtual.hpp
+++ b/rocclr/runtime/device/pal/palvirtual.hpp
@@ -13,6 +13,7 @@
#include "palCmdBuffer.h"
#include "palCmdAllocator.h"
#include "palQueue.h"
+#include "palLinearAllocator.h"
/*! \addtogroup PAL PAL Resource Implementation
* @{
@@ -53,14 +54,15 @@ public:
Queue(Pal::IDevice* palDev)
: iDev_(palDev), iQueue_(NULL),
- cmdBufIdSlot_(StartCmdBufIdx), cmdBufIdCurrent_(StartCmdBufIdx),
- cmbBufIdRetired_(0), cmdCnt_(0)
- {
- for (uint i = 0; i < MaxCmdBuffers; ++i) {
- iCmdBuffs_[i] = NULL;
- iCmdFences_[i] = NULL;
- }
+ cmdBufIdSlot_(StartCmdBufIdx), cmdBufIdCurrent_(StartCmdBufIdx),
+ cmbBufIdRetired_(0), cmdCnt_(0), vlAlloc_(64 * Ki)
+ {
+ for (uint i = 0; i < MaxCmdBuffers; ++i) {
+ iCmdBuffs_[i] = NULL;
+ iCmdFences_[i] = NULL;
}
+ vlAlloc_.Init();
+ }
~Queue();
@@ -102,6 +104,7 @@ public:
uint cmbBufIdRetired_; //!< The last retired command buffer ID
uint cmdCnt_; //!< Counter of commands
std::map memReferences_;
+ Util::VirtualLinearAllocator vlAlloc_;
};
struct CommandBatch : public amd::HeapObject