From ece92c4e215a4560a4185c9c957ad567f30227c7 Mon Sep 17 00:00:00 2001
From: foreman
Date: Thu, 26 Jan 2017 13:45:49 -0500
Subject: [PATCH] P4 to Git Change 1366459 by gandryey@gera-w8 on 2017/01/26
13:37:23
SWDEV-112016 - [ROCm CQE][OCLonLC][QR][G] Seg fault observed with "sub_buffers_read_write" of Buffers, due to CL#1364923
- Fix subbuffers logic with AHP allocations
- Make AHP allocations to use UHP path
Affected files ...
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocblit.cpp#7 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocdevice.cpp#37 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocmemory.cpp#7 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocsettings.cpp#14 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocvirtual.cpp#28 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocvirtual.hpp#7 edit
[ROCm/clr commit: 5fd072d9b33c764f6d493494b620ed94779a3aea]
---
.../rocclr/runtime/device/rocm/rocblit.cpp | 2 +
.../rocclr/runtime/device/rocm/rocdevice.cpp | 2 +
.../rocclr/runtime/device/rocm/rocmemory.cpp | 41 +++++++++++--------
.../runtime/device/rocm/rocsettings.cpp | 2 +-
.../rocclr/runtime/device/rocm/rocvirtual.cpp | 6 +++
.../rocclr/runtime/device/rocm/rocvirtual.hpp | 2 +
6 files changed, 38 insertions(+), 17 deletions(-)
diff --git a/projects/clr/rocclr/runtime/device/rocm/rocblit.cpp b/projects/clr/rocclr/runtime/device/rocm/rocblit.cpp
index a557565ee8..ba8cf926fd 100644
--- a/projects/clr/rocclr/runtime/device/rocm/rocblit.cpp
+++ b/projects/clr/rocclr/runtime/device/rocm/rocblit.cpp
@@ -22,10 +22,12 @@ DmaBlitManager::DmaBlitManager(VirtualGPU& gpu, Setup setup)
inline void
DmaBlitManager::synchronize() const
{
+ // todo TS tracking isn't implemented
gpu().releaseGpuMemoryFence();
if (syncOperation_) {
// gpu().waitAllEngines();
+ gpu().releasePinnedMem();
}
}
diff --git a/projects/clr/rocclr/runtime/device/rocm/rocdevice.cpp b/projects/clr/rocclr/runtime/device/rocm/rocdevice.cpp
index 599b574d7f..bde814d9c9 100644
--- a/projects/clr/rocclr/runtime/device/rocm/rocdevice.cpp
+++ b/projects/clr/rocclr/runtime/device/rocm/rocdevice.cpp
@@ -1417,6 +1417,7 @@ Device::createMemory(amd::Memory &owner) const
amd::Coord3D(0, 0, 0), imageView->getRegion(),
0,
0, true);
+ owner.setHostMem(nullptr);
imageView->release();
}
@@ -1564,6 +1565,7 @@ Device::xferQueue() const
LogError("Couldn't create the device transfer manager!");
}
}
+ xferQueue_->enableSyncBlit();
return xferQueue_;
}
diff --git a/projects/clr/rocclr/runtime/device/rocm/rocmemory.cpp b/projects/clr/rocclr/runtime/device/rocm/rocmemory.cpp
index 6a7ce7756f..4913a8c768 100644
--- a/projects/clr/rocclr/runtime/device/rocm/rocmemory.cpp
+++ b/projects/clr/rocclr/runtime/device/rocm/rocmemory.cpp
@@ -43,6 +43,9 @@ Memory::Memory(const roc::Device &dev, size_t size)
Memory::~Memory()
{
dev_.removeVACache(this);
+ if (nullptr != mapMemory_) {
+ mapMemory_->release();
+ }
}
bool
@@ -62,7 +65,6 @@ Memory::allocateMapMemory(size_t allocationSize)
if ((mapMemory == NULL) || (!mapMemory->create())) {
LogError("[OCL] Fail to allocate map target object");
- dev_.hostFree(mapData);
if (mapMemory) {
mapMemory->release();
}
@@ -125,9 +127,7 @@ Memory::allocMapTarget(
}
}
- roc::Memory* hsaMapMemory = reinterpret_cast(
- mapMemory_->getDeviceMemory(dev_));
- return reinterpret_cast(hsaMapMemory->getDeviceMemory()) + origin[0];
+ return reinterpret_cast(mapMemory_->getHostMem()) + origin[0];
}
void
@@ -284,7 +284,7 @@ Buffer::destroy()
// if they are identical, the host pointer will be
// deallocated later on => avoid double deallocation
if (isHostMemDirectAccess()) {
- if (memFlags & CL_MEM_USE_HOST_PTR) {
+ if (memFlags & (CL_MEM_USE_HOST_PTR | CL_MEM_ALLOC_HOST_PTR)) {
if (dev_.agent_profile() != HSA_PROFILE_FULL) {
hsa_amd_memory_unlock(owner()->getHostMem());
}
@@ -318,12 +318,13 @@ Buffer::create()
if(owner()->isInterop())
return createInteropBuffer(GL_ARRAY_BUFFER, 0, NULL, NULL);
- if (owner()->parent()) {
+ if (nullptr != owner()->parent()) {
+ amd::Memory& parent = *owner()->parent();
// Sub-Buffer creation.
- roc::Memory *parentBuffer =
- static_cast(owner()->parent()->getDeviceMemory(dev_));
+ roc:Memory* parentBuffer =
+ static_cast(parent.getDeviceMemory(dev_));
- if (parentBuffer == NULL) {
+ if (parentBuffer == nullptr) {
LogError("[OCL] Fail to allocate parent buffer");
return false;
}
@@ -332,8 +333,19 @@ Buffer::create()
deviceMemory_ = parentBuffer->getDeviceMemory() + offset;
flags_ |= SubMemoryObject;
- flags_ |=
- parentBuffer->isHostMemDirectAccess() ? HostMemoryDirectAccess : 0;
+ flags_ |= parentBuffer->isHostMemDirectAccess() ?
+ HostMemoryDirectAccess : 0;
+
+ // Explicitly set the host memory location,
+ // because the parent location could change after reallocation
+ if (nullptr != parent.getHostMem()) {
+ owner()->setHostMem(
+ reinterpret_cast(parent.getHostMem()) + offset);
+ }
+ else {
+ owner()->setHostMem(nullptr);
+ }
+
return true;
}
@@ -383,10 +395,7 @@ Buffer::create()
owner()->getHostMem(), *devBufferView, amd::Coord3D(0),
amd::Coord3D(size()), true);
- if (!ret) {
- dev_.memFree(deviceMemory_, size());
- deviceMemory_ = NULL;
- }
+ owner()->setHostMem(nullptr);
bufferView->release();
return ret;
@@ -420,7 +429,7 @@ Buffer::create()
}
if (owner()->getSvmPtr() != owner()->getHostMem()) {
- if (memFlags & CL_MEM_USE_HOST_PTR) {
+ if (memFlags & (CL_MEM_USE_HOST_PTR | CL_MEM_ALLOC_HOST_PTR)) {
hsa_agent_t agent = dev_.getBackendDevice();
hsa_status_t status = hsa_amd_memory_lock(
owner()->getHostMem(), owner()->getSize(), &agent, 1, &deviceMemory_);
diff --git a/projects/clr/rocclr/runtime/device/rocm/rocsettings.cpp b/projects/clr/rocclr/runtime/device/rocm/rocsettings.cpp
index cbdccdc700..09c299645b 100644
--- a/projects/clr/rocclr/runtime/device/rocm/rocsettings.cpp
+++ b/projects/clr/rocclr/runtime/device/rocm/rocsettings.cpp
@@ -73,7 +73,7 @@ Settings::Settings()
bool
Settings::create(bool fullProfile)
{
- customHostAllocator_ = true;
+ customHostAllocator_ = false;
if (fullProfile) {
pinnedXferSize_ = 0;
diff --git a/projects/clr/rocclr/runtime/device/rocm/rocvirtual.cpp b/projects/clr/rocclr/runtime/device/rocm/rocvirtual.cpp
index 6fe28dea08..1d7c9f20db 100644
--- a/projects/clr/rocclr/runtime/device/rocm/rocvirtual.cpp
+++ b/projects/clr/rocclr/runtime/device/rocm/rocvirtual.cpp
@@ -1839,4 +1839,10 @@ VirtualGPU::findPinnedMem(void* addr, size_t size)
}
return nullptr;
}
+
+void
+VirtualGPU::enableSyncBlit() const
+{
+ blitMgr_->enableSynchronization();
+}
} // End of roc namespace
diff --git a/projects/clr/rocclr/runtime/device/rocm/rocvirtual.hpp b/projects/clr/rocclr/runtime/device/rocm/rocvirtual.hpp
index bbf29929f6..95b6a4337d 100644
--- a/projects/clr/rocclr/runtime/device/rocm/rocvirtual.hpp
+++ b/projects/clr/rocclr/runtime/device/rocm/rocvirtual.hpp
@@ -212,6 +212,8 @@ public:
//! Finds if pinned memory is cached
amd::Memory* findPinnedMem(void* addr, size_t size);
+ void enableSyncBlit() const;
+
// } roc OpenCL integration
private:
bool dispatchAqlPacket(